diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkCanvas.cpp | 26 | ||||
-rw-r--r-- | src/core/SkDevice.cpp | 36 | ||||
-rw-r--r-- | src/gpu/SkGpuCanvas.cpp | 11 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 5 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 4 |
5 files changed, 65 insertions, 17 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 07c2748a7a..dbd4852006 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -417,21 +417,27 @@ SkDevice* SkCanvas::init(SkDevice* device) { } SkCanvas::SkCanvas(SkDeviceFactory* factory) - : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)), - fDeviceFactory(factory) { + : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) { inc_canvas(); - if (!factory) - fDeviceFactory = SkNEW(SkRasterDeviceFactory); + if (factory) { + factory->ref(); + } else { + factory = SkNEW(SkRasterDeviceFactory); + } + fDeviceFactory = factory; this->init(NULL); } SkCanvas::SkCanvas(SkDevice* device) - : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)), - fDeviceFactory(device->getDeviceFactory()) { + : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) { inc_canvas(); + fDeviceFactory = device->getDeviceFactory(); + SkASSERT(fDeviceFactory); + fDeviceFactory->ref(); + this->init(device); } @@ -441,6 +447,9 @@ SkCanvas::SkCanvas(const SkBitmap& bitmap) SkDevice* device = SkNEW_ARGS(SkDevice, (this, bitmap, false)); fDeviceFactory = device->getDeviceFactory(); + SkASSERT(fDeviceFactory); + fDeviceFactory->ref(); + this->init(device)->unref(); } @@ -450,7 +459,7 @@ SkCanvas::~SkCanvas() { this->internalRestore(); // restore the last, since we're going away SkSafeUnref(fBounder); - SkDELETE(fDeviceFactory); + SkSafeUnref(fDeviceFactory); dec_canvas(); } @@ -560,8 +569,7 @@ bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { } SkDeviceFactory* SkCanvas::setDeviceFactory(SkDeviceFactory* factory) { - SkDELETE(fDeviceFactory); - fDeviceFactory = factory; + SkRefCnt_SafeAssign(fDeviceFactory, factory); return factory; } diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 6305e190fe..850a53fd16 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -3,10 +3,31 @@ #include "SkMetaData.h" #include "SkRect.h" -SkDeviceFactory::~SkDeviceFactory() {} +//#define TRACE_FACTORY_LIFETIME + +#ifdef TRACE_FACTORY_LIFETIME + static int gFactoryCounter; +#endif + +SkDeviceFactory::SkDeviceFactory() { +#ifdef TRACE_FACTORY_LIFETIME + SkDebugf("+++ factory index %d\n", gFactoryCounter); + ++gFactoryCounter; +#endif +} + +SkDeviceFactory::~SkDeviceFactory() { +#ifdef TRACE_FACTORY_LIFETIME + --gFactoryCounter; + SkDebugf("--- factory index %d\n", gFactoryCounter); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// SkDevice::SkDevice(SkCanvas* canvas) : fCanvas(canvas), fMetaData(NULL) { fOrigin.setZero(); + fCachedDeviceFactory = NULL; } SkDevice::SkDevice(SkCanvas* canvas, const SkBitmap& bitmap, bool isForLayer) @@ -21,10 +42,23 @@ SkDevice::SkDevice(SkCanvas* canvas, const SkBitmap& bitmap, bool isForLayer) } } } + fCachedDeviceFactory = NULL; } SkDevice::~SkDevice() { delete fMetaData; + SkSafeUnref(fCachedDeviceFactory); +} + +SkDeviceFactory* SkDevice::onNewDeviceFactory() { + return SkNEW(SkRasterDeviceFactory); +} + +SkDeviceFactory* SkDevice::getDeviceFactory() { + if (NULL == fCachedDeviceFactory) { + fCachedDeviceFactory = this->onNewDeviceFactory(); + } + return fCachedDeviceFactory; } SkMetaData& SkDevice::getMetaData() { diff --git a/src/gpu/SkGpuCanvas.cpp b/src/gpu/SkGpuCanvas.cpp index 9513bbd91f..08cbb32a05 100644 --- a/src/gpu/SkGpuCanvas.cpp +++ b/src/gpu/SkGpuCanvas.cpp @@ -23,14 +23,11 @@ /////////////////////////////////////////////////////////////////////////////// -static SkDeviceFactory* make_df(GrContext* context, - GrRenderTarget* renderTarget) { - return SkNEW_ARGS(SkGpuDeviceFactory, (context, renderTarget)); -} +SkGpuCanvas::SkGpuCanvas(GrContext* context, GrRenderTarget* renderTarget) { + SkDeviceFactory* factory = SkNEW_ARGS(SkGpuDeviceFactory, + (context, renderTarget)); + this->setDeviceFactory(factory)->unref(); -SkGpuCanvas::SkGpuCanvas(GrContext* context, - GrRenderTarget* renderTarget) - : SkCanvas(make_df(context, renderTarget)) { SkASSERT(context); fContext = context; fContext->ref(); diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 036d9b5ae9..1c70513245 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -210,6 +210,11 @@ intptr_t SkGpuDevice::getLayerTextureHandle() const { return 0; } } + +SkDeviceFactory* SkGpuDevice::onNewDeviceFactory() { + return SkNEW_ARGS(SkGpuDeviceFactory, (fContext, fRenderTarget)); +} + /////////////////////////////////////////////////////////////////////////////// void SkGpuDevice::makeRenderTargetCurrent() { diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index efe7257704..13ffd5b0d4 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -168,6 +168,10 @@ void SkPDFDevice::init() { } } +SkDeviceFactory* SkPDFDevice::onNewDeviceFactory() { + return SkNEW(SkPDFDeviceFactory); +} + void SkPDFDevice::cleanUp() { fGraphicStateResources.unrefAll(); fXObjectResources.unrefAll(); |