diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/base/resource/resource_bundle.cc | 12 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle.h | 3 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_linux.cc | 6 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_mac.mm | 20 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle_posix.cc | 8 | ||||
-rw-r--r-- | ui/gfx/image.cc | 45 | ||||
-rw-r--r-- | ui/gfx/image.h | 19 | ||||
-rw-r--r-- | ui/gfx/image_mac.mm | 12 | ||||
-rw-r--r-- | ui/gfx/image_mac_unittest.mm | 114 | ||||
-rw-r--r-- | ui/gfx/image_unittest.cc | 45 | ||||
-rw-r--r-- | ui/gfx/image_unittest_util.cc (renamed from ui/gfx/image_unittest.h) | 20 | ||||
-rw-r--r-- | ui/gfx/image_unittest_util.h | 33 | ||||
-rw-r--r-- | ui/ui_unittests.gypi | 4 |
13 files changed, 306 insertions, 35 deletions
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc index 1b6fd11..306a61e 100644 --- a/ui/base/resource/resource_bundle.cc +++ b/ui/base/resource/resource_bundle.cc @@ -119,6 +119,11 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) { scoped_ptr<SkBitmap> bitmap(LoadBitmap(resources_data_, resource_id)); if (bitmap.get()) { + // Check if there's a large version of the image as well. + scoped_ptr<SkBitmap> large_bitmap; + if (large_icon_resources_data_) + large_bitmap.reset(LoadBitmap(large_icon_resources_data_, resource_id)); + // The load was successful, so cache the image. base::AutoLock lock_scope(*lock_); @@ -126,7 +131,11 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) { if (images_.count(resource_id)) return *images_[resource_id]; - gfx::Image* image = new gfx::Image(bitmap.release()); + 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); images_[resource_id] = image; return *image; } @@ -190,6 +199,7 @@ void ResourceBundle::ReloadFonts() { ResourceBundle::ResourceBundle() : lock_(new base::Lock), resources_data_(NULL), + large_icon_resources_data_(NULL), locale_resources_data_(NULL) { } diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h index 2598662..cdd9383 100644 --- a/ui/base/resource/resource_bundle.h +++ b/ui/base/resource/resource_bundle.h @@ -235,6 +235,8 @@ class ResourceBundle { // Returns the full pathname of the main resources file to load. May return // an empty string if no main resources data files are found. static FilePath GetResourcesFilePath(); + + static FilePath GetLargeIconResourcesFilePath(); #endif // Returns the full pathname of the locale file to load. May return an empty @@ -263,6 +265,7 @@ class ResourceBundle { // Handles for data sources. DataHandle resources_data_; + DataHandle large_icon_resources_data_; DataHandle locale_resources_data_; // References to extra data packs loaded via AddDataPackToSharedInstance. diff --git a/ui/base/resource/resource_bundle_linux.cc b/ui/base/resource/resource_bundle_linux.cc index 437f725..5806fb0 100644 --- a/ui/base/resource/resource_bundle_linux.cc +++ b/ui/base/resource/resource_bundle_linux.cc @@ -66,6 +66,12 @@ FilePath ResourceBundle::GetResourcesFilePath() { } // static +FilePath ResourceBundle::GetLargeIconResourcesFilePath() { + // Not supported. + return FilePath(); +} + +// static FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) { FilePath locale_file_path; PathService::Get(ui::DIR_LOCALES, &locale_file_path); diff --git a/ui/base/resource/resource_bundle_mac.mm b/ui/base/resource/resource_bundle_mac.mm index 1a238a7..0508177 100644 --- a/ui/base/resource/resource_bundle_mac.mm +++ b/ui/base/resource/resource_bundle_mac.mm @@ -46,6 +46,11 @@ FilePath ResourceBundle::GetResourcesFilePath() { } // static +FilePath ResourceBundle::GetLargeIconResourcesFilePath() { + return GetResourcesPakFilePath(@"theme_resources_large", nil); +} + +// static FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) { NSString* mac_locale = base::SysUTF8ToNSString(app_locale); @@ -89,6 +94,21 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { // Cache the converted image. if (ns_image.get()) { + // Load a high resolution version of the icon if available. + if (large_icon_resources_data_) { + scoped_refptr<RefCountedStaticMemory> large_data( + LoadResourceBytes(large_icon_resources_data_, resource_id)); + if (large_data.get()) { + scoped_nsobject<NSData> ns_large_data( + [[NSData alloc] initWithBytes:large_data->front() + length:large_data->size()]); + NSImageRep* image_rep = + [NSBitmapImageRep imageRepWithData:ns_large_data]; + if (image_rep) + [ns_image addRepresentation:image_rep]; + } + } + base::AutoLock lock(*lock_); // Another thread raced the load and has already cached the image. diff --git a/ui/base/resource/resource_bundle_posix.cc b/ui/base/resource/resource_bundle_posix.cc index 97747e0..d2fe55b 100644 --- a/ui/base/resource/resource_bundle_posix.cc +++ b/ui/base/resource/resource_bundle_posix.cc @@ -98,6 +98,14 @@ void ResourceBundle::LoadCommonResources() { CHECK(!resources_file_path.empty()) << "chrome.pak not found"; resources_data_ = LoadResourcesDataPak(resources_file_path); CHECK(resources_data_) << "failed to load chrome.pak"; + + FilePath large_icon_resources_file_path = GetLargeIconResourcesFilePath(); + if (!large_icon_resources_file_path.empty()) { + large_icon_resources_data_ = + LoadResourcesDataPak(large_icon_resources_file_path); + CHECK(large_icon_resources_data_) << + "failed to load theme_resources_large.pak"; + } } std::string ResourceBundle::LoadLocaleResources( diff --git a/ui/gfx/image.cc b/ui/gfx/image.cc index b42e215..389935dc8 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); }; @@ -158,6 +166,12 @@ Image::Image(const SkBitmap* bitmap) AddRepresentation(rep); } +Image::Image(const std::vector<const SkBitmap*>& bitmaps) + : default_representation_(Image::kSkBitmapRep) { + internal::SkBitmapRep* rep = new internal::SkBitmapRep(bitmaps); + AddRepresentation(rep); +} + #if defined(OS_LINUX) Image::Image(GdkPixbuf* pixbuf) : default_representation_(Image::kGdkPixbufRep) { @@ -246,8 +260,9 @@ internal::ImageRep* Image::GetRepresentation(RepresentationType rep_type) { #elif defined(OS_MACOSX) if (default_representation_ == 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); @@ -266,7 +281,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); } @@ -284,4 +299,14 @@ void Image::AddRepresentation(internal::ImageRep* rep) { 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 fddf4da..69117ff 100644 --- a/ui/gfx/image.h +++ b/ui/gfx/image.h @@ -15,6 +15,7 @@ #pragma once #include <map> +#include <vector> #include "base/basictypes.h" #include "base/gtest_prod_util.h" @@ -25,6 +26,7 @@ class SkBitmap; namespace { class ImageTest; +class ImageMacTest; } namespace gfx { @@ -44,11 +46,17 @@ 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 @@ -64,6 +72,16 @@ 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); @@ -92,6 +110,7 @@ class Image { RepresentationMap representations_; friend class ::ImageTest; + friend class ::ImageMacTest; DISALLOW_COPY_AND_ASSIGN(Image); }; diff --git a/ui/gfx/image_mac.mm b/ui/gfx/image_mac.mm index b3dc977..544c214 100644 --- a/ui/gfx/image_mac.mm +++ b/ui/gfx/image_mac.mm @@ -4,14 +4,22 @@ #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 { -const SkBitmap* NSImageToSkBitmap(NSImage* image) { - return new SkBitmap(::gfx::NSImageToSkBitmap(image, [image size], false)); +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; } } // namespace internal diff --git a/ui/gfx/image_mac_unittest.mm b/ui/gfx/image_mac_unittest.mm new file mode 100644 index 0000000..7d19e73 --- /dev/null +++ b/ui/gfx/image_mac_unittest.mm @@ -0,0 +1,114 @@ +// 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. + +#include <Cocoa/Cocoa.h> + +#include "base/logging.h" +#include "base/memory/scoped_nsobject.h" +#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" + +namespace { + +class ImageMacTest : public testing::Test { + public: + size_t GetRepCount(const gfx::Image& image) { + return image.representations_.size(); + } + + void CreateBitmapImageRep(int width, int height, NSImageRep** image_rep) { + scoped_nsobject<NSImage> image([[NSImage alloc] + initWithSize:NSMakeSize(width, height)]); + [image lockFocus]; + [[NSColor redColor] set]; + NSRectFill(NSMakeRect(0, 0, width, height)); + [image unlockFocus]; + EXPECT_TRUE([[[image representations] lastObject] + isKindOfClass:[NSImageRep class]]); + *image_rep = [[image representations] lastObject]; + } +}; + +namespace gt = gfx::test; + +TEST_F(ImageMacTest, MultiResolutionNSImageToSkBitmap) { + const int width1 = 10; + const int height1 = 12; + const int width2 = 20; + const int height2 = 24; + + NSImageRep* image_rep_1; + CreateBitmapImageRep(width1, height1, &image_rep_1); + NSImageRep* image_rep_2; + CreateBitmapImageRep(width2, height2, &image_rep_2); + scoped_nsobject<NSImage> ns_image([[NSImage alloc] + initWithSize:NSMakeSize(width1, height1)]); + [ns_image addRepresentation:image_rep_1]; + [ns_image addRepresentation:image_rep_2]; + + gfx::Image image(ns_image.release()); + + EXPECT_EQ(1u, GetRepCount(image)); + 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); + } + + // GetNumberOfSkBitmaps and GetSkBitmapAtIndex should create a second + // representation. + EXPECT_EQ(2u, GetRepCount(image)); +} + +TEST_F(ImageMacTest, MultiResolutionSkBitmapToNSImage) { + 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, GetRepCount(image)); + EXPECT_EQ(2u, image.GetNumberOfSkBitmaps()); + + NSImage* ns_image = image; + EXPECT_TRUE(ns_image); + + EXPECT_EQ(2u, [[image representations] count]); + NSImageRep* image_rep_1 = [[image representations] objectAtIndex:0]; + NSImageRep* image_rep_2 = [[image representations] objectAtIndex:1]; + + if ([image_rep_1 size].width == width1) { + EXPECT_EQ([image_rep_1 size].height, height1); + EXPECT_EQ([image_rep_2 size].width, width2); + EXPECT_EQ([image_rep_2 size].height, height2); + } else { + EXPECT_EQ([image_rep_1 size].width, width2); + EXPECT_EQ([image_rep_1 size].height, height2); + EXPECT_EQ([image_rep_2 size].width, width1); + EXPECT_EQ([image_rep_2 size].height, height1); + } + + // Cast to NSImage* should create a second representation. + EXPECT_EQ(2u, GetRepCount(image)); +} + +} // namespace diff --git a/ui/gfx/image_unittest.cc b/ui/gfx/image_unittest.cc index 6f41bfe..f02a2fa 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.h" +#include "ui/gfx/image_unittest_util.h" #if defined(OS_LINUX) #include <gtk/gtk.h> @@ -34,7 +34,7 @@ class ImageTest : public testing::Test { namespace gt = gfx::test; TEST_F(ImageTest, SkiaToSkia) { - gfx::Image image(gt::CreateBitmap()); + gfx::Image image(gt::CreateBitmap(25, 25)); const SkBitmap* bitmap = static_cast<const SkBitmap*>(image); EXPECT_TRUE(bitmap); EXPECT_FALSE(bitmap->isNull()); @@ -52,7 +52,7 @@ TEST_F(ImageTest, SkiaToSkia) { } TEST_F(ImageTest, SkiaToSkiaRef) { - gfx::Image image(gt::CreateBitmap()); + gfx::Image image(gt::CreateBitmap(25, 25)); const SkBitmap& bitmap = static_cast<const SkBitmap&>(image); EXPECT_FALSE(bitmap.isNull()); @@ -68,7 +68,7 @@ TEST_F(ImageTest, SkiaToSkiaRef) { } TEST_F(ImageTest, SkiaToPlatform) { - gfx::Image image(gt::CreateBitmap()); + gfx::Image image(gt::CreateBitmap(25, 25)); const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; EXPECT_TRUE(image.HasRepresentation(gfx::Image::kSkBitmapRep)); @@ -131,7 +131,7 @@ TEST_F(ImageTest, CheckSkiaColor) { TEST_F(ImageTest, SwapRepresentations) { const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; - gfx::Image image1(gt::CreateBitmap()); + gfx::Image image1(gt::CreateBitmap(25, 25)); const SkBitmap* bitmap1 = image1; EXPECT_EQ(1U, GetRepCount(image1)); @@ -149,6 +149,41 @@ TEST_F(ImageTest, SwapRepresentations) { EXPECT_EQ(1U, GetRepCount(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, GetRepCount(image)); + 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, GetRepCount(image)); + 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_util.cc index 09abfce..b996a86 100644 --- a/ui/gfx/image_unittest.h +++ b/ui/gfx/image_unittest_util.cc @@ -5,10 +5,8 @@ // 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 "ui/gfx/image_unittest_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -22,24 +20,16 @@ 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* CreateBitmap(int width, int height) { SkBitmap* bitmap = new SkBitmap(); - bitmap->setConfig(SkBitmap::kARGB_8888_Config, 25, 25); + bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); bitmap->allocPixels(); bitmap->eraseRGB(255, 0, 0); return bitmap; } PlatformImage CreatePlatformImage() { - scoped_ptr<SkBitmap> bitmap(CreateBitmap()); + scoped_ptr<SkBitmap> bitmap(CreateBitmap(25, 25)); #if defined(OS_MACOSX) NSImage* image = gfx::SkBitmapToNSImage(*(bitmap.get())); base::mac::NSObjectRetain(image); @@ -63,5 +53,3 @@ gfx::Image::RepresentationType GetPlatformRepresentationType() { } // namespace test } // namespace gfx - -#endif // UI_GFX_IMAGE_UNITTEST_H_ diff --git a/ui/gfx/image_unittest_util.h b/ui/gfx/image_unittest_util.h new file mode 100644 index 0000000..f087f90 --- /dev/null +++ b/ui/gfx/image_unittest_util.h @@ -0,0 +1,33 @@ +// 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_UTIL_H_ +#define UI_GFX_IMAGE_UNITTEST_UTIL_H_ + +#include "ui/gfx/image.h" + +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(int width, int height); + +PlatformImage CreatePlatformImage(); + +gfx::Image::RepresentationType GetPlatformRepresentationType(); + +} // namespace test +} // namespace gfx + +#endif // UI_GFX_IMAGE_UNITTEST_UTIL_H_ diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi index 2a767a4..2867afb 100644 --- a/ui/ui_unittests.gypi +++ b/ui/ui_unittests.gypi @@ -32,8 +32,10 @@ '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.h', + 'gfx/image_unittest_util.h', + 'gfx/image_unittest_util.cc', 'gfx/insets_unittest.cc', 'gfx/rect_unittest.cc', 'gfx/run_all_unittests.cc', |