Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 4 |
| 5 #ifndef UI_COMPOSITOR_LAYER_H_ | 5 #ifndef UI_COMPOSITOR_LAYER_H_ |
| 6 #define UI_COMPOSITOR_LAYER_H_ | 6 #define UI_COMPOSITOR_LAYER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 // Adds |invalid_rect| to the Layer's pending invalid rect and calls | 277 // Adds |invalid_rect| to the Layer's pending invalid rect and calls |
| 278 // ScheduleDraw(). Returns false if the paint request is ignored. | 278 // ScheduleDraw(). Returns false if the paint request is ignored. |
| 279 bool SchedulePaint(const gfx::Rect& invalid_rect); | 279 bool SchedulePaint(const gfx::Rect& invalid_rect); |
| 280 | 280 |
| 281 // Schedules a redraw of the layer tree at the compositor. | 281 // Schedules a redraw of the layer tree at the compositor. |
| 282 // Note that this _does not_ invalidate any region of this layer; use | 282 // Note that this _does not_ invalidate any region of this layer; use |
| 283 // SchedulePaint() for that. | 283 // SchedulePaint() for that. |
| 284 void ScheduleDraw(); | 284 void ScheduleDraw(); |
| 285 | 285 |
| 286 // Sends damaged rectangles recorded in |damaged_region_| to | 286 // Sends damaged rectangles recorded in |damaged_region_| to |
| 287 // |compostior_| to repaint the content. | 287 // |cc_layer_| to update dirty rect. |
|
danakj
2014/01/16 19:48:29
// Uses damaged rectangles recorded in |damaged_re
simonhong
2014/01/16 20:59:59
Done.
| |
| 288 void SendDamagedRects(); | 288 void SendDamagedRects(); |
| 289 | 289 |
| 290 const SkRegion& damaged_region() const { return damaged_region_; } | 290 const SkRegion& damaged_region() const { return damaged_region_; } |
| 291 | 291 |
| 292 // Suppresses painting the content by disgarding damaged region and ignoring | 292 // Suppresses painting the content by deleting |delegate_|. |
|
danakj
2014/01/16 19:48:29
This disconnects the delegate - it doesn't delete
simonhong
2014/01/16 20:59:59
Modified to disconnecting |delegate_|.
| |
| 293 // new paint requests. | |
| 294 void SuppressPaint(); | 293 void SuppressPaint(); |
| 295 | 294 |
| 296 // Notifies the layer that the device scale factor has changed. | 295 // Notifies the layer that the device scale factor has changed. |
| 297 void OnDeviceScaleFactorChanged(float device_scale_factor); | 296 void OnDeviceScaleFactorChanged(float device_scale_factor); |
| 298 | 297 |
| 299 // Sets whether the layer should scale its content. If true, the canvas will | 298 // Sets whether the layer should scale its content. If true, the canvas will |
| 300 // be scaled in software rendering mode before it is passed to | 299 // be scaled in software rendering mode before it is passed to |
| 301 // |LayerDelegate::OnPaint|. | 300 // |LayerDelegate::OnPaintLayer|. |
| 302 // Set to false if the delegate handles scaling. | 301 // Set to false if the delegate handles scaling. |
| 303 // NOTE: if this is called during |LayerDelegate::OnPaint|, the new value will | 302 // NOTE: if this is called during |LayerDelegate::OnPaint|, the new value will |
| 304 // not apply to the canvas passed to the pending draw. | 303 // not apply to the canvas passed to the pending draw. |
| 305 void set_scale_content(bool scale_content) { scale_content_ = scale_content; } | 304 void set_scale_content(bool scale_content) { scale_content_ = scale_content; } |
| 306 | 305 |
| 307 // Returns true if the layer scales its content. | 306 // Returns true if the layer scales its content. |
| 308 bool scale_content() const { return scale_content_; } | 307 bool scale_content() const { return scale_content_; } |
| 309 | 308 |
| 310 // Sometimes the Layer is being updated by something other than SetCanvas | |
| 311 // (e.g. the GPU process on UI_COMPOSITOR_IMAGE_TRANSPORT). | |
| 312 bool layer_updated_externally() const { return layer_updated_externally_; } | |
| 313 | |
| 314 // Requets a copy of the layer's output as a texture or bitmap. | 309 // Requets a copy of the layer's output as a texture or bitmap. |
| 315 void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request); | 310 void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request); |
| 316 | 311 |
| 317 // ContentLayerClient | 312 // ContentLayerClient |
| 318 virtual void PaintContents( | 313 virtual void PaintContents( |
| 319 SkCanvas* canvas, const gfx::Rect& clip, gfx::RectF* opaque) OVERRIDE; | 314 SkCanvas* canvas, const gfx::Rect& clip, gfx::RectF* opaque) OVERRIDE; |
| 320 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} | 315 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} |
| 321 | 316 |
| 322 cc::Layer* cc_layer() { return cc_layer_; } | 317 cc::Layer* cc_layer() { return cc_layer_; } |
| 323 | 318 |
| 324 // TextureLayerClient | 319 // TextureLayerClient |
| 325 virtual unsigned PrepareTexture() OVERRIDE; | 320 virtual unsigned PrepareTexture() OVERRIDE; |
| 326 virtual bool PrepareTextureMailbox( | 321 virtual bool PrepareTextureMailbox( |
| 327 cc::TextureMailbox* mailbox, | 322 cc::TextureMailbox* mailbox, |
| 328 scoped_ptr<cc::SingleReleaseCallback>* release_callback, | 323 scoped_ptr<cc::SingleReleaseCallback>* release_callback, |
| 329 bool use_shared_memory) OVERRIDE; | 324 bool use_shared_memory) OVERRIDE; |
| 330 | 325 |
| 331 float device_scale_factor() const { return device_scale_factor_; } | 326 float device_scale_factor() const { return device_scale_factor_; } |
| 332 | 327 |
| 333 // Forces a render surface to be used on this layer. This has no positive | 328 // Forces a render surface to be used on this layer. This has no positive |
| 334 // impact, and is only used for benchmarking/testing purpose. | 329 // impact, and is only used for benchmarking/testing purpose. |
| 335 void SetForceRenderSurface(bool force); | 330 void SetForceRenderSurface(bool force); |
| 336 bool force_render_surface() const { return force_render_surface_; } | 331 bool force_render_surface() const { return force_render_surface_; } |
| 337 | 332 |
| 338 // LayerClient | 333 // LayerClient |
| 339 virtual std::string DebugName() OVERRIDE; | 334 virtual std::string DebugName() OVERRIDE; |
| 340 | |
| 341 virtual scoped_refptr<base::debug::ConvertableToTraceFormat> | 335 virtual scoped_refptr<base::debug::ConvertableToTraceFormat> |
| 342 TakeDebugInfo() OVERRIDE; | 336 TakeDebugInfo() OVERRIDE; |
| 343 | 337 |
| 344 // LayerAnimationEventObserver | 338 // LayerAnimationEventObserver |
| 345 virtual void OnAnimationStarted(const cc::AnimationEvent& event) OVERRIDE; | 339 virtual void OnAnimationStarted(const cc::AnimationEvent& event) OVERRIDE; |
| 346 | 340 |
| 347 // Whether this layer has animations waiting to get sent to its cc::Layer. | 341 // Whether this layer has animations waiting to get sent to its cc::Layer. |
| 348 bool HasPendingThreadedAnimations() { | 342 bool HasPendingThreadedAnimations() { |
| 349 return pending_threaded_animations_.size() != 0; | 343 return pending_threaded_animations_.size() != 0; |
| 350 } | 344 } |
| 351 | 345 |
| 352 // Triggers a call to SwitchToLayer. | 346 // Triggers a call to SwitchToLayer. |
| 353 void SwitchCCLayerForTest(); | 347 void SwitchCCLayerForTest(); |
| 354 | 348 |
| 355 private: | 349 private: |
| 356 // Stacks |child| above or below |other|. Helper method for StackAbove() and | 350 // Stacks |child| above or below |other|. Helper method for StackAbove() and |
| 357 // StackBelow(). | 351 // StackBelow(). |
| 358 void StackRelativeTo(Layer* child, Layer* other, bool above); | 352 void StackRelativeTo(Layer* child, Layer* other, bool above); |
| 359 | 353 |
| 360 bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const; | 354 bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const; |
| 361 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; | 355 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; |
| 362 | 356 |
| 363 // Following are invoked from the animation or if no animation exists to | |
| 364 // update the values immediately. | |
| 365 void SetBoundsImmediately(const gfx::Rect& bounds); | |
| 366 void SetTransformImmediately(const gfx::Transform& transform); | |
| 367 void SetOpacityImmediately(float opacity); | |
| 368 void SetVisibilityImmediately(bool visibility); | |
| 369 void SetBrightnessImmediately(float brightness); | |
| 370 void SetGrayscaleImmediately(float grayscale); | |
| 371 void SetColorImmediately(SkColor color); | |
| 372 | |
| 373 // Implementation of LayerAnimatorDelegate | 357 // Implementation of LayerAnimatorDelegate |
| 374 virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE; | 358 virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE; |
| 375 virtual void SetTransformFromAnimation( | 359 virtual void SetTransformFromAnimation( |
| 376 const gfx::Transform& transform) OVERRIDE; | 360 const gfx::Transform& transform) OVERRIDE; |
| 377 virtual void SetOpacityFromAnimation(float opacity) OVERRIDE; | 361 virtual void SetOpacityFromAnimation(float opacity) OVERRIDE; |
| 378 virtual void SetVisibilityFromAnimation(bool visibility) OVERRIDE; | 362 virtual void SetVisibilityFromAnimation(bool visibility) OVERRIDE; |
| 379 virtual void SetBrightnessFromAnimation(float brightness) OVERRIDE; | 363 virtual void SetBrightnessFromAnimation(float brightness) OVERRIDE; |
| 380 virtual void SetGrayscaleFromAnimation(float grayscale) OVERRIDE; | 364 virtual void SetGrayscaleFromAnimation(float grayscale) OVERRIDE; |
| 381 virtual void SetColorFromAnimation(SkColor color) OVERRIDE; | 365 virtual void SetColorFromAnimation(SkColor color) OVERRIDE; |
| 382 virtual void ScheduleDrawForAnimation() OVERRIDE; | 366 virtual void ScheduleDrawForAnimation() OVERRIDE; |
| 383 virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE; | 367 virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE; |
| 384 virtual gfx::Transform GetTransformForAnimation() const OVERRIDE; | 368 virtual gfx::Transform GetTransformForAnimation() const OVERRIDE; |
| 385 virtual float GetOpacityForAnimation() const OVERRIDE; | 369 virtual float GetOpacityForAnimation() const OVERRIDE; |
| 386 virtual bool GetVisibilityForAnimation() const OVERRIDE; | 370 virtual bool GetVisibilityForAnimation() const OVERRIDE; |
| 387 virtual float GetBrightnessForAnimation() const OVERRIDE; | 371 virtual float GetBrightnessForAnimation() const OVERRIDE; |
| 388 virtual float GetGrayscaleForAnimation() const OVERRIDE; | 372 virtual float GetGrayscaleForAnimation() const OVERRIDE; |
| 389 virtual SkColor GetColorForAnimation() const OVERRIDE; | 373 virtual SkColor GetColorForAnimation() const OVERRIDE; |
| 390 virtual float GetDeviceScaleFactor() const OVERRIDE; | 374 virtual float GetDeviceScaleFactor() const OVERRIDE; |
| 391 virtual void AddThreadedAnimation( | 375 virtual void AddThreadedAnimation( |
| 392 scoped_ptr<cc::Animation> animation) OVERRIDE; | 376 scoped_ptr<cc::Animation> animation) OVERRIDE; |
| 393 virtual void RemoveThreadedAnimation(int animation_id) OVERRIDE; | 377 virtual void RemoveThreadedAnimation(int animation_id) OVERRIDE; |
| 394 | 378 |
| 379 // Creates a corresponding composited layer for |type_|. | |
| 395 void CreateWebLayer(); | 380 void CreateWebLayer(); |
| 381 | |
| 382 // Recomputes and sets to |cc_layer_|. | |
| 396 void RecomputeCCTransformFromTransform(const gfx::Transform& transform); | 383 void RecomputeCCTransformFromTransform(const gfx::Transform& transform); |
| 397 void RecomputeDrawsContentAndUVRect(); | 384 void RecomputeDrawsContentAndUVRect(); |
| 398 void RecomputePosition(); | 385 void RecomputePosition(); |
| 399 | 386 |
| 400 // Set all filters which got applied to the layer. | 387 // Set all filters which got applied to the layer. |
| 401 void SetLayerFilters(); | 388 void SetLayerFilters(); |
| 402 | 389 |
| 403 // Set all filters which got applied to the layer background. | 390 // Set all filters which got applied to the layer background. |
| 404 void SetLayerBackgroundFilters(); | 391 void SetLayerBackgroundFilters(); |
| 405 | 392 |
| 406 void UpdateIsDrawn(); | 393 // Cleanup |cc_layer_| and replaces it with |new_layer|. |
| 407 | |
| 408 void SwitchToLayer(scoped_refptr<cc::Layer> new_layer); | 394 void SwitchToLayer(scoped_refptr<cc::Layer> new_layer); |
| 409 | 395 |
| 410 // We cannot send animations to our cc_layer_ until we have been added to a | 396 // We cannot send animations to our cc_layer_ until we have been added to a |
| 411 // layer tree. Instead, we hold on to these animations in | 397 // layer tree. Instead, we hold on to these animations in |
| 412 // pending_threaded_animations_, and expect SendPendingThreadedAnimations to | 398 // pending_threaded_animations_, and expect SendPendingThreadedAnimations to |
| 413 // be called once we have been added to a tree. | 399 // be called once we have been added to a tree. |
| 414 void SendPendingThreadedAnimations(); | 400 void SendPendingThreadedAnimations(); |
| 415 | 401 |
| 416 const LayerType type_; | 402 const LayerType type_; |
| 417 | 403 |
| 418 Compositor* compositor_; | 404 Compositor* compositor_; |
| 419 | 405 |
| 420 scoped_refptr<ui::Texture> texture_; | 406 scoped_refptr<ui::Texture> texture_; |
| 421 | 407 |
| 422 Layer* parent_; | 408 Layer* parent_; |
| 423 | 409 |
| 424 // This layer's children, in bottom-to-top stacking order. | 410 // This layer's children, in bottom-to-top stacking order. |
| 425 std::vector<Layer*> children_; | 411 std::vector<Layer*> children_; |
| 426 | 412 |
| 427 gfx::Rect bounds_; | 413 gfx::Rect bounds_; |
| 428 | 414 |
| 429 // Visibility of this layer. See SetVisible/IsDrawn for more details. | 415 // Visibility of this layer. See SetVisible/IsDrawn for more details. |
| 430 bool visible_; | 416 bool visible_; |
| 431 | 417 |
| 418 // See SetForceRenderSurface() for more details. | |
|
danakj
2014/01/16 19:48:29
Is this really needed?
simonhong
2014/01/16 20:59:59
No.. I think it's redundant. Removed.
| |
| 432 bool force_render_surface_; | 419 bool force_render_surface_; |
| 433 | 420 |
| 434 bool fills_bounds_opaquely_; | 421 bool fills_bounds_opaquely_; |
| 435 | 422 |
| 436 // If true the layer is always up to date. | |
| 437 bool layer_updated_externally_; | |
| 438 | |
| 439 // Union of damaged rects, in pixel coordinates, to be used when | 423 // Union of damaged rects, in pixel coordinates, to be used when |
| 440 // compositor is ready to paint the content. | 424 // compositor is ready to paint the content. |
| 441 SkRegion damaged_region_; | 425 SkRegion damaged_region_; |
| 442 | 426 |
| 443 int background_blur_radius_; | 427 int background_blur_radius_; |
| 444 | 428 |
| 445 // Several variables which will change the visible representation of | 429 // Several variables which will change the visible representation of |
| 446 // the layer. | 430 // the layer. |
| 447 float layer_saturation_; | 431 float layer_saturation_; |
| 448 float layer_brightness_; | 432 float layer_brightness_; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 // The size of the delegated frame in DIP, set when SetShowDelegatedContent | 481 // The size of the delegated frame in DIP, set when SetShowDelegatedContent |
| 498 // was called. | 482 // was called. |
| 499 gfx::Size delegated_frame_size_in_dip_; | 483 gfx::Size delegated_frame_size_in_dip_; |
| 500 | 484 |
| 501 DISALLOW_COPY_AND_ASSIGN(Layer); | 485 DISALLOW_COPY_AND_ASSIGN(Layer); |
| 502 }; | 486 }; |
| 503 | 487 |
| 504 } // namespace ui | 488 } // namespace ui |
| 505 | 489 |
| 506 #endif // UI_COMPOSITOR_LAYER_H_ | 490 #endif // UI_COMPOSITOR_LAYER_H_ |
| OLD | NEW |