Reland "Revert "Use ManagedBackendTexture in place of TestUtils backend texture helpers.""

This reverts commit 21f8b51099.

Reason for revert: D3D traced resource assert from unit test

Original change's description:
> Revert "Revert "Use ManagedBackendTexture in place of TestUtils backend texture helpers.""
>
> This reverts commit f625e4ce45.
>
> Change-Id: Id73c53ec7ab8d4a5951712dc150d86e6349addbf
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325658
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>

TBR=egdaniel@google.com,bsalomon@google.com

# Not skipping CQ checks because this is a reland.

Change-Id: I407f1d522d5c4f28d070cc2ce87af7faffca11fd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325860
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2020-10-12 21:30:00 +00:00 committed by Skia Commit-Bot
parent 5d08a27530
commit 4efaf5e9fe
25 changed files with 699 additions and 672 deletions

View File

@ -1482,18 +1482,22 @@ sk_sp<SkSurface> GPUSink::createDstSurface(GrDirectContext* context, SkISize siz
break; break;
case SkCommandLineConfigGpu::SurfType::kBackendTexture: case SkCommandLineConfigGpu::SurfType::kBackendTexture:
surface = sk_gpu_test::MakeBackendTextureSurface(context, surface = sk_gpu_test::MakeBackendTextureSurface(context,
info, info.dimensions(),
kTopLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin,
fSampleCount, fSampleCount,
info.colorType(),
info.refColorSpace(),
GrMipmapped::kNo, GrMipmapped::kNo,
GrProtected::kNo, GrProtected::kNo,
&props); &props);
break; break;
case SkCommandLineConfigGpu::SurfType::kBackendRenderTarget: case SkCommandLineConfigGpu::SurfType::kBackendRenderTarget:
surface = sk_gpu_test::MakeBackendRenderTargetSurface(context, surface = sk_gpu_test::MakeBackendRenderTargetSurface(context,
info, info.dimensions(),
kBottomLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin,
fSampleCount, fSampleCount,
info.colorType(),
info.refColorSpace(),
GrProtected::kNo, GrProtected::kNo,
&props); &props);
break; break;

View File

@ -44,7 +44,6 @@
#include "tests/TestUtils.h" #include "tests/TestUtils.h"
#include "tools/gpu/BackendSurfaceFactory.h" #include "tools/gpu/BackendSurfaceFactory.h"
#include "tools/gpu/GrContextFactory.h" #include "tools/gpu/GrContextFactory.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include <initializer_list> #include <initializer_list>
#include <memory> #include <memory>
@ -788,14 +787,10 @@ enum class DDLStage { kMakeImage, kDrawImage, kDetach, kDrawDDL };
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) {
auto dContext = ctxInfo.directContext(); auto dContext = ctxInfo.directContext();
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext, GrBackendTexture backendTex;
kSize, CreateBackendTexture(dContext, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
kSize, SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
kRGBA_8888_SkColorType, if (!backendTex.isValid()) {
GrMipmapped::kNo,
GrRenderable::kNo,
GrProtected::kNo);
if (!mbet) {
return; return;
} }
@ -803,6 +798,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) {
sk_sp<SkSurface> s = params.make(dContext); sk_sp<SkSurface> s = params.make(dContext);
if (!s) { if (!s) {
dContext->deleteBackendTexture(backendTex);
return; return;
} }
@ -816,21 +812,20 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) {
auto rContext = canvas->recordingContext(); auto rContext = canvas->recordingContext();
if (!rContext) { if (!rContext) {
s = nullptr;
dContext->deleteBackendTexture(backendTex);
return; return;
} }
// Wrapped Backend Textures are not supported in DDL // Wrapped Backend Textures are not supported in DDL
TextureReleaseChecker releaseChecker; TextureReleaseChecker releaseChecker;
sk_sp<SkImage> image = SkImage::MakeFromTexture( sk_sp<SkImage> image =
rContext, SkImage::MakeFromTexture(rContext, backendTex, kTopLeft_GrSurfaceOrigin,
mbet->texture(), kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr,
kTopLeft_GrSurfaceOrigin, TextureReleaseChecker::Release, &releaseChecker);
kRGBA_8888_SkColorType,
kPremul_SkAlphaType,
nullptr,
sk_gpu_test::ManagedBackendTexture::ReleaseProc,
mbet->releaseContext(TextureReleaseChecker::Release, &releaseChecker));
REPORTER_ASSERT(reporter, !image); REPORTER_ASSERT(reporter, !image);
dContext->deleteBackendTexture(backendTex);
} }
static sk_sp<SkPromiseImageTexture> dummy_fulfill_proc(void*) { static sk_sp<SkPromiseImageTexture> dummy_fulfill_proc(void*) {
@ -994,14 +989,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSkSurfaceFlush, reporter, ctxInfo) {
SkSurfaceCharacterization characterization; SkSurfaceCharacterization characterization;
SkAssertResult(s->characterize(&characterization)); SkAssertResult(s->characterize(&characterization));
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(context, ii); GrBackendTexture backendTexture;
if (!mbet) {
ERRORF(reporter, "Could not make texture."); if (!CreateBackendTexture(context, &backendTexture, ii, SkColors::kCyan, GrMipmapped::kNo,
GrRenderable::kNo)) {
REPORTER_ASSERT(reporter, false);
return; return;
} }
FulfillInfo fulfillInfo; FulfillInfo fulfillInfo;
fulfillInfo.fTex = SkPromiseImageTexture::Make(mbet->texture()); fulfillInfo.fTex = SkPromiseImageTexture::Make(backendTexture);
sk_sp<SkDeferredDisplayList> ddl; sk_sp<SkDeferredDisplayList> ddl;
@ -1053,6 +1050,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSkSurfaceFlush, reporter, ctxInfo) {
REPORTER_ASSERT(reporter, fulfillInfo.fTex->unique()); REPORTER_ASSERT(reporter, fulfillInfo.fTex->unique());
fulfillInfo.fTex.reset(); fulfillInfo.fTex.reset();
DeleteBackendTexture(context, backendTexture);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -17,20 +17,22 @@
#include "tests/Test.h" #include "tests/Test.h"
#include "tests/TestUtils.h" #include "tests/TestUtils.h"
#include "tools/gpu/GrContextFactory.h" #include "tools/gpu/GrContextFactory.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include "tools/gpu/gl/GLTestContext.h" #include "tools/gpu/gl/GLTestContext.h"
#ifdef SK_GL #ifdef SK_GL
using sk_gpu_test::GLTestContext; using sk_gpu_test::GLTestContext;
static void cleanup(GLTestContext* glctx0, static void cleanup(GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx1,
GrGLuint texID0, sk_sp<GrDirectContext> dContext, GrBackendTexture* backendTex1,
GLTestContext* glctx1,
sk_sp<GrDirectContext> dContext,
GrEGLImage image1) { GrEGLImage image1) {
if (glctx1) { if (glctx1) {
glctx1->makeCurrent(); glctx1->makeCurrent();
if (dContext) {
if (backendTex1 && backendTex1->isValid()) {
dContext->deleteBackendTexture(*backendTex1);
}
}
if (GR_EGL_NO_IMAGE != image1) { if (GR_EGL_NO_IMAGE != image1) {
glctx1->destroyEGLImage(image1); glctx1->destroyEGLImage(image1);
} }
@ -62,18 +64,19 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
return; return;
} }
sk_sp<GrDirectContext> context1 = GrDirectContext::MakeGL(sk_ref_sp(glCtx1->gl())); sk_sp<GrDirectContext> context1 = GrDirectContext::MakeGL(sk_ref_sp(glCtx1->gl()));
GrBackendTexture backendTexture1;
GrEGLImage image = GR_EGL_NO_IMAGE; GrEGLImage image = GR_EGL_NO_IMAGE;
GrGLTextureInfo externalTexture; GrGLTextureInfo externalTexture;
externalTexture.fID = 0; externalTexture.fID = 0;
if (!context1) { if (!context1) {
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return; return;
} }
if (!glCtx1->gl()->hasExtension("EGL_KHR_image") || if (!glCtx1->gl()->hasExtension("EGL_KHR_image") ||
!glCtx1->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) { !glCtx1->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) {
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return; return;
} }
@ -83,25 +86,25 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
context1->flushAndSubmit(); context1->flushAndSubmit();
static const int kSize = 100; static const int kSize = 100;
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( CreateBackendTexture(context1.get(), &backendTexture1, kSize, kSize, kRGBA_8888_SkColorType,
context1.get(), kSize, kSize, kRGBA_8888_SkColorType, GrMipmapped::kNo, SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo,
GrRenderable::kNo, GrProtected::kNo); GrProtected::kNo);
if (!mbet) { if (!backendTexture1.isValid()) {
ERRORF(reporter, "Error creating texture for EGL Image"); ERRORF(reporter, "Error creating texture for EGL Image");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return; return;
} }
GrGLTextureInfo texInfo; GrGLTextureInfo texInfo;
if (!mbet->texture().getGLTextureInfo(&texInfo)) { if (!backendTexture1.getGLTextureInfo(&texInfo)) {
ERRORF(reporter, "Failed to get GrGLTextureInfo"); ERRORF(reporter, "Failed to get GrGLTextureInfo");
return; return;
} }
if (GR_GL_TEXTURE_2D != texInfo.fTarget) { if (GR_GL_TEXTURE_2D != texInfo.fTarget) {
ERRORF(reporter, "Expected backend texture to be 2D"); ERRORF(reporter, "Expected backend texture to be 2D");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return; return;
} }
@ -109,7 +112,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
image = glCtx1->texture2DToEGLImage(texInfo.fID); image = glCtx1->texture2DToEGLImage(texInfo.fID);
if (GR_EGL_NO_IMAGE == image) { if (GR_EGL_NO_IMAGE == image) {
ERRORF(reporter, "Error creating EGL Image from texture"); ERRORF(reporter, "Error creating EGL Image from texture");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return; return;
} }
@ -144,7 +147,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
externalTexture.fFormat = GR_GL_RGBA8; externalTexture.fFormat = GR_GL_RGBA8;
if (0 == externalTexture.fID) { if (0 == externalTexture.fID) {
ERRORF(reporter, "Error converting EGL Image back to texture"); ERRORF(reporter, "Error converting EGL Image back to texture");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return; return;
} }
@ -160,7 +163,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType); backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
if (!texProxy) { if (!texProxy) {
ERRORF(reporter, "Error wrapping external texture in GrTextureProxy."); ERRORF(reporter, "Error wrapping external texture in GrTextureProxy.");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return; return;
} }
GrSwizzle swizzle = GrSwizzle swizzle =
@ -171,7 +174,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
if (!surfaceContext) { if (!surfaceContext) {
ERRORF(reporter, "Error wrapping external texture in GrSurfaceContext."); ERRORF(reporter, "Error wrapping external texture in GrSurfaceContext.");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return; return;
} }
@ -203,7 +206,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
TestCopyFromSurface(reporter, context0, surfaceContext->asSurfaceProxy(), TestCopyFromSurface(reporter, context0, surfaceContext->asSurfaceProxy(),
surfaceContext->origin(), colorType, pixels.get(), "EGLImageTest-copy"); surfaceContext->origin(), colorType, pixels.get(), "EGLImageTest-copy");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
} }
#endif // SK_GL #endif // SK_GL

View File

@ -28,9 +28,6 @@
#include "src/image/SkSurface_Gpu.h" #include "src/image/SkSurface_Gpu.h"
#include "tests/Test.h" #include "tests/Test.h"
#include "tests/TestUtils.h" #include "tests/TestUtils.h"
#include "tools/gpu/BackendSurfaceFactory.h"
#include "tools/gpu/BackendTextureImageFactory.h"
#include "tools/gpu/ManagedBackendTexture.h"
static constexpr int kSize = 8; static constexpr int kSize = 8;
@ -47,50 +44,42 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) {
// createBackendTexture currently doesn't support uploading data to mip maps // createBackendTexture currently doesn't support uploading data to mip maps
// so we don't send any. However, we pretend there is data for the checks below which is // so we don't send any. However, we pretend there is data for the checks below which is
// fine since we are never actually using these textures for any work on the gpu. // fine since we are never actually using these textures for any work on the gpu.
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithData(dContext, GrBackendTexture backendTex;
kSize, CreateBackendTexture(dContext, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
kSize, SkColors::kTransparent, mipMapped, renderable);
kRGBA_8888_SkColorType,
SkColors::kTransparent,
mipMapped,
renderable,
GrProtected::kNo);
sk_sp<GrTextureProxy> proxy; sk_sp<GrTextureProxy> proxy;
sk_sp<SkImage> image; sk_sp<SkImage> image;
if (GrRenderable::kYes == renderable) { if (GrRenderable::kYes == renderable) {
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture( sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(
dContext, dContext,
mbet->texture(), backendTex,
kTopLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin,
0, 0,
kRGBA_8888_SkColorType, kRGBA_8888_SkColorType,
/*color space*/ nullptr, nullptr,
/*surface props*/ nullptr, nullptr);
sk_gpu_test::ManagedBackendTexture::ReleaseProc,
mbet->releaseContext());
SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice(); SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice();
proxy = device->accessRenderTargetContext()->asTextureProxyRef(); proxy = device->accessRenderTargetContext()->asTextureProxyRef();
} else { } else {
image = SkImage::MakeFromTexture(dContext, image = SkImage::MakeFromTexture(dContext, backendTex,
mbet->texture(),
kTopLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType, kRGBA_8888_SkColorType,
kPremul_SkAlphaType, kPremul_SkAlphaType, nullptr,
/* color space */ nullptr, nullptr, nullptr);
sk_gpu_test::ManagedBackendTexture::ReleaseProc,
mbet->releaseContext());
const GrSurfaceProxyView* view = as_IB(image)->view(dContext); const GrSurfaceProxyView* view = as_IB(image)->view(dContext);
REPORTER_ASSERT(reporter, view); REPORTER_ASSERT(reporter, view);
if (!view) { if (!view) {
continue; dContext->deleteBackendTexture(backendTex);
return;
} }
proxy = view->asTextureProxyRef(); proxy = view->asTextureProxyRef();
} }
REPORTER_ASSERT(reporter, proxy); REPORTER_ASSERT(reporter, proxy);
if (!proxy) { if (!proxy) {
continue; dContext->deleteBackendTexture(backendTex);
return;
} }
REPORTER_ASSERT(reporter, proxy->isInstantiated()); REPORTER_ASSERT(reporter, proxy->isInstantiated());
@ -98,7 +87,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) {
GrTexture* texture = proxy->peekTexture(); GrTexture* texture = proxy->peekTexture();
REPORTER_ASSERT(reporter, texture); REPORTER_ASSERT(reporter, texture);
if (!texture) { if (!texture) {
continue; dContext->deleteBackendTexture(backendTex);
return;
} }
if (GrMipmapped::kYes == mipMapped) { if (GrMipmapped::kYes == mipMapped) {
@ -111,6 +101,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) {
} else { } else {
REPORTER_ASSERT(reporter, GrMipmapped::kNo == texture->mipmapped()); REPORTER_ASSERT(reporter, GrMipmapped::kNo == texture->mipmapped());
} }
dContext->deleteBackendTexture(backendTex);
} }
} }
} }
@ -125,14 +116,20 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
for (auto betMipMapped : {GrMipmapped::kNo, GrMipmapped::kYes}) { for (auto betMipMapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
for (auto requestMipMapped : {GrMipmapped::kNo, GrMipmapped::kYes}) { for (auto requestMipMapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
auto ii = GrBackendTexture backendTex;
SkImageInfo::Make({kSize, kSize}, kRGBA_8888_SkColorType, kPremul_SkAlphaType); CreateBackendTexture(dContext, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
sk_sp<SkImage> image = sk_gpu_test::MakeBackendTextureImage( SkColors::kTransparent, betMipMapped, GrRenderable::kNo);
dContext, ii, SkColors::kTransparent, betMipMapped);
sk_sp<SkImage> image = SkImage::MakeFromTexture(dContext, backendTex,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,
kPremul_SkAlphaType, nullptr,
nullptr, nullptr);
GrTextureProxy* proxy = as_IB(image)->peekProxy(); GrTextureProxy* proxy = as_IB(image)->peekProxy();
REPORTER_ASSERT(reporter, proxy); REPORTER_ASSERT(reporter, proxy);
if (!proxy) { if (!proxy) {
dContext->deleteBackendTexture(backendTex);
return; return;
} }
@ -141,6 +138,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
sk_sp<GrTexture> texture = sk_ref_sp(proxy->peekTexture()); sk_sp<GrTexture> texture = sk_ref_sp(proxy->peekTexture());
REPORTER_ASSERT(reporter, texture); REPORTER_ASSERT(reporter, texture);
if (!texture) { if (!texture) {
dContext->deleteBackendTexture(backendTex);
return; return;
} }
@ -149,6 +147,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
kPremul_SkAlphaType, nullptr); kPremul_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, imageGen); REPORTER_ASSERT(reporter, imageGen);
if (!imageGen) { if (!imageGen) {
dContext->deleteBackendTexture(backendTex);
return; return;
} }
@ -161,6 +160,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
REPORTER_ASSERT(reporter, genProxy); REPORTER_ASSERT(reporter, genProxy);
if (!genProxy) { if (!genProxy) {
dContext->deleteBackendTexture(backendTex);
return; return;
} }
@ -172,16 +172,17 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
REPORTER_ASSERT(reporter, genProxy->isInstantiated()); REPORTER_ASSERT(reporter, genProxy->isInstantiated());
if (!genProxy->isInstantiated()) { if (!genProxy->isInstantiated()) {
dContext->deleteBackendTexture(backendTex);
return; return;
} }
GrTexture* genTexture = genProxy->peekTexture(); GrTexture* genTexture = genProxy->peekTexture();
REPORTER_ASSERT(reporter, genTexture); REPORTER_ASSERT(reporter, genTexture);
if (!genTexture) { if (!genTexture) {
dContext->deleteBackendTexture(backendTex);
return; return;
} }
GrBackendTexture backendTex = texture->getBackendTexture();
GrBackendTexture genBackendTex = genTexture->getBackendTexture(); GrBackendTexture genBackendTex = genTexture->getBackendTexture();
if (GrBackendApi::kOpenGL == genBackendTex.backend()) { if (GrBackendApi::kOpenGL == genBackendTex.backend()) {
@ -251,6 +252,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
} else { } else {
REPORTER_ASSERT(reporter, false); REPORTER_ASSERT(reporter, false);
} }
// Must make sure the uses of the backend texture have finished (we possibly have a
// queued up copy) before we delete the backend texture.
dContext->flushAndSubmit();
dContext->priv().getGpu()->testingOnly_flushGpuAndSync();
dContext->deleteBackendTexture(backendTex);
} }
} }
} }
@ -269,24 +278,28 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn
for (auto isWrapped : {false, true}) { for (auto isWrapped : {false, true}) {
GrMipmapped mipMapped = willUseMips ? GrMipmapped::kYes : GrMipmapped::kNo; GrMipmapped mipMapped = willUseMips ? GrMipmapped::kYes : GrMipmapped::kNo;
sk_sp<SkSurface> surface; sk_sp<SkSurface> surface;
SkImageInfo info = GrBackendTexture backendTex;
SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType); CreateBackendTexture(dContext, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
SkColors::kTransparent, mipMapped, GrRenderable::kYes);
if (isWrapped) { if (isWrapped) {
surface = sk_gpu_test::MakeBackendTextureSurface(dContext, surface = SkSurface::MakeFromBackendTexture(dContext,
info, backendTex,
kTopLeft_GrSurfaceOrigin,
/* sample count */ 1,
mipMapped);
} else {
surface = SkSurface::MakeRenderTarget(dContext,
SkBudgeted::kYes,
info,
/* sample count */ 1,
kTopLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin,
0,
kRGBA_8888_SkColorType,
nullptr, nullptr,
nullptr);
} else {
SkImageInfo info = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
surface = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kYes, info, 0,
kTopLeft_GrSurfaceOrigin, nullptr,
willUseMips); willUseMips);
} }
REPORTER_ASSERT(reporter, surface); REPORTER_ASSERT(reporter, surface);
if (!surface) {
dContext->deleteBackendTexture(backendTex);
}
SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice(); SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice();
GrTextureProxy* texProxy = device->accessRenderTargetContext()->asTextureProxy(); GrTextureProxy* texProxy = device->accessRenderTargetContext()->asTextureProxy();
REPORTER_ASSERT(reporter, mipMapped == texProxy->mipmapped()); REPORTER_ASSERT(reporter, mipMapped == texProxy->mipmapped());
@ -297,12 +310,21 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn
sk_sp<SkImage> image = surface->makeImageSnapshot(); sk_sp<SkImage> image = surface->makeImageSnapshot();
REPORTER_ASSERT(reporter, image); REPORTER_ASSERT(reporter, image);
if (!image) {
dContext->deleteBackendTexture(backendTex);
}
texProxy = as_IB(image)->peekProxy(); texProxy = as_IB(image)->peekProxy();
REPORTER_ASSERT(reporter, mipMapped == texProxy->mipmapped()); REPORTER_ASSERT(reporter, mipMapped == texProxy->mipmapped());
texProxy->instantiate(resourceProvider); texProxy->instantiate(resourceProvider);
texture = texProxy->peekTexture(); texture = texProxy->peekTexture();
REPORTER_ASSERT(reporter, mipMapped == texture->mipmapped()); REPORTER_ASSERT(reporter, mipMapped == texture->mipmapped());
// Must flush the dContext to make sure all the cmds (copies, etc.) from above are sent
// to the gpu before we delete the backendHandle.
dContext->flushAndSubmit();
dContext->priv().getGpu()->testingOnly_flushGpuAndSync();
dContext->deleteBackendTexture(backendTex);
} }
} }
} }

