Rename onCreateDevice -> onCreateCompatibleDevice

This is a port of https://codereview.chromium.org/723743002/ with the
following changes:

* drop the legacy onCreateDevice variant completely
* also convert SkXPSDevice & SkGatherPixelRefsAndRects to the new API

This is expected to break canaries and will require a manual/cowboy
roll.

TBR=reed@google.com
NOTREECHECKS=true

Review URL: https://codereview.chromium.org/720213002
This commit is contained in:
fmalita 2014-11-13 08:33:37 -08:00 committed by Commit bot
parent 3b27adef0a
commit 6987dcaf25
13 changed files with 44 additions and 38 deletions

View File

@ -107,7 +107,7 @@ protected:
const uint16_t indices[], int indexCount,
const SkPaint& paint) SK_OVERRIDE;
/** The SkBaseDevice passed will be an SkBaseDevice which was returned by a call to
onCreateDevice on this device with kSaveLayer_Usage.
onCreateCompatibleDevice on this device with kSaveLayer_Usage.
*/
virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
const SkPaint&) SK_OVERRIDE;
@ -153,7 +153,7 @@ private:
// any clip information.
virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRIDE;
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRIDE;
virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE;
virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes) SK_OVERRIDE;

View File

@ -236,7 +236,7 @@ protected:
virtual void drawPatch(const SkDraw&, const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
/** The SkDevice passed will be an SkDevice which was returned by a call to
onCreateDevice on this device with kSaveLayer_Usage.
onCreateCompatibleDevice on this device with kSaveLayer_Usage.
*/
virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
const SkPaint&) = 0;
@ -340,6 +340,16 @@ protected:
void setPixelGeometry(SkPixelGeometry geo);
struct CreateInfo {
CreateInfo(const SkImageInfo& info, Usage usage) : fInfo(info), fUsage(usage) {}
SkImageInfo fInfo;
Usage fUsage;
};
virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo& cinfo) {
return NULL;
}
private:
friend class SkCanvas;
friend struct DeviceCM; //for setMatrixClip
@ -366,10 +376,6 @@ private:
// just called by SkCanvas for imagefilter
SkBaseDevice* createCompatibleDeviceForImageFilter(const SkImageInfo&);
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) {
return NULL;
}
/** Causes any deferred drawing to the device to be completed.
*/
virtual void flush() {}

View File

@ -319,7 +319,7 @@ private:
const SkVector& ppuScale,
IXpsOMPath* shadedPath);
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRIDE;
// Disable the default copy and assign implementation.
SkXPSDevice(const SkXPSDevice&);

View File

@ -259,7 +259,7 @@ private:
const SkRegion& existingClipRegion);
// override from SkBaseDevice
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRIDE;
void init();
void cleanUp(bool clearFontUsage);

View File

