Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/compositor/compositor_switches.h" | |
| 7 #include "ui/gfx/canvas.h" | 8 #include "ui/gfx/canvas.h" |
| 9 #include "ui/gfx/transform.h" | |
| 8 | 10 |
| 9 namespace ui { | 11 namespace ui { |
| 10 | 12 |
| 11 PaintContext::PaintContext(cc::DisplayItemList* list, | 13 PaintContext::PaintContext(cc::DisplayItemList* list, |
| 12 float device_scale_factor, | 14 float device_scale_factor, |
| 13 const gfx::Rect& invalidation) | 15 const gfx::Rect& invalidation, |
| 16 const gfx::Size& size) | |
|
danakj
2017/07/19 17:00:59
I was thinking about this and wondering if the rea
| |
| 14 : list_(list), | 17 : list_(list), |
| 15 device_scale_factor_(device_scale_factor), | 18 device_scale_factor_(device_scale_factor), |
| 16 invalidation_(invalidation) { | 19 paint_recording_scale_x_(IsPixelCanvas() ? device_scale_factor_ : 1.f), |
| 20 paint_recording_scale_y_(paint_recording_scale_x_), | |
| 21 invalidation_( | |
| 22 gfx::ScaleToEnclosingRect(invalidation, paint_recording_scale_x_)), | |
| 23 paint_recording_bounds_( | |
| 24 gfx::ScaleToRoundedRect(gfx::Rect(size), paint_recording_scale_x_)) { | |
| 25 ComputePaintRecordingScales(size); | |
| 17 #if DCHECK_IS_ON() | 26 #if DCHECK_IS_ON() |
| 18 root_visited_ = nullptr; | 27 root_visited_ = nullptr; |
| 19 inside_paint_recorder_ = false; | 28 inside_paint_recorder_ = false; |
| 20 #endif | 29 #endif |
| 21 } | 30 } |
| 22 | 31 |
| 23 PaintContext::PaintContext(const PaintContext& other, | 32 PaintContext::PaintContext(const PaintContext& other, |
| 24 const gfx::Vector2d& offset) | 33 const gfx::Rect& bounds, |
| 34 const gfx::Rect& parent_bounds, | |
| 35 ScaleType scale_type) | |
| 25 : list_(other.list_), | 36 : list_(other.list_), |
| 26 device_scale_factor_(other.device_scale_factor_), | 37 device_scale_factor_(other.device_scale_factor_), |
| 27 invalidation_(other.invalidation_), | 38 invalidation_(other.invalidation_), |
| 28 offset_(other.offset_ + offset) { | 39 paint_recording_bounds_( |
| 40 other.GetSnappedRecordingBounds(parent_bounds, bounds)), | |
| 41 scale_type_(scale_type) { | |
| 42 ComputePaintRecordingScales(bounds.size()); | |
| 29 #if DCHECK_IS_ON() | 43 #if DCHECK_IS_ON() |
| 30 root_visited_ = other.root_visited_; | 44 root_visited_ = other.root_visited_; |
| 31 inside_paint_recorder_ = other.inside_paint_recorder_; | 45 inside_paint_recorder_ = other.inside_paint_recorder_; |
| 32 #endif | 46 #endif |
| 33 } | 47 } |
| 34 | 48 |
| 35 PaintContext::PaintContext(const PaintContext& other, | 49 PaintContext::PaintContext(const PaintContext& other, |
| 36 CloneWithoutInvalidation c) | 50 CloneWithoutInvalidation c) |
| 37 : list_(other.list_), | 51 : list_(other.list_), |
| 38 device_scale_factor_(other.device_scale_factor_), | 52 device_scale_factor_(other.device_scale_factor_), |
| 53 paint_recording_scale_x_(other.paint_recording_scale_x_), | |
| 54 paint_recording_scale_y_(other.paint_recording_scale_y_), | |
| 39 invalidation_(), | 55 invalidation_(), |
| 40 offset_(other.offset_) { | 56 paint_recording_bounds_(other.paint_recording_bounds_) { |
| 41 #if DCHECK_IS_ON() | 57 #if DCHECK_IS_ON() |
| 42 root_visited_ = other.root_visited_; | 58 root_visited_ = other.root_visited_; |
| 43 inside_paint_recorder_ = other.inside_paint_recorder_; | 59 inside_paint_recorder_ = other.inside_paint_recorder_; |
| 44 #endif | 60 #endif |
| 45 } | 61 } |
| 46 | 62 |
| 47 PaintContext::~PaintContext() { | 63 PaintContext::~PaintContext() { |
| 48 } | 64 } |
| 49 | 65 |
| 50 gfx::Rect PaintContext::ToLayerSpaceBounds( | 66 gfx::Rect PaintContext::ToLayerSpaceBounds( |
| 51 const gfx::Size& size_in_context) const { | 67 const gfx::Size& size_in_context) const { |
| 52 return gfx::Rect(size_in_context) + offset_; | 68 return gfx::Rect(paint_recording_bounds_.origin(), size_in_context); |
| 53 } | 69 } |
| 54 | 70 |
| 55 gfx::Rect PaintContext::ToLayerSpaceRect(const gfx::Rect& rect) const { | 71 void PaintContext::ComputePaintRecordingScales(const gfx::Size& size) { |
| 56 return rect + offset_; | 72 if (!IsPixelCanvas()) { |
| 73 // If pixel canvas is disabled, all recordings are done in DIPs. These are | |
| 74 // later played back on to the raster canvas at |device_scale_factor_|. | |
| 75 paint_recording_scale_x_ = paint_recording_scale_y_ = 1.f; | |
| 76 return; | |
| 77 } | |
| 78 | |
| 79 paint_recording_scale_x_ = paint_recording_scale_y_ = device_scale_factor_; | |
| 80 if (scale_type_ == ScaleType::SCALE_TO_SCALE_FACTOR) | |
| 81 return; | |
| 82 | |
| 83 if (size.width() > 0) { | |
| 84 paint_recording_scale_x_ = | |
| 85 static_cast<float>(paint_recording_bounds_.width()) / | |
| 86 static_cast<float>(size.width()); | |
| 87 } | |
| 88 | |
| 89 if (size.height() > 0) { | |
| 90 paint_recording_scale_y_ = | |
| 91 static_cast<float>(paint_recording_bounds_.height()) / | |
| 92 static_cast<float>(size.height()); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 bool PaintContext::IsPixelCanvas() const { | |
| 97 return IsPixelCanvasRecordingEnabled(); | |
| 98 } | |
| 99 | |
| 100 gfx::Rect PaintContext::GetSnappedRecordingBounds( | |
| 101 const gfx::Rect& parent_bounds, | |
| 102 const gfx::Rect& child_bounds) const { | |
| 103 if (!IsPixelCanvas()) | |
| 104 return (child_bounds + paint_recording_bounds().OffsetFromOrigin()); | |
| 105 | |
| 106 const gfx::Vector2d& child_origin = child_bounds.OffsetFromOrigin(); | |
| 107 | |
| 108 int right = child_origin.x() + child_bounds.width(); | |
| 109 int bottom = child_origin.y() + child_bounds.height(); | |
| 110 | |
| 111 int new_x = std::round(child_origin.x() * device_scale_factor_); | |
| 112 int new_y = std::round(child_origin.y() * device_scale_factor_); | |
| 113 | |
| 114 int new_right; | |
| 115 int new_bottom; | |
| 116 | |
| 117 if (right == parent_bounds.width()) { | |
| 118 new_right = paint_recording_bounds_.width(); | |
| 119 } else { | |
| 120 new_right = std::round(right * device_scale_factor_); | |
| 121 } | |
| 122 | |
| 123 if (bottom == parent_bounds.height()) { | |
| 124 new_bottom = paint_recording_bounds_.height(); | |
| 125 } else { | |
| 126 new_bottom = std::round(bottom * device_scale_factor_); | |
| 127 } | |
| 128 return gfx::Rect(new_x + paint_recording_bounds().x(), | |
| 129 new_y + paint_recording_bounds().y(), new_right - new_x, | |
| 130 new_bottom - new_y); | |
| 57 } | 131 } |
| 58 | 132 |
| 59 } // namespace ui | 133 } // namespace ui |
| OLD | NEW |