View File

@ -17,8 +17,8 @@
#include "src/gpu/effects/GrPorterDuffXferProcessor.h" #include "src/gpu/effects/GrPorterDuffXferProcessor.h"
#include "src/gpu/gl/GrGLCaps.h" #include "src/gpu/gl/GrGLCaps.h"
#include "src/gpu/ops/GrMeshDrawOp.h" #include "src/gpu/ops/GrMeshDrawOp.h"
#include "tests/TestUtils.h"
#include "tools/gpu/GrContextFactory.h" #include "tools/gpu/GrContextFactory.h"
#include "tools/gpu/ManagedBackendTexture.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -999,15 +999,16 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, options) {
SK_ABORT("Mock context failed to honor request for no ARB_blend_func_extended."); SK_ABORT("Mock context failed to honor request for no ARB_blend_func_extended.");
} }
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( GrBackendTexture backendTex;
ctx, 100, 100, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo); CreateBackendTexture(ctx, &backendTex, 100, 100, kRGBA_8888_SkColorType,
SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo);
GrXferProcessor::DstProxyView fakeDstProxyView; GrXferProcessor::DstProxyView fakeDstProxyView;
{ {
sk_sp<GrTextureProxy> proxy = proxyProvider->wrapBackendTexture( sk_sp<GrTextureProxy> proxy = proxyProvider->wrapBackendTexture(
mbet->texture(), kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType, backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType);
mbet->refCountedCallback()); GrSwizzle swizzle = caps.getReadSwizzle(backendTex.getBackendFormat(),
GrSwizzle swizzle = GrColorType::kRGBA_8888);
caps.getReadSwizzle(mbet->texture().getBackendFormat(), GrColorType::kRGBA_8888);
fakeDstProxyView.setProxyView({std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}); fakeDstProxyView.setProxyView({std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle});
} }
@ -1033,4 +1034,5 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, options) {
} }
} }
} }
ctx->deleteBackendTexture(backendTex);
} }

View File

@ -22,8 +22,6 @@
#include "src/gpu/GrTexture.h" #include "src/gpu/GrTexture.h"
#include "tests/Test.h" #include "tests/Test.h"
#include "tests/TestUtils.h" #include "tests/TestUtils.h"
#include "tools/gpu/BackendTextureImageFactory.h"
#include "tools/gpu/ManagedBackendTexture.h"
// Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture
// and render targets to GrSurface all work as expected. // and render targets to GrSurface all work as expected.
@ -359,11 +357,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) {
// that they'd succeed if the texture wasn't kRead. We want to be sure we're failing with // that they'd succeed if the texture wasn't kRead. We want to be sure we're failing with
// kRead for the right reason. // kRead for the right reason.
for (auto ioType : {kRead_GrIOType, kRW_GrIOType}) { for (auto ioType : {kRead_GrIOType, kRW_GrIOType}) {
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithData( auto backendTex = dContext->createBackendTexture(&srcPixmap, 1,
dContext, srcPixmap, GrRenderable::kNo, GrProtected::kNo); GrRenderable::kYes, GrProtected::kNo);
auto proxy = proxyProvider->wrapBackendTexture(mbet->texture(), kBorrow_GrWrapOwnership,
GrWrapCacheable::kNo, ioType, auto proxy = proxyProvider->wrapBackendTexture(
mbet->refCountedCallback()); backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, ioType);
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
GrColorType::kRGBA_8888); GrColorType::kRGBA_8888);
GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle); GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
@ -417,45 +415,51 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) {
// Mip regen should not work with a read only texture. // Mip regen should not work with a read only texture.
if (dContext->priv().caps()->mipmapSupport()) { if (dContext->priv().caps()->mipmapSupport()) {
mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext, DeleteBackendTexture(dContext, backendTex);
kSize, backendTex = dContext->createBackendTexture(
kSize, kSize, kSize, kRGBA_8888_SkColorType,
kRGBA_8888_SkColorType, SkColors::kTransparent, GrMipmapped::kYes, GrRenderable::kYes,
GrMipmapped::kYes,
GrRenderable::kNo,
GrProtected::kNo); GrProtected::kNo);
proxy = proxyProvider->wrapBackendTexture(mbet->texture(), kBorrow_GrWrapOwnership, proxy = proxyProvider->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership,
GrWrapCacheable::kNo, ioType, GrWrapCacheable::kNo, ioType);
mbet->refCountedCallback());
dContext->flushAndSubmit(); dContext->flushAndSubmit();
proxy->peekTexture()->markMipmapsDirty(); // avoids assert in GrGpu. proxy->peekTexture()->markMipmapsDirty(); // avoids assert in GrGpu.
auto regenResult = auto regenResult =
dContext->priv().getGpu()->regenerateMipMapLevels(proxy->peekTexture()); dContext->priv().getGpu()->regenerateMipMapLevels(proxy->peekTexture());
REPORTER_ASSERT(reporter, regenResult == (ioType == kRW_GrIOType)); REPORTER_ASSERT(reporter, regenResult == (ioType == kRW_GrIOType));
} }
DeleteBackendTexture(dContext, backendTex);
} }
} }
static const int kSurfSize = 10; static const int kSurfSize = 10;
static sk_sp<GrTexture> make_wrapped_texture(GrDirectContext* dContext, GrRenderable renderable) { static sk_sp<GrTexture> make_wrapped_texture(GrDirectContext* dContext, GrRenderable renderable) {
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( GrBackendTexture backendTexture;
dContext, kSurfSize, kSurfSize, kRGBA_8888_SkColorType, GrMipmapped::kNo, renderable); CreateBackendTexture(dContext, &backendTexture, kSurfSize, kSurfSize, kRGBA_8888_SkColorType,
SkASSERT(mbet); SkColors::kTransparent, GrMipmapped::kNo, renderable, GrProtected::kNo);
sk_sp<GrTextureProxy> proxy; SkASSERT(backendTexture.isValid());
if (renderable == GrRenderable::kYes) { sk_sp<GrTexture> texture;
proxy = dContext->priv().proxyProvider()->wrapRenderableBackendTexture( if (GrRenderable::kYes == renderable) {
mbet->texture(), 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, texture = dContext->priv().resourceProvider()->wrapRenderableBackendTexture(
mbet->refCountedCallback()); backendTexture, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
} else { } else {
proxy = dContext->priv().proxyProvider()->wrapBackendTexture( texture = dContext->priv().resourceProvider()->wrapBackendTexture(
mbet->texture(), kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType, backendTexture, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
mbet->refCountedCallback());
} }
if (!proxy) { // Add a release proc that deletes the GrBackendTexture.
return nullptr; struct ReleaseContext {
} GrDirectContext* fDContext;
return sk_ref_sp(proxy->peekTexture()); GrBackendTexture fBackendTexture;
};
auto release = [](void* rc) {
auto releaseContext = static_cast<ReleaseContext*>(rc);
auto dContext = releaseContext->fDContext;
dContext->deleteBackendTexture(releaseContext->fBackendTexture);
delete releaseContext;
};
texture->setRelease(release, new ReleaseContext{dContext, backendTexture});
return texture;
} }
static sk_sp<GrTexture> make_normal_texture(GrDirectContext* dContext, GrRenderable renderable) { static sk_sp<GrTexture> make_normal_texture(GrDirectContext* dContext, GrRenderable renderable) {
@ -773,11 +777,22 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(TextureIdleProcFlushTest, reporter, contextInfo) {
// is a wrapped-texture backed image. // is a wrapped-texture backed image.
surf->getCanvas()->clear(SK_ColorWHITE); surf->getCanvas()->clear(SK_ColorWHITE);
auto img1 = surf->makeImageSnapshot(); auto img1 = surf->makeImageSnapshot();
auto img2 = sk_gpu_test::MakeBackendTextureImage(dContext, info, SkColors::kBlack);
REPORTER_ASSERT(reporter, img1 && img2); GrBackendTexture backendTexture;
if (!CreateBackendTexture(dContext, &backendTexture, info, SkColors::kBlack,
GrMipmapped::kNo, GrRenderable::kNo)) {
REPORTER_ASSERT(reporter, false);
continue;
}
auto img2 = SkImage::MakeFromTexture(dContext, backendTexture, kTopLeft_GrSurfaceOrigin,
info.colorType(), info.alphaType(), nullptr);
surf->getCanvas()->drawImage(std::move(img1), 0, 0); surf->getCanvas()->drawImage(std::move(img1), 0, 0);
surf->getCanvas()->drawImage(std::move(img2), 1, 1); surf->getCanvas()->drawImage(std::move(img2), 1, 1);
idleTexture.reset(); idleTexture.reset();
DeleteBackendTexture(dContext, backendTexture);
} }
} }
} }

