Combine event and touch action regions into a single class
[WebKit-https.git] / Source / WebKit / WebProcess / WebPage / RemoteLayerTree / PlatformCALayerRemote.h
1 /*
2  * Copyright (C) 2013 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma once
27
28 #include "RemoteLayerTreeTransaction.h"
29 #include <WebCore/PlatformCALayer.h>
30 #include <WebCore/PlatformLayer.h>
31
32 namespace WebCore {
33 class LayerPool;
34 }
35
36 namespace WebKit {
37
38 class RemoteLayerTreeContext;
39
40 class PlatformCALayerRemote : public WebCore::PlatformCALayer {
41 public:
42     static Ref<PlatformCALayerRemote> create(WebCore::PlatformCALayer::LayerType, WebCore::PlatformCALayerClient*, RemoteLayerTreeContext&);
43     static Ref<PlatformCALayerRemote> create(PlatformLayer *, WebCore::PlatformCALayerClient*, RemoteLayerTreeContext&);
44     static Ref<PlatformCALayerRemote> create(const PlatformCALayerRemote&, WebCore::PlatformCALayerClient*, RemoteLayerTreeContext&);
45     static Ref<PlatformCALayerRemote> createForEmbeddedView(WebCore::PlatformCALayer::LayerType, WebCore::GraphicsLayer::EmbeddedViewID, WebCore::PlatformCALayerClient*, RemoteLayerTreeContext&);
46
47     virtual ~PlatformCALayerRemote();
48
49     PlatformLayer* platformLayer() const override { return nullptr; }
50
51     void recursiveBuildTransaction(RemoteLayerTreeContext&, RemoteLayerTreeTransaction&);
52
53     void setNeedsDisplayInRect(const WebCore::FloatRect& dirtyRect) override;
54     void setNeedsDisplay() override;
55
56     void copyContentsFromLayer(PlatformCALayer*) override;
57
58     WebCore::PlatformCALayer* superlayer() const override;
59     void removeFromSuperlayer() override;
60     void setSublayers(const WebCore::PlatformCALayerList&) override;
61     void removeAllSublayers() override;
62     void appendSublayer(WebCore::PlatformCALayer&) override;
63     void insertSublayer(WebCore::PlatformCALayer&, size_t index) override;
64     void replaceSublayer(WebCore::PlatformCALayer& reference, WebCore::PlatformCALayer&) override;
65     const WebCore::PlatformCALayerList* customSublayers() const override { return nullptr; }
66     void adoptSublayers(WebCore::PlatformCALayer& source) override;
67
68     void addAnimationForKey(const String& key, WebCore::PlatformCAAnimation&) override;
69     void removeAnimationForKey(const String& key) override;
70     RefPtr<WebCore::PlatformCAAnimation> animationForKey(const String& key) override;
71     void animationStarted(const String& key, MonotonicTime beginTime) override;
72     void animationEnded(const String& key) override;
73
74     void setMask(WebCore::PlatformCALayer*) override;
75
76     bool isOpaque() const override;
77     void setOpaque(bool) override;
78
79     WebCore::FloatRect bounds() const override;
80     void setBounds(const WebCore::FloatRect&) override;
81
82     WebCore::FloatPoint3D position() const override;
83     void setPosition(const WebCore::FloatPoint3D&) override;
84
85     WebCore::FloatPoint3D anchorPoint() const override;
86     void setAnchorPoint(const WebCore::FloatPoint3D&) override;
87
88     WebCore::TransformationMatrix transform() const override;
89     void setTransform(const WebCore::TransformationMatrix&) override;
90
91     WebCore::TransformationMatrix sublayerTransform() const override;
92     void setSublayerTransform(const WebCore::TransformationMatrix&) override;
93
94     bool isHidden() const override;
95     void setHidden(bool) override;
96
97     bool contentsHidden() const override;
98     void setContentsHidden(bool) override;
99
100     bool userInteractionEnabled() const override;
101     void setUserInteractionEnabled(bool) override;
102
103     void setBackingStoreAttached(bool) override;
104     bool backingStoreAttached() const override;
105
106     bool geometryFlipped() const override;
107     void setGeometryFlipped(bool) override;
108
109     bool isDoubleSided() const override;
110     void setDoubleSided(bool) override;
111
112     bool masksToBounds() const override;
113     void setMasksToBounds(bool) override;
114
115     bool acceleratesDrawing() const override;
116     void setAcceleratesDrawing(bool) override;
117
118     bool wantsDeepColorBackingStore() const override;
119     void setWantsDeepColorBackingStore(bool) override;
120
121     bool supportsSubpixelAntialiasedText() const override;
122     void setSupportsSubpixelAntialiasedText(bool) override;
123
124     bool hasContents() const override;
125     CFTypeRef contents() const override;
126     void setContents(CFTypeRef) override;
127
128     void setContentsRect(const WebCore::FloatRect&) override;
129
130     void setMinificationFilter(WebCore::PlatformCALayer::FilterType) override;
131     void setMagnificationFilter(WebCore::PlatformCALayer::FilterType) override;
132
133     WebCore::Color backgroundColor() const override;
134     void setBackgroundColor(const WebCore::Color&) override;
135
136     void setBorderWidth(float) override;
137     void setBorderColor(const WebCore::Color&) override;
138
139     float opacity() const override;
140     void setOpacity(float) override;
141
142     void setFilters(const WebCore::FilterOperations&) override;
143     static bool filtersCanBeComposited(const WebCore::FilterOperations&);
144     void copyFiltersFrom(const WebCore::PlatformCALayer&) override;
145
146 #if ENABLE(CSS_COMPOSITING)
147     void setBlendMode(WebCore::BlendMode) override;
148 #endif
149
150     void setName(const String&) override;
151
152     void setSpeed(float) override;
153
154     void setTimeOffset(CFTimeInterval) override;
155
156     float contentsScale() const override;
157     void setContentsScale(float) override;
158
159     float cornerRadius() const override;
160     void setCornerRadius(float) override;
161
162     void setEdgeAntialiasingMask(unsigned) override;
163
164     // FIXME: Having both shapeRoundedRect and shapePath is redundant. We could use shapePath for everything.
165     WebCore::FloatRoundedRect shapeRoundedRect() const override;
166     void setShapeRoundedRect(const WebCore::FloatRoundedRect&) override;
167
168     WebCore::Path shapePath() const override;
169     void setShapePath(const WebCore::Path&) override;
170
171     WebCore::WindRule shapeWindRule() const override;
172     void setShapeWindRule(WebCore::WindRule) override;
173
174     WebCore::GraphicsLayer::CustomAppearance customAppearance() const override;
175     void updateCustomAppearance(WebCore::GraphicsLayer::CustomAppearance) override;
176
177     void setEventRegion(const WebCore::EventRegion&) override;
178
179     WebCore::GraphicsLayer::EmbeddedViewID embeddedViewID() const override;
180
181     WebCore::TiledBacking* tiledBacking() override { return nullptr; }
182
183     Ref<WebCore::PlatformCALayer> clone(WebCore::PlatformCALayerClient* owner) const override;
184
185     Ref<PlatformCALayer> createCompatibleLayer(WebCore::PlatformCALayer::LayerType, WebCore::PlatformCALayerClient*) const override;
186
187     void enumerateRectsBeingDrawn(CGContextRef, void (^block)(CGRect)) override;
188
189     virtual uint32_t hostingContextID();
190
191     unsigned backingStoreBytesPerPixel() const override;
192
193     void setClonedLayer(const PlatformCALayer*);
194
195     RemoteLayerTreeTransaction::LayerProperties& properties() { return m_properties; }
196     const RemoteLayerTreeTransaction::LayerProperties& properties() const { return m_properties; }
197
198     void didCommit();
199
200     void moveToContext(RemoteLayerTreeContext&);
201     void clearContext() { m_context = nullptr; }
202     RemoteLayerTreeContext* context() const { return m_context; }
203
204 protected:
205     PlatformCALayerRemote(WebCore::PlatformCALayer::LayerType, WebCore::PlatformCALayerClient* owner, RemoteLayerTreeContext&);
206     PlatformCALayerRemote(WebCore::PlatformCALayer::LayerType, WebCore::GraphicsLayer::EmbeddedViewID, WebCore::PlatformCALayerClient* owner, RemoteLayerTreeContext&);
207     PlatformCALayerRemote(const PlatformCALayerRemote&, WebCore::PlatformCALayerClient*, RemoteLayerTreeContext&);
208
209     void updateClonedLayerProperties(PlatformCALayerRemote& clone, bool copyContents = true) const;
210
211 private:
212     bool isPlatformCALayerRemote() const override { return true; }
213     void ensureBackingStore();
214     void updateBackingStore();
215     void removeSublayer(PlatformCALayerRemote*);
216
217     bool requiresCustomAppearanceUpdateOnBoundsChange() const;
218
219     WebCore::LayerPool& layerPool() override;
220
221     RemoteLayerTreeTransaction::LayerProperties m_properties;
222     WebCore::PlatformCALayerList m_children;
223     PlatformCALayerRemote* m_superlayer { nullptr };
224     PlatformCALayerRemote* m_maskLayer { nullptr };
225     HashMap<String, RefPtr<WebCore::PlatformCAAnimation>> m_animations;
226
227     WebCore::GraphicsLayer::EmbeddedViewID m_embeddedViewID;
228
229     bool m_acceleratesDrawing { false };
230     bool m_wantsDeepColorBackingStore { false };
231
232     RemoteLayerTreeContext* m_context;
233 };
234
235 } // namespace WebKit
236
237 SPECIALIZE_TYPE_TRAITS_PLATFORM_CALAYER(WebKit::PlatformCALayerRemote, isPlatformCALayerRemote())