Chromium Code Reviews| Index: ui/gfx/image/image_skia_operations.cc |
| diff --git a/ui/gfx/image/image_skia_operations.cc b/ui/gfx/image/image_skia_operations.cc |
| index 8afaf876eab4e777ab66f447b1b37bac9554ebb8..753ee88cf9770bb57c810d73900577401aa0a8b2 100644 |
| --- a/ui/gfx/image/image_skia_operations.cc |
| +++ b/ui/gfx/image/image_skia_operations.cc |
| @@ -344,6 +344,40 @@ class ResizeSource : public ImageSkiaSource { |
| DISALLOW_COPY_AND_ASSIGN(ResizeSource); |
| }; |
| +// Image source that uses |resize_method| to generate missing image |
| +// representations. |
| +class FallbackResizeSource : public ImageSkiaSource { |
|
pkotwicz
2012/10/16 22:13:27
Can you use ResizeSource here?
Also can you fix th
tbarzic
2012/10/16 23:19:33
Done.
|
| + public: |
| + FallbackResizeSource(const ImageSkia& source, |
| + skia::ImageOperations::ResizeMethod resize_method) |
| + : source_(source), |
| + resize_method_(resize_method) { |
| + } |
| + virtual ~FallbackResizeSource() {} |
| + |
| + // gfx::ImageSkiaSource overrides: |
| + virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| + const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor); |
| + if (image_rep.scale_factor() == scale_factor) |
| + return image_rep; |
| + |
| + const float scale = ui::GetScaleFactorScale(scale_factor); |
| + const Size target_pixel_size = gfx::ToFlooredSize( |
| + source_.size().Scale(scale)); |
| + |
| + const SkBitmap resized = skia::ImageOperations::Resize( |
| + image_rep.sk_bitmap(), |
| + resize_method_, |
| + target_pixel_size.width(), |
| + target_pixel_size.height()); |
| + return ImageSkiaRep(resized, scale_factor); |
| + } |
| + |
| + private: |
| + ImageSkia source_; |
| + skia::ImageOperations::ResizeMethod resize_method_; |
| +}; |
| + |
| // DropShadowSource generates image reps with drop shadow for image reps in |
| // |source| that represent requested scale factors. |
| class DropShadowSource : public ImageSkiaSource { |
| @@ -449,6 +483,14 @@ ImageSkia ImageSkiaOperations::CreateResizedImage( |
| } |
| // static |
| +ImageSkia ImageSkiaOperations::CreateImageWithFallbackResizeMethod( |
| + const ImageSkia& source, |
| + skia::ImageOperations::ResizeMethod resize_method) { |
| + return ImageSkia(new FallbackResizeSource(source, resize_method), |
| + source.size()); |
| +} |
| + |
| +// static |
| ImageSkia ImageSkiaOperations::CreateImageWithDropShadow( |
| const ImageSkia& source, |
| const ShadowValues& shadows) { |