Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Side by Side Diff: tests/EGLImageTest.cpp

Issue 1455093003: Remove GrContextFactory::getGLContext (Closed) Base URL: https://skia.googlesource.com/skia.git@commandbuffer-as-api-01-gpu-test-context-support
Patch Set: rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrContextFactory.h ('k') | tests/GLInterfaceValidationTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Test.h" 8 #include "Test.h"
9 #if SK_SUPPORT_GPU 9 #if SK_SUPPORT_GPU
10 #include "GrContext.h" 10 #include "GrContext.h"
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 glctx1->unref(); 31 glctx1->unref();
32 } 32 }
33 33
34 glctx0->makeCurrent(); 34 glctx0->makeCurrent();
35 if (texID0) { 35 if (texID0) {
36 GR_GL_CALL(glctx0->gl(), DeleteTextures(1, &texID0)); 36 GR_GL_CALL(glctx0->gl(), DeleteTextures(1, &texID0));
37 } 37 }
38 } 38 }
39 39
40 DEF_GPUTEST(EGLImageTest, reporter, factory) { 40 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(EGLImageTest, reporter, context0, glCtx0) {
41 for (int glCtxType = 0; glCtxType < GrContextFactory::kGLContextTypeCnt; ++g lCtxType) { 41 // Try to create a second GL context and then check if the contexts have nec essary
42 GrContextFactory::GLContextType type = (GrContextFactory::GLContextType) glCtxType; 42 // extensions to run this test.
43 if (!GrContextFactory::IsRenderingGLContext(type)) { 43
44 continue; 44 if (kGLES_GrGLStandard != glCtx0->gl()->fStandard) {
45 return;
46 }
47 GrGLGpu* gpu0 = static_cast<GrGLGpu*>(context0->getGpu());
48 if (!gpu0->glCaps().externalTextureSupport()) {
49 return;
50 }
51
52 SkGLContext* glCtx1 = glCtx0->createNew();
53 if (!glCtx1) {
54 return;
55 }
56 GrContext* context1 = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext )glCtx1->gl());
57 const GrGLTextureInfo* backendTexture1 = nullptr;
58 GrEGLImage image = GR_EGL_NO_IMAGE;
59 GrGLTextureInfo externalTexture;
60 externalTexture.fID = 0;
61
62 if (!context1) {
63 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
64 return;
65 }
66
67 if (!glCtx1->gl()->hasExtension("EGL_KHR_image") ||
68 !glCtx1->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) {
69 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
70 return;
71 }
72
73 ///////////////////////////////// CONTEXT 1 //////////////////////////////// ///
74
75 // Use GL Context 1 to create a texture unknown to GrContext.
76 context1->flush();
77 GrGpu* gpu1 = context1->getGpu();
78 static const int kSize = 100;
79 backendTexture1 = reinterpret_cast<const GrGLTextureInfo*>(
80 gpu1->createTestingOnlyBackendTexture(nullptr, kSize, kSize, kRGBA_8888_ GrPixelConfig));
81 if (!backendTexture1 || !backendTexture1->fID) {
82 ERRORF(reporter, "Error creating texture for EGL Image");
83 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
84 return;
85 }
86 if (GR_GL_TEXTURE_2D != backendTexture1->fTarget) {
87 ERRORF(reporter, "Expected backend texture to be 2D");
88 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
89 return;
90 }
91
92 // Wrap the texture in an EGLImage
93 image = glCtx1->texture2DToEGLImage(backendTexture1->fID);
94 if (GR_EGL_NO_IMAGE == image) {
95 ERRORF(reporter, "Error creating EGL Image from texture");
96 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
97 return;
98 }
99
100 // Populate the texture using GL context 1. Important to use TexSubImage as TexImage orphans
101 // the EGL image. Also, this must be done after creating the EGLImage as the texture
102 // contents may not be preserved when the image is created.
103 SkAutoTMalloc<uint32_t> pixels(kSize * kSize);
104 for (int i = 0; i < kSize*kSize; ++i) {
105 pixels.get()[i] = 0xDDAABBCC;
106 }
107 GR_GL_CALL(glCtx1->gl(), ActiveTexture(GR_GL_TEXTURE0));
108 GR_GL_CALL(glCtx1->gl(), BindTexture(backendTexture1->fTarget, backendTextur e1->fID));
109 GR_GL_CALL(glCtx1->gl(), TexSubImage2D(backendTexture1->fTarget, 0, 0, 0, kS ize, kSize,
110 GR_GL_RGBA, GR_GL_UNSIGNED_BYTE, pixe ls.get()));
111 GR_GL_CALL(glCtx1->gl(), Finish());
112 // We've been making direct GL calls in GL context 1, let GrContext 1 know i ts internal
113 // state is invalid.
114 context1->resetContext();
115
116 ///////////////////////////////// CONTEXT 0 //////////////////////////////// ///
117
118 // Make a new texture ID in GL Context 0 from the EGL Image
119 glCtx0->makeCurrent();
120 externalTexture.fTarget = GR_GL_TEXTURE_EXTERNAL;
121 externalTexture.fID = glCtx0->eglImageToExternalTexture(image);
122
123 // Wrap this texture ID in a GrTexture
124 GrBackendTextureDesc externalDesc;
125 externalDesc.fConfig = kRGBA_8888_GrPixelConfig;
126 externalDesc.fWidth = kSize;
127 externalDesc.fHeight = kSize;
128 externalDesc.fTextureHandle = reinterpret_cast<GrBackendObject>(&externalTex ture);
129 SkAutoTUnref<GrTexture> externalTextureObj(
130 context0->textureProvider()->wrapBackendTexture(externalDesc));
131 if (!externalTextureObj) {
132 ERRORF(reporter, "Error wrapping external texture in GrTexture.");
133 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
134 return;
135 }
136
137 // Read the pixels and see if we get the values set in GL context 1
138 memset(pixels.get(), 0, sizeof(uint32_t)*kSize*kSize);
139 bool read = externalTextureObj->readPixels(0, 0, kSize, kSize, kRGBA_8888_Gr PixelConfig,
140 pixels.get());
141 if (!read) {
142 ERRORF(reporter, "Error reading external texture.");
143 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
144 return;
145 }
146 for (int i = 0; i < kSize*kSize; ++i) {
147 if (pixels.get()[i] != 0xDDAABBCC) {
148 ERRORF(reporter, "Error, external texture pixel value %d should be 0 xDDAABBCC,"
149 " got 0x%08x.", pixels.get()[i]);
150 break;
45 } 151 }
46
47 // Try to create a second GL context and then check if the contexts have necessary
48 // extensions to run this test.
49
50 GrContext* context0 = factory->get(type);
51 if (!context0) {
52 continue;
53 }
54 SkGLContext* glCtx0 = factory->getGLContext(type);
55 SkASSERT(glCtx0);
56 if (kGLES_GrGLStandard != glCtx0->gl()->fStandard) {
57 continue;
58 }
59 GrGLGpu* gpu0 = static_cast<GrGLGpu*>(context0->getGpu());
60 if (!gpu0->glCaps().externalTextureSupport()) {
61 continue;
62 }
63
64 SkGLContext* glCtx1 = glCtx0->createNew();
65 if (!glCtx1) {
66 continue;
67 }
68 GrContext* context1 = GrContext::Create(kOpenGL_GrBackend, (GrBackendCon text)glCtx1->gl());
69 const GrGLTextureInfo* backendTexture1 = nullptr;
70 GrEGLImage image = GR_EGL_NO_IMAGE;
71 GrGLTextureInfo externalTexture;
72 externalTexture.fID = 0;
73
74 if (!context1) {
75 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTextur e1, image);
76 continue;
77 }
78
79 if (!glCtx1->gl()->hasExtension("EGL_KHR_image") ||
80 !glCtx1->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) {
81 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTextur e1, image);
82 continue;
83 }
84
85 ///////////////////////////////// CONTEXT 1 ///////////////////////////////////
86
87 // Use GL Context 1 to create a texture unknown to GrContext.
88 context1->flush();
89 GrGpu* gpu1 = context1->getGpu();
90 static const int kSize = 100;
91 backendTexture1 = reinterpret_cast<const GrGLTextureInfo*>(
92 gpu1->createTestingOnlyBackendTexture(nullptr, kSize, kSize, kRGBA_8 888_GrPixelConfig));
93 if (!backendTexture1 || !backendTexture1->fID) {
94 ERRORF(reporter, "Error creating texture for EGL Image");
95 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTextur e1, image);
96 continue;
97 }
98 if (GR_GL_TEXTURE_2D != backendTexture1->fTarget) {
99 ERRORF(reporter, "Expected backend texture to be 2D");
100 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTextur e1, image);
101 continue;
102 }
103
104 // Wrap the texture in an EGLImage
105 image = glCtx1->texture2DToEGLImage(backendTexture1->fID);
106 if (GR_EGL_NO_IMAGE == image) {
107 ERRORF(reporter, "Error creating EGL Image from texture");
108 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTextur e1, image);
109 continue;
110 }
111
112 // Populate the texture using GL context 1. Important to use TexSubImage as TexImage orphans
113 // the EGL image. Also, this must be done after creating the EGLImage as the texture
114 // contents may not be preserved when the image is created.
115 SkAutoTMalloc<uint32_t> pixels(kSize * kSize);
116 for (int i = 0; i < kSize*kSize; ++i) {
117 pixels.get()[i] = 0xDDAABBCC;
118 }
119 GR_GL_CALL(glCtx1->gl(), ActiveTexture(GR_GL_TEXTURE0));
120 GR_GL_CALL(glCtx1->gl(), BindTexture(backendTexture1->fTarget, backendTe xture1->fID));
121 GR_GL_CALL(glCtx1->gl(), TexSubImage2D(backendTexture1->fTarget, 0, 0, 0 , kSize, kSize,
122 GR_GL_RGBA, GR_GL_UNSIGNED_BYTE, pixels.get()));
123 GR_GL_CALL(glCtx1->gl(), Finish());
124 // We've been making direct GL calls in GL context 1, let GrContext 1 kn ow its internal
125 // state is invalid.
126 context1->resetContext();
127
128 ///////////////////////////////// CONTEXT 0 ///////////////////////////////////
129
130 // Make a new texture ID in GL Context 0 from the EGL Image
131 glCtx0->makeCurrent();
132 externalTexture.fTarget = GR_GL_TEXTURE_EXTERNAL;
133 externalTexture.fID = glCtx0->eglImageToExternalTexture(image);
134
135 // Wrap this texture ID in a GrTexture
136 GrBackendTextureDesc externalDesc;
137 externalDesc.fConfig = kRGBA_8888_GrPixelConfig;
138 externalDesc.fWidth = kSize;
139 externalDesc.fHeight = kSize;
140 externalDesc.fTextureHandle = reinterpret_cast<GrBackendObject>(&externa lTexture);
141 SkAutoTUnref<GrTexture> externalTextureObj(
142 context0->textureProvider()->wrapBackendTexture(externalDesc));
143 if (!externalTextureObj) {
144 ERRORF(reporter, "Error wrapping external texture in GrTexture.");
145 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTextur e1, image);
146 continue;
147 }
148
149 // Read the pixels and see if we get the values set in GL context 1
150 memset(pixels.get(), 0, sizeof(uint32_t)*kSize*kSize);
151 bool read = externalTextureObj->readPixels(0, 0, kSize, kSize, kRGBA_888 8_GrPixelConfig,
152 pixels.get());
153 if (!read) {
154 ERRORF(reporter, "Error reading external texture.");
155 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTextur e1, image);
156 continue;
157 }
158 for (int i = 0; i < kSize*kSize; ++i) {
159 if (pixels.get()[i] != 0xDDAABBCC) {
160 ERRORF(reporter, "Error, external texture pixel value %d should be 0xDDAABBCC,"
161 " got 0x%08x.", pixels.get()[i]);
162 break;
163 }
164 }
165 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
166 } 152 }
153 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, imag e);
167 } 154 }
168 155
169 #endif 156 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrContextFactory.h ('k') | tests/GLInterfaceValidationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698