OLD | NEW |
---|---|
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 Loading... | |
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(EGLImageTest, reporter, factory) { | 82 DEF_GPUTEST(EGLImageTest, reporter, factory) { |
41 for (int glCtxType = 0; glCtxType < GrContextFactory::kGLContextTypeCnt; ++g lCtxType) { | 83 for (int glCtxType = 0; glCtxType < GrContextFactory::kGLContextTypeCnt; ++g lCtxType) { |
42 GrContextFactory::GLContextType type = (GrContextFactory::GLContextType) glCtxType; | 84 GrContextFactory::GLContextType type = (GrContextFactory::GLContextType) glCtxType; |
43 if (!GrContextFactory::IsRenderingGLContext(type)) { | 85 if (!GrContextFactory::IsRenderingGLContext(type)) { |
44 continue; | 86 continue; |
45 } | 87 } |
46 | 88 |
47 // Try to create a second GL context and then check if the contexts have necessary | 89 // Try to create a second GL context and then check if the contexts have necessary |
48 // extensions to run this test. | 90 // extensions to run this test. |
49 | 91 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 externalDesc.fHeight = kSize; | 175 externalDesc.fHeight = kSize; |
134 externalDesc.fTextureHandle = reinterpret_cast<GrBackendObject>(&externa lTexture); | 176 externalDesc.fTextureHandle = reinterpret_cast<GrBackendObject>(&externa lTexture); |
135 SkAutoTUnref<GrTexture> externalTextureObj( | 177 SkAutoTUnref<GrTexture> externalTextureObj( |
136 context0->textureProvider()->wrapBackendTexture(externalDesc)); | 178 context0->textureProvider()->wrapBackendTexture(externalDesc)); |
137 if (!externalTextureObj) { | 179 if (!externalTextureObj) { |
138 ERRORF(reporter, "Error wrapping external texture in GrTexture."); | 180 ERRORF(reporter, "Error wrapping external texture in GrTexture."); |
139 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTextur e1, image); | 181 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTextur e1, image); |
140 continue; | 182 continue; |
141 } | 183 } |
142 | 184 |
143 // Read the pixels and see if we get the values set in GL context 1 | 185 // Should not be able to wrap as a RT |
144 memset(pixels.get(), 0, sizeof(uint32_t)*kSize*kSize); | 186 externalDesc.fFlags = kRenderTarget_GrBackendTextureFlag; |
145 bool read = externalTextureObj->readPixels(0, 0, kSize, kSize, kRGBA_888 8_GrPixelConfig, | 187 SkAutoTUnref<GrTexture> externalTextureRTObj( |
146 pixels.get()); | 188 context0->textureProvider()->wrapBackendTexture(externalDesc)); |
147 if (!read) { | 189 if (externalTextureRTObj) { |
148 ERRORF(reporter, "Error reading external texture."); | 190 ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture as a RT."); |
149 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTextur e1, image); | |
150 continue; | |
151 } | 191 } |
152 for (int i = 0; i < kSize*kSize; ++i) { | 192 externalDesc.fFlags = kNone_GrBackendTextureFlag; |
153 if (pixels.get()[i] != 0xDDAABBCC) { | 193 |
154 ERRORF(reporter, "Error, external texture pixel value %d should be 0xDDAABBCC," | 194 // Should not be able to wrap with a sample count |
155 " got 0x%08x.", pixels.get()[i]); | 195 externalDesc.fSampleCnt = 4; |
156 break; | 196 SkAutoTUnref<GrTexture> externalTextureMSAAObj( |
157 } | 197 context0->textureProvider()->wrapBackendTexture(externalDesc)); |
198 if (externalTextureMSAAObj) { | |
199 ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture wit h MSAA."); | |
158 } | 200 } |
201 externalDesc.fSampleCnt = 0; | |
joshualitt
2015/11/20 22:57:04
is there a reason you set this to 0?
bsalomon
2015/11/23 15:05:14
Just in case someone added a third wrap test.
| |
202 | |
203 test_read_pixels(reporter, context0, externalTextureObj, pixels.get()); | |
204 | |
205 test_write_pixels(reporter, context0, externalTextureObj); | |
206 | |
207 test_copy_surface(reporter, context0, externalTextureObj, pixels.get()); | |
208 | |
159 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image); | 209 cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image); |
160 } | 210 } |
161 } | 211 } |
162 | 212 |
163 #endif | 213 #endif |
OLD | NEW |