start to replace onCreateDevice with onCreateCompatibleDevice

the new virtual takes a struct which we can amend in the future w/o having to
update our subclasses in chrome.

BUG=skia:
NOTRY=True

Review URL: https://codereview.chromium.org/723743002
This commit is contained in:
reed 2014-11-12 14:31:11 -08:00 committed by Commit bot
parent e069400cab
commit b122ee50fb
10 changed files with 37 additions and 25 deletions

View File

@ -153,7 +153,7 @@ private:
// any clip information. // any clip information.
virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRIDE; 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 SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE;
virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes) SK_OVERRIDE; virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes) SK_OVERRIDE;

View File

@ -340,6 +340,17 @@ protected:
void setPixelGeometry(SkPixelGeometry geo); 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) {
// call deprecated method until we can update chrome's subclasses
return this->onCreateDevice(cinfo.fInfo, cinfo.fUsage);
}
private: private:
friend class SkCanvas; friend class SkCanvas;
friend struct DeviceCM; //for setMatrixClip friend struct DeviceCM; //for setMatrixClip
@ -366,6 +377,7 @@ private:
// just called by SkCanvas for imagefilter // just called by SkCanvas for imagefilter
SkBaseDevice* createCompatibleDeviceForImageFilter(const SkImageInfo&); SkBaseDevice* createCompatibleDeviceForImageFilter(const SkImageInfo&);
// DEPRECATED -- override onCreateCompatibleDevice instead.
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) { virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) {
return NULL; return NULL;
} }

View File

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

View File

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

View File

@ -29,15 +29,15 @@ SkBaseDevice::~SkBaseDevice() {
} }
SkBaseDevice* SkBaseDevice::createCompatibleDevice(const SkImageInfo& info) { 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) { 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) { SkBaseDevice* SkBaseDevice::createCompatibleDeviceForImageFilter(const SkImageInfo& info) {
return this->onCreateDevice(info, kImageFilter_Usage); return this->onCreateCompatibleDevice(CreateInfo(info, kImageFilter_Usage));
} }
SkMetaData& SkBaseDevice::getMetaData() { SkMetaData& SkBaseDevice::getMetaData() {

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

View File

@ -142,7 +142,7 @@ private:
SkGpuDevice(GrSurface*, const SkSurfaceProps&, unsigned flags = 0); 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; 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. // PDF does not support image filters, so render them on CPU.
// Note that this rendering is done at "screen" resolution (100dpi), not // Note that this rendering is done at "screen" resolution (100dpi), not
// printer resolution. // printer resolution.
// FIXME: It may be possible to express some filters natively using PDF // FIXME: It may be possible to express some filters natively using PDF
// to improve quality and file size (http://skbug.com/3043) // to improve quality and file size (http://skbug.com/3043)
if (kImageFilter_Usage == usage) { if (kImageFilter_Usage == cinfo.fUsage) {
return SkBitmapDevice::Create(info); return SkBitmapDevice::Create(cinfo.fInfo);
} }
SkMatrix initialTransform; SkMatrix initialTransform;
initialTransform.reset(); 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)); return SkNEW_ARGS(SkPDFDevice, (size, size, initialTransform));
} }

View File

@ -159,7 +159,7 @@ public:
virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE; 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; virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE;
@ -463,15 +463,15 @@ const SkBitmap& SkDeferredDevice::onAccessBitmap() {
return immediateDevice()->accessBitmap(false); 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. // 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. // Create a compatible non-deferred device.
// We do not create a deferred device because we know the new 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). // will not be used with a deferred canvas (there is no API for that).
// And connecting a SkDeferredDevice to non-deferred canvas can result // And connecting a SkDeferredDevice to non-deferred canvas can result
// in unpredictable behavior. // in unpredictable behavior.
return immediateDevice()->createCompatibleDevice(info); return immediateDevice()->onCreateCompatibleDevice(cinfo);
} }
SkSurface* SkDeferredDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) { SkSurface* SkDeferredDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) {

View File

@ -157,10 +157,10 @@ protected:
virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRIDE { virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRIDE {
not_supported(); 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. // we expect to only get called via savelayer, in which case it is fine.
SkASSERT(kSaveLayer_Usage == usage); SkASSERT(kSaveLayer_Usage == cinfo.fUsage);
return SkNEW_ARGS(GatherPixelRefDevice, (info.width(), info.height(), fPRSet)); return SkNEW_ARGS(GatherPixelRefDevice, (cinfo.fInfo.width(), cinfo.fInfo.height(), fPRSet));
} }
virtual void flush() SK_OVERRIDE {} virtual void flush() SK_OVERRIDE {}