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

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

Issue 1560403002: Scale scrollbar in use-zoom-for-dsf mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
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 "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 return updated; 272 return updated;
273 } 273 }
274 274
275 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( 275 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart(
276 const gfx::Rect& layer_rect, 276 const gfx::Rect& layer_rect,
277 const gfx::Rect& content_rect, 277 const gfx::Rect& content_rect,
278 ScrollbarPart part) { 278 ScrollbarPart part) {
279 DCHECK(!content_rect.size().IsEmpty()); 279 DCHECK(!content_rect.size().IsEmpty());
280 DCHECK(!layer_rect.size().IsEmpty()); 280 DCHECK(!layer_rect.size().IsEmpty());
281 281
282 // If zoom is used to scale the content for device scale factor,
283 // convert the size of layer_rect to DIP so that it will generate
284 // the image for scaled scrollbar.
285 float scale = 1.0f / layer_tree_host()->painted_device_scale_factor();
286 gfx::Rect adjusted_layer_rect(
skobes 2016/01/07 21:49:10 "scaled_layer_rect" is clearer
oshima 2016/01/09 00:58:39 I used adjusted because its origin isn't scaled. I
287 layer_rect.origin(),
skobes 2016/01/07 21:49:10 Don't we need to scale the origin as well? I assu
oshima 2016/01/09 00:58:39 This is correct. We want to scale the size only an
288 gfx::ScaleToFlooredSize(layer_rect.size(), scale, scale));
289
282 SkBitmap skbitmap; 290 SkBitmap skbitmap;
283 skbitmap.allocN32Pixels(content_rect.width(), content_rect.height()); 291 skbitmap.allocN32Pixels(content_rect.width(), content_rect.height());
284 SkCanvas skcanvas(skbitmap); 292 SkCanvas skcanvas(skbitmap);
285 293
286 float scale_x = 294 float scale_x =
287 content_rect.width() / static_cast<float>(layer_rect.width()); 295 content_rect.width() / static_cast<float>(adjusted_layer_rect.width());
288 float scale_y = 296 float scale_y =
289 content_rect.height() / static_cast<float>(layer_rect.height()); 297 content_rect.height() / static_cast<float>(adjusted_layer_rect.height());
290 298
291 skcanvas.scale(SkFloatToScalar(scale_x), 299 skcanvas.scale(SkFloatToScalar(scale_x),
292 SkFloatToScalar(scale_y)); 300 SkFloatToScalar(scale_y));
293 skcanvas.translate(SkFloatToScalar(-layer_rect.x()), 301 skcanvas.translate(SkFloatToScalar(-adjusted_layer_rect.x()),
294 SkFloatToScalar(-layer_rect.y())); 302 SkFloatToScalar(-adjusted_layer_rect.y()));
295 303
296 SkRect layer_skrect = RectToSkRect(layer_rect); 304 SkRect layer_skrect = RectToSkRect(adjusted_layer_rect);
297 SkPaint paint; 305 SkPaint paint;
298 paint.setAntiAlias(false); 306 paint.setAntiAlias(false);
299 paint.setXfermodeMode(SkXfermode::kClear_Mode); 307 paint.setXfermodeMode(SkXfermode::kClear_Mode);
300 skcanvas.drawRect(layer_skrect, paint); 308 skcanvas.drawRect(layer_skrect, paint);
301 skcanvas.clipRect(layer_skrect); 309 skcanvas.clipRect(layer_skrect);
302 310
303 scrollbar_->PaintPart(&skcanvas, part, layer_rect); 311 scrollbar_->PaintPart(&skcanvas, part, adjusted_layer_rect);
304 // Make sure that the pixels are no longer mutable to unavoid unnecessary 312 // Make sure that the pixels are no longer mutable to unavoid unnecessary
305 // allocation and copying. 313 // allocation and copying.
306 skbitmap.setImmutable(); 314 skbitmap.setImmutable();
307 315
308 return UIResourceBitmap(skbitmap); 316 return UIResourceBitmap(skbitmap);
309 } 317 }
310 318
311 } // namespace cc 319 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/trees/layer_tree_host.h » ('j') | third_party/WebKit/Source/platform/scroll/Scrollbar.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698