MCRec* fMCRec;
// the first N recs that can fit here mean we won't call malloc
enum {
- kMCRecSize = 128, // most recent measurement
+ kMCRecSize = 136, // most recent measurement
kMCRecCount = 8, // common depth for save/restores
};
intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)];
const SkRect& dst, const SkPaint* paint);
void internalDrawPaint(const SkPaint& paint);
void internalSaveLayer(const SkRect* bounds, const SkPaint*, SaveFlags, SaveLayerStrategy);
- void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*);
+ void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool isBitmapDevice);
// shared by save() and saveLayer()
void internalSave();
/**
* Create a new device based on CreateInfo. If the paint is not null, then it represents a
* preview of how the new device will be composed with its creator device (this).
+ *
+ * The subclass may be handed this device in drawDevice(), so it must always return
+ * a device that it knows how to draw, and that it knows how to identify if it is not of the
+ * same subclass (since drawDevice is passed a SkBaseDevice*). If the subclass cannot fulfill
+ * that contract (e.g. PDF cannot support some settings on the paint) it should return NULL,
+ * and the caller may then decide to explicitly create a bitmapdevice, knowing that later
+ * it could not call drawDevice with it (but it could call drawSprite or drawBitmap).
*/
virtual SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) {
return NULL;
DeviceCM* fNext;
SkBaseDevice* fDevice;
SkRasterClip fClip;
- const SkMatrix* fMatrix;
SkPaint* fPaint; // may be null (in the future)
+ const SkMatrix* fMatrix;
+ SkMatrix fMatrixStorage;
+ const bool fDeviceIsBitmapDevice;
DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas,
- bool conservativeRasterClip)
+ bool conservativeRasterClip, bool deviceIsBitmapDevice)
: fNext(NULL)
, fClip(conservativeRasterClip)
+ , fDeviceIsBitmapDevice(deviceIsBitmapDevice)
{
if (NULL != device) {
device->ref();
}
#endif
}
-
-private:
- SkMatrix fMatrixStorage;
};
/* This is the record we keep for each save/restore level in the stack.
SkASSERT(sizeof(DeviceCM) <= sizeof(fBaseLayerStorage));
fMCRec->fLayer = (DeviceCM*)fBaseLayerStorage;
- new (fBaseLayerStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip);
+ new (fBaseLayerStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, false);
fMCRec->fTopLayer = fMCRec->fLayer;
return;
}
- SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage;
- device = device->onCreateDevice(SkBaseDevice::CreateInfo(info, usage, geo), paint);
- if (NULL == device) {
- SkErrorInternals::SetError( kInternalError_SkError,
- "Unable to create device for layer.");
- return;
+ bool forceSpriteOnRestore = false;
+ {
+ const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage;
+ const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(info, usage, geo);
+ SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint);
+ if (NULL == newDev) {
+ // If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't handle the paint)
+ newDev = SkBitmapDevice::Create(createInfo.fInfo);
+ if (NULL == newDev) {
+ SkErrorInternals::SetError(kInternalError_SkError,
+ "Unable to create device for layer.");
+ return;
+ }
+ forceSpriteOnRestore = true;
+ }
+ device = newDev;
}
device->setOrigin(ir.fLeft, ir.fTop);
- DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRasterClip));
+ DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRasterClip,
+ forceSpriteOnRestore));
device->unref();
layer->fNext = fMCRec->fTopLayer;
if (layer->fNext) {
const SkIPoint& origin = layer->fDevice->getOrigin();
this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(),
- layer->fPaint);
+ layer->fPaint, layer->fDeviceIsBitmapDevice);
// reset this, since internalDrawDevice will have set it to true
fDeviceCMDirty = true;
SkDELETE(layer);
}
void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y,
- const SkPaint* paint) {
+ const SkPaint* paint, bool deviceIsBitmapDevice) {
SkPaint tmp;
if (NULL == paint) {
paint = &tmp;
dstDev->drawSprite(iter, dst, pos.x() + offset.x(), pos.y() + offset.y(),
tmpUnfiltered);
}
+ } else if (deviceIsBitmapDevice) {
+ const SkBitmap& src = srcDev->accessBitmap(false);
+ dstDev->drawSprite(iter, src, pos.x(), pos.y(), *paint);
} else {
dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint);
}
#ifndef SkDeviceImageFilterProxy_DEFINED
#define SkDeviceImageFilterProxy_DEFINED
+#include "SkBitmapDevice.h"
#include "SkDevice.h"
#include "SkImageFilter.h"
#include "SkSurfaceProps.h"
SkBaseDevice::kNever_TileUsage,
kUnknown_SkPixelGeometry,
true /*forImageFilter*/);
- return fDevice->onCreateDevice(cinfo, NULL);
+ SkBaseDevice* dev = fDevice->onCreateDevice(cinfo, NULL);
+ if (NULL == dev) {
+ dev = SkBitmapDevice::Create(cinfo.fInfo);
+ }
+ return dev;
}
bool canHandleImageFilter(const SkImageFilter* filter) override {
return fDevice->canHandleImageFilter(filter);