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" |
(...skipping 24 matching lines...) Expand all Loading... |
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, GL_RGBA, GL_UNSIGNED_BYTE, &texel); |
| 45 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
45 | 46 |
46 glBindFramebuffer(GL_FRAMEBUFFER, old_fbo); | 47 glBindFramebuffer(GL_FRAMEBUFFER, old_fbo); |
47 | 48 |
48 glDeleteFramebuffers(1, &fbo); | 49 glDeleteFramebuffers(1, &fbo); |
49 | 50 |
50 return texel; | 51 return texel; |
51 } | 52 } |
52 } | 53 } |
53 | 54 |
54 class GLTextureMailboxTest : public testing::Test { | 55 class GLTextureMailboxTest : public testing::Test { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); | 107 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); |
107 glFlush(); | 108 glFlush(); |
108 | 109 |
109 gl1_.MakeCurrent(); | 110 gl1_.MakeCurrent(); |
110 | 111 |
111 glBindTexture(GL_TEXTURE_2D, tex1); | 112 glBindTexture(GL_TEXTURE_2D, tex1); |
112 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); | 113 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); |
113 EXPECT_EQ(source_pixel, ReadTexel(tex1, 0, 0)); | 114 EXPECT_EQ(source_pixel, ReadTexel(tex1, 0, 0)); |
114 } | 115 } |
115 | 116 |
| 117 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTextureRGB) { |
| 118 gl1_.MakeCurrent(); |
| 119 |
| 120 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; |
| 121 glGenMailboxCHROMIUM(mailbox1); |
| 122 |
| 123 GLbyte mailbox2[GL_MAILBOX_SIZE_CHROMIUM]; |
| 124 glGenMailboxCHROMIUM(mailbox2); |
| 125 |
| 126 GLuint tex1; |
| 127 glGenTextures(1, &tex1); |
| 128 |
| 129 glBindTexture(GL_TEXTURE_2D, tex1); |
| 130 uint32 source_pixel = 0xFF000000; |
| 131 glTexImage2D(GL_TEXTURE_2D, |
| 132 0, |
| 133 GL_RGB, |
| 134 1, 1, |
| 135 0, |
| 136 GL_RGB, |
| 137 GL_UNSIGNED_BYTE, |
| 138 &source_pixel); |
| 139 |
| 140 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox1); |
| 141 glFlush(); |
| 142 |
| 143 gl2_.MakeCurrent(); |
| 144 |
| 145 GLuint tex2; |
| 146 glGenTextures(1, &tex2); |
| 147 |
| 148 glBindTexture(GL_TEXTURE_2D, tex2); |
| 149 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox1); |
| 150 EXPECT_EQ(source_pixel, ReadTexel(tex2, 0, 0)); |
| 151 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); |
| 152 glFlush(); |
| 153 |
| 154 gl1_.MakeCurrent(); |
| 155 |
| 156 glBindTexture(GL_TEXTURE_2D, tex1); |
| 157 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); |
| 158 EXPECT_EQ(source_pixel, ReadTexel(tex1, 0, 0)); |
| 159 } |
| 160 |
| 161 TEST_F(GLTextureMailboxTest, ProduceAndConsumeTextureDirect) { |
| 162 gl1_.MakeCurrent(); |
| 163 |
| 164 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; |
| 165 glGenMailboxCHROMIUM(mailbox1); |
| 166 |
| 167 GLbyte mailbox2[GL_MAILBOX_SIZE_CHROMIUM]; |
| 168 glGenMailboxCHROMIUM(mailbox2); |
| 169 |
| 170 GLuint tex1; |
| 171 glGenTextures(1, &tex1); |
| 172 |
| 173 glBindTexture(GL_TEXTURE_2D, tex1); |
| 174 uint32 source_pixel = 0xFF0000FF; |
| 175 glTexImage2D(GL_TEXTURE_2D, |
| 176 0, |
| 177 GL_RGBA, |
| 178 1, 1, |
| 179 0, |
| 180 GL_RGBA, |
| 181 GL_UNSIGNED_BYTE, |
| 182 &source_pixel); |
| 183 |
| 184 glProduceTextureDirectCHROMIUM(tex1, GL_TEXTURE_2D, mailbox1); |
| 185 glFlush(); |
| 186 |
| 187 gl2_.MakeCurrent(); |
| 188 |
| 189 GLuint tex2 = glCreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox1); |
| 190 glBindTexture(GL_TEXTURE_2D, tex2); |
| 191 EXPECT_EQ(source_pixel, ReadTexel(tex2, 0, 0)); |
| 192 glProduceTextureDirectCHROMIUM(tex2, GL_TEXTURE_2D, mailbox2); |
| 193 glFlush(); |
| 194 |
| 195 gl1_.MakeCurrent(); |
| 196 |
| 197 GLuint tex3 = glCreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox2); |
| 198 glBindTexture(GL_TEXTURE_2D, tex3); |
| 199 EXPECT_EQ(source_pixel, ReadTexel(tex3, 0, 0)); |
| 200 } |
| 201 |
116 TEST_F(GLTextureMailboxTest, ConsumeTextureValidatesKey) { | 202 TEST_F(GLTextureMailboxTest, ConsumeTextureValidatesKey) { |
117 GLuint tex; | 203 GLuint tex; |
118 glGenTextures(1, &tex); | 204 glGenTextures(1, &tex); |
119 | 205 |
120 glBindTexture(GL_TEXTURE_2D, tex); | 206 glBindTexture(GL_TEXTURE_2D, tex); |
121 uint32 source_pixel = 0xFF0000FF; | 207 uint32 source_pixel = 0xFF0000FF; |
122 glTexImage2D(GL_TEXTURE_2D, | 208 glTexImage2D(GL_TEXTURE_2D, |
123 0, | 209 0, |
124 GL_RGBA, | 210 GL_RGBA, |
125 1, 1, | 211 1, 1, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 367 |
282 gl2_.MakeCurrent(); | 368 gl2_.MakeCurrent(); |
283 gl2_.Destroy(); | 369 gl2_.Destroy(); |
284 | 370 |
285 gl1_.MakeCurrent(); | 371 gl1_.MakeCurrent(); |
286 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex1, 0, 0)); | 372 EXPECT_EQ(0xFF00FF00u, ReadTexel(tex1, 0, 0)); |
287 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 373 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
288 glDeleteTextures(1, &tex1); | 374 glDeleteTextures(1, &tex1); |
289 } | 375 } |
290 | 376 |
| 377 TEST_F(GLTextureMailboxTest, ProduceTextureDirectInvalidTarget) { |
| 378 gl1_.MakeCurrent(); |
| 379 |
| 380 GLbyte mailbox1[GL_MAILBOX_SIZE_CHROMIUM]; |
| 381 glGenMailboxCHROMIUM(mailbox1); |
| 382 |
| 383 GLuint tex1; |
| 384 glGenTextures(1, &tex1); |
| 385 |
| 386 glBindTexture(GL_TEXTURE_CUBE_MAP, tex1); |
| 387 uint32 source_pixel = 0xFF0000FF; |
| 388 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
| 389 0, |
| 390 GL_RGBA, |
| 391 1, 1, |
| 392 0, |
| 393 GL_RGBA, |
| 394 GL_UNSIGNED_BYTE, |
| 395 &source_pixel); |
| 396 |
| 397 glProduceTextureDirectCHROMIUM(tex1, GL_TEXTURE_2D, mailbox1); |
| 398 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
| 399 } |
| 400 |
291 // http://crbug.com/281565 | 401 // http://crbug.com/281565 |
292 #if !defined(OS_ANDROID) | 402 #if !defined(OS_ANDROID) |
293 TEST_F(GLTextureMailboxTest, ProduceFrontBufferMultipleContexts) { | 403 TEST_F(GLTextureMailboxTest, ProduceFrontBufferMultipleContexts) { |
294 gl1_.MakeCurrent(); | 404 gl1_.MakeCurrent(); |
295 Mailbox mailbox[2]; | 405 Mailbox mailbox[2]; |
296 glGenMailboxCHROMIUM(mailbox[0].name); | 406 glGenMailboxCHROMIUM(mailbox[0].name); |
297 glGenMailboxCHROMIUM(mailbox[1].name); | 407 glGenMailboxCHROMIUM(mailbox[1].name); |
298 GLuint tex[2]; | 408 GLuint tex[2]; |
299 glGenTextures(2, tex); | 409 glGenTextures(2, tex); |
300 | 410 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 other_gl[i].Destroy(); | 445 other_gl[i].Destroy(); |
336 } | 446 } |
337 | 447 |
338 gl1_.MakeCurrent(); | 448 gl1_.MakeCurrent(); |
339 glDeleteTextures(2, tex); | 449 glDeleteTextures(2, tex); |
340 } | 450 } |
341 #endif | 451 #endif |
342 | 452 |
343 } // namespace gpu | 453 } // namespace gpu |
344 | 454 |
OLD | NEW |