Removing the SkPicture backend from SkDeferredCanvas code

Review URL: https://codereview.appspot.com/6446095

git-svn-id: http://skia.googlecode.com/svn/trunk@4974 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
junov@chromium.org 2012-08-07 14:53:59 +00:00
parent 24e8999b4b
commit 3de7acc180
4 changed files with 0 additions and 61 deletions

View File

@ -8,20 +8,12 @@
#ifndef SkDeferredCanvas_DEFINED #ifndef SkDeferredCanvas_DEFINED
#define SkDeferredCanvas_DEFINED #define SkDeferredCanvas_DEFINED
#ifndef SK_DEFERRED_CANVAS_USES_GPIPE
#define SK_DEFERRED_CANVAS_USES_GPIPE 1
#endif
#include "SkCanvas.h" #include "SkCanvas.h"
#include "SkDevice.h" #include "SkDevice.h"
#include "SkPixelRef.h" #include "SkPixelRef.h"
#if SK_DEFERRED_CANVAS_USES_GPIPE
#include "SkGPipe.h" #include "SkGPipe.h"
#include "SkChunkAlloc.h" #include "SkChunkAlloc.h"
#else
#include "SkPicture.h"
#endif
/** \class SkDeferredCanvas /** \class SkDeferredCanvas
Subclass of SkCanvas that encapsulates an SkPicture or SkGPipe for deferred Subclass of SkCanvas that encapsulates an SkPicture or SkGPipe for deferred
@ -184,7 +176,6 @@ public:
typedef SkRefCnt INHERITED; typedef SkRefCnt INHERITED;
}; };
#if SK_DEFERRED_CANVAS_USES_GPIPE
protected: protected:
class DeferredPipeController : public SkGPipeController { class DeferredPipeController : public SkGPipeController {
public: public:
@ -212,7 +203,6 @@ protected:
SkTDArray<PipeBlock> fBlockList; SkTDArray<PipeBlock> fBlockList;
SkGPipeReader fReader; SkGPipeReader fReader;
}; };
#endif
public: public:
class DeferredDevice : public SkDevice { class DeferredDevice : public SkDevice {
@ -347,12 +337,8 @@ public:
void endRecording(); void endRecording();
void beginRecording(); void beginRecording();
#if SK_DEFERRED_CANVAS_USES_GPIPE
DeferredPipeController fPipeController; DeferredPipeController fPipeController;
SkGPipeWriter fPipeWriter; SkGPipeWriter fPipeWriter;
#else
SkPicture fPicture;
#endif
SkDevice* fImmediateDevice; SkDevice* fImmediateDevice;
SkCanvas* fImmediateCanvas; SkCanvas* fImmediateCanvas;
SkCanvas* fRecordingCanvas; SkCanvas* fRecordingCanvas;

View File

@ -169,11 +169,7 @@ size_t SkDeferredCanvas::storageAllocatedForRecording() const {
} }
size_t SkDeferredCanvas::freeMemoryIfPossible(size_t bytesToFree) { size_t SkDeferredCanvas::freeMemoryIfPossible(size_t bytesToFree) {
#if SK_DEFERRED_CANVAS_USES_GPIPE
return this->getDeferredDevice()->freeMemoryIfPossible(bytesToFree); return this->getDeferredDevice()->freeMemoryIfPossible(bytesToFree);
#else
return 0;
#endif
} }
void SkDeferredCanvas::validate() const { void SkDeferredCanvas::validate() const {
@ -518,8 +514,6 @@ SkCanvas* SkDeferredCanvas::canvasForDrawIter() {
return drawingCanvas(); return drawingCanvas();
} }
#if SK_DEFERRED_CANVAS_USES_GPIPE
// SkDeferredCanvas::DeferredPipeController // SkDeferredCanvas::DeferredPipeController
//------------------------------------------- //-------------------------------------------
@ -576,8 +570,6 @@ void SkDeferredCanvas::DeferredPipeController::reset() {
fAllocator.reset(); fAllocator.reset();
} }
#endif // SK_DEFERRED_CANVAS_USES_GPIPE
// SkDeferredCanvas::DeferredDevice // SkDeferredCanvas::DeferredDevice
//------------------------------------ //------------------------------------
@ -592,9 +584,7 @@ SkDeferredCanvas::DeferredDevice::DeferredDevice(
SkSafeRef(fDeviceContext); SkSafeRef(fDeviceContext);
fImmediateDevice = immediateDevice; // ref counted via fImmediateCanvas fImmediateDevice = immediateDevice; // ref counted via fImmediateCanvas
fImmediateCanvas = SkNEW_ARGS(SkCanvas, (fImmediateDevice)); fImmediateCanvas = SkNEW_ARGS(SkCanvas, (fImmediateDevice));
#if SK_DEFERRED_CANVAS_USES_GPIPE
fPipeController.setPlaybackCanvas(fImmediateCanvas); fPipeController.setPlaybackCanvas(fImmediateCanvas);
#endif
beginRecording(); beginRecording();
} }
@ -610,22 +600,13 @@ void SkDeferredCanvas::DeferredDevice::setMaxRecordingStorage(size_t maxStorage)
} }
void SkDeferredCanvas::DeferredDevice::endRecording() { void SkDeferredCanvas::DeferredDevice::endRecording() {
#if SK_DEFERRED_CANVAS_USES_GPIPE
fPipeWriter.endRecording(); fPipeWriter.endRecording();
fPipeController.reset(); fPipeController.reset();
#else
fPicture.endRecording();
#endif
fRecordingCanvas = NULL; fRecordingCanvas = NULL;
} }
void SkDeferredCanvas::DeferredDevice::beginRecording() { void SkDeferredCanvas::DeferredDevice::beginRecording() {
#if SK_DEFERRED_CANVAS_USES_GPIPE
fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0); fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0);
#else
fRecordingCanvas = fPicture.beginRecording(fImmediateDevice->width(),
fImmediateDevice->height());
#endif
} }
void SkDeferredCanvas::DeferredDevice::setDeviceContext( void SkDeferredCanvas::DeferredDevice::setDeviceContext(
@ -675,26 +656,15 @@ bool SkDeferredCanvas::DeferredDevice::isFreshFrame() {
} }
void SkDeferredCanvas::DeferredDevice::flushPending() { void SkDeferredCanvas::DeferredDevice::flushPending() {
#if SK_DEFERRED_CANVAS_USES_GPIPE
if (!fPipeController.hasRecorded()) { if (!fPipeController.hasRecorded()) {
return; return;
} }
#else
if (!fPicture.hasRecorded()) {
return;
}
#endif
if (fDeviceContext) { if (fDeviceContext) {
fDeviceContext->prepareForDraw(); fDeviceContext->prepareForDraw();
} }
#if SK_DEFERRED_CANVAS_USES_GPIPE
fPipeWriter.flushRecording(true); fPipeWriter.flushRecording(true);
fPipeController.playback(); fPipeController.playback();
#else
fPicture.draw(fImmediateCanvas);
this->beginRecording();
#endif
} }
void SkDeferredCanvas::DeferredDevice::flush() { void SkDeferredCanvas::DeferredDevice::flush() {
@ -702,23 +672,16 @@ void SkDeferredCanvas::DeferredDevice::flush() {
fImmediateCanvas->flush(); fImmediateCanvas->flush();
} }
#if SK_DEFERRED_CANVAS_USES_GPIPE
size_t SkDeferredCanvas::DeferredDevice::freeMemoryIfPossible(size_t bytesToFree) { size_t SkDeferredCanvas::DeferredDevice::freeMemoryIfPossible(size_t bytesToFree) {
return fPipeWriter.freeMemoryIfPossible(bytesToFree); return fPipeWriter.freeMemoryIfPossible(bytesToFree);
} }
#endif
size_t SkDeferredCanvas::DeferredDevice::storageAllocatedForRecording() const { size_t SkDeferredCanvas::DeferredDevice::storageAllocatedForRecording() const {
#if SK_DEFERRED_CANVAS_USES_GPIPE
return (fPipeController.storageAllocatedForRecording() return (fPipeController.storageAllocatedForRecording()
+ fPipeWriter.storageAllocatedForRecording()); + fPipeWriter.storageAllocatedForRecording());
#else
return 0;
#endif
} }
SkCanvas* SkDeferredCanvas::DeferredDevice::recordingCanvas() { SkCanvas* SkDeferredCanvas::DeferredDevice::recordingCanvas() {
#if SK_DEFERRED_CANVAS_USES_GPIPE
size_t storageAllocated = this->storageAllocatedForRecording(); size_t storageAllocated = this->storageAllocatedForRecording();
if (storageAllocated > fMaxRecordingStorageBytes) { if (storageAllocated > fMaxRecordingStorageBytes) {
// First, attempt to reduce cache without flushing // First, attempt to reduce cache without flushing
@ -731,7 +694,6 @@ SkCanvas* SkDeferredCanvas::DeferredDevice::recordingCanvas() {
this->freeMemoryIfPossible(~0); this->freeMemoryIfPossible(~0);
} }
} }
#endif
return fRecordingCanvas; return fRecordingCanvas;
} }

View File

@ -756,14 +756,12 @@ static void TestDeferredCanvasStateConsistency(
AssertCanvasStatesEqual(reporter, &deferredCanvas, &referenceCanvas, AssertCanvasStatesEqual(reporter, &deferredCanvas, &referenceCanvas,
testStep); testStep);
#if SK_DEFERRED_CANVAS_USES_GPIPE
deferredCanvas.flush(); deferredCanvas.flush();
testStep->setAssertMessageFormat( testStep->setAssertMessageFormat(
kDeferredPostFlushPlaybackAssertMessageFormat); kDeferredPostFlushPlaybackAssertMessageFormat);
AssertCanvasStatesEqual(reporter, AssertCanvasStatesEqual(reporter,
deferredCanvas.getDeferredDevice()->immediateCanvas(), deferredCanvas.getDeferredDevice()->immediateCanvas(),
&referenceCanvas, testStep); &referenceCanvas, testStep);
#endif
// Verified that deferred canvas state is not affected by flushing // Verified that deferred canvas state is not affected by flushing
// pending draw operations // pending draw operations

View File

@ -210,13 +210,9 @@ static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) {
canvas.drawBitmap(sourceImage, 0, 0, NULL); canvas.drawBitmap(sourceImage, 0, 0, NULL);
} }
// SkPicture path is not fixed
#if SK_DEFERRED_CANVAS_USES_GPIPE
REPORTER_ASSERT(reporter, mockDevice.fDrawBitmapCallCount == 4); REPORTER_ASSERT(reporter, mockDevice.fDrawBitmapCallCount == 4);
#endif
} }
#if SK_DEFERRED_CANVAS_USES_GPIPE
static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) { static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) {
SkBitmap store; SkBitmap store;
store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
@ -282,16 +278,13 @@ static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) {
canvas.drawBitmap(sourceImages[1], 0, 0, NULL); canvas.drawBitmap(sourceImages[1], 0, 0, NULL);
REPORTER_ASSERT(reporter, canvas.storageAllocatedForRecording() > 2*bitmapSize); REPORTER_ASSERT(reporter, canvas.storageAllocatedForRecording() > 2*bitmapSize);
} }
#endif
static void TestDeferredCanvas(skiatest::Reporter* reporter) { static void TestDeferredCanvas(skiatest::Reporter* reporter) {
TestDeferredCanvasBitmapAccess(reporter); TestDeferredCanvasBitmapAccess(reporter);
TestDeferredCanvasFlush(reporter); TestDeferredCanvasFlush(reporter);
TestDeferredCanvasFreshFrame(reporter); TestDeferredCanvasFreshFrame(reporter);
TestDeferredCanvasMemoryLimit(reporter); TestDeferredCanvasMemoryLimit(reporter);
#if SK_DEFERRED_CANVAS_USES_GPIPE
TestDeferredCanvasBitmapCaching(reporter); TestDeferredCanvasBitmapCaching(reporter);
#endif
} }
#include "TestClassDef.h" #include "TestClassDef.h"