diff options
author | Matt Sarett <msarett@google.com> | 2017-01-20 16:59:02 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-23 15:23:31 +0000 |
commit | 977f64cbfad1ecd7fd4b1231c694c7e828fda1f0 (patch) | |
tree | d419cde9e63734448b8f01da25105123086d667c /src/core/SkPixmap.cpp | |
parent | 6987b00fae08ef0731042bb341b4e002a2da72c2 (diff) |
Refactor trimming logic for read/writePixels()
(1) Move trimming logic into Bitmap/Pixmap level for
raster. Everything goes through here, so we'll
only do the work once.
(2) This means it also goes to GPU level.
(3) Always use SkReadPixelsRec rather than inlining
the logic.
(4) Create an SkWritePixelsRec to encapsulate write
trimming.
(5) Disabled kIndex8 as a dst - always.
BUG=skia:6021
Change-Id: I748f50c3b726f7c6de5462e2b1ccb54bc387a510
Reviewed-on: https://skia-review.googlesource.com/7326
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>
Diffstat (limited to 'src/core/SkPixmap.cpp')
-rw-r--r-- | src/core/SkPixmap.cpp | 34 |
1 files changed, 9 insertions, 25 deletions
diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp index 1e24b93a60..c0889cfd84 100644 --- a/src/core/SkPixmap.cpp +++ b/src/core/SkPixmap.cpp @@ -16,6 +16,7 @@ #include "SkNx.h" #include "SkPM4f.h" #include "SkPixmap.h" +#include "SkReadPixelsRec.h" #include "SkSurface.h" #include "SkUtils.h" @@ -83,37 +84,20 @@ bool SkPixmap::extractSubset(SkPixmap* result, const SkIRect& subset) const { return true; } -bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels, size_t dstRB, - int x, int y) const { - if (!SkImageInfoValidConversion(requestedDstInfo, fInfo)) { +bool SkPixmap::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, int x, int y) +const { + if (!SkImageInfoValidConversion(dstInfo, fInfo)) { return false; } - if (nullptr == dstPixels || dstRB < requestedDstInfo.minRowBytes()) { + SkReadPixelsRec rec(dstInfo, dstPixels, dstRB, x, y); + if (!rec.trim(fInfo.width(), fInfo.height())) { return false; } - SkIRect srcR = SkIRect::MakeXYWH(x, y, requestedDstInfo.width(), requestedDstInfo.height()); - if (!srcR.intersect(0, 0, this->width(), this->height())) { - return false; - } - - // the intersect may have shrunk info's logical size - const SkImageInfo dstInfo = requestedDstInfo.makeWH(srcR.width(), srcR.height()); - - // if x or y are negative, then we have to adjust pixels - if (x > 0) { - x = 0; - } - if (y > 0) { - y = 0; - } - // here x,y are either 0 or negative - dstPixels = ((char*)dstPixels - y * dstRB - x * dstInfo.bytesPerPixel()); - - const SkImageInfo srcInfo = this->info().makeWH(dstInfo.width(), dstInfo.height()); - const void* srcPixels = this->addr(srcR.x(), srcR.y()); - return SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRB, + const void* srcPixels = this->addr(rec.fX, rec.fY); + const SkImageInfo srcInfo = fInfo.makeWH(rec.fInfo.width(), rec.fInfo.height()); + return SkPixelInfo::CopyPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, srcInfo, srcPixels, this->rowBytes(), this->ctable()); } |