View File

@ -36,9 +36,9 @@
#include "src/image/SkImage_Base.h" #include "src/image/SkImage_Base.h"
#include "src/image/SkImage_GpuYUVA.h" #include "src/image/SkImage_GpuYUVA.h"
#include "tests/Test.h" #include "tests/Test.h"
#include "tests/TestUtils.h"
#include "tools/Resources.h" #include "tools/Resources.h"
#include "tools/ToolUtils.h" #include "tools/ToolUtils.h"
#include "tools/gpu/ManagedBackendTexture.h"
using namespace sk_gpu_test; using namespace sk_gpu_test;
@ -487,17 +487,19 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsImage, reporter
SkColorType colorType = static_cast<SkColorType>(ct); SkColorType colorType = static_cast<SkColorType>(ct);
bool can = dContext->colorTypeSupportedAsImage(colorType); bool can = dContext->colorTypeSupportedAsImage(colorType);
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( GrBackendTexture backendTex;
dContext, kSize, kSize, colorType, GrMipmapped::kNo, GrRenderable::kNo); CreateBackendTexture(dContext, &backendTex, kSize, kSize, colorType, SkColors::kTransparent,
if (!mbet) { GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
ERRORF(reporter, "Could not create texture with color type %d.", colorType);
continue; auto img = SkImage::MakeFromTexture(dContext, backendTex, kTopLeft_GrSurfaceOrigin,
}
auto img = SkImage::MakeFromTexture(dContext, mbet->texture(), kTopLeft_GrSurfaceOrigin,
colorType, kOpaque_SkAlphaType, nullptr); colorType, kOpaque_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, can == SkToBool(img), REPORTER_ASSERT(reporter, can == SkToBool(img),
"colorTypeSupportedAsImage:%d, actual:%d, ct:%d", can, SkToBool(img), "colorTypeSupportedAsImage:%d, actual:%d, ct:%d", can, SkToBool(img),
colorType); colorType);
img.reset();
dContext->flushAndSubmit();
dContext->deleteBackendTexture(backendTex);
} }
} }
@ -830,36 +832,27 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c
auto dContext = ctxInfo.directContext(); auto dContext = ctxInfo.directContext();
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext, SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, SkColorType::kRGBA_8888_SkColorType,
kWidth, kPremul_SkAlphaType);
kHeight, GrBackendTexture backendTex;
kRGBA_8888_SkColorType, if (!CreateBackendTexture(dContext, &backendTex, ii, SkColors::kRed, GrMipmapped::kNo,
GrMipmapped::kNo, GrRenderable::kNo)) {
GrRenderable::kNo,
GrProtected::kNo);
if (!mbet) {
ERRORF(reporter, "couldn't create backend texture\n"); ERRORF(reporter, "couldn't create backend texture\n");
} }
TextureReleaseChecker releaseChecker; TextureReleaseChecker releaseChecker;
GrSurfaceOrigin texOrigin = kBottomLeft_GrSurfaceOrigin; GrSurfaceOrigin texOrigin = kBottomLeft_GrSurfaceOrigin;
sk_sp<SkImage> refImg = SkImage::MakeFromTexture( sk_sp<SkImage> refImg(
dContext, SkImage::MakeFromTexture(dContext, backendTex, texOrigin, kRGBA_8888_SkColorType,
mbet->texture(), kPremul_SkAlphaType, nullptr,
texOrigin, TextureReleaseChecker::Release, &releaseChecker));
kRGBA_8888_SkColorType,
kPremul_SkAlphaType,
/*color space*/nullptr,
sk_gpu_test::ManagedBackendTexture::ReleaseProc,
mbet->releaseContext(TextureReleaseChecker::Release, &releaseChecker));
GrSurfaceOrigin readBackOrigin; GrSurfaceOrigin readBackOrigin;
GrBackendTexture readBackBackendTex = refImg->getBackendTexture(false, &readBackOrigin); GrBackendTexture readBackBackendTex = refImg->getBackendTexture(false, &readBackOrigin);
if (!GrBackendTexture::TestingOnly_Equals(readBackBackendTex, mbet->texture())) { if (!GrBackendTexture::TestingOnly_Equals(readBackBackendTex, backendTex)) {
ERRORF(reporter, "backend mismatch\n"); ERRORF(reporter, "backend mismatch\n");
} }
REPORTER_ASSERT(reporter, REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(readBackBackendTex, backendTex));
GrBackendTexture::TestingOnly_Equals(readBackBackendTex, mbet->texture()));
if (readBackOrigin != texOrigin) { if (readBackOrigin != texOrigin) {
ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, texOrigin); ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, texOrigin);
} }
@ -869,6 +862,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c
REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount);
refImg.reset(nullptr); // force a release of the image refImg.reset(nullptr); // force a release of the image
REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount);
DeleteBackendTexture(dContext, backendTex);
} }
static void test_cross_context_image(skiatest::Reporter* reporter, const GrContextOptions& options, static void test_cross_context_image(skiatest::Reporter* reporter, const GrContextOptions& options,

View File

@ -15,7 +15,7 @@
#include "src/gpu/GrGpu.h" #include "src/gpu/GrGpu.h"
#include "src/gpu/GrTexture.h" #include "src/gpu/GrTexture.h"
#include "src/image/SkImage_Gpu.h" #include "src/image/SkImage_Gpu.h"
#include "tools/gpu/ManagedBackendTexture.h" #include "tests/TestUtils.h"
using namespace sk_gpu_test; using namespace sk_gpu_test;
@ -270,37 +270,23 @@ DEF_GPUTEST(PromiseImageTextureShutdown, reporter, ctxInfo) {
continue; continue;
} }
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(ctx, GrBackendTexture backendTex;
kWidth, CreateBackendTexture(ctx, &backendTex, kWidth, kHeight, kAlpha_8_SkColorType,
kHeight, SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo,
kAlpha_8_SkColorType, GrProtected::kNo);
GrMipmapped::kNo, REPORTER_ASSERT(reporter, backendTex.isValid());
GrRenderable::kNo);
if (!mbet) {
ERRORF(reporter, "Could not create texture alpha texture.");
continue;
}
SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kRGBA_8888_SkColorType, SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kRGBA_8888_SkColorType,
kPremul_SkAlphaType); kPremul_SkAlphaType);
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info); sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info);
SkCanvas* canvas = surface->getCanvas(); SkCanvas* canvas = surface->getCanvas();
PromiseTextureChecker promiseChecker(mbet->texture(), reporter, false); PromiseTextureChecker promiseChecker(backendTex, reporter, false);
sk_sp<SkImage> image(SkImage_Gpu::MakePromiseTexture( sk_sp<SkImage> image(SkImage_Gpu::MakePromiseTexture(
ctx, ctx, backendTex.getBackendFormat(), kWidth, kHeight, GrMipmapped::kNo,
mbet->texture().getBackendFormat(), kTopLeft_GrSurfaceOrigin, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr,
kWidth, PromiseTextureChecker::Fulfill, PromiseTextureChecker::Release,
kHeight, PromiseTextureChecker::Done, &promiseChecker,
GrMipmapped::kNo,
kTopLeft_GrSurfaceOrigin,
kAlpha_8_SkColorType,
kPremul_SkAlphaType,
/*color space*/ nullptr,
PromiseTextureChecker::Fulfill,
PromiseTextureChecker::Release,
PromiseTextureChecker::Done,
&promiseChecker,
SkDeferredDisplayListRecorder::PromiseImageApiVersion::kNew)); SkDeferredDisplayListRecorder::PromiseImageApiVersion::kNew));
REPORTER_ASSERT(reporter, image); REPORTER_ASSERT(reporter, image);
@ -391,12 +377,15 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PromiseImageNullFulfill, reporter, ctxInfo) {
auto dContext = ctxInfo.directContext(); auto dContext = ctxInfo.directContext();
GrBackendFormat backendFormat = // Do all this just to get a valid backend format for the image.
dContext->defaultBackendFormat(kRGBA_8888_SkColorType, GrRenderable::kYes); GrBackendTexture backendTex;
if (!backendFormat.isValid()) { CreateBackendTexture(dContext, &backendTex, kWidth, kHeight, kRGBA_8888_SkColorType,
ERRORF(reporter, "No valid default kRGBA_8888 texture format."); SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kYes,
return; GrProtected::kNo);
} REPORTER_ASSERT(reporter, backendTex.isValid());
GrBackendFormat backendFormat = backendTex.getBackendFormat();
REPORTER_ASSERT(reporter, backendFormat.isValid());
dContext->deleteBackendTexture(backendTex);
struct Counts { struct Counts {
int fFulfillCount = 0; int fFulfillCount = 0;

View File

@ -7,6 +7,8 @@
// This is a GPU-backend specific test. // This is a GPU-backend specific test.
#include "tests/Test.h"
#include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
@ -20,8 +22,6 @@
#include "src/gpu/GrTexture.h" #include "src/gpu/GrTexture.h"
#include "src/gpu/GrTextureProxy.h" #include "src/gpu/GrTextureProxy.h"
#include "src/gpu/SkGr.h" #include "src/gpu/SkGr.h"
#include "tests/Test.h"
#include "tools/gpu/ManagedBackendTexture.h"
#ifdef SK_GL #ifdef SK_GL
#include "src/gpu/gl/GrGLDefines.h" #include "src/gpu/gl/GrGLDefines.h"
#include "src/gpu/gl/GrGLUtil.h" #include "src/gpu/gl/GrGLUtil.h"
@ -265,57 +265,47 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
// Tests wrapBackendTexture that is only renderable // Tests wrapBackendTexture that is only renderable
{ {
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(direct, GrBackendTexture backendTex;
kWidthHeight, CreateBackendTexture(direct, &backendTex, kWidthHeight, kWidthHeight, colorType,
kWidthHeight, SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kYes,
colorType, GrProtected::kNo);
GrMipmapped::kNo,
GrRenderable::kYes);
if (!mbet) {
ERRORF(reporter,
"Could not create renderable backend texture of color type %d",
colorType);
continue;
}
sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture( sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
mbet->texture(), supportedNumSamples, kBorrow_GrWrapOwnership, backendTex, supportedNumSamples, kBorrow_GrWrapOwnership,
GrWrapCacheable::kNo, nullptr); GrWrapCacheable::kNo, nullptr);
if (!sProxy) { if (!sProxy) {
ERRORF(reporter, "wrapRenderableBackendTexture failed"); direct->deleteBackendTexture(backendTex);
continue; continue; // This can fail on Mesa
} }
check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo); check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo);
check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(), check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
supportedNumSamples, SkBackingFit::kExact, supportedNumSamples, SkBackingFit::kExact,
caps.maxWindowRectangles()); caps.maxWindowRectangles());
direct->deleteBackendTexture(backendTex);
} }
{
// Tests wrapBackendTexture that is only textureable // Tests wrapBackendTexture that is only textureable
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(direct, {
kWidthHeight, // Internal offscreen texture
kWidthHeight, GrBackendTexture backendTex;
colorType, CreateBackendTexture(direct, &backendTex, kWidthHeight, kWidthHeight, colorType,
GrMipmapped::kNo, SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo,
GrRenderable::kNo); GrProtected::kNo);
if (!mbet) {
ERRORF(reporter,
"Could not create non-renderable backend texture of color type %d",
colorType);
continue;
}
sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture( sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
mbet->texture(), kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType);
kRead_GrIOType, mbet->refCountedCallback());
if (!sProxy) { if (!sProxy) {
ERRORF(reporter, "wrapBackendTexture failed"); direct->deleteBackendTexture(backendTex);
continue; continue;
} }
check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo); check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo);
check_texture(reporter, resourceProvider, sProxy->asTextureProxy(), check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
SkBackingFit::kExact); SkBackingFit::kExact);
direct->deleteBackendTexture(backendTex);
} }
} }
} }

