| 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 <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" |
| 11 #include "cc/input/main_thread_scrolling_reason.h" | 11 #include "cc/input/main_thread_scrolling_reason.h" |
| 12 #include "cc/layers/painted_scrollbar_layer_impl.h" | 12 #include "cc/layers/painted_scrollbar_layer_impl.h" |
| 13 #include "cc/paint/paint_canvas.h" | |
| 14 #include "cc/paint/paint_flags.h" | 13 #include "cc/paint/paint_flags.h" |
| 14 #include "cc/paint/skia_paint_canvas.h" |
| 15 #include "cc/resources/ui_resource_bitmap.h" | 15 #include "cc/resources/ui_resource_bitmap.h" |
| 16 #include "cc/trees/draw_property_utils.h" | 16 #include "cc/trees/draw_property_utils.h" |
| 17 #include "cc/trees/layer_tree_host.h" | 17 #include "cc/trees/layer_tree_host.h" |
| 18 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 19 #include "skia/ext/platform_canvas.h" | 19 #include "skia/ext/platform_canvas.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 21 #include "third_party/skia/include/core/SkCanvas.h" | 21 #include "third_party/skia/include/core/SkCanvas.h" |
| 22 #include "third_party/skia/include/core/SkSize.h" | 22 #include "third_party/skia/include/core/SkSize.h" |
| 23 #include "ui/gfx/geometry/size_conversions.h" | 23 #include "ui/gfx/geometry/size_conversions.h" |
| 24 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 258 |
| 259 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( | 259 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( |
| 260 const gfx::Rect& layer_rect, | 260 const gfx::Rect& layer_rect, |
| 261 const gfx::Rect& content_rect, | 261 const gfx::Rect& content_rect, |
| 262 ScrollbarPart part) { | 262 ScrollbarPart part) { |
| 263 DCHECK(!content_rect.size().IsEmpty()); | 263 DCHECK(!content_rect.size().IsEmpty()); |
| 264 DCHECK(!layer_rect.size().IsEmpty()); | 264 DCHECK(!layer_rect.size().IsEmpty()); |
| 265 | 265 |
| 266 SkBitmap skbitmap; | 266 SkBitmap skbitmap; |
| 267 skbitmap.allocN32Pixels(content_rect.width(), content_rect.height()); | 267 skbitmap.allocN32Pixels(content_rect.width(), content_rect.height()); |
| 268 PaintCanvas canvas(skbitmap); | 268 SkiaPaintCanvas canvas(skbitmap); |
| 269 | 269 |
| 270 float scale_x = | 270 float scale_x = |
| 271 content_rect.width() / static_cast<float>(layer_rect.width()); | 271 content_rect.width() / static_cast<float>(layer_rect.width()); |
| 272 float scale_y = | 272 float scale_y = |
| 273 content_rect.height() / static_cast<float>(layer_rect.height()); | 273 content_rect.height() / static_cast<float>(layer_rect.height()); |
| 274 | 274 |
| 275 canvas.scale(SkFloatToScalar(scale_x), SkFloatToScalar(scale_y)); | 275 canvas.scale(SkFloatToScalar(scale_x), SkFloatToScalar(scale_y)); |
| 276 canvas.translate(SkFloatToScalar(-layer_rect.x()), | 276 canvas.translate(SkFloatToScalar(-layer_rect.x()), |
| 277 SkFloatToScalar(-layer_rect.y())); | 277 SkFloatToScalar(-layer_rect.y())); |
| 278 | 278 |
| 279 SkRect layer_skrect = RectToSkRect(layer_rect); | 279 SkRect layer_skrect = RectToSkRect(layer_rect); |
| 280 PaintFlags paint; | 280 PaintFlags paint; |
| 281 paint.setAntiAlias(false); | 281 paint.setAntiAlias(false); |
| 282 paint.setBlendMode(SkBlendMode::kClear); | 282 paint.setBlendMode(SkBlendMode::kClear); |
| 283 canvas.drawRect(layer_skrect, paint); | 283 canvas.drawRect(layer_skrect, paint); |
| 284 canvas.clipRect(layer_skrect); | 284 canvas.clipRect(layer_skrect); |
| 285 | 285 |
| 286 scrollbar_->PaintPart(&canvas, part, layer_rect); | 286 scrollbar_->PaintPart(&canvas, part, layer_rect); |
| 287 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 287 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
| 288 // allocation and copying. | 288 // allocation and copying. |
| 289 skbitmap.setImmutable(); | 289 skbitmap.setImmutable(); |
| 290 | 290 |
| 291 return UIResourceBitmap(skbitmap); | 291 return UIResourceBitmap(skbitmap); |
| 292 } | 292 } |
| 293 | 293 |
| 294 } // namespace cc | 294 } // namespace cc |
| OLD | NEW |