Fix: warnings in media/capture/filters
[platform/framework/web/chromium-efl.git] / pdf / paint_aggregator.h
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.
4
5 #ifndef PDF_PAINT_AGGREGATOR_H_
6 #define PDF_PAINT_AGGREGATOR_H_
7
8 #include <vector>
9
10 #include "pdf/paint_ready_rect.h"
11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/geometry/vector2d.h"
13
14 namespace chrome_pdf {
15
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
20 // functionality.
21 //
22 // See http://code.google.com/p/ppapi/wiki/2DPaintingModel
23 class PaintAggregator {
24  public:
25   struct PaintUpdate {
26     PaintUpdate();
27     PaintUpdate(const PaintUpdate& that);
28     ~PaintUpdate();
29
30     // True if there is a scroll applied. This indicates that the scroll delta
31     // and scroll_rect are nonzero (just as a convenience).
32     bool has_scroll;
33
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
37     // region instead).
38     //
39     // If there is no scroll, this will be (0, 0).
40     gfx::Vector2d scroll_delta;
41
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;
46
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;
52   };
53
54   PaintAggregator();
55
56   // There is a PendingUpdate if InvalidateRect or ScrollRect were called and
57   // ClearPendingUpdate was not called.
58   bool HasPendingUpdate() const;
59   void ClearPendingUpdate();
60
61   PaintUpdate GetPendingUpdate();
62
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
65   // (pending).
66   void SetIntermediateResults(const std::vector<PaintReadyRect>& ready,
67                               const std::vector<gfx::Rect>& pending);
68
69   // Returns the rectangles that are ready to be painted.
70   std::vector<PaintReadyRect> GetReadyRects() const;
71
72   // The given rect should be repainted.
73   void InvalidateRect(const gfx::Rect& rect);
74
75   // The given rect should be scrolled by the given amounts.
76   void ScrollRect(const gfx::Rect& clip_rect, const gfx::Vector2d& amount);
77
78  private:
79   // This structure is an internal version of PaintUpdate. It's different in
80   // two respects:
81   //
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.
85   //
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 {
89    public:
90     InternalPaintUpdate();
91     ~InternalPaintUpdate();
92
93     // Computes the rect damaged by scrolling within `scroll_rect` by
94     // `scroll_delta`. This rect must be repainted. It is not included in
95     // paint_rects.
96     gfx::Rect GetScrollDamage() const;
97
98     gfx::Vector2d scroll_delta;
99     gfx::Rect scroll_rect;
100
101     // Does not include the scroll damage rect unless
102     // synthesized_scroll_damage_rect_ is set.
103     std::vector<gfx::Rect> paint_rects;
104
105     // Rectangles that are finished painting.
106     std::vector<PaintReadyRect> ready_rects;
107
108     // Whether we have added the scroll damage rect to paint_rects yet or not.
109     bool synthesized_scroll_damage_rect_;
110   };
111
112   gfx::Rect ScrollPaintRect(const gfx::Rect& paint_rect,
113                             const gfx::Vector2d& amount) const;
114   void InvalidateScrollRect();
115
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);
120
121   InternalPaintUpdate update_;
122 };
123
124 }  // namespace chrome_pdf
125
126 #endif  // PDF_PAINT_AGGREGATOR_H_