1 // Copyright 2010 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PDF_PAINT_AGGREGATOR_H_
6 #define PDF_PAINT_AGGREGATOR_H_
10 #include "pdf/paint_ready_rect.h"
11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/geometry/vector2d.h"
14 namespace chrome_pdf {
16 // This class is responsible for aggregating multiple invalidation and scroll
17 // commands to produce a scroll and repaint sequence. You can use this manually
18 // to track your updates, but most applications will use the PaintManager to
19 // additionally handle the necessary callbacks on top of the PaintAggregator
22 // See http://code.google.com/p/ppapi/wiki/2DPaintingModel
23 class PaintAggregator {
27 PaintUpdate(const PaintUpdate& that);
30 // True if there is a scroll applied. This indicates that the scroll delta
31 // and scroll_rect are nonzero (just as a convenience).
34 // The amount to scroll by. Either the X or Y may be nonzero to indicate a
35 // scroll in that direction, but there will never be a scroll in both
36 // directions at the same time (this will be converted to a paint of the
39 // If there is no scroll, this will be (0, 0).
40 gfx::Vector2d scroll_delta;
42 // The rectangle that should be scrolled by the scroll_delta. If there is no
43 // scroll, this will be (0, 0, 0, 0). We only track one scroll command at
44 // once. If there are multiple ones, they will be converted to invalidates.
45 gfx::Rect scroll_rect;
47 // A list of all the individual dirty rectangles. This is an aggregated list
48 // of all invalidate calls. Different rectangles may be unified to produce a
49 // minimal list with no overlap that is more efficient to paint. This list
50 // also contains the region exposed by any scroll command.
51 std::vector<gfx::Rect> paint_rects;
56 // There is a PendingUpdate if InvalidateRect or ScrollRect were called and
57 // ClearPendingUpdate was not called.
58 bool HasPendingUpdate() const;
59 void ClearPendingUpdate();
61 PaintUpdate GetPendingUpdate();
63 // Sets the result of a call to the plugin to paint. This includes rects that
64 // are finished painting (ready), and ones that are still in-progress
66 void SetIntermediateResults(const std::vector<PaintReadyRect>& ready,
67 const std::vector<gfx::Rect>& pending);
69 // Returns the rectangles that are ready to be painted.
70 std::vector<PaintReadyRect> GetReadyRects() const;
72 // The given rect should be repainted.
73 void InvalidateRect(const gfx::Rect& rect);
75 // The given rect should be scrolled by the given amounts.
76 void ScrollRect(const gfx::Rect& clip_rect, const gfx::Vector2d& amount);
79 // This structure is an internal version of PaintUpdate. It's different in
82 // - The scroll damange (area exposed by the scroll operation, if any) is
83 // maintained separately from the dirty rects generated by calling
84 // InvalidateRect. We need to know this distinction for some operations.
86 // - The paint bounds union is computed on the fly so we don't have to keep
87 // a rectangle up to date as we do different operations.
88 class InternalPaintUpdate {
90 InternalPaintUpdate();
91 ~InternalPaintUpdate();
93 // Computes the rect damaged by scrolling within `scroll_rect` by
94 // `scroll_delta`. This rect must be repainted. It is not included in
96 gfx::Rect GetScrollDamage() const;
98 gfx::Vector2d scroll_delta;
99 gfx::Rect scroll_rect;
101 // Does not include the scroll damage rect unless
102 // synthesized_scroll_damage_rect_ is set.
103 std::vector<gfx::Rect> paint_rects;
105 // Rectangles that are finished painting.
106 std::vector<PaintReadyRect> ready_rects;
108 // Whether we have added the scroll damage rect to paint_rects yet or not.
109 bool synthesized_scroll_damage_rect_;
112 gfx::Rect ScrollPaintRect(const gfx::Rect& paint_rect,
113 const gfx::Vector2d& amount) const;
114 void InvalidateScrollRect();
116 // Internal method used by InvalidateRect. If `check_scroll` is true, then the
117 // method checks if there's a pending scroll and if so also invalidates `rect`
118 // in the new scroll position.
119 void InvalidateRectInternal(const gfx::Rect& rect, bool check_scroll);
121 InternalPaintUpdate update_;
124 } // namespace chrome_pdf
126 #endif // PDF_PAINT_AGGREGATOR_H_