diff options
author | Robert Phillips <robertphillips@google.com> | 2017-03-29 12:08:49 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-29 17:00:16 +0000 |
commit | 301431d7516a18e2b4232ccb70d2a79e8192c748 (patch) | |
tree | 5af992a5a1b311ca03c929e5097312cd9c48e334 | |
parent | e7d30484ea8a5677a9403ccd23a9c0961df62ccd (diff) |
Miscellaneous GrSurfaceProxy-related cleanup
This is pulled out of: https://skia-review.googlesource.com/c/10284/ (Remove GrSurface-derived classes from ops)
Change-Id: I083c0beefe4899b3517d0b0569bb25096809f410
Reviewed-on: https://skia-review.googlesource.com/10483
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
-rw-r--r-- | src/core/SkSpecialImage.cpp | 10 | ||||
-rw-r--r-- | src/core/SkSpecialSurface.cpp | 2 | ||||
-rw-r--r-- | src/gpu/GrXferProcessor.cpp | 2 | ||||
-rw-r--r-- | src/gpu/GrXferProcessor.h | 2 | ||||
-rw-r--r-- | src/gpu/effects/GrConfigConversionEffect.cpp | 2 | ||||
-rw-r--r-- | src/gpu/effects/GrCustomXfermode.cpp | 4 | ||||
-rw-r--r-- | tests/ClearTest.cpp | 9 | ||||
-rw-r--r-- | tests/PackedConfigsTextureTest.cpp | 5 | ||||
-rw-r--r-- | tests/SRGBMipMapTest.cpp | 24 | ||||
-rw-r--r-- | tests/SRGBReadWritePixelsTest.cpp | 62 |
10 files changed, 75 insertions, 47 deletions
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index 339341a8e8..fad5d1471c 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -17,6 +17,7 @@ #if SK_SUPPORT_GPU #include "GrContext.h" +#include "GrContextPriv.h" #include "GrResourceProvider.h" #include "GrSurfaceContext.h" #include "GrSurfaceProxyPriv.h" @@ -416,14 +417,13 @@ public: return false; } - // Reading back to an SkBitmap ends deferral - GrTexture* texture = fTextureProxy->instantiate(fContext->resourceProvider()); - if (!texture) { + sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeWrappedSurfaceContext( + fTextureProxy, nullptr); + if (!sContext) { return false; } - if (!texture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPixelConfig, - dst->getPixels(), dst->rowBytes())) { + if (!sContext->readPixels(info, dst->getPixels(), dst->rowBytes(), 0, 0)) { return false; } diff --git a/src/core/SkSpecialSurface.cpp b/src/core/SkSpecialSurface.cpp index 381e3d8eb1..1f396a7ac2 100644 --- a/src/core/SkSpecialSurface.cpp +++ b/src/core/SkSpecialSurface.cpp @@ -136,7 +136,7 @@ public: ~SkSpecialSurface_Gpu() override { } sk_sp<SkSpecialImage> onMakeImageSnapshot() override { - if (!fRenderTargetContext->asTexture()) { + if (!fRenderTargetContext->asTextureProxy()) { return nullptr; } sk_sp<SkSpecialImage> tmp(SkSpecialImage::MakeDeferredFromGpu( diff --git a/src/gpu/GrXferProcessor.cpp b/src/gpu/GrXferProcessor.cpp index 45bcc2d595..f2060289da 100644 --- a/src/gpu/GrXferProcessor.cpp +++ b/src/gpu/GrXferProcessor.cpp @@ -71,7 +71,7 @@ GrXferBarrierType GrXferProcessor::xferBarrierType(const GrRenderTarget* rt, SkASSERT(caps.textureBarrierSupport()); return kTexture_GrXferBarrierType; } - return this->onXferBarrier(rt, caps); + return this->onXferBarrier(caps); } #ifdef SK_DEBUG diff --git a/src/gpu/GrXferProcessor.h b/src/gpu/GrXferProcessor.h index 54630af750..2898d7f735 100644 --- a/src/gpu/GrXferProcessor.h +++ b/src/gpu/GrXferProcessor.h @@ -209,7 +209,7 @@ private: * that a kTexture type barrier is required is handled by the base class and need not be * considered by subclass overrides of this function. */ - virtual GrXferBarrierType onXferBarrier(const GrRenderTarget*, const GrCaps&) const { + virtual GrXferBarrierType onXferBarrier(const GrCaps&) const { return kNone_GrXferBarrierType; } diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp index 2c6589d6aa..790a47490c 100644 --- a/src/gpu/effects/GrConfigConversionEffect.cpp +++ b/src/gpu/effects/GrConfigConversionEffect.cpp @@ -220,7 +220,7 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context // from readTex to tempTex followed by a PM->UPM draw to readTex and finally read the data. // We then verify that two reads produced the same values. - if (!readRTC->asTexture()) { + if (!readRTC->asTextureProxy()) { continue; } GrPaint paint1; diff --git a/src/gpu/effects/GrCustomXfermode.cpp b/src/gpu/effects/GrCustomXfermode.cpp index 2e6d27cdfa..55b73e0fa3 100644 --- a/src/gpu/effects/GrCustomXfermode.cpp +++ b/src/gpu/effects/GrCustomXfermode.cpp @@ -100,7 +100,7 @@ public: private: void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override; - GrXferBarrierType onXferBarrier(const GrRenderTarget*, const GrCaps&) const override; + GrXferBarrierType onXferBarrier(const GrCaps&) const override; void onGetBlendInfo(BlendInfo*) const override; @@ -187,7 +187,7 @@ bool CustomXP::onIsEqual(const GrXferProcessor& other) const { return fMode == s.fMode && fHWBlendEquation == s.fHWBlendEquation; } -GrXferBarrierType CustomXP::onXferBarrier(const GrRenderTarget* rt, const GrCaps& caps) const { +GrXferBarrierType CustomXP::onXferBarrier(const GrCaps& caps) const { if (this->hasHWBlendEquation() && !caps.advancedCoherentBlendEquationSupport()) { return kBlend_GrXferBarrierType; } diff --git a/tests/ClearTest.cpp b/tests/ClearTest.cpp index d4b85872d8..843c4c371c 100644 --- a/tests/ClearTest.cpp +++ b/tests/ClearTest.cpp @@ -17,12 +17,17 @@ static bool check_rect(GrRenderTargetContext* rtc, const SkIRect& rect, uint32_t expectedValue, uint32_t* actualValue, int* failX, int* failY) { - GrRenderTarget* rt = rtc->accessRenderTarget(); int w = rect.width(); int h = rect.height(); std::unique_ptr<uint32_t[]> pixels(new uint32_t[w * h]); memset(pixels.get(), ~expectedValue, sizeof(uint32_t) * w * h); - rt->readPixels(rect.fLeft, rect.fTop, w, h, kRGBA_8888_GrPixelConfig, pixels.get()); + + SkImageInfo dstInfo = SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType); + + if (!rtc->readPixels(dstInfo, pixels.get(), 0, rect.fLeft, rect.fTop)) { + return false; + } + for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { uint32_t pixel = pixels.get()[y * w + x]; diff --git a/tests/PackedConfigsTextureTest.cpp b/tests/PackedConfigsTextureTest.cpp index 4b8e3cd6f0..7a51651e7f 100644 --- a/tests/PackedConfigsTextureTest.cpp +++ b/tests/PackedConfigsTextureTest.cpp @@ -99,7 +99,7 @@ template <typename T> void runTest(skiatest::Reporter* reporter, GrContext* context, T val1, T val2, int arraySize, GrPixelConfig config) { SkTDArray<T> controlPixelData; - // We will read back into an 8888 buffer since 565/4444 read backes aren't supported + // We will read back into an 8888 buffer since 565/4444 read backs aren't supported SkTDArray<GrColor> readBuffer; controlPixelData.setCount(arraySize); readBuffer.setCount(arraySize); @@ -115,8 +115,7 @@ void runTest(skiatest::Reporter* reporter, GrContext* context, desc.fWidth = DEV_W; desc.fHeight = DEV_H; desc.fConfig = config; - desc.fOrigin = 0 == origin ? - kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; + desc.fOrigin = 0 == origin ? kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; sk_sp<GrTexture> fpTexture(context->resourceProvider()->createTexture( desc, SkBudgeted::kNo, controlPixelData.begin(), 0)); SkASSERT(fpTexture); diff --git a/tests/SRGBMipMapTest.cpp b/tests/SRGBMipMapTest.cpp index 89a47c9d85..54c68aeb23 100644 --- a/tests/SRGBMipMapTest.cpp +++ b/tests/SRGBMipMapTest.cpp @@ -13,6 +13,7 @@ #include "GrRenderTargetContext.h" #include "GrResourceProvider.h" #include "SkCanvas.h" +#include "SkGr.h" #include "SkSurface.h" #include "gl/GrGLGpu.h" @@ -45,16 +46,19 @@ static bool check_value(U8CPU value, U8CPU expected, U8CPU error) { } } -void read_and_check_pixels(skiatest::Reporter* reporter, GrTexture* texture, U8CPU expected, +void read_and_check_pixels(skiatest::Reporter* reporter, GrSurfaceContext* context, + U8CPU expected, const SkImageInfo& dstInfo, U8CPU error, const char* subtestName) { - int w = texture->width(); - int h = texture->height(); + int w = dstInfo.width(); + int h = dstInfo.height(); SkAutoTMalloc<uint32_t> readData(w * h); memset(readData.get(), 0, sizeof(uint32_t) * w * h); - if (!texture->readPixels(0, 0, w, h, texture->config(), readData.get())) { + + if (!context->readPixels(dstInfo, readData.get(), 0, 0, 0)) { ERRORF(reporter, "Could not read pixels for %s.", subtestName); return; } + for (int j = 0; j < h; ++j) { for (int i = 0; i < w; ++i) { uint32_t read = readData[j * w + i]; @@ -112,6 +116,12 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SRGBMipMaps, reporter, ctxInfo) { const U8CPU expectedLinear = srgb60 / 2; const U8CPU error = 10; + const SkImageInfo iiSRGBA = SkImageInfo::Make(rtS, rtS, kRGBA_8888_SkColorType, + kPremul_SkAlphaType, + SkColorSpace::MakeSRGB()); + const SkImageInfo iiRGBA = SkImageInfo::Make(rtS, rtS, kRGBA_8888_SkColorType, + kPremul_SkAlphaType); + // Create our test texture GrSurfaceDesc desc; desc.fFlags = kNone_GrSurfaceFlags; @@ -142,7 +152,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SRGBMipMaps, reporter, ctxInfo) { // 1) Draw texture to S32 surface (should generate/use sRGB mips) paint.setGammaCorrect(true); s32RenderTargetContext->drawRect(noClip, GrPaint(paint), GrAA::kNo, SkMatrix::I(), rect); - read_and_check_pixels(reporter, s32RenderTargetContext->asTexture().get(), expectedSRGB, error, + read_and_check_pixels(reporter, s32RenderTargetContext.get(), expectedSRGB, iiSRGBA, error, "first render of sRGB"); // 2) Draw texture to L32 surface (should generate/use linear mips) @@ -161,14 +171,14 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SRGBMipMaps, reporter, ctxInfo) { GrGLGpu* glGpu = static_cast<GrGLGpu*>(context->getGpu()); if (glGpu->glCaps().srgbDecodeDisableSupport() && glGpu->glCaps().srgbDecodeDisableAffectsMipmaps()) { - read_and_check_pixels(reporter, l32RenderTargetContext->asTexture().get(), expectedLinear, + read_and_check_pixels(reporter, l32RenderTargetContext.get(), expectedLinear, iiRGBA, error, "re-render as linear"); } // 3) Go back to sRGB paint.setGammaCorrect(true); s32RenderTargetContext->drawRect(noClip, std::move(paint), GrAA::kNo, SkMatrix::I(), rect); - read_and_check_pixels(reporter, s32RenderTargetContext->asTexture().get(), expectedSRGB, error, + read_and_check_pixels(reporter, s32RenderTargetContext.get(), expectedSRGB, iiSRGBA, error, "re-render as sRGB"); } #endif diff --git a/tests/SRGBReadWritePixelsTest.cpp b/tests/SRGBReadWritePixelsTest.cpp index 5addc2e7fd..9729774cd0 100644 --- a/tests/SRGBReadWritePixelsTest.cpp +++ b/tests/SRGBReadWritePixelsTest.cpp @@ -9,8 +9,11 @@ #if SK_SUPPORT_GPU #include "GrCaps.h" #include "GrContext.h" +#include "GrContextPriv.h" #include "GrResourceProvider.h" +#include "GrSurfaceContext.h" #include "SkCanvas.h" +#include "SkGr.h" #include "SkSurface.h" // using anonymous namespace because these functions are used as template params. @@ -112,17 +115,20 @@ static bool check_srgb_to_linear_to_srgb_conversion(uint32_t input, uint32_t out typedef bool (*CheckFn) (uint32_t orig, uint32_t actual, float error); -void read_and_check_pixels(skiatest::Reporter* reporter, GrTexture* texture, uint32_t* origData, - GrPixelConfig readConfig, CheckFn checker, float error, +void read_and_check_pixels(skiatest::Reporter* reporter, GrSurfaceContext* context, + uint32_t* origData, + const SkImageInfo& dstInfo, CheckFn checker, float error, const char* subtestName) { - int w = texture->width(); - int h = texture->height(); + int w = dstInfo.width(); + int h = dstInfo.height(); SkAutoTMalloc<uint32_t> readData(w * h); memset(readData.get(), 0, sizeof(uint32_t) * w * h); - if (!texture->readPixels(0, 0, w, h, readConfig, readData.get())) { + + if (!context->readPixels(dstInfo, readData.get(), 0, 0, 0)) { ERRORF(reporter, "Could not read pixels for %s.", subtestName); return; } + for (int j = 0; j < h; ++j) { for (int i = 0; i < w; ++i) { uint32_t orig = origData[j * w + i]; @@ -156,6 +162,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, ctxInfo) { } } + const SkImageInfo iiSRGBA = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, + kPremul_SkAlphaType, + SkColorSpace::MakeSRGB()); + const SkImageInfo iiRGBA = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, + kPremul_SkAlphaType); GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fWidth = kW; @@ -163,25 +174,27 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, ctxInfo) { desc.fConfig = kSRGBA_8888_GrPixelConfig; if (context->caps()->isConfigRenderable(desc.fConfig, false) && context->caps()->isConfigTexturable(desc.fConfig)) { - sk_sp<GrTexture> tex(context->resourceProvider()->createTexture(desc, SkBudgeted::kNo)); - if (!tex) { - ERRORF(reporter, "Could not create SRGBA texture."); + + sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeDeferredSurfaceContext( + desc, SkBackingFit::kExact, + SkBudgeted::kNo); + if (!sContext) { + ERRORF(reporter, "Could not create SRGBA surface context."); return; } float error = context->caps()->shaderCaps()->floatPrecisionVaries() ? 1.2f : 0.5f; // Write srgba data and read as srgba and then as rgba - if (tex->writePixels(0, 0, kW, kH, kSRGBA_8888_GrPixelConfig, origData)) { + if (sContext->writePixels(iiSRGBA, origData, 0, 0, 0)) { // For the all-srgba case, we allow a small error only for devices that have // precision variation because the srgba data gets converted to linear and back in // the shader. - float smallError = context->caps()->shaderCaps()->floatPrecisionVaries() ? 1.f : - 0.0f; - read_and_check_pixels(reporter, tex.get(), origData, kSRGBA_8888_GrPixelConfig, + float smallError = context->caps()->shaderCaps()->floatPrecisionVaries() ? 1.f : 0.0f; + read_and_check_pixels(reporter, sContext.get(), origData, iiSRGBA, check_srgb_to_linear_to_srgb_conversion, smallError, "write/read srgba to srgba texture"); - read_and_check_pixels(reporter, tex.get(), origData, kRGBA_8888_GrPixelConfig, + read_and_check_pixels(reporter, sContext.get(), origData, iiRGBA, check_srgb_to_linear_conversion, error, "write srgba/read rgba with srgba texture"); } else { @@ -189,12 +202,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, ctxInfo) { } // Now verify that we can write linear data - if (tex->writePixels(0, 0, kW, kH, kRGBA_8888_GrPixelConfig, origData)) { + if (sContext->writePixels(iiRGBA, origData, 0, 0, 0)) { // We allow more error on GPUs with lower precision shader variables. - read_and_check_pixels(reporter, tex.get(), origData, kSRGBA_8888_GrPixelConfig, + read_and_check_pixels(reporter, sContext.get(), origData, iiSRGBA, check_linear_to_srgb_conversion, error, "write rgba/read srgba with srgba texture"); - read_and_check_pixels(reporter, tex.get(), origData, kRGBA_8888_GrPixelConfig, + read_and_check_pixels(reporter, sContext.get(), origData, iiRGBA, check_linear_to_srgb_to_linear_conversion, error, "write/read rgba with srgba texture"); } else { @@ -202,18 +215,19 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, ctxInfo) { } desc.fConfig = kRGBA_8888_GrPixelConfig; - tex.reset(context->resourceProvider()->createTexture(desc, SkBudgeted::kNo)); - if (!tex) { - ERRORF(reporter, "Could not create RGBA texture."); + sContext = context->contextPriv().makeDeferredSurfaceContext(desc, SkBackingFit::kExact, + SkBudgeted::kNo); + if (!sContext) { + ERRORF(reporter, "Could not create RGBA surface context."); return; } // Write srgba data to a rgba texture and read back as srgba and rgba - if (tex->writePixels(0, 0, kW, kH, kSRGBA_8888_GrPixelConfig, origData)) { - read_and_check_pixels(reporter, tex.get(), origData, kSRGBA_8888_GrPixelConfig, + if (sContext->writePixels(iiSRGBA, origData, 0, 0, 0)) { + read_and_check_pixels(reporter, sContext.get(), origData, iiSRGBA, check_srgb_to_linear_to_srgb_conversion, error, "write/read srgba to rgba texture"); - read_and_check_pixels(reporter, tex.get(), origData, kRGBA_8888_GrPixelConfig, + read_and_check_pixels(reporter, sContext.get(), origData, iiRGBA, check_srgb_to_linear_conversion, error, "write srgba/read rgba to rgba texture"); } else { @@ -221,8 +235,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, ctxInfo) { } // Write rgba data to a rgba texture and read back as srgba - if (tex->writePixels(0, 0, kW, kH, kRGBA_8888_GrPixelConfig, origData)) { - read_and_check_pixels(reporter, tex.get(), origData, kSRGBA_8888_GrPixelConfig, + if (sContext->writePixels(iiRGBA, origData, 0, 0, 0)) { + read_and_check_pixels(reporter, sContext.get(), origData, iiSRGBA, check_linear_to_srgb_conversion, 1.2f, "write rgba/read srgba to rgba texture"); } else { |