OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
6 #include <GLES2/gl2ext.h> | 6 #include <GLES2/gl2ext.h> |
7 #include <GLES2/gl2extchromium.h> | 7 #include <GLES2/gl2extchromium.h> |
8 | 8 |
9 #include "gpu/command_buffer/client/gles2_lib.h" | 9 #include "gpu/command_buffer/client/gles2_lib.h" |
10 #include "gpu/command_buffer/common/mailbox.h" | 10 #include "gpu/command_buffer/common/mailbox.h" |
11 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 11 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
12 #include "gpu/command_buffer/service/mailbox_manager.h" | 12 #include "gpu/command_buffer/service/mailbox_manager.h" |
13 #include "gpu/command_buffer/tests/gl_manager.h" | 13 #include "gpu/command_buffer/tests/gl_manager.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/gl/gl_share_group.h" | 16 #include "ui/gl/gl_share_group.h" |
17 | 17 |
18 namespace gpu { | 18 namespace gpu { |
19 | 19 |
20 namespace { | 20 namespace { |
21 uint32 ReadTexel(GLuint id, GLint x, GLint y) { | 21 uint32 ReadTexel(GLuint id, GLint x, GLint y, GLenum format = GL_RGBA) { |
piman
2014/06/09 14:37:25
nit: no default argument in Chromium style.
| |
22 GLint old_fbo = 0; | 22 GLint old_fbo = 0; |
23 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo); | 23 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo); |
24 | 24 |
25 GLuint fbo; | 25 GLuint fbo; |
26 glGenFramebuffers(1, &fbo); | 26 glGenFramebuffers(1, &fbo); |
27 glBindFramebuffer(GL_FRAMEBUFFER, fbo); | 27 glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
28 glFramebufferTexture2D(GL_FRAMEBUFFER, | 28 glFramebufferTexture2D(GL_FRAMEBUFFER, |
29 GL_COLOR_ATTACHMENT0, | 29 GL_COLOR_ATTACHMENT0, |
30 GL_TEXTURE_2D, | 30 GL_TEXTURE_2D, |
31 id, | 31 id, |
32 0); | 32 0); |
33 // Some drivers (NVidia/SGX) require texture settings to be a certain way or | 33 // Some drivers (NVidia/SGX) require texture settings to be a certain way or |
34 // they won't report FRAMEBUFFER_COMPLETE. | 34 // they won't report FRAMEBUFFER_COMPLETE. |
35 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 35 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
36 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 36 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
37 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 37 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
38 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 38 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
39 | 39 |
40 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 40 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
41 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | 41 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
42 | 42 |
43 uint32 texel = 0; | 43 uint32 texel = 0; |
44 glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &texel); | 44 glReadPixels(x, y, 1, 1, format, GL_UNSIGNED_BYTE, &texel); |
45 | 45 |
46 glBindFramebuffer(GL_FRAMEBUFFER, old_fbo); | 46 glBindFramebuffer(GL_FRAMEBUFFER, old_fbo); |
47 | 47 |
48 glDeleteFramebuffers(1, &fbo); | 48 glDeleteFramebuffers(1, &fbo); |
49 | 49 |
50 return texel; | 50 return texel; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 class GLTextureMailboxTest : public testing::Test { | 54 class GLTextureMailboxTest : public testing::Test { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); | 106 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); |
107 glFlush(); | 107 glFlush(); |
108 | 108 |
109 gl1_.MakeCurrent(); | 109 gl1_.MakeCurrent(); |
110 | 110 |
111 glBindTexture(GL_TEXTURE_2D, tex1); | 111 glBindTexture(GL_TEXTURE_2D, tex1); |
112 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); | 112 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); |
113 EXPECT_EQ(source_pixel, ReadTexel(tex1, 0, 0)); | 113 EXPECT_EQ(source_pixel, ReadTexel(tex1, 0, 0)); |
114 } | 114 } |
115 | 115 |
116 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTextureRGB) { | |
117 gl1_.MakeCurrent(); | |
118 | |
119 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; | |
120 glGenMailboxCHROMIUM(mailbox1); | |
121 | |
122 GLbyte mailbox2[GL_MAILBOX_SIZE_CHROMIUM]; | |
123 glGenMailboxCHROMIUM(mailbox2); | |
124 | |
125 GLuint tex1; | |
126 glGenTextures(1, &tex1); | |
127 | |
128 glBindTexture(GL_TEXTURE_2D, tex1); | |
129 uint32 source_pixel = 0xFF0000; | |
130 glTexImage2D(GL_TEXTURE_2D, | |
131 0, | |
132 GL_RGB, | |
133 1, 1, | |
134 0, | |
135 GL_RGB, | |
136 GL_UNSIGNED_BYTE, | |
137 &source_pixel); | |
138 | |
139 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox1); | |
140 glFlush(); | |
141 | |
142 gl2_.MakeCurrent(); | |
143 | |
144 GLuint tex2; | |
145 glGenTextures(1, &tex2); | |
146 | |
147 glBindTexture(GL_TEXTURE_2D, tex2); | |
148 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox1); | |
149 EXPECT_EQ(source_pixel, ReadTexel(tex2, 0, 0, GL_RGB)); | |
150 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); | |
151 glFlush(); | |
152 | |
153 gl1_.MakeCurrent(); | |
154 | |
155 glBindTexture(GL_TEXTURE_2D, tex1); | |
156 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); | |
157 EXPECT_EQ(source_pixel, ReadTexel(tex1, 0, 0, GL_RGB)); | |
158 } | |
159 | |
160 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTextureDirect) { | |
161 gl1_.MakeCurrent(); | |
162 | |
163 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; | |
164 glGenMailboxCHROMIUM(mailbox1); | |
165 | |
166 GLbyte mailbox2[GL_MAILBOX_SIZE_CHROMIUM]; | |
167 glGenMailboxCHROMIUM(mailbox2); | |
168 | |
169 GLuint tex1; | |
170 glGenTextures(1, &tex1); | |
171 | |
172 glBindTexture(GL_TEXTURE_2D, tex1); | |
173 uint32 source_pixel = 0xFF0000FF; | |
174 glTexImage2D(GL_TEXTURE_2D, | |
175 0, | |
176 GL_RGBA, | |
177 1, 1, | |
178 0, | |
179 GL_RGBA, | |
180 GL_UNSIGNED_BYTE, | |
181 &source_pixel); | |
182 | |
183 glProduceTextureDirectCHROMIUM(tex1, GL_TEXTURE_2D, mailbox1); | |
184 glFlush(); | |
185 | |
186 gl2_.MakeCurrent(); | |
187 | |
188 GLuint tex2 = glCreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox1); | |
189 glBindTexture(GL_TEXTURE_2D, tex2); | |
190 EXPECT_EQ(source_pixel, ReadTexel(tex2, 0, 0)); | |
191 glProduceTextureDirectCHROMIUM(tex2, GL_TEXTURE_2D, mailbox2); | |
192 glFlush(); | |
193 | |
194 gl1_.MakeCurrent(); | |
195 | |
196 GLuint tex3 = glCreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); | |
197 glBindTexture(GL_TEXTURE_2D, tex3); | |
198 EXPECT_EQ(source_pixel, ReadTexel(tex3, 0, 0)); | |
199 } | |
200 | |
116 TEST_F(GLTextureMailboxTest, ConsumeTextureValidatesKey) { | 201 TEST_F(GLTextureMailboxTest, ConsumeTextureValidatesKey) { |
117 GLuint tex; | 202 GLuint tex; |
118 glGenTextures(1, &tex); | 203 glGenTextures(1, &tex); |
119 | 204 |
120 glBindTexture(GL_TEXTURE_2D, tex); | 205 glBindTexture(GL_TEXTURE_2D, tex); |
121 uint32 source_pixel = 0xFF0000FF; | 206 uint32 source_pixel = 0xFF0000FF; |
122 glTexImage2D(GL_TEXTURE_2D, | 207 glTexImage2D(GL_TEXTURE_2D, |
123 0, | 208 0, |
124 GL_RGBA, | 209 GL_RGBA, |
125 1, 1, | 210 1, 1, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 | 366 |
282 gl2_.MakeCurrent(); | 367 gl2_.MakeCurrent(); |
283 gl2_.Destroy(); | 368 gl2_.Destroy(); |
284 | 369 |
285 gl1_.MakeCurrent(); | 370 gl1_.MakeCurrent(); |
286 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex1, 0, 0)); | 371 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex1, 0, 0)); |
287 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 372 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
288 glDeleteTextures(1, &tex1); | 373 glDeleteTextures(1, &tex1); |
289 } | 374 } |
290 | 375 |
376 TEST_F(GLTextureMailboxTest, ProduceTextureDirectInvalideTarget) { | |
piman
2014/06/09 14:37:25
nit: Invalide->Invalid ?
| |
377 gl1_.MakeCurrent(); | |
378 | |
379 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; | |
380 glGenMailboxCHROMIUM(mailbox1); | |
381 | |
382 GLuint tex1; | |
383 glGenTextures(1, &tex1); | |
384 | |
385 glBindTexture(GL_TEXTURE_CUBE_MAP, tex1); | |
386 uint32 source_pixel = 0xFF0000FF; | |
387 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, | |
388 0, | |
389 GL_RGBA, | |
390 1, 1, | |
391 0, | |
392 GL_RGBA, | |
393 GL_UNSIGNED_BYTE, | |
394 &source_pixel); | |
395 | |
396 glProduceTextureDirectCHROMIUM(tex1, GL_TEXTURE_2D, mailbox1); | |
397 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); | |
398 } | |
399 | |
291 // http://crbug.com/281565 | 400 // http://crbug.com/281565 |
292 #if !defined(OS_ANDROID) | 401 #if !defined(OS_ANDROID) |
293 TEST_F(GLTextureMailboxTest, ProduceFrontBufferMultipleContexts) { | 402 TEST_F(GLTextureMailboxTest, ProduceFrontBufferMultipleContexts) { |
294 gl1_.MakeCurrent(); | 403 gl1_.MakeCurrent(); |
295 Mailbox mailbox[2]; | 404 Mailbox mailbox[2]; |
296 glGenMailboxCHROMIUM(mailbox[0].name); | 405 glGenMailboxCHROMIUM(mailbox[0].name); |
297 glGenMailboxCHROMIUM(mailbox[1].name); | 406 glGenMailboxCHROMIUM(mailbox[1].name); |
298 GLuint tex[2]; | 407 GLuint tex[2]; |
299 glGenTextures(2, tex); | 408 glGenTextures(2, tex); |
300 | 409 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 other_gl[i].Destroy(); | 444 other_gl[i].Destroy(); |
336 } | 445 } |
337 | 446 |
338 gl1_.MakeCurrent(); | 447 gl1_.MakeCurrent(); |
339 glDeleteTextures(2, tex); | 448 glDeleteTextures(2, tex); |
340 } | 449 } |
341 #endif | 450 #endif |
342 | 451 |
343 } // namespace gpu | 452 } // namespace gpu |
344 | 453 |
OLD | NEW |