View File

@ -17,7 +17,7 @@
#include "src/gpu/GrTexture.h" #include "src/gpu/GrTexture.h"
#include "src/gpu/GrTextureProxy.h" #include "src/gpu/GrTextureProxy.h"
#include "tests/Test.h" #include "tests/Test.h"
#include "tools/gpu/ManagedBackendTexture.h" #include "tests/TestUtils.h"
struct ProxyParams { struct ProxyParams {
int fSize; int fSize;
@ -36,24 +36,27 @@ static sk_sp<GrSurfaceProxy> make_deferred(GrProxyProvider* proxyProvider, const
GrMipmapped::kNo, p.fFit, p.fBudgeted, GrProtected::kNo); GrMipmapped::kNo, p.fFit, p.fBudgeted, GrProtected::kNo);
} }
static sk_sp<GrSurfaceProxy> make_backend(GrDirectContext* dContext, const ProxyParams& p) { static sk_sp<GrSurfaceProxy> make_backend(GrDirectContext* dContext,
const ProxyParams& p,
GrBackendTexture* backendTex) {
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider(); GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
SkColorType skColorType = GrColorTypeToSkColorType(p.fColorType); SkColorType skColorType = GrColorTypeToSkColorType(p.fColorType);
SkASSERT(SkColorType::kUnknown_SkColorType != skColorType); SkASSERT(SkColorType::kUnknown_SkColorType != skColorType);
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( CreateBackendTexture(dContext, backendTex, p.fSize, p.fSize, skColorType,
dContext, p.fSize, p.fSize, skColorType, GrMipmapped::kNo, GrRenderable::kNo); SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo);
if (!mbet) { if (!backendTex->isValid()) {
return nullptr; return nullptr;
} }
return proxyProvider->wrapBackendTexture(mbet->texture(), return proxyProvider->wrapBackendTexture(*backendTex, kBorrow_GrWrapOwnership,
kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType);
GrWrapCacheable::kNo, }
kRead_GrIOType,
mbet->refCountedCallback()); static void cleanup_backend(GrDirectContext* dContext, const GrBackendTexture& backendTex) {
dContext->deleteBackendTexture(backendTex);
} }
// Basic test that two proxies with overlapping intervals and compatible descriptors are // Basic test that two proxies with overlapping intervals and compatible descriptors are
@ -213,11 +216,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) {
TestCase t[1] = { TestCase t[1] = {
{{64, kNotRT, kRGBA, kE, 1, kNotB}, {64, kNotRT, kRGBA, kE, 1, kNotB}, kDontShare}}; {{64, kNotRT, kRGBA, kE, 1, kNotB}, {64, kNotRT, kRGBA, kE, 1, kNotB}, kDontShare}};
sk_sp<GrSurfaceProxy> p1 = make_backend(direct, t[0].fP1); GrBackendTexture backEndTex;
sk_sp<GrSurfaceProxy> p1 = make_backend(direct, t[0].fP1, &backEndTex);
sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, caps, t[0].fP2); sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, caps, t[0].fP2);
non_overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2), non_overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2),
t[0].fExpectation); t[0].fExpectation);
cleanup_backend(direct, backEndTex);
} }
} }
@ -340,15 +346,18 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorCurOpsTaskIndexTest,
// Wrapped proxy that will be ignored by the resourceAllocator. We use this to try and get the // Wrapped proxy that will be ignored by the resourceAllocator. We use this to try and get the
// resource allocator fCurOpsTaskIndex to fall behind what it really should be. // resource allocator fCurOpsTaskIndex to fall behind what it really should be.
sk_sp<GrSurfaceProxy> proxyWrapped = make_backend(context, params); GrBackendTexture backEndTex;
sk_sp<GrSurfaceProxy> proxyWrapped = make_backend(context, params, &backEndTex);
if (!proxyWrapped) { if (!proxyWrapped) {
return; return;
} }
// Same as above, but we actually need to have at least two intervals that don't go through the // Same as above, but we actually need to have at least two intervals that don't go through the
// resource allocator to expose the index bug. // resource allocator to expose the index bug.
sk_sp<GrSurfaceProxy> proxyWrapped2 = make_backend(context, params); GrBackendTexture backEndTex2;
sk_sp<GrSurfaceProxy> proxyWrapped2 = make_backend(context, params, &backEndTex2);
if (!proxyWrapped2) { if (!proxyWrapped2) {
cleanup_backend(context, backEndTex);
return; return;
} }
@ -389,6 +398,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorCurOpsTaskIndexTest,
REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error); REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error);
REPORTER_ASSERT(reporter, 3 == startIndex && 4 == stopIndex); REPORTER_ASSERT(reporter, 3 == startIndex && 4 == stopIndex);
cleanup_backend(context, backEndTex);
cleanup_backend(context, backEndTex2);
context->setResourceCacheLimit(origMaxBytes); context->setResourceCacheLimit(origMaxBytes);
} }

View File

@ -7,11 +7,7 @@
#include "include/core/SkTypes.h" #include "include/core/SkTypes.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
#include "src/core/SkMessageBus.h"
#include "src/core/SkMipmap.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrGpu.h" #include "src/gpu/GrGpu.h"
#include "src/gpu/GrGpuResourceCacheAccess.h" #include "src/gpu/GrGpuResourceCacheAccess.h"
@ -22,10 +18,15 @@
#include "src/gpu/GrResourceCache.h" #include "src/gpu/GrResourceCache.h"
#include "src/gpu/GrResourceProvider.h" #include "src/gpu/GrResourceProvider.h"
#include "src/gpu/GrTexture.h" #include "src/gpu/GrTexture.h"
#include "tools/gpu/GrContextFactory.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"
#include "src/core/SkMessageBus.h"
#include "src/core/SkMipmap.h"
#include "src/gpu/SkGr.h" #include "src/gpu/SkGr.h"
#include "tests/Test.h" #include "tests/Test.h"
#include "tools/gpu/GrContextFactory.h" #include "tests/TestUtils.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include <thread> #include <thread>
@ -190,44 +191,51 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxI
return; return;
} }
GrBackendTexture backendTextures[2];
static const int kW = 100; static const int kW = 100;
static const int kH = 100; static const int kH = 100;
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( CreateBackendTexture(context, &backendTextures[0], kW, kH, kRGBA_8888_SkColorType,
context, kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo); SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo,
GrBackendTexture unmbet = context->createBackendTexture( GrProtected::kNo);
kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo); CreateBackendTexture(context, &backendTextures[1], kW, kH, kRGBA_8888_SkColorType,
if (!mbet || !unmbet.isValid()) { SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo,
ERRORF(reporter, "Could not create backend texture."); GrProtected::kNo);
REPORTER_ASSERT(reporter, backendTextures[0].isValid());
REPORTER_ASSERT(reporter, backendTextures[1].isValid());
if (!backendTextures[0].isValid() || !backendTextures[1].isValid()) {
return; return;
} }
context->resetContext(); context->resetContext();
sk_sp<GrTexture> borrowed(resourceProvider->wrapBackendTexture( sk_sp<GrTexture> borrowed(resourceProvider->wrapBackendTexture(
mbet->texture(), kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType)); backendTextures[0], kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType));
sk_sp<GrTexture> adopted(resourceProvider->wrapBackendTexture( sk_sp<GrTexture> adopted(resourceProvider->wrapBackendTexture(
unmbet, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType)); backendTextures[1], kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType));
REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr); REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr);
if (!borrowed || !adopted) { if (!borrowed || !adopted) {
return; return;
} }
borrowed.reset(); borrowed.reset(nullptr);
adopted.reset(); adopted.reset(nullptr);
context->flushAndSubmit(/*sync*/ true); context->flushAndSubmit();
bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(mbet->texture()); bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(backendTextures[0]);
bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(unmbet); bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(backendTextures[1]);
REPORTER_ASSERT(reporter, borrowedIsAlive); REPORTER_ASSERT(reporter, borrowedIsAlive);
REPORTER_ASSERT(reporter, !adoptedIsAlive); REPORTER_ASSERT(reporter, !adoptedIsAlive);
if (borrowedIsAlive) {
context->deleteBackendTexture(backendTextures[0]);
}
if (adoptedIsAlive) { if (adoptedIsAlive) {
context->deleteBackendTexture(unmbet); context->deleteBackendTexture(backendTextures[1]);
} }
context->resetContext(); context->resetContext();

View File