@ -111,8 +111,8 @@ void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) {
fBitmap.lockPixels();
}
SkBaseDevice* SkBitmapDevice::onCreateDevice(const SkImageInfo& info, Usage usage) {
return SkBitmapDevice::Create(info);// &this->getDeviceProperties());
SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(const CreateInfo& cinfo) {
return SkBitmapDevice::Create(cinfo.fInfo);// &this->getDeviceProperties());
}
void SkBitmapDevice::lockPixels() {

View File

@ -29,15 +29,15 @@ SkBaseDevice::~SkBaseDevice() {
}
SkBaseDevice* SkBaseDevice::createCompatibleDevice(const SkImageInfo& info) {
return this->onCreateDevice(info, kGeneral_Usage);
return this->onCreateCompatibleDevice(CreateInfo(info, kGeneral_Usage));
}
SkBaseDevice* SkBaseDevice::createCompatibleDeviceForSaveLayer(const SkImageInfo& info) {
return this->onCreateDevice(info, kSaveLayer_Usage);
return this->onCreateCompatibleDevice(CreateInfo(info, kSaveLayer_Usage));
}
SkBaseDevice* SkBaseDevice::createCompatibleDeviceForImageFilter(const SkImageInfo& info) {
return this->onCreateDevice(info, kImageFilter_Usage);
return this->onCreateCompatibleDevice(CreateInfo(info, kImageFilter_Usage));
}
SkMetaData& SkBaseDevice::getMetaData() {

View File

@ -2247,10 +2247,10 @@ void SkXPSDevice::drawDevice(const SkDraw& d, SkBaseDevice* dev,
"Could not add layer to current visuals.");
}
SkBaseDevice* SkXPSDevice::onCreateDevice(const SkImageInfo&, Usage) {
SkBaseDevice* SkXPSDevice::onCreateCompatibleDevice(const CreateInfo& info) {
//Conditional for bug compatibility with PDF device.
#if 0
if (SkBaseDevice::kGeneral_Usage == usage) {
if (SkBaseDevice::kGeneral_Usage == info.fUsage) {
return NULL;
SK_CRASH();
//To what stream do we write?

View File

@ -1751,24 +1751,24 @@ void SkGpuDevice::flush() {
///////////////////////////////////////////////////////////////////////////////
SkBaseDevice* SkGpuDevice::onCreateDevice(const SkImageInfo& info, Usage usage) {
SkBaseDevice* SkGpuDevice::onCreateCompatibleDevice(const CreateInfo& cinfo) {
GrSurfaceDesc desc;
desc.fConfig = fRenderTarget->config();
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = info.width();
desc.fHeight = info.height();
desc.fWidth = cinfo.fInfo.width();
desc.fHeight = cinfo.fInfo.height();
desc.fSampleCnt = fRenderTarget->numSamples();
SkAutoTUnref<GrTexture> texture;
// Skia's convention is to only clear a device if it is non-opaque.
unsigned flags = info.isOpaque() ? 0 : kNeedClear_Flag;
unsigned flags = cinfo.fInfo.isOpaque() ? 0 : kNeedClear_Flag;
// If we're using distance field text, enable in the new device
flags |= (fFlags & kDFText_Flag) ? kDFText_Flag : 0;
#if CACHE_COMPATIBLE_DEVICE_TEXTURES
// layers are never draw in repeat modes, so we can request an approx
// match and ignore any padding.
const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ?
const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == cinfo.fUsage) ?
GrContext::kApprox_ScratchTexMatch :
GrContext::kExact_ScratchTexMatch;
texture.reset(fContext->refScratchTexture(desc, match));
@ -1779,7 +1779,7 @@ SkBaseDevice* SkGpuDevice::onCreateDevice(const SkImageInfo& info, Usage usage)
return SkGpuDevice::Create(texture, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType), flags);
} else {
SkDebugf("---- failed to create compatible device texture [%d %d]\n",
info.width(), info.height());
cinfo.fInfo.width(), cinfo.fInfo.height());
return NULL;
}
}

View File

@ -142,7 +142,7 @@ private:
SkGpuDevice(GrSurface*, const SkSurfaceProps&, unsigned flags = 0);
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRIDE;
virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE;

View File

@ -567,19 +567,19 @@ void GraphicStackState::updateDrawingState(const GraphicStateEntry& state) {
}
}
SkBaseDevice* SkPDFDevice::onCreateDevice(const SkImageInfo& info, Usage usage) {
SkBaseDevice* SkPDFDevice::onCreateCompatibleDevice(const CreateInfo& cinfo) {
// PDF does not support image filters, so render them on CPU.
// Note that this rendering is done at "screen" resolution (100dpi), not
// printer resolution.
// FIXME: It may be possible to express some filters natively using PDF
// to improve quality and file size (http://skbug.com/3043)
if (kImageFilter_Usage == usage) {
return SkBitmapDevice::Create(info);
if (kImageFilter_Usage == cinfo.fUsage) {
return SkBitmapDevice::Create(cinfo.fInfo);
}
SkMatrix initialTransform;
initialTransform.reset();
SkISize size = SkISize::Make(info.width(), info.height());
SkISize size = SkISize::Make(cinfo.fInfo.width(), cinfo.fInfo.height());
return SkNEW_ARGS(SkPDFDevice, (size, size, initialTransform));
}
@ -1231,7 +1231,7 @@ void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode,
void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device,
int x, int y, const SkPaint& paint) {
// our onCreateDevice() always creates SkPDFDevice subclasses.
// our onCreateCompatibleDevice() always creates SkPDFDevice subclasses.
SkPDFDevice* pdfDevice = static_cast<SkPDFDevice*>(device);
if (pdfDevice->isContentEmpty()) {
return;

View File

@ -159,7 +159,7 @@ public:
virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE;
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRIDE;
virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE;
@ -463,15 +463,15 @@ const SkBitmap& SkDeferredDevice::onAccessBitmap() {
return immediateDevice()->accessBitmap(false);
}
SkBaseDevice* SkDeferredDevice::onCreateDevice(const SkImageInfo& info, Usage usage) {
SkBaseDevice* SkDeferredDevice::onCreateCompatibleDevice(const CreateInfo& cinfo) {
// Save layer usage not supported, and not required by SkDeferredCanvas.
SkASSERT(usage != kSaveLayer_Usage);
SkASSERT(cinfo.fUsage != kSaveLayer_Usage);
// Create a compatible non-deferred device.
// We do not create a deferred device because we know the new device
// will not be used with a deferred canvas (there is no API for that).
// And connecting a SkDeferredDevice to non-deferred canvas can result
// in unpredictable behavior.
return immediateDevice()->createCompatibleDevice(info);
return immediateDevice()->onCreateCompatibleDevice(cinfo);
}
SkSurface* SkDeferredDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) {

View File

@ -302,11 +302,11 @@ private:
NotSupported();
}
virtual SkBaseDevice* onCreateDevice(const SkImageInfo& info, Usage usage) SK_OVERRIDE {
virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo& info) SK_OVERRIDE {
// we expect to only get called via savelayer, in which case it is fine.
SkASSERT(kSaveLayer_Usage == usage);
SkASSERT(kSaveLayer_Usage == info.fUsage);
return SkNEW_ARGS(SkGatherPixelRefsAndRectsDevice,
(info.width(), info.height(), fPRCont));
(info.fInfo.width(), info.fInfo.height(), fPRCont));
}
static void NotSupported() {

View File

@ -157,10 +157,10 @@ protected:
virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRIDE {
not_supported();
}
virtual SkBaseDevice* onCreateDevice(const SkImageInfo& info, Usage usage) SK_OVERRIDE {
virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo& cinfo) SK_OVERRIDE {
// we expect to only get called via savelayer, in which case it is fine.
SkASSERT(kSaveLayer_Usage == usage);
return SkNEW_ARGS(GatherPixelRefDevice, (info.width(), info.height(), fPRSet));
SkASSERT(kSaveLayer_Usage == cinfo.fUsage);
return SkNEW_ARGS(GatherPixelRefDevice, (cinfo.fInfo.width(), cinfo.fInfo.height(), fPRSet));
}
virtual void flush() SK_OVERRIDE {}