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 a474f6ef6f6d04022b71d1859c82a051a188bdec..874ec9abdd1120e4169e03ec27da55e062da2dc6 100644 |
| --- a/ui/gfx/image/image_skia_operations.cc |
| +++ b/ui/gfx/image/image_skia_operations.cc |
| @@ -105,6 +105,9 @@ class BlendingImageSource : public gfx::ImageSkiaSource { |
| alpha_(alpha) { |
| } |
| + virtual ~BlendingImageSource() { |
| + } |
| + |
| // gfx::ImageSkiaSource overrides: |
| virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| ImageSkiaRep first_rep = first_.GetRepresentation(scale_factor); |
| @@ -130,6 +133,9 @@ class MaskedImageSource : public gfx::ImageSkiaSource { |
| alpha_(alpha) { |
| } |
| + virtual ~MaskedImageSource() { |
| + } |
| + |
| // gfx::ImageSkiaSource overrides: |
| virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| ImageSkiaRep rgb_rep = rgb_.GetRepresentation(scale_factor); |
| @@ -159,6 +165,9 @@ class TiledImageSource : public gfx::ImageSkiaSource { |
| dst_h_(dst_h) { |
| } |
| + virtual ~TiledImageSource() { |
| + } |
| + |
| // gfx::ImageSkiaSource overrides: |
| virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| ImageSkiaRep source_rep = source_.GetRepresentation(scale_factor); |
| @@ -180,6 +189,72 @@ class TiledImageSource : public gfx::ImageSkiaSource { |
| DISALLOW_COPY_AND_ASSIGN(TiledImageSource); |
| }; |
| +// ImageSkiaSource which uses SkBitmapOperations::CreateButtonBackground |
| +// to generate image reps for the target image. |
| +class ButtonImageSource: public gfx::ImageSkiaSource { |
| + public: |
| + ButtonImageSource(SkColor color, |
| + const ImageSkia& image, |
| + const ImageSkia& mask) |
| + : color_(color), |
| + image_(image), |
| + mask_(mask) { |
| + } |
| + |
| + virtual ~ButtonImageSource() { |
| + } |
| + |
| + // gfx::ImageSkiaSource overrides: |
| + virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| + ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); |
| + ImageSkiaRep mask_rep = mask_.GetRepresentation(scale_factor); |
| + MatchScale(&image_rep, &mask_rep); |
| + return ImageSkiaRep( |
| + SkBitmapOperations::CreateButtonBackground(color_, |
| + image_rep.sk_bitmap(), mask_rep.sk_bitmap()), |
| + image_rep.scale_factor()); |
| + } |
| + |
| + private: |
| + const SkColor color_; |
| + const ImageSkia image_; |
| + const ImageSkia mask_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ButtonImageSource); |
| +}; |
| + |
| +// ImageSkiaSource which uses SkBitmap::extractSubset to generate image reps |
| +// for the target image. |
| +class ExtractSubsetImageSource: public gfx::ImageSkiaSource { |
| + public: |
| + ExtractSubsetImageSource(const gfx::ImageSkia& image, |
| + const gfx::Rect& subset_bounds) |
| + : image_(image), |
| + subset_bounds_(subset_bounds) { |
| + } |
| + |
| + ~ExtractSubsetImageSource() { |
| + } |
| + |
| + // gfx::ImageSkiaSource overrides: |
| + virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { |
| + ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); |
| + SkIRect subset_bounds_in_pixel = RectToSkIRect(subset_bounds_.Scale( |
| + ui::GetScaleFactorScale(image_rep.scale_factor()))); |
| + SkBitmap dst; |
| + bool success = image_rep.sk_bitmap().extractSubset(&dst, |
| + subset_bounds_in_pixel); |
| + DCHECK(success); |
| + return gfx::ImageSkiaRep(dst, image_rep.scale_factor()); |
| + } |
| + |
| + private: |
| + const gfx::ImageSkia image_; |
| + const gfx::Rect subset_bounds_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ExtractSubsetImageSource); |
| +}; |
| + |
| } // namespace; |
| // static |
| @@ -211,4 +286,23 @@ ImageSkia ImageSkiaOperations::CreateResizedImage( |
| target_size_in_dip); |
| } |
| +// static |
| +ImageSkia ImageSkiaOperations::CreateButtonBackground(SkColor color, |
|
sky
2012/07/16 21:23:40
This is only called in one place, should it be mov
pkotwicz
2012/07/17 01:15:41
I would rather keep it here, especially as it is p
|
| + const ImageSkia& image, |
| + const ImageSkia& mask) { |
| + return ImageSkia(new ButtonImageSource(color, image, mask), mask.size()); |
| +} |
| + |
| +// static |
| +ImageSkia ImageSkiaOperations::ExtractSubset(const ImageSkia& image, |
| + const Rect& subset_bounds) { |
| + gfx::Rect clipped_bounds = subset_bounds.Intersect(gfx::Rect(image.size())); |
| + if (image.isNull() || clipped_bounds.IsEmpty()) { |
| + return ImageSkia(); |
| + } |
| + |
| + return ImageSkia(new ExtractSubsetImageSource(image, clipped_bounds), |
| + clipped_bounds.size()); |
| +} |
| + |
| } // namespace gfx |