blob: 4680662b94df556638447268629bf2ec387dd7ee [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"
[email protected]aad0a0072012-11-01 18:15:5810#include "ui/gfx/rect_f.h"
[email protected]cd57cc5a2012-10-12 22:43:4111#include <vector>
[email protected]cd57cc5a2012-10-12 22:43:4112
[email protected]aad0a0072012-11-01 18:15:5813class SkImageFilter;
14
15namespace gfx {
16class Rect;
17}
18
[email protected]cd57cc5a2012-10-12 22:43:4119namespace WebKit {
20class WebFilterOperations;
21}
22
23namespace cc {
24
[email protected]96baf3e2012-10-22 23:09:5525class LayerImpl;
26class RenderSurfaceImpl;
[email protected]cd57cc5a2012-10-12 22:43:4127
[email protected]96baf3e2012-10-22 23:09:5528// Computes the region where pixels have actually changed on a RenderSurfaceImpl. This region is used
[email protected]cd57cc5a2012-10-12 22:43:4129// to scissor what is actually drawn to the screen to save GPU computation and bandwidth.
[email protected]96baf3e2012-10-22 23:09:5530class DamageTracker {
[email protected]cd57cc5a2012-10-12 22:43:4131public:
[email protected]96baf3e2012-10-22 23:09:5532 static scoped_ptr<DamageTracker> create();
33 ~DamageTracker();
[email protected]cd57cc5a2012-10-12 22:43:4134
[email protected]aad0a0072012-11-01 18:15:5835 void didDrawDamagedArea() { m_currentDamageRect = gfx::RectF(); }
[email protected]cd57cc5a2012-10-12 22:43:4136 void forceFullDamageNextUpdate() { m_forceFullDamageNextUpdate = true; }
[email protected]aad0a0072012-11-01 18:15:5837 void updateDamageTrackingState(const std::vector<LayerImpl*>& layerList, int targetSurfaceLayerID, bool targetSurfacePropertyChangedOnlyFromDescendant, const gfx::Rect& targetSurfaceContentRect, LayerImpl* targetSurfaceMaskLayer, const WebKit::WebFilterOperations&, SkImageFilter* filter);
[email protected]cd57cc5a2012-10-12 22:43:4138
[email protected]aad0a0072012-11-01 18:15:5839 const gfx::RectF& currentDamageRect() { return m_currentDamageRect; }
[email protected]cd57cc5a2012-10-12 22:43:4140
41private:
[email protected]96baf3e2012-10-22 23:09:5542 DamageTracker();
[email protected]cd57cc5a2012-10-12 22:43:4143
[email protected]aad0a0072012-11-01 18:15:5844 gfx::RectF trackDamageFromActiveLayers(const std::vector<LayerImpl*>& layerList, int targetSurfaceLayerID);
45 gfx::RectF trackDamageFromSurfaceMask(LayerImpl* targetSurfaceMaskLayer);
46 gfx::RectF trackDamageFromLeftoverRects();
[email protected]cd57cc5a2012-10-12 22:43:4147
[email protected]aad0a0072012-11-01 18:15:5848 gfx::RectF removeRectFromCurrentFrame(int layerID, bool& layerIsNew);
49 void saveRectForNextFrame(int layerID, const gfx::RectF& targetSpaceRect);
[email protected]cd57cc5a2012-10-12 22:43:4150
51 // These helper functions are used only in trackDamageFromActiveLayers().
[email protected]aad0a0072012-11-01 18:15:5852 void extendDamageForLayer(LayerImpl*, gfx::RectF& targetDamageRect);
53 void extendDamageForRenderSurface(LayerImpl*, gfx::RectF& targetDamageRect);
[email protected]cd57cc5a2012-10-12 22:43:4154
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]aad0a0072012-11-01 18:15:5858 typedef base::hash_map<int, gfx::RectF> RectMap;
[email protected]cd57cc5a2012-10-12 22:43:4159 scoped_ptr<RectMap> m_currentRectHistory;
60 scoped_ptr<RectMap> m_nextRectHistory;
61
[email protected]aad0a0072012-11-01 18:15:5862 gfx::RectF m_currentDamageRect;
[email protected]cd57cc5a2012-10-12 22:43:4163 bool m_forceFullDamageNextUpdate;
64};
65
66} // namespace cc
67
68#endif // CCDamageTracker_h