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

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

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: Resolving comments Created 3 years, 5 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/paint_recorder.h" 12 #include "cc/paint/paint_recorder.h"
13 #include "ui/compositor/compositor_export.h" 13 #include "ui/compositor/compositor_export.h"
14 #include "ui/gfx/geometry/rect.h" 14 #include "ui/gfx/geometry/rect.h"
15 15
16 namespace cc { 16 namespace cc {
17 class DisplayItemList; 17 class DisplayItemList;
18 } 18 }
19 19
20 namespace ui { 20 namespace ui {
21 class ClipRecorder; 21 class ClipRecorder;
22 class CompositingRecorder; 22 class CompositingRecorder;
23 class PaintRecorder; 23 class PaintRecorder;
24 class TransformRecorder; 24 class TransformRecorder;
25 25
26 class COMPOSITOR_EXPORT PaintContext { 26 class COMPOSITOR_EXPORT PaintContext {
27 public: 27 public:
28 // Construct a PaintContext that may only re-paint the area in the 28 enum class ScaleType {
29 // |invalidation|. 29 // Scales the context by the default dsf. Use this if you dont want any form
30 // of distortion during scaling.
31 SCALE_TO_SCALE_FACTOR = 0,
danakj 2017/07/19 17:00:59 enums should be kFoo style now
malaykeshav 2017/07/21 00:12:33 Done
32
33 // Scales the context based on the effective dsf. This may lead to minor
34 // distortion during scaling due to edge snapping.
35 SCALE_TO_FIT
36 };
37
38 // Construct a PaintContext of given size that may only re-paint the area in
39 // the |invalidation|.
30 PaintContext(cc::DisplayItemList* list, 40 PaintContext(cc::DisplayItemList* list,
31 float device_scale_factor, 41 float device_scale_factor,
32 const gfx::Rect& invalidation); 42 const gfx::Rect& invalidation,
43 const gfx::Size& size);
33 44
34 // Clone a PaintContext with an additional |offset|. 45 // Clone a PaintContext with different |bounds| that has some offset from its
35 PaintContext(const PaintContext& other, const gfx::Vector2d& offset); 46 // parent.
47 PaintContext(const PaintContext& other,
48 const gfx::Rect& bounds,
49 const gfx::Rect& parent_bounds,
50 ScaleType 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 |paint_recording_bounds_| touches an invalidated area, so
50 // re-painted. When false, re-painting can be skipped. Bounds should be in 65 // should be 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(paint_recording_bounds_);
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::Point& PaintOffset() const {
78 return paint_recording_bounds_.origin();
79 }
64 #endif 80 #endif
65 81
66 const gfx::Rect& InvalidationForTesting() const { return invalidation_; } 82 const gfx::Rect& InvalidationForTesting() const { return invalidation_; }
67 83
84 bool IsPixelCanvas() const;
85
86 const gfx::Size& paint_recording_size() const {
87 return paint_recording_bounds_.size();
88 }
89 const gfx::Rect& paint_recording_bounds() const {
90 return paint_recording_bounds_;
91 }
92
93 gfx::PointF paint_recording_scale() const {
94 return gfx::PointF(paint_recording_scale_x_, paint_recording_scale_y_);
95 }
96
68 private: 97 private:
69 // The Recorder classes need access to the internal canvas and friends, but we 98 // 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 99 // don't want to expose them on this class so that people must go through the
71 // recorders to access them. 100 // recorders to access them.
72 friend class ClipRecorder; 101 friend class ClipRecorder;
73 friend class CompositingRecorder; 102 friend class CompositingRecorder;
74 friend class PaintRecorder; 103 friend class PaintRecorder;
75 friend class TransformRecorder; 104 friend class TransformRecorder;
76 // The Cache class also needs to access the DisplayItemList to append its 105 // The Cache class also needs to access the DisplayItemList to append its
77 // cache contents. 106 // cache contents.
78 friend class PaintCache; 107 friend class PaintCache;
79 108
80 // Returns a rect with the given size in the space of the context's 109 // Returns a rect with the given size in the space of the context's
81 // containing layer. 110 // containing layer.
82 gfx::Rect ToLayerSpaceBounds(const gfx::Size& size_in_context) const; 111 gfx::Rect ToLayerSpaceBounds(const gfx::Size& size_in_context) const;
83 112
84 // Returns the given rect translated by the layer space offset. 113 // Given the DIP |size|, this function updates the paint recording scales.
85 gfx::Rect ToLayerSpaceRect(const gfx::Rect& rect) const; 114 void ComputePaintRecordingScales(const gfx::Size& size);
115
116 // Scales the |child_bounds| to its recording bounds based on the
117 // |device_scale_factor_|. The recording bounds are snapped to the
118 // |parent bound|'s right and/or bottom edge if required.
danakj 2017/07/19 17:00:59 |parent_bounds|'
malaykeshav 2017/07/21 00:12:33 Done
119 // This function returns |child_bounds| as is if pixel canvas is disabled.
danakj 2017/07/19 17:00:59 "as is if" reads a bit awkward, maybe reorder thin
malaykeshav 2017/07/21 00:12:33 Done
120 gfx::Rect GetSnappedRecordingBounds(const gfx::Rect& parent_bounds,
121 const gfx::Rect& child_bounds) const;
86 122
87 cc::DisplayItemList* list_; 123 cc::DisplayItemList* list_;
88 // The device scale of the frame being painted. Used to determine which bitmap 124 // The device scale of the frame being painted. Used to determine which bitmap
89 // resources to use in the frame. 125 // resources to use in the frame.
90 float device_scale_factor_; 126 float device_scale_factor_;
127 // The scale at which the paint commands are recorded at. Due to the decimal
128 // rounding and snapping to edges during scaling operations, the effective
129 // paint recording scale may end up being slightly different between the x and
130 // y axis.
131 float paint_recording_scale_x_;
132 float paint_recording_scale_y_;
91 // Invalidation in the space of the paint root (ie the space of the layer 133 // Invalidation in the space of the paint root (ie the space of the layer
92 // backing the paint taking place). 134 // backing the paint taking place). This is in pixel size if pixel canvas is
135 // enabled.
93 gfx::Rect invalidation_; 136 gfx::Rect invalidation_;
94 // Offset from the PaintContext to the space of the paint root and the 137 // Paint Recording bounds for this paint context. The offset is relative to
95 // |invalidation_|. 138 // the paint root.
96 gfx::Vector2d offset_; 139 const gfx::Rect paint_recording_bounds_;
140 // The |scale_type| tells the context how it needs to perform scaling when
141 // pixel canvas is enabled.
142 ScaleType scale_type_ = ScaleType::SCALE_TO_SCALE_FACTOR;
97 143
98 #if DCHECK_IS_ON() 144 #if DCHECK_IS_ON()
99 // Used to verify that the |invalidation_| is only used to compare against 145 // Used to verify that the |invalidation_| is only used to compare against
100 // rects in the same space. 146 // rects in the same space.
101 mutable void* root_visited_; 147 mutable void* root_visited_;
102 // Used to verify that paint recorders are not nested. True while a paint 148 // Used to verify that paint recorders are not nested. True while a paint
103 // recorder is active. 149 // recorder is active.
104 mutable bool inside_paint_recorder_; 150 mutable bool inside_paint_recorder_;
105 #endif 151 #endif
106 152
107 DISALLOW_COPY_AND_ASSIGN(PaintContext); 153 DISALLOW_COPY_AND_ASSIGN(PaintContext);
108 }; 154 };
109 155
110 } // namespace ui 156 } // namespace ui
111 157
112 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_ 158 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698