summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-25 13:58:34 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-25 13:58:34 +0000
commitef8ca82edcb77b5c78fbe8c3a87338713ad72890 (patch)
treee79e17383340ed975b68a235f292f57dda1eea6d /skia
parent2f66e8ce0f3ac83e5dbc80bfa52760bb1a903ced (diff)
downloadchromium_src-ef8ca82edcb77b5c78fbe8c3a87338713ad72890.zip
chromium_src-ef8ca82edcb77b5c78fbe8c3a87338713ad72890.tar.gz
chromium_src-ef8ca82edcb77b5c78fbe8c3a87338713ad72890.tar.bz2
Add favicons to tabs on the Mac. Also moved SkBitmapToNSImage() to
skia/ext/skia_utils_mac.h and removed chrome/browser/cocoa/cocoa_utils.h. Patch by rsesek. BUG=13565 Review URL: http://codereview.chromium.org/131018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19244 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/skia_utils_mac.h3
-rw-r--r--skia/ext/skia_utils_mac.mm15
-rw-r--r--skia/ext/skia_utils_mac_unittest.mm71
3 files changed, 89 insertions, 0 deletions
diff --git a/skia/ext/skia_utils_mac.h b/skia/ext/skia_utils_mac.h
index 14cd17f..06cb151 100644
--- a/skia/ext/skia_utils_mac.h
+++ b/skia/ext/skia_utils_mac.h
@@ -57,6 +57,9 @@ SkBitmap CGImageToSkBitmap(CGImageRef image);
#ifdef __OBJC__
// Draws an NSImage with a given size into a SkBitmap.
SkBitmap NSImageToSkBitmap(NSImage* image, NSSize size, bool is_opaque);
+
+// Given an SkBitmap, return an autoreleased NSImage.
+NSImage* SkBitmapToNSImage(const SkBitmap& icon);
#endif
} // namespace gfx
diff --git a/skia/ext/skia_utils_mac.mm b/skia/ext/skia_utils_mac.mm
index 463fd52..cdf49cc 100644
--- a/skia/ext/skia_utils_mac.mm
+++ b/skia/ext/skia_utils_mac.mm
@@ -10,6 +10,8 @@
#include "base/scoped_cftyperef.h"
#include "base/scoped_ptr.h"
#include "skia/ext/bitmap_platform_device_mac.h"
+#include "third_party/skia/include/utils/mac/SkCGUtils.h"
+#include "third_party/skia/include/core/SkColorPriv.h"
namespace gfx {
@@ -165,4 +167,17 @@ SkBitmap NSImageToSkBitmap(NSImage* image, NSSize size, bool is_opaque) {
return bitmap;
}
+NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) {
+ // First convert SkBitmap to CGImageRef.
+ CGImageRef cgimage = SkCreateCGImageRef(skiaBitmap);
+
+ // Now convert to NSImage.
+ NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc]
+ initWithCGImage:cgimage] autorelease];
+ CFRelease(cgimage);
+ NSImage* image = [[[NSImage alloc] init] autorelease];
+ [image addRepresentation:bitmap];
+ return image;
+}
+
} // namespace gfx
diff --git a/skia/ext/skia_utils_mac_unittest.mm b/skia/ext/skia_utils_mac_unittest.mm
new file mode 100644
index 0000000..c29a249
--- /dev/null
+++ b/skia/ext/skia_utils_mac_unittest.mm
@@ -0,0 +1,71 @@
+// Copyright (c) 2009 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 "skia/ext/skia_utils_mac.mm"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class SkiaUtilsMacTest : public testing::Test {
+ public:
+ // If not red, is blue.
+ // If not tfbit (twenty-four-bit), is 444.
+ void ShapeHelper(int width, int height, bool isred, bool tfbit);
+};
+
+void SkiaUtilsMacTest::ShapeHelper(int width, int height,
+ bool isred, bool tfbit) {
+ SkBitmap thing;
+
+ if (tfbit)
+ thing.setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ else
+ thing.setConfig(SkBitmap::kARGB_4444_Config, width, height);
+ thing.allocPixels();
+
+ if (isred)
+ thing.eraseRGB(0xff, 0, 0);
+ else
+ thing.eraseRGB(0, 0, 0xff);
+
+ // Confirm size
+ NSImage* image = gfx::SkBitmapToNSImage(thing);
+ EXPECT_DOUBLE_EQ([image size].width, (double)width);
+ EXPECT_DOUBLE_EQ([image size].height, (double)height);
+
+ // Get the color of a pixel and make sure it looks fine
+ [image lockFocus];
+
+ 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];
+ [color getRed:&red green:&green blue:&blue alpha:&alpha];
+
+ // Be tolerant of floating point rounding, gamma, etc.
+ if (isred) {
+ EXPECT_GT(red, 0.8);
+ EXPECT_LT(blue, 0.2);
+ } else {
+ EXPECT_LT(red, 0.2);
+ EXPECT_GT(blue, 0.8);
+ }
+ EXPECT_LT(green, 0.2);
+ EXPECT_GT(alpha, 0.9);
+}
+
+TEST_F(SkiaUtilsMacTest, BitmapToNSImage_RedSquare64x64) {
+ ShapeHelper(64, 64, true, true);
+}
+
+TEST_F(SkiaUtilsMacTest, BitmapToNSImage_BlueRectangle199x19) {
+ ShapeHelper(199, 19, false, true);
+}
+
+TEST_F(SkiaUtilsMacTest, BitmapToNSImage_BlueRectangle444) {
+ ShapeHelper(200, 200, false, false);
+}
+
+} // namespace