diff options
author | Mike Reed <reed@google.com> | 2018-02-08 14:10:40 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-02-08 19:34:50 +0000 |
commit | 4c790bd7dd8a6edacfc39b65b7043742331ab4da (patch) | |
tree | 1d66da0bfa6b7627315388b0d3f712897ea03bbd /src/image/SkSurface.cpp | |
parent | b9fc24e465767db8bd9dbddfd67c905392346e66 (diff) |
add writePixels to SkSurface --> so we can remove it from canvas
Bug: skia:
Change-Id: Ib35d7bdc113c3fd9f6dfacb42ec61aaa448cb165
Reviewed-on: https://skia-review.googlesource.com/105623
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/image/SkSurface.cpp')
-rw-r--r-- | src/image/SkSurface.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index ef6d809957..26ee40e9fb 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -184,6 +184,30 @@ bool SkSurface::readPixels(const SkBitmap& bitmap, int srcX, int srcY) { return bitmap.peekPixels(&pm) && this->readPixels(pm, srcX, srcY); } +void SkSurface::writePixels(const SkPixmap& pmap, int x, int y) { + if (pmap.addr() == nullptr || pmap.width() <= 0 || pmap.height() <= 0) { + return; + } + + const SkIRect srcR = SkIRect::MakeXYWH(x, y, pmap.width(), pmap.height()); + const SkIRect dstR = SkIRect::MakeWH(this->width(), this->height()); + if (SkIRect::Intersects(srcR, dstR)) { + ContentChangeMode mode = kRetain_ContentChangeMode; + if (srcR.contains(dstR)) { + mode = kDiscard_ContentChangeMode; + } + asSB(this)->aboutToDraw(mode); + asSB(this)->onWritePixels(pmap, x, y); + } +} + +void SkSurface::writePixels(const SkBitmap& src, int x, int y) { + SkPixmap pm; + if (src.peekPixels(&pm)) { + this->writePixels(pm, x, y); + } +} + GrBackendObject SkSurface::getTextureHandle(BackendHandleAccess access) { return asSB(this)->onGetTextureHandle(access); } @@ -232,6 +256,7 @@ protected: return MakeNull(info.width(), info.height()); } sk_sp<SkImage> onNewImageSnapshot() override { return nullptr; } + void onWritePixels(const SkPixmap&, int x, int y) override {} void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) override {} void onCopyOnWrite(ContentChangeMode) override {} }; |