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#ifndef PlatformCALayerRemote_h
27#define PlatformCALayerRemote_h
28
29#include "RemoteLayerTreeTransaction.h"
30#include <WebCore/PlatformCALayer.h>
31#include <WebCore/PlatformLayer.h>
32#include <WebCore/TileController.h>
33
34namespace WebCore {
35class LayerPool;
36}
37
38namespace WebKit {
39
40class RemoteLayerTreeContext;
41
42class PlatformCALayerRemote : public WebCore::PlatformCALayer {
43public:
44    static PassRefPtr<PlatformCALayerRemote> create(WebCore::PlatformCALayer::LayerType, WebCore::PlatformCALayerClient*, RemoteLayerTreeContext&);
45    static PassRefPtr<PlatformCALayerRemote> create(PlatformLayer *, WebCore::PlatformCALayerClient*, RemoteLayerTreeContext&);
46    static PassRefPtr<PlatformCALayerRemote> create(const PlatformCALayerRemote&, WebCore::PlatformCALayerClient*, RemoteLayerTreeContext&);
47
48    virtual ~PlatformCALayerRemote();
49
50    virtual PlatformLayer* platformLayer() const override { return nullptr; }
51
52    void recursiveBuildTransaction(RemoteLayerTreeContext&, RemoteLayerTreeTransaction&);
53
54    virtual void setNeedsDisplay(const WebCore::FloatRect* dirtyRect = 0) override;
55
56    virtual void copyContentsFromLayer(PlatformCALayer*) override;
57
58    virtual WebCore::PlatformCALayer* superlayer() const override;
59    virtual void removeFromSuperlayer() override;
60    virtual void setSublayers(const WebCore::PlatformCALayerList&) override;
61    virtual void removeAllSublayers() override;
62    virtual void appendSublayer(WebCore::PlatformCALayer*) override;
63    virtual void insertSublayer(WebCore::PlatformCALayer*, size_t index) override;
64    virtual void replaceSublayer(WebCore::PlatformCALayer* reference, WebCore::PlatformCALayer*) override;
65    virtual const WebCore::PlatformCALayerList* customSublayers() const override { return nullptr; }
66    virtual void adoptSublayers(WebCore::PlatformCALayer* source) override;
67
68    virtual void addAnimationForKey(const String& key, WebCore::PlatformCAAnimation*) override;
69    virtual void removeAnimationForKey(const String& key) override;
70    virtual PassRefPtr<WebCore::PlatformCAAnimation> animationForKey(const String& key) override;
71    virtual void animationStarted(const String& key, CFTimeInterval beginTime) override;
72
73    virtual void setMask(WebCore::PlatformCALayer*) override;
74
75    virtual bool isOpaque() const override;
76    virtual void setOpaque(bool) override;
77
78    virtual WebCore::FloatRect bounds() const override;
79    virtual void setBounds(const WebCore::FloatRect&) override;
80
81    virtual WebCore::FloatPoint3D position() const override;
82    virtual void setPosition(const WebCore::FloatPoint3D&) override;
83
84    virtual WebCore::FloatPoint3D anchorPoint() const override;
85    virtual void setAnchorPoint(const WebCore::FloatPoint3D&) override;
86
87    virtual WebCore::TransformationMatrix transform() const override;
88    virtual void setTransform(const WebCore::TransformationMatrix&) override;
89
90    virtual WebCore::TransformationMatrix sublayerTransform() const override;
91    virtual void setSublayerTransform(const WebCore::TransformationMatrix&) override;
92
93    virtual void setHidden(bool) override;
94
95    virtual void setGeometryFlipped(bool) override;
96
97    virtual bool isDoubleSided() const override;
98    virtual void setDoubleSided(bool) override;
99
100    virtual bool masksToBounds() const override;
101    virtual void setMasksToBounds(bool) override;
102
103    virtual bool acceleratesDrawing() const override;
104    virtual void setAcceleratesDrawing(bool) override;
105
106    virtual CFTypeRef contents() const override;
107    virtual void setContents(CFTypeRef) override;
108
109    virtual void setContentsRect(const WebCore::FloatRect&) override;
110
111    virtual void setMinificationFilter(WebCore::PlatformCALayer::FilterType) override;
112    virtual void setMagnificationFilter(WebCore::PlatformCALayer::FilterType) override;
113
114    virtual WebCore::Color backgroundColor() const override;
115    virtual void setBackgroundColor(const WebCore::Color&) override;
116
117    virtual void setBorderWidth(float) override;
118    virtual void setBorderColor(const WebCore::Color&) override;
119
120    virtual float opacity() const override;
121    virtual void setOpacity(float) override;
122
123#if ENABLE(CSS_FILTERS)
124    virtual void setFilters(const WebCore::FilterOperations&) override;
125    static bool filtersCanBeComposited(const WebCore::FilterOperations&);
126    virtual void copyFiltersFrom(const WebCore::PlatformCALayer*) override;
127#endif
128
129#if ENABLE(CSS_COMPOSITING)
130    virtual void setBlendMode(WebCore::BlendMode) override;
131#endif
132
133    virtual void setName(const String&) override;
134
135    virtual void setSpeed(float) override;
136
137    virtual void setTimeOffset(CFTimeInterval) override;
138
139    virtual float contentsScale() const override;
140    virtual void setContentsScale(float) override;
141
142    virtual void setEdgeAntialiasingMask(unsigned) override;
143
144    virtual WebCore::GraphicsLayer::CustomAppearance customAppearance() const override;
145    virtual void updateCustomAppearance(WebCore::GraphicsLayer::CustomAppearance) override;
146
147    virtual WebCore::GraphicsLayer::CustomBehavior customBehavior() const override;
148    virtual void updateCustomBehavior(WebCore::GraphicsLayer::CustomBehavior) override;
149
150    virtual WebCore::TiledBacking* tiledBacking() override { return nullptr; }
151
152    virtual PassRefPtr<WebCore::PlatformCALayer> clone(WebCore::PlatformCALayerClient* owner) const override;
153
154    virtual PassRefPtr<PlatformCALayer> createCompatibleLayer(WebCore::PlatformCALayer::LayerType, WebCore::PlatformCALayerClient*) const override;
155
156    virtual void enumerateRectsBeingDrawn(CGContextRef, void (^block)(CGRect)) override;
157
158    virtual uint32_t hostingContextID();
159
160    void setClonedLayer(const PlatformCALayer*);
161
162    RemoteLayerTreeTransaction::LayerProperties& properties() { return m_properties; }
163    const RemoteLayerTreeTransaction::LayerProperties& properties() const { return m_properties; }
164
165    void didCommit();
166
167    void clearContext() { m_context = nullptr; }
168    RemoteLayerTreeContext* context() const { return m_context; }
169
170protected:
171    PlatformCALayerRemote(WebCore::PlatformCALayer::LayerType, WebCore::PlatformCALayerClient* owner, RemoteLayerTreeContext& context);
172    PlatformCALayerRemote(const PlatformCALayerRemote&, WebCore::PlatformCALayerClient*, RemoteLayerTreeContext&);
173
174    void updateClonedLayerProperties(PlatformCALayerRemote& clone, bool copyContents = true) const;
175
176private:
177    virtual bool isPlatformCALayerRemote() const override { return true; }
178    void ensureBackingStore();
179    void updateBackingStore();
180    void removeSublayer(PlatformCALayerRemote*);
181
182    bool requiresCustomAppearanceUpdateOnBoundsChange() const;
183
184    virtual WebCore::LayerPool& layerPool() override;
185
186    RemoteLayerTreeTransaction::LayerProperties m_properties;
187    WebCore::PlatformCALayerList m_children;
188    PlatformCALayerRemote* m_superlayer;
189    PlatformCALayerRemote* m_maskLayer;
190    HashMap<String, RefPtr<WebCore::PlatformCAAnimation>> m_animations;
191    bool m_acceleratesDrawing;
192
193    RemoteLayerTreeContext* m_context;
194};
195
196PLATFORM_CALAYER_TYPE_CASTS(PlatformCALayerRemote, isPlatformCALayerRemote())
197
198} // namespace WebKit
199
200#endif // PlatformCALayerRemote_h
201