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

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

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: 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
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/paint_info.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
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& parent_paint_info,
41 const gfx::Rect& bounds,
42 const gfx::Size& parent_size,
43 ScaleType scale_type);
44
45 // Clones a given paint info, |other|, without the invalidation from its
46 // PaintContext.
47 static PaintInfo ClonePaintInfo(const PaintInfo& other);
48
49 PaintInfo(const PaintInfo& other);
50 ~PaintInfo();
51
52 // Returns true if all paint commands are recorded at pixel size.
53 bool IsPixelCanvas() const;
54
55 const ui::PaintContext& context() const {
56 return root_context_ ? *root_context_ : context_;
57 }
58
59 gfx::Vector2d offset_from_root() const {
60 return paint_recording_bounds_.OffsetFromOrigin();
61 }
62
63 const gfx::Vector2d& offset_from_parent() const {
64 return offset_from_parent_;
65 }
66
67 float paint_recording_scale_x() const { return paint_recording_scale_x_; }
68
69 float paint_recording_scale_y() const { return paint_recording_scale_y_; }
70
71 const gfx::Size& paint_recording_size() const {
72 return paint_recording_bounds_.size();
73 }
74
75 const gfx::Rect& paint_recording_bounds() const {
76 return paint_recording_bounds_;
77 }
78
79 private:
80 friend class PaintInfoTest;
81
82 PaintInfo(const ui::PaintContext& root_context, const gfx::Size& size);
83 PaintInfo(const PaintInfo& parent_paint_info,
84 const gfx::Rect& bounds,
85 const gfx::Size& parent_size,
86 ScaleType scale_type);
87 PaintInfo(const PaintInfo& other,
88 ui::PaintContext::CloneWithoutInvalidation c);
89
90 // Scales the |child_bounds| to its recording bounds based on the
91 // |context.device_scale_factor()|. The recording bounds are snapped to the
92 // parent's right and/or bottom edge if required.
93 // If pixel canvas is disabled, this function returns |child_bounds| as is.
94 gfx::Rect GetSnappedRecordingBounds(const gfx::Size& parent_size,
95 const gfx::Rect& child_bounds) const;
96
97 // The scale at which the paint commands are recorded at. Due to the decimal
98 // rounding and snapping to edges during the scale operation, the effective
99 // paint recording scale may end up being slightly different between the x and
100 // y axis.
101 float paint_recording_scale_x_;
102 float paint_recording_scale_y_;
103
104 // Paint Recording bounds of the view. The offset is relative to the root
105 // PaintInfo.
106 const gfx::Rect paint_recording_bounds_;
107
108 // Offset relative to the parent view's paint recording bounds. Returns 0
109 // offset if this is the root.
110 gfx::Vector2d offset_from_parent_;
111
112 // Compositor PaintContext associated with the view this object belongs to.
113 ui::PaintContext context_;
114 const ui::PaintContext* root_context_;
115 };
116
117 } // namespace views
118
119 #endif // UI_VIEWS_PAINT_INFO_H_
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/paint_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698