1/*
2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
3 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer.
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#pragma once
32
33#include "CachedResourceHandle.h"
34#include "CachedSVGDocumentClient.h"
35#include "RenderLayer.h"
36
37namespace WebCore {
38
39class CachedSVGDocument;
40class Element;
41class FilterOperations;
42
43class RenderLayerFilters final : private CachedSVGDocumentClient {
44 WTF_MAKE_FAST_ALLOCATED;
45public:
46 explicit RenderLayerFilters(RenderLayer&);
47 virtual ~RenderLayerFilters();
48
49 const LayoutRect& dirtySourceRect() const { return m_dirtySourceRect; }
50 void expandDirtySourceRect(const LayoutRect& rect) { m_dirtySourceRect.unite(rect); }
51
52 CSSFilter* filter() const { return m_filter.get(); }
53 void setFilter(RefPtr<CSSFilter>&&);
54
55 bool hasFilterThatMovesPixels() const;
56 bool hasFilterThatShouldBeRestrictedBySecurityOrigin() const;
57
58 void updateReferenceFilterClients(const FilterOperations&);
59 void removeReferenceFilterClients();
60
61 void buildFilter(RenderElement&, float scaleFactor, RenderingMode);
62
63 // Per render
64 LayoutRect repaintRect() const { return m_repaintRect; }
65
66 GraphicsContext* beginFilterEffect(GraphicsContext& destinationContext, const LayoutRect& filterBoxRect, const LayoutRect& dirtyRect, const LayoutRect& layerRepaintRect);
67 void applyFilterEffect(GraphicsContext& destinationContext);
68
69private:
70 void notifyFinished(CachedResource&) final;
71 void resetDirtySourceRect() { m_dirtySourceRect = LayoutRect(); }
72
73 RenderLayer& m_layer;
74
75 Vector<RefPtr<Element>> m_internalSVGReferences;
76 Vector<CachedResourceHandle<CachedSVGDocument>> m_externalSVGReferences;
77
78 RefPtr<CSSFilter> m_filter;
79 LayoutRect m_dirtySourceRect;
80
81 // Data used per paint
82 LayoutPoint m_paintOffset;
83 LayoutRect m_repaintRect;
84};
85
86} // namespace WebCore
87