OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 |
| 5 |
| 6 #ifndef LayerChromium_h |
| 7 #define LayerChromium_h |
| 8 |
| 9 #if USE(ACCELERATED_COMPOSITING) |
| 10 |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "CCLayerAnimationController.h" |
| 13 #include "CCOcclusionTracker.h" |
| 14 #include "FloatPoint.h" |
| 15 #include "Region.h" |
| 16 #include "RenderSurfaceChromium.h" |
| 17 #include "SkColor.h" |
| 18 #include <public/WebFilterOperations.h> |
| 19 #include <public/WebTransformationMatrix.h> |
| 20 #include <string> |
| 21 #include <vector> |
| 22 |
| 23 namespace WebKit { |
| 24 class WebAnimationDelegate; |
| 25 class WebLayerScrollClient; |
| 26 } |
| 27 |
| 28 namespace cc { |
| 29 |
| 30 class CCActiveAnimation; |
| 31 struct CCAnimationEvent; |
| 32 class CCLayerAnimationDelegate; |
| 33 class CCLayerImpl; |
| 34 class CCLayerTreeHost; |
| 35 class CCPriorityCalculator; |
| 36 class CCTextureUpdateQueue; |
| 37 class ScrollbarLayerChromium; |
| 38 struct CCAnimationEvent; |
| 39 struct CCRenderingStats; |
| 40 |
| 41 // Base class for composited layers. Special layer types are derived from |
| 42 // this class. |
| 43 class LayerChromium : public base::RefCounted<LayerChromium>, public CCLayerAnim
ationControllerClient { |
| 44 public: |
| 45 typedef std::vector<scoped_refptr<LayerChromium> > LayerList; |
| 46 |
| 47 static scoped_refptr<LayerChromium> create(); |
| 48 |
| 49 // CCLayerAnimationControllerClient implementation |
| 50 virtual int id() const OVERRIDE; |
| 51 virtual void setOpacityFromAnimation(float) OVERRIDE; |
| 52 virtual float opacity() const OVERRIDE; |
| 53 virtual void setTransformFromAnimation(const WebKit::WebTransformationMatrix
&) OVERRIDE; |
| 54 // A layer's transform operates layer space. That is, entirely in logical, |
| 55 // non-page-scaled pixels (that is, they have page zoom baked in, but not pa
ge scale). |
| 56 // The root layer is a special case -- it operates in physical pixels. |
| 57 virtual const WebKit::WebTransformationMatrix& transform() const OVERRIDE; |
| 58 |
| 59 LayerChromium* rootLayer(); |
| 60 LayerChromium* parent() const; |
| 61 void addChild(scoped_refptr<LayerChromium>); |
| 62 void insertChild(scoped_refptr<LayerChromium>, size_t index); |
| 63 void replaceChild(LayerChromium* reference, scoped_refptr<LayerChromium> new
Layer); |
| 64 void removeFromParent(); |
| 65 void removeAllChildren(); |
| 66 void setChildren(const LayerList&); |
| 67 |
| 68 const LayerList& children() const { return m_children; } |
| 69 |
| 70 void setAnchorPoint(const FloatPoint&); |
| 71 FloatPoint anchorPoint() const { return m_anchorPoint; } |
| 72 |
| 73 void setAnchorPointZ(float); |
| 74 float anchorPointZ() const { return m_anchorPointZ; } |
| 75 |
| 76 void setBackgroundColor(SkColor); |
| 77 SkColor backgroundColor() const { return m_backgroundColor; } |
| 78 |
| 79 // A layer's bounds are in logical, non-page-scaled pixels (however, the |
| 80 // root layer's bounds are in physical pixels). |
| 81 void setBounds(const IntSize&); |
| 82 const IntSize& bounds() const { return m_bounds; } |
| 83 virtual IntSize contentBounds() const; |
| 84 |
| 85 void setMasksToBounds(bool); |
| 86 bool masksToBounds() const { return m_masksToBounds; } |
| 87 |
| 88 void setMaskLayer(LayerChromium*); |
| 89 LayerChromium* maskLayer() const { return m_maskLayer.get(); } |
| 90 |
| 91 virtual void setNeedsDisplayRect(const FloatRect& dirtyRect); |
| 92 void setNeedsDisplay() { setNeedsDisplayRect(FloatRect(FloatPoint(), bounds(
))); } |
| 93 virtual bool needsDisplay() const; |
| 94 |
| 95 void setOpacity(float); |
| 96 bool opacityIsAnimating() const; |
| 97 |
| 98 void setFilters(const WebKit::WebFilterOperations&); |
| 99 const WebKit::WebFilterOperations& filters() const { return m_filters; } |
| 100 |
| 101 // Background filters are filters applied to what is behind this layer, when
they are viewed through non-opaque |
| 102 // regions in this layer. They are used through the WebLayer interface, and
are not exposed to HTML. |
| 103 void setBackgroundFilters(const WebKit::WebFilterOperations&); |
| 104 const WebKit::WebFilterOperations& backgroundFilters() const { return m_back
groundFilters; } |
| 105 |
| 106 virtual void setContentsOpaque(bool); |
| 107 bool contentsOpaque() const { return m_contentsOpaque; } |
| 108 |
| 109 void setPosition(const FloatPoint&); |
| 110 FloatPoint position() const { return m_position; } |
| 111 |
| 112 void setIsContainerForFixedPositionLayers(bool); |
| 113 bool isContainerForFixedPositionLayers() const { return m_isContainerForFixe
dPositionLayers; } |
| 114 |
| 115 void setFixedToContainerLayer(bool); |
| 116 bool fixedToContainerLayer() const { return m_fixedToContainerLayer; } |
| 117 |
| 118 void setSublayerTransform(const WebKit::WebTransformationMatrix&); |
| 119 const WebKit::WebTransformationMatrix& sublayerTransform() const { return m_
sublayerTransform; } |
| 120 |
| 121 void setTransform(const WebKit::WebTransformationMatrix&); |
| 122 bool transformIsAnimating() const; |
| 123 |
| 124 const IntRect& visibleContentRect() const { return m_visibleContentRect; } |
| 125 void setVisibleContentRect(const IntRect& visibleContentRect) { m_visibleCon
tentRect = visibleContentRect; } |
| 126 |
| 127 void setScrollPosition(const IntPoint&); |
| 128 const IntPoint& scrollPosition() const { return m_scrollPosition; } |
| 129 |
| 130 void setMaxScrollPosition(const IntSize&); |
| 131 const IntSize& maxScrollPosition() const { return m_maxScrollPosition; } |
| 132 |
| 133 void setScrollable(bool); |
| 134 bool scrollable() const { return m_scrollable; } |
| 135 |
| 136 void setShouldScrollOnMainThread(bool); |
| 137 bool shouldScrollOnMainThread() const { return m_shouldScrollOnMainThread; } |
| 138 |
| 139 void setHaveWheelEventHandlers(bool); |
| 140 bool haveWheelEventHandlers() const { return m_haveWheelEventHandlers; } |
| 141 |
| 142 void setNonFastScrollableRegion(const Region&); |
| 143 void setNonFastScrollableRegionChanged() { m_nonFastScrollableRegionChanged
= true; } |
| 144 const Region& nonFastScrollableRegion() const { return m_nonFastScrollableRe
gion; } |
| 145 |
| 146 void setLayerScrollClient(WebKit::WebLayerScrollClient* layerScrollClient) {
m_layerScrollClient = layerScrollClient; } |
| 147 |
| 148 void setDrawCheckerboardForMissingTiles(bool); |
| 149 bool drawCheckerboardForMissingTiles() const { return m_drawCheckerboardForM
issingTiles; } |
| 150 |
| 151 bool forceRenderSurface() const { return m_forceRenderSurface; } |
| 152 void setForceRenderSurface(bool); |
| 153 |
| 154 IntSize scrollDelta() const { return IntSize(); } |
| 155 |
| 156 void setImplTransform(const WebKit::WebTransformationMatrix&); |
| 157 const WebKit::WebTransformationMatrix& implTransform() const { return m_impl
Transform; } |
| 158 |
| 159 void setDoubleSided(bool); |
| 160 bool doubleSided() const { return m_doubleSided; } |
| 161 |
| 162 void setPreserves3D(bool preserve3D) { m_preserves3D = preserve3D; } |
| 163 bool preserves3D() const { return m_preserves3D; } |
| 164 |
| 165 void setUseParentBackfaceVisibility(bool useParentBackfaceVisibility) { m_us
eParentBackfaceVisibility = useParentBackfaceVisibility; } |
| 166 bool useParentBackfaceVisibility() const { return m_useParentBackfaceVisibil
ity; } |
| 167 |
| 168 virtual void setUseLCDText(bool); |
| 169 bool useLCDText() const { return m_useLCDText; } |
| 170 |
| 171 virtual void setLayerTreeHost(CCLayerTreeHost*); |
| 172 |
| 173 bool hasContributingDelegatedRenderPasses() const { return false; } |
| 174 |
| 175 void setIsDrawable(bool); |
| 176 |
| 177 void setReplicaLayer(LayerChromium*); |
| 178 LayerChromium* replicaLayer() const { return m_replicaLayer.get(); } |
| 179 |
| 180 bool hasMask() const { return m_maskLayer; } |
| 181 bool hasReplica() const { return m_replicaLayer; } |
| 182 bool replicaHasMask() const { return m_replicaLayer && (m_maskLayer || m_rep
licaLayer->m_maskLayer); } |
| 183 |
| 184 // These methods typically need to be overwritten by derived classes. |
| 185 virtual bool drawsContent() const; |
| 186 virtual void update(CCTextureUpdateQueue&, const CCOcclusionTracker*, CCRend
eringStats&) { } |
| 187 virtual bool needMoreUpdates(); |
| 188 virtual void setIsMask(bool) { } |
| 189 virtual void bindContentsTexture() { } |
| 190 virtual bool needsContentsScale() const; |
| 191 |
| 192 void setDebugBorderColor(SkColor); |
| 193 void setDebugBorderWidth(float); |
| 194 void setDebugName(const std::string&); |
| 195 |
| 196 virtual void pushPropertiesTo(CCLayerImpl*); |
| 197 |
| 198 void clearRenderSurface() { m_renderSurface.reset(); } |
| 199 RenderSurfaceChromium* renderSurface() const { return m_renderSurface.get();
} |
| 200 void createRenderSurface(); |
| 201 |
| 202 float drawOpacity() const { return m_drawOpacity; } |
| 203 void setDrawOpacity(float opacity) { m_drawOpacity = opacity; } |
| 204 |
| 205 bool drawOpacityIsAnimating() const { return m_drawOpacityIsAnimating; } |
| 206 void setDrawOpacityIsAnimating(bool drawOpacityIsAnimating) { m_drawOpacityI
sAnimating = drawOpacityIsAnimating; } |
| 207 |
| 208 LayerChromium* renderTarget() const { ASSERT(!m_renderTarget || m_renderTarg
et->renderSurface()); return m_renderTarget; } |
| 209 void setRenderTarget(LayerChromium* target) { m_renderTarget = target; } |
| 210 |
| 211 bool drawTransformIsAnimating() const { return m_drawTransformIsAnimating; } |
| 212 void setDrawTransformIsAnimating(bool animating) { m_drawTransformIsAnimatin
g = animating; } |
| 213 bool screenSpaceTransformIsAnimating() const { return m_screenSpaceTransform
IsAnimating; } |
| 214 void setScreenSpaceTransformIsAnimating(bool animating) { m_screenSpaceTrans
formIsAnimating = animating; } |
| 215 |
| 216 // This moves from layer space, with origin in the center to target space wi
th origin in the top left. |
| 217 // That is, it converts from logical, non-page-scaled, to target pixels (and
if the target is the |
| 218 // root render surface, then this converts to physical pixels). |
| 219 const WebKit::WebTransformationMatrix& drawTransform() const { return m_draw
Transform; } |
| 220 void setDrawTransform(const WebKit::WebTransformationMatrix& matrix) { m_dra
wTransform = matrix; } |
| 221 // This moves from content space, with origin the top left to screen space w
ith origin in the top left. |
| 222 // It converts logical, non-page-scaled pixels to physical pixels. |
| 223 const WebKit::WebTransformationMatrix& screenSpaceTransform() const { return
m_screenSpaceTransform; } |
| 224 void setScreenSpaceTransform(const WebKit::WebTransformationMatrix& matrix)
{ m_screenSpaceTransform = matrix; } |
| 225 const IntRect& drawableContentRect() const { return m_drawableContentRect; } |
| 226 void setDrawableContentRect(const IntRect& rect) { m_drawableContentRect = r
ect; } |
| 227 // The contentsScale converts from logical, non-page-scaled pixels to target
pixels. |
| 228 // The contentsScale is 1 for the root layer as it is already in physical pi
xels. |
| 229 float contentsScale() const { return m_contentsScale; } |
| 230 void setContentsScale(float); |
| 231 |
| 232 // When true, the layer's contents are not scaled by the current page scale
factor. |
| 233 // setBoundsContainPageScale recursively sets the value on all child layers. |
| 234 void setBoundsContainPageScale(bool); |
| 235 bool boundsContainPageScale() const { return m_boundsContainPageScale; } |
| 236 |
| 237 // Returns true if any of the layer's descendants has content to draw. |
| 238 bool descendantDrawsContent(); |
| 239 |
| 240 CCLayerTreeHost* layerTreeHost() const { return m_layerTreeHost; } |
| 241 |
| 242 // Set the priority of all desired textures in this layer. |
| 243 virtual void setTexturePriorities(const CCPriorityCalculator&) { } |
| 244 |
| 245 bool addAnimation(scoped_ptr<CCActiveAnimation>); |
| 246 void pauseAnimation(int animationId, double timeOffset); |
| 247 void removeAnimation(int animationId); |
| 248 |
| 249 void suspendAnimations(double monotonicTime); |
| 250 void resumeAnimations(double monotonicTime); |
| 251 |
| 252 CCLayerAnimationController* layerAnimationController() { return m_layerAnima
tionController.get(); } |
| 253 void setLayerAnimationController(scoped_ptr<CCLayerAnimationController>); |
| 254 scoped_ptr<CCLayerAnimationController> releaseLayerAnimationController(); |
| 255 |
| 256 void setLayerAnimationDelegate(WebKit::WebAnimationDelegate* layerAnimationD
elegate) { m_layerAnimationDelegate = layerAnimationDelegate; } |
| 257 |
| 258 bool hasActiveAnimation() const; |
| 259 |
| 260 virtual void notifyAnimationStarted(const CCAnimationEvent&, double wallCloc
kTime); |
| 261 virtual void notifyAnimationFinished(double wallClockTime); |
| 262 |
| 263 virtual Region visibleContentOpaqueRegion() const; |
| 264 |
| 265 virtual ScrollbarLayerChromium* toScrollbarLayerChromium(); |
| 266 |
| 267 protected: |
| 268 friend class CCLayerImpl; |
| 269 friend class TreeSynchronizer; |
| 270 virtual ~LayerChromium(); |
| 271 |
| 272 LayerChromium(); |
| 273 |
| 274 void setNeedsCommit(); |
| 275 |
| 276 IntRect layerRectToContentRect(const WebKit::WebRect& layerRect); |
| 277 |
| 278 // This flag is set when layer need repainting/updating. |
| 279 bool m_needsDisplay; |
| 280 |
| 281 // Tracks whether this layer may have changed stacking order with its siblin
gs. |
| 282 bool m_stackingOrderChanged; |
| 283 |
| 284 // The update rect is the region of the compositor resource that was actuall
y updated by the compositor. |
| 285 // For layers that may do updating outside the compositor's control (i.e. pl
ugin layers), this information |
| 286 // is not available and the update rect will remain empty. |
| 287 // Note this rect is in layer space (not content space). |
| 288 FloatRect m_updateRect; |
| 289 |
| 290 scoped_refptr<LayerChromium> m_maskLayer; |
| 291 |
| 292 // Constructs a CCLayerImpl of the correct runtime type for this LayerChromi
um type. |
| 293 virtual scoped_ptr<CCLayerImpl> createCCLayerImpl(); |
| 294 int m_layerId; |
| 295 |
| 296 private: |
| 297 friend class base::RefCounted<LayerChromium>; |
| 298 |
| 299 void setParent(LayerChromium*); |
| 300 bool hasAncestor(LayerChromium*) const; |
| 301 bool descendantIsFixedToContainerLayer() const; |
| 302 |
| 303 size_t numChildren() const { return m_children.size(); } |
| 304 |
| 305 // Returns the index of the child or -1 if not found. |
| 306 int indexOfChild(const LayerChromium*); |
| 307 |
| 308 // This should only be called from removeFromParent. |
| 309 void removeChild(LayerChromium*); |
| 310 |
| 311 LayerList m_children; |
| 312 LayerChromium* m_parent; |
| 313 |
| 314 // LayerChromium instances have a weak pointer to their CCLayerTreeHost. |
| 315 // This pointer value is nil when a LayerChromium is not in a tree and is |
| 316 // updated via setLayerTreeHost() if a layer moves between trees. |
| 317 CCLayerTreeHost* m_layerTreeHost; |
| 318 |
| 319 scoped_ptr<CCLayerAnimationController> m_layerAnimationController; |
| 320 |
| 321 // Layer properties. |
| 322 IntSize m_bounds; |
| 323 |
| 324 // Uses layer's content space. |
| 325 IntRect m_visibleContentRect; |
| 326 |
| 327 IntPoint m_scrollPosition; |
| 328 IntSize m_maxScrollPosition; |
| 329 bool m_scrollable; |
| 330 bool m_shouldScrollOnMainThread; |
| 331 bool m_haveWheelEventHandlers; |
| 332 Region m_nonFastScrollableRegion; |
| 333 bool m_nonFastScrollableRegionChanged; |
| 334 FloatPoint m_position; |
| 335 FloatPoint m_anchorPoint; |
| 336 SkColor m_backgroundColor; |
| 337 SkColor m_debugBorderColor; |
| 338 float m_debugBorderWidth; |
| 339 std::string m_debugName; |
| 340 float m_opacity; |
| 341 WebKit::WebFilterOperations m_filters; |
| 342 WebKit::WebFilterOperations m_backgroundFilters; |
| 343 float m_anchorPointZ; |
| 344 bool m_isContainerForFixedPositionLayers; |
| 345 bool m_fixedToContainerLayer; |
| 346 bool m_isDrawable; |
| 347 bool m_masksToBounds; |
| 348 bool m_contentsOpaque; |
| 349 bool m_doubleSided; |
| 350 bool m_useLCDText; |
| 351 bool m_preserves3D; |
| 352 bool m_useParentBackfaceVisibility; |
| 353 bool m_drawCheckerboardForMissingTiles; |
| 354 bool m_forceRenderSurface; |
| 355 |
| 356 WebKit::WebTransformationMatrix m_transform; |
| 357 WebKit::WebTransformationMatrix m_sublayerTransform; |
| 358 |
| 359 // Replica layer used for reflections. |
| 360 scoped_refptr<LayerChromium> m_replicaLayer; |
| 361 |
| 362 // Transient properties. |
| 363 scoped_ptr<RenderSurfaceChromium> m_renderSurface; |
| 364 float m_drawOpacity; |
| 365 bool m_drawOpacityIsAnimating; |
| 366 |
| 367 LayerChromium* m_renderTarget; |
| 368 |
| 369 WebKit::WebTransformationMatrix m_drawTransform; |
| 370 WebKit::WebTransformationMatrix m_screenSpaceTransform; |
| 371 bool m_drawTransformIsAnimating; |
| 372 bool m_screenSpaceTransformIsAnimating; |
| 373 |
| 374 // Uses target surface space. |
| 375 IntRect m_drawableContentRect; |
| 376 float m_contentsScale; |
| 377 bool m_boundsContainPageScale; |
| 378 |
| 379 WebKit::WebTransformationMatrix m_implTransform; |
| 380 |
| 381 WebKit::WebAnimationDelegate* m_layerAnimationDelegate; |
| 382 WebKit::WebLayerScrollClient* m_layerScrollClient; |
| 383 }; |
| 384 |
| 385 void sortLayers(std::vector<scoped_refptr<LayerChromium> >::iterator, std::vecto
r<scoped_refptr<LayerChromium> >::iterator, void*); |
| 386 |
| 387 } |
| 388 #endif // USE(ACCELERATED_COMPOSITING) |
| 389 |
| 390 #endif |
OLD | NEW |