bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override;
bool onPeekPixels(SkPixmap*) override;
bool onAccessPixels(SkPixmap*) override;
- void onAttachToCanvas(SkCanvas*) override;
- void onDetachFromCanvas() override;
private:
friend class SkCanvas;
*/
const SkIPoint& getOrigin() const { return fOrigin; }
- /**
- * onAttachToCanvas is invoked whenever a device is installed in a canvas
- * (i.e., setDevice, saveLayer (for the new device created by the save),
- * and SkCanvas' SkBaseDevice & SkBitmap -taking ctors). It allows the
- * devices to prepare for drawing (e.g., locking their pixels, etc.)
- */
- virtual void onAttachToCanvas(SkCanvas*) {
- SkASSERT(!fAttachedToCanvas);
-#ifdef SK_DEBUG
- fAttachedToCanvas = true;
-#endif
- };
-
- /**
- * onDetachFromCanvas notifies a device that it will no longer be drawn to.
- * It gives the device a chance to clean up (e.g., unlock its pixels). It
- * is invoked from setDevice (for the displaced device), restore and
- * possibly from SkCanvas' dtor.
- */
- virtual void onDetachFromCanvas() {
- SkASSERT(fAttachedToCanvas);
-#ifdef SK_DEBUG
- fAttachedToCanvas = false;
-#endif
- };
-
protected:
enum TileUsage {
kPossible_TileUsage, //!< the created device may be drawn tiled
SkBitmap fLegacyBitmap;
#endif
-#ifdef SK_DEBUG
- bool fAttachedToCanvas;
-#endif
-
typedef SkRefCnt INHERITED;
};
SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap)
: INHERITED(SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType))
- , fBitmap(bitmap) {
+ , fBitmap(bitmap)
+{
SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr));
+ fBitmap.lockPixels();
}
SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) {
SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps)
: INHERITED(surfaceProps)
- , fBitmap(bitmap) {
+ , fBitmap(bitmap)
+{
SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr));
+ fBitmap.lockPixels();
}
SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo,
return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, x, y);
}
-void SkBitmapDevice::onAttachToCanvas(SkCanvas* canvas) {
- INHERITED::onAttachToCanvas(canvas);
- fBitmap.lockPixels();
-}
-
-void SkBitmapDevice::onDetachFromCanvas() {
- INHERITED::onDetachFromCanvas();
- fBitmap.unlockPixels();
-}
-
///////////////////////////////////////////////////////////////////////////////
void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
, fClip(conservativeRasterClip)
, fStashedMatrix(stashed)
{
- if (nullptr != device) {
- device->ref();
- device->onAttachToCanvas(canvas);
- }
+ SkSafeRef(device);
fDevice = device;
fPaint = paint ? new SkPaint(*paint) : nullptr;
}
~DeviceCM() {
- if (fDevice) {
- fDevice->onDetachFromCanvas();
- fDevice->unref();
- }
+ SkSafeUnref(fDevice);
delete fPaint;
}
if (device) {
// The root device and the canvas should always have the same pixel geometry
SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry());
- device->onAttachToCanvas(this);
fMCRec->fLayer->fDevice = SkRef(device);
fMCRec->fRasterClip.setRect(device->getGlobalBounds());
}
#include "SkTextBlobRunIterator.h"
#include "SkTextToPathIter.h"
-SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps)
- : fSurfaceProps(surfaceProps)
-#ifdef SK_DEBUG
- , fAttachedToCanvas(false)
-#endif
-{
+SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps) : fSurfaceProps(surfaceProps) {
fOrigin.setZero();
fMetaData = nullptr;
}
return false;
}
-void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) {
- ASSERT_SINGLE_OWNER
- INHERITED::onAttachToCanvas(canvas);
-
- // Canvas promises that this ptr is valid until onDetachFromCanvas is called
- fClipStack.reset(SkRef(canvas->getClipStack()));
-}
-
-void SkGpuDevice::onDetachFromCanvas() {
- ASSERT_SINGLE_OWNER
- INHERITED::onDetachFromCanvas();
- fClip.reset();
- fClipStack.reset(nullptr);
-}
-
// call this every draw call, to ensure that the context reflects our state,
// and not the state from some other canvas/device
void SkGpuDevice::prepareDraw(const SkDraw& draw) {
ASSERT_SINGLE_OWNER
- SkASSERT(fClipStack.get());
-
- SkASSERT(draw.fClipStack && draw.fClipStack == fClipStack);
- fClip.reset(fClipStack, &this->getOrigin());
+ fClip.reset(draw.fClipStack, &this->getOrigin());
}
GrDrawContext* SkGpuDevice::accessDrawContext() {
void flush() override;
- void onAttachToCanvas(SkCanvas* canvas) override;
- void onDetachFromCanvas() override;
-
bool onAccessPixels(SkPixmap*) override;
// for debugging purposes only
sk_sp<GrRenderTarget> fRenderTarget;
sk_sp<GrDrawContext> fDrawContext;
- SkAutoTUnref<const SkClipStack> fClipStack;
SkIPoint fClipOrigin;
GrClipStackClip fClip;
SkISize fSize;
, fPageSize(pageSize)
, fContentSize(pageSize)
, fExistingClipRegion(SkIRect::MakeSize(pageSize))
- , fClipStack(nullptr)
, fRasterDpi(rasterDpi)
, fDocument(doc) {
SkASSERT(pageSize.width() > 0);
return info;
}
-void SkPDFDevice::onAttachToCanvas(SkCanvas* canvas) {
- INHERITED::onAttachToCanvas(canvas);
-
- // Canvas promises that this ptr is valid until onDetachFromCanvas is called
- fClipStack = canvas->getClipStack();
-}
-
-void SkPDFDevice::onDetachFromCanvas() {
- INHERITED::onDetachFromCanvas();
-
- fClipStack = nullptr;
-}
-
sk_sp<SkSurface> SkPDFDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) {
return SkSurface::MakeRaster(info, &props);
}
void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
const SkPaint&) override;
- void onAttachToCanvas(SkCanvas* canvas) override;
- void onDetachFromCanvas() override;
SkImageInfo imageInfo() const override;
// PDF specific methods.
};
SkSinglyLinkedList<ContentEntry> fContentEntries;
- const SkClipStack* fClipStack;
-
SkScalar fRasterDpi;
SkPDFDocument* fDocument;