bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) override;
bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override;
void* onAccessPixels(SkImageInfo* info, size_t* rowBytes) override;
-
- /** Called when this device is installed into a Canvas. Balanced by a call
- to unlockPixels() when the device is removed from a Canvas.
- */
- void lockPixels() override;
- void unlockPixels() override;
+ void onAttachToCanvas(SkCanvas*) override;
+ void onDetachFromCanvas() override;
private:
friend class SkCanvas;
*/
virtual void onAttachToCanvas(SkCanvas*) {
SkASSERT(!fAttachedToCanvas);
- this->lockPixels();
#ifdef SK_DEBUG
fAttachedToCanvas = true;
#endif
*/
virtual void onDetachFromCanvas() {
SkASSERT(fAttachedToCanvas);
- this->unlockPixels();
#ifdef SK_DEBUG
fAttachedToCanvas = false;
#endif
*/
virtual const SkBitmap& onAccessBitmap() = 0;
- /** Called when this device is installed into a Canvas. Balanced by a call
- to unlockPixels() when the device is removed from a Canvas.
- */
- virtual void lockPixels() {}
- virtual void unlockPixels() {}
-
/**
* Override and return true for filters that the device can handle
* intrinsically. Doing so means that SkCanvas will pass-through this
return SkBitmapDevice::Create(cinfo.fInfo, &leaky);
}
-void SkBitmapDevice::lockPixels() {
- if (fBitmap.lockPixelsAreWritable()) {
- fBitmap.lockPixels();
- }
-}
-
-void SkBitmapDevice::unlockPixels() {
- if (fBitmap.lockPixelsAreWritable()) {
- fBitmap.unlockPixels();
- }
-}
-
const SkBitmap& SkBitmapDevice::onAccessBitmap() {
return fBitmap;
}
return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, x, y);
}
+void SkBitmapDevice::onAttachToCanvas(SkCanvas* canvas) {
+ INHERITED::onAttachToCanvas(canvas);
+ if (fBitmap.lockPixelsAreWritable()) {
+ fBitmap.lockPixels();
+ }
+}
+
+void SkBitmapDevice::onDetachFromCanvas() {
+ INHERITED::onDetachFromCanvas();
+ if (fBitmap.lockPixelsAreWritable()) {
+ fBitmap.unlockPixels();
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
const SkPaint&) override
{SkASSERT(0);}
- void lockPixels() override {}
- void unlockPixels() override {}
-
bool canHandleImageFilter(const SkImageFilter*) override {
return false;
}