Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: ui/compositor/paint_context.h

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: Update unittests for RasterSource Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_COMPOSITOR_PAINT_CONTEXT_H_ 5 #ifndef UI_COMPOSITOR_PAINT_CONTEXT_H_
6 #define UI_COMPOSITOR_PAINT_CONTEXT_H_ 6 #define UI_COMPOSITOR_PAINT_CONTEXT_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "cc/paint/display_item_list.h"
12 #include "cc/paint/paint_recorder.h" 13 #include "cc/paint/paint_recorder.h"
13 #include "ui/compositor/compositor_export.h" 14 #include "ui/compositor/compositor_export.h"
14 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
15 16
16 namespace cc { 17 namespace cc {
17 class DisplayItemList; 18 class DisplayItemList;
18 } 19 }
19 20
20 namespace ui { 21 namespace ui {
21 class ClipRecorder; 22 class ClipRecorder;
22 class CompositingRecorder; 23 class CompositingRecorder;
23 class PaintRecorder; 24 class PaintRecorder;
24 class TransformRecorder; 25 class TransformRecorder;
25 26
26 class COMPOSITOR_EXPORT PaintContext { 27 class COMPOSITOR_EXPORT PaintContext {
27 public: 28 public:
29 enum ScaleType {
30 // Scales the context by the default dsf. Use this if you dont want any form
31 // of distortion during scaling.
32 SCALE_TO_SCALE_FACTOR = 0,
33
34 // Scales the context based on the effective dsf. This may lead to minor
35 // distortion during scaling.
36 SCALE_TO_FIT
37 };
38
28 // Construct a PaintContext that may only re-paint the area in the 39 // Construct a PaintContext that may only re-paint the area in the
29 // |invalidation|. 40 // |invalidation|.
oshima 2017/06/15 22:59:12 update the comment
malaykeshav 2017/06/16 20:41:57 Done
30 PaintContext(cc::DisplayItemList* list, 41 PaintContext(cc::DisplayItemList* list,
31 float device_scale_factor, 42 float device_scale_factor,
32 const gfx::Rect& invalidation); 43 const gfx::Rect& invalidation,
44 const gfx::Size& size);
33 45
34 // Clone a PaintContext with an additional |offset|. 46 // Clone a PaintContext with different |bounds| that has some offset from its
35 PaintContext(const PaintContext& other, const gfx::Vector2d& offset); 47 // parent. |scale_type| should be from |ScaleType|.
48 PaintContext(const PaintContext& other,
49 const gfx::Rect& bounds,
50 int scale_type);
36 51
37 // Clone a PaintContext that has no consideration for invalidation. 52 // Clone a PaintContext that has no consideration for invalidation.
38 enum CloneWithoutInvalidation { 53 enum CloneWithoutInvalidation {
39 CLONE_WITHOUT_INVALIDATION, 54 CLONE_WITHOUT_INVALIDATION,
40 }; 55 };
41 PaintContext(const PaintContext& other, CloneWithoutInvalidation c); 56 PaintContext(const PaintContext& other, CloneWithoutInvalidation c);
42 57
43 ~PaintContext(); 58 ~PaintContext();
44 59
45 // When true, IsRectInvalid() can be called, otherwise its result would be 60 // When true, ShouldRepaint() can be called, otherwise its result would be
46 // invalid. 61 // invalid.
47 bool CanCheckInvalid() const { return !invalidation_.IsEmpty(); } 62 bool CanCheckRepaint() const { return !invalidation_.IsEmpty(); }
48 63
49 // When true, the |bounds| touches an invalidated area, so should be 64 // When true, the |pixel_bounds_| touches an invalidated area, so should be
50 // re-painted. When false, re-painting can be skipped. Bounds should be in 65 // re-painted. When false, re-painting can be skipped.
51 // the local space with offsets up to the painting root in the PaintContext. 66 bool ShouldRepaint() const {
52 bool IsRectInvalid(const gfx::Rect& bounds) const { 67 DCHECK(CanCheckRepaint());
53 DCHECK(CanCheckInvalid()); 68 return invalidation_.Intersects(gfx::Rect(pixel_size()) + offset_);
54 return invalidation_.Intersects(bounds + offset_);
55 } 69 }
56 70
57 #if DCHECK_IS_ON() 71 #if DCHECK_IS_ON()
58 void Visited(void* visited) const { 72 void Visited(void* visited) const {
59 if (!root_visited_) 73 if (!root_visited_)
60 root_visited_ = visited; 74 root_visited_ = visited;
61 } 75 }
62 void* RootVisited() const { return root_visited_; } 76 void* RootVisited() const { return root_visited_; }
63 const gfx::Vector2d& PaintOffset() const { return offset_; } 77 const gfx::Vector2d& PaintOffset() const { return offset_; }
64 #endif 78 #endif
65 79
66 const gfx::Rect& InvalidationForTesting() const { return invalidation_; } 80 const gfx::Rect& InvalidationForTesting() const { return invalidation_; }
67 81
82 bool IsPixelCanvas() const { return list_ && list_->pixel_canvas_enabled(); }
83
84 // Due to decimal rounding during scaling operations the effective device
85 // scale factor ends up being different from |device_scale_factor_|. To
86 // convert any DIP measurement to its corresponding measurement on the canvas,
87 // the following scales must be used.
88 float effective_scale_factor_x() const;
89 float effective_scale_factor_y() const;
90
91 const gfx::Size& pixel_size() const { return pixel_bounds_.size(); }
92 const gfx::Rect& pixel_bounds() const { return pixel_bounds_; }
93
94 // Scales the given DIP measurements to their corresponding canvas measurement
95 // using the effective scale factors which may be different from
96 // |device_scale_factor_|.
97 // Returns the measurements as is, if pixel canvas is disabled.
98 gfx::Size ScaleToEffectivePixelSize(const gfx::Size& size) const;
99 gfx::Rect ScaleToEffectivePixelBounds(const gfx::Rect& bounds) const;
oshima 2017/06/15 22:59:12 Effective, may not be a good name in this context.
malaykeshav 2017/06/16 20:41:57 Done
100
68 private: 101 private:
69 // The Recorder classes need access to the internal canvas and friends, but we 102 // The Recorder classes need access to the internal canvas and friends, but we
70 // don't want to expose them on this class so that people must go through the 103 // don't want to expose them on this class so that people must go through the
71 // recorders to access them. 104 // recorders to access them.
72 friend class ClipRecorder; 105 friend class ClipRecorder;
73 friend class CompositingRecorder; 106 friend class CompositingRecorder;
74 friend class PaintRecorder; 107 friend class PaintRecorder;
75 friend class TransformRecorder; 108 friend class TransformRecorder;
76 // The Cache class also needs to access the DisplayItemList to append its 109 // The Cache class also needs to access the DisplayItemList to append its
77 // cache contents. 110 // cache contents.
78 friend class PaintCache; 111 friend class PaintCache;
79 112
80 // Returns a rect with the given size in the space of the context's 113 // Returns a rect with the given size in the space of the context's
81 // containing layer. 114 // containing layer.
82 gfx::Rect ToLayerSpaceBounds(const gfx::Size& size_in_context) const; 115 gfx::Rect ToLayerSpaceBounds(const gfx::Size& size_in_context) const;
83 116
84 // Returns the given rect translated by the layer space offset. 117 // Returns the given rect translated by the layer space offset.
85 gfx::Rect ToLayerSpaceRect(const gfx::Rect& rect) const; 118 gfx::Rect ToLayerSpaceRect(const gfx::Rect& rect) const;
86 119
120 // Scales the |child_bounds| to its pixel bounds based on the
121 // |device_scale_factor_|. The pixel bounds are snapped to the parent bound's
122 // right and/or bottom edge if required.
123 // This function returns |child_bounds| as is if pixel canvas is disabled.
124 gfx::Rect GetSnappedPixelBounds(const gfx::Rect& child_bounds,
125 int scale_type) const;
126
87 cc::DisplayItemList* list_; 127 cc::DisplayItemList* list_;
88 // The device scale of the frame being painted. Used to determine which bitmap 128 // The device scale of the frame being painted. Used to determine which bitmap
89 // resources to use in the frame. 129 // resources to use in the frame.
90 float device_scale_factor_; 130 float device_scale_factor_;
91 // Invalidation in the space of the paint root (ie the space of the layer 131 // Invalidation in the space of the paint root (ie the space of the layer
92 // backing the paint taking place). 132 // backing the paint taking place). This is in pixel size if pixel canvas is
133 // enabled.
93 gfx::Rect invalidation_; 134 gfx::Rect invalidation_;
135 // Bounds of the paint context.
136 gfx::Rect bounds_;
137 // Bounds of paint context in exact pixel size. This will have the same value
138 // as |bounds_| if pixel canvas is disabled.
139 gfx::Rect pixel_bounds_;
94 // Offset from the PaintContext to the space of the paint root and the 140 // Offset from the PaintContext to the space of the paint root and the
95 // |invalidation_|. 141 // |invalidation_|. This is in pixels if pixel canvas is enabled.
96 gfx::Vector2d offset_; 142 gfx::Vector2d offset_;
143 // The |scale_type| tells the context how it needs to perform scaling when
144 // pixel canvas is enabled.
145 int scale_type_ = SCALE_TO_SCALE_FACTOR;
97 146
98 #if DCHECK_IS_ON() 147 #if DCHECK_IS_ON()
99 // Used to verify that the |invalidation_| is only used to compare against 148 // Used to verify that the |invalidation_| is only used to compare against
100 // rects in the same space. 149 // rects in the same space.
101 mutable void* root_visited_; 150 mutable void* root_visited_;
102 // Used to verify that paint recorders are not nested. True while a paint 151 // Used to verify that paint recorders are not nested. True while a paint
103 // recorder is active. 152 // recorder is active.
104 mutable bool inside_paint_recorder_; 153 mutable bool inside_paint_recorder_;
105 #endif 154 #endif
106 155
107 DISALLOW_COPY_AND_ASSIGN(PaintContext); 156 DISALLOW_COPY_AND_ASSIGN(PaintContext);
108 }; 157 };
109 158
110 } // namespace ui 159 } // namespace ui
111 160
112 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_ 161 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698