remove SkDeviceFactory from the collective consciousness, now that devices know

how to create compatible siblings.



git-svn-id: http://skia.googlecode.com/svn/trunk@1808 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-07-06 20:00:52 +00:00
Родитель 1e257a5db3
Коммит cde92111d5
10 изменённых файлов: 19 добавлений и 314 удалений

Просмотреть файл

@ -52,15 +52,7 @@ class SkPicture;
*/ */
class SK_API SkCanvas : public SkRefCnt { class SK_API SkCanvas : public SkRefCnt {
public: public:
/** SkCanvas();
DEPRECATED: Will be replaced by SkDevice::createCompatibleDevice
Construct a canvas with the given device factory.
@param factory Specify the factory for generating additional devices.
The factory may be null, in which case
SkRasterDeviceFactory will be used.
*/
explicit SkCanvas(SkDeviceFactory* factory = NULL);
/** Construct a canvas with the specified device to draw into. The device /** Construct a canvas with the specified device to draw into. The device
factory will be retrieved from the passed device. factory will be retrieved from the passed device.
@ -106,24 +98,8 @@ public:
SkDevice* setBitmapDevice(const SkBitmap& bitmap); SkDevice* setBitmapDevice(const SkBitmap& bitmap);
/** /**
* DEPRECATED: Will be replaced by SkDevice::createCompatibleDevice * Shortcut for getDevice()->createCompatibleDevice(...).
* * If getDevice() == NULL, this method does nothing, and returns NULL.
* Return the current device factory, or NULL. The reference count of
* the returned factory is not changed.
*/
SkDeviceFactory* getDeviceFactory() const { return fDeviceFactory; }
/**
* DEPRECATED: Will be replaced by SkDevice::createCompatibleDevice
*
* Replace any existing factory with the specified factory, unrefing the
* previous (if any), and refing the new one (if any). For convenience,
* the factory parameter is also returned.
*/
SkDeviceFactory* setDeviceFactory(SkDeviceFactory*);
/**
* Shortcut for getDevice()->createCompatibleDevice(...)
*/ */
SkDevice* createCompatibleDevice(SkBitmap::Config config, SkDevice* createCompatibleDevice(SkBitmap::Config config,
int width, int height, int width, int height,

Просмотреть файл

@ -30,28 +30,6 @@ class SkMatrix;
class SkMetaData; class SkMetaData;
class SkRegion; class SkRegion;
/** \class SkDeviceFactory
DEPRECATED: Will be replaced by SkDevice::createCompatibleDevice
Devices that extend SkDevice should also provide a SkDeviceFactory class
to pass into SkCanvas. Doing so will eliminate the need to extend
SkCanvas as well.
*/
class SK_API SkDeviceFactory : public SkRefCnt {
public:
SkDeviceFactory();
virtual ~SkDeviceFactory();
virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width,
int height, bool isOpaque, bool isLayer) = 0;
};
class SkRasterDeviceFactory : public SkDeviceFactory {
public:
virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width,
int height, bool isOpaque, bool isLayer);
};
class SK_API SkDevice : public SkRefCnt { class SK_API SkDevice : public SkRefCnt {
public: public:
// SkDevice(); // SkDevice();
@ -80,15 +58,6 @@ public:
virtual ~SkDevice(); virtual ~SkDevice();
/**
* DEPRECATED: Will be replaced by SkDevice::createCompatibleDevice
*
* Return the factory that will create this subclass of SkDevice.
* The returned factory is cached by the device, and so its reference count
* is not changed by this call.
*/
SkDeviceFactory* getDeviceFactory();
/** /**
* Creates a device that is of the same type as this device (e.g. SW-raster, * Creates a device that is of the same type as this device (e.g. SW-raster,
* GPU, or PDF). The backing store for this device is created automatically * GPU, or PDF). The backing store for this device is created automatically
@ -282,17 +251,6 @@ public:
virtual bool filterTextFlags(const SkPaint& paint, TextFlags*); virtual bool filterTextFlags(const SkPaint& paint, TextFlags*);
protected: protected:
/**
* DEPRECATED: Will be replaced by SkDevice::createCompatibleDevice
*
* subclasses can override this to return a new (or ref'd) instance of
* a device factory that will create this subclass of device. This value
* is cached, so it should get called at most once for a given instance.
*
* If not overriden then createCompatibleDevice will be used by canvas.
*/
virtual SkDeviceFactory* onNewDeviceFactory();
/** Update as needed the pixel value in the bitmap, so that the caller can access /** Update as needed the pixel value in the bitmap, so that the caller can access
the pixels directly. Note: only the pixels field should be altered. The config/width/height/rowbytes the pixels directly. Note: only the pixels field should be altered. The config/width/height/rowbytes
must remain unchanged. must remain unchanged.
@ -330,8 +288,6 @@ private:
SkBitmap fBitmap; SkBitmap fBitmap;
SkIPoint fOrigin; SkIPoint fOrigin;
SkMetaData* fMetaData; SkMetaData* fMetaData;
SkDeviceFactory* fCachedDeviceFactory;
}; };
#endif #endif

Просмотреть файл

@ -168,10 +168,12 @@ public:
kDevKernText_Flag = 0x02, kDevKernText_Flag = 0x02,
kGammaForBlack_Flag = 0x04, // illegal to set both Gamma flags kGammaForBlack_Flag = 0x04, // illegal to set both Gamma flags
kGammaForWhite_Flag = 0x08, // illegal to set both Gamma flags kGammaForWhite_Flag = 0x08, // illegal to set both Gamma flags
// together, these two flags resulting in a two bit value which matches // together, these two flags resulting in a two bit value which matches
// up with the SkPaint::Hinting enum. // up with the SkPaint::Hinting enum.
kHintingBit1_Flag = 0x10, kHintingBit1_Flag = 0x10,
kHintingBit2_Flag = 0x20, kHintingBit2_Flag = 0x20,
kEmbeddedBitmapText_Flag = 0x40, kEmbeddedBitmapText_Flag = 0x40,
kEmbolden_Flag = 0x80, kEmbolden_Flag = 0x80,
kSubpixelPositioning_Flag = 0x100, kSubpixelPositioning_Flag = 0x100,

Просмотреть файл

@ -1,58 +0,0 @@
/*
Copyright 2010 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef SkGpuDeviceFactory_DEFINED
#define SkGpuDeviceFactory_DEFINED
#include "SkDevice.h"
class GrContext;
class SK_API SkGpuDeviceFactory : public SkDeviceFactory {
public:
/**
* The constructor will ref() the context, passing it to each device
* that it creates. It will be unref()'d in the destructor
* Non-layered devices created by the factory will draw to the
* rootRenderTarget. rootRenderTarget is ref-counted by the factory.
* SkGpuDevice::Current3DApiRenderTarget() can be passed as a special
* value that will cause the factory to create a render target object
* that reflects the state of the underlying 3D API at the time of
* construction.
*/
SkGpuDeviceFactory(GrContext*, GrRenderTarget* rootRenderTarget);
/**
* When the root layer is both a GrRenderTarget and a GrTexture it
* is handy to have the factory hang on to a ref to the GrTexture object.
* This is because the GrTexture has a ref to the GrRenderTarget but not
* vice-versa.
*/
SkGpuDeviceFactory(GrContext*, GrTexture* rootRenderTargetTexture);
virtual ~SkGpuDeviceFactory();
virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width,
int height, bool isOpaque, bool isLayer);
private:
GrContext* fContext;
GrRenderTarget* fRootRenderTarget;
GrTexture* fRootTexture;
};
#endif

Просмотреть файл

@ -39,12 +39,6 @@ class SkPDFStream;
struct ContentEntry; struct ContentEntry;
struct GraphicStateEntry; struct GraphicStateEntry;
class SkPDFDeviceFactory : public SkDeviceFactory {
public:
virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width,
int height, bool isOpaque, bool isForLayer);
};
/** \class SkPDFDevice /** \class SkPDFDevice
The drawing context for the PDF backend. The drawing context for the PDF backend.
@ -65,7 +59,7 @@ public:
* a scale+translate transform to move the origin from the * a scale+translate transform to move the origin from the
* bottom left (PDF default) to the top left. Note2: drawDevice * bottom left (PDF default) to the top left. Note2: drawDevice
* (used by layer restore) draws the device after this initial * (used by layer restore) draws the device after this initial
* transform is applied, so the PDF device factory does an * transform is applied, so the PDF device does an
* inverse scale+translate to accommodate the one that SkPDFDevice * inverse scale+translate to accommodate the one that SkPDFDevice
* always does. * always does.
*/ */
@ -150,12 +144,7 @@ public:
return fInitialTransform; return fInitialTransform;
} }
protected:
// override
virtual SkDeviceFactory* onNewDeviceFactory();
private: private:
friend class SkPDFDeviceFactory;
// TODO(vandebo) push most of SkPDFDevice's state into a core object in // TODO(vandebo) push most of SkPDFDevice's state into a core object in
// order to get the right access levels without using friend. // order to get the right access levels without using friend.
friend class ScopedContentEntry; friend class ScopedContentEntry;
@ -175,7 +164,6 @@ private:
SkTScopedPtr<ContentEntry> fContentEntries; SkTScopedPtr<ContentEntry> fContentEntries;
ContentEntry* fLastContentEntry; ContentEntry* fLastContentEntry;
// For use by the DeviceFactory.
SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack, SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack,
const SkRegion& existingClipRegion); const SkRegion& existingClipRegion);

