[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" |
| 10 | #include "FloatRect.h" |
| 11 | #include <vector> |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 12 | |
| 13 | namespace WebKit { |
| 14 | class WebFilterOperations; |
| 15 | } |
| 16 | |
| 17 | namespace cc { |
| 18 | |
| 19 | class CCLayerImpl; |
| 20 | class CCRenderSurface; |
| 21 | |
| 22 | // Computes the region where pixels have actually changed on a RenderSurface. This region is used |
| 23 | // to scissor what is actually drawn to the screen to save GPU computation and bandwidth. |
| 24 | class CCDamageTracker { |
| 25 | public: |
| 26 | static scoped_ptr<CCDamageTracker> create(); |
| 27 | ~CCDamageTracker(); |
| 28 | |
| 29 | void didDrawDamagedArea() { m_currentDamageRect = FloatRect(); } |
| 30 | void forceFullDamageNextUpdate() { m_forceFullDamageNextUpdate = true; } |
| 31 | void updateDamageTrackingState(const std::vector<CCLayerImpl*>& layerList, int targetSurfaceLayerID, bool targetSurfacePropertyChangedOnlyFromDescendant, const IntRect& targetSurfaceContentRect, CCLayerImpl* targetSurfaceMaskLayer, const WebKit::WebFilterOperations&); |
| 32 | |
| 33 | const FloatRect& currentDamageRect() { return m_currentDamageRect; } |
| 34 | |
| 35 | private: |
| 36 | CCDamageTracker(); |
| 37 | |
| 38 | FloatRect trackDamageFromActiveLayers(const std::vector<CCLayerImpl*>& layerList, int targetSurfaceLayerID); |
| 39 | FloatRect trackDamageFromSurfaceMask(CCLayerImpl* targetSurfaceMaskLayer); |
| 40 | FloatRect trackDamageFromLeftoverRects(); |
| 41 | |
| 42 | FloatRect removeRectFromCurrentFrame(int layerID, bool& layerIsNew); |
| 43 | void saveRectForNextFrame(int layerID, const FloatRect& targetSpaceRect); |
| 44 | |
| 45 | // These helper functions are used only in trackDamageFromActiveLayers(). |
| 46 | void extendDamageForLayer(CCLayerImpl*, FloatRect& targetDamageRect); |
| 47 | void extendDamageForRenderSurface(CCLayerImpl*, FloatRect& targetDamageRect); |
| 48 | |
| 49 | // To correctly track exposed regions, two hashtables of rects are maintained. |
| 50 | // The "current" map is used to compute exposed regions of the current frame, while |
| 51 | // the "next" map is used to collect layer rects that are used in the next frame. |
[email protected] | 9dcbad24 | 2012-10-16 01:34:24 | [diff] [blame^] | 52 | typedef base::hash_map<int, FloatRect> RectMap; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 53 | scoped_ptr<RectMap> m_currentRectHistory; |
| 54 | scoped_ptr<RectMap> m_nextRectHistory; |
| 55 | |
| 56 | FloatRect m_currentDamageRect; |
| 57 | bool m_forceFullDamageNextUpdate; |
| 58 | }; |
| 59 | |
| 60 | } // namespace cc |
| 61 | |
| 62 | #endif // CCDamageTracker_h |