diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-19 23:18:22 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-19 23:18:22 +0000 |
commit | abe92999c62ebc866b8a0451b3a1eb1d71e37391 (patch) | |
tree | 3ead886a3c26bda2a80373ffde83b980941158ef /ui/gfx/image_mac_unittest.mm | |
parent | a1d19d7439593f3bca7a0b4b8cc3be442a3c1272 (diff) | |
download | chromium_src-abe92999c62ebc866b8a0451b3a1eb1d71e37391.zip chromium_src-abe92999c62ebc866b8a0451b3a1eb1d71e37391.tar.gz chromium_src-abe92999c62ebc866b8a0451b3a1eb1d71e37391.tar.bz2 |
Add support for multi resolution icons
To support HiDPI we need a way to load two copies of icons, a low resolution version and a high resolution version.
To support this, this change does the following:
- split theme_resource.grd into three files:
- theme_resources.grd: icons that only have one resolution
- theme_resources_standard.grd: low resolution icons
- theme_resources_large.grd: high resolution icons
- theme_resource.grd and theme_resources_standard.grd and compiled into chrome.pak/chrome.rc for all platforms.
- theme_resources_large.grd is compiled into theme_resources_large.pak for platforms that want high resolution icons (currently only Mac)
- gfx::Image now support icons with multiple resolution
Currently not all ThemeService APIs return multi-resolution images. Once this is checked in I'll work on converting them as I go.
Note, this change will have to be coordinated with the change to reorganize theme resources. I'll work with saintlou on that.
BUG=75812
TEST=Added a TIFF to theme_resources.grd. Verified that the toolbar icon had a mutliresolution image. Verified that unit tests passed.
Review URL: http://codereview.chromium.org/6849030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82185 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/image_mac_unittest.mm')
-rw-r--r-- | ui/gfx/image_mac_unittest.mm | 114 |
1 files changed, 114 insertions, 0 deletions
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 |