Просмотреть файл

@ -419,17 +419,10 @@ SkDevice* SkCanvas::init(SkDevice* device) {
return this->setDevice(device); return this->setDevice(device);
} }
SkCanvas::SkCanvas(SkDeviceFactory* factory) SkCanvas::SkCanvas()
: fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) { : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
inc_canvas(); inc_canvas();
if (factory) {
factory->ref();
} else {
factory = SkNEW(SkRasterDeviceFactory);
}
fDeviceFactory = factory;
this->init(NULL); this->init(NULL);
} }
@ -437,9 +430,6 @@ SkCanvas::SkCanvas(SkDevice* device)
: fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) { : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
inc_canvas(); inc_canvas();
fDeviceFactory = device->getDeviceFactory();
SkSafeRef(fDeviceFactory);
this->init(device); this->init(device);
} }
@ -447,11 +437,7 @@ SkCanvas::SkCanvas(const SkBitmap& bitmap)
: fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) { : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) {
inc_canvas(); inc_canvas();
SkDevice* device = SkNEW_ARGS(SkDevice, (bitmap)); this->init(SkNEW_ARGS(SkDevice, (bitmap)))->unref();
fDeviceFactory = device->getDeviceFactory();
SkSafeRef(fDeviceFactory);
this->init(device)->unref();
} }
SkCanvas::~SkCanvas() { SkCanvas::~SkCanvas() {
@ -460,7 +446,6 @@ SkCanvas::~SkCanvas() {
this->internalRestore(); // restore the last, since we're going away this->internalRestore(); // restore the last, since we're going away
SkSafeUnref(fBounder); SkSafeUnref(fBounder);
SkSafeUnref(fDeviceFactory);
dec_canvas(); dec_canvas();
} }
@ -508,10 +493,6 @@ SkDevice* SkCanvas::setDevice(SkDevice* device) {
things like lock/unlock their pixels, etc. things like lock/unlock their pixels, etc.
*/ */
if (device) { if (device) {
// To mirror our (SkDevice*) constructor, we grab the factory from the
// new device
this->setDeviceFactory(device->getDeviceFactory());
device->lockPixels(); device->lockPixels();
} }
if (rootDevice) { if (rootDevice) {
@ -573,11 +554,6 @@ bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
return device->readPixels(srcRect, bitmap); return device->readPixels(srcRect, bitmap);
} }
SkDeviceFactory* SkCanvas::setDeviceFactory(SkDeviceFactory* factory) {
SkRefCnt_SafeAssign(fDeviceFactory, factory);
return factory;
}
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
bool SkCanvas::readPixels(SkBitmap* bitmap) { bool SkCanvas::readPixels(SkBitmap* bitmap) {
@ -1185,13 +1161,12 @@ void SkCanvas::setExternalMatrix(const SkMatrix* matrix) {
SkDevice* SkCanvas::createLayerDevice(SkBitmap::Config config, SkDevice* SkCanvas::createLayerDevice(SkBitmap::Config config,
int width, int height, int width, int height,
bool isOpaque) { bool isOpaque) {
if (fDeviceFactory) { SkDevice* device = this->getDevice();
return fDeviceFactory->newDevice(this, config, width, height, if (device) {
isOpaque, true); return device->createCompatibleDeviceForSaveLayer(config, width, height,
isOpaque);
} else { } else {
return this->getDevice()->createCompatibleDeviceForSaveLayer( return NULL;
config, width, height,
isOpaque);
} }
} }
@ -1200,8 +1175,7 @@ SkDevice* SkCanvas::createCompatibleDevice(SkBitmap::Config config,
bool isOpaque) { bool isOpaque) {
SkDevice* device = this->getDevice(); SkDevice* device = this->getDevice();
if (device) { if (device) {
return device->createCompatibleDevice(config, width, height, return device->createCompatibleDevice(config, width, height, isOpaque);
isOpaque);
} else { } else {
return NULL; return NULL;
} }

Просмотреть файл

@ -3,45 +3,16 @@
#include "SkMetaData.h" #include "SkMetaData.h"
#include "SkRect.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) { SkDevice::SkDevice(const SkBitmap& bitmap) : fBitmap(bitmap) {
fOrigin.setZero(); fOrigin.setZero();
fMetaData = NULL; fMetaData = NULL;
fCachedDeviceFactory = NULL;
} }
SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque) { SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque) {
fOrigin.setZero(); fOrigin.setZero();
fMetaData = NULL; fMetaData = NULL;
fCachedDeviceFactory = NULL;
fBitmap.setConfig(config, width, height); fBitmap.setConfig(config, width, height);
fBitmap.allocPixels(); fBitmap.allocPixels();
@ -53,18 +24,6 @@ SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque
SkDevice::~SkDevice() { SkDevice::~SkDevice() {
delete fMetaData; 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, SkDevice* SkDevice::createCompatibleDevice(SkBitmap::Config config,
@ -278,19 +237,3 @@ bool SkDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) {
return false; 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));
}
}

Просмотреть файл

@ -19,18 +19,15 @@
#include "SkGpuCanvas.h" #include "SkGpuCanvas.h"
#include "SkGpuDevice.h" #include "SkGpuDevice.h"
#include "SkGpuDeviceFactory.h"
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
SkGpuCanvas::SkGpuCanvas(GrContext* context, GrRenderTarget* renderTarget) { SkGpuCanvas::SkGpuCanvas(GrContext* context, GrRenderTarget* renderTarget) {
SkDeviceFactory* factory = SkNEW_ARGS(SkGpuDeviceFactory,
(context, renderTarget));
this->setDeviceFactory(factory)->unref();
SkASSERT(context); SkASSERT(context);
fContext = context; fContext = context;
fContext->ref(); fContext->ref();
this->setDevice(new SkGpuDevice(context, renderTarget))->unref();
} }
SkGpuCanvas::~SkGpuCanvas() { SkGpuCanvas::~SkGpuCanvas() {

Просмотреть файл

@ -19,7 +19,6 @@
#include "GrTextContext.h" #include "GrTextContext.h"
#include "SkGpuDevice.h" #include "SkGpuDevice.h"
#include "SkGpuDeviceFactory.h"
#include "SkGrTexturePixelRef.h" #include "SkGrTexturePixelRef.h"
#include "SkColorFilter.h" #include "SkColorFilter.h"
@ -47,6 +46,7 @@ enum {
kShaderTextureIdx = 0 kShaderTextureIdx = 0
}; };
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
SkGpuDevice::SkAutoCachedTexture:: SkGpuDevice::SkAutoCachedTexture::
@ -1494,58 +1494,3 @@ SkDevice* SkGpuDevice::onCreateCompatibleDevice(SkBitmap::Config config,
width, height, usage)); 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));
}
}

Просмотреть файл

@ -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, static inline SkBitmap makeContentBitmap(const SkISize& contentSize,
const SkMatrix* initialTransform) { const SkMatrix* initialTransform) {
SkBitmap bitmap; SkBitmap bitmap;
@ -565,10 +551,6 @@ void SkPDFDevice::init() {
fLastContentEntry = NULL; fLastContentEntry = NULL;
} }
SkDeviceFactory* SkPDFDevice::onNewDeviceFactory() {
return SkNEW(SkPDFDeviceFactory);
}
void SkPDFDevice::cleanUp() { void SkPDFDevice::cleanUp() {
fGraphicStateResources.unrefAll(); fGraphicStateResources.unrefAll();
fXObjectResources.unrefAll(); fXObjectResources.unrefAll();