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

Side by Side Diff: ui/compositor/paint_context.cc

Issue 2849953004: SV Test
Patch Set: Created 3 years, 7 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_recorder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/compositor/paint_context.h" 5 #include "ui/compositor/paint_context.h"
6 6
7 #include "ui/gfx/canvas.h" 7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/geometry/vector2d_f.h"
9
10 #include "base/debug/stack_trace.h"
8 11
9 namespace ui { 12 namespace ui {
10 13
11 PaintContext::PaintContext(cc::DisplayItemList* list, 14 PaintContext::PaintContext(cc::DisplayItemList* list,
12 float device_scale_factor, 15 float device_scale_factor,
13 const gfx::Rect& invalidation) 16 const gfx::Rect& invalidation)
14 : list_(list), 17 : list_(list),
15 owned_recorder_(new cc::PaintRecorder), 18 owned_recorder_(new cc::PaintRecorder),
16 recorder_(owned_recorder_.get()), 19 recorder_(owned_recorder_.get()),
17 device_scale_factor_(device_scale_factor), 20 invalidation_(
18 invalidation_(invalidation) { 21 gfx::ScaleToEnclosingRect(invalidation, device_scale_factor)),
22 device_scale_factor_(device_scale_factor) {
19 #if DCHECK_IS_ON() 23 #if DCHECK_IS_ON()
20 root_visited_ = nullptr; 24 root_visited_ = nullptr;
21 inside_paint_recorder_ = false; 25 inside_paint_recorder_ = false;
22 #endif 26 #endif
23 } 27 }
24 28
25 PaintContext::PaintContext(const PaintContext& other, 29 PaintContext::PaintContext(const PaintContext& other,
26 const gfx::Vector2d& offset) 30 const gfx::Vector2d& offset)
27 : list_(other.list_), 31 : list_(other.list_),
28 owned_recorder_(nullptr), 32 owned_recorder_(nullptr),
29 recorder_(other.recorder_), 33 recorder_(other.recorder_),
30 device_scale_factor_(other.device_scale_factor_),
31 invalidation_(other.invalidation_), 34 invalidation_(other.invalidation_),
32 offset_(other.offset_ + offset) { 35 offset_(other.offset_ + offset),
36 device_scale_factor_(other.device_scale_factor_) {
33 #if DCHECK_IS_ON() 37 #if DCHECK_IS_ON()
34 root_visited_ = other.root_visited_; 38 root_visited_ = other.root_visited_;
35 inside_paint_recorder_ = other.inside_paint_recorder_; 39 inside_paint_recorder_ = other.inside_paint_recorder_;
36 #endif 40 #endif
37 } 41 }
38 42
39 PaintContext::PaintContext(const PaintContext& other, 43 PaintContext::PaintContext(const PaintContext& other,
40 CloneWithoutInvalidation c) 44 CloneWithoutInvalidation c)
41 : list_(other.list_), 45 : list_(other.list_),
42 owned_recorder_(nullptr), 46 owned_recorder_(nullptr),
43 recorder_(other.recorder_), 47 recorder_(other.recorder_),
44 device_scale_factor_(other.device_scale_factor_),
45 invalidation_(), 48 invalidation_(),
46 offset_(other.offset_) { 49 offset_(other.offset_),
50 device_scale_factor_(other.device_scale_factor_) {
47 #if DCHECK_IS_ON() 51 #if DCHECK_IS_ON()
48 root_visited_ = other.root_visited_; 52 root_visited_ = other.root_visited_;
49 inside_paint_recorder_ = other.inside_paint_recorder_; 53 inside_paint_recorder_ = other.inside_paint_recorder_;
50 #endif 54 #endif
51 } 55 }
52 56
53 PaintContext::~PaintContext() { 57 PaintContext::~PaintContext() {
54 } 58 }
55 59
60 gfx::Vector2dF PaintContext::CanvasScale() const {
61 return gfx::Vector2dF(
62 (float)(pixel_size_.width()) / size_.width(),
63 (float)(pixel_size_.height()) / size_.height());
64 }
65
66 gfx::Rect PaintContext::GetPixelBounds(const gfx::Rect& child_bounds) const {
67 float dsf = device_scale_factor();
68
69 int right = child_bounds.x() + child_bounds.width();
70 int bottom = child_bounds.y() + child_bounds.height();
71
72 int new_x = std::round(child_bounds.x() * dsf);
73 int new_y = std::round(child_bounds.y() * dsf);
74
75 int new_right;
76 int new_bottom;
77
78 if (right == size_.width()) {
79 new_right = pixel_size_.width();
80 } else {
81 new_right = std::round(right * dsf);
82 }
83 if (bottom == size_.height()) {
84 new_bottom = pixel_size_.height();
85 } else {
86 new_bottom = std::round(bottom * dsf);
87 }
88 return gfx::Rect(new_x, new_y, new_right - new_x, new_bottom - new_y);
89
90 }
91
92 void PaintContext::UpdateSizeAndDSF(const gfx::Size& pixel_size,
93 const gfx::Size& size) {
94 pixel_size_ = pixel_size;
95 size_ = size;
96 /*
97 device_scale_factor_x_ = (float)pixel_size.width() / (float)size.width();
98 device_scale_factor_y_ = (float)pixel_size.height() / (float)size.height();
99 LOG(ERROR) << "UpdateSize:" << device_scale_factor_x_;
100 if (device_scale_factor_x_ == 1.25) {
101 base::debug::StackTrace().Print();
102 }
103 */
104 }
105
56 gfx::Rect PaintContext::ToLayerSpaceBounds( 106 gfx::Rect PaintContext::ToLayerSpaceBounds(
57 const gfx::Size& size_in_context) const { 107 const gfx::Size& size_in_context) const {
58 return gfx::Rect(size_in_context) + offset_; 108 return gfx::Rect(size_in_context) + offset_;
59 } 109 }
60 110
61 gfx::Rect PaintContext::ToLayerSpaceRect(const gfx::Rect& rect) const { 111 gfx::Rect PaintContext::ToLayerSpaceRect(const gfx::Rect& rect) const {
62 return rect + offset_; 112 return rect + offset_;
63 } 113 }
64 114
65 } // namespace ui 115 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/paint_context.h ('k') | ui/compositor/paint_recorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698