Expose the owning surface to a canvas?

Handy if you want to flush, or otherwise understand the underlying buffer(s).

Change-Id: I3d6610695c8603232192b26c687c6c74512165dd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/254803
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Mike Reed 2019-11-15 15:00:27 -05:00 committed by Skia Commit-Bot
parent 67a625e51e
commit a2b3b9efb8
3 changed files with 12 additions and 1 deletions

View File

@ -73,7 +73,9 @@ protected:
}
}
// Prevent any batching between "frames".
canvas->flush();
if (auto surf = canvas->getSurface()) {
surf->flush();
}
}
}

View File

@ -286,6 +286,11 @@ public:
*/
virtual GrContext* getGrContext();
/** Sometimes a canvas is owned by a surface. If it is, getSurface() will return a bare
* pointer to that surface, else this will return nullptr.
*/
SkSurface* getSurface() const;
/** Returns the pixel base address, SkImageInfo, rowBytes, and origin if the pixels
can be read directly. The returned address is only valid
while SkCanvas is in scope and unchanged. Any SkCanvas call or SkSurface call

View File

@ -619,6 +619,10 @@ void SkCanvas::onFlush() {
}
}
SkSurface* SkCanvas::getSurface() const {
return fSurfaceBase;
}
SkISize SkCanvas::getBaseLayerSize() const {
SkBaseDevice* d = this->getDevice();
return d ? SkISize::Make(d->width(), d->height()) : SkISize::Make(0, 0);