From a90aa2bfd430ca9bc321c3c7b3f1c727927606d1 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Mon, 10 Apr 2017 08:19:26 -0400 Subject: [PATCH] consolidate read/writePixels in GrSurfaceContext Change-Id: I118fcd49990597d4dfea92efd3f9d99e52fdbfab Reviewed-on: https://skia-review.googlesource.com/11481 Commit-Queue: Robert Phillips Reviewed-by: Brian Osman --- src/gpu/GrRenderTargetContext.cpp | 45 ++------------------------------------- src/gpu/GrRenderTargetContext.h | 4 ---- src/gpu/GrSurfaceContext.cpp | 44 +++++++++++++++++++++++++++++++++++++- src/gpu/GrSurfaceContext.h | 22 ++++++------------- src/gpu/GrTextureContext.cpp | 42 +----------------------------------- src/gpu/GrTextureContext.h | 4 ---- tools/gpu/GrTest.cpp | 2 +- 7 files changed, 53 insertions(+), 110 deletions(-) diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index b0a1b6d..3aefde0 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -42,9 +42,9 @@ #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this->drawingManager()->getContext()) #define ASSERT_SINGLE_OWNER \ - SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) + SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) #define ASSERT_SINGLE_OWNER_PRIV \ - SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->fSingleOwner);) + SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());) #define RETURN_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return; } #define RETURN_IF_ABANDONED_PRIV if (fRenderTargetContext->drawingManager()->wasAbandoned()) { return; } #define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; } @@ -141,47 +141,6 @@ bool GrRenderTargetContext::onCopy(GrSurfaceProxy* srcProxy, fRenderTargetProxy.get(), srcProxy, srcRect, dstPoint); } -// TODO: move this (and GrTextureContext::onReadPixels) to GrSurfaceContext? -bool GrRenderTargetContext::onReadPixels(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(fRenderTargetProxy.get(), - this->getColorSpace(), x, y, - dstInfo.width(), dstInfo.height(), config, - dstInfo.colorSpace(), - dstBuffer, dstRowBytes, flags); -} - -// TODO: move this (and GrTextureContext::onReadPixels) to GrSurfaceContext? -bool GrRenderTargetContext::onWritePixels(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(fRenderTargetProxy.get(), - this->getColorSpace(), x, y, - srcInfo.width(), srcInfo.height(), - config, srcInfo.colorSpace(), - srcBuffer, srcRowBytes, flags); -} - - void GrRenderTargetContext::drawText(const GrClip& clip, const SkPaint& skPaint, const SkMatrix& viewMatrix, const char text[], size_t byteLength, SkScalar x, SkScalar y, diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h index 8feec78..1d1f9ec 100644 --- a/src/gpu/GrRenderTargetContext.h +++ b/src/gpu/GrRenderTargetContext.h @@ -457,10 +457,6 @@ private: const GrClip&, GrPaint&&, GrAA, const SkMatrix&, const SkPath&, const GrStyle&); bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override; - bool onReadPixels(const SkImageInfo& dstInfo, void* dstBuffer, - size_t dstRowBytes, int x, int y, uint32_t flags) override; - bool onWritePixels(const SkImageInfo& srcInfo, const void* srcBuffer, - size_t srcRowBytes, int x, int y, uint32_t flags) override; // These perform processing specific to Gr[Mesh]DrawOp-derived ops before recording them into // the op list. They return the id of the opList to which the op was added, or 0, if it was diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp index a28c27a..6b6a942 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); } diff --git a/src/gpu/GrSurfaceContext.h b/src/gpu/GrSurfaceContext.h index 88badc1..bab753c 100644 --- a/src/gpu/GrSurfaceContext.h +++ b/src/gpu/GrSurfaceContext.h @@ -74,9 +74,7 @@ public: * unsupported pixel config. */ bool readPixels(const SkImageInfo& dstInfo, void* dstBuffer, size_t dstRowBytes, - int x, int y, uint32_t flags = 0) { - return this->onReadPixels(dstInfo, dstBuffer, dstRowBytes, x, y, flags); - } + int x, int y, uint32_t flags = 0); /** * Writes a rectangle of pixels [srcInfo, srcBuffer, srcRowbytes] into the @@ -91,9 +89,7 @@ public: * unsupported pixel config. */ bool writePixels(const SkImageInfo& srcInfo, const void* srcBuffer, size_t srcRowBytes, - int x, int y, uint32_t flags = 0) { - return this->onWritePixels(srcInfo, srcBuffer, srcRowBytes, x, y, flags); - } + int x, int y, uint32_t flags = 0); // TODO: this is virtual b.c. this object doesn't have a pointer to the wrapped GrSurfaceProxy? virtual GrSurfaceProxy* asSurfaceProxy() = 0; @@ -129,20 +125,14 @@ protected: sk_sp fColorSpace; GrAuditTrail* fAuditTrail; - // In debug builds we guard against improper thread handling - SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;) - private: - virtual bool onCopy(GrSurfaceProxy* src, - const SkIRect& srcRect, - const SkIPoint& dstPoint) = 0; - virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstBuffer, - size_t dstRowBytes, int x, int y, uint32_t flags) = 0; - virtual bool onWritePixels(const SkImageInfo& srcInfo, const void* srcBuffer, - size_t srcRowBytes, int x, int y, uint32_t flags) = 0; + virtual bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) = 0; GrDrawingManager* fDrawingManager; + // In debug builds we guard against improper thread handling + SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;) + typedef SkRefCnt INHERITED; }; diff --git a/src/gpu/GrTextureContext.cpp b/src/gpu/GrTextureContext.cpp index ca6f7a2..76b7588 100644 --- a/src/gpu/GrTextureContext.cpp +++ b/src/gpu/GrTextureContext.cpp @@ -15,7 +15,7 @@ #include "../private/GrAuditTrail.h" #define ASSERT_SINGLE_OWNER \ - SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) + SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) #define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; } GrTextureContext::GrTextureContext(GrContext* context, @@ -98,43 +98,3 @@ bool GrTextureContext::onCopy(GrSurfaceProxy* srcProxy, return result; } -// TODO: move this (and GrRenderTargetContext::onReadPixels) to GrSurfaceContext? -bool GrTextureContext::onReadPixels(const SkImageInfo& dstInfo, void* dstBuffer, - size_t dstRowBytes, int x, int y, uint32_t flags) { - // TODO: teach GrTexture 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(fTextureProxy.get(), this->getColorSpace(), - x, y, dstInfo.width(), dstInfo.height(), - config, - dstInfo.colorSpace(), dstBuffer, dstRowBytes, - flags); -} - -// TODO: move this (and GrRenderTargetContext::onReadPixels) to GrSurfaceContext? -bool GrTextureContext::onWritePixels(const SkImageInfo& srcInfo, const void* srcBuffer, - size_t srcRowBytes, int x, int y, - uint32_t flags) { - // TODO: teach GrTexture 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(fTextureProxy.get(), this->getColorSpace(), - x, y, srcInfo.width(), srcInfo.height(), - config, - srcInfo.colorSpace(), srcBuffer, srcRowBytes, - flags); -} diff --git a/src/gpu/GrTextureContext.h b/src/gpu/GrTextureContext.h index d5e1eb9..995ebf5 100644 --- a/src/gpu/GrTextureContext.h +++ b/src/gpu/GrTextureContext.h @@ -47,10 +47,6 @@ private: friend class GrDrawingManager; // for ctor bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override; - bool onReadPixels(const SkImageInfo& dstInfo, void* dstBuffer, - size_t dstRowBytes, int x, int y, uint32_t flags) override; - bool onWritePixels(const SkImageInfo& srcInfo, const void* srcBuffer, - size_t srcRowBytes, int x, int y, uint32_t flags) override; GrTextureOpList* getOpList(); diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index 56d47c5..30f7316 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -226,7 +226,7 @@ int GrResourceCache::countUniqueKeysWithTag(const char* tag) const { /////////////////////////////////////////////////////////////////////////////// #define ASSERT_SINGLE_OWNER \ - SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->fSingleOwner);) + SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());) uint32_t GrRenderTargetContextPriv::testingOnly_addLegacyMeshDrawOp( GrPaint&& paint, -- 2.7.4