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