diff options
author | Robert Phillips <robertphillips@google.com> | 2017-04-10 08:19:26 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-10 12:56:33 +0000 |
commit | a90aa2bfd430ca9bc321c3c7b3f1c727927606d1 (patch) | |
tree | 48176ea4a4fb3d529760e60ca9e9ca3978c5cf39 /src/gpu/GrSurfaceContext.cpp | |
parent | 768f52ff85662e6627438987e3277f3926eb6577 (diff) |
consolidate read/writePixels in GrSurfaceContext
Change-Id: I118fcd49990597d4dfea92efd3f9d99e52fdbfab
Reviewed-on: https://skia-review.googlesource.com/11481
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/gpu/GrSurfaceContext.cpp')
-rw-r--r-- | src/gpu/GrSurfaceContext.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp index a28c27a649..6b6a942720 100644 --- a/src/gpu/GrSurfaceContext.cpp +++ b/src/gpu/GrSurfaceContext.cpp @@ -6,7 +6,10 @@ */ #include "GrSurfaceContext.h" + +#include "GrContextPriv.h" #include "SkColorSpace_Base.h" +#include "SkGr.h" #include "../private/GrAuditTrail.h" @@ -23,8 +26,47 @@ GrSurfaceContext::GrSurfaceContext(GrContext* context, : fContext(context) , fColorSpace(std::move(colorSpace)) , fAuditTrail(auditTrail) + , fDrawingManager(drawingMgr) #ifdef SK_DEBUG , fSingleOwner(singleOwner) #endif - , fDrawingManager(drawingMgr) { +{ +} + +bool GrSurfaceContext::readPixels(const SkImageInfo& dstInfo, void* dstBuffer, + size_t dstRowBytes, int x, int y, uint32_t flags) { + // TODO: teach GrRenderTarget to take ImageInfo directly to specify the src pixels + GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo, *fContext->caps()); + if (kUnknown_GrPixelConfig == config) { + return false; + } + + // TODO: this seems to duplicate code in SkImage_Gpu::onReadPixels + if (kUnpremul_SkAlphaType == dstInfo.alphaType()) { + flags |= GrContextPriv::kUnpremul_PixelOpsFlag; + } + + return fContext->contextPriv().readSurfacePixels(this->asSurfaceProxy(), + this->getColorSpace(), x, y, + dstInfo.width(), dstInfo.height(), config, + dstInfo.colorSpace(), + dstBuffer, dstRowBytes, flags); +} + +bool GrSurfaceContext::writePixels(const SkImageInfo& srcInfo, const void* srcBuffer, + size_t srcRowBytes, int x, int y, uint32_t flags) { + // TODO: teach GrRenderTarget to take ImageInfo directly to specify the src pixels + GrPixelConfig config = SkImageInfo2GrPixelConfig(srcInfo, *fContext->caps()); + if (kUnknown_GrPixelConfig == config) { + return false; + } + if (kUnpremul_SkAlphaType == srcInfo.alphaType()) { + flags |= GrContextPriv::kUnpremul_PixelOpsFlag; + } + + return fContext->contextPriv().writeSurfacePixels(this->asSurfaceProxy(), + this->getColorSpace(), x, y, + srcInfo.width(), srcInfo.height(), + config, srcInfo.colorSpace(), + srcBuffer, srcRowBytes, flags); } |