[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 1 | // Copyright (c) 2009 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. | ||||
4 | |||||
[email protected] | 921f159 | 2011-03-18 00:41:02 | [diff] [blame] | 5 | #ifndef CONTENT_RENDERER_PAINT_AGGREGATOR_H_ |
6 | #define CONTENT_RENDERER_PAINT_AGGREGATOR_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 8 | |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 9 | #include <vector> |
10 | |||||
[email protected] | 38e0898 | 2010-10-22 17:28:43 | [diff] [blame] | 11 | #include "base/basictypes.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 12 | #include "ui/gfx/rect.h" |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 13 | |
14 | // This class is responsible for aggregating multiple invalidation and scroll | ||||
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 15 | // commands to produce a scroll and repaint sequence. |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 16 | class PaintAggregator { |
17 | public: | ||||
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 18 | // This structure describes an aggregation of InvalidateRect and ScrollRect |
19 | // calls. If |scroll_rect| is non-empty, then that rect should be scrolled | ||||
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 20 | // by the amount specified by |scroll_delta|. If |paint_rects| is non-empty, |
21 | // then those rects should be repainted. If |scroll_rect| and |paint_rects| | ||||
22 | // are non-empty, then scrolling should be performed before repainting. | ||||
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 23 | // |scroll_delta| can only specify scrolling in one direction (i.e., the x |
24 | // and y members cannot both be non-zero). | ||||
25 | struct PendingUpdate { | ||||
[email protected] | 38e0898 | 2010-10-22 17:28:43 | [diff] [blame] | 26 | PendingUpdate(); |
27 | ~PendingUpdate(); | ||||
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 28 | |
29 | // Returns the rect damaged by scrolling within |scroll_rect| by | ||||
30 | // |scroll_delta|. This rect must be repainted. | ||||
31 | gfx::Rect GetScrollDamage() const; | ||||
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 32 | |
33 | // Returns the smallest rect containing all paint rects. | ||||
34 | gfx::Rect GetPaintBounds() const; | ||||
[email protected] | 38e0898 | 2010-10-22 17:28:43 | [diff] [blame] | 35 | |
36 | gfx::Point scroll_delta; | ||||
37 | gfx::Rect scroll_rect; | ||||
38 | std::vector<gfx::Rect> paint_rects; | ||||
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 39 | }; |
40 | |||||
41 | // There is a PendingUpdate if InvalidateRect or ScrollRect were called and | ||||
42 | // ClearPendingUpdate was not called. | ||||
43 | bool HasPendingUpdate() const; | ||||
44 | void ClearPendingUpdate(); | ||||
45 | |||||
[email protected] | dd01581 | 2010-12-06 23:39:30 | [diff] [blame] | 46 | // Fills |update| and clears the pending update. |
47 | void PopPendingUpdate(PendingUpdate* update); | ||||
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 48 | |
49 | // The given rect should be repainted. | ||||
50 | void InvalidateRect(const gfx::Rect& rect); | ||||
51 | |||||
52 | // The given rect should be scrolled by the given amounts. | ||||
53 | void ScrollRect(int dx, int dy, const gfx::Rect& clip_rect); | ||||
54 | |||||
55 | private: | ||||
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 56 | gfx::Rect ScrollPaintRect(const gfx::Rect& paint_rect, int dx, int dy) const; |
57 | bool ShouldInvalidateScrollRect(const gfx::Rect& rect) const; | ||||
58 | void InvalidateScrollRect(); | ||||
[email protected] | 8fbfa3dc | 2009-12-09 21:05:56 | [diff] [blame] | 59 | void CombinePaintRects(); |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 60 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 61 | PendingUpdate update_; |
62 | }; | ||||
63 | |||||
[email protected] | 921f159 | 2011-03-18 00:41:02 | [diff] [blame] | 64 | #endif // CONTENT_RENDERER_PAINT_AGGREGATOR_H_ |