Chromium Code Reviews| 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" |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 skia::ImageOperations::ResizeMethod method, | 313 skia::ImageOperations::ResizeMethod method, |
| 314 const Size& target_dip_size) | 314 const Size& target_dip_size) |
| 315 : source_(source), | 315 : source_(source), |
| 316 resize_method_(method), | 316 resize_method_(method), |
| 317 target_dip_size_(target_dip_size) { | 317 target_dip_size_(target_dip_size) { |
| 318 } | 318 } |
| 319 virtual ~ResizeSource() {} | 319 virtual ~ResizeSource() {} |
| 320 | 320 |
| 321 // gfx::ImageSkiaSource overrides: | 321 // gfx::ImageSkiaSource overrides: |
| 322 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | 322 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| 323 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); | |
| 324 if (image_rep.GetWidth() == target_dip_size_.width() && | |
| 325 image_rep.GetHeight() == target_dip_size_.height()) | |
| 326 return image_rep; | |
| 327 | |
| 328 const float scale = ui::GetScaleFactorScale(scale_factor); | 323 const float scale = ui::GetScaleFactorScale(scale_factor); |
| 329 const Size target_pixel_size = gfx::ToFlooredSize( | 324 const Size target_pixel_size = gfx::ToFlooredSize( |
| 330 target_dip_size_.Scale(scale)); | 325 target_dip_size_.Scale(scale)); |
| 326 | |
| 327 const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); | |
| 328 | |
| 329 if (image_rep.pixel_width() == target_pixel_size.width() && | |
| 330 image_rep.pixel_height() == target_pixel_size.height()) { | |
| 331 if (image_rep.scale_factor() == scale_factor) | |
|
pkotwicz
2012/10/17 18:42:20
Nit: I think you can include this if as part of th
tbarzic
2012/10/17 19:00:46
yeah, but in that case we could call skia::ImageOp
pkotwicz
2012/10/17 19:13:29
Sorry I should have seen that. You can if you want
tbarzic
2012/10/17 19:15:42
ok, Done.
| |
| 332 return image_rep; | |
| 333 return ImageSkiaRep(image_rep.sk_bitmap(), scale_factor); | |
| 334 } | |
| 335 | |
| 331 const SkBitmap resized = skia::ImageOperations::Resize( | 336 const SkBitmap resized = skia::ImageOperations::Resize( |
| 332 image_rep.sk_bitmap(), | 337 image_rep.sk_bitmap(), |
| 333 resize_method_, | 338 resize_method_, |
| 334 target_pixel_size.width(), | 339 target_pixel_size.width(), |
| 335 target_pixel_size.height()); | 340 target_pixel_size.height()); |
| 336 return ImageSkiaRep(resized, scale_factor); | 341 return ImageSkiaRep(resized, scale_factor); |
| 337 } | 342 } |
| 338 | 343 |
| 339 private: | 344 private: |
| 340 const ImageSkia source_; | 345 const ImageSkia source_; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 // static | 447 // static |
| 443 ImageSkia ImageSkiaOperations::CreateResizedImage( | 448 ImageSkia ImageSkiaOperations::CreateResizedImage( |
| 444 const ImageSkia& source, | 449 const ImageSkia& source, |
| 445 skia::ImageOperations::ResizeMethod method, | 450 skia::ImageOperations::ResizeMethod method, |
| 446 const Size& target_dip_size) { | 451 const Size& target_dip_size) { |
| 447 return ImageSkia(new ResizeSource(source, method, target_dip_size), | 452 return ImageSkia(new ResizeSource(source, method, target_dip_size), |
| 448 target_dip_size); | 453 target_dip_size); |
| 449 } | 454 } |
| 450 | 455 |
| 451 // static | 456 // static |
| 457 ImageSkia ImageSkiaOperations::SetFallbackResizeMethod( | |
| 458 const ImageSkia& source, | |
| 459 skia::ImageOperations::ResizeMethod method) { | |
| 460 return ImageSkia(new ResizeSource(source, method, source.size()), | |
| 461 source.size()); | |
| 462 } | |
| 463 | |
| 464 // static | |
| 452 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow( | 465 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow( |
| 453 const ImageSkia& source, | 466 const ImageSkia& source, |
| 454 const ShadowValues& shadows) { | 467 const ShadowValues& shadows) { |
| 455 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); | 468 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); |
| 456 gfx::Size shadow_image_size = source.size(); | 469 gfx::Size shadow_image_size = source.size(); |
| 457 shadow_image_size.Enlarge(shadow_padding.width(), | 470 shadow_image_size.Enlarge(shadow_padding.width(), |
| 458 shadow_padding.height()); | 471 shadow_padding.height()); |
| 459 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); | 472 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); |
| 460 } | 473 } |
| 461 | 474 |
| 462 } // namespace gfx | 475 } // namespace gfx |
| OLD | NEW |