| 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/rect_conversions.h" |
| 21 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 22 #include "ui/gfx/size_conversions.h" |
| 22 #include "ui/gfx/skbitmap_operations.h" | 23 #include "ui/gfx/skbitmap_operations.h" |
| 23 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
| 24 | 25 |
| 25 namespace gfx { | 26 namespace gfx { |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 bool ScalingEnabled() { | 29 bool ScalingEnabled() { |
| 29 static bool scale_images = !CommandLine::ForCurrentProcess()->HasSwitch( | 30 static bool scale_images = !CommandLine::ForCurrentProcess()->HasSwitch( |
| 30 switches::kDisableScalingInImageSkiaOperations); | 31 switches::kDisableScalingInImageSkiaOperations); |
| 31 return scale_images; | 32 return scale_images; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 virtual ~ResizeSource() {} | 319 virtual ~ResizeSource() {} |
| 319 | 320 |
| 320 // gfx::ImageSkiaSource overrides: | 321 // gfx::ImageSkiaSource overrides: |
| 321 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 322 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| 322 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); | 323 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); |
| 323 if (image_rep.GetWidth() == target_dip_size_.width() && | 324 if (image_rep.GetWidth() == target_dip_size_.width() && |
| 324 image_rep.GetHeight() == target_dip_size_.height()) | 325 image_rep.GetHeight() == target_dip_size_.height()) |
| 325 return image_rep; | 326 return image_rep; |
| 326 | 327 |
| 327 const float scale = ui::GetScaleFactorScale(scale_factor); | 328 const float scale = ui::GetScaleFactorScale(scale_factor); |
| 328 const Size target_pixel_size(target_dip_size_.Scale(scale)); | 329 const Size target_pixel_size = gfx::ToFlooredSize( |
| 330 target_dip_size_.Scale(scale)); |
| 329 const SkBitmap resized = skia::ImageOperations::Resize( | 331 const SkBitmap resized = skia::ImageOperations::Resize( |
| 330 image_rep.sk_bitmap(), | 332 image_rep.sk_bitmap(), |
| 331 resize_method_, | 333 resize_method_, |
| 332 target_pixel_size.width(), | 334 target_pixel_size.width(), |
| 333 target_pixel_size.height()); | 335 target_pixel_size.height()); |
| 334 return ImageSkiaRep(resized, scale_factor); | 336 return ImageSkiaRep(resized, scale_factor); |
| 335 } | 337 } |
| 336 | 338 |
| 337 private: | 339 private: |
| 338 const ImageSkia source_; | 340 const ImageSkia source_; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 const ImageSkia& source, | 453 const ImageSkia& source, |
| 452 const ShadowValues& shadows) { | 454 const ShadowValues& shadows) { |
| 453 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); | 455 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); |
| 454 gfx::Size shadow_image_size = source.size(); | 456 gfx::Size shadow_image_size = source.size(); |
| 455 shadow_image_size.Enlarge(shadow_padding.width(), | 457 shadow_image_size.Enlarge(shadow_padding.width(), |
| 456 shadow_padding.height()); | 458 shadow_padding.height()); |
| 457 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); | 459 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); |
| 458 } | 460 } |
| 459 | 461 |
| 460 } // namespace gfx | 462 } // namespace gfx |
| OLD | NEW |