diff options
author | Matt Sarett <msarett@google.com> | 2017-01-23 15:51:01 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-23 15:51:14 +0000 |
commit | 26ecfe0af8da1d17a079e17af85c5c576bfeca84 (patch) | |
tree | ffce62c50685254f0728a711f023b0d1a6792283 /src/core/SkPixmap.cpp | |
parent | bfe8dca7dfdd9cafbccba0a637f2fcd58c7a54fb (diff) |
Revert "Refactor trimming logic for read/writePixels()"
This reverts commit 977f64cbfad1ecd7fd4b1231c694c7e828fda1f0.
Reason for revert: Triggering nanobench asserts
Original change's description:
> 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>
>
TBR=msarett@google.com,brianosman@google.com,reed@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:6021
Change-Id: If9aacc6ce8b20e3dfe8a0f22ebca653f28356175
Reviewed-on: https://skia-review.googlesource.com/7379
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
Diffstat (limited to 'src/core/SkPixmap.cpp')
-rw-r--r-- | src/core/SkPixmap.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp index c0889cfd84..1e24b93a60 100644 --- a/src/core/SkPixmap.cpp +++ b/src/core/SkPixmap.cpp @@ -16,7 +16,6 @@ #include "SkNx.h" #include "SkPM4f.h" #include "SkPixmap.h" -#include "SkReadPixelsRec.h" #include "SkSurface.h" #include "SkUtils.h" @@ -84,20 +83,37 @@ bool SkPixmap::extractSubset(SkPixmap* result, const SkIRect& subset) const { return true; } -bool SkPixmap::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, int x, int y) -const { - if (!SkImageInfoValidConversion(dstInfo, fInfo)) { +bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels, size_t dstRB, + int x, int y) const { + if (!SkImageInfoValidConversion(requestedDstInfo, fInfo)) { return false; } - SkReadPixelsRec rec(dstInfo, dstPixels, dstRB, x, y); - if (!rec.trim(fInfo.width(), fInfo.height())) { + if (nullptr == dstPixels || dstRB < requestedDstInfo.minRowBytes()) { return false; } - 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, + 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, srcInfo, srcPixels, this->rowBytes(), this->ctable()); } |