@ -29,14 +29,15 @@
#include "src/image/SkImage_Gpu.h" #include "src/image/SkImage_Gpu.h"
#include "src/image/SkSurface_Gpu.h" #include "src/image/SkSurface_Gpu.h"
#include "tests/Test.h" #include "tests/Test.h"
#include "tools/ToolUtils.h" #include "tests/TestUtils.h"
#include "tools/gpu/BackendSurfaceFactory.h" #include "tools/gpu/BackendSurfaceFactory.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include <functional> #include <functional>
#include <initializer_list> #include <initializer_list>
#include <vector> #include <vector>
#include "tools/ToolUtils.h"
static void release_direct_surface_storage(void* pixels, void* context) { static void release_direct_surface_storage(void* pixels, void* context) {
SkASSERT(pixels == context); SkASSERT(pixels == context);
sk_free(pixels); sk_free(pixels);
@ -107,13 +108,19 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsSurface, report
REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d", REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
colorType, can, SkToBool(surf)); colorType, can, SkToBool(surf));
surf = sk_gpu_test::MakeBackendTextureSurface(context, GrBackendTexture backendTex;
{kSize, kSize}, CreateBackendTexture(context, &backendTex, kSize, kSize, colorType,
kTopLeft_GrSurfaceOrigin, SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kYes,
/*sample cnt*/ 1, GrProtected::kNo);
colorType); surf = SkSurface::MakeFromBackendTexture(context, backendTex,
kTopLeft_GrSurfaceOrigin, 0, colorType,
nullptr, nullptr);
REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d", REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
colorType, can, SkToBool(surf)); colorType, can, SkToBool(surf));
surf.reset();
context->flushAndSubmit();
context->deleteBackendTexture(backendTex);
} }
// The MSAA test only makes sense if the colorType is renderable to begin with. // The MSAA test only makes sense if the colorType is renderable to begin with.
@ -126,8 +133,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsSurface, report
REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d", REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
colorType, can, SkToBool(surf)); colorType, can, SkToBool(surf));
surf = sk_gpu_test::MakeBackendTextureSurface( GrBackendTexture backendTex;
context, {kSize, kSize}, kTopLeft_GrSurfaceOrigin, kSampleCnt, colorType); CreateBackendTexture(context, &backendTex, kSize, kSize, colorType,
SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kYes,
GrProtected::kNo);
surf = SkSurface::MakeFromBackendTexture(context, backendTex,
kTopLeft_GrSurfaceOrigin, kSampleCnt,
colorType, nullptr, nullptr);
REPORTER_ASSERT(reporter, can == SkToBool(surf), REPORTER_ASSERT(reporter, can == SkToBool(surf),
"colorTypeSupportedAsSurface:%d, surf:%d, ct:%d", can, SkToBool(surf), "colorTypeSupportedAsSurface:%d, surf:%d, ct:%d", can, SkToBool(surf),
colorType); colorType);
@ -135,13 +147,15 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsSurface, report
if (surf) { if (surf) {
auto rtc = ((SkSurface_Gpu*)(surf.get()))->getDevice()->accessRenderTargetContext(); auto rtc = ((SkSurface_Gpu*)(surf.get()))->getDevice()->accessRenderTargetContext();
int storedCnt = rtc->numSamples(); int storedCnt = rtc->numSamples();
GrBackendFormat format = rtc->writeSurfaceView().proxy()->backendFormat(); int allowedCnt = context->priv().caps()->getRenderTargetSampleCount(
int allowedCnt = storedCnt, backendTex.getBackendFormat());
context->priv().caps()->getRenderTargetSampleCount(storedCnt, format);
REPORTER_ASSERT(reporter, storedCnt == allowedCnt, REPORTER_ASSERT(reporter, storedCnt == allowedCnt,
"Should store an allowed sample count (%d vs %d)", allowedCnt, "Should store an allowed sample count (%d vs %d)", allowedCnt,
storedCnt); storedCnt);
} }
surf.reset();
context->flushAndSubmit();
context->deleteBackendTexture(backendTex);
} }
for (int sampleCnt : {1, 2}) { for (int sampleCnt : {1, 2}) {
@ -187,27 +201,39 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_maxSurfaceSamplesForColorType, repo
for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) { for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) {
SkColorType colorType = static_cast<SkColorType>(ct); SkColorType colorType = static_cast<SkColorType>(ct);
int maxSampleCnt = context->maxSurfaceSampleCountForColorType(colorType); int max = context->maxSurfaceSampleCountForColorType(colorType);
if (!maxSampleCnt) { if (!max) {
continue; continue;
} }
GrBackendTexture backendTex;
CreateBackendTexture(context, &backendTex, kSize, kSize, colorType,
SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kYes,
GrProtected::kNo);
if (!backendTex.isValid()) {
continue;
}
SkScopeExit freeTex([&backendTex, context] {
context->deleteBackendTexture(backendTex);
});
if (!context->colorTypeSupportedAsSurface(colorType)) { if (!context->colorTypeSupportedAsSurface(colorType)) {
continue; continue;
} }
auto info = SkImageInfo::Make(kSize, kSize, colorType, kOpaque_SkAlphaType, nullptr); auto info = SkImageInfo::Make(kSize, kSize, colorType, kOpaque_SkAlphaType, nullptr);
auto surf = sk_gpu_test::MakeBackendTextureSurface( auto surf = SkSurface::MakeFromBackendTexture(context, backendTex,
context, info, kTopLeft_GrSurfaceOrigin, maxSampleCnt); kTopLeft_GrSurfaceOrigin, max,
colorType, nullptr, nullptr);
REPORTER_ASSERT(reporter, surf);
if (!surf) { if (!surf) {
ERRORF(reporter, "Could not make surface of color type %d.", colorType);
continue; continue;
} }
int sampleCnt = ((SkSurface_Gpu*)(surf.get())) int sampleCnt = ((SkSurface_Gpu*)(surf.get()))
->getDevice() ->getDevice()
->accessRenderTargetContext() ->accessRenderTargetContext()
->numSamples(); ->numSamples();
REPORTER_ASSERT(reporter, sampleCnt == maxSampleCnt, "Exected: %d, actual: %d", REPORTER_ASSERT(reporter, sampleCnt == max, "Exected: %d, actual: %d", max, sampleCnt);
maxSampleCnt, sampleCnt);
} }
} }
@ -653,7 +679,9 @@ DEF_TEST(surface_raster_zeroinitialized, reporter) {
static sk_sp<SkSurface> create_gpu_surface_backend_texture(GrDirectContext* dContext, static sk_sp<SkSurface> create_gpu_surface_backend_texture(GrDirectContext* dContext,
int sampleCnt, int sampleCnt,
const SkColor4f& color) { const SkColor4f& color,
GrBackendTexture* outTexture) {
// On Pixel and Pixel2XL's with Adreno 530 and 540s, setting width and height to 10s reliably // On Pixel and Pixel2XL's with Adreno 530 and 540s, setting width and height to 10s reliably
// triggers what appears to be a driver race condition where the 10x10 surface from the // triggers what appears to be a driver race condition where the 10x10 surface from the
// OverdrawSurface_gpu test is reused(?) for this surface created by the SurfacePartialDraw_gpu // OverdrawSurface_gpu test is reused(?) for this surface created by the SurfacePartialDraw_gpu
@ -677,16 +705,25 @@ static sk_sp<SkSurface> create_gpu_surface_backend_texture(GrDirectContext* dCon
const int kHeight = 100; const int kHeight = 100;
#endif #endif
auto surf = sk_gpu_test::MakeBackendTextureSurface(dContext, SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, SkColorType::kRGBA_8888_SkColorType,
{kWidth, kHeight}, kPremul_SkAlphaType);
kTopLeft_GrSurfaceOrigin,
sampleCnt, if (!CreateBackendTexture(dContext, outTexture, ii, color,
kRGBA_8888_SkColorType); GrMipmapped::kNo, GrRenderable::kYes)) {
if (!surf) {
return nullptr; return nullptr;
} }
surf->getCanvas()->clear(color);
return surf; sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(dContext,
*outTexture,
kTopLeft_GrSurfaceOrigin,
sampleCnt,
kRGBA_8888_SkColorType,
nullptr, nullptr);
if (!surface) {
DeleteBackendTexture(dContext, *outTexture);
return nullptr;
}
return surface;
} }
static bool supports_readpixels(const GrCaps* caps, SkSurface* surface) { static bool supports_readpixels(const GrCaps* caps, SkSurface* surface) {
@ -701,7 +738,8 @@ static bool supports_readpixels(const GrCaps* caps, SkSurface* surface) {
static sk_sp<SkSurface> create_gpu_surface_backend_render_target(GrDirectContext* dContext, static sk_sp<SkSurface> create_gpu_surface_backend_render_target(GrDirectContext* dContext,
int sampleCnt, int sampleCnt,
const SkColor4f& color) { const SkColor4f& color,
GrBackendTexture* outTexture) {
const int kWidth = 10; const int kWidth = 10;
const int kHeight = 10; const int kHeight = 10;
@ -709,7 +747,10 @@ static sk_sp<SkSurface> create_gpu_surface_backend_render_target(GrDirectContext
{kWidth, kHeight}, {kWidth, kHeight},
kTopLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin,
sampleCnt, sampleCnt,
kRGBA_8888_SkColorType); kRGBA_8888_SkColorType,
nullptr,
GrProtected::kNo,
nullptr);
if (!surf) { if (!surf) {
return nullptr; return nullptr;
} }
@ -782,7 +823,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) {
const SkColor4f kOrigColor{.67f, .67f, .67f, 1}; const SkColor4f kOrigColor{.67f, .67f, .67f, 1};
for (auto& surfaceFunc : for (auto& surfaceFunc :
{&create_gpu_surface_backend_texture, &create_gpu_surface_backend_render_target}) { {&create_gpu_surface_backend_texture, &create_gpu_surface_backend_render_target}) {
auto surface = surfaceFunc(dContext, 1, kOrigColor); GrBackendTexture backendTex;
auto surface = surfaceFunc(dContext, 1, kOrigColor, &backendTex);
if (!surface) { if (!surface) {
ERRORF(reporter, "Could not create GPU SkSurface."); ERRORF(reporter, "Could not create GPU SkSurface.");
return; return;
@ -796,6 +838,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) {
auto imageSurfaceCtx = makeImageSurfaceContext(surface.get()); auto imageSurfaceCtx = makeImageSurfaceContext(surface.get());
test_surface_context_clear(reporter, dContext, imageSurfaceCtx.get(), test_surface_context_clear(reporter, dContext, imageSurfaceCtx.get(),
kOrigColor.toSkColor()); kOrigColor.toSkColor());
dContext->deleteBackendTexture(backendTex);
} }
} }
@ -861,9 +904,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacePartialDraw_Gpu, reporter, ctxInfo) {
// Validate that we can draw to the canvas and that the original texture color is // Validate that we can draw to the canvas and that the original texture color is
// preserved in pixels that aren't rendered to via the surface. // preserved in pixels that aren't rendered to via the surface.
// This works only for non-multisampled case. // This works only for non-multisampled case.
auto surface = surfaceFunc(context, 1, kOrigColor); GrBackendTexture backendTex;
if (surface && supports_readpixels(context->priv().caps(), surface.get())) { auto surface = surfaceFunc(context, 1, kOrigColor, &backendTex);
const GrCaps* caps = context->priv().caps();
if (!supports_readpixels(caps, surface.get())) {
continue;
}
if (surface) {
test_surface_draw_partially(reporter, surface, kOrigColor.toSkColor()); test_surface_draw_partially(reporter, surface, kOrigColor.toSkColor());
surface.reset();
context->deleteBackendTexture(backendTex);
} }
} }
} }
@ -885,7 +935,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedWithRelease_Gpu, reporter, ctxI
GrGpu* gpu = ctx->priv().getGpu(); GrGpu* gpu = ctx->priv().getGpu();
for (bool useTexture : {false, true}) { for (bool useTexture : {false, true}) {
sk_sp<sk_gpu_test::ManagedBackendTexture> mbet; GrBackendTexture backendTex;
GrBackendRenderTarget backendRT; GrBackendRenderTarget backendRT;
sk_sp<SkSurface> surface; sk_sp<SkSurface> surface;
@ -895,22 +945,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedWithRelease_Gpu, reporter, ctxI
if (useTexture) { if (useTexture) {
SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, SkColorType::kRGBA_8888_SkColorType, SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, SkColorType::kRGBA_8888_SkColorType,
kPremul_SkAlphaType); kPremul_SkAlphaType);
mbet = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(ctx, ii, GrMipMapped::kNo, if (!CreateBackendTexture(ctx, &backendTex, ii, SkColors::kRed, GrMipmapped::kNo,
GrRenderable::kYes); GrRenderable::kYes)) {
if (!mbet) {
continue; continue;
} }
surface = SkSurface::MakeFromBackendTexture( surface = SkSurface::MakeFromBackendTexture(ctx, backendTex, texOrigin, 1,
ctx,
mbet->texture(),
texOrigin,
/*sample count*/ 1,
kRGBA_8888_SkColorType, kRGBA_8888_SkColorType,
/*color space*/ nullptr, nullptr, nullptr,
/*surface props*/ nullptr, ReleaseChecker::Release,
sk_gpu_test::ManagedBackendTexture::ReleaseProc, &releaseChecker);
mbet->releaseContext(ReleaseChecker::Release, &releaseChecker));
} else { } else {
backendRT = gpu->createTestingOnlyBackendRenderTarget({kWidth, kHeight}, backendRT = gpu->createTestingOnlyBackendRenderTarget({kWidth, kHeight},
GrColorType::kRGBA_8888); GrColorType::kRGBA_8888);
@ -937,7 +981,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedWithRelease_Gpu, reporter, ctxI
surface.reset(nullptr); // force a release of the surface surface.reset(nullptr); // force a release of the surface
REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount);
if (!useTexture) { if (useTexture) {
DeleteBackendTexture(ctx, backendTex);
} else {
gpu->deleteTestingOnlyBackendRenderTarget(backendRT); gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
} }
} }
@ -958,7 +1004,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAttachStencil_Gpu, reporter, ctxInf
for (auto& surfaceFunc : for (auto& surfaceFunc :
{&create_gpu_surface_backend_texture, &create_gpu_surface_backend_render_target}) { {&create_gpu_surface_backend_texture, &create_gpu_surface_backend_render_target}) {
for (int sampleCnt : {1, 4, 8}) { for (int sampleCnt : {1, 4, 8}) {
auto surface = surfaceFunc(context, sampleCnt, kOrigColor); GrBackendTexture backendTex;
auto surface = surfaceFunc(context, sampleCnt, kOrigColor, &backendTex);
if (!surface && sampleCnt > 1) { if (!surface && sampleCnt > 1) {
// Certain platforms don't support MSAA, skip these. // Certain platforms don't support MSAA, skip these.
@ -970,6 +1017,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAttachStencil_Gpu, reporter, ctxInf
GrRenderTarget* rt = surface->getCanvas() GrRenderTarget* rt = surface->getCanvas()
->internal_private_accessTopLayerRenderTargetContext()->accessRenderTarget(); ->internal_private_accessTopLayerRenderTargetContext()->accessRenderTarget();
REPORTER_ASSERT(reporter, resourceProvider->attachStencilAttachment(rt, sampleCnt)); REPORTER_ASSERT(reporter, resourceProvider->attachStencilAttachment(rt, sampleCnt));
if (backendTex.isValid()) {
context->deleteBackendTexture(backendTex);
}
} }
} }
} }
@ -978,29 +1028,34 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReplaceSurfaceBackendTexture, reporter, ctxIn
auto context = ctxInfo.directContext(); auto context = ctxInfo.directContext();
for (int sampleCnt : {1, 2}) { for (int sampleCnt : {1, 2}) {
GrBackendTexture backendTexture1;
auto ii = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); auto ii = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
auto mbet1 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo( if (!CreateBackendTexture(context, &backendTexture1, ii, SkColors::kTransparent,
context, ii, GrMipmapped::kNo, GrRenderable::kYes); GrMipmapped::kNo, GrRenderable::kYes)) {
if (!mbet1) {
continue; continue;
} }
auto mbet2 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo( SkScopeExit delete1(
context, ii, GrMipmapped::kNo, GrRenderable::kYes); [context, &backendTexture1] { DeleteBackendTexture(context, backendTexture1); });
if (!mbet2) { GrBackendTexture backendTexture2;
if (!CreateBackendTexture(context, &backendTexture2, ii, SkColors::kTransparent,
GrMipmapped::kNo, GrRenderable::kYes)) {
ERRORF(reporter, "Expected to be able to make second texture"); ERRORF(reporter, "Expected to be able to make second texture");
continue; continue;
} }
SkScopeExit delete2(
[context, &backendTexture2] { DeleteBackendTexture(context, backendTexture2); });
auto ii2 = ii.makeWH(8, 8); auto ii2 = ii.makeWH(8, 8);
auto mbet3 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(
context, ii2, GrMipmapped::kNo, GrRenderable::kYes);
GrBackendTexture backendTexture3; GrBackendTexture backendTexture3;
if (!mbet3) { if (!CreateBackendTexture(context, &backendTexture3, ii2, SkColors::kTransparent,
GrMipmapped::kNo, GrRenderable::kYes)) {
ERRORF(reporter, "Couldn't create different sized texture."); ERRORF(reporter, "Couldn't create different sized texture.");
continue; continue;
} }
SkScopeExit delete3(
[context, &backendTexture3] { DeleteBackendTexture(context, backendTexture3); });
auto surf = SkSurface::MakeFromBackendTexture( auto surf = SkSurface::MakeFromBackendTexture(
context, mbet1->texture(), kTopLeft_GrSurfaceOrigin, sampleCnt, context, backendTexture1, kTopLeft_GrSurfaceOrigin, sampleCnt,
kRGBA_8888_SkColorType, ii.refColorSpace(), nullptr); kRGBA_8888_SkColorType, ii.refColorSpace(), nullptr);
if (!surf) { if (!surf) {
continue; continue;
@ -1011,7 +1066,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReplaceSurfaceBackendTexture, reporter, ctxIn
surf->getCanvas()->saveLayer(nullptr, nullptr); surf->getCanvas()->saveLayer(nullptr, nullptr);
surf->getCanvas()->clipRect(SkRect::MakeXYWH(0, 0, 1, 1)); surf->getCanvas()->clipRect(SkRect::MakeXYWH(0, 0, 1, 1));
// switch origin while we're at it. // switch origin while we're at it.
bool replaced = surf->replaceBackendTexture(mbet2->texture(), kBottomLeft_GrSurfaceOrigin); bool replaced = surf->replaceBackendTexture(backendTexture2, kBottomLeft_GrSurfaceOrigin);
REPORTER_ASSERT(reporter, replaced); REPORTER_ASSERT(reporter, replaced);
SkPaint paint; SkPaint paint;
paint.setColor(SK_ColorRED); paint.setColor(SK_ColorRED);
@ -1036,7 +1091,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReplaceSurfaceBackendTexture, reporter, ctxIn
} }
// The original texture should still be all blue. // The original texture should still be all blue.
surf = SkSurface::MakeFromBackendTexture( surf = SkSurface::MakeFromBackendTexture(
context, mbet1->texture(), kBottomLeft_GrSurfaceOrigin, sampleCnt, context, backendTexture1, kBottomLeft_GrSurfaceOrigin, sampleCnt,
kRGBA_8888_SkColorType, ii.refColorSpace(), nullptr); kRGBA_8888_SkColorType, ii.refColorSpace(), nullptr);
if (!surf) { if (!surf) {
ERRORF(reporter, "Could not create second surface."); ERRORF(reporter, "Could not create second surface.");
@ -1058,17 +1113,17 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReplaceSurfaceBackendTexture, reporter, ctxIn
// Can't replace with the same texture // Can't replace with the same texture
REPORTER_ASSERT(reporter, REPORTER_ASSERT(reporter,
!surf->replaceBackendTexture(mbet1->texture(), kTopLeft_GrSurfaceOrigin)); !surf->replaceBackendTexture(backendTexture1, kTopLeft_GrSurfaceOrigin));
// Can't replace with invalid texture // Can't replace with invalid texture
REPORTER_ASSERT(reporter, !surf->replaceBackendTexture({}, kTopLeft_GrSurfaceOrigin)); REPORTER_ASSERT(reporter, !surf->replaceBackendTexture({}, kTopLeft_GrSurfaceOrigin));
// Can't replace with different size texture. // Can't replace with different size texture.
REPORTER_ASSERT(reporter, REPORTER_ASSERT(reporter,
!surf->replaceBackendTexture(mbet3->texture(), kTopLeft_GrSurfaceOrigin)); !surf->replaceBackendTexture(backendTexture3, kTopLeft_GrSurfaceOrigin));
// Can't replace texture of non-wrapped SkSurface. // Can't replace texture of non-wrapped SkSurface.
surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, ii, sampleCnt, nullptr); surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, ii, sampleCnt, nullptr);
REPORTER_ASSERT(reporter, surf); REPORTER_ASSERT(reporter, surf);
if (surf) { if (surf) {
REPORTER_ASSERT(reporter, !surf->replaceBackendTexture(mbet1->texture(), REPORTER_ASSERT(reporter, !surf->replaceBackendTexture(backendTexture1,
kTopLeft_GrSurfaceOrigin)); kTopLeft_GrSurfaceOrigin));
} }
} }

