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 return ImageSkiaRep(image_rep.sk_bitmap(), scale_factor); |
| 332 } |
| 333 |
331 const SkBitmap resized = skia::ImageOperations::Resize( | 334 const SkBitmap resized = skia::ImageOperations::Resize( |
332 image_rep.sk_bitmap(), | 335 image_rep.sk_bitmap(), |
333 resize_method_, | 336 resize_method_, |
334 target_pixel_size.width(), | 337 target_pixel_size.width(), |
335 target_pixel_size.height()); | 338 target_pixel_size.height()); |
336 return ImageSkiaRep(resized, scale_factor); | 339 return ImageSkiaRep(resized, scale_factor); |
337 } | 340 } |
338 | 341 |
339 private: | 342 private: |
340 const ImageSkia source_; | 343 const ImageSkia source_; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 // static | 445 // static |
443 ImageSkia ImageSkiaOperations::CreateResizedImage( | 446 ImageSkia ImageSkiaOperations::CreateResizedImage( |
444 const ImageSkia& source, | 447 const ImageSkia& source, |
445 skia::ImageOperations::ResizeMethod method, | 448 skia::ImageOperations::ResizeMethod method, |
446 const Size& target_dip_size) { | 449 const Size& target_dip_size) { |
447 return ImageSkia(new ResizeSource(source, method, target_dip_size), | 450 return ImageSkia(new ResizeSource(source, method, target_dip_size), |
448 target_dip_size); | 451 target_dip_size); |
449 } | 452 } |
450 | 453 |
451 // static | 454 // static |
| 455 ImageSkia ImageSkiaOperations::CreateImageWithCustomResizeMethod( |
| 456 const ImageSkia& source, |
| 457 skia::ImageOperations::ResizeMethod method) { |
| 458 return ImageSkia(new ResizeSource(source, method, source.size()), |
| 459 source.size()); |
| 460 } |
| 461 |
| 462 // static |
452 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow( | 463 ImageSkia ImageSkiaOperations::CreateImageWithDropShadow( |
453 const ImageSkia& source, | 464 const ImageSkia& source, |
454 const ShadowValues& shadows) { | 465 const ShadowValues& shadows) { |
455 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); | 466 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); |
456 gfx::Size shadow_image_size = source.size(); | 467 gfx::Size shadow_image_size = source.size(); |
457 shadow_image_size.Enlarge(shadow_padding.width(), | 468 shadow_image_size.Enlarge(shadow_padding.width(), |
458 shadow_padding.height()); | 469 shadow_padding.height()); |
459 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); | 470 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); |
460 } | 471 } |
461 | 472 |
462 } // namespace gfx | 473 } // namespace gfx |
OLD | NEW |