OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2010 Google 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 are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 |
| 32 #ifndef LayerChromium_h |
| 33 #define LayerChromium_h |
| 34 |
| 35 #if USE(ACCELERATED_COMPOSITING) |
| 36 |
| 37 #include "FloatPoint.h" |
| 38 #include "Region.h" |
| 39 #include "RenderSurfaceChromium.h" |
| 40 #include "SkColor.h" |
| 41 #include "cc/CCLayerAnimationController.h" |
| 42 #include "cc/CCOcclusionTracker.h" |
| 43 |
| 44 #include <public/WebFilterOperations.h> |
| 45 #include <public/WebTransformationMatrix.h> |
| 46 #include <wtf/OwnPtr.h> |
| 47 #include <wtf/PassOwnPtr.h> |
| 48 #include <wtf/PassRefPtr.h> |
| 49 #include <wtf/RefCounted.h> |
| 50 #include <wtf/Vector.h> |
| 51 #include <wtf/text/StringHash.h> |
| 52 #include <wtf/text/WTFString.h> |
| 53 |
| 54 |
| 55 namespace WebCore { |
| 56 |
| 57 class CCActiveAnimation; |
| 58 struct CCAnimationEvent; |
| 59 class CCLayerAnimationDelegate; |
| 60 class CCLayerImpl; |
| 61 class CCLayerTreeHost; |
| 62 class CCTextureUpdater; |
| 63 class ScrollbarLayerChromium; |
| 64 |
| 65 // Delegate for handling scroll input for a LayerChromium. |
| 66 class LayerChromiumScrollDelegate { |
| 67 public: |
| 68 virtual void didScroll(const IntSize&) = 0; |
| 69 |
| 70 protected: |
| 71 virtual ~LayerChromiumScrollDelegate() { } |
| 72 }; |
| 73 |
| 74 // Base class for composited layers. Special layer types are derived from |
| 75 // this class. |
| 76 class LayerChromium : public RefCounted<LayerChromium>, public CCLayerAnimationC
ontrollerClient { |
| 77 public: |
| 78 static PassRefPtr<LayerChromium> create(); |
| 79 |
| 80 virtual ~LayerChromium(); |
| 81 |
| 82 // CCLayerAnimationControllerClient implementation |
| 83 virtual int id() const OVERRIDE { return m_layerId; } |
| 84 virtual void setOpacityFromAnimation(float) OVERRIDE; |
| 85 virtual float opacity() const OVERRIDE { return m_opacity; } |
| 86 virtual void setTransformFromAnimation(const WebKit::WebTransformationMatrix
&) OVERRIDE; |
| 87 // A layer's transform operates layer space. That is, entirely in logical, |
| 88 // non-page-scaled pixels (that is, they have page zoom baked in, but not pa
ge scale). |
| 89 // The root layer is a special case -- it operates in physical pixels. |
| 90 virtual const WebKit::WebTransformationMatrix& transform() const OVERRIDE {
return m_transform; } |
| 91 |
| 92 const LayerChromium* rootLayer() const; |
| 93 LayerChromium* parent() const; |
| 94 void addChild(PassRefPtr<LayerChromium>); |
| 95 void insertChild(PassRefPtr<LayerChromium>, size_t index); |
| 96 void replaceChild(LayerChromium* reference, PassRefPtr<LayerChromium> newLay
er); |
| 97 void removeFromParent(); |
| 98 void removeAllChildren(); |
| 99 void setChildren(const Vector<RefPtr<LayerChromium> >&); |
| 100 const Vector<RefPtr<LayerChromium> >& children() const { return m_children;
} |
| 101 |
| 102 void setAnchorPoint(const FloatPoint&); |
| 103 FloatPoint anchorPoint() const { return m_anchorPoint; } |
| 104 |
| 105 void setAnchorPointZ(float); |
| 106 float anchorPointZ() const { return m_anchorPointZ; } |
| 107 |
| 108 void setBackgroundColor(SkColor); |
| 109 SkColor backgroundColor() const { return m_backgroundColor; } |
| 110 |
| 111 // A layer's bounds are in logical, non-page-scaled pixels (however, the |
| 112 // root layer's bounds are in physical pixels). |
| 113 void setBounds(const IntSize&); |
| 114 const IntSize& bounds() const { return m_bounds; } |
| 115 virtual IntSize contentBounds() const { return bounds(); } |
| 116 |
| 117 void setMasksToBounds(bool); |
| 118 bool masksToBounds() const { return m_masksToBounds; } |
| 119 |
| 120 void setMaskLayer(LayerChromium*); |
| 121 LayerChromium* maskLayer() const { return m_maskLayer.get(); } |
| 122 |
| 123 virtual void setNeedsDisplayRect(const FloatRect& dirtyRect); |
| 124 void setNeedsDisplay() { setNeedsDisplayRect(FloatRect(FloatPoint(), bounds(
))); } |
| 125 virtual bool needsDisplay() const { return m_needsDisplay; } |
| 126 |
| 127 void setOpacity(float); |
| 128 bool opacityIsAnimating() const; |
| 129 |
| 130 void setFilters(const WebKit::WebFilterOperations&); |
| 131 const WebKit::WebFilterOperations& filters() { return m_filters; } |
| 132 |
| 133 // Background filters are filters applied to what is behind this layer, when
they are viewed through non-opaque |
| 134 // regions in this layer. They are used through the WebLayer interface, and
are not exposed to HTML. |
| 135 void setBackgroundFilters(const WebKit::WebFilterOperations&); |
| 136 const WebKit::WebFilterOperations& backgroundFilters() { return m_background
Filters; } |
| 137 |
| 138 virtual void setOpaque(bool); |
| 139 bool opaque() const { return m_opaque; } |
| 140 |
| 141 void setPosition(const FloatPoint&); |
| 142 FloatPoint position() const { return m_position; } |
| 143 |
| 144 void setIsContainerForFixedPositionLayers(bool); |
| 145 bool isContainerForFixedPositionLayers() const { return m_isContainerForFixe
dPositionLayers; } |
| 146 |
| 147 void setFixedToContainerLayer(bool); |
| 148 bool fixedToContainerLayer() const { return m_fixedToContainerLayer; } |
| 149 |
| 150 void setSublayerTransform(const WebKit::WebTransformationMatrix&); |
| 151 const WebKit::WebTransformationMatrix& sublayerTransform() const { return m_
sublayerTransform; } |
| 152 |
| 153 void setTransform(const WebKit::WebTransformationMatrix&); |
| 154 bool transformIsAnimating() const; |
| 155 |
| 156 const IntRect& visibleLayerRect() const { return m_visibleLayerRect; } |
| 157 void setVisibleLayerRect(const IntRect& visibleLayerRect) { m_visibleLayerRe
ct = visibleLayerRect; } |
| 158 |
| 159 const IntRect& scissorRect() const { return m_scissorRect; } |
| 160 void setScissorRect(const IntRect& scissorRect) { m_scissorRect = scissorRec
t; } |
| 161 |
| 162 void setScrollPosition(const IntPoint&); |
| 163 const IntPoint& scrollPosition() const { return m_scrollPosition; } |
| 164 |
| 165 void setMaxScrollPosition(const IntSize&); |
| 166 const IntSize& maxScrollPosition() const { return m_maxScrollPosition; } |
| 167 |
| 168 void setScrollable(bool); |
| 169 bool scrollable() const { return m_scrollable; } |
| 170 void setShouldScrollOnMainThread(bool); |
| 171 void setHaveWheelEventHandlers(bool); |
| 172 const Region& nonFastScrollableRegion() { return m_nonFastScrollableRegion;
} |
| 173 void setNonFastScrollableRegion(const Region&); |
| 174 void setNonFastScrollableRegionChanged() { m_nonFastScrollableRegionChanged
= true; } |
| 175 void setLayerScrollDelegate(LayerChromiumScrollDelegate* layerScrollDelegate
) { m_layerScrollDelegate = layerScrollDelegate; } |
| 176 void scrollBy(const IntSize&); |
| 177 |
| 178 void setDrawCheckerboardForMissingTiles(bool); |
| 179 bool drawCheckerboardForMissingTiles() const { return m_drawCheckerboardForM
issingTiles; } |
| 180 |
| 181 bool forceRenderSurface() const { return m_forceRenderSurface; } |
| 182 void setForceRenderSurface(bool); |
| 183 |
| 184 IntSize scrollDelta() const { return IntSize(); } |
| 185 |
| 186 float pageScaleDelta() const { return 1; } |
| 187 |
| 188 void setDoubleSided(bool); |
| 189 bool doubleSided() const { return m_doubleSided; } |
| 190 |
| 191 void setPreserves3D(bool preserve3D) { m_preserves3D = preserve3D; } |
| 192 bool preserves3D() const { return m_preserves3D; } |
| 193 |
| 194 void setUseParentBackfaceVisibility(bool useParentBackfaceVisibility) { m_us
eParentBackfaceVisibility = useParentBackfaceVisibility; } |
| 195 bool useParentBackfaceVisibility() const { return m_useParentBackfaceVisibil
ity; } |
| 196 |
| 197 void setUsesLayerClipping(bool usesLayerClipping) { m_usesLayerClipping = us
esLayerClipping; } |
| 198 bool usesLayerClipping() const { return m_usesLayerClipping; } |
| 199 |
| 200 virtual void setIsNonCompositedContent(bool); |
| 201 bool isNonCompositedContent() const { return m_isNonCompositedContent; } |
| 202 |
| 203 virtual void setLayerTreeHost(CCLayerTreeHost*); |
| 204 |
| 205 void setIsDrawable(bool); |
| 206 |
| 207 void setReplicaLayer(LayerChromium*); |
| 208 LayerChromium* replicaLayer() const { return m_replicaLayer.get(); } |
| 209 |
| 210 // These methods typically need to be overwritten by derived classes. |
| 211 virtual bool drawsContent() const { return m_isDrawable; } |
| 212 virtual void update(CCTextureUpdater&, const CCOcclusionTracker*) { } |
| 213 virtual void idleUpdate(CCTextureUpdater&, const CCOcclusionTracker*) { } |
| 214 virtual void setIsMask(bool) { } |
| 215 virtual void bindContentsTexture() { } |
| 216 virtual bool needsContentsScale() const { return false; } |
| 217 |
| 218 void setDebugBorderColor(SkColor); |
| 219 void setDebugBorderWidth(float); |
| 220 void setDebugName(const String&); |
| 221 |
| 222 virtual void pushPropertiesTo(CCLayerImpl*); |
| 223 |
| 224 void clearRenderSurface() { m_renderSurface.clear(); } |
| 225 RenderSurfaceChromium* renderSurface() const { return m_renderSurface.get();
} |
| 226 void createRenderSurface(); |
| 227 |
| 228 float drawOpacity() const { return m_drawOpacity; } |
| 229 void setDrawOpacity(float opacity) { m_drawOpacity = opacity; } |
| 230 |
| 231 bool drawOpacityIsAnimating() const { return m_drawOpacityIsAnimating; } |
| 232 void setDrawOpacityIsAnimating(bool drawOpacityIsAnimating) { m_drawOpacityI
sAnimating = drawOpacityIsAnimating; } |
| 233 |
| 234 const IntRect& clipRect() const { return m_clipRect; } |
| 235 void setClipRect(const IntRect& clipRect) { m_clipRect = clipRect; } |
| 236 RenderSurfaceChromium* targetRenderSurface() const { return m_targetRenderSu
rface; } |
| 237 void setTargetRenderSurface(RenderSurfaceChromium* surface) { m_targetRender
Surface = surface; } |
| 238 |
| 239 bool drawTransformIsAnimating() const { return m_drawTransformIsAnimating; } |
| 240 void setDrawTransformIsAnimating(bool animating) { m_drawTransformIsAnimatin
g = animating; } |
| 241 bool screenSpaceTransformIsAnimating() const { return m_screenSpaceTransform
IsAnimating; } |
| 242 void setScreenSpaceTransformIsAnimating(bool animating) { m_screenSpaceTrans
formIsAnimating = animating; } |
| 243 |
| 244 // This moves from layer space, with origin in the center to target space wi
th origin in the top left. |
| 245 // That is, it converts from logical, non-page-scaled, to target pixels (and
if the target is the |
| 246 // root render surface, then this converts to physical pixels). |
| 247 const WebKit::WebTransformationMatrix& drawTransform() const { return m_draw
Transform; } |
| 248 void setDrawTransform(const WebKit::WebTransformationMatrix& matrix) { m_dra
wTransform = matrix; } |
| 249 // This moves from layer space, with origin the top left to screen space wit
h origin in the top left. |
| 250 // It converts logical, non-page-scaled pixels to physical pixels. |
| 251 const WebKit::WebTransformationMatrix& screenSpaceTransform() const { return
m_screenSpaceTransform; } |
| 252 void setScreenSpaceTransform(const WebKit::WebTransformationMatrix& matrix)
{ m_screenSpaceTransform = matrix; } |
| 253 const IntRect& drawableContentRect() const { return m_drawableContentRect; } |
| 254 void setDrawableContentRect(const IntRect& rect) { m_drawableContentRect = r
ect; } |
| 255 // The contentsScale converts from logical, non-page-scaled pixels to target
pixels. |
| 256 // The contentsScale is 1 for the root layer as it is already in physical pi
xels. |
| 257 float contentsScale() const { return m_contentsScale; } |
| 258 void setContentsScale(float); |
| 259 |
| 260 // Returns true if any of the layer's descendants has content to draw. |
| 261 bool descendantDrawsContent(); |
| 262 |
| 263 CCLayerTreeHost* layerTreeHost() const { return m_layerTreeHost; } |
| 264 |
| 265 // Reserve any textures needed for this layer. |
| 266 virtual void reserveTextures() { } |
| 267 |
| 268 void setAlwaysReserveTextures(bool alwaysReserveTextures) { m_alwaysReserveT
extures = alwaysReserveTextures; } |
| 269 bool alwaysReserveTextures() const { return m_alwaysReserveTextures; } |
| 270 |
| 271 bool addAnimation(PassOwnPtr<CCActiveAnimation>); |
| 272 void pauseAnimation(int animationId, double timeOffset); |
| 273 void removeAnimation(int animationId); |
| 274 |
| 275 void suspendAnimations(double monotonicTime); |
| 276 void resumeAnimations(double monotonicTime); |
| 277 |
| 278 CCLayerAnimationController* layerAnimationController() { return m_layerAnima
tionController.get(); } |
| 279 void setLayerAnimationController(PassOwnPtr<CCLayerAnimationController>); |
| 280 PassOwnPtr<CCLayerAnimationController> releaseLayerAnimationController(); |
| 281 |
| 282 void setLayerAnimationDelegate(CCLayerAnimationDelegate* layerAnimationDeleg
ate) { m_layerAnimationDelegate = layerAnimationDelegate; } |
| 283 |
| 284 bool hasActiveAnimation() const; |
| 285 |
| 286 virtual void notifyAnimationStarted(const CCAnimationEvent&, double wallCloc
kTime); |
| 287 virtual void notifyAnimationFinished(double wallClockTime); |
| 288 |
| 289 virtual Region visibleContentOpaqueRegion() const; |
| 290 |
| 291 virtual ScrollbarLayerChromium* toScrollbarLayerChromium() { return 0; } |
| 292 |
| 293 protected: |
| 294 friend class CCLayerImpl; |
| 295 friend class TreeSynchronizer; |
| 296 |
| 297 LayerChromium(); |
| 298 |
| 299 void setNeedsCommit(); |
| 300 |
| 301 // This flag is set when layer need repainting/updating. |
| 302 bool m_needsDisplay; |
| 303 |
| 304 // Tracks whether this layer may have changed stacking order with its siblin
gs. |
| 305 bool m_stackingOrderChanged; |
| 306 |
| 307 // The update rect is the region of the compositor resource that was actuall
y updated by the compositor. |
| 308 // For layers that may do updating outside the compositor's control (i.e. pl
ugin layers), this information |
| 309 // is not available and the update rect will remain empty. |
| 310 // Note this rect is in layer space (not content space). |
| 311 FloatRect m_updateRect; |
| 312 |
| 313 RefPtr<LayerChromium> m_maskLayer; |
| 314 |
| 315 // Constructs a CCLayerImpl of the correct runtime type for this LayerChromi
um type. |
| 316 virtual PassOwnPtr<CCLayerImpl> createCCLayerImpl(); |
| 317 int m_layerId; |
| 318 |
| 319 private: |
| 320 void setParent(LayerChromium*); |
| 321 bool hasAncestor(LayerChromium*) const; |
| 322 bool descendantIsFixedToContainerLayer() const; |
| 323 |
| 324 size_t numChildren() const { return m_children.size(); } |
| 325 |
| 326 // Returns the index of the child or -1 if not found. |
| 327 int indexOfChild(const LayerChromium*); |
| 328 |
| 329 // This should only be called from removeFromParent. |
| 330 void removeChild(LayerChromium*); |
| 331 |
| 332 Vector<RefPtr<LayerChromium> > m_children; |
| 333 LayerChromium* m_parent; |
| 334 |
| 335 // LayerChromium instances have a weak pointer to their CCLayerTreeHost. |
| 336 // This pointer value is nil when a LayerChromium is not in a tree and is |
| 337 // updated via setLayerTreeHost() if a layer moves between trees. |
| 338 CCLayerTreeHost* m_layerTreeHost; |
| 339 |
| 340 OwnPtr<CCLayerAnimationController> m_layerAnimationController; |
| 341 |
| 342 // Layer properties. |
| 343 IntSize m_bounds; |
| 344 |
| 345 // Uses layer's content space. |
| 346 IntRect m_visibleLayerRect; |
| 347 |
| 348 // During drawing, identifies the region outside of which nothing should be
drawn. |
| 349 // Currently this is set to layer's clipRect if usesLayerClipping is true, o
therwise |
| 350 // it's targetRenderSurface's contentRect. |
| 351 // Uses target surface's space. |
| 352 IntRect m_scissorRect; |
| 353 IntPoint m_scrollPosition; |
| 354 IntSize m_maxScrollPosition; |
| 355 bool m_scrollable; |
| 356 bool m_shouldScrollOnMainThread; |
| 357 bool m_haveWheelEventHandlers; |
| 358 Region m_nonFastScrollableRegion; |
| 359 bool m_nonFastScrollableRegionChanged; |
| 360 FloatPoint m_position; |
| 361 FloatPoint m_anchorPoint; |
| 362 SkColor m_backgroundColor; |
| 363 SkColor m_debugBorderColor; |
| 364 float m_debugBorderWidth; |
| 365 String m_debugName; |
| 366 float m_opacity; |
| 367 WebKit::WebFilterOperations m_filters; |
| 368 WebKit::WebFilterOperations m_backgroundFilters; |
| 369 float m_anchorPointZ; |
| 370 bool m_isContainerForFixedPositionLayers; |
| 371 bool m_fixedToContainerLayer; |
| 372 bool m_isDrawable; |
| 373 bool m_masksToBounds; |
| 374 bool m_opaque; |
| 375 bool m_doubleSided; |
| 376 bool m_usesLayerClipping; |
| 377 bool m_isNonCompositedContent; |
| 378 bool m_preserves3D; |
| 379 bool m_useParentBackfaceVisibility; |
| 380 bool m_alwaysReserveTextures; |
| 381 bool m_drawCheckerboardForMissingTiles; |
| 382 bool m_forceRenderSurface; |
| 383 |
| 384 WebKit::WebTransformationMatrix m_transform; |
| 385 WebKit::WebTransformationMatrix m_sublayerTransform; |
| 386 |
| 387 // Replica layer used for reflections. |
| 388 RefPtr<LayerChromium> m_replicaLayer; |
| 389 |
| 390 // Transient properties. |
| 391 OwnPtr<RenderSurfaceChromium> m_renderSurface; |
| 392 float m_drawOpacity; |
| 393 bool m_drawOpacityIsAnimating; |
| 394 |
| 395 // Uses target surface space. |
| 396 IntRect m_clipRect; |
| 397 RenderSurfaceChromium* m_targetRenderSurface; |
| 398 WebKit::WebTransformationMatrix m_drawTransform; |
| 399 WebKit::WebTransformationMatrix m_screenSpaceTransform; |
| 400 bool m_drawTransformIsAnimating; |
| 401 bool m_screenSpaceTransformIsAnimating; |
| 402 |
| 403 // Uses target surface space. |
| 404 IntRect m_drawableContentRect; |
| 405 float m_contentsScale; |
| 406 |
| 407 CCLayerAnimationDelegate* m_layerAnimationDelegate; |
| 408 LayerChromiumScrollDelegate* m_layerScrollDelegate; |
| 409 }; |
| 410 |
| 411 void sortLayers(Vector<RefPtr<LayerChromium> >::iterator, Vector<RefPtr<LayerChr
omium> >::iterator, void*); |
| 412 |
| 413 } |
| 414 #endif // USE(ACCELERATED_COMPOSITING) |
| 415 |
| 416 #endif |
OLD | NEW |