kSilent_PlaybackMode,
};
-static bool shouldDrawImmediately(const SkBitmap* bitmap, const SkPaint* paint,
- size_t bitmapSizeThreshold) {
+static bool should_draw_immediately(const SkBitmap* bitmap, const SkPaint* paint,
+ size_t bitmapSizeThreshold) {
if (bitmap && ((bitmap->getTexture() && !bitmap->isImmutable()) ||
(bitmap->getSize() > bitmapSizeThreshold))) {
return true;
if (shader && !shader->asAGradient(NULL)) {
SkBitmap bm;
if (shader->asABitmap(&bm, NULL, NULL) &&
- NULL != bm.getTexture()) {
+ bm.getTexture()) {
return true;
}
}
bool hasPendingCommands();
size_t storageAllocatedForRecording() const;
size_t freeMemoryIfPossible(size_t bytesToFree);
- size_t getBitmapSizeThreshold() const;
- void setBitmapSizeThreshold(size_t sizeThreshold);
void flushPendingCommands(PlaybackMode);
void skipPendingCommands();
void setMaxRecordingStorage(size_t);
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
- virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE;
+ virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE;
protected:
virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE;
SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE
{SkASSERT(0);}
virtual void drawPosText(const SkDraw&, const void* text, size_t len,
- const SkScalar pos[], SkScalar constY,
- int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE
+ const SkScalar pos[], int scalarsPerPos,
+ const SkPoint& offset, const SkPaint& paint) SK_OVERRIDE
{SkASSERT(0);}
virtual void drawTextOnPath(const SkDraw&, const void* text,
size_t len, const SkPath& path,
SkXfermode* xmode, const uint16_t indices[],
int indexCount, const SkPaint& paint) SK_OVERRIDE
{SkASSERT(0);}
+ virtual void drawPatch(const SkDraw&, const SkPoint cubics[12], const SkColor colors[4],
+ const SkPoint texCoords[4], SkXfermode* xmode,
+ const SkPaint& paint) SK_OVERRIDE
+ {SkASSERT(0);}
virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
const SkPaint&) SK_OVERRIDE
{SkASSERT(0);}
bool fCanDiscardCanvasContents;
size_t fMaxRecordingStorageBytes;
size_t fPreviousStorageAllocated;
- size_t fBitmapSizeThreshold;
};
SkDeferredDevice::SkDeferredDevice(SkSurface* surface) {
fFreshFrame = true;
fCanDiscardCanvasContents = false;
fPreviousStorageAllocated = 0;
- fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold;
fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes;
fNotificationClient = NULL;
this->beginRecording();
void SkDeferredDevice::aboutToDraw()
{
- if (NULL != fNotificationClient) {
+ if (fNotificationClient) {
fNotificationClient->prepareForDraw();
}
if (fCanDiscardCanvasContents) {
- if (NULL != fSurface) {
+ if (fSurface) {
fSurface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
}
fCanDiscardCanvasContents = false;
return val;
}
-size_t SkDeferredDevice::getBitmapSizeThreshold() const {
- return fBitmapSizeThreshold;
-}
-
-void SkDeferredDevice::setBitmapSizeThreshold(size_t sizeThreshold) {
- fBitmapSizeThreshold = sizeThreshold;
-}
-
size_t SkDeferredDevice::storageAllocatedForRecording() const {
return (fPipeController.storageAllocatedForRecording()
+ fPipeWriter.storageAllocatedForRecording());
return immediateDevice()->createCompatibleDevice(info);
}
-SkSurface* SkDeferredDevice::newSurface(const SkImageInfo& info) {
- return this->immediateDevice()->newSurface(info);
+SkSurface* SkDeferredDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) {
+ return this->immediateDevice()->newSurface(info, props);
}
bool SkDeferredDevice::onReadPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
}
}
private:
- void init(SkDeferredCanvas& canvas, const SkBitmap* bitmap, const SkPaint* paint)
- {
- SkDeferredDevice* device = static_cast<SkDeferredDevice*>(canvas.getDevice());
- if (canvas.isDeferredDrawing() && (NULL != device) &&
- shouldDrawImmediately(bitmap, paint, device->getBitmapSizeThreshold())) {
+ void init(SkDeferredCanvas& canvas, const SkBitmap* bitmap, const SkPaint* paint) {
+ if (canvas.isDeferredDrawing() &&
+ should_draw_immediately(bitmap, paint, canvas.getBitmapSizeThreshold())) {
canvas.setDeferredDrawing(false);
fCanvas = &canvas;
} else {
}
void SkDeferredCanvas::init() {
+ fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold;
fDeferredDrawing = true; // On by default
+ fCachedCanvasSize.setEmpty();
+ fCachedCanvasSizeDirty = true;
}
void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) {
}
void SkDeferredCanvas::setBitmapSizeThreshold(size_t sizeThreshold) {
- SkDeferredDevice* deferredDevice = this->getDeferredDevice();
- SkASSERT(deferredDevice);
- deferredDevice->setBitmapSizeThreshold(sizeThreshold);
+ fBitmapSizeThreshold = sizeThreshold;
}
void SkDeferredCanvas::recordedDrawCommand() {
return this->getDeferredDevice()->isFreshFrame();
}
+SkISize SkDeferredCanvas::getCanvasSize() const {
+ if (fCachedCanvasSizeDirty) {
+ fCachedCanvasSize = this->getBaseLayerSize();
+ fCachedCanvasSizeDirty = false;
+ }
+ return fCachedCanvasSize;
+}
+
bool SkDeferredCanvas::hasPendingCommands() const {
return this->getDeferredDevice()->hasPendingCommands();
}
SkSurface* SkDeferredCanvas::setSurface(SkSurface* surface) {
SkDeferredDevice* deferredDevice = this->getDeferredDevice();
- SkASSERT(NULL != deferredDevice);
+ SkASSERT(deferredDevice);
// By swapping the surface into the existing device, we preserve
// all pending commands, which can help to seamlessly recover from
// a lost accelerated graphics context.
deferredDevice->setSurface(surface);
+ fCachedCanvasSizeDirty = true;
return surface;
}
bool SkDeferredCanvas::isFullFrame(const SkRect* rect,
const SkPaint* paint) const {
SkCanvas* canvas = this->drawingCanvas();
- SkISize canvasSize = this->getDeviceSize();
+ SkISize canvasSize = this->getCanvasSize();
if (rect) {
if (!canvas->getTotalMatrix().rectStaysRect()) {
return false; // conservative
SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight)));
}
-void SkDeferredCanvas::willSave(SaveFlags flags) {
- this->drawingCanvas()->save(flags);
+void SkDeferredCanvas::willSave() {
+ this->drawingCanvas()->save();
this->recordedDrawCommand();
- this->INHERITED::willSave(flags);
+ this->INHERITED::willSave();
}
SkCanvas::SaveLayerStrategy SkDeferredCanvas::willSaveLayer(const SkRect* bounds,
this->recordedDrawCommand();
}
-void SkDeferredCanvas::onDrawPicture(const SkPicture* picture) {
- this->drawingCanvas()->drawPicture(picture);
+void SkDeferredCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
+ const SkPaint& paint) {
+ AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
+ this->drawingCanvas()->drawTextBlob(blob, x, y, paint);
+ this->recordedDrawCommand();
+}
+
+void SkDeferredCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
+ const SkPaint* paint) {
+ this->drawingCanvas()->drawPicture(picture, matrix, paint);
this->recordedDrawCommand();
}
this->recordedDrawCommand();
}
+void SkDeferredCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
+ const SkPoint texCoords[4], SkXfermode* xmode,
+ const SkPaint& paint) {
+ AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
+ this->drawingCanvas()->drawPatch(cubics, colors, texCoords, xmode, paint);
+ this->recordedDrawCommand();
+}
+
SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) {
this->drawingCanvas()->setDrawFilter(filter);
this->INHERITED::setDrawFilter(filter);