Simplify sk_gpu_test::MakeTextureProxyFromData.

Make it take GrImageInfo.

Change-Id: I9ec16e9b935fbe3e829b4669f715c17873a1793a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/249813
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2019-10-21 15:04:52 -04:00 committed by Skia Commit-Bot
parent c056e169ea
commit 4eda7108a2
10 changed files with 55 additions and 89 deletions

View File

@ -130,9 +130,8 @@ static sk_sp<SkImage> make_reference_image(GrContext* context,
auto origin = bottomLeftOrigin ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, GrRenderable::kNo, kImageSize,
kImageSize, bm.colorType(), bm.alphaType(),
origin, bm.getPixels(), bm.rowBytes());
auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, GrRenderable::kNo, origin,
bm.info(), bm.getPixels(), bm.rowBytes());
if (!proxy) {
return nullptr;
}

View File

@ -78,11 +78,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
for (auto dstPoint : kDstPoints) {
for (auto ii: kImageInfos) {
auto src = sk_gpu_test::MakeTextureProxyFromData(
context, sRenderable, kW, kH, ii.colorType(),
ii.alphaType(), sOrigin, srcPixels.get(), kRowBytes);
context, sRenderable, sOrigin, ii, srcPixels.get(),
kRowBytes);
auto dst = sk_gpu_test::MakeTextureProxyFromData(
context, dRenderable, kW, kH, ii.colorType(),
ii.alphaType(), dOrigin, dstPixels.get(), kRowBytes);
context, dRenderable, dOrigin, ii, dstPixels.get(),
kRowBytes);
// Should always work if the color type is RGBA, but may not work
// for BGRA

View File

