summaryrefslogtreecommitdiffstats
path: root/ui/gfx/image.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ui/gfx/image.cc')
-rw-r--r--ui/gfx/image.cc45
1 files changed, 35 insertions, 10 deletions
diff --git a/ui/gfx/image.cc b/ui/gfx/image.cc
index 9395279..23edd96 100644
--- a/ui/gfx/image.cc
+++ b/ui/gfx/image.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/logging.h"
+#include "base/stl_util-inl.h"
#include "third_party/skia/include/core/SkBitmap.h"
#if defined(OS_LINUX)
@@ -26,7 +27,7 @@ namespace internal {
#if defined(OS_MACOSX)
// This is a wrapper around gfx::NSImageToSkBitmap() because this cross-platform
// file cannot include the [square brackets] of ObjC.
-const SkBitmap* NSImageToSkBitmap(NSImage* image);
+bool NSImageToSkBitmaps(NSImage* image, std::vector<const SkBitmap*>* bitmaps);
#endif
#if defined(OS_LINUX)
@@ -84,20 +85,27 @@ class ImageRep {
class SkBitmapRep : public ImageRep {
public:
explicit SkBitmapRep(const SkBitmap* bitmap)
- : ImageRep(Image::kSkBitmapRep),
- bitmap_(bitmap) {
+ : ImageRep(Image::kSkBitmapRep) {
CHECK(bitmap);
+ bitmaps_.push_back(bitmap);
+ }
+
+ explicit SkBitmapRep(const std::vector<const SkBitmap*>& bitmaps)
+ : ImageRep(Image::kSkBitmapRep),
+ bitmaps_(bitmaps) {
+ CHECK(!bitmaps_.empty());
}
virtual ~SkBitmapRep() {
- delete bitmap_;
- bitmap_ = NULL;
+ STLDeleteElements(&bitmaps_);
}
- const SkBitmap* bitmap() const { return bitmap_; }
+ const SkBitmap* bitmap() const { return bitmaps_[0]; }
+
+ const std::vector<const SkBitmap*>& bitmaps() const { return bitmaps_; }
private:
- const SkBitmap* bitmap_;
+ std::vector<const SkBitmap*> bitmaps_;
DISALLOW_COPY_AND_ASSIGN(SkBitmapRep);
};
@@ -193,6 +201,12 @@ Image::Image(const SkBitmap* bitmap)
AddRepresentation(rep);
}
+Image::Image(const std::vector<const SkBitmap*>& bitmaps)
+ : storage_(new internal::ImageStorage(Image::kSkBitmapRep)) {
+ internal::SkBitmapRep* rep = new internal::SkBitmapRep(bitmaps);
+ AddRepresentation(rep);
+}
+
#if defined(OS_LINUX)
Image::Image(GdkPixbuf* pixbuf)
: storage_(new internal::ImageStorage(Image::kGdkPixbufRep)) {
@@ -289,8 +303,9 @@ internal::ImageRep* Image::GetRepresentation(RepresentationType rep_type) {
#elif defined(OS_MACOSX)
if (storage_->default_representation_type() == Image::kNSImageRep) {
internal::NSImageRep* nsimage_rep = default_rep->AsNSImageRep();
- rep = new internal::SkBitmapRep(
- internal::NSImageToSkBitmap(nsimage_rep->image()));
+ std::vector<const SkBitmap*> bitmaps;
+ CHECK(internal::NSImageToSkBitmaps(nsimage_rep->image(), &bitmaps));
+ rep = new internal::SkBitmapRep(bitmaps);
}
#endif
CHECK(rep);
@@ -309,7 +324,7 @@ internal::ImageRep* Image::GetRepresentation(RepresentationType rep_type) {
}
#elif defined(OS_MACOSX)
if (rep_type == Image::kNSImageRep) {
- NSImage* image = gfx::SkBitmapToNSImage(*(skia_rep->bitmap()));
+ NSImage* image = gfx::SkBitmapsToNSImage(skia_rep->bitmaps());
base::mac::NSObjectRetain(image);
native_rep = new internal::NSImageRep(image);
}
@@ -327,4 +342,14 @@ void Image::AddRepresentation(internal::ImageRep* rep) {
storage_->representations().insert(std::make_pair(rep->type(), rep));
}
+size_t Image::GetNumberOfSkBitmaps() {
+ return GetRepresentation(Image::kSkBitmapRep)->AsSkBitmapRep()->
+ bitmaps().size();
+}
+
+const SkBitmap* Image::GetSkBitmapAtIndex(size_t index) {
+ return GetRepresentation(Image::kSkBitmapRep)->AsSkBitmapRep()->
+ bitmaps()[index];
+}
+
} // namespace gfx