OLD | NEW |
---|---|
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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "cc/layers/painted_scrollbar_layer_impl.h" | 10 #include "cc/layers/painted_scrollbar_layer_impl.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( | 237 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( |
238 const gfx::Rect& rect, | 238 const gfx::Rect& rect, |
239 ScrollbarPart part) { | 239 ScrollbarPart part) { |
240 DCHECK(!rect.size().IsEmpty()); | 240 DCHECK(!rect.size().IsEmpty()); |
241 | 241 |
242 SkBitmap skbitmap; | 242 SkBitmap skbitmap; |
243 skbitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); | 243 skbitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); |
244 skbitmap.allocPixels(); | 244 skbitmap.allocPixels(); |
245 | 245 |
246 SkCanvas skcanvas(skbitmap); | 246 SkCanvas skcanvas(skbitmap); |
247 skcanvas.translate(SkFloatToScalar(-rect.x()), SkFloatToScalar(-rect.y())); | 247 |
248 // Skia will round to the nearest pixel on scaling, so we need to take that | |
249 // into account when translating back to the origin. | |
250 float adjustmentX = round(location_.x() * contents_scale_x()); | |
danakj
2014/01/31 18:58:43
Using location_ here looks wrong, the input |rect|
bokan
2014/01/31 19:00:40
yikes! You're right, I'll think about this some mo
| |
251 float adjustmentY = round(location_.y() * contents_scale_y()); | |
252 skcanvas.translate(SkFloatToScalar(-adjustmentX), | |
253 SkFloatToScalar(-adjustmentY)); | |
248 skcanvas.scale(SkFloatToScalar(contents_scale_x()), | 254 skcanvas.scale(SkFloatToScalar(contents_scale_x()), |
249 SkFloatToScalar(contents_scale_y())); | 255 SkFloatToScalar(contents_scale_y())); |
250 | 256 |
251 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( | 257 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( |
252 rect, 1.f / contents_scale_x(), 1.f / contents_scale_y()); | 258 rect, 1.f / contents_scale_x(), 1.f / contents_scale_y()); |
253 SkRect layer_skrect = RectToSkRect(layer_rect); | 259 SkRect layer_skrect = RectToSkRect(layer_rect); |
254 SkPaint paint; | 260 SkPaint paint; |
255 paint.setAntiAlias(false); | 261 paint.setAntiAlias(false); |
256 paint.setXfermodeMode(SkXfermode::kClear_Mode); | 262 paint.setXfermodeMode(SkXfermode::kClear_Mode); |
257 skcanvas.drawRect(layer_skrect, paint); | 263 skcanvas.drawRect(layer_skrect, paint); |
258 skcanvas.clipRect(layer_skrect); | 264 skcanvas.clipRect(layer_skrect); |
259 | 265 |
260 scrollbar_->PaintPart(&skcanvas, part, layer_rect); | 266 scrollbar_->PaintPart(&skcanvas, part, layer_rect); |
261 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 267 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
262 // allocation and copying. | 268 // allocation and copying. |
263 skbitmap.setImmutable(); | 269 skbitmap.setImmutable(); |
264 | 270 |
265 return UIResourceBitmap(skbitmap); | 271 return UIResourceBitmap(skbitmap); |
266 } | 272 } |
267 | 273 |
268 } // namespace cc | 274 } // namespace cc |
OLD | NEW |