OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/compositor/paint_info.h" | |
6 | |
7 #include "ui/compositor/compositor_switches.h" | |
8 | |
9 namespace ui { | |
10 | |
11 PaintInfo::PaintInfo(const PaintContext& context, const gfx::Size& size) | |
12 : paint_recording_scale_x_(IsPixelCanvas() ? context.device_scale_factor() | |
13 : 1.f), | |
14 paint_recording_scale_y_(paint_recording_scale_x_), | |
15 paint_recording_bounds_( | |
16 gfx::ScaleToRoundedRect(gfx::Rect(size), paint_recording_scale_x_)), | |
danakj
2017/07/21 17:29:39
Rounding is almost always not what you want to do
malaykeshav
2017/07/21 23:30:17
That's true. But if we round at every location in
danakj
2017/07/25 17:58:56
Not finding bugs easily isn't surprising, they wou
malaykeshav
2017/07/25 22:57:57
For pixel canvas we are only modifying the scaling
| |
17 context_(context, gfx::Vector2d()), | |
18 root_context_(&context) {} | |
19 | |
20 PaintInfo::PaintInfo(const PaintInfo& other, | |
21 const gfx::Rect& bounds, | |
22 const gfx::Rect& parent_bounds, | |
23 ScaleType scale_type) | |
24 : paint_recording_bounds_( | |
25 other.GetSnappedRecordingBounds(parent_bounds, bounds)), | |
26 offset_from_parent_(paint_recording_bounds_.OffsetFromOrigin() - | |
27 other.paint_recording_bounds_.OffsetFromOrigin()), | |
28 context_(other.context(), offset_from_parent_), | |
29 root_context_(nullptr) { | |
30 ComputePaintRecordingScales(bounds.size(), scale_type); | |
31 } | |
32 | |
33 PaintInfo::PaintInfo(const PaintInfo& other) | |
34 : paint_recording_scale_x_(other.paint_recording_scale_x_), | |
35 paint_recording_scale_y_(other.paint_recording_scale_y_), | |
36 paint_recording_bounds_(other.paint_recording_bounds_), | |
37 offset_from_parent_(other.offset_from_parent_), | |
38 context_(other.context(), ui::PaintContext::CLONE_WITHOUT_INVALIDATION), | |
39 root_context_(nullptr) {} | |
40 | |
41 PaintInfo::~PaintInfo() {} | |
42 | |
43 // static | |
44 bool PaintInfo::IsPixelCanvas() { | |
45 return IsPixelCanvasRecordingEnabled(); | |
danakj
2017/07/21 17:29:39
pass this in the constructor, instead of reading t
malaykeshav
2017/07/21 23:30:17
Done. Passing it to PaintContext should propagate
| |
46 } | |
47 | |
48 void PaintInfo::ComputePaintRecordingScales(const gfx::Size& size, | |
49 ScaleType scale_type) { | |
50 if (!IsPixelCanvas()) { | |
51 // If pixel canvas is disabled, all recordings are done in DIPs. These are | |
52 // later played back on to the raster canvas at |device_scale_factor_|. | |
53 paint_recording_scale_x_ = paint_recording_scale_y_ = 1.f; | |
54 return; | |
55 } | |
56 | |
57 paint_recording_scale_x_ = paint_recording_scale_y_ = | |
58 context().device_scale_factor(); | |
59 if (scale_type == ScaleType::kScaleToScaleFactor) | |
60 return; | |
61 | |
62 if (size.width() > 0) { | |
63 paint_recording_scale_x_ = | |
64 static_cast<float>(paint_recording_bounds_.width()) / | |
65 static_cast<float>(size.width()); | |
66 } | |
67 | |
68 if (size.height() > 0) { | |
69 paint_recording_scale_y_ = | |
70 static_cast<float>(paint_recording_bounds_.height()) / | |
71 static_cast<float>(size.height()); | |
72 } | |
73 } | |
74 | |
75 gfx::Rect PaintInfo::GetSnappedRecordingBounds( | |
76 const gfx::Rect& parent_bounds, | |
77 const gfx::Rect& child_bounds) const { | |
78 if (!IsPixelCanvas()) | |
79 return (child_bounds + paint_recording_bounds_.OffsetFromOrigin()); | |
80 | |
81 const gfx::Vector2d& child_origin = child_bounds.OffsetFromOrigin(); | |
82 | |
83 int right = child_origin.x() + child_bounds.width(); | |
84 int bottom = child_origin.y() + child_bounds.height(); | |
85 | |
86 int new_x = std::round(child_origin.x() * context().device_scale_factor()); | |
87 int new_y = std::round(child_origin.y() * context().device_scale_factor()); | |
88 | |
89 int new_right; | |
90 int new_bottom; | |
91 | |
92 if (right == parent_bounds.width()) { | |
93 new_right = paint_recording_bounds_.width(); | |
94 } else { | |
95 new_right = std::round(right * context().device_scale_factor()); | |
96 } | |
97 | |
98 if (bottom == parent_bounds.height()) { | |
99 new_bottom = paint_recording_bounds_.height(); | |
100 } else { | |
101 new_bottom = std::round(bottom * context().device_scale_factor()); | |
102 } | |
103 | |
104 return gfx::Rect(new_x + paint_recording_bounds_.x(), | |
105 new_y + paint_recording_bounds_.y(), new_right - new_x, | |
106 new_bottom - new_y); | |
107 } | |
108 | |
109 } // namespace ui | |
OLD | NEW |