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