summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/themes/theme_service_mac.mm16
-rw-r--r--chrome/browser/ui/tests/ui_gfx_image_unittest.cc4
-rw-r--r--chrome/browser/ui/tests/ui_gfx_image_unittest.mm6
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--skia/ext/skia_utils_mac.h10
-rw-r--r--skia/ext/skia_utils_mac.mm90
-rw-r--r--skia/ext/skia_utils_mac_unittest.mm142
-rw-r--r--ui/base/resource/resource_bundle.cc7
-rw-r--r--ui/gfx/image.cc45
-rw-r--r--ui/gfx/image.h20
-rw-r--r--ui/gfx/image_mac.mm12
-rw-r--r--ui/gfx/image_unittest.cc47
-rw-r--r--ui/gfx/image_unittest.h67
-rw-r--r--ui/ui_unittests.gypi4
14 files changed, 123 insertions, 349 deletions
diff --git a/chrome/browser/themes/theme_service_mac.mm b/chrome/browser/themes/theme_service_mac.mm
index 73fd814..30d359e 100644
--- a/chrome/browser/themes/theme_service_mac.mm
+++ b/chrome/browser/themes/theme_service_mac.mm
@@ -10,9 +10,7 @@
#include "chrome/browser/themes/browser_theme_pack.h"
#include "skia/ext/skia_utils_mac.h"
#import "third_party/GTM/AppKit/GTMNSColor+Luminance.h"
-#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_utils.h"
-#include "ui/gfx/image.h"
NSString* const kBrowserThemeDidChangeNotification =
@"BrowserThemeDidChangeNotification";
@@ -46,18 +44,8 @@ NSImage* ThemeService::GetNSImageNamed(int id, bool allow_default) const {
// SkBitmap > native conversion?
// - For consistency with other platforms.
// - To get the generated tinted images.
- NSImage* nsimage = nil;
- if (theme_pack_.get()) {
- SkBitmap* bitmap = theme_pack_->GetBitmapNamed(id);
- if (bitmap)
- nsimage = gfx::SkBitmapToNSImage(*bitmap);
- }
-
- // If the theme didn't override this image then load it from the resource
- // bundle.
- if (!nsimage) {
- nsimage = rb_.GetNativeImageNamed(id);
- }
+ SkBitmap* bitmap = GetBitmapNamed(id);
+ NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap);
// We loaded successfully. Cache the image.
if (nsimage) {
diff --git a/chrome/browser/ui/tests/ui_gfx_image_unittest.cc b/chrome/browser/ui/tests/ui_gfx_image_unittest.cc
index 7c8f100..cfe1c9b 100644
--- a/chrome/browser/ui/tests/ui_gfx_image_unittest.cc
+++ b/chrome/browser/ui/tests/ui_gfx_image_unittest.cc
@@ -6,7 +6,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image.h"
-#include "ui/gfx/image_unittest_util.h"
+#include "ui/gfx/image_unittest.h"
#if defined(OS_LINUX)
#include <gtk/gtk.h>
@@ -43,7 +43,7 @@ TEST(UiGfxImageTest, GtkImageView) {
GtkWidget* fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), fixed);
- gfx::Image image(gfx::test::CreateBitmap(25, 25));
+ gfx::Image image(gfx::test::CreateBitmap());
GtkWidget* image_view = gtk_image_new_from_pixbuf(image);
gtk_fixed_put(GTK_FIXED(fixed), image_view, 10, 10);
gtk_widget_set_size_request(image_view, 25, 25);
diff --git a/chrome/browser/ui/tests/ui_gfx_image_unittest.mm b/chrome/browser/ui/tests/ui_gfx_image_unittest.mm
index 7245ff1..9f62332 100644
--- a/chrome/browser/ui/tests/ui_gfx_image_unittest.mm
+++ b/chrome/browser/ui/tests/ui_gfx_image_unittest.mm
@@ -9,7 +9,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image.h"
-#include "ui/gfx/image_unittest_util.h"
+#include "ui/gfx/image_unittest.h"
namespace {
@@ -17,7 +17,7 @@ class UiGfxImageTest : public CocoaTest {
};
TEST_F(UiGfxImageTest, CheckColor) {
- gfx::Image image(gfx::test::CreateBitmap(25, 25));
+ gfx::Image image(gfx::test::CreateBitmap());
[image lockFocus];
NSColor* color = NSReadPixel(NSMakePoint(10, 10));
[image unlockFocus];
@@ -42,7 +42,7 @@ TEST_F(UiGfxImageTest, ImageView) {
[[test_window() contentView] addSubview:image_view];
[test_window() orderFront:nil];
- gfx::Image image(gfx::test::CreateBitmap(25, 25));
+ gfx::Image image(gfx::test::CreateBitmap());
[image_view setImage:image];
}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 5f78970..10d040b 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -191,8 +191,6 @@
'../content/browser/tab_contents/test_tab_contents.h',
'../content/common/notification_observer_mock.cc',
'../content/common/notification_observer_mock.h',
- '../ui/gfx/image_unittest_util.h',
- '../ui/gfx/image_unittest_util.cc',
],
'conditions': [
['OS=="linux"', {
diff --git a/skia/ext/skia_utils_mac.h b/skia/ext/skia_utils_mac.h
index 04d4a1d..0551643 100644
--- a/skia/ext/skia_utils_mac.h
+++ b/skia/ext/skia_utils_mac.h
@@ -7,7 +7,6 @@
#pragma once
#include <CoreGraphics/CGColor.h>
-#include <vector>
#include "third_party/skia/include/core/SkColor.h"
@@ -24,10 +23,8 @@ typedef struct _NSSize NSSize;
#ifdef __OBJC__
@class NSImage;
-@class NSImageRep;
#else
class NSImage;
-class NSImageRep;
#endif
namespace gfx {
@@ -67,9 +64,6 @@ SkBitmap CGImageToSkBitmap(CGImageRef image);
// Draws an NSImage with a given size into a SkBitmap.
SkBitmap NSImageToSkBitmap(NSImage* image, NSSize size, bool is_opaque);
-// Draws an NSImageRep with a given size into a SkBitmap.
-SkBitmap NSImageRepToSkBitmap(NSImageRep* image, NSSize size, bool is_opaque);
-
// Given an SkBitmap and a color space, return an autoreleased NSImage.
NSImage* SkBitmapToNSImageWithColorSpace(const SkBitmap& icon,
CGColorSpaceRef colorSpace);
@@ -79,10 +73,6 @@ NSImage* SkBitmapToNSImageWithColorSpace(const SkBitmap& icon,
// TODO(thakis): Remove this -- http://crbug.com/69432
NSImage* SkBitmapToNSImage(const SkBitmap& icon);
-// Given a vector of SkBitmaps, return an NSImage with each bitmap added
-// as a representation.
-NSImage* SkBitmapsToNSImage(const std::vector<const SkBitmap*>& bitmaps);
-
// Returns |[NSImage imageNamed:@"NSApplicationIcon"]| as SkBitmap.
SkBitmap AppplicationIconAtSize(int size);
diff --git a/skia/ext/skia_utils_mac.mm b/skia/ext/skia_utils_mac.mm
index 3c6b191..c78121a 100644
--- a/skia/ext/skia_utils_mac.mm
+++ b/skia/ext/skia_utils_mac.mm
@@ -8,7 +8,6 @@
#include "base/logging.h"
#include "base/mac/scoped_cftyperef.h"
-#include "base/memory/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
#include "skia/ext/bitmap_platform_device_mac.h"
#include "third_party/skia/include/utils/mac/SkCGUtils.h"
@@ -168,67 +167,19 @@ SkBitmap NSImageToSkBitmap(NSImage* image, NSSize size, bool is_opaque) {
return bitmap;
}
-SkBitmap NSImageRepToSkBitmap(NSImageRep* image, NSSize size, bool is_opaque) {
- SkBitmap bitmap;
- bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width, size.height);
- if (!bitmap.allocPixels())
- return bitmap; // Return |bitmap| which should respond true to isNull().
-
- bitmap.setIsOpaque(is_opaque);
-
- base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space(
- CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
- void* data = bitmap.getPixels();
-
- // Allocate a bitmap context with 4 components per pixel (BGRA). Apple
- // recommends these flags for improved CG performance.
-#define HAS_ARGB_SHIFTS(a, r, g, b) \
- (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \
- && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b))
-#if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0)
- base::mac::ScopedCFTypeRef<CGContextRef> context(
- CGBitmapContextCreate(data, size.width, size.height, 8, size.width*4,
- color_space,
- kCGImageAlphaPremultipliedFirst |
- kCGBitmapByteOrder32Host));
-#else
-#error We require that Skia's and CoreGraphics's recommended \
- image memory layout match.
-#endif
-#undef HAS_ARGB_SHIFTS
-
- // Something went really wrong. Best guess is that the bitmap data is invalid.
- DCHECK(context);
-
- // Save the current graphics context so that we can restore it later.
- [NSGraphicsContext saveGraphicsState];
-
- // Dummy context that we will draw into.
- NSGraphicsContext* context_cocoa =
- [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
- [NSGraphicsContext setCurrentContext:context_cocoa];
-
- // This will stretch any images to |size| if it does not fit or is non-square.
- [image drawInRect:NSMakeRect(0, 0, size.width, size.height)];
-
- // Done drawing, restore context.
- [NSGraphicsContext restoreGraphicsState];
-
- return bitmap;
-}
-
NSImage* SkBitmapToNSImageWithColorSpace(const SkBitmap& skiaBitmap,
CGColorSpaceRef colorSpace) {
if (skiaBitmap.isNull())
return nil;
// First convert SkBitmap to CGImageRef.
- base::mac::ScopedCFTypeRef<CGImageRef> cgimage(
- SkCreateCGImageRefWithColorspace(skiaBitmap, colorSpace));
+ CGImageRef cgimage =
+ SkCreateCGImageRefWithColorspace(skiaBitmap, colorSpace);
// Now convert to NSImage.
- scoped_nsobject<NSBitmapImageRep> bitmap(
- [[NSBitmapImageRep alloc] initWithCGImage:cgimage]);
+ NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc]
+ initWithCGImage:cgimage] autorelease];
+ CFRelease(cgimage);
NSImage* image = [[[NSImage alloc] init] autorelease];
[image addRepresentation:bitmap];
[image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())];
@@ -241,37 +192,6 @@ NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) {
return SkBitmapToNSImageWithColorSpace(skiaBitmap, colorSpace.get());
}
-NSImage* SkBitmapsToNSImage(const std::vector<const SkBitmap*>& bitmaps) {
- if (bitmaps.empty())
- return nil;
-
- base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space(
- CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
- NSImage* image = [[[NSImage alloc] init] autorelease];
- NSSize min_size = NSZeroSize;
-
- for (std::vector<const SkBitmap*>::const_iterator it = bitmaps.begin();
- it != bitmaps.end(); ++it) {
- const SkBitmap& skiaBitmap = **it;
- // First convert SkBitmap to CGImageRef.
- base::mac::ScopedCFTypeRef<CGImageRef> cgimage(
- SkCreateCGImageRefWithColorspace(skiaBitmap, color_space));
-
- // Now convert to NSImage.
- scoped_nsobject<NSBitmapImageRep> bitmap(
- [[NSBitmapImageRep alloc] initWithCGImage:cgimage]);
- [image addRepresentation:bitmap];
-
- if (min_size.width == 0 || min_size.width > skiaBitmap.width()) {
- min_size.width = skiaBitmap.width();
- min_size.height = skiaBitmap.height();
- }
- }
-
- [image setSize:min_size];
- return image;
-}
-
SkBitmap AppplicationIconAtSize(int size) {
NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
return NSImageToSkBitmap(image, NSMakeSize(size, size), /* is_opaque=*/true);
diff --git a/skia/ext/skia_utils_mac_unittest.mm b/skia/ext/skia_utils_mac_unittest.mm
index 7d07fb6..7401f11 100644
--- a/skia/ext/skia_utils_mac_unittest.mm
+++ b/skia/ext/skia_utils_mac_unittest.mm
@@ -9,60 +9,39 @@ namespace {
class SkiaUtilsMacTest : public testing::Test {
public:
- // Creates a red or blue bitmap.
- SkBitmap CreateSkBitmap(int width, int height, bool isred, bool tfbit);
-
- // Creates a red or blue image.
- NSImage* CreateNSImage(int width, int height, bool isred);
-
- // Checks that the given bitmap rep is actually red or blue.
- void TestImageRep(NSBitmapImageRep* imageRep, bool isred);
-
- // Checks that the given bitmap is actually red or blue.
- void TestSkBitmap(const SkBitmap& bitmap, bool isred);
-
// If not red, is blue.
// If not tfbit (twenty-four-bit), is 444.
void ShapeHelper(int width, int height, bool isred, bool tfbit);
};
-SkBitmap SkiaUtilsMacTest::CreateSkBitmap(int width, int height,
- bool isred, bool tfbit) {
- SkBitmap bitmap;
+void SkiaUtilsMacTest::ShapeHelper(int width, int height,
+ bool isred, bool tfbit) {
+ SkBitmap thing;
if (tfbit)
- bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ thing.setConfig(SkBitmap::kARGB_8888_Config, width, height);
else
- bitmap.setConfig(SkBitmap::kARGB_4444_Config, width, height);
- bitmap.allocPixels();
+ thing.setConfig(SkBitmap::kARGB_4444_Config, width, height);
+ thing.allocPixels();
if (isred)
- bitmap.eraseRGB(0xff, 0, 0);
+ thing.eraseRGB(0xff, 0, 0);
else
- bitmap.eraseRGB(0, 0, 0xff);
+ thing.eraseRGB(0, 0, 0xff);
- return bitmap;
-}
+ // Confirm size
+ NSImage* image = gfx::SkBitmapToNSImage(thing);
+ EXPECT_DOUBLE_EQ([image size].width, (double)width);
+ EXPECT_DOUBLE_EQ([image size].height, (double)height);
-NSImage* SkiaUtilsMacTest::CreateNSImage(int width, int height, bool isred) {
- NSImage* image = [[[NSImage alloc] initWithSize:NSMakeSize(width, height)]
- autorelease];
+ // Get the color of a pixel and make sure it looks fine
[image lockFocus];
- if (isred)
- [[NSColor colorWithDeviceRed:1.0 green:0.0 blue:0.0 alpha:1.0] set];
- else
- [[NSColor colorWithDeviceRed:0.0 green:0.0 blue:1.0 alpha:1.0] set];
- NSRectFill(NSMakeRect(0, 0, width, height));
- [image unlockFocus];
- return image;
-}
-void SkiaUtilsMacTest::TestImageRep(NSBitmapImageRep* imageRep, bool isred) {
- // Get the color of a pixel and make sure it looks fine
- int x = [imageRep size].width > 17 ? 17 : 0;
- int y = [imageRep size].height > 17 ? 17 : 0;
- NSColor* color = [imageRep colorAtX:x y:y];
+ int x = width > 17 ? 17 : 0;
+ int y = height > 17 ? 17 : 0;
+ NSColor* color = NSReadPixel(NSMakePoint(x, y));
CGFloat red = 0, green = 0, blue = 0, alpha = 0;
+ [image unlockFocus];
// SkBitmapToNSImage returns a bitmap in the calibrated color space (sRGB),
// while NSReadPixel returns a color in the device color space. Convert back
@@ -73,45 +52,14 @@ void SkiaUtilsMacTest::TestImageRep(NSBitmapImageRep* imageRep, bool isred) {
// Be tolerant of floating point rounding and lossy color space conversions.
if (isred) {
- EXPECT_NEAR(red, 1.0, 0.025);
- EXPECT_NEAR(blue, 0.0, 0.025);
- } else {
- EXPECT_NEAR(red, 0.0, 0.025);
- EXPECT_NEAR(blue, 1.0, 0.025);
- }
- EXPECT_NEAR(green, 0.0, 0.025);
- EXPECT_NEAR(alpha, 1.0, 0.025);
-}
-
-void SkiaUtilsMacTest::TestSkBitmap(const SkBitmap& bitmap, bool isred) {
- int x = bitmap.width() > 17 ? 17 : 0;
- int y = bitmap.height() > 17 ? 17 : 0;
- SkColor color = bitmap.getColor(x, y);
-
- if (isred) {
- EXPECT_EQ(255u, SkColorGetR(color));
- EXPECT_EQ(0u, SkColorGetB(color));
+ EXPECT_GT(red, 0.95);
+ EXPECT_LT(blue, 0.05);
} else {
- EXPECT_EQ(0u, SkColorGetR(color));
- EXPECT_EQ(255u, SkColorGetB(color));
+ EXPECT_LT(red, 0.05);
+ EXPECT_GT(blue, 0.95);
}
- EXPECT_EQ(0u, SkColorGetG(color));
- EXPECT_EQ(255u, SkColorGetA(color));
-}
-
-void SkiaUtilsMacTest::ShapeHelper(int width, int height,
- bool isred, bool tfbit) {
- SkBitmap thing(CreateSkBitmap(width, height, isred, tfbit));
-
- // Confirm size
- NSImage* image = gfx::SkBitmapToNSImage(thing);
- EXPECT_DOUBLE_EQ([image size].width, (double)width);
- EXPECT_DOUBLE_EQ([image size].height, (double)height);
-
- EXPECT_TRUE([[image representations] count] == 1);
- EXPECT_TRUE([[[image representations] lastObject]
- isKindOfClass:[NSBitmapImageRep class]]);
- TestImageRep([[image representations] lastObject], isred);
+ EXPECT_LT(green, 0.05);
+ EXPECT_GT(alpha, 0.95);
}
TEST_F(SkiaUtilsMacTest, FAILS_BitmapToNSImage_RedSquare64x64) {
@@ -126,48 +74,4 @@ TEST_F(SkiaUtilsMacTest, FAILS_BitmapToNSImage_BlueRectangle444) {
ShapeHelper(200, 200, false, false);
}
-TEST_F(SkiaUtilsMacTest, FAILS_MultipleBitmapsToNSImage) {
- int redWidth = 10;
- int redHeight = 15;
- int blueWidth = 20;
- int blueHeight = 30;
-
- SkBitmap redBitmap(CreateSkBitmap(redWidth, redHeight, true, true));
- SkBitmap blueBitmap(CreateSkBitmap(blueWidth, blueHeight, false, true));
- std::vector<const SkBitmap*> bitmaps;
- bitmaps.push_back(&redBitmap);
- bitmaps.push_back(&blueBitmap);
-
- NSImage* image = gfx::SkBitmapsToNSImage(bitmaps);
-
- // Image size should be the same as the smallest bitmap.
- EXPECT_DOUBLE_EQ(redWidth, [image size].width);
- EXPECT_DOUBLE_EQ(redHeight, [image size].height);
-
- EXPECT_EQ(2u, [[image representations] count]);
-
- for (NSBitmapImageRep* imageRep in [image representations]) {
- bool isred = [imageRep size].width == redWidth;
- if (isred) {
- EXPECT_DOUBLE_EQ(redHeight, [imageRep size].height);
- } else {
- EXPECT_DOUBLE_EQ(blueWidth, [imageRep size].width);
- EXPECT_DOUBLE_EQ(blueHeight, [imageRep size].height);
- }
- TestImageRep(imageRep, isred);
- }
-}
-
-TEST_F(SkiaUtilsMacTest, FAILS_NSImageRepToSkBitmap) {
- int width = 10;
- int height = 15;
- bool isred = true;
-
- NSImage* image = CreateNSImage(width, height, isred);
- EXPECT_EQ(1u, [[image representations] count]);
- NSBitmapImageRep* imageRep = [[image representations] lastObject];
- SkBitmap bitmap(gfx::NSImageRepToSkBitmap(imageRep, [image size], false));
- TestSkBitmap(bitmap, isred);
-}
-
} // namespace
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index 306a61e..a8d9607 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -131,11 +131,8 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
if (images_.count(resource_id))
return *images_[resource_id];
- std::vector<const SkBitmap*> bitmaps;
- bitmaps.push_back(bitmap.release());
- if (large_bitmap.get())
- bitmaps.push_back(large_bitmap.release());
- gfx::Image* image = new gfx::Image(bitmaps);
+ // TODO(sail): Add the large bitmap to the image as well.
+ gfx::Image* image = new gfx::Image(bitmap.release());
images_[resource_id] = image;
return *image;
}
diff --git a/ui/gfx/image.cc b/ui/gfx/image.cc
index 23edd96..9395279 100644
--- a/ui/gfx/image.cc
+++ b/ui/gfx/image.cc
@@ -7,7 +7,6 @@
#include <algorithm>
#include "base/logging.h"
-#include "base/stl_util-inl.h"
#include "third_party/skia/include/core/SkBitmap.h"
#if defined(OS_LINUX)
@@ -27,7 +26,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.
-bool NSImageToSkBitmaps(NSImage* image, std::vector<const SkBitmap*>* bitmaps);
+const SkBitmap* NSImageToSkBitmap(NSImage* image);
#endif
#if defined(OS_LINUX)
@@ -85,27 +84,20 @@ class ImageRep {
class SkBitmapRep : public ImageRep {
public:
explicit SkBitmapRep(const SkBitmap* 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());
+ bitmap_(bitmap) {
+ CHECK(bitmap);
}
virtual ~SkBitmapRep() {
- STLDeleteElements(&bitmaps_);
+ delete bitmap_;
+ bitmap_ = NULL;
}
- const SkBitmap* bitmap() const { return bitmaps_[0]; }
-
- const std::vector<const SkBitmap*>& bitmaps() const { return bitmaps_; }
+ const SkBitmap* bitmap() const { return bitmap_; }
private:
- std::vector<const SkBitmap*> bitmaps_;
+ const SkBitmap* bitmap_;
DISALLOW_COPY_AND_ASSIGN(SkBitmapRep);
};
@@ -201,12 +193,6 @@ 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)) {
@@ -303,9 +289,8 @@ 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();
- std::vector<const SkBitmap*> bitmaps;
- CHECK(internal::NSImageToSkBitmaps(nsimage_rep->image(), &bitmaps));
- rep = new internal::SkBitmapRep(bitmaps);
+ rep = new internal::SkBitmapRep(
+ internal::NSImageToSkBitmap(nsimage_rep->image()));
}
#endif
CHECK(rep);
@@ -324,7 +309,7 @@ internal::ImageRep* Image::GetRepresentation(RepresentationType rep_type) {
}
#elif defined(OS_MACOSX)
if (rep_type == Image::kNSImageRep) {
- NSImage* image = gfx::SkBitmapsToNSImage(skia_rep->bitmaps());
+ NSImage* image = gfx::SkBitmapToNSImage(*(skia_rep->bitmap()));
base::mac::NSObjectRetain(image);
native_rep = new internal::NSImageRep(image);
}
@@ -342,14 +327,4 @@ 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
diff --git a/ui/gfx/image.h b/ui/gfx/image.h
index ed9508f..518d8ac4 100644
--- a/ui/gfx/image.h
+++ b/ui/gfx/image.h
@@ -18,7 +18,6 @@
#pragma once
#include <map>
-#include <vector>
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
@@ -30,7 +29,6 @@ class SkBitmap;
namespace {
class ImageTest;
-class ImageMacTest;
}
namespace gfx {
@@ -53,18 +51,11 @@ class Image {
// Creates a new image with the default representation. The object will take
// ownership of the image.
explicit Image(const SkBitmap* bitmap);
-
- // To create an Image that supports multiple resolutions pass a vector
- // of bitmaps, one for each resolution.
- explicit Image(const std::vector<const SkBitmap*>& bitmaps);
-
#if defined(OS_LINUX)
// Does not increase |pixbuf|'s reference count; expects to take ownership.
explicit Image(GdkPixbuf* pixbuf);
#elif defined(OS_MACOSX)
// Does not retain |image|; expects to take ownership.
- // A single NSImage object can contain multiple bitmaps so there's no reason
- // to pass a vector of these.
explicit Image(NSImage* image);
#endif
@@ -87,16 +78,6 @@ class Image {
operator NSImage*();
#endif
- // Gets the number of bitmaps in this image. This may cause a conversion
- // to a bitmap representation. Note, this function and GetSkBitmapAtIndex()
- // are primarily meant to be used by the theme provider.
- size_t GetNumberOfSkBitmaps();
-
- // Gets the bitmap at the given index. This may cause a conversion
- // to a bitmap representation. Note, the internal ordering of bitmaps is not
- // guaranteed.
- const SkBitmap* GetSkBitmapAtIndex(size_t index);
-
// Inspects the representations map to see if the given type exists.
bool HasRepresentation(RepresentationType type);
@@ -122,7 +103,6 @@ class Image {
scoped_refptr<internal::ImageStorage> storage_;
friend class ::ImageTest;
- friend class ::ImageMacTest;
};
} // namespace gfx
diff --git a/ui/gfx/image_mac.mm b/ui/gfx/image_mac.mm
index 55b4aa4..b3dc977 100644
--- a/ui/gfx/image_mac.mm
+++ b/ui/gfx/image_mac.mm
@@ -4,22 +4,14 @@
#import <AppKit/AppKit.h>
-#include "base/memory/scoped_ptr.h"
#include "skia/ext/skia_utils_mac.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace gfx {
namespace internal {
-bool NSImageToSkBitmaps(NSImage* image, std::vector<const SkBitmap*>* bitmaps) {
- for (NSImageRep* imageRep in [image representations]) {
- scoped_ptr<SkBitmap> bitmap(new SkBitmap(
- gfx::NSImageRepToSkBitmap(imageRep, [imageRep size], false)));
- if (bitmap->isNull())
- return false;
- bitmaps->push_back(bitmap.release());
- }
- return true;
+const SkBitmap* NSImageToSkBitmap(NSImage* image) {
+ return new SkBitmap(::gfx::NSImageToSkBitmap(image, [image size], false));
}
} // namespace internal
diff --git a/ui/gfx/image_unittest.cc b/ui/gfx/image_unittest.cc
index aba1ed6..ce2a1f8 100644
--- a/ui/gfx/image_unittest.cc
+++ b/ui/gfx/image_unittest.cc
@@ -6,7 +6,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image.h"
-#include "ui/gfx/image_unittest_util.h"
+#include "ui/gfx/image_unittest.h"
#if defined(OS_LINUX)
#include <gtk/gtk.h>
@@ -30,7 +30,7 @@ class ImageTest : public testing::Test {
namespace gt = gfx::test;
TEST_F(ImageTest, SkiaToSkia) {
- gfx::Image image(gt::CreateBitmap(25, 25));
+ gfx::Image image(gt::CreateBitmap());
const SkBitmap* bitmap = static_cast<const SkBitmap*>(image);
EXPECT_TRUE(bitmap);
EXPECT_FALSE(bitmap->isNull());
@@ -48,7 +48,7 @@ TEST_F(ImageTest, SkiaToSkia) {
}
TEST_F(ImageTest, SkiaToSkiaRef) {
- gfx::Image image(gt::CreateBitmap(25, 25));
+ gfx::Image image(gt::CreateBitmap());
const SkBitmap& bitmap = static_cast<const SkBitmap&>(image);
EXPECT_FALSE(bitmap.isNull());
@@ -64,7 +64,7 @@ TEST_F(ImageTest, SkiaToSkiaRef) {
}
TEST_F(ImageTest, SkiaToPlatform) {
- gfx::Image image(gt::CreateBitmap(25, 25));
+ gfx::Image image(gt::CreateBitmap());
const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U;
EXPECT_TRUE(image.HasRepresentation(gfx::Image::kSkBitmapRep));
@@ -127,7 +127,7 @@ TEST_F(ImageTest, CheckSkiaColor) {
TEST_F(ImageTest, SwapRepresentations) {
const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U;
- gfx::Image image1(gt::CreateBitmap(25, 25));
+ gfx::Image image1(gt::CreateBitmap());
const SkBitmap* bitmap1 = image1;
EXPECT_EQ(1U, image1.RepresentationCount());
@@ -148,7 +148,7 @@ TEST_F(ImageTest, SwapRepresentations) {
TEST_F(ImageTest, Copy) {
const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U;
- gfx::Image image1(gt::CreateBitmap(25, 25));
+ gfx::Image image1(gt::CreateBitmap());
gfx::Image image2(image1);
EXPECT_EQ(1U, image1.RepresentationCount());
@@ -171,41 +171,6 @@ TEST_F(ImageTest, Assign) {
static_cast<const SkBitmap*>(image2));
}
-TEST_F(ImageTest, MultiResolutionSkBitmap) {
- const int width1 = 10;
- const int height1 = 12;
- const int width2 = 20;
- const int height2 = 24;
-
- std::vector<const SkBitmap*> bitmaps;
- bitmaps.push_back(gt::CreateBitmap(width1, height1));
- bitmaps.push_back(gt::CreateBitmap(width2, height2));
- gfx::Image image(bitmaps);
-
- EXPECT_EQ(1u, image.RepresentationCount());
- EXPECT_EQ(2u, image.GetNumberOfSkBitmaps());
-
- const SkBitmap* bitmap1 = image.GetSkBitmapAtIndex(0);
- EXPECT_TRUE(bitmap1);
- const SkBitmap* bitmap2 = image.GetSkBitmapAtIndex(1);
- EXPECT_TRUE(bitmap2);
-
- if (bitmap1->width() == width1) {
- EXPECT_EQ(bitmap1->height(), height1);
- EXPECT_EQ(bitmap2->width(), width2);
- EXPECT_EQ(bitmap2->height(), height2);
- } else {
- EXPECT_EQ(bitmap1->width(), width2);
- EXPECT_EQ(bitmap1->height(), height2);
- EXPECT_EQ(bitmap2->width(), width1);
- EXPECT_EQ(bitmap2->height(), height1);
- }
-
- // Sanity check.
- EXPECT_EQ(1u, image.RepresentationCount());
- EXPECT_EQ(2u, image.GetNumberOfSkBitmaps());
-}
-
// Integration tests with UI toolkit frameworks require linking against the
// Views library and cannot be here (gfx_unittests doesn't include it). They
// instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc.
diff --git a/ui/gfx/image_unittest.h b/ui/gfx/image_unittest.h
index e69de29..09abfce 100644
--- a/ui/gfx/image_unittest.h
+++ b/ui/gfx/image_unittest.h
@@ -0,0 +1,67 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Because the unit tests for gfx::Image are spread across multiple
+// implementation files, this header contains the reusable components.
+
+#ifndef UI_GFX_IMAGE_UNITTEST_H_
+#define UI_GFX_IMAGE_UNITTEST_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+#if defined(OS_LINUX)
+#include "ui/gfx/gtk_util.h"
+#elif defined(OS_MACOSX)
+#include "base/mac/mac_util.h"
+#include "skia/ext/skia_utils_mac.h"
+#endif
+
+namespace gfx {
+namespace test {
+
+#if defined(OS_MACOSX)
+typedef NSImage* PlatformImage;
+#elif defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
+typedef GdkPixbuf* PlatformImage;
+#else
+typedef const SkBitmap* PlatformImage;
+#endif
+
+SkBitmap* CreateBitmap() {
+ SkBitmap* bitmap = new SkBitmap();
+ bitmap->setConfig(SkBitmap::kARGB_8888_Config, 25, 25);
+ bitmap->allocPixels();
+ bitmap->eraseRGB(255, 0, 0);
+ return bitmap;
+}
+
+PlatformImage CreatePlatformImage() {
+ scoped_ptr<SkBitmap> bitmap(CreateBitmap());
+#if defined(OS_MACOSX)
+ NSImage* image = gfx::SkBitmapToNSImage(*(bitmap.get()));
+ base::mac::NSObjectRetain(image);
+ return image;
+#elif defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
+ return gfx::GdkPixbufFromSkBitmap(bitmap.get());
+#else
+ return bitmap.release();
+#endif
+}
+
+gfx::Image::RepresentationType GetPlatformRepresentationType() {
+#if defined(OS_MACOSX)
+ return gfx::Image::kNSImageRep;
+#elif defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
+ return gfx::Image::kGdkPixbufRep;
+#else
+ return gfx::Image::kSkBitmapRep;
+#endif
+}
+
+} // namespace test
+} // namespace gfx
+
+#endif // UI_GFX_IMAGE_UNITTEST_H_
diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi
index 2867afb..2a767a4 100644
--- a/ui/ui_unittests.gypi
+++ b/ui/ui_unittests.gypi
@@ -32,10 +32,8 @@
'gfx/codec/png_codec_unittest.cc',
'gfx/color_utils_unittest.cc',
'gfx/font_unittest.cc',
- 'gfx/image_mac_unittest.mm',
'gfx/image_unittest.cc',
- 'gfx/image_unittest_util.h',
- 'gfx/image_unittest_util.cc',
+ 'gfx/image_unittest.h',
'gfx/insets_unittest.cc',
'gfx/rect_unittest.cc',
'gfx/run_all_unittests.cc',