diff options
author | junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-07-23 13:35:14 +0000 |
---|---|---|
committer | junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-07-23 13:35:14 +0000 |
commit | bfeddae9da240693441556b2f278827e213f75e8 (patch) | |
tree | da8eae02490967677ab398adef409ea0bfdcf6ca /tests | |
parent | 47580694fbe974a065caf7c39c3d2075708c2018 (diff) |
Fix unbound memory consumption problem with run away deferred canvases.
With this CL, deferred canvases will trigger a flush when then the
memory allocated for recording commands (including flattened objects)
exceeds 64MB.
TEST=DeferredCanvas skia unit test, test step TestDeferredCanvasMemoryLimit
BUG=http://code.google.com/p/chromium/issues/detail?id=137884
Review URL: https://codereview.appspot.com/6425053
git-svn-id: http://skia.googlecode.com/svn/trunk@4714 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/DeferredCanvasTest.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp index 17adb52118..449f5e97bc 100644 --- a/tests/DeferredCanvasTest.cpp +++ b/tests/DeferredCanvasTest.cpp @@ -10,7 +10,6 @@ #include "SkDeferredCanvas.h" #include "SkShader.h" - static const int gWidth = 2; static const int gHeight = 2; @@ -177,10 +176,54 @@ static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) { } } +class MockDevice : public SkDevice { +public: + MockDevice(const SkBitmap& bm) : SkDevice(bm) { + fDrawBitmapCallCount = 0; + } + virtual void drawBitmap(const SkDraw&, const SkBitmap&, + const SkIRect*, + const SkMatrix&, const SkPaint&) { + fDrawBitmapCallCount++; + } + + int fDrawBitmapCallCount; +}; + +// Verifies that the deferred canvas triggers a flush when its memory +// limit is exceeded +static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) { + SkBitmap store; + store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); + store.allocPixels(); + MockDevice mockDevice(store); + SkDeferredCanvas canvas(&mockDevice); + canvas.setMaxRecordingStorage(160000); + + SkBitmap sourceImage; + // 100 by 100 image, takes 40,000 bytes in memory + sourceImage.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); + sourceImage.allocPixels(); + + for (int i = 0; i < 6; i++) { + sourceImage.notifyPixelsChanged(); // to force re-serialization + canvas.drawBitmap(sourceImage, 0, 0, NULL); + } + + // FIXME: Test temporarily disabled because the SkPicture path is not + // fixed and the SkGPipe path does not yet serialize images, but it + // will soon. +#if 0 + REPORTER_ASSERT(reporter, mockDevice.fDrawBitmapCallCount == 4); +#endif +} + + static void TestDeferredCanvas(skiatest::Reporter* reporter) { TestDeferredCanvasBitmapAccess(reporter); TestDeferredCanvasFlush(reporter); TestDeferredCanvasFreshFrame(reporter); + TestDeferredCanvasMemoryLimit(reporter); } #include "TestClassDef.h" |