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>
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 7247ae3..fb93350 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -27,6 +27,7 @@
#include "SkImageInfoPriv.h"
#include "SkMipMap.h"
#include "SkPixelRef.h"
+#include "SkReadPixelsRec.h"
SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, sk_sp<GrTexture> tex,
sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted)
@@ -128,20 +129,26 @@
}
}
-bool SkImage_Gpu::onReadPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+bool SkImage_Gpu::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
int srcX, int srcY, CachingHint) const {
- if (!SkImageInfoValidConversion(info, this->onImageInfo())) {
+ if (!SkImageInfoValidConversion(dstInfo, this->onImageInfo())) {
return false;
}
- GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getContext()->caps());
+ SkReadPixelsRec rec(dstInfo, dstPixels, dstRB, srcX, srcY);
+ if (!rec.trim(this->width(), this->height())) {
+ return false;
+ }
+
+ GrPixelConfig config = SkImageInfo2GrPixelConfig(rec.fInfo, *fTexture->getContext()->caps());
uint32_t flags = 0;
- if (kUnpremul_SkAlphaType == info.alphaType() && kPremul_SkAlphaType == fAlphaType) {
+ if (kUnpremul_SkAlphaType == rec.fInfo.alphaType() && kPremul_SkAlphaType == fAlphaType) {
// let the GPU perform this transformation for us
flags = GrContext::kUnpremul_PixelOpsFlag;
}
- if (!fTexture->readPixels(fColorSpace.get(), srcX, srcY, info.width(), info.height(), config,
- info.colorSpace(), pixels, rowBytes, flags)) {
+ if (!fTexture->readPixels(fColorSpace.get(), rec.fX, rec.fY, rec.fInfo.width(),
+ rec.fInfo.height(), config, rec.fInfo.colorSpace(), rec.fPixels,
+ rec.fRowBytes, flags)) {
return false;
}
// do we have to manually fix-up the alpha channel?
@@ -152,8 +159,8 @@
//
// Should this be handled by Ganesh? todo:?
//
- if (kPremul_SkAlphaType == info.alphaType() && kUnpremul_SkAlphaType == fAlphaType) {
- apply_premul(info, pixels, rowBytes);
+ if (kPremul_SkAlphaType == rec.fInfo.alphaType() && kUnpremul_SkAlphaType == fAlphaType) {
+ apply_premul(rec.fInfo, rec.fPixels, rec.fRowBytes);
}
return true;
}