diff options
author | caryclark@google.com <caryclark@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-11 17:37:17 +0000 |
---|---|---|
committer | caryclark@google.com <caryclark@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-11 17:37:17 +0000 |
commit | b8c84c061a245ee966bb42d5e7942560688910db (patch) | |
tree | 7dc6a96937d72e2ecfa0600a5787ed67b236d75e /skia/ext/skia_utils_mac_unittest.mm | |
parent | e18b9c2762c2a863e3737a75647500b252d143d1 (diff) | |
download | chromium_src-b8c84c061a245ee966bb42d5e7942560688910db.zip chromium_src-b8c84c061a245ee966bb42d5e7942560688910db.tar.gz chromium_src-b8c84c061a245ee966bb42d5e7942560688910db.tar.bz2 |
Create a local bitmap to capture CoreGraphics rendering
when the canvas is not backed by a bitmap.
During normal desktop drawing, CoreGraphics calls that
image theme elements like checkboxes and buttons draw
into the device bitmap owned by Skia's canvas. When a
PDF is created as part of a print preview, no bitmap is
allocated.
In the latter case, associate a local array of pixels
with the CGContext to capture the theme rendering, then
draw it with Skia once the theme rendering is complete.
This fix over-allocates memory. It creates a pixel map
as large as the device. The bounds of the CG drawing is
not visible to Skia, and the clip may not be set. The
PDF may be larger than need be for the same reason.
In a subsequent change, the theme element's bounds
can reduce the size of the bitmap allocation. This could
be done by setting the clip or by passing the rectangle
to the graphics context. This would require a sizeable
edit to RenderThemeMac.mm.
Also, change the unit test to test both paths, when the
device is backed by a bitmap, and when it is not. This
requires the unit test to call the destructor and reset
the clip before comparing the results.
BUG=121752
TEST=http://stmarksparish.com/printtest.aspx, print to PDF
TEST=SkiaUtilsMacTest.BitLocker_*
Review URL: https://chromiumcodereview.appspot.com/10031005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131795 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext/skia_utils_mac_unittest.mm')
-rw-r--r-- | skia/ext/skia_utils_mac_unittest.mm | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/skia/ext/skia_utils_mac_unittest.mm b/skia/ext/skia_utils_mac_unittest.mm index b2175cd..24310b0 100644 --- a/skia/ext/skia_utils_mac_unittest.mm +++ b/skia/ext/skia_utils_mac_unittest.mm @@ -25,7 +25,11 @@ class SkiaUtilsMacTest : public testing::Test { TestIdentity = 0, TestTranslate = 1, TestClip = 2, - TestXClip = TestTranslate | TestClip + TestXClip = TestTranslate | TestClip, + TestNoBits = 4, + TestTranslateNoBits = TestTranslate | TestNoBits, + TestClipNoBits = TestClip | TestNoBits, + TestXClipNoBits = TestXClip | TestNoBits, }; void RunBitLockerTest(BitLockerTest test); @@ -119,7 +123,9 @@ void SkiaUtilsMacTest::RunBitLockerTest(BitLockerTest test) { memcpy(bits, original, sizeof(original)); SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); - bitmap.setPixels(bits); + if (!(test & TestNoBits)) { + bitmap.setPixels(bits); + } SkCanvas canvas; canvas.setBitmapDevice(bitmap); if (test & TestTranslate) @@ -128,12 +134,22 @@ void SkiaUtilsMacTest::RunBitLockerTest(BitLockerTest test) { SkRect clipRect = {0, height / 2, width, height}; canvas.clipRect(clipRect); } - gfx::SkiaBitLocker bitLocker(&canvas); - CGContextRef cgContext = bitLocker.cgContext(); - CGColorRef testColor = CGColorGetConstantColor(kCGColorWhite); - CGContextSetFillColorWithColor(cgContext, testColor); - CGRect cgRect = {{0, 0}, {width, height}}; - CGContextFillRect(cgContext, cgRect); + { + gfx::SkiaBitLocker bitLocker(&canvas); + CGContextRef cgContext = bitLocker.cgContext(); + CGColorRef testColor = CGColorGetConstantColor(kCGColorWhite); + CGContextSetFillColorWithColor(cgContext, testColor); + CGRect cgRect = {{0, 0}, {width, height}}; + CGContextFillRect(cgContext, cgRect); + if (test & TestNoBits) { + bitmap.setPixels(bits); + canvas.setBitmapDevice(bitmap); + if (test & TestClip) { + SkRect clipRect = {0, height / 2, width, height}; + canvas.clipRect(clipRect); + } + } + } const unsigned results[][storageSize] = { {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}, // identity {0xFF333333, 0xFFFFFFFF, 0xFF999999, 0xFFFFFFFF}, // translate @@ -141,7 +157,7 @@ void SkiaUtilsMacTest::RunBitLockerTest(BitLockerTest test) { {0xFF333333, 0xFF666666, 0xFF999999, 0xFFFFFFFF} // translate | clip }; for (unsigned index = 0; index < storageSize; index++) - EXPECT_EQ(results[test][index], bits[index]); + EXPECT_EQ(results[test & ~TestNoBits][index], bits[index]); } void SkiaUtilsMacTest::ShapeHelper(int width, int height, @@ -231,5 +247,21 @@ TEST_F(SkiaUtilsMacTest, BitLocker_XClip) { RunBitLockerTest(SkiaUtilsMacTest::TestXClip); } +TEST_F(SkiaUtilsMacTest, BitLocker_NoBits) { + RunBitLockerTest(SkiaUtilsMacTest::TestNoBits); +} + +TEST_F(SkiaUtilsMacTest, BitLocker_TranslateNoBits) { + RunBitLockerTest(SkiaUtilsMacTest::TestTranslateNoBits); +} + +TEST_F(SkiaUtilsMacTest, BitLocker_ClipNoBits) { + RunBitLockerTest(SkiaUtilsMacTest::TestClipNoBits); +} + +TEST_F(SkiaUtilsMacTest, BitLocker_XClipNoBits) { + RunBitLockerTest(SkiaUtilsMacTest::TestXClipNoBits); +} + } // namespace |