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>
This commit is contained in:
Robert Phillips 2017-03-29 12:08:49 -04:00 committed by Skia Commit-Bot
parent e7d30484ea
commit 301431d751
10 changed files with 75 additions and 47 deletions

View File

@ -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;
}

View File

@ -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(

View File

@ -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

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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];

View File

@ -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);

View File

@ -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

View File

@ -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 {