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

Side by Side Diff: ui/views/paint_info.cc

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: Fix applist_unittest and sync with ToT Created 3 years, 4 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
(Empty)
1 // Copyright 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/views/paint_info.h"
6
7 namespace views {
8
9 // static
10 PaintInfo PaintInfo::CreateRootPaintInfo(const ui::PaintContext& root_context,
11 const gfx::Size& size) {
12 return PaintInfo(root_context, size);
13 }
14
15 // static
16 PaintInfo PaintInfo::CreateChildPaintInfo(const PaintInfo& other,
17 const gfx::Rect& bounds,
18 const gfx::Size& parent_size,
19 ScaleType scale_type) {
20 return PaintInfo(other, bounds, parent_size, scale_type);
21 }
22
23 PaintInfo::PaintInfo(const ui::PaintContext& root_context,
sky 2017/07/28 16:02:11 Style guide says order of declarations and definit
malaykeshav 2017/07/31 18:54:29 The style guide mentions that classes should be de
sky 2017/08/01 15:10:24 Here's the relevant item, "Function declaration or
malaykeshav 2017/08/01 19:31:01 Done
24 const gfx::Size& size)
25 : paint_recording_scale_x_(root_context.is_pixel_canvas()
26 ? root_context.device_scale_factor()
27 : 1.f),
28 paint_recording_scale_y_(paint_recording_scale_x_),
29 paint_recording_bounds_(
30 gfx::ScaleToRoundedRect(gfx::Rect(size), paint_recording_scale_x_)),
31 context_(root_context, gfx::Vector2d()),
32 root_context_(&root_context) {}
33
34 PaintInfo::PaintInfo(const PaintInfo& other,
35 const gfx::Rect& bounds,
36 const gfx::Size& parent_size,
37 ScaleType scale_type)
38 : paint_recording_scale_x_(1.f),
39 paint_recording_scale_y_(1.f),
40 paint_recording_bounds_(
41 other.GetSnappedRecordingBounds(parent_size, bounds)),
42 offset_from_parent_(paint_recording_bounds_.OffsetFromOrigin() -
43 other.paint_recording_bounds_.OffsetFromOrigin()),
44 context_(other.context(), offset_from_parent_),
45 root_context_(nullptr) {
46 ComputePaintRecordingScales(bounds.size(), scale_type);
47 }
48
49 PaintInfo::PaintInfo(const PaintInfo& other)
50 : paint_recording_scale_x_(other.paint_recording_scale_x_),
51 paint_recording_scale_y_(other.paint_recording_scale_y_),
52 paint_recording_bounds_(other.paint_recording_bounds_),
53 offset_from_parent_(other.offset_from_parent_),
54 context_(other.context(), ui::PaintContext::CLONE_WITHOUT_INVALIDATION),
55 root_context_(nullptr) {}
56
57 PaintInfo::~PaintInfo() {}
58
59 bool PaintInfo::IsPixelCanvas() const {
60 return context().is_pixel_canvas();
61 }
62
63 void PaintInfo::ComputePaintRecordingScales(const gfx::Size& size,
sky 2017/07/28 16:02:11 You only call this from one place, how about movin
malaykeshav 2017/07/31 18:54:29 Done
64 ScaleType scale_type) {
65 if (!IsPixelCanvas()) {
66 // If pixel canvas is disabled, all recordings are done in DIPs. These are
67 // later played back on to the raster canvas at |device_scale_factor_|.
68 paint_recording_scale_x_ = paint_recording_scale_y_ = 1.f;
sky 2017/07/28 16:02:11 When you inline this function in the constructor t
malaykeshav 2017/07/31 18:54:29 Ack
69 return;
70 }
71
72 paint_recording_scale_x_ = paint_recording_scale_y_ =
73 context().device_scale_factor();
74 if (scale_type == ScaleType::kScaleToScaleFactor)
75 return;
76
77 if (size.width() > 0) {
78 paint_recording_scale_x_ =
79 static_cast<float>(paint_recording_bounds_.width()) /
80 static_cast<float>(size.width());
81 }
82
83 if (size.height() > 0) {
84 paint_recording_scale_y_ =
85 static_cast<float>(paint_recording_bounds_.height()) /
86 static_cast<float>(size.height());
87 }
88 }
89
90 gfx::Rect PaintInfo::GetSnappedRecordingBounds(
91 const gfx::Size& parent_size,
92 const gfx::Rect& child_bounds) const {
93 if (!IsPixelCanvas())
94 return (child_bounds + paint_recording_bounds_.OffsetFromOrigin());
95
96 const gfx::Vector2d& child_origin = child_bounds.OffsetFromOrigin();
97
98 int right = child_origin.x() + child_bounds.width();
99 int bottom = child_origin.y() + child_bounds.height();
100
101 int new_x = std::round(child_origin.x() * context().device_scale_factor());
102 int new_y = std::round(child_origin.y() * context().device_scale_factor());
103
104 int new_right;
105 int new_bottom;
106
107 if (right == parent_size.width())
108 new_right = paint_recording_bounds_.width();
109 else
110 new_right = std::round(right * context().device_scale_factor());
111
112 if (bottom == parent_size.height())
113 new_bottom = paint_recording_bounds_.height();
114 else
115 new_bottom = std::round(bottom * context().device_scale_factor());
116
117 return gfx::Rect(new_x + paint_recording_bounds_.x(),
118 new_y + paint_recording_bounds_.y(), new_right - new_x,
119 new_bottom - new_y);
120 }
121
122 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698