View File

@ -107,6 +107,68 @@ void FillPixelData(int width, int height, GrColor* data) {
} }
} }
bool CreateBackendTexture(GrDirectContext* dContext,
GrBackendTexture* backendTex,
int width, int height,
SkColorType colorType,
const SkColor4f& color,
GrMipmapped mipMapped,
GrRenderable renderable,
GrProtected isProtected) {
SkImageInfo info = SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType);
return CreateBackendTexture(dContext, backendTex, info, color, mipMapped, renderable,
isProtected);
}
bool CreateBackendTexture(GrDirectContext* dContext,
GrBackendTexture* backendTex,
const SkImageInfo& ii,
const SkColor4f& color,
GrMipmapped mipMapped,
GrRenderable renderable,
GrProtected isProtected) {
bool finishedBECreate = false;
auto markFinished = [](void* context) {
*(bool*)context = true;
};
*backendTex = dContext->createBackendTexture(ii.width(), ii.height(), ii.colorType(),
color, mipMapped, renderable, isProtected,
markFinished, &finishedBECreate);
if (backendTex->isValid()) {
dContext->submit();
while (!finishedBECreate) {
dContext->checkAsyncWorkCompletion();
}
}
return backendTex->isValid();
}
bool CreateBackendTexture(GrDirectContext* dContext,
GrBackendTexture* backendTex,
const SkBitmap& bm) {
bool finishedBECreate = false;
auto markFinished = [](void* context) {
*(bool*)context = true;
};
*backendTex = dContext->createBackendTexture(bm.pixmap(), GrRenderable::kNo, GrProtected::kNo,
markFinished, &finishedBECreate);
if (backendTex->isValid()) {
dContext->submit();
while (!finishedBECreate) {
dContext->checkAsyncWorkCompletion();
}
}
return backendTex->isValid();
}
void DeleteBackendTexture(GrDirectContext* dContext, const GrBackendTexture& backendTex) {
dContext->flush();
dContext->submit(true);
dContext->deleteBackendTexture(backendTex);
}
bool DoesFullBufferContainCorrectColor(const GrColor* srcBuffer, bool DoesFullBufferContainCorrectColor(const GrColor* srcBuffer,
const GrColor* dstBuffer, const GrColor* dstBuffer,
int width, int height) { int width, int height) {

View File

@ -34,6 +34,30 @@ void TestCopyFromSurface(skiatest::Reporter*, GrDirectContext*, GrSurfaceProxy*
// Fills data with a red-green gradient // Fills data with a red-green gradient
void FillPixelData(int width, int height, GrColor* data); void FillPixelData(int width, int height, GrColor* data);
// Create a solid colored backend texture and syncs the CPU to wait for upload to finish
bool CreateBackendTexture(GrDirectContext*,
GrBackendTexture* backendTex,
int width, int height,
SkColorType colorType,
const SkColor4f& color,
GrMipmapped,
GrRenderable,
GrProtected = GrProtected::kNo);
bool CreateBackendTexture(GrDirectContext*,
GrBackendTexture* backendTex,
const SkImageInfo& ii,
const SkColor4f& color,
GrMipmapped,
GrRenderable,
GrProtected = GrProtected::kNo);
bool CreateBackendTexture(GrDirectContext*,
GrBackendTexture* backendTex,
const SkBitmap& bm);
void DeleteBackendTexture(GrDirectContext*, const GrBackendTexture& backendTex);
// Checks srcBuffer and dstBuffer contain the same colors // Checks srcBuffer and dstBuffer contain the same colors
bool DoesFullBufferContainCorrectColor(const GrColor* srcBuffer, bool DoesFullBufferContainCorrectColor(const GrColor* srcBuffer,
const GrColor* dstBuffer, const GrColor* dstBuffer,

View File

@ -9,7 +9,6 @@
#include "tests/Test.h" #include "tests/Test.h"
#include "include/core/SkImage.h"
#include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
@ -19,8 +18,9 @@
#include "src/gpu/GrResourceProvider.h" #include "src/gpu/GrResourceProvider.h"
#include "src/gpu/GrTexture.h" #include "src/gpu/GrTexture.h"
#include "src/gpu/GrTextureProxy.h" #include "src/gpu/GrTextureProxy.h"
#include "include/core/SkImage.h"
#include "src/gpu/SkGr.h" #include "src/gpu/SkGr.h"
#include "tools/gpu/ManagedBackendTexture.h"
#ifdef SK_DAWN #ifdef SK_DAWN
#include "src/gpu/dawn/GrDawnGpu.h" #include "src/gpu/dawn/GrDawnGpu.h"
@ -96,26 +96,29 @@ static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, GrRe
return proxy; return proxy;
} }
static sk_sp<GrTextureProxy> create_wrapped_backend(GrDirectContext* dContext) { static sk_sp<GrTextureProxy> create_wrapped_backend(GrDirectContext* dContext,
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( SkBackingFit fit,
dContext, sk_sp<GrTexture>* backingSurface) {
kSize.width(), GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
kSize.height(), GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
GrColorTypeToSkColorType(kColorType),
GrMipmapped::kNo, GrBackendFormat format =
GrRenderable::kNo, proxyProvider->caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
GrProtected::kNo);
if (!mbet) { *backingSurface =
resourceProvider->createTexture(kSize, format, GrRenderable::kNo, 1, GrMipmapped::kNo,
SkBudgeted::kNo, GrProtected::kNo);
if (!(*backingSurface)) {
return nullptr; return nullptr;
} }
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
return proxyProvider->wrapBackendTexture(mbet->texture(), GrBackendTexture backendTex = (*backingSurface)->getBackendTexture();
kBorrow_GrWrapOwnership,
GrWrapCacheable::kYes, return proxyProvider->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership,
kRead_GrIOType, GrWrapCacheable::kYes, kRead_GrIOType);
mbet->refCountedCallback());
} }
// This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning // This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning
// and looking them up work, etc. // and looking them up work, etc.
static void basic_test(GrDirectContext* dContext, static void basic_test(GrDirectContext* dContext,
@ -335,11 +338,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) {
} }
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
sk_sp<GrTexture> backingTex;
sk_sp<GrTextureProxy> proxy = create_wrapped_backend(direct, fit, &backingTex);
basic_test(direct, reporter, std::move(proxy));
backingTex = nullptr;
cache->purgeAllUnlocked(); cache->purgeAllUnlocked();
} }
basic_test(direct, reporter, create_wrapped_backend(direct));
invalidation_test(direct, reporter); invalidation_test(direct, reporter);
invalidation_and_instantiation_test(direct, reporter); invalidation_and_instantiation_test(direct, reporter);
} }

View File

@ -11,11 +11,15 @@
#if defined(SK_VULKAN) #if defined(SK_VULKAN)
#include "include/gpu/vk/GrVkVulkan.h"
#include "tests/Test.h"
#include "tests/TestUtils.h"
#include "include/core/SkImage.h" #include "include/core/SkImage.h"
#include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
#include "include/gpu/vk/GrVkTypes.h" #include "include/gpu/vk/GrVkTypes.h"
#include "include/gpu/vk/GrVkVulkan.h"
#include "src/gpu/GrRenderTargetContext.h" #include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrTexture.h" #include "src/gpu/GrTexture.h"
#include "src/gpu/GrTextureProxy.h" #include "src/gpu/GrTextureProxy.h"
@ -26,50 +30,41 @@
#include "src/image/SkImage_Base.h" #include "src/image/SkImage_Base.h"
#include "src/image/SkImage_GpuBase.h" #include "src/image/SkImage_GpuBase.h"
#include "src/image/SkSurface_Gpu.h" #include "src/image/SkSurface_Gpu.h"
#include "tests/Test.h"
#include "tools/gpu/ManagedBackendTexture.h"
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) { DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) {
auto dContext = ctxInfo.directContext(); auto dContext = ctxInfo.directContext();
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( GrBackendTexture backendTex;
dContext, 1, 1, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo); CreateBackendTexture(dContext, &backendTex, 1, 1, kRGBA_8888_SkColorType,
if (!mbet) { SkColors::kTransparent, GrMipmapped::kNo,
ERRORF(reporter, "Could not create backend texture."); GrRenderable::kNo, GrProtected::kNo);
return; REPORTER_ASSERT(reporter, backendTex.isValid());
}
GrVkImageInfo info; GrVkImageInfo info;
REPORTER_ASSERT(reporter, mbet->texture().getVkImageInfo(&info)); REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
VkImageLayout initLayout = info.fImageLayout; VkImageLayout initLayout = info.fImageLayout;
// Verify that setting that layout via a copy of a backendTexture is reflected in all the // Verify that setting that layout via a copy of a backendTexture is reflected in all the
// backendTextures. // backendTextures.
GrBackendTexture backendTex1 = mbet->texture(); GrBackendTexture backendTexCopy = backendTex;
GrBackendTexture backendTex2 = backendTex1; REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, backendTex2.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout); REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
backendTex2.setVkImageLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); backendTexCopy.setVkImageLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
REPORTER_ASSERT(reporter, backendTex1.getVkImageInfo(&info)); REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout); REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout);
REPORTER_ASSERT(reporter, backendTex2.getVkImageInfo(&info)); REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout); REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout);
// Setting back the layout since we didn't actually change it // Setting back the layout since we didn't actually change it
backendTex1.setVkImageLayout(initLayout); backendTex.setVkImageLayout(initLayout);
sk_sp<SkImage> wrappedImage = SkImage::MakeFromTexture( sk_sp<SkImage> wrappedImage = SkImage::MakeFromTexture(dContext, backendTex,
dContext,
backendTex1,
kTopLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType, kRGBA_8888_SkColorType,
kPremul_SkAlphaType, kPremul_SkAlphaType, nullptr);
/*color space*/ nullptr,
sk_gpu_test::ManagedBackendTexture::ReleaseProc,
mbet->releaseContext());
REPORTER_ASSERT(reporter, wrappedImage.get()); REPORTER_ASSERT(reporter, wrappedImage.get());
const GrSurfaceProxyView* view = as_IB(wrappedImage)->view(dContext); const GrSurfaceProxyView* view = as_IB(wrappedImage)->view(dContext);
@ -83,7 +78,7 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) {
REPORTER_ASSERT(reporter, initLayout == vkTexture->currentLayout()); REPORTER_ASSERT(reporter, initLayout == vkTexture->currentLayout());
vkTexture->updateImageLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); vkTexture->updateImageLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
REPORTER_ASSERT(reporter, backendTex1.getVkImageInfo(&info)); REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == info.fImageLayout); REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == info.fImageLayout);
GrBackendTexture backendTexImage = wrappedImage->getBackendTexture(false); GrBackendTexture backendTexImage = wrappedImage->getBackendTexture(false);
@ -96,10 +91,10 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) {
vkTexture->updateImageLayout(initLayout); vkTexture->updateImageLayout(initLayout);
REPORTER_ASSERT(reporter, backendTex1.getVkImageInfo(&info)); REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout); REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
REPORTER_ASSERT(reporter, backendTex2.getVkImageInfo(&info)); REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout); REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
REPORTER_ASSERT(reporter, backendTexImage.getVkImageInfo(&info)); REPORTER_ASSERT(reporter, backendTexImage.getVkImageInfo(&info));
@ -108,23 +103,25 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) {
// Check that we can do things like assigning the backend texture to invalid one, assign an // Check that we can do things like assigning the backend texture to invalid one, assign an
// invalid one, assin a backend texture to inself etc. Success here is that we don't hit any of // invalid one, assin a backend texture to inself etc. Success here is that we don't hit any of
// our ref counting asserts. // our ref counting asserts.
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex1, backendTex2)); REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex, backendTexCopy));
GrBackendTexture invalidTexture; GrBackendTexture invalidTexture;
REPORTER_ASSERT(reporter, !invalidTexture.isValid()); REPORTER_ASSERT(reporter, !invalidTexture.isValid());
REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex2)); REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTexCopy));
backendTex2 = invalidTexture; backendTexCopy = invalidTexture;
REPORTER_ASSERT(reporter, !backendTex2.isValid()); REPORTER_ASSERT(reporter, !backendTexCopy.isValid());
REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex2)); REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTexCopy));
invalidTexture = backendTex1; invalidTexture = backendTex;
REPORTER_ASSERT(reporter, invalidTexture.isValid()); REPORTER_ASSERT(reporter, invalidTexture.isValid());
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex1)); REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex));
invalidTexture = static_cast<decltype(invalidTexture)&>(invalidTexture); invalidTexture = static_cast<decltype(invalidTexture)&>(invalidTexture);
REPORTER_ASSERT(reporter, invalidTexture.isValid()); REPORTER_ASSERT(reporter, invalidTexture.isValid());
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, invalidTexture)); REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, invalidTexture));
dContext->deleteBackendTexture(backendTex);
} }
// This test is disabled because it executes illegal vulkan calls which cause the validations layers // This test is disabled because it executes illegal vulkan calls which cause the validations layers

