1717#include " tests/Test.h"
1818#include " tests/TestUtils.h"
1919#include " tools/gpu/GrContextFactory.h"
20- #include " tools/gpu/ManagedBackendTexture.h"
2120#include " tools/gpu/gl/GLTestContext.h"
2221
2322#ifdef SK_GL
2423
2524using sk_gpu_test::GLTestContext;
2625
27- static void cleanup (GLTestContext* glctx0,
28- GrGLuint texID0,
29- GLTestContext* glctx1,
30- sk_sp<GrDirectContext> dContext,
26+ static void cleanup (GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx1,
27+ sk_sp<GrDirectContext> dContext, GrBackendTexture* backendTex1,
3128 GrEGLImage image1) {
3229 if (glctx1) {
3330 glctx1->makeCurrent ();
31+ if (dContext) {
32+ if (backendTex1 && backendTex1->isValid ()) {
33+ dContext->deleteBackendTexture (*backendTex1);
34+ }
35+ }
3436 if (GR_EGL_NO_IMAGE != image1) {
3537 glctx1->destroyEGLImage (image1);
3638 }
@@ -62,18 +64,19 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
6264 return ;
6365 }
6466 sk_sp<GrDirectContext> context1 = GrDirectContext::MakeGL (sk_ref_sp (glCtx1->gl ()));
67+ GrBackendTexture backendTexture1;
6568 GrEGLImage image = GR_EGL_NO_IMAGE;
6669 GrGLTextureInfo externalTexture;
6770 externalTexture.fID = 0 ;
6871
6972 if (!context1) {
70- cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, image);
73+ cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, &backendTexture1, image);
7174 return ;
7275 }
7376
7477 if (!glCtx1->gl ()->hasExtension (" EGL_KHR_image" ) ||
7578 !glCtx1->gl ()->hasExtension (" EGL_KHR_gl_texture_2D_image" )) {
76- cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, image);
79+ cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, &backendTexture1, image);
7780 return ;
7881 }
7982
@@ -83,33 +86,33 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
8386 context1->flushAndSubmit ();
8487 static const int kSize = 100 ;
8588
86- auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData (
87- context1. get (), kSize , kSize , kRGBA_8888_SkColorType , GrMipmapped::kNo ,
88- GrRenderable:: kNo , GrProtected::kNo );
89+ CreateBackendTexture (context1. get (), &backendTexture1, kSize , kSize , kRGBA_8888_SkColorType ,
90+ SkColors:: kTransparent , GrMipmapped:: kNo , GrRenderable ::kNo ,
91+ GrProtected::kNo );
8992
90- if (!mbet ) {
93+ if (!backendTexture1. isValid () ) {
9194 ERRORF (reporter, " Error creating texture for EGL Image" );
92- cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, image);
95+ cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, &backendTexture1, image);
9396 return ;
9497 }
9598
9699 GrGLTextureInfo texInfo;
97- if (!mbet-> texture () .getGLTextureInfo (&texInfo)) {
100+ if (!backendTexture1 .getGLTextureInfo (&texInfo)) {
98101 ERRORF (reporter, " Failed to get GrGLTextureInfo" );
99102 return ;
100103 }
101104
102105 if (GR_GL_TEXTURE_2D != texInfo.fTarget ) {
103106 ERRORF (reporter, " Expected backend texture to be 2D" );
104- cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, image);
107+ cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, &backendTexture1, image);
105108 return ;
106109 }
107110
108111 // Wrap the texture in an EGLImage
109112 image = glCtx1->texture2DToEGLImage (texInfo.fID );
110113 if (GR_EGL_NO_IMAGE == image) {
111114 ERRORF (reporter, " Error creating EGL Image from texture" );
112- cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, image);
115+ cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, &backendTexture1, image);
113116 return ;
114117 }
115118
@@ -144,7 +147,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
144147 externalTexture.fFormat = GR_GL_RGBA8;
145148 if (0 == externalTexture.fID ) {
146149 ERRORF (reporter, " Error converting EGL Image back to texture" );
147- cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, image);
150+ cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, &backendTexture1, image);
148151 return ;
149152 }
150153
@@ -160,7 +163,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
160163 backendTex, kBorrow_GrWrapOwnership , GrWrapCacheable::kNo , kRW_GrIOType );
161164 if (!texProxy) {
162165 ERRORF (reporter, " Error wrapping external texture in GrTextureProxy." );
163- cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, image);
166+ cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, &backendTexture1, image);
164167 return ;
165168 }
166169 GrSwizzle swizzle =
@@ -171,7 +174,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
171174
172175 if (!surfaceContext) {
173176 ERRORF (reporter, " Error wrapping external texture in GrSurfaceContext." );
174- cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, image);
177+ cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, &backendTexture1, image);
175178 return ;
176179 }
177180
@@ -203,7 +206,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
203206 TestCopyFromSurface (reporter, context0, surfaceContext->asSurfaceProxy (),
204207 surfaceContext->origin (), colorType, pixels.get (), " EGLImageTest-copy" );
205208
206- cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, image);
209+ cleanup (glCtx0, externalTexture.fID , glCtx1.get (), context1, &backendTexture1, image);
207210}
208211
209212#endif // SK_GL
0 commit comments