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

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

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: Merged PaintContext Offset into paint_recording_bounds_ 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,
32
33 // Scales the context based on the effective dsf. This may lead to minor
34 // distortion during scaling.
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 // A tranform that converts a given cooridinate from local DIP coordinates to
94 // the parent paint recording coordinates.
95 gfx::Transform TransformToParentRecordingSpace(
vmpstr 2017/07/11 17:37:22 Just some general thoughts: - It feels like ui::P
malaykeshav 2017/07/12 00:55:35 Done. Moving this to views::View() and exposing pa
96 const gfx::Vector2d& offset_from_parent) const;
97
68 private: 98 private:
69 // The Recorder classes need access to the internal canvas and friends, but we 99 // 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 100 // don't want to expose them on this class so that people must go through the
71 // recorders to access them. 101 // recorders to access them.
72 friend class ClipRecorder; 102 friend class ClipRecorder;
73 friend class CompositingRecorder; 103 friend class CompositingRecorder;
74 friend class PaintRecorder; 104 friend class PaintRecorder;
75 friend class TransformRecorder; 105 friend class TransformRecorder;
76 // The Cache class also needs to access the DisplayItemList to append its 106 // The Cache class also needs to access the DisplayItemList to append its
77 // cache contents. 107 // cache contents.
78 friend class PaintCache; 108 friend class PaintCache;
79 109
80 // Returns a rect with the given size in the space of the context's 110 // Returns a rect with the given size in the space of the context's
81 // containing layer. 111 // containing layer.
82 gfx::Rect ToLayerSpaceBounds(const gfx::Size& size_in_context) const; 112 gfx::Rect ToLayerSpaceBounds(const gfx::Size& size_in_context) const;
83 113
84 // Returns the given rect translated by the layer space offset. 114 // Given the DIP |size|, this function updates the paint recording scales.
85 gfx::Rect ToLayerSpaceRect(const gfx::Rect& rect) const; 115 void ComputePaintRecordingScales(const gfx::Size& size);
116
117 // Scales the |child_bounds| to its recording bounds based on the
118 // |device_scale_factor_|. The recording bounds are snapped to the
119 // |parent bound|'s right and/or bottom edge if required.
120 // This function returns |child_bounds| as is if pixel canvas is disabled.
121 gfx::Rect GetSnappedRecordingBounds(const gfx::Rect& parent_bounds,
122 const gfx::Rect& child_bounds) const;
86 123
87 cc::DisplayItemList* list_; 124 cc::DisplayItemList* list_;
88 // The device scale of the frame being painted. Used to determine which bitmap 125 // The device scale of the frame being painted. Used to determine which bitmap
89 // resources to use in the frame. 126 // resources to use in the frame.
90 float device_scale_factor_; 127 float device_scale_factor_;
128 // The scale at which the paint commands are recorded at. Due to the decimal
129 // rounding and snapping to edges during scaling operations, the effective
130 // paint recording scale may end up being slightly different between the x and
131 // y axis.
132 float paint_recording_scale_x_;
133 float paint_recording_scale_y_;
91 // Invalidation in the space of the paint root (ie the space of the layer 134 // Invalidation in the space of the paint root (ie the space of the layer
92 // backing the paint taking place). 135 // backing the paint taking place). This is in pixel size if pixel canvas is
136 // enabled.
93 gfx::Rect invalidation_; 137 gfx::Rect invalidation_;
94 // Offset from the PaintContext to the space of the paint root and the 138 // Paint Recording bounds for this paint context. The offset is relative to
95 // |invalidation_|. 139 // the paint root.
96 gfx::Vector2d offset_; 140 const gfx::Rect paint_recording_bounds_;
141 // The |scale_type| tells the context how it needs to perform scaling when
142 // pixel canvas is enabled.
143 ScaleType scale_type_ = ScaleType::SCALE_TO_SCALE_FACTOR;
97 144
98 #if DCHECK_IS_ON() 145 #if DCHECK_IS_ON()
99 // Used to verify that the |invalidation_| is only used to compare against 146 // Used to verify that the |invalidation_| is only used to compare against
100 // rects in the same space. 147 // rects in the same space.
101 mutable void* root_visited_; 148 mutable void* root_visited_;
102 // Used to verify that paint recorders are not nested. True while a paint 149 // Used to verify that paint recorders are not nested. True while a paint
103 // recorder is active. 150 // recorder is active.
104 mutable bool inside_paint_recorder_; 151 mutable bool inside_paint_recorder_;
105 #endif 152 #endif
106 153
107 DISALLOW_COPY_AND_ASSIGN(PaintContext); 154 DISALLOW_COPY_AND_ASSIGN(PaintContext);
108 }; 155 };
109 156
110 } // namespace ui 157 } // namespace ui
111 158
112 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_ 159 #endif // UI_COMPOSITOR_PAINT_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698