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

Side by Side Diff: tests/EGLImageTest.cpp

Issue 1464593004: More tests for EGLImage (Closed) Base URL: https://skia.googlesource.com/skia.git@external
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/gl/GrGLGpu.cpp ('k') | no next file » | 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 static void test_read_pixels(skiatest::Reporter* reporter, GrContext* context,
41 GrTexture* externalTexture, uint32_t expectedPixelV alues[]) {
42 int pixelCnt = externalTexture->width() * externalTexture->height();
43 SkAutoTMalloc<uint32_t> pixels(pixelCnt);
44 memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt);
45 bool read = externalTexture->readPixels(0, 0, externalTexture->width(),
46 externalTexture->height(), kRGBA_888 8_GrPixelConfig,
47 pixels.get());
48 if (!read) {
49 ERRORF(reporter, "Error reading external texture.");
50 }
51 for (int i = 0; i < pixelCnt; ++i) {
52 if (pixels.get()[i] != expectedPixelValues[i]) {
53 ERRORF(reporter, "Error, external texture pixel value %d should be 0 x%08x,"
54 " got 0x%08x.", i, expectedPixelValues[i], pixels.g et()[i]);
55 break;
56 }
57 }
58 }
59
60 static void test_write_pixels(skiatest::Reporter* reporter, GrContext* context,
61 GrTexture* externalTexture) {
62 int pixelCnt = externalTexture->width() * externalTexture->height();
63 SkAutoTMalloc<uint32_t> pixels(pixelCnt);
64 memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt);
65 bool write = externalTexture->writePixels(0, 0, 0, 0, kRGBA_8888_GrPixelConf ig, pixels.get());
66 REPORTER_ASSERT_MESSAGE(reporter, !write, "Should not be able to write to a EXTERNAL"
67 " texture.");
68 }
69
70 static void test_copy_surface(skiatest::Reporter* reporter, GrContext* context,
71 GrTexture* externalTexture, uint32_t expectedPixel Values[]) {
72 GrSurfaceDesc copyDesc;
73 copyDesc.fConfig = kRGBA_8888_GrPixelConfig;
74 copyDesc.fWidth = externalTexture->width();
75 copyDesc.fHeight = externalTexture->height();
76 copyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
77 SkAutoTUnref<GrTexture> copy(context->textureProvider()->createTexture(copyD esc, true));
78 context->copySurface(copy, externalTexture);
79 test_read_pixels(reporter, context, copy, expectedPixelValues);
80 }
81
40 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(EGLImageTest, reporter, context0, glCtx0) { 82 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(EGLImageTest, reporter, context0, glCtx0) {
41 // Try to create a second GL context and then check if the contexts have nec essary 83 // Try to create a second GL context and then check if the contexts have nec essary
42 // extensions to run this test. 84 // extensions to run this test.
43 85
44 if (kGLES_GrGLStandard != glCtx0->gl()->fStandard) { 86 if (kGLES_GrGLStandard != glCtx0->gl()->fStandard) {
45 return; 87 return;
46 } 88 }
47 GrGLGpu* gpu0 = static_cast<GrGLGpu*>(context0->getGpu()); 89 GrGLGpu* gpu0 = static_cast<GrGLGpu*>(context0->getGpu());
48 if (!gpu0->glCaps().externalTextureSupport()) { 90 if (!gpu0->glCaps().externalTextureSupport()) {
49 return; 91 return;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 externalDesc.fHeight = kSize; 169 externalDesc.fHeight = kSize;
128 externalDesc.fTextureHandle = reinterpret_cast<GrBackendObject>(&externalTex ture); 170 externalDesc.fTextureHandle = reinterpret_cast<GrBackendObject>(&externalTex ture);
129 SkAutoTUnref<GrTexture> externalTextureObj( 171 SkAutoTUnref<GrTexture> externalTextureObj(
130 context0->textureProvider()->wrapBackendTexture(externalDesc)); 172 context0->textureProvider()->wrapBackendTexture(externalDesc));
131 if (!externalTextureObj) { 173 if (!externalTextureObj) {
132 ERRORF(reporter, "Error wrapping external texture in GrTexture."); 174 ERRORF(reporter, "Error wrapping external texture in GrTexture.");
133 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image); 175 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
134 return; 176 return;
135 } 177 }
136 178
137 // Read the pixels and see if we get the values set in GL context 1 179 // Should not be able to wrap as a RT
138 memset(pixels.get(), 0, sizeof(uint32_t)*kSize*kSize); 180 externalDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
139 bool read = externalTextureObj->readPixels(0, 0, kSize, kSize, kRGBA_8888_Gr PixelConfig, 181 SkAutoTUnref<GrTexture> externalTextureRTObj(
140 pixels.get()); 182 context0->textureProvider()->wrapBackendTexture(externalDesc));
141 if (!read) { 183 if (externalTextureRTObj) {
142 ERRORF(reporter, "Error reading external texture."); 184 ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture as a RT .");
143 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
144 return;
145 } 185 }
146 for (int i = 0; i < kSize*kSize; ++i) { 186 externalDesc.fFlags = kNone_GrBackendTextureFlag;
147 if (pixels.get()[i] != 0xDDAABBCC) { 187
148 ERRORF(reporter, "Error, external texture pixel value %d should be 0 xDDAABBCC," 188 // Should not be able to wrap with a sample count
149 " got 0x%08x.", pixels.get()[i]); 189 externalDesc.fSampleCnt = 4;
150 break; 190 SkAutoTUnref<GrTexture> externalTextureMSAAObj(
151 } 191 context0->textureProvider()->wrapBackendTexture(externalDesc));
192 if (externalTextureMSAAObj) {
193 ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture with MS AA.");
152 } 194 }
195 externalDesc.fSampleCnt = 0;
196
197 test_read_pixels(reporter, context0, externalTextureObj, pixels.get());
198
199 test_write_pixels(reporter, context0, externalTextureObj);
200
201 test_copy_surface(reporter, context0, externalTextureObj, pixels.get());
202
153 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, imag e); 203 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, imag e);
154 } 204 }
155 205
156 #endif 206 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698