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

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

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: Implements ViewPaintContext that encapsulates CompositorPaintContext. Also adds unittest 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
« no previous file with comments | « ui/compositor/paint_context.h ('k') | ui/compositor/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 (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 #ifndef UI_COMPOSITOR_PAINT_INFO_H_
6 #define UI_COMPOSITOR_PAINT_INFO_H_
7
8 #include "ui/compositor/paint_context.h"
9 #include "ui/gfx/geometry/rect.h"
10
11 namespace ui {
12
13 class COMPOSITOR_EXPORT PaintInfo {
malaykeshav 2017/07/21 00:12:33 Could be renamed to ViewPaintContext.
14 public:
15 enum class ScaleType {
16 // Scales the context by the default dsf. Use this if you dont want any form
17 // of distortion during scaling.
18 kScaleToScaleFactor = 0,
19
20 // Scales the context based on the effective dsf. This may lead to minor
21 // distortion during scaling due to edge snapping.
22 kScaleToFit
23 };
24
25 PaintInfo(const PaintContext& context, const gfx::Size& size);
26 PaintInfo(const PaintInfo& other,
27 const gfx::Rect& bounds,
28 const gfx::Rect& parent_bounds,
29 ScaleType scale_type);
30 PaintInfo(const PaintInfo& other);
31 ~PaintInfo();
32
33 const PaintContext& context() const {
34 return root_context_ ? *root_context_ : context_;
35 }
36
37 gfx::Vector2d offset_from_root() const {
38 return paint_recording_bounds_.OffsetFromOrigin();
39 }
40
41 static bool IsPixelCanvas();
42
43 gfx::Vector2d offset_from_parent() const { return offset_from_parent_; }
44
45 gfx::PointF paint_recording_scale() const {
46 return gfx::PointF(paint_recording_scale_x_, paint_recording_scale_y_);
47 }
48
49 const gfx::Size& paint_recording_size() const {
50 return paint_recording_bounds_.size();
51 }
52
53 const gfx::Rect& paint_recording_bounds() const {
54 return paint_recording_bounds_;
55 }
56
57 private:
58 // The scale at which the paint commands are recorded at. Due to the decimal
59 // rounding and snapping to edges during scaling operations, the effective
60 // paint recording scale may end up being slightly different between the x and
61 // y axis.
62 float paint_recording_scale_x_;
63 float paint_recording_scale_y_;
64
65 // Paint Recording bounds for this view. The offset is relative to the root
66 // paint context.
67 const gfx::Rect paint_recording_bounds_;
68
69 // Offset relative to the parent paint context.
70 gfx::Vector2d offset_from_parent_;
71
72 // PaintContext associated with the view this object belongs to.
73 PaintContext context_;
74 const PaintContext* root_context_;
75
76 // Given the DIP |size|, this function updates the paint recording scales.
77 void ComputePaintRecordingScales(const gfx::Size& size, ScaleType scale_type);
78
79 // Scales the |child_bounds| to its recording bounds based on the
80 // |context.device_scale_factor()|. The recording bounds are snapped to the
81 // |parent_bound|'s right and/or bottom edge if required.
82 // If pixel canvas is disabled, this function returns |child_bounds| as is.
83 gfx::Rect GetSnappedRecordingBounds(const gfx::Rect& parent_bounds,
84 const gfx::Rect& child_bounds) const;
85 };
86
87 } // namespace ui
88
89 #endif // UI_COMPOSITOR_PAINT_INFO_H_
OLDNEW
« no previous file with comments | « ui/compositor/paint_context.h ('k') | ui/compositor/paint_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698