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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 240 } |
241 | 241 |
242 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( | 242 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( |
243 const gfx::Rect& layer_rect, | 243 const gfx::Rect& layer_rect, |
244 const gfx::Rect& content_rect, | 244 const gfx::Rect& content_rect, |
245 ScrollbarPart part) { | 245 ScrollbarPart part) { |
246 DCHECK(!content_rect.size().IsEmpty()); | 246 DCHECK(!content_rect.size().IsEmpty()); |
247 DCHECK(!layer_rect.size().IsEmpty()); | 247 DCHECK(!layer_rect.size().IsEmpty()); |
248 | 248 |
249 SkBitmap skbitmap; | 249 SkBitmap skbitmap; |
250 skbitmap.setConfig(SkBitmap::kARGB_8888_Config, | 250 skbitmap.allocN32Pixels(content_rect.width(), content_rect.height()); |
251 content_rect.width(), | |
252 content_rect.height()); | |
253 skbitmap.allocPixels(); | |
254 | |
255 SkCanvas skcanvas(skbitmap); | 251 SkCanvas skcanvas(skbitmap); |
256 | 252 |
257 float scale_x = | 253 float scale_x = |
258 content_rect.width() / static_cast<float>(layer_rect.width()); | 254 content_rect.width() / static_cast<float>(layer_rect.width()); |
259 float scale_y = | 255 float scale_y = |
260 content_rect.height() / static_cast<float>(layer_rect.height()); | 256 content_rect.height() / static_cast<float>(layer_rect.height()); |
261 | 257 |
262 skcanvas.scale(SkFloatToScalar(scale_x), | 258 skcanvas.scale(SkFloatToScalar(scale_x), |
263 SkFloatToScalar(scale_y)); | 259 SkFloatToScalar(scale_y)); |
264 skcanvas.translate(SkFloatToScalar(-layer_rect.x()), | 260 skcanvas.translate(SkFloatToScalar(-layer_rect.x()), |
265 SkFloatToScalar(-layer_rect.y())); | 261 SkFloatToScalar(-layer_rect.y())); |
266 | 262 |
267 SkRect layer_skrect = RectToSkRect(layer_rect); | 263 SkRect layer_skrect = RectToSkRect(layer_rect); |
268 SkPaint paint; | 264 SkPaint paint; |
269 paint.setAntiAlias(false); | 265 paint.setAntiAlias(false); |
270 paint.setXfermodeMode(SkXfermode::kClear_Mode); | 266 paint.setXfermodeMode(SkXfermode::kClear_Mode); |
271 skcanvas.drawRect(layer_skrect, paint); | 267 skcanvas.drawRect(layer_skrect, paint); |
272 skcanvas.clipRect(layer_skrect); | 268 skcanvas.clipRect(layer_skrect); |
273 | 269 |
274 scrollbar_->PaintPart(&skcanvas, part, layer_rect); | 270 scrollbar_->PaintPart(&skcanvas, part, layer_rect); |
275 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 271 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
276 // allocation and copying. | 272 // allocation and copying. |
277 skbitmap.setImmutable(); | 273 skbitmap.setImmutable(); |
278 | 274 |
279 return UIResourceBitmap(skbitmap); | 275 return UIResourceBitmap(skbitmap); |
280 } | 276 } |
281 | 277 |
282 } // namespace cc | 278 } // namespace cc |
OLD | NEW |