diff options
-rw-r--r-- | include/core/SkSurface.h | 10 | ||||
-rw-r--r-- | src/core/SkBitmapDevice.cpp | 10 | ||||
-rw-r--r-- | src/core/SkBitmapDevice.h | 4 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 14 | ||||
-rw-r--r-- | src/core/SkDevice.cpp | 13 | ||||
-rw-r--r-- | src/core/SkDevice.h | 8 | ||||
-rw-r--r-- | src/core/SkWritePixelsRec.h | 8 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 14 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.h | 4 | ||||
-rw-r--r-- | src/image/SkReadPixelsRec.h | 8 | ||||
-rw-r--r-- | src/image/SkSurface.cpp | 11 |
11 files changed, 61 insertions, 43 deletions
diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index b13702e83e..4a8d81205f 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -284,13 +284,13 @@ public: bool peekPixels(SkPixmap*); /** - * Copy the pixels from the surface into the specified buffer (pixels + rowBytes), - * converting them into the requested format (dstInfo). The surface pixels are read + * Copy the pixels from the surface into the specified pixmap, + * converting them into the pixmap's format. The surface pixels are read * starting at the specified (srcX,srcY) location. * - * The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle + * The pixmap and (srcX,srcY) offset specifies a source rectangle * - * srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height()); + * srcR.setXYWH(srcX, srcY, pixmap.width(), pixmap.height()); * * srcR is intersected with the bounds of the base-layer. If this intersection is not empty, * then we have two sets of pixels (of equal size). Replace the dst pixels with the @@ -301,8 +301,10 @@ public: * - If srcR does not intersect the surface bounds. * - If the requested colortype/alphatype cannot be converted from the surface's types. */ + bool readPixels(const SkPixmap& dst, int srcX, int srcY); bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY); + bool readPixels(const SkBitmap& dst, int srcX, int srcY); const SkSurfaceProps& props() const { return fProps; } diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 05920495c9..b3ab7fc03c 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -150,23 +150,21 @@ bool SkBitmapDevice::onPeekPixels(SkPixmap* pmap) { return false; } -bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels, - size_t srcRowBytes, int x, int y) { +bool SkBitmapDevice::onWritePixels(const SkPixmap& pm, int x, int y) { // since we don't stop creating un-pixeled devices yet, check for no pixels here if (nullptr == fBitmap.getPixels()) { return false; } - if (fBitmap.writePixels(SkPixmap(srcInfo, srcPixels, srcRowBytes), x, y)) { + if (fBitmap.writePixels(pm, x, y)) { fBitmap.notifyPixelsChanged(); return true; } return false; } -bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, - int x, int y) { - return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, x, y); +bool SkBitmapDevice::onReadPixels(const SkPixmap& pm, int x, int y) { + return fBitmap.readPixels(pm, x, y); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkBitmapDevice.h b/src/core/SkBitmapDevice.h index 7b08017f18..85a57281cd 100644 --- a/src/core/SkBitmapDevice.h +++ b/src/core/SkBitmapDevice.h @@ -120,8 +120,8 @@ protected: /////////////////////////////////////////////////////////////////////////// - bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) override; - bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override; + bool onReadPixels(const SkPixmap&, int x, int y) override; + bool onWritePixels(const SkPixmap&, int, int) override; bool onPeekPixels(SkPixmap*) override; bool onAccessPixels(SkPixmap*) override; diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index dab5be499a..809c2014bf 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -815,17 +815,13 @@ SkBaseDevice* SkCanvas::getTopDevice() const { return fMCRec->fTopLayer->fDevice.get(); } -bool SkCanvas::readPixels(const SkImageInfo& dstInfo, void* dstP, size_t rowBytes, int x, int y) { +bool SkCanvas::readPixels(const SkPixmap& pm, int x, int y) { SkBaseDevice* device = this->getDevice(); - if (!device) { - return false; - } - - return device->readPixels(dstInfo, dstP, rowBytes, x, y); + return device && pm.addr() && device->readPixels(pm, x, y); } -bool SkCanvas::readPixels(const SkPixmap& pm, int x, int y) { - return pm.addr() && this->readPixels(pm.info(), pm.writable_addr(), pm.rowBytes(), x, y); +bool SkCanvas::readPixels(const SkImageInfo& dstInfo, void* dstP, size_t rowBytes, int x, int y) { + return this->readPixels({ dstInfo, dstP, rowBytes}, x, y); } bool SkCanvas::readPixels(const SkBitmap& bm, int x, int y) { @@ -864,7 +860,7 @@ bool SkCanvas::writePixels(const SkImageInfo& srcInfo, const void* pixels, size_ // conversion. We could pull those checks into this function and avoid the unnecessary // generation ID bump. But then we would be performing those checks twice, since they // are also necessary at the bitmap/pixmap entry points. - return device->writePixels(srcInfo, pixels, rowBytes, x, y); + return device->writePixels({srcInfo, pixels, rowBytes}, x, y); } ////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index ddc3d33aef..bf71fdebd6 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -292,20 +292,19 @@ sk_sp<SkSpecialImage> SkBaseDevice::snapSpecial() { return nullptr; } /////////////////////////////////////////////////////////////////////////////////////////////////// -bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowBytes, int x, int y) { - return this->onReadPixels(info, dstP, rowBytes, x, y); +bool SkBaseDevice::readPixels(const SkPixmap& pm, int x, int y) { + return this->onReadPixels(pm, x, y); } -bool SkBaseDevice::writePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes, - int x, int y) { - return this->onWritePixels(info, pixels, rowBytes, x, y); +bool SkBaseDevice::writePixels(const SkPixmap& pm, int x, int y) { + return this->onWritePixels(pm, x, y); } -bool SkBaseDevice::onWritePixels(const SkImageInfo&, const void*, size_t, int, int) { +bool SkBaseDevice::onWritePixels(const SkPixmap&, int, int) { return false; } -bool SkBaseDevice::onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) { +bool SkBaseDevice::onReadPixels(const SkPixmap&, int x, int y) { return false; } diff --git a/src/core/SkDevice.h b/src/core/SkDevice.h index 2f6bff53d9..c0aef8ed95 100644 --- a/src/core/SkDevice.h +++ b/src/core/SkDevice.h @@ -70,7 +70,7 @@ public: return this->imageInfo().isOpaque(); } - bool writePixels(const SkImageInfo&, const void*, size_t rowBytes, int x, int y); + bool writePixels(const SkPixmap&, int x, int y); /** * Try to get write-access to the pixels behind the device. If successful, this returns true @@ -270,7 +270,7 @@ protected: virtual sk_sp<SkSpecialImage> makeSpecial(const SkImage*); virtual sk_sp<SkSpecialImage> snapSpecial(); - bool readPixels(const SkImageInfo&, void* dst, size_t rowBytes, int x, int y); + bool readPixels(const SkPixmap&, int x, int y); /////////////////////////////////////////////////////////////////////////// @@ -285,7 +285,7 @@ protected: * * This is explicitly asserted in readPixels(), the public way to call this. */ - virtual bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y); + virtual bool onReadPixels(const SkPixmap&, int x, int y); /** * The caller is responsible for "pre-clipping" the src. The impl can assume that the src @@ -293,7 +293,7 @@ protected: * * This is explicitly asserted in writePixelsDirect(), the public way to call this. */ - virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int x, int y); + virtual bool onWritePixels(const SkPixmap&, int x, int y); virtual bool onAccessPixels(SkPixmap*) { return false; } diff --git a/src/core/SkWritePixelsRec.h b/src/core/SkWritePixelsRec.h index 652a13a822..262a2de6c8 100644 --- a/src/core/SkWritePixelsRec.h +++ b/src/core/SkWritePixelsRec.h @@ -22,6 +22,14 @@ struct SkWritePixelsRec { , fY(y) {} + SkWritePixelsRec(const SkPixmap& pm, int x, int y) + : fPixels(pm.addr()) + , fRowBytes(pm.rowBytes()) + , fInfo(pm.info()) + , fX(x) + , fY(y) + {} + const void* fPixels; size_t fRowBytes; SkImageInfo fInfo; diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 5f2130b87c..57b2d41def 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -194,15 +194,14 @@ sk_sp<SkSpecialImage> SkGpuDevice::filterTexture(SkSpecialImage* srcImg, /////////////////////////////////////////////////////////////////////////////// -bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, - int x, int y) { +bool SkGpuDevice::onReadPixels(const SkPixmap& pm, int x, int y) { ASSERT_SINGLE_OWNER - if (!SkImageInfoValidConversion(dstInfo, this->imageInfo())) { + if (!SkImageInfoValidConversion(pm.info(), this->imageInfo())) { return false; } - SkReadPixelsRec rec(dstInfo, dstPixels, dstRowBytes, x, y); + SkReadPixelsRec rec(pm, x, y); if (!rec.trim(this->width(), this->height())) { return false; } @@ -210,15 +209,14 @@ bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size return fRenderTargetContext->readPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.fX, rec.fY); } -bool SkGpuDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels, - size_t srcRowBytes, int x, int y) { +bool SkGpuDevice::onWritePixels(const SkPixmap& pm, int x, int y) { ASSERT_SINGLE_OWNER - if (!SkImageInfoValidConversion(this->imageInfo(), srcInfo)) { + if (!SkImageInfoValidConversion(this->imageInfo(), pm.info())) { return false; } - SkWritePixelsRec rec(srcInfo, srcPixels, srcRowBytes, x, y); + SkWritePixelsRec rec(pm, x, y); if (!rec.trim(this->width(), this->height())) { return false; } diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h index 3f69153355..3fc3807d22 100644 --- a/src/gpu/SkGpuDevice.h +++ b/src/gpu/SkGpuDevice.h @@ -124,8 +124,8 @@ public: bool onAccessPixels(SkPixmap*) override; protected: - bool onReadPixels(const SkImageInfo&, void*, size_t, int, int) override; - bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override; + bool onReadPixels(const SkPixmap&, int, int) override; + bool onWritePixels(const SkPixmap&, int, int) override; bool onShouldDisableLCD(const SkPaint&) const final; private: diff --git a/src/image/SkReadPixelsRec.h b/src/image/SkReadPixelsRec.h index ed93b74b0f..6626ef26fc 100644 --- a/src/image/SkReadPixelsRec.h +++ b/src/image/SkReadPixelsRec.h @@ -22,6 +22,14 @@ struct SkReadPixelsRec { , fY(y) {} + SkReadPixelsRec(const SkPixmap& pm, int x, int y) + : fPixels(pm.writable_addr()) + , fRowBytes(pm.rowBytes()) + , fInfo(pm.info()) + , fX(x) + , fY(y) + {} + void* fPixels; size_t fRowBytes; SkImageInfo fInfo; diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index d7fa60589a..29068b2c4a 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -170,9 +170,18 @@ bool SkSurface::peekPixels(SkPixmap* pmap) { return this->getCanvas()->peekPixels(pmap); } +bool SkSurface::readPixels(const SkPixmap& pm, int srcX, int srcY) { + return this->getCanvas()->readPixels(pm, srcX, srcY); +} + bool SkSurface::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY) { - return this->getCanvas()->readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY); + return this->readPixels({dstInfo, dstPixels, dstRowBytes}, srcX, srcY); +} + +bool SkSurface::readPixels(const SkBitmap& bitmap, int srcX, int srcY) { + SkPixmap pm; + return bitmap.peekPixels(&pm) && this->readPixels(pm, srcX, srcY); } GrBackendObject SkSurface::getTextureHandle(BackendHandleAccess access) { |