| 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 cbe2c8efc3f7c330e5229d2a19c2004a4be8b40b..21b1e3fadec3133fa914bba0b67f0dd5328f1476 100644
|
| --- a/ui/gfx/image/image_skia_operations.cc
|
| +++ b/ui/gfx/image/image_skia_operations.cc
|
| @@ -6,12 +6,14 @@
|
|
|
| #include "base/command_line.h"
|
| #include "base/logging.h"
|
| +#include "skia/ext/image_operations.h"
|
| #include "skia/ext/platform_canvas.h"
|
| #include "ui/base/layout.h"
|
| #include "ui/base/ui_base_switches.h"
|
| #include "ui/gfx/image/image_skia.h"
|
| #include "ui/gfx/image/image_skia_rep.h"
|
| #include "ui/gfx/image/image_skia_source.h"
|
| +#include "ui/gfx/insets.h"
|
| #include "ui/gfx/rect.h"
|
| #include "ui/gfx/size.h"
|
| #include "ui/gfx/skbitmap_operations.h"
|
| @@ -141,6 +143,70 @@ class TiledImageSource : public gfx::ImageSkiaSource {
|
| DISALLOW_COPY_AND_ASSIGN(TiledImageSource);
|
| };
|
|
|
| +class ResizeSource : public ImageSkiaSource {
|
| + public:
|
| + ResizeSource(const ImageSkia& source,
|
| + const Size& target_dip_size)
|
| + : source_(source),
|
| + target_dip_size_(target_dip_size) {
|
| + }
|
| + virtual ~ResizeSource() {}
|
| +
|
| + private:
|
| + // gfx::ImageSkiaSource overrides:
|
| + virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
|
| + const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
|
| + if (image_rep.GetWidth() == target_dip_size_.width() &&
|
| + image_rep.GetHeight() == target_dip_size_.height())
|
| + return image_rep;
|
| +
|
| + const float scale = image_rep.GetScale();
|
| + const Size target_pixel_size(target_dip_size_.Scale(scale));
|
| + const SkBitmap resized = skia::ImageOperations::Resize(
|
| + image_rep.sk_bitmap(),
|
| + skia::ImageOperations::RESIZE_BEST,
|
| + target_pixel_size.width(),
|
| + target_pixel_size.height());
|
| + return ImageSkiaRep(resized, image_rep.scale_factor());
|
| + }
|
| +
|
| + const ImageSkia source_;
|
| + const Size target_dip_size_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ResizeSource);
|
| +};
|
| +
|
| +class DropShadowSource : public ImageSkiaSource {
|
| + public:
|
| + DropShadowSource(const ImageSkia& source,
|
| + const ShadowValues& dip_shadows)
|
| + : source_(source),
|
| + dip_shadows_(dip_shadows) {
|
| + }
|
| + virtual ~DropShadowSource() {}
|
| +
|
| + private:
|
| + // gfx::ImageSkiaSource overrides:
|
| + virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
|
| + const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
|
| +
|
| + const float scale = image_rep.GetScale();
|
| + ShadowValues shadow_in_pixel;
|
| + for (size_t i = 0; i < dip_shadows_.size(); ++i)
|
| + shadow_in_pixel.push_back(dip_shadows_[i].Scale(scale));
|
| +
|
| + const SkBitmap shadow_image = SkBitmapOperations::CreateDropShadow(
|
| + image_rep.sk_bitmap(),
|
| + shadow_in_pixel);
|
| + return ImageSkiaRep(shadow_image, image_rep.scale_factor());
|
| + }
|
| +
|
| + const ImageSkia source_;
|
| + const ShadowValues dip_shadows_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(DropShadowSource);
|
| +};
|
| +
|
| } // namespace;
|
|
|
| // static
|
| @@ -164,4 +230,21 @@ ImageSkia ImageSkiaOperations::CreateTiledImage(const ImageSkia& source,
|
| gfx::Size(dst_w, dst_h));
|
| }
|
|
|
| +// static
|
| +ImageSkia ImageSkiaOperations::CreateResizedImage(const ImageSkia& source,
|
| + const Size& target_dip_size) {
|
| + return ImageSkia(new ResizeSource(source, target_dip_size), target_dip_size);
|
| +}
|
| +
|
| +// static
|
| +ImageSkia ImageSkiaOperations::CreateDropShadowImage(
|
| + const ImageSkia& source,
|
| + const ShadowValues& shadows) {
|
| + const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows);
|
| + gfx::Size shadow_image_size = source.size();
|
| + shadow_image_size.Enlarge(shadow_padding.width(),
|
| + shadow_padding.height());
|
| + return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size);
|
| +}
|
| +
|
| } // namespace gfx
|
|
|