remove (unused by chrome) SkDeferredCanvas(device) factory signature
BUG=skia:
R=junov@chromium.org
Review URL: https://codereview.chromium.org/136753016
git-svn-id: http://skia.googlecode.com/svn/trunk@13302 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/bench/DeferredCanvasBench.cpp b/bench/DeferredCanvasBench.cpp
index 6bf4dfd..b063a9c 100644
--- a/bench/DeferredCanvasBench.cpp
+++ b/bench/DeferredCanvasBench.cpp
@@ -25,6 +25,7 @@
}
virtual void onDraw(const int loops, SkCanvas* canvas) {
+#if 0 // what specifically are we interested in timing here?
SkBaseDevice *device = canvas->getDevice()->createCompatibleDevice(
SkBitmap::kARGB_8888_Config, CANVAS_WIDTH, CANVAS_HEIGHT, false);
@@ -35,6 +36,7 @@
drawInDeferredCanvas(loops, deferredCanvas);
finalizeDeferredCanvas(deferredCanvas);
deferredCanvas->flush();
+#endif
}
virtual void initDeferredCanvas(SkDeferredCanvas* canvas) = 0;
diff --git a/include/utils/SkDeferredCanvas.h b/include/utils/SkDeferredCanvas.h
index d621785..b0435de 100644
--- a/include/utils/SkDeferredCanvas.h
+++ b/include/utils/SkDeferredCanvas.h
@@ -33,7 +33,7 @@
*/
static SkDeferredCanvas* Create(SkSurface* surface);
- static SkDeferredCanvas* Create(SkBaseDevice* device);
+// static SkDeferredCanvas* Create(SkBaseDevice* device);
virtual ~SkDeferredCanvas();
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index 27627ab..1cb6d37 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -140,7 +140,6 @@
// FIXME: Derive from SkBaseDevice.
class DeferredDevice : public SkBitmapDevice {
public:
- explicit DeferredDevice(SkBaseDevice* immediateDevice);
explicit DeferredDevice(SkSurface* surface);
~DeferredDevice();
@@ -254,17 +253,6 @@
size_t fBitmapSizeThreshold;
};
-DeferredDevice::DeferredDevice(SkBaseDevice* immediateDevice)
- : SkBitmapDevice(SkBitmap::kNo_Config,
- immediateDevice->width(), immediateDevice->height(),
- immediateDevice->isOpaque(),
- immediateDevice->getDeviceProperties()) {
- fSurface = NULL;
- fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice));
- fPipeController.setPlaybackCanvas(fImmediateCanvas);
- this->init();
-}
-
DeferredDevice::DeferredDevice(SkSurface* surface)
: SkBitmapDevice(SkBitmap::kNo_Config,
surface->getCanvas()->getDevice()->width(),
@@ -551,11 +539,6 @@
return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice));
}
-SkDeferredCanvas* SkDeferredCanvas::Create(SkBaseDevice* device) {
- SkAutoTUnref<DeferredDevice> deferredDevice(SkNEW_ARGS(DeferredDevice, (device)));
- return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice));
-}
-
SkDeferredCanvas::SkDeferredCanvas(DeferredDevice* device) : SkCanvas (device) {
this->init();
}
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index bddba59..55169cc 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -61,6 +61,7 @@
#include "SkRegion.h"
#include "SkShader.h"
#include "SkStream.h"
+#include "SkSurface.h"
#include "SkTDArray.h"
#include "Test.h"
@@ -140,6 +141,12 @@
bm->eraseColor(color);
}
+static SkSurface* createSurface(SkColor color) {
+ SkSurface* surface = SkSurface::NewRasterPMColor(kWidth, kHeight);
+ surface->getCanvas()->clear(color);
+ return surface;
+}
+
class CanvasTestStep;
static SkTDArray<CanvasTestStep*>& testStepArray() {
static SkTDArray<CanvasTestStep*> theTests;
@@ -749,10 +756,9 @@
CanvasTestStep* testStep,
const SkCanvas& referenceCanvas, bool silent) {
- SkBitmap deferredStore;
- createBitmap(&deferredStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
- SkBitmapDevice deferredDevice(deferredStore);
- SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(&deferredDevice));
+ SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF));
+ SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(surface.get()));
+
testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat);
testStep->draw(deferredCanvas, reporter);
testStep->setAssertMessageFormat(kDeferredPreFlushAssertMessageFormat);
diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp
index d15eeff..75c20c1 100644
--- a/tests/DeferredCanvasTest.cpp
+++ b/tests/DeferredCanvasTest.cpp
@@ -13,6 +13,7 @@
#include "SkDeferredCanvas.h"
#include "SkGradientShader.h"
#include "SkShader.h"
+#include "SkSurface.h"
#include "Test.h"
#if SK_SUPPORT_GPU
#include "GrContextFactory.h"
@@ -29,20 +30,39 @@
bm->eraseColor(color);
}
+static SkSurface* createSurface(SkColor color) {
+ SkSurface* surface = SkSurface::NewRasterPMColor(gWidth, gHeight);
+ surface->getCanvas()->clear(color);
+ return surface;
+}
+
+static SkPMColor read_pixel(SkSurface* surface, int x, int y) {
+ SkPMColor pixel = 0;
+ SkBitmap bitmap;
+ bitmap.installPixels(SkImageInfo::MakeN32Premul(1, 1), &pixel, 4, NULL, NULL);
+ SkCanvas canvas(bitmap);
+
+ SkPaint paint;
+ paint.setXfermodeMode(SkXfermode::kSrc_Mode);
+ surface->draw(&canvas, -x, -y, &paint);
+ return pixel;
+}
+
static void TestDeferredCanvasBitmapAccess(skiatest::Reporter* reporter) {
SkBitmap store;
- create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
- SkBitmapDevice device(store);
- SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
-
+ SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF));
+ SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
+
canvas->clear(0x00000000);
- SkAutoLockPixels alp(store);
- REPORTER_ASSERT(reporter, store.getColor(0,0) == 0xFFFFFFFF); //verify that clear was deferred
+ // verify that the clear() was deferred
+ REPORTER_ASSERT(reporter, 0xFFFFFFFF == read_pixel(surface, 0, 0));
+
SkBitmap accessed = canvas->getDevice()->accessBitmap(false);
- REPORTER_ASSERT(reporter, store.getColor(0,0) == 0x00000000); //verify that clear was executed
- REPORTER_ASSERT(reporter, accessed.pixelRef() == store.pixelRef());
+
+ // verify that clear was executed
+ REPORTER_ASSERT(reporter, 0 == read_pixel(surface, 0, 0));
}
class MockSurface : public SkSurface_Base {
@@ -256,31 +276,30 @@
}
static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) {
- SkBitmap store;
-
- create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
- SkBitmapDevice device(store);
- SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
+ SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF));
+ SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
canvas->clear(0x00000000);
- SkAutoLockPixels alp(store);
- REPORTER_ASSERT(reporter, store.getColor(0,0) == 0xFFFFFFFF); //verify that clear was deferred
+ // verify that clear was deferred
+ REPORTER_ASSERT(reporter, 0xFFFFFFFF == read_pixel(surface, 0, 0));
+
canvas->flush();
- REPORTER_ASSERT(reporter, store.getColor(0,0) == 0x00000000); //verify that clear was executed
+
+ // verify that clear was executed
+ REPORTER_ASSERT(reporter, 0 == read_pixel(surface, 0, 0));
}
static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) {
- SkBitmap store;
SkRect fullRect;
fullRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(gWidth),
SkIntToScalar(gHeight));
SkRect partialRect;
partialRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0),
SkIntToScalar(1), SkIntToScalar(1));
- create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
- SkBitmapDevice device(store);
- SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
+
+ SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF));
+ SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
// verify that frame is intially fresh
REPORTER_ASSERT(reporter, canvas->isFreshFrame());
@@ -446,29 +465,6 @@
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);
- SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&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 < 5; i++) {
- sourceImage.notifyPixelsChanged(); // to force re-serialization
- canvas->drawBitmap(sourceImage, 0, 0, NULL);
- }
-
- REPORTER_ASSERT(reporter, mockDevice.fDrawBitmapCallCount == 4);
-}
-
class NotificationCounter : public SkDeferredCanvas::NotificationClient {
public:
NotificationCounter() {
@@ -498,13 +494,35 @@
typedef SkDeferredCanvas::NotificationClient INHERITED;
};
-static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) {
- SkBitmap store;
- store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
- store.allocPixels();
- SkBitmapDevice device(store);
+// Verifies that the deferred canvas triggers a flush when its memory
+// limit is exceeded
+static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) {
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+ SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
+
NotificationCounter notificationCounter;
- SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
+ canvas->setNotificationClient(¬ificationCounter);
+
+ 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 < 5; i++) {
+ sourceImage.notifyPixelsChanged(); // to force re-serialization
+ canvas->drawBitmap(sourceImage, 0, 0, NULL);
+ }
+
+ REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount);
+}
+
+static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) {
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+ SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
+
+ NotificationCounter notificationCounter;
canvas->setNotificationClient(¬ificationCounter);
const int imageCount = 2;
@@ -582,12 +600,10 @@
}
static void TestDeferredCanvasSkip(skiatest::Reporter* reporter) {
- SkBitmap store;
- store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
- store.allocPixels();
- SkBitmapDevice device(store);
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+ SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
+
NotificationCounter notificationCounter;
- SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
canvas->setNotificationClient(¬ificationCounter);
canvas->clear(0x0);
REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawCommandsCount);
@@ -603,11 +619,8 @@
// This test covers a code path that inserts bitmaps into the bitmap heap through the
// flattening of SkBitmapProcShaders. The refcount in the bitmap heap is maintained through
// the flattening and unflattening of the shader.
- SkBitmap store;
- store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
- store.allocPixels();
- SkBitmapDevice device(store);
- SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+ SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
// test will fail if nbIterations is not in sync with
// BITMAPS_TO_KEEP in SkGPipeWrite.cpp
const int nbIterations = 5;
@@ -641,9 +654,7 @@
}
static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter) {
- SkBitmap store;
- store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
- store.allocPixels();
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
SkBitmap sourceImage;
// 100 by 100 image, takes 40,000 bytes in memory
@@ -652,8 +663,7 @@
// 1 under : should not store the image
{
- SkBitmapDevice device(store);
- SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
+ SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
canvas->setBitmapSizeThreshold(39999);
canvas->drawBitmap(sourceImage, 0, 0, NULL);
size_t newBytesAllocated = canvas->storageAllocatedForRecording();
@@ -662,8 +672,7 @@
// exact value : should store the image
{
- SkBitmapDevice device(store);
- SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
+ SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
canvas->setBitmapSizeThreshold(40000);
canvas->drawBitmap(sourceImage, 0, 0, NULL);
size_t newBytesAllocated = canvas->storageAllocatedForRecording();
@@ -672,8 +681,7 @@
// 1 over : should still store the image
{
- SkBitmapDevice device(store);
- SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
+ SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
canvas->setBitmapSizeThreshold(40001);
canvas->drawBitmap(sourceImage, 0, 0, NULL);
size_t newBytesAllocated = canvas->storageAllocatedForRecording();
@@ -811,15 +819,14 @@
}
static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporter) {
- SkBitmap store;
- store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
- store.allocPixels();
- SkBitmapDevice device(store);
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+ SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
+
NotificationCounter notificationCounter;
- SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
canvas->setNotificationClient(¬ificationCounter);
+
SkAutoTUnref<SkBaseDevice> secondaryDevice(canvas->createCompatibleDevice(
- SkBitmap::kARGB_8888_Config, 10, 10, device.isOpaque()));
+ SkBitmap::kARGB_8888_Config, 10, 10, false));
SkCanvas secondaryCanvas(secondaryDevice.get());
SkRect rect = SkRect::MakeWH(5, 5);
SkPaint paint;