summaryrefslogtreecommitdiffstats
path: root/skia/ext/skia_utils_mac_unittest.mm
diff options
context:
space:
mode:
authorsail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-20 20:35:44 +0000
committersail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-20 20:35:44 +0000
commit89d03e277a46afa96c83d3168b5b952a5970cf1a (patch)
tree7bcf2121999b03e2dbaa526fb9ff482000ea050f /skia/ext/skia_utils_mac_unittest.mm
parentd19ea34f835815a4768bb03a6863eb3dba3613c1 (diff)
downloadchromium_src-89d03e277a46afa96c83d3168b5b952a5970cf1a.zip
chromium_src-89d03e277a46afa96c83d3168b5b952a5970cf1a.tar.gz
chromium_src-89d03e277a46afa96c83d3168b5b952a5970cf1a.tar.bz2
Revert high res icon changes
The new high res icon change may have caused a perf regression. To verify I'm reverting the following chnages: commit 3a360c6b3d2fc174cb7597d6365cfc5418d1442b r82326 Disable loading high res icons on Mac commit 3c39226937a39d0042b8a794f13505c7a25ca58b r82247 Fix reload button unit test commit f87ab117fc159566868e71e4df5672852bebd718 r82245 Unregister toolbar view from window notifications commit 0b287ba4a4ad5c19d901f973eb9af594dcf3dba1 r82239 Fix failing Mac unit tests commit 8b681c46a139d12151323952c58122f6805d7597 r82236 Mac: Remove custom drawn buttons commit 6ae8a2fe40485731b86267e362936db16b4c0706 r82209 Fix clang build break commit e8a19d1e0c76f204c834318566e4206320583449 r82185 Add support for multi resolution icons BUG=None TEST=Compling Review URL: http://codereview.chromium.org/6878077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82352 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext/skia_utils_mac_unittest.mm')
-rw-r--r--skia/ext/skia_utils_mac_unittest.mm144
1 files changed, 23 insertions, 121 deletions
diff --git a/skia/ext/skia_utils_mac_unittest.mm b/skia/ext/skia_utils_mac_unittest.mm
index a0f8d06..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,47 +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);
-
- // Due to colorspace issues the colors may not match exactly.
- // TODO(sail): Need to fix this, http://crbug.com/79946
- if (isred) {
- EXPECT_NEAR(255u, SkColorGetR(color), 20);
- EXPECT_NEAR(0u, SkColorGetB(color), 20);
+ EXPECT_GT(red, 0.95);
+ EXPECT_LT(blue, 0.05);
} else {
- EXPECT_NEAR(0u, SkColorGetR(color), 20);
- EXPECT_NEAR(255u, SkColorGetB(color), 20);
+ EXPECT_LT(red, 0.05);
+ EXPECT_GT(blue, 0.95);
}
- EXPECT_NEAR(0u, SkColorGetG(color), 20);
- EXPECT_NEAR(255u, SkColorGetA(color), 20);
-}
-
-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) {
@@ -128,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, 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