blob: 5121b064e8d28219798b8ef1e02a8d8b8e4f10c6 [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
[email protected]9dcbad242012-10-16 01:34:248#include "base/hash_tables.h"
[email protected]cd57cc5a2012-10-12 22:43:419#include "base/memory/scoped_ptr.h"
10#include "FloatRect.h"
11#include <vector>
[email protected]cd57cc5a2012-10-12 22:43:4112
13namespace WebKit {
14class WebFilterOperations;
15}
16
17namespace cc {
18
19class CCLayerImpl;
20class 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.
24class CCDamageTracker {
25public:
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
35private:
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]9dcbad242012-10-16 01:34:2452 typedef base::hash_map<int, FloatRect> RectMap;
[email protected]cd57cc5a2012-10-12 22:43:4153 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