diff options
author | amanda@chromium.org <amanda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-25 01:01:52 +0000 |
---|---|---|
committer | amanda@chromium.org <amanda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-25 01:01:52 +0000 |
commit | 8860e4f513e757810afecfb62a2bd282cd731ed9 (patch) | |
tree | a1905994c55ee794c1e4d3e450ba009f8d5f65f1 /chrome/browser/cocoa | |
parent | 2d896aedfc2630ee7a7c973e84d69f5099104767 (diff) | |
download | chromium_src-8860e4f513e757810afecfb62a2bd282cd731ed9.zip chromium_src-8860e4f513e757810afecfb62a2bd282cd731ed9.tar.gz chromium_src-8860e4f513e757810afecfb62a2bd282cd731ed9.tar.bz2 |
Update WebKit to 45111 and Skia to 239
Review URL: http://codereview.chromium.org/147121
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/cocoa_utils.mm | 66 | ||||
-rw-r--r-- | chrome/browser/cocoa/cocoa_utils_unittest.mm | 17 |
2 files changed, 7 insertions, 76 deletions
diff --git a/chrome/browser/cocoa/cocoa_utils.mm b/chrome/browser/cocoa/cocoa_utils.mm index 4bc65a3..9c7584d 100644 --- a/chrome/browser/cocoa/cocoa_utils.mm +++ b/chrome/browser/cocoa/cocoa_utils.mm @@ -21,71 +21,9 @@ void ReleaseData(void* info, const void* pixelData, size_t size) { namespace CocoaUtils { -NSImage* SkBitmapToNSImage(const SkBitmap& icon) { +NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) { // First convert SkBitmap to CGImageRef. - CGImageRef cgimage; - if (icon.config() != SkBitmap::kARGB_8888_Config) { - cgimage = SkCreateCGImageRef(icon); - } else { - // The above code returns a valid NSImage even in the - // kARGB_8888_Config case. As an example, the unit test which - // draws a blue SkBitmap can lockPixels, NSReadPixel, and pull out - // a single pixel from the NSImage and see it blue. However, the - // NSImage returned will be in ABGR format. Although Cocoa is - // otherwise happy with that format (as seen in simple tests - // outside Chromium), Chromium is NOT happy. In Chromium, B and R - // are swapped. - // - // As a hint, CIImage supports a few formats, such as ARGB. - // Interestingly, it does NOT support ABGR. I speculate there is - // some way we set up our drawing context which has the format - // specified wrong (in skia/ext/bitmap_platform_device_mac.cc), - // but I have not been able to solve this yet. - // - // TODO(jrg): track down the disconnect. - // TODO(jrg): Remove byte conversion. - // TODO(jrg): Fix unit tests to NOT swap bytes. - // http://crbug.com/14020 - CGBitmapInfo info = (kCGImageAlphaPremultipliedFirst | - kCGBitmapByteOrder32Host); - int width = icon.width(); - int height = icon.height(); - int rowbytes = icon.rowBytes(); - int rowwords = rowbytes/4; - unsigned length = rowbytes * height; - DCHECK(length > 0); - uint32_t* rawptr = static_cast<uint32_t*>(malloc(length)); - DCHECK(rawptr); - if (!rawptr || !length) - return nil; - - // Convert ABGR to ARGB - icon.lockPixels(); - uint32_t* rawbitmap = static_cast<uint32_t*>(icon.getPixels()); - uint32_t rawbit; - int offset; - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - offset = x + y*rowwords; - rawbit = rawbitmap[offset]; - rawptr[offset] = SkPackARGB32(SkGetPackedA32(rawbit), - SkGetPackedR32(rawbit), - SkGetPackedG32(rawbit), - SkGetPackedB32(rawbit)); - } - } - icon.unlockPixels(); - - CGDataProviderRef dataRef = - CGDataProviderCreateWithData(rawptr, rawptr, length, ReleaseData); - CGColorSpaceRef space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); - cgimage = CGImageCreate(width, height, 8, - icon.bytesPerPixel() * 8, - rowbytes, space, info, dataRef, - NULL, false, kCGRenderingIntentDefault); - CGColorSpaceRelease(space); - CGDataProviderRelease(dataRef); - } + CGImageRef cgimage = SkCreateCGImageRef(skiaBitmap); // Now convert to NSImage. NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc] diff --git a/chrome/browser/cocoa/cocoa_utils_unittest.mm b/chrome/browser/cocoa/cocoa_utils_unittest.mm index 7812f2c..41e188f 100644 --- a/chrome/browser/cocoa/cocoa_utils_unittest.mm +++ b/chrome/browser/cocoa/cocoa_utils_unittest.mm @@ -14,12 +14,11 @@ class CocoaUtilsTest : public testing::Test { // If not red, is blue. // If not tfbit (twenty-four-bit), is 444. - // If swap, swap R and B before testing (see TODOs in cocoa_utils.mm) - void ShapeHelper(int width, int height, bool isred, bool tfbit, bool swap); + void ShapeHelper(int width, int height, bool isred, bool tfbit); }; void CocoaUtilsTest::ShapeHelper(int width, int height, - bool isred, bool tfbit, bool swap) { + bool isred, bool tfbit) { SkBitmap thing; if (tfbit) @@ -48,12 +47,6 @@ void CocoaUtilsTest::ShapeHelper(int width, int height, [image unlockFocus]; [color getRed:&red green:&green blue:&blue alpha:&alpha]; - if (swap) { - CGFloat tmp = red; - red = blue; - blue = tmp; - } - // Be tolerant of floating point rounding, gamma, etc. if (isred) { EXPECT_GT(red, 0.8); @@ -68,15 +61,15 @@ void CocoaUtilsTest::ShapeHelper(int width, int height, TEST_F(CocoaUtilsTest, BitmapToNSImage_RedSquare64x64) { - ShapeHelper(64, 64, true, true, true); + ShapeHelper(64, 64, true, true); } TEST_F(CocoaUtilsTest, BitmapToNSImage_BlueRectangle199x19) { - ShapeHelper(199, 19, false, true, true); + ShapeHelper(199, 19, false, true); } TEST_F(CocoaUtilsTest, BitmapToNSImage_BlueRectangle444) { - ShapeHelper(200, 200, false, false, false); + ShapeHelper(200, 200, false, false); } |