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

Side by Side Diff: cc/layers/painted_scrollbar_layer.cc

Issue 2276633003: Move scaling of ui resources for scrollbars to the time of upload (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scrollbarpixeltests
Patch Set: uploadscale: fixmath Created 4 years, 3 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 | « cc/layers/painted_scrollbar_layer.h ('k') | cc/layers/scrollbar_layer_unittest.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "cc/layers/painted_scrollbar_layer.h" 5 #include "cc/layers/painted_scrollbar_layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "cc/base/math_util.h" 10 #include "cc/base/math_util.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 bool PaintedScrollbarLayer::AlwaysUseActiveTreeOpacity() const { 73 bool PaintedScrollbarLayer::AlwaysUseActiveTreeOpacity() const {
74 return true; 74 return true;
75 } 75 }
76 76
77 ScrollbarOrientation PaintedScrollbarLayer::orientation() const { 77 ScrollbarOrientation PaintedScrollbarLayer::orientation() const {
78 return scrollbar_->Orientation(); 78 return scrollbar_->Orientation();
79 } 79 }
80 80
81 int PaintedScrollbarLayer::MaxTextureSize() {
82 DCHECK(layer_tree_host());
83 return layer_tree_host()->GetRendererCapabilities().max_texture_size;
84 }
85
86 float PaintedScrollbarLayer::ClampScaleToMaxTextureSize(float scale) {
87 // If the scaled bounds() is bigger than the max texture size of the
88 // device, we need to clamp it by rescaling, since this is used
89 // below to set the texture size.
90 gfx::Size scaled_bounds = gfx::ScaleToCeiledSize(bounds(), scale);
91 if (scaled_bounds.width() > MaxTextureSize() ||
92 scaled_bounds.height() > MaxTextureSize()) {
93 if (bounds().width() > bounds().height())
94 return (MaxTextureSize() - 1) / static_cast<float>(bounds().width());
95 else
96 return (MaxTextureSize() - 1) / static_cast<float>(bounds().height());
97 }
98 return scale;
99 }
100
101 void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { 81 void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) {
102 Layer::PushPropertiesTo(layer); 82 Layer::PushPropertiesTo(layer);
103 83
104 PaintedScrollbarLayerImpl* scrollbar_layer = 84 PaintedScrollbarLayerImpl* scrollbar_layer =
105 static_cast<PaintedScrollbarLayerImpl*>(layer); 85 static_cast<PaintedScrollbarLayerImpl*>(layer);
106 86
107 scrollbar_layer->SetScrollLayerId(scroll_layer_id_); 87 scrollbar_layer->SetScrollLayerId(scroll_layer_id_);
108 scrollbar_layer->set_internal_contents_scale_and_bounds( 88 scrollbar_layer->set_internal_contents_scale_and_bounds(
109 internal_contents_scale_, internal_content_bounds_); 89 internal_contents_scale_, internal_content_bounds_);
110 90
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 .layer_transforms_should_scale_layer_contents) { 175 .layer_transforms_should_scale_layer_contents) {
196 gfx::Transform transform; 176 gfx::Transform transform;
197 transform = draw_property_utils::ScreenSpaceTransform( 177 transform = draw_property_utils::ScreenSpaceTransform(
198 this, GetLayerTree()->property_trees()->transform_tree); 178 this, GetLayerTree()->property_trees()->transform_tree);
199 179
200 gfx::Vector2dF transform_scales = 180 gfx::Vector2dF transform_scales =
201 MathUtil::ComputeTransform2dScaleComponents(transform, scale); 181 MathUtil::ComputeTransform2dScaleComponents(transform, scale);
202 scale = std::max(transform_scales.x(), transform_scales.y()); 182 scale = std::max(transform_scales.x(), transform_scales.y());
203 } 183 }
204 bool changed = false; 184 bool changed = false;
205 changed |= UpdateProperty(ClampScaleToMaxTextureSize(scale), 185 changed |= UpdateProperty(scale, &internal_contents_scale_);
206 &internal_contents_scale_);
207 changed |= 186 changed |=
208 UpdateProperty(gfx::ScaleToCeiledSize(bounds(), internal_contents_scale_), 187 UpdateProperty(gfx::ScaleToCeiledSize(bounds(), internal_contents_scale_),
209 &internal_content_bounds_); 188 &internal_content_bounds_);
210 if (changed) { 189 if (changed) {
211 // If the content scale or bounds change, repaint. 190 // If the content scale or bounds change, repaint.
212 SetNeedsDisplay(); 191 SetNeedsDisplay();
213 } 192 }
214 } 193 }
215 194
216 bool PaintedScrollbarLayer::Update() { 195 bool PaintedScrollbarLayer::Update() {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 283
305 scrollbar_->PaintPart(&skcanvas, part, layer_rect); 284 scrollbar_->PaintPart(&skcanvas, part, layer_rect);
306 // Make sure that the pixels are no longer mutable to unavoid unnecessary 285 // Make sure that the pixels are no longer mutable to unavoid unnecessary
307 // allocation and copying. 286 // allocation and copying.
308 skbitmap.setImmutable(); 287 skbitmap.setImmutable();
309 288
310 return UIResourceBitmap(skbitmap); 289 return UIResourceBitmap(skbitmap);
311 } 290 }
312 291
313 } // namespace cc 292 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/painted_scrollbar_layer.h ('k') | cc/layers/scrollbar_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698