1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_PAINT_AGGREGATOR_H_
6 #define CONTENT_RENDERER_PAINT_AGGREGATOR_H_
10 #include "base/basictypes.h"
11 #include "content/common/content_export.h"
12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/vector2d.h"
17 // This class is responsible for aggregating multiple invalidation and scroll
18 // commands to produce a scroll and repaint sequence.
19 class CONTENT_EXPORT PaintAggregator
{
21 // This structure describes an aggregation of InvalidateRect and ScrollRect
22 // calls. If |scroll_rect| is non-empty, then that rect should be scrolled
23 // by the amount specified by |scroll_delta|. If |paint_rects| is non-empty,
24 // then those rects should be repainted. If |scroll_rect| and |paint_rects|
25 // are non-empty, then scrolling should be performed before repainting.
26 // |scroll_delta| can only specify scrolling in one direction (i.e., the x
27 // and y members cannot both be non-zero).
28 struct CONTENT_EXPORT PendingUpdate
{
32 // Returns the rect damaged by scrolling within |scroll_rect| by
33 // |scroll_delta|. This rect must be repainted.
34 gfx::Rect
GetScrollDamage() const;
36 // Returns the smallest rect containing all paint rects.
37 gfx::Rect
GetPaintBounds() const;
39 gfx::Vector2d scroll_delta
;
40 gfx::Rect scroll_rect
;
41 std::vector
<gfx::Rect
> paint_rects
;
44 // There is a PendingUpdate if InvalidateRect or ScrollRect were called and
45 // ClearPendingUpdate was not called.
46 bool HasPendingUpdate() const;
47 void ClearPendingUpdate();
49 // Fills |update| and clears the pending update.
50 void PopPendingUpdate(PendingUpdate
* update
);
52 // The given rect should be repainted.
53 void InvalidateRect(const gfx::Rect
& rect
);
55 // The given rect should be scrolled by the given amounts.
56 void ScrollRect(const gfx::Vector2d
& delta
, const gfx::Rect
& clip_rect
);
59 gfx::Rect
ScrollPaintRect(const gfx::Rect
& paint_rect
,
60 const gfx::Vector2d
& delta
) const;
61 bool ShouldInvalidateScrollRect(const gfx::Rect
& rect
) const;
62 void InvalidateScrollRect();
63 void CombinePaintRects();
65 PendingUpdate update_
;
68 } // namespace content
70 #endif // CONTENT_RENDERER_PAINT_AGGREGATOR_H_