diff options
author | Matt Sarett <msarett@google.com> | 2017-01-23 12:15:09 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-23 18:12:46 +0000 |
commit | 03dd6d5208a6e3d92190e7020300e4399178ae4b (patch) | |
tree | 8d062392a5072a50d10f032bbea8502aaa713581 /src/core/SkPixmap.cpp | |
parent | a6725fcb14f63734d7668bb0550cd9c128e841b0 (diff) |
Reland "Refactor trimming logic for read/writePixels()"
Original CL: https://skia-review.googlesource.com/c/7326/
(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.
CQ_INCLUDE_TRYBOTS=skia.primary:Perf-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug
BUG=skia:6021
Change-Id: I25a964e3c610c4e36d195a255e2150657baec649
Reviewed-on: https://skia-review.googlesource.com/7404
Reviewed-by: Matt Sarett <msarett@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()); } |