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

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

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 #ifndef UI_VIEWS_PAINT_INFO_H_
6 #define UI_VIEWS_PAINT_INFO_H_
7
8 #include "ui/compositor/paint_context.h"
9 #include "ui/gfx/geometry/rect.h"
10 #include "ui/views/views_export.h"
11
12 namespace views {
13
14 // This class manages the context required during View::Paint(). It is
15 // responsible for setting the paint recording size and the paint recording
16 // scale factors for an individual View.
17 // Each PaintInfo instance has paint recording offset relative to a root
18 // PaintInfo.
19 // All coordinates are in paint recording space. If pixel canvas is enabled this
20 // essentially becomes pixel coordinate space.
21 class VIEWS_EXPORT PaintInfo {
22 public:
23 enum class ScaleType {
24 // Scale the recordings by the default dsf. Use this if you don't want any
25 // form of distortion during scaling.
26 kScaleToScaleFactor = 0,
27
28 // Scale the recordings based on the effective dsf. This may lead to minor
29 // distortion during scaling due to edge snapping.
30 kScaleToFit
31 };
32
33 // Instantiates a root PaintInfo. This should only be initialized at the Paint
34 // root, ie., a layer or the root of a widget.
35 static PaintInfo CreateRootPaintInfo(const ui::PaintContext& root_context,
sky 2017/07/28 16:02:12 Thanks for the improved names, they make it much e
36 const gfx::Size& size);
37
38 // Instantiate a child PaintInfo instance. All bounds for this object are
39 // relative to its root PaintInfo.
40 static PaintInfo CreateChildPaintInfo(const PaintInfo& other,
sky 2017/07/28 16:02:11 other -> parent_paint_info.
malaykeshav 2017/07/31 18:54:29 Done
41 const gfx::Rect& bounds,
42 const gfx::Size& parent_size,
43 ScaleType scale_type);
44
45 PaintInfo(const PaintInfo& other);
sky 2017/07/28 16:02:12 The way you have this class set up the assignment
malaykeshav 2017/07/31 18:54:29 You are right, this will create a PaintContext clo
46 ~PaintInfo();
47
48 const ui::PaintContext& context() const {
49 return root_context_ ? *root_context_ : context_;
50 }
51
52 gfx::Vector2d offset_from_root() const {
53 return paint_recording_bounds_.OffsetFromOrigin();
54 }
55
56 // Returns true if all paint commands are recorded at pixel size.
57 bool IsPixelCanvas() const;
58
59 const gfx::Vector2d& offset_from_parent() const {
60 return offset_from_parent_;
61 }
62
63 gfx::PointF paint_recording_scale() const {
sky 2017/07/28 16:02:11 Why are you using a Point for something that isn't
malaykeshav 2017/07/31 18:54:29 Done
64 return gfx::PointF(paint_recording_scale_x_, paint_recording_scale_y_);
65 }
66
67 const gfx::Size& paint_recording_size() const {
68 return paint_recording_bounds_.size();
69 }
70
71 const gfx::Rect& paint_recording_bounds() const {
72 return paint_recording_bounds_;
73 }
74
75 private:
76 friend class PaintInfoTest;
77
78 PaintInfo(const ui::PaintContext& root_context, const gfx::Size& size);
79 PaintInfo(const PaintInfo& other,
80 const gfx::Rect& bounds,
81 const gfx::Size& parent_size,
82 ScaleType scale_type);
83
84 // Given the DIP |size|, this function updates the paint recording scales.
85 void ComputePaintRecordingScales(const gfx::Size& size, ScaleType scale_type);
86
87 // Scales the |child_bounds| to its recording bounds based on the
88 // |context.device_scale_factor()|. The recording bounds are snapped to the
89 // parent's right and/or bottom edge if required.
90 // If pixel canvas is disabled, this function returns |child_bounds| as is.
91 gfx::Rect GetSnappedRecordingBounds(const gfx::Size& parent_size,
92 const gfx::Rect& child_bounds) const;
93
94 // The scale at which the paint commands are recorded at. Due to the decimal
95 // rounding and snapping to edges during the scale operation, the effective
96 // paint recording scale may end up being slightly different between the x and
97 // y axis.
98 float paint_recording_scale_x_;
99 float paint_recording_scale_y_;
100
101 // Paint Recording bounds of the view. The offset is relative to the root
102 // PaintInfo.
103 const gfx::Rect paint_recording_bounds_;
104
105 // Offset relative to the parent view's paint recording bounds. Returns 0
106 // offset if this is the root.
107 gfx::Vector2d offset_from_parent_;
108
109 // Compositor PaintContext associated with the view this object belongs to.
110 ui::PaintContext context_;
111 const ui::PaintContext* root_context_;
112 };
113
114 } // namespace views
115
116 #endif // UI_VIEWS_PAINT_INFO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698