@ -47,9 +47,10 @@ void runFPTest(skiatest::Reporter* reporter, GrContext* context, T min, T max, T
}
for (auto origin : {kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
auto fpProxy = sk_gpu_test::MakeTextureProxyFromData(context, GrRenderable::kYes, DEV_W,
DEV_H, colorType, kPremul_SkAlphaType,
origin, controlPixelData.begin(), 0);
auto fpProxy = sk_gpu_test::MakeTextureProxyFromData(
context, GrRenderable::kYes, origin,
{colorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H},
controlPixelData.begin(), 0);
// Floating point textures are NOT supported everywhere
if (!fpProxy) {
continue;

View File

@ -29,9 +29,10 @@ void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColo
fill_pixel_data(kWidth, kHeight, srcBuffer.get());
auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderable, kWidth, kHeight, ct,
kPremul_SkAlphaType,
kTopLeft_GrSurfaceOrigin, srcBuffer, 0);
auto grCT = SkColorTypeToGrColorType(ct);
auto proxy = sk_gpu_test::MakeTextureProxyFromData(
context, renderable, kTopLeft_GrSurfaceOrigin,
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
REPORTER_ASSERT(reporter, proxy);
if (proxy) {
auto sContext = context->priv().makeWrappedSurfaceContext(
@ -61,9 +62,9 @@ void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColo
2));
}
proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderable, kWidth, kHeight, ct,
kPremul_SkAlphaType, kBottomLeft_GrSurfaceOrigin,
srcBuffer, 0);
proxy = sk_gpu_test::MakeTextureProxyFromData(
context, renderable, kBottomLeft_GrSurfaceOrigin,
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
REPORTER_ASSERT(reporter, proxy);
if (proxy) {
auto sContext = context->priv().makeWrappedSurfaceContext(

View File

@ -113,13 +113,15 @@ static void run_test(skiatest::Reporter* reporter, GrContext* context, int array
SkImageInfo::Make(DEV_W, DEV_H, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, GrRenderable::kNo, DEV_W, DEV_H,
colorType, kPremul_SkAlphaType, origin,
controlPixelData.begin(), 0);
auto grColorType = SkColorTypeToGrColorType(colorType);
auto proxy = sk_gpu_test::MakeTextureProxyFromData(
context, GrRenderable::kNo, origin,
{grColorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H},
controlPixelData.begin(), 0);
SkASSERT(proxy);
auto sContext = context->priv().makeWrappedSurfaceContext(
std::move(proxy), SkColorTypeToGrColorType(colorType), kPremul_SkAlphaType);
auto sContext = context->priv().makeWrappedSurfaceContext(std::move(proxy), grColorType,
kPremul_SkAlphaType);
if (!sContext->readPixels(dstInfo, readBuffer.begin(), 0, {0, 0})) {
// We only require this to succeed if the format is renderable.

View File

@ -471,8 +471,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) {
for (auto origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
sk_sp<GrTextureProxy> proxy = sk_gpu_test::MakeTextureProxyFromData(
context, renderable, DEV_W, DEV_H, bmp.colorType(), bmp.alphaType(), origin,
bmp.getPixels(), bmp.rowBytes());
context, renderable, origin, bmp.info(), bmp.getPixels(), bmp.rowBytes());
auto sContext = context->priv().makeWrappedSurfaceContext(
std::move(proxy), SkColorTypeToGrColorType(bmp.colorType()),
kPremul_SkAlphaType);

View File

@ -187,8 +187,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
auto origin = GrRenderable::kYes == renderable ? kBottomLeft_GrSurfaceOrigin
: kTopLeft_GrSurfaceOrigin;
auto proxy = sk_gpu_test::MakeTextureProxyFromData(
context, renderable, X_SIZE, Y_SIZE, info.fColorType, info.fAlphaType, origin,
rgbaData, 0);
context, renderable, origin,
{info.fColorType, info.fAlphaType, nullptr, X_SIZE, Y_SIZE}, rgbaData, 0);
if (!proxy) {
continue;
}

View File

@ -106,8 +106,10 @@ static void test_copy_to_surface(skiatest::Reporter* reporter,
for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
auto origin = dstContext->asSurfaceProxy()->origin();
auto src = sk_gpu_test::MakeTextureProxyFromData(
context, renderable, dstContext->width(), dstContext->height(),
kRGBA_8888_SkColorType, kPremul_SkAlphaType, origin, pixels.get(), 0);
context, 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()));

View File

@ -18,67 +18,39 @@ namespace sk_gpu_test {
sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context,
GrRenderable renderable,
int width,
int height,
GrColorType colorType, SkAlphaType alphaType,
GrSurfaceOrigin origin,
const void* data, size_t rowBytes) {
const GrImageInfo& imageInfo,
const void* data,
size_t rowBytes) {
if (context->priv().abandoned()) {
return nullptr;
}
const GrCaps* caps = context->priv().caps();
const GrBackendFormat format = caps->getDefaultBackendFormat(colorType, renderable);
const GrBackendFormat format = caps->getDefaultBackendFormat(imageInfo.colorType(), renderable);
if (!format.isValid()) {
return nullptr;
}
sk_sp<GrTextureProxy> proxy;
if (kBottomLeft_GrSurfaceOrigin == origin) {
// We (soon will) only support using kBottomLeft with wrapped textures.
auto backendTex = context->createBackendTexture(
width, height, format, SkColors::kTransparent, GrMipMapped::kNo, renderable,
GrProtected::kNo);
if (!backendTex.isValid()) {
return nullptr;
}
// Adopt ownership so our caller doesn't have to worry about deleting the backend texture.
if (GrRenderable::kYes == renderable) {
proxy = context->priv().proxyProvider()->wrapRenderableBackendTexture(
backendTex, origin, 1, colorType, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
nullptr, nullptr);
} else {
proxy = context->priv().proxyProvider()->wrapBackendTexture(
backendTex, colorType, origin, kAdopt_GrWrapOwnership,
GrWrapCacheable::kNo, kRW_GrIOType);
}
if (!proxy) {
context->deleteBackendTexture(backendTex);
return nullptr;
}
} else {
GrSurfaceDesc desc;
desc.fConfig = GrColorTypeToPixelConfig(colorType);
desc.fWidth = width;
desc.fHeight = height;
proxy = context->priv().proxyProvider()->createProxy(format, desc, renderable, 1, origin,
GrMipMapped::kNo, SkBackingFit::kExact,
SkBudgeted::kYes, GrProtected::kNo);
if (!proxy) {
return nullptr;
}
GrSurfaceDesc desc;
desc.fConfig = GrColorTypeToPixelConfig(imageInfo.colorType());
desc.fWidth = imageInfo.width();
desc.fHeight = imageInfo.height();
proxy = context->priv().proxyProvider()->createProxy(format, desc, renderable, 1, origin,
GrMipMapped::kNo, SkBackingFit::kExact,
SkBudgeted::kYes, GrProtected::kNo);
if (!proxy) {
return nullptr;
}
auto sContext = context->priv().makeWrappedSurfaceContext(proxy, colorType, alphaType, nullptr);
auto sContext = context->priv().makeWrappedSurfaceContext(proxy, imageInfo.colorType(),
imageInfo.alphaType(),
imageInfo.refColorSpace(), nullptr);
if (!sContext) {
return nullptr;
}
if (!sContext->writePixels({colorType, alphaType, nullptr, width, height}, data, rowBytes,
{0, 0}, context)) {
if (!sContext->writePixels(imageInfo, data, rowBytes, {0, 0}, context)) {
return nullptr;
}
return proxy;

View File

@ -9,28 +9,18 @@
#define ProxyUtils_DEFINED
#include "include/private/GrTypesPriv.h"
#include "src/gpu/GrImageInfo.h"
#include "src/gpu/GrTextureProxy.h"
namespace sk_gpu_test {
/** Makes a texture proxy containing the passed in color data. */
sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext*, GrRenderable, int width, int height,
GrColorType, SkAlphaType, GrSurfaceOrigin,
const void* data, size_t rowBytes);
/** Version that takes SkColorType rather than GrColorType. */
inline sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, GrRenderable renderable,
int width, int height, SkColorType ct,
SkAlphaType alphaType, GrSurfaceOrigin origin,
const void* data, size_t rowBytes) {
GrColorType grCT = SkColorTypeToGrColorType(ct);
if (GrColorType::kUnknown == grCT) {
return nullptr;
}
return MakeTextureProxyFromData(context, renderable, width, height, grCT, alphaType, origin,
data, rowBytes);
}
sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext*,
GrRenderable,
GrSurfaceOrigin,
const GrImageInfo&,
const void* data,
size_t rowBytes);
} // namespace sk_gpu_test