diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkCanvas.cpp | 46 | ||||
-rw-r--r-- | src/core/SkDevice.cpp | 57 | ||||
-rw-r--r-- | src/gpu/SkGpuCanvas.cpp | 7 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 57 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 18 |
5 files changed, 13 insertions, 172 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index d5a2d1559c..3c17351afd 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -419,17 +419,10 @@ SkDevice* SkCanvas::init(SkDevice* device) { return this->setDevice(device); } -SkCanvas::SkCanvas(SkDeviceFactory* factory) - : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) { +SkCanvas::SkCanvas() +: fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) { inc_canvas(); - - if (factory) { - factory->ref(); - } else { - factory = SkNEW(SkRasterDeviceFactory); - } - fDeviceFactory = factory; - + this->init(NULL); } @@ -437,9 +430,6 @@ SkCanvas::SkCanvas(SkDevice* device) : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) { inc_canvas(); - fDeviceFactory = device->getDeviceFactory(); - SkSafeRef(fDeviceFactory); - this->init(device); } @@ -447,11 +437,7 @@ SkCanvas::SkCanvas(const SkBitmap& bitmap) : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) { inc_canvas(); - SkDevice* device = SkNEW_ARGS(SkDevice, (bitmap)); - fDeviceFactory = device->getDeviceFactory(); - SkSafeRef(fDeviceFactory); - - this->init(device)->unref(); + this->init(SkNEW_ARGS(SkDevice, (bitmap)))->unref(); } SkCanvas::~SkCanvas() { @@ -460,7 +446,6 @@ SkCanvas::~SkCanvas() { this->internalRestore(); // restore the last, since we're going away SkSafeUnref(fBounder); - SkSafeUnref(fDeviceFactory); dec_canvas(); } @@ -508,10 +493,6 @@ SkDevice* SkCanvas::setDevice(SkDevice* device) { things like lock/unlock their pixels, etc. */ if (device) { - // To mirror our (SkDevice*) constructor, we grab the factory from the - // new device - this->setDeviceFactory(device->getDeviceFactory()); - device->lockPixels(); } if (rootDevice) { @@ -573,11 +554,6 @@ bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { return device->readPixels(srcRect, bitmap); } -SkDeviceFactory* SkCanvas::setDeviceFactory(SkDeviceFactory* factory) { - SkRefCnt_SafeAssign(fDeviceFactory, factory); - return factory; -} - ////////////////////////////////////////////////////////////////////////////// bool SkCanvas::readPixels(SkBitmap* bitmap) { @@ -1185,13 +1161,12 @@ void SkCanvas::setExternalMatrix(const SkMatrix* matrix) { SkDevice* SkCanvas::createLayerDevice(SkBitmap::Config config, int width, int height, bool isOpaque) { - if (fDeviceFactory) { - return fDeviceFactory->newDevice(this, config, width, height, - isOpaque, true); + SkDevice* device = this->getDevice(); + if (device) { + return device->createCompatibleDeviceForSaveLayer(config, width, height, + isOpaque); } else { - return this->getDevice()->createCompatibleDeviceForSaveLayer( - config, width, height, - isOpaque); + return NULL; } } @@ -1200,8 +1175,7 @@ SkDevice* SkCanvas::createCompatibleDevice(SkBitmap::Config config, bool isOpaque) { SkDevice* device = this->getDevice(); if (device) { - return device->createCompatibleDevice(config, width, height, - isOpaque); + return device->createCompatibleDevice(config, width, height, isOpaque); } else { return NULL; } diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index ae283b04ef..78b2dcc2ef 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -3,45 +3,16 @@ #include "SkMetaData.h" #include "SkRect.h" -//#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 -} - /////////////////////////////////////////////////////////////////////////////// -#if 0 -SkDevice::SkDevice() : fMetaData(NULL) { - fOrigin.setZero(); - fCachedDeviceFactory = NULL; -} -#endif - SkDevice::SkDevice(const SkBitmap& bitmap) : fBitmap(bitmap) { fOrigin.setZero(); fMetaData = NULL; - fCachedDeviceFactory = NULL; } SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque) { fOrigin.setZero(); fMetaData = NULL; - fCachedDeviceFactory = NULL; fBitmap.setConfig(config, width, height); fBitmap.allocPixels(); @@ -53,18 +24,6 @@ SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque SkDevice::~SkDevice() { delete fMetaData; - SkSafeUnref(fCachedDeviceFactory); -} - -SkDeviceFactory* SkDevice::onNewDeviceFactory() { - return NULL; -} - -SkDeviceFactory* SkDevice::getDeviceFactory() { - if (NULL == fCachedDeviceFactory) { - fCachedDeviceFactory = this->onNewDeviceFactory(); - } - return fCachedDeviceFactory; } SkDevice* SkDevice::createCompatibleDevice(SkBitmap::Config config, @@ -278,19 +237,3 @@ bool SkDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { return false; } -/////////////////////////////////////////////////////////////////////////////// - -SkDevice* SkRasterDeviceFactory::newDevice(SkCanvas*, - SkBitmap::Config config, int width, - int height, bool isOpaque, - bool isForLayer) { - if (isForLayer) { - return SkNEW_ARGS(SkDevice, (config, width, height, isOpaque)); - } else { - // should we ever get here? - SkBitmap bitmap; - bitmap.setConfig(config, width, height); - bitmap.setIsOpaque(isOpaque); - return SkNEW_ARGS(SkDevice, (bitmap)); - } -} diff --git a/src/gpu/SkGpuCanvas.cpp b/src/gpu/SkGpuCanvas.cpp index 08cbb32a05..a3bbea82a3 100644 --- a/src/gpu/SkGpuCanvas.cpp +++ b/src/gpu/SkGpuCanvas.cpp @@ -19,18 +19,15 @@ #include "SkGpuCanvas.h" #include "SkGpuDevice.h" -#include "SkGpuDeviceFactory.h" /////////////////////////////////////////////////////////////////////////////// SkGpuCanvas::SkGpuCanvas(GrContext* context, GrRenderTarget* renderTarget) { - SkDeviceFactory* factory = SkNEW_ARGS(SkGpuDeviceFactory, - (context, renderTarget)); - this->setDeviceFactory(factory)->unref(); - SkASSERT(context); fContext = context; fContext->ref(); + + this->setDevice(new SkGpuDevice(context, renderTarget))->unref(); } SkGpuCanvas::~SkGpuCanvas() { diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index a49e079e9e..0f1872666a 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -19,7 +19,6 @@ #include "GrTextContext.h" #include "SkGpuDevice.h" -#include "SkGpuDeviceFactory.h" #include "SkGrTexturePixelRef.h" #include "SkColorFilter.h" @@ -47,6 +46,7 @@ enum { kShaderTextureIdx = 0 }; + /////////////////////////////////////////////////////////////////////////////// SkGpuDevice::SkAutoCachedTexture:: @@ -1494,58 +1494,3 @@ SkDevice* SkGpuDevice::onCreateCompatibleDevice(SkBitmap::Config config, width, height, usage)); } - -/////////////////////////////////////////////////////////////////////////////// - -SkGpuDeviceFactory::SkGpuDeviceFactory(GrContext* context, - GrRenderTarget* rootRenderTarget) { - GrAssert(NULL != context); - GrAssert(NULL != rootRenderTarget); - - // check this now rather than passing this value to SkGpuDevice cons. - // we want the rt that is bound *now* in the 3D API, not the one - // at the time of newDevice. - if (SkGpuDevice::Current3DApiRenderTarget() == rootRenderTarget) { - fRootRenderTarget = context->createRenderTargetFrom3DApiState(); - } else { - fRootRenderTarget = rootRenderTarget; - rootRenderTarget->ref(); - } - - fContext = context; - context->ref(); - - fRootTexture = NULL; -} - -SkGpuDeviceFactory::SkGpuDeviceFactory(GrContext* context, GrTexture* rootRenderTargetTexture) { - GrAssert(NULL != context); - GrAssert(NULL != rootRenderTargetTexture); - GrAssert(NULL != rootRenderTargetTexture->asRenderTarget()); - - fRootTexture = rootRenderTargetTexture; - rootRenderTargetTexture->ref(); - - fRootRenderTarget = rootRenderTargetTexture->asRenderTarget(); - fRootRenderTarget->ref(); - - fContext = context; - context->ref(); -} - -SkGpuDeviceFactory::~SkGpuDeviceFactory() { - fContext->unref(); - fRootRenderTarget->unref(); - GrSafeUnref(fRootTexture); -} - -SkDevice* SkGpuDeviceFactory::newDevice(SkCanvas*, SkBitmap::Config config, - int width, int height, - bool isOpaque, bool isLayer) { - if (isLayer) { - return SkNEW_ARGS(SkGpuDevice, (fContext, config, width, height)); - } else { - return SkNEW_ARGS(SkGpuDevice, (fContext, fRootRenderTarget)); - } -} - diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 0da237d3d2..3eb2ee8277 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -487,20 +487,6 @@ private: //////////////////////////////////////////////////////////////////////////////// -SkDevice* SkPDFDeviceFactory::newDevice(SkCanvas* c, SkBitmap::Config config, - int width, int height, bool isOpaque, - bool isForLayer) { - SkMatrix initialTransform; - initialTransform.reset(); - SkISize size = SkISize::Make(width, height); - if (isForLayer) { - return SkNEW_ARGS(SkPDFDevice, (size, c->getTotalClipStack(), - c->getTotalClip())); - } else { - return SkNEW_ARGS(SkPDFDevice, (size, size, initialTransform)); - } -} - static inline SkBitmap makeContentBitmap(const SkISize& contentSize, const SkMatrix* initialTransform) { SkBitmap bitmap; @@ -565,10 +551,6 @@ void SkPDFDevice::init() { fLastContentEntry = NULL; } -SkDeviceFactory* SkPDFDevice::onNewDeviceFactory() { - return SkNEW(SkPDFDeviceFactory); -} - void SkPDFDevice::cleanUp() { fGraphicStateResources.unrefAll(); fXObjectResources.unrefAll(); |