| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/gfx/image/image_skia_operations.h" | 5 #include "ui/gfx/image/image_skia_operations.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "skia/ext/image_operations.h" | 9 #include "skia/ext/image_operations.h" |
| 10 #include "skia/ext/platform_canvas.h" | 10 #include "skia/ext/platform_canvas.h" |
| 11 #include "ui/base/layout.h" | 11 #include "ui/base/layout.h" |
| 12 #include "ui/base/ui_base_switches.h" | 12 #include "ui/base/ui_base_switches.h" |
| 13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 14 #include "ui/gfx/image/canvas_image_source.h" | 14 #include "ui/gfx/image/canvas_image_source.h" |
| 15 #include "ui/gfx/image/image_skia.h" | 15 #include "ui/gfx/image/image_skia.h" |
| 16 #include "ui/gfx/image/image_skia_rep.h" | 16 #include "ui/gfx/image/image_skia_rep.h" |
| 17 #include "ui/gfx/image/image_skia_source.h" | 17 #include "ui/gfx/image/image_skia_source.h" |
| 18 #include "ui/gfx/insets.h" | 18 #include "ui/gfx/insets.h" |
| 19 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| 20 #include "ui/gfx/rect_conversions.h" |
| 20 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 21 #include "ui/gfx/skbitmap_operations.h" | 22 #include "ui/gfx/skbitmap_operations.h" |
| 22 #include "ui/gfx/skia_util.h" | 23 #include "ui/gfx/skia_util.h" |
| 23 | 24 |
| 24 namespace gfx { | 25 namespace gfx { |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 bool ScalingEnabled() { | 28 bool ScalingEnabled() { |
| 28 static bool scale_images = !CommandLine::ForCurrentProcess()->HasSwitch( | 29 static bool scale_images = !CommandLine::ForCurrentProcess()->HasSwitch( |
| 29 switches::kDisableScalingInImageSkiaOperations); | 30 switches::kDisableScalingInImageSkiaOperations); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 : image_(image), | 280 : image_(image), |
| 280 subset_bounds_(subset_bounds) { | 281 subset_bounds_(subset_bounds) { |
| 281 } | 282 } |
| 282 | 283 |
| 283 virtual ~ExtractSubsetImageSource() { | 284 virtual ~ExtractSubsetImageSource() { |
| 284 } | 285 } |
| 285 | 286 |
| 286 // gfx::ImageSkiaSource overrides: | 287 // gfx::ImageSkiaSource overrides: |
| 287 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 288 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| 288 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); | 289 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); |
| 289 SkIRect subset_bounds_in_pixel = RectToSkIRect(subset_bounds_.Scale( | 290 SkIRect subset_bounds_in_pixel = RectToSkIRect( |
| 290 ui::GetScaleFactorScale(image_rep.scale_factor()))); | 291 ToEnclosingRect(subset_bounds_.Scale( |
| 292 ui::GetScaleFactorScale(image_rep.scale_factor())))); |
| 291 SkBitmap dst; | 293 SkBitmap dst; |
| 292 bool success = image_rep.sk_bitmap().extractSubset(&dst, | 294 bool success = image_rep.sk_bitmap().extractSubset(&dst, |
| 293 subset_bounds_in_pixel); | 295 subset_bounds_in_pixel); |
| 294 DCHECK(success); | 296 DCHECK(success); |
| 295 return gfx::ImageSkiaRep(dst, image_rep.scale_factor()); | 297 return gfx::ImageSkiaRep(dst, image_rep.scale_factor()); |
| 296 } | 298 } |
| 297 | 299 |
| 298 private: | 300 private: |
| 299 const gfx::ImageSkia image_; | 301 const gfx::ImageSkia image_; |
| 300 const gfx::Rect subset_bounds_; | 302 const gfx::Rect subset_bounds_; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 const ImageSkia& source, | 451 const ImageSkia& source, |
| 450 const ShadowValues& shadows) { | 452 const ShadowValues& shadows) { |
| 451 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); | 453 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); |
| 452 gfx::Size shadow_image_size = source.size(); | 454 gfx::Size shadow_image_size = source.size(); |
| 453 shadow_image_size.Enlarge(shadow_padding.width(), | 455 shadow_image_size.Enlarge(shadow_padding.width(), |
| 454 shadow_padding.height()); | 456 shadow_padding.height()); |
| 455 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); | 457 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); |
| 456 } | 458 } |
| 457 | 459 |
| 458 } // namespace gfx | 460 } // namespace gfx |
| OLD | NEW |