[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
[email protected] | 0fb2500 | 2012-10-12 07:20:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 4 | |
| 5 | #ifndef CCDamageTracker_h |
| 6 | #define CCDamageTracker_h |
| 7 | |
[email protected] | 9dcbad24 | 2012-10-16 01:34:24 | [diff] [blame] | 8 | #include "base/hash_tables.h" |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame^] | 10 | #include "ui/gfx/rect_f.h" |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 11 | #include <vector> |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 12 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame^] | 13 | class SkImageFilter; |
| 14 | |
| 15 | namespace gfx { |
| 16 | class Rect; |
| 17 | } |
| 18 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 19 | namespace WebKit { |
| 20 | class WebFilterOperations; |
| 21 | } |
| 22 | |
| 23 | namespace cc { |
| 24 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 25 | class LayerImpl; |
| 26 | class RenderSurfaceImpl; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 27 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 28 | // Computes the region where pixels have actually changed on a RenderSurfaceImpl. This region is used |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 29 | // to scissor what is actually drawn to the screen to save GPU computation and bandwidth. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 30 | class DamageTracker { |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 31 | public: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 32 | static scoped_ptr<DamageTracker> create(); |
| 33 | ~DamageTracker(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 34 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame^] | 35 | void didDrawDamagedArea() { m_currentDamageRect = gfx::RectF(); } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 36 | void forceFullDamageNextUpdate() { m_forceFullDamageNextUpdate = true; } |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame^] | 37 | void updateDamageTrackingState(const std::vector<LayerImpl*>& layerList, int targetSurfaceLayerID, bool targetSurfacePropertyChangedOnlyFromDescendant, const gfx::Rect& targetSurfaceContentRect, LayerImpl* targetSurfaceMaskLayer, const WebKit::WebFilterOperations&, SkImageFilter* filter); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 38 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame^] | 39 | const gfx::RectF& currentDamageRect() { return m_currentDamageRect; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 40 | |
| 41 | private: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 42 | DamageTracker(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 43 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame^] | 44 | gfx::RectF trackDamageFromActiveLayers(const std::vector<LayerImpl*>& layerList, int targetSurfaceLayerID); |
| 45 | gfx::RectF trackDamageFromSurfaceMask(LayerImpl* targetSurfaceMaskLayer); |
| 46 | gfx::RectF trackDamageFromLeftoverRects(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 47 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame^] | 48 | gfx::RectF removeRectFromCurrentFrame(int layerID, bool& layerIsNew); |
| 49 | void saveRectForNextFrame(int layerID, const gfx::RectF& targetSpaceRect); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 50 | |
| 51 | // These helper functions are used only in trackDamageFromActiveLayers(). |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame^] | 52 | void extendDamageForLayer(LayerImpl*, gfx::RectF& targetDamageRect); |
| 53 | void extendDamageForRenderSurface(LayerImpl*, gfx::RectF& targetDamageRect); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 54 | |
| 55 | // To correctly track exposed regions, two hashtables of rects are maintained. |
| 56 | // The "current" map is used to compute exposed regions of the current frame, while |
| 57 | // the "next" map is used to collect layer rects that are used in the next frame. |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame^] | 58 | typedef base::hash_map<int, gfx::RectF> RectMap; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 59 | scoped_ptr<RectMap> m_currentRectHistory; |
| 60 | scoped_ptr<RectMap> m_nextRectHistory; |
| 61 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame^] | 62 | gfx::RectF m_currentDamageRect; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 63 | bool m_forceFullDamageNextUpdate; |
| 64 | }; |
| 65 | |
| 66 | } // namespace cc |
| 67 | |
| 68 | #endif // CCDamageTracker_h |