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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 276 |
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 // Uses damaged rectangles recorded in |damaged_region_| to invalidate the |
287 // |compostior_| to repaint the content. | 287 // |cc_layer_|. |
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 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 |
(...skipping 27 matching lines...) Expand all Loading... |
351 void SwitchCCLayerForTest(); | 346 void SwitchCCLayerForTest(); |
352 | 347 |
353 private: | 348 private: |
354 // Stacks |child| above or below |other|. Helper method for StackAbove() and | 349 // Stacks |child| above or below |other|. Helper method for StackAbove() and |
355 // StackBelow(). | 350 // StackBelow(). |
356 void StackRelativeTo(Layer* child, Layer* other, bool above); | 351 void StackRelativeTo(Layer* child, Layer* other, bool above); |
357 | 352 |
358 bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const; | 353 bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const; |
359 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; | 354 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; |
360 | 355 |
361 // Following are invoked from the animation or if no animation exists to | |
362 // update the values immediately. | |
363 void SetBoundsImmediately(const gfx::Rect& bounds); | |
364 void SetTransformImmediately(const gfx::Transform& transform); | |
365 void SetOpacityImmediately(float opacity); | |
366 void SetVisibilityImmediately(bool visibility); | |
367 void SetBrightnessImmediately(float brightness); | |
368 void SetGrayscaleImmediately(float grayscale); | |
369 void SetColorImmediately(SkColor color); | |
370 | |
371 // Implementation of LayerAnimatorDelegate | 356 // Implementation of LayerAnimatorDelegate |
372 virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE; | 357 virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE; |
373 virtual void SetTransformFromAnimation( | 358 virtual void SetTransformFromAnimation( |
374 const gfx::Transform& transform) OVERRIDE; | 359 const gfx::Transform& transform) OVERRIDE; |
375 virtual void SetOpacityFromAnimation(float opacity) OVERRIDE; | 360 virtual void SetOpacityFromAnimation(float opacity) OVERRIDE; |
376 virtual void SetVisibilityFromAnimation(bool visibility) OVERRIDE; | 361 virtual void SetVisibilityFromAnimation(bool visibility) OVERRIDE; |
377 virtual void SetBrightnessFromAnimation(float brightness) OVERRIDE; | 362 virtual void SetBrightnessFromAnimation(float brightness) OVERRIDE; |
378 virtual void SetGrayscaleFromAnimation(float grayscale) OVERRIDE; | 363 virtual void SetGrayscaleFromAnimation(float grayscale) OVERRIDE; |
379 virtual void SetColorFromAnimation(SkColor color) OVERRIDE; | 364 virtual void SetColorFromAnimation(SkColor color) OVERRIDE; |
380 virtual void ScheduleDrawForAnimation() OVERRIDE; | 365 virtual void ScheduleDrawForAnimation() OVERRIDE; |
381 virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE; | 366 virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE; |
382 virtual gfx::Transform GetTransformForAnimation() const OVERRIDE; | 367 virtual gfx::Transform GetTransformForAnimation() const OVERRIDE; |
383 virtual float GetOpacityForAnimation() const OVERRIDE; | 368 virtual float GetOpacityForAnimation() const OVERRIDE; |
384 virtual bool GetVisibilityForAnimation() const OVERRIDE; | 369 virtual bool GetVisibilityForAnimation() const OVERRIDE; |
385 virtual float GetBrightnessForAnimation() const OVERRIDE; | 370 virtual float GetBrightnessForAnimation() const OVERRIDE; |
386 virtual float GetGrayscaleForAnimation() const OVERRIDE; | 371 virtual float GetGrayscaleForAnimation() const OVERRIDE; |
387 virtual SkColor GetColorForAnimation() const OVERRIDE; | 372 virtual SkColor GetColorForAnimation() const OVERRIDE; |
388 virtual float GetDeviceScaleFactor() const OVERRIDE; | 373 virtual float GetDeviceScaleFactor() const OVERRIDE; |
389 virtual void AddThreadedAnimation( | 374 virtual void AddThreadedAnimation( |
390 scoped_ptr<cc::Animation> animation) OVERRIDE; | 375 scoped_ptr<cc::Animation> animation) OVERRIDE; |
391 virtual void RemoveThreadedAnimation(int animation_id) OVERRIDE; | 376 virtual void RemoveThreadedAnimation(int animation_id) OVERRIDE; |
392 | 377 |
| 378 // Creates a corresponding composited layer for |type_|. |
393 void CreateWebLayer(); | 379 void CreateWebLayer(); |
| 380 |
| 381 // Recomputes and sets to |cc_layer_|. |
394 void RecomputeCCTransformFromTransform(const gfx::Transform& transform); | 382 void RecomputeCCTransformFromTransform(const gfx::Transform& transform); |
395 void RecomputeDrawsContentAndUVRect(); | 383 void RecomputeDrawsContentAndUVRect(); |
396 void RecomputePosition(); | 384 void RecomputePosition(); |
397 | 385 |
398 // Set all filters which got applied to the layer. | 386 // Set all filters which got applied to the layer. |
399 void SetLayerFilters(); | 387 void SetLayerFilters(); |
400 | 388 |
401 // Set all filters which got applied to the layer background. | 389 // Set all filters which got applied to the layer background. |
402 void SetLayerBackgroundFilters(); | 390 void SetLayerBackgroundFilters(); |
403 | 391 |
404 void UpdateIsDrawn(); | 392 // Cleanup |cc_layer_| and replaces it with |new_layer|. |
405 | |
406 void SwitchToLayer(scoped_refptr<cc::Layer> new_layer); | 393 void SwitchToLayer(scoped_refptr<cc::Layer> new_layer); |
407 | 394 |
408 // We cannot send animations to our cc_layer_ until we have been added to a | 395 // We cannot send animations to our cc_layer_ until we have been added to a |
409 // layer tree. Instead, we hold on to these animations in | 396 // layer tree. Instead, we hold on to these animations in |
410 // pending_threaded_animations_, and expect SendPendingThreadedAnimations to | 397 // pending_threaded_animations_, and expect SendPendingThreadedAnimations to |
411 // be called once we have been added to a tree. | 398 // be called once we have been added to a tree. |
412 void SendPendingThreadedAnimations(); | 399 void SendPendingThreadedAnimations(); |
413 | 400 |
414 const LayerType type_; | 401 const LayerType type_; |
415 | 402 |
416 Compositor* compositor_; | 403 Compositor* compositor_; |
417 | 404 |
418 scoped_refptr<ui::Texture> texture_; | 405 scoped_refptr<ui::Texture> texture_; |
419 | 406 |
420 Layer* parent_; | 407 Layer* parent_; |
421 | 408 |
422 // This layer's children, in bottom-to-top stacking order. | 409 // This layer's children, in bottom-to-top stacking order. |
423 std::vector<Layer*> children_; | 410 std::vector<Layer*> children_; |
424 | 411 |
425 gfx::Rect bounds_; | 412 gfx::Rect bounds_; |
426 | 413 |
427 // Visibility of this layer. See SetVisible/IsDrawn for more details. | 414 // Visibility of this layer. See SetVisible/IsDrawn for more details. |
428 bool visible_; | 415 bool visible_; |
429 | 416 |
430 bool force_render_surface_; | 417 bool force_render_surface_; |
431 | 418 |
432 bool fills_bounds_opaquely_; | 419 bool fills_bounds_opaquely_; |
433 | 420 |
434 // If true the layer is always up to date. | |
435 bool layer_updated_externally_; | |
436 | |
437 // Union of damaged rects, in pixel coordinates, to be used when | 421 // Union of damaged rects, in pixel coordinates, to be used when |
438 // compositor is ready to paint the content. | 422 // compositor is ready to paint the content. |
439 SkRegion damaged_region_; | 423 SkRegion damaged_region_; |
440 | 424 |
441 int background_blur_radius_; | 425 int background_blur_radius_; |
442 | 426 |
443 // Several variables which will change the visible representation of | 427 // Several variables which will change the visible representation of |
444 // the layer. | 428 // the layer. |
445 float layer_saturation_; | 429 float layer_saturation_; |
446 float layer_brightness_; | 430 float layer_brightness_; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 // The size of the delegated frame in DIP, set when SetShowDelegatedContent | 479 // The size of the delegated frame in DIP, set when SetShowDelegatedContent |
496 // was called. | 480 // was called. |
497 gfx::Size delegated_frame_size_in_dip_; | 481 gfx::Size delegated_frame_size_in_dip_; |
498 | 482 |
499 DISALLOW_COPY_AND_ASSIGN(Layer); | 483 DISALLOW_COPY_AND_ASSIGN(Layer); |
500 }; | 484 }; |
501 | 485 |
502 } // namespace ui | 486 } // namespace ui |
503 | 487 |
504 #endif // UI_COMPOSITOR_LAYER_H_ | 488 #endif // UI_COMPOSITOR_LAYER_H_ |
OLD | NEW |