View File

@ -11,19 +11,21 @@
#if defined(SK_VULKAN) #if defined(SK_VULKAN)
#include "include/gpu/vk/GrVkVulkan.h"
#include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
#include "include/gpu/vk/GrVkTypes.h"
#include "include/gpu/vk/GrVkVulkan.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrRenderTarget.h" #include "src/gpu/GrRenderTarget.h"
#include "src/gpu/GrTexture.h" #include "src/gpu/GrTexture.h"
#include "tools/gpu/GrContextFactory.h"
#include "include/gpu/vk/GrVkTypes.h"
#include "src/gpu/vk/GrVkCaps.h" #include "src/gpu/vk/GrVkCaps.h"
#include "src/gpu/vk/GrVkGpu.h" #include "src/gpu/vk/GrVkGpu.h"
#include "src/gpu/vk/GrVkMemory.h" #include "src/gpu/vk/GrVkMemory.h"
#include "tests/Test.h" #include "tests/Test.h"
#include "tools/gpu/GrContextFactory.h" #include "tests/TestUtils.h"
#include "tools/gpu/ManagedBackendTexture.h"
using sk_gpu_test::GrContextFactory; using sk_gpu_test::GrContextFactory;
@ -32,36 +34,30 @@ const int kH = 1024;
const SkColorType kColorType = SkColorType::kRGBA_8888_SkColorType; const SkColorType kColorType = SkColorType::kRGBA_8888_SkColorType;
void wrap_tex_test(skiatest::Reporter* reporter, GrDirectContext* dContext) { void wrap_tex_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
GrGpu* gpu = dContext->priv().getGpu(); GrGpu* gpu = dContext->priv().getGpu();
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( GrBackendTexture origBackendTex;
dContext, kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo); CreateBackendTexture(dContext, &origBackendTex, kW, kH, kColorType, SkColors::kTransparent,
if (!mbet) { GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
ERRORF(reporter, "Could not create backend texture.");
return;
}
GrBackendTexture origBackendTex = mbet->texture();
GrVkImageInfo imageInfo; GrVkImageInfo imageInfo;
SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
{
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership, sk_sp<GrTexture> tex = gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership,
GrWrapCacheable::kNo, kRead_GrIOType); GrWrapCacheable::kNo, kRead_GrIOType);
REPORTER_ASSERT(reporter, tex); REPORTER_ASSERT(reporter, tex);
}
// image is null // image is null
{ {
GrVkImageInfo backendCopy = imageInfo; GrVkImageInfo backendCopy = imageInfo;
backendCopy.fImage = VK_NULL_HANDLE; backendCopy.fImage = VK_NULL_HANDLE;
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
sk_sp<GrTexture> tex = gpu->wrapBackendTexture( tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); kRead_GrIOType);
REPORTER_ASSERT(reporter, !tex); REPORTER_ASSERT(reporter, !tex);
tex = gpu->wrapBackendTexture( tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); kRead_GrIOType);
REPORTER_ASSERT(reporter, !tex); REPORTER_ASSERT(reporter, !tex);
} }
@ -70,11 +66,11 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
GrVkImageInfo backendCopy = imageInfo; GrVkImageInfo backendCopy = imageInfo;
backendCopy.fAlloc = GrVkAlloc(); backendCopy.fAlloc = GrVkAlloc();
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
sk_sp<GrTexture> tex = gpu->wrapBackendTexture( tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); kRead_GrIOType);
REPORTER_ASSERT(reporter, tex); REPORTER_ASSERT(reporter, tex);
tex = gpu->wrapBackendTexture( tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); kRead_GrIOType);
REPORTER_ASSERT(reporter, !tex); REPORTER_ASSERT(reporter, !tex);
} }
@ -82,34 +78,37 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
{ {
GrVkImageInfo backendCopy = imageInfo; GrVkImageInfo backendCopy = imageInfo;
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
sk_sp<GrTexture> tex = gpu->wrapBackendTexture( tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); kRead_GrIOType);
REPORTER_ASSERT(reporter, tex); REPORTER_ASSERT(reporter, tex);
if (tex) {
mbet->wasAdopted();
} }
// image has MSAA
{
GrVkImageInfo backendCopy = imageInfo;
backendCopy.fSampleCount = 4;
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
kRead_GrIOType);
REPORTER_ASSERT(reporter, !tex);
tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
kRead_GrIOType);
REPORTER_ASSERT(reporter, !tex);
} }
} }
void wrap_rt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) { void wrap_rt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
GrGpu* gpu = dContext->priv().getGpu(); GrGpu* gpu = dContext->priv().getGpu();
GrColorType ct = SkColorTypeToGrColorType(kColorType);
for (int sampleCnt : {1, 4}) { GrBackendTexture origBackendTex;
GrBackendFormat format = gpu->caps()->getDefaultBackendFormat(ct, GrRenderable::kYes); CreateBackendTexture(dContext, &origBackendTex, kW, kH, kColorType, SkColors::kTransparent,
if (sampleCnt > gpu->caps()->maxRenderTargetSampleCount(format)) { GrMipmapped::kNo, GrRenderable::kYes, GrProtected::kNo);
continue;
}
GrBackendRenderTarget origBackendRT =
gpu->createTestingOnlyBackendRenderTarget({kW, kH}, ct, sampleCnt);
if (!origBackendRT.isValid()) {
ERRORF(reporter, "Could not create backend render target.");
}
GrVkImageInfo imageInfo; GrVkImageInfo imageInfo;
REPORTER_ASSERT(reporter, origBackendRT.getVkImageInfo(&imageInfo)); SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
GrBackendRenderTarget origBackendRT(kW, kH, 1, imageInfo);
sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(origBackendRT); sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(origBackendRT);
REPORTER_ASSERT(reporter, rt); REPORTER_ASSERT(reporter, rt);
@ -133,20 +132,30 @@ void wrap_rt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
REPORTER_ASSERT(reporter, rt); REPORTER_ASSERT(reporter, rt);
} }
gpu->deleteTestingOnlyBackendRenderTarget(origBackendRT); // Image has MSAA
{
GrColorType ct = SkColorTypeToGrColorType(kColorType);
GrGpu* gpu = dContext->priv().getGpu();
GrBackendRenderTarget backendRT =
gpu->createTestingOnlyBackendRenderTarget({kW, kW}, ct, 4);
if (backendRT.isValid()) {
rt = gpu->wrapBackendRenderTarget(backendRT);
REPORTER_ASSERT(reporter, rt);
dContext->priv().getGpu()->deleteTestingOnlyBackendRenderTarget(backendRT);
} }
}
// When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the
// resource when we're done.
dContext->deleteBackendTexture(origBackendTex);
} }
void wrap_trt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) { void wrap_trt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
GrGpu* gpu = dContext->priv().getGpu(); GrGpu* gpu = dContext->priv().getGpu();
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( GrBackendTexture origBackendTex;
dContext, kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kYes); CreateBackendTexture(dContext, &origBackendTex, kW, kH, kColorType, SkColors::kTransparent,
if (!mbet) { GrMipmapped::kNo, GrRenderable::kYes, GrProtected::kNo);
ERRORF(reporter, "Could not create renderable backend texture.");
return;
}
GrBackendTexture origBackendTex = mbet->texture();
GrVkImageInfo imageInfo; GrVkImageInfo imageInfo;
SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
@ -181,6 +190,15 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
REPORTER_ASSERT(reporter, !tex); REPORTER_ASSERT(reporter, !tex);
} }
// check adopt creation
{
GrVkImageInfo backendCopy = imageInfo;
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership,
GrWrapCacheable::kNo);
REPORTER_ASSERT(reporter, tex);
}
// check rendering with MSAA // check rendering with MSAA
{ {
int maxSamples = dContext->priv().caps()->maxRenderTargetSampleCount( int maxSamples = dContext->priv().caps()->maxRenderTargetSampleCount(
@ -191,16 +209,14 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
REPORTER_ASSERT(reporter, SkToBool(tex) == shouldSucceed); REPORTER_ASSERT(reporter, SkToBool(tex) == shouldSucceed);
} }
// check adopt creation // Image has MSAA
{ {
GrVkImageInfo backendCopy = imageInfo; GrVkImageInfo backendCopy = imageInfo;
backendCopy.fSampleCount = 4;
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership, tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership,
GrWrapCacheable::kNo); GrWrapCacheable::kNo);
REPORTER_ASSERT(reporter, tex); REPORTER_ASSERT(reporter, !tex);
if (tex) {
mbet->wasAdopted();
}
} }
} }

View File

@ -323,9 +323,11 @@ static sk_sp<SkImage> draw_with_gpu(std::function<bool(SkCanvas*)> draw,
case SurfaceType::kBackendTexture: case SurfaceType::kBackendTexture:
surface = sk_gpu_test::MakeBackendTextureSurface(context, surface = sk_gpu_test::MakeBackendTextureSurface(context,
info, info.dimensions(),
kTopLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin,
FLAGS_samples, FLAGS_samples,
info.colorType(),
info.refColorSpace(),
GrMipmapped::kNo, GrMipmapped::kNo,
GrProtected::kNo, GrProtected::kNo,
&props); &props);
@ -333,9 +335,11 @@ static sk_sp<SkImage> draw_with_gpu(std::function<bool(SkCanvas*)> draw,
case SurfaceType::kBackendRenderTarget: case SurfaceType::kBackendRenderTarget:
surface = sk_gpu_test::MakeBackendRenderTargetSurface(context, surface = sk_gpu_test::MakeBackendRenderTargetSurface(context,
info, info.dimensions(),
kBottomLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin,
FLAGS_samples, FLAGS_samples,
info.colorType(),
info.refColorSpace(),
GrProtected::kNo, GrProtected::kNo,
&props); &props);
break; break;

View File

@ -15,38 +15,7 @@
namespace sk_gpu_test { namespace sk_gpu_test {
sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext* dContext, sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext* context,
const SkImageInfo& ii,
GrSurfaceOrigin origin,
int sampleCnt,
GrMipmapped mipMapped,
GrProtected isProtected,
const SkSurfaceProps* props) {
if (ii.alphaType() == kUnpremul_SkAlphaType) {
return nullptr;
}
auto mbet = ManagedBackendTexture::MakeWithoutData(dContext,
ii.width(),
ii.height(),
ii.colorType(),
mipMapped,
GrRenderable::kYes,
isProtected);
if (!mbet) {
return nullptr;
}
return SkSurface::MakeFromBackendTexture(dContext,
mbet->texture(),
origin,
sampleCnt,
ii.colorType(),
ii.refColorSpace(),
props,
ManagedBackendTexture::ReleaseProc,
mbet->releaseContext());
}
sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext* dContext,
SkISize dimensions, SkISize dimensions,
GrSurfaceOrigin origin, GrSurfaceOrigin origin,
int sampleCnt, int sampleCnt,
@ -55,29 +24,45 @@ sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext* dContext,
GrMipmapped mipMapped, GrMipmapped mipMapped,
GrProtected isProtected, GrProtected isProtected,
const SkSurfaceProps* props) { const SkSurfaceProps* props) {
auto ii = SkImageInfo::Make(dimensions, colorType, kPremul_SkAlphaType, std::move(colorSpace)); auto mbet = ManagedBackendTexture::MakeWithoutData(context,
return MakeBackendTextureSurface( dimensions.fWidth,
dContext, ii, origin, sampleCnt, mipMapped, isProtected, props); dimensions.fHeight,
} colorType,
sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* dContext, mipMapped,
const SkImageInfo& ii, GrRenderable::kYes,
GrSurfaceOrigin origin, isProtected);
int sampleCnt, if (!mbet) {
GrProtected isProtected,
const SkSurfaceProps* props) {
if (ii.alphaType() == kUnpremul_SkAlphaType) {
return nullptr; return nullptr;
} }
auto ct = SkColorTypeToGrColorType(ii.colorType()); return SkSurface::MakeFromBackendTexture(context,
mbet->texture(),
origin,
sampleCnt,
colorType,
std::move(colorSpace),
props,
ManagedBackendTexture::ReleaseProc,
mbet->releaseContext());
}
sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* context,
SkISize dimensions,
GrSurfaceOrigin origin,
int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
GrProtected isProtected,
const SkSurfaceProps* props) {
auto ct = SkColorTypeToGrColorType(colorType);
struct ReleaseContext { struct ReleaseContext {
GrDirectContext* fContext; GrDirectContext* fContext;
GrBackendRenderTarget fRenderTarget; GrBackendRenderTarget fRenderTarget;
}; };
auto bert = dContext->priv().getGpu()->createTestingOnlyBackendRenderTarget( auto bert = context->priv().getGpu()->createTestingOnlyBackendRenderTarget(
ii.dimensions(), ct, sampleCnt, isProtected); dimensions, ct, sampleCnt, isProtected);
auto rc = new ReleaseContext{dContext, bert}; auto rc = new ReleaseContext{context, bert};
SkASSERT(!bert.isValid() || bert.sampleCnt() >= sampleCnt); SkASSERT(!bert.isValid() || bert.sampleCnt() >= sampleCnt);
auto proc = [](void* c) { auto proc = [](void* c) {
@ -89,19 +74,7 @@ sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* dContext,
}; };
return SkSurface::MakeFromBackendRenderTarget( return SkSurface::MakeFromBackendRenderTarget(
dContext, bert, origin, ii.colorType(), ii.refColorSpace(), props, proc, rc); context, bert, origin, colorType, std::move(colorSpace), props, proc, rc);
}
sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* dContext,
SkISize dimensions,
GrSurfaceOrigin origin,
int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
GrProtected isProtected,
const SkSurfaceProps* props) {
auto ii = SkImageInfo::Make(dimensions, colorType, kPremul_SkAlphaType, std::move(colorSpace));
return MakeBackendRenderTargetSurface(dContext, ii, origin, sampleCnt, isProtected, props);
} }
} // namespace sk_gpu_test } // namespace sk_gpu_test

View File

@ -19,14 +19,6 @@ class SkSurfaceProps;
namespace sk_gpu_test { namespace sk_gpu_test {
sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext*,
const SkImageInfo&,
GrSurfaceOrigin,
int sampleCnt,
GrMipmapped = GrMipmapped::kNo,
GrProtected = GrProtected::kNo,
const SkSurfaceProps* = nullptr);
sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext*, sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext*,
SkISize, SkISize,
GrSurfaceOrigin, GrSurfaceOrigin,
@ -38,13 +30,6 @@ sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext*,
const SkSurfaceProps* = nullptr); const SkSurfaceProps* = nullptr);
/** Creates an SkSurface backed by a non-textureable render target. */ /** Creates an SkSurface backed by a non-textureable render target. */
sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext*,
const SkImageInfo&,
GrSurfaceOrigin,
int sampleCnt,
GrProtected = GrProtected::kNo,
const SkSurfaceProps* = nullptr);
sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext*, sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext*,
SkISize, SkISize,
GrSurfaceOrigin, GrSurfaceOrigin,

View File

@ -40,36 +40,4 @@ sk_sp<SkImage> MakeBackendTextureImage(GrDirectContext* dContext,
ManagedBackendTexture::ReleaseProc, ManagedBackendTexture::ReleaseProc,
mbet->releaseContext()); mbet->releaseContext());
} }
sk_sp<SkImage> MakeBackendTextureImage(GrDirectContext* dContext,
const SkImageInfo& info,
SkColor4f color,
GrMipmapped mipmapped,
GrRenderable renderable,
GrSurfaceOrigin origin) {
if (info.alphaType() == kOpaque_SkAlphaType) {
color = color.makeOpaque();
} else if (info.alphaType() == kPremul_SkAlphaType) {
auto pmColor = color.premul();
color = {pmColor.fR, pmColor.fG, pmColor.fB, pmColor.fA};
}
auto mbet = ManagedBackendTexture::MakeWithData(dContext,
info.width(),
info.height(),
info.colorType(),
color,
mipmapped,
renderable,
GrProtected::kNo);
return SkImage::MakeFromTexture(dContext,
mbet->texture(),
origin,
info.colorType(),
info.alphaType(),
info.refColorSpace(),
ManagedBackendTexture::ReleaseProc,
mbet->releaseContext());
}
} // namespace sk_gpu_test } // namespace sk_gpu_test

View File

@ -5,15 +5,12 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include "include/core/SkColor.h"
#include "include/core/SkRefCnt.h" #include "include/core/SkRefCnt.h"
#include "include/gpu/GrTypes.h" #include "include/gpu/GrTypes.h"
class GrDirectContext; class GrDirectContext;
class SkColorSpace;
class SkImage; class SkImage;
class SkPixmap; class SkPixmap;
struct SkISize;
namespace sk_gpu_test { namespace sk_gpu_test {
/** /**
@ -23,17 +20,6 @@ namespace sk_gpu_test {
* For testing purposes the texture can be made renderable to exercise different code paths for * For testing purposes the texture can be made renderable to exercise different code paths for
* renderable textures/formats. * renderable textures/formats.
*/ */
sk_sp<SkImage> MakeBackendTextureImage(GrDirectContext*, sk_sp<SkImage> MakeBackendTextureImage(GrDirectContext*, const SkPixmap&,
const SkPixmap&, GrRenderable, GrSurfaceOrigin);
GrRenderable,
GrSurfaceOrigin);
/** Creates an image of with a solid color. */
sk_sp<SkImage> MakeBackendTextureImage(GrDirectContext*,
const SkImageInfo& info,
SkColor4f,
GrMipmapped = GrMipmapped::kNo,
GrRenderable = GrRenderable::kNo,
GrSurfaceOrigin = GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin);
} // namespace sk_gpu_test } // namespace sk_gpu_test

View File

@ -7,27 +7,10 @@
#include "tools/gpu/ManagedBackendTexture.h" #include "tools/gpu/ManagedBackendTexture.h"
#include "include/core/SkImageInfo.h"
#include "include/private/GrTypesPriv.h"
#include "src/core/SkMipmap.h"
namespace {
struct Context {
sk_sp<sk_gpu_test::ManagedBackendTexture> fMBET;
GrGpuFinishedProc fWrappedProc = nullptr;
GrGpuFinishedContext fWrappedContext = nullptr;
};
} // anonymous namespace
namespace sk_gpu_test { namespace sk_gpu_test {
void ManagedBackendTexture::ReleaseProc(void* ctx) { void ManagedBackendTexture::ReleaseProc(void* context) {
std::unique_ptr<Context> context(static_cast<Context*>(ctx)); static_cast<ManagedBackendTexture*>(context)->unref();
if (context->fWrappedProc) {
context->fWrappedProc(context->fWrappedContext);
}
} }
ManagedBackendTexture::~ManagedBackendTexture() { ManagedBackendTexture::~ManagedBackendTexture() {
@ -36,49 +19,9 @@ ManagedBackendTexture::~ManagedBackendTexture() {
} }
} }
void* ManagedBackendTexture::releaseContext(GrGpuFinishedProc wrappedProc, void* ManagedBackendTexture::releaseContext() {
GrGpuFinishedContext wrappedCtx) const { this->ref();
// Make sure we don't get a wrapped ctx without a wrapped proc return static_cast<void*>(this);
SkASSERT(!wrappedCtx || wrappedProc);
return new Context{sk_ref_sp(this), wrappedProc, wrappedCtx};
}
sk_sp<GrRefCntedCallback> ManagedBackendTexture::refCountedCallback() const {
return sk_make_sp<GrRefCntedCallback>(ReleaseProc, this->releaseContext());
}
void ManagedBackendTexture::wasAdopted() { fTexture = {}; }
sk_sp<ManagedBackendTexture> ManagedBackendTexture::MakeFromInfo(GrDirectContext* dContext,
const SkImageInfo& ii,
GrMipmapped mipmapped,
GrRenderable renderable,
GrProtected isProtected) {
return MakeWithoutData(
dContext, ii.width(), ii.height(), ii.colorType(), mipmapped, renderable, isProtected);
}
sk_sp<ManagedBackendTexture> ManagedBackendTexture::MakeFromBitmap(GrDirectContext* dContext,
const SkBitmap& bitmap,
GrMipmapped mipmapped,
GrRenderable renderable,
GrProtected isProtected) {
std::vector<SkPixmap> levels({bitmap.pixmap()});
std::unique_ptr<SkMipmap> mm;
if (mipmapped == GrMipmapped::kYes) {
mm.reset(SkMipmap::Build(bitmap, nullptr));
if (!mm) {
return nullptr;
}
for (int i = 0; i < mm->countLevels(); ++i) {
SkMipmap::Level level;
SkAssertResult(mm->getLevel(i, &level));
levels.push_back(level.fPixmap);
}
}
return MakeWithData(
dContext, levels.data(), static_cast<int>(levels.size()), renderable, isProtected);
} }
} // namespace sk_gpu_test } // namespace sk_gpu_test

View File

@ -11,9 +11,6 @@
#include "include/core/SkRefCnt.h" #include "include/core/SkRefCnt.h"
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
class GrRefCntedCallback;
struct SkImageInfo;
namespace sk_gpu_test { namespace sk_gpu_test {
class ManagedBackendTexture : public SkNVRefCnt<ManagedBackendTexture> { class ManagedBackendTexture : public SkNVRefCnt<ManagedBackendTexture> {
@ -37,19 +34,6 @@ public:
template <typename... Args> template <typename... Args>
static sk_sp<ManagedBackendTexture> MakeWithoutData(GrDirectContext*, Args&&...); static sk_sp<ManagedBackendTexture> MakeWithoutData(GrDirectContext*, Args&&...);
static sk_sp<ManagedBackendTexture> MakeFromInfo(GrDirectContext* dContext,
const SkImageInfo&,
GrMipmapped = GrMipmapped::kNo,
GrRenderable = GrRenderable::kNo,
GrProtected = GrProtected::kNo);
static sk_sp<ManagedBackendTexture> MakeFromBitmap(GrDirectContext*,
const SkBitmap&,
GrMipmapped,
GrRenderable,
GrProtected = GrProtected::kNo);
/** GrGpuFinishedProc or image/surface release proc. */ /** GrGpuFinishedProc or image/surface release proc. */
static void ReleaseProc(void* context); static void ReleaseProc(void* context);
@ -57,18 +41,9 @@ public:
/** /**
* The context to use with ReleaseProc. This adds a ref so it *must* be balanced by a call to * The context to use with ReleaseProc. This adds a ref so it *must* be balanced by a call to
* ReleaseProc. If a wrappedProc is provided then it will be called by ReleaseProc. * ReleaseProc.
*/ */
void* releaseContext(GrGpuFinishedProc wrappedProc = nullptr, void* releaseContext();
GrGpuFinishedContext wrappedContext = nullptr) const;
sk_sp<GrRefCntedCallback> refCountedCallback() const;
/**
* Call if the underlying GrBackendTexture was adopted by a GrContext. This clears this out the
* MBET without deleting the texture.
*/
void wasAdopted();
const GrBackendTexture& texture() { return fTexture; } const GrBackendTexture& texture() { return fTexture; }
@ -77,7 +52,7 @@ private:
ManagedBackendTexture(const ManagedBackendTexture&) = delete; ManagedBackendTexture(const ManagedBackendTexture&) = delete;
ManagedBackendTexture(ManagedBackendTexture&&) = delete; ManagedBackendTexture(ManagedBackendTexture&&) = delete;
sk_sp<GrDirectContext> fDContext; GrDirectContext* fDContext = nullptr;
GrBackendTexture fTexture; GrBackendTexture fTexture;
}; };
@ -85,7 +60,7 @@ template <typename... Args>
inline sk_sp<ManagedBackendTexture> ManagedBackendTexture::MakeWithData(GrDirectContext* dContext, inline sk_sp<ManagedBackendTexture> ManagedBackendTexture::MakeWithData(GrDirectContext* dContext,
Args&&... args) { Args&&... args) {
sk_sp<ManagedBackendTexture> mbet(new ManagedBackendTexture); sk_sp<ManagedBackendTexture> mbet(new ManagedBackendTexture);
mbet->fDContext = sk_ref_sp(dContext); mbet->fDContext = dContext;
mbet->fTexture = dContext->createBackendTexture(std::forward<Args>(args)..., mbet->fTexture = dContext->createBackendTexture(std::forward<Args>(args)...,
ReleaseProc, ReleaseProc,
mbet->releaseContext()); mbet->releaseContext());
@ -97,7 +72,7 @@ inline sk_sp<ManagedBackendTexture> ManagedBackendTexture::MakeWithoutData(
GrDirectContext* dContext, GrDirectContext* dContext,
Args&&... args) { Args&&... args) {
sk_sp<ManagedBackendTexture> mbet(new ManagedBackendTexture); sk_sp<ManagedBackendTexture> mbet(new ManagedBackendTexture);
mbet->fDContext = sk_ref_sp(dContext); mbet->fDContext = dContext;
mbet->fTexture = dContext->createBackendTexture(std::forward<Args>(args)...); mbet->fTexture = dContext->createBackendTexture(std::forward<Args>(args)...);
return mbet; return mbet;
} }

View File

@ -86,12 +86,6 @@ bool VkTestHelper::init() {
} }
void VkTestHelper::cleanup() { void VkTestHelper::cleanup() {
// Make sure any work, release procs, etc left on the context are finished with before we start
// tearing everything down.
if (fDirectContext) {
fDirectContext->flushAndSubmit(true);
}
fDirectContext.reset(); fDirectContext.reset();
fBackendContext.fMemoryAllocator.reset(); fBackendContext.fMemoryAllocator.reset();