sk_gpu_test::MakeTextureProxyFromData -> MakeTextureProxyViewFromData

Change-Id: Ie55a147566ef68a64e3b03d8cab701e54dbf1f0d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309780
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Brian Salomon 2020-08-12 14:06:50 -04:00 committed by Skia Commit-Bot
parent cab588677b
commit 652124c372
10 changed files with 50 additions and 76 deletions

View File

@ -132,16 +132,12 @@ static sk_sp<SkImage> make_reference_image(GrDirectContext* context,
auto origin = bottomLeftOrigin ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
// TODO: make MakeTextureProxyFromData return a GrSurfaceProxyView
auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, GrRenderable::kNo, origin,
bm.info(), bm.getPixels(), bm.rowBytes());
if (!proxy) {
auto view = sk_gpu_test::MakeTextureProxyViewFromData(context, GrRenderable::kNo, origin,
bm.info(), bm.getPixels(), bm.rowBytes());
if (!view) {
return nullptr;
}
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
GrColorType::kRGBA_8888);
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, std::move(view),
ii.colorType(), kOpaque_SkAlphaType, nullptr);
}

View File

@ -78,17 +78,17 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
for (const SkIRect& srcRect : kSrcRects) {
for (const SkIPoint& dstPoint : kDstPoints) {
for (const SkImageInfo& ii: kImageInfos) {
auto src = sk_gpu_test::MakeTextureProxyFromData(
auto srcView = sk_gpu_test::MakeTextureProxyViewFromData(
dContext, sRenderable, sOrigin, ii, srcPixels.get(),
kRowBytes);
auto dst = sk_gpu_test::MakeTextureProxyFromData(
auto dstView = sk_gpu_test::MakeTextureProxyViewFromData(
dContext, dRenderable, dOrigin, ii, dstPixels.get(),
kRowBytes);
// Should always work if the color type is RGBA, but may not work
// for BGRA
if (ii.colorType() == kRGBA_8888_SkColorType) {
if (!src || !dst) {
if (!srcView || !dstView) {
ERRORF(reporter,
"Could not create surfaces for copy surface test.");
continue;
@ -98,7 +98,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
kBGRA_8888_SkColorType, GrRenderable::kNo).isValid()) {
continue;
}
if (!src || !dst) {
if (!srcView || !dstView) {
ERRORF(reporter,
"Could not create surfaces for copy surface test.");
continue;
@ -106,9 +106,6 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
}
GrColorType grColorType = SkColorTypeToGrColorType(ii.colorType());
GrSwizzle dstSwizzle = dContext->priv().caps()->getReadSwizzle(
dst->backendFormat(), grColorType);
GrSurfaceProxyView dstView(std::move(dst), dOrigin, dstSwizzle);
auto dstContext = GrSurfaceContext::Make(dContext,
std::move(dstView),
grColorType,
@ -116,14 +113,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
bool result = false;
if (sOrigin == dOrigin) {
result = dstContext->testCopy(src.get(), srcRect, dstPoint);
result = dstContext->testCopy(srcView.proxy(),
srcRect,
dstPoint);
} else if (dRenderable == GrRenderable::kYes) {
SkASSERT(dstContext->asRenderTargetContext());
GrSwizzle srcSwizzle = dContext->priv().caps()->getReadSwizzle(
src->backendFormat(), grColorType);
GrSurfaceProxyView view(std::move(src), sOrigin, srcSwizzle);
result = dstContext->asRenderTargetContext()->blitTexture(
std::move(view), srcRect, dstPoint);
std::move(srcView), srcRect, dstPoint);
}
bool expectedResult = true;

View File

@ -49,19 +49,16 @@ void runFPTest(skiatest::Reporter* reporter, GrDirectContext* dContext,
}
for (auto origin : {kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
auto fpProxy = sk_gpu_test::MakeTextureProxyFromData(
auto fpView = sk_gpu_test::MakeTextureProxyViewFromData(
dContext, GrRenderable::kYes, origin,
{colorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H},
controlPixelData.begin(), 0);
{colorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H}, controlPixelData.begin(),
0);
// Floating point textures are NOT supported everywhere
if (!fpProxy) {
if (!fpView) {
continue;
}
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(fpProxy->backendFormat(),
colorType);
GrSurfaceProxyView view(std::move(fpProxy), origin, swizzle);
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), colorType,
auto sContext = GrSurfaceContext::Make(dContext, std::move(fpView), colorType,
kPremul_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, sContext);
@ -70,7 +67,7 @@ void runFPTest(skiatest::Reporter* reporter, GrDirectContext* dContext,
readBuffer.begin(), 0, {0, 0});
REPORTER_ASSERT(reporter, result);
REPORTER_ASSERT(reporter,
0 == memcmp(readBuffer.begin(), controlPixelData.begin(), readBuffer.bytes()));
!memcmp(readBuffer.begin(), controlPixelData.begin(), readBuffer.bytes()));
}
}

View File

@ -32,13 +32,11 @@ void basic_texture_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
FillPixelData(kWidth, kHeight, srcBuffer.get());
auto grCT = SkColorTypeToGrColorType(ct);
auto proxy = sk_gpu_test::MakeTextureProxyFromData(
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
dContext, renderable, kTopLeft_GrSurfaceOrigin,
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
REPORTER_ASSERT(reporter, proxy);
if (proxy) {
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), grCT);
GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
REPORTER_ASSERT(reporter, view);
if (view) {
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), grCT, kPremul_SkAlphaType,
nullptr);
@ -61,13 +59,11 @@ void basic_texture_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
REPORTER_ASSERT(reporter, DoesFullBufferContainCorrectColor(srcBuffer, dstBuffer, 10, 2));
}
proxy = sk_gpu_test::MakeTextureProxyFromData(
view = sk_gpu_test::MakeTextureProxyViewFromData(
dContext, renderable, kBottomLeft_GrSurfaceOrigin,
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
REPORTER_ASSERT(reporter, proxy);
if (proxy) {
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), grCT);
GrSurfaceProxyView view(proxy, kBottomLeft_GrSurfaceOrigin, swizzle);
REPORTER_ASSERT(reporter, view);
if (view) {
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), grCT, kPremul_SkAlphaType,
nullptr);
@ -88,7 +84,6 @@ void basic_texture_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
REPORTER_ASSERT(reporter, result);
REPORTER_ASSERT(reporter, DoesFullBufferContainCorrectColor(srcBuffer, dstBuffer, 4, 5));
}
}

View File

@ -115,16 +115,12 @@ static void run_test(skiatest::Reporter* reporter, GrDirectContext* dContext, in
for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
auto grColorType = SkColorTypeToGrColorType(colorType);
auto proxy = sk_gpu_test::MakeTextureProxyFromData(
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
dContext, GrRenderable::kNo, origin,
{grColorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H},
controlPixelData.begin(), 0);
SkASSERT(proxy);
{grColorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H}, controlPixelData.begin(),
0);
SkASSERT(view);
GrSwizzle readSwizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
grColorType);
GrSurfaceProxyView view(std::move(proxy), origin, readSwizzle);
GrSurfaceContext sContext(dContext, std::move(view), grColorType, kPremul_SkAlphaType,
nullptr);

View File

@ -431,12 +431,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) {
// On the GPU we will also try reading back from a non-renderable texture.
for (auto origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
sk_sp<GrTextureProxy> proxy = sk_gpu_test::MakeTextureProxyFromData(
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
dContext, renderable, origin, bmp.info(), bmp.getPixels(), bmp.rowBytes());
GrColorType grColorType = SkColorTypeToGrColorType(bmp.colorType());
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
grColorType);
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
auto sContext = GrSurfaceContext::Make(dContext, std::move(view),
grColorType, kPremul_SkAlphaType, nullptr);
auto info = SkImageInfo::Make(DEV_W, DEV_H, kN32_SkColorType, kPremul_SkAlphaType);

View File

@ -186,16 +186,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
auto origin = GrRenderable::kYes == renderable ? kBottomLeft_GrSurfaceOrigin
: kTopLeft_GrSurfaceOrigin;
auto proxy = sk_gpu_test::MakeTextureProxyFromData(
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
dContext, renderable, origin,
{info.fColorType, info.fAlphaType, nullptr, X_SIZE, Y_SIZE}, rgbaData, 0);
if (!proxy) {
if (!view) {
continue;
}
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
info.fColorType);
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), info.fColorType,
kPremul_SkAlphaType, nullptr);

View File

@ -102,14 +102,14 @@ static void test_copy_to_surface(skiatest::Reporter* reporter,
for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
auto origin = dstContext->origin();
auto src = sk_gpu_test::MakeTextureProxyFromData(
auto srcView = sk_gpu_test::MakeTextureProxyViewFromData(
dContext, renderable, origin,
{GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr, dstContext->width(),
dstContext->height()},
pixels.get(), 0);
// If this assert ever fails we can add a fallback to do copy as draw, but until then we can
// be more restrictive.
SkAssertResult(dstContext->testCopy(src.get()));
SkAssertResult(dstContext->testCopy(srcView.proxy()));
TestReadPixels(reporter, dContext, dstContext, pixels.get(), testName);
}
}

View File

@ -21,21 +21,21 @@
namespace sk_gpu_test {
sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrDirectContext* dContext,
GrRenderable renderable,
GrSurfaceOrigin origin,
const GrImageInfo& imageInfo,
const void* data,
size_t rowBytes) {
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext* dContext,
GrRenderable renderable,
GrSurfaceOrigin origin,
const GrImageInfo& imageInfo,
const void* data,
size_t rowBytes) {
if (dContext->abandoned()) {
return nullptr;
return {};
}
const GrCaps* caps = dContext->priv().caps();
const GrBackendFormat format = caps->getDefaultBackendFormat(imageInfo.colorType(), renderable);
if (!format.isValid()) {
return nullptr;
return {};
}
GrSwizzle swizzle = caps->getReadSwizzle(format, imageInfo.colorType());
@ -45,18 +45,18 @@ sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrDirectContext* dContext,
SkBackingFit::kExact, SkBudgeted::kYes,
GrProtected::kNo);
if (!proxy) {
return nullptr;
return {};
}
GrSurfaceProxyView view(proxy, origin, swizzle);
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), imageInfo.colorType(),
imageInfo.alphaType(), imageInfo.refColorSpace());
if (!sContext) {
return nullptr;
return {};
}
if (!sContext->writePixels(dContext, imageInfo, data, rowBytes, {0, 0})) {
return nullptr;
return {};
}
return proxy;
return sContext->readSurfaceView();
}
GrProgramInfo* CreateProgramInfo(const GrCaps* caps,

View File

@ -19,12 +19,12 @@ class GrProgramInfo;
namespace sk_gpu_test {
/** Makes a texture proxy containing the passed in color data. */
sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrDirectContext*,
GrRenderable,
GrSurfaceOrigin,
const GrImageInfo&,
const void* data,
size_t rowBytes);
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext*,
GrRenderable,
GrSurfaceOrigin,
const GrImageInfo&,
const void* data,
size_t rowBytes);
GrProgramInfo* CreateProgramInfo(const GrCaps*,
SkArenaAlloc*,