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

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

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: Resolving comments and Sync with ToT 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 #include "ui/compositor/paint_context.h" 5 #include "ui/compositor/paint_context.h"
6 6
7 #include "ui/compositor/compositor_switches.h"
7 #include "ui/gfx/canvas.h" 8 #include "ui/gfx/canvas.h"
9 #include "ui/gfx/transform.h"
8 10
9 namespace ui { 11 namespace ui {
10 12
11 PaintContext::PaintContext(cc::DisplayItemList* list, 13 PaintContext::PaintContext(cc::DisplayItemList* list,
12 float device_scale_factor, 14 float device_scale_factor,
13 const gfx::Rect& invalidation) 15 const gfx::Rect& invalidation,
16 const gfx::Size& size)
14 : list_(list), 17 : list_(list),
15 device_scale_factor_(device_scale_factor), 18 device_scale_factor_(device_scale_factor),
16 invalidation_(invalidation) { 19 paint_recording_scale_x_(IsPixelCanvas() ? device_scale_factor_ : 1.f),
20 paint_recording_scale_y_(paint_recording_scale_x_),
21 invalidation_(
22 gfx::ScaleToEnclosingRect(invalidation, paint_recording_scale_x_)),
23 paint_recording_bounds_(
24 gfx::ScaleToRoundedRect(gfx::Rect(size), paint_recording_scale_x_)) {
25 ComputePaintRecordingScales(size);
17 #if DCHECK_IS_ON() 26 #if DCHECK_IS_ON()
18 root_visited_ = nullptr; 27 root_visited_ = nullptr;
19 inside_paint_recorder_ = false; 28 inside_paint_recorder_ = false;
20 #endif 29 #endif
21 } 30 }
22 31
23 PaintContext::PaintContext(const PaintContext& other, 32 PaintContext::PaintContext(const PaintContext& other,
24 const gfx::Vector2d& offset) 33 const gfx::Rect& bounds,
34 const gfx::Rect& parent_bounds,
35 ScaleType scale_type)
25 : list_(other.list_), 36 : list_(other.list_),
26 device_scale_factor_(other.device_scale_factor_), 37 device_scale_factor_(other.device_scale_factor_),
27 invalidation_(other.invalidation_), 38 invalidation_(other.invalidation_),
28 offset_(other.offset_ + offset) { 39 paint_recording_bounds_(
40 other.GetSnappedRecordingBounds(parent_bounds, bounds)),
41 scale_type_(scale_type) {
42 ComputePaintRecordingScales(bounds.size());
29 #if DCHECK_IS_ON() 43 #if DCHECK_IS_ON()
30 root_visited_ = other.root_visited_; 44 root_visited_ = other.root_visited_;
31 inside_paint_recorder_ = other.inside_paint_recorder_; 45 inside_paint_recorder_ = other.inside_paint_recorder_;
32 #endif 46 #endif
33 } 47 }
34 48
35 PaintContext::PaintContext(const PaintContext& other, 49 PaintContext::PaintContext(const PaintContext& other,
36 CloneWithoutInvalidation c) 50 CloneWithoutInvalidation c)
37 : list_(other.list_), 51 : list_(other.list_),
38 device_scale_factor_(other.device_scale_factor_), 52 device_scale_factor_(other.device_scale_factor_),
53 paint_recording_scale_x_(other.paint_recording_scale_x_),
54 paint_recording_scale_y_(other.paint_recording_scale_y_),
39 invalidation_(), 55 invalidation_(),
40 offset_(other.offset_) { 56 paint_recording_bounds_(other.paint_recording_bounds_) {
41 #if DCHECK_IS_ON() 57 #if DCHECK_IS_ON()
42 root_visited_ = other.root_visited_; 58 root_visited_ = other.root_visited_;
43 inside_paint_recorder_ = other.inside_paint_recorder_; 59 inside_paint_recorder_ = other.inside_paint_recorder_;
44 #endif 60 #endif
45 } 61 }
46 62
47 PaintContext::~PaintContext() { 63 PaintContext::~PaintContext() {
48 } 64 }
49 65
50 gfx::Rect PaintContext::ToLayerSpaceBounds( 66 gfx::Rect PaintContext::ToLayerSpaceBounds(
51 const gfx::Size& size_in_context) const { 67 const gfx::Size& size_in_context) const {
52 return gfx::Rect(size_in_context) + offset_; 68 return gfx::Rect(paint_recording_bounds_.origin(), size_in_context);
53 } 69 }
54 70
55 gfx::Rect PaintContext::ToLayerSpaceRect(const gfx::Rect& rect) const { 71 void PaintContext::ComputePaintRecordingScales(const gfx::Size& size) {
56 return rect + offset_; 72 if (!IsPixelCanvas()) {
vmpstr 2017/07/12 17:48:19 Can you leave a comment here explaining? It's not
malaykeshav 2017/07/12 18:08:26 Done
73 paint_recording_scale_x_ = paint_recording_scale_y_ = 1.f;
74 return;
75 }
76
77 paint_recording_scale_x_ = paint_recording_scale_y_ = device_scale_factor_;
78 if (scale_type_ == ScaleType::SCALE_TO_SCALE_FACTOR)
79 return;
80
81 if (size.width() > 0) {
82 paint_recording_scale_x_ =
83 static_cast<float>(paint_recording_bounds_.width()) /
84 static_cast<float>(size.width());
85 }
86
87 if (size.height() > 0) {
88 paint_recording_scale_y_ =
89 static_cast<float>(paint_recording_bounds_.height()) /
90 static_cast<float>(size.height());
91 }
92 }
93
94 bool PaintContext::IsPixelCanvas() const {
95 return IsPixelCanvasRecordingEnabled();
96 }
97
98 gfx::Rect PaintContext::GetSnappedRecordingBounds(
99 const gfx::Rect& parent_bounds,
100 const gfx::Rect& child_bounds) const {
101 if (!IsPixelCanvas())
102 return (child_bounds + paint_recording_bounds().OffsetFromOrigin());
103
104 const gfx::Vector2d& child_origin = child_bounds.OffsetFromOrigin();
105
106 int right = child_origin.x() + child_bounds.width();
107 int bottom = child_origin.y() + child_bounds.height();
108
109 int new_x = std::round(child_origin.x() * device_scale_factor_);
110 int new_y = std::round(child_origin.y() * device_scale_factor_);
111
112 int new_right;
113 int new_bottom;
114
115 if (right == parent_bounds.width()) {
116 new_right = paint_recording_bounds_.width();
117 } else {
118 new_right = std::round(right * device_scale_factor_);
119 }
120
121 if (bottom == parent_bounds.height()) {
122 new_bottom = paint_recording_bounds_.height();
123 } else {
124 new_bottom = std::round(bottom * device_scale_factor_);
125 }
126 return gfx::Rect(new_x + paint_recording_bounds().x(),
127 new_y + paint_recording_bounds().y(), new_right - new_x,
128 new_bottom - new_y);
57 } 129 }
58 130
59 } // namespace ui 131 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698