OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/service/mailbox_manager.h" | 9 #include "gpu/command_buffer/service/mailbox_manager.h" |
10 #include "gpu/command_buffer/tests/gl_manager.h" | 10 #include "gpu/command_buffer/tests/gl_manager.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 160 |
161 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 161 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
162 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, invalid_mailbox); | 162 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, invalid_mailbox); |
163 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); | 163 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
164 | 164 |
165 // Ensure level 0 is still intact after glConsumeTextureCHROMIUM fails. | 165 // Ensure level 0 is still intact after glConsumeTextureCHROMIUM fails. |
166 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 166 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
167 EXPECT_EQ(source_pixel, ReadTexel(tex, 0, 0)); | 167 EXPECT_EQ(source_pixel, ReadTexel(tex, 0, 0)); |
168 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 168 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
169 } | 169 } |
| 170 |
| 171 TEST_F(GLTextureMailboxTest, SharedTextures) { |
| 172 gl1_.MakeCurrent(); |
| 173 GLuint tex1; |
| 174 glGenTextures(1, &tex1); |
| 175 |
| 176 glBindTexture(GL_TEXTURE_2D, tex1); |
| 177 uint32 source_pixel = 0xFF0000FF; |
| 178 glTexImage2D(GL_TEXTURE_2D, |
| 179 0, |
| 180 GL_RGBA, |
| 181 1, 1, |
| 182 0, |
| 183 GL_RGBA, |
| 184 GL_UNSIGNED_BYTE, |
| 185 &source_pixel); |
| 186 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM]; |
| 187 glGenMailboxCHROMIUM(mailbox); |
| 188 |
| 189 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox); |
| 190 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 191 glFlush(); |
| 192 |
| 193 gl2_.MakeCurrent(); |
| 194 GLuint tex2; |
| 195 glGenTextures(1, &tex2); |
| 196 |
| 197 glBindTexture(GL_TEXTURE_2D, tex2); |
| 198 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox); |
| 199 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 200 |
| 201 // Change texture in context 2. |
| 202 source_pixel = 0xFF00FF00; |
| 203 glTexSubImage2D(GL_TEXTURE_2D, |
| 204 0, |
| 205 0, 0, |
| 206 1, 1, |
| 207 GL_RGBA, |
| 208 GL_UNSIGNED_BYTE, |
| 209 &source_pixel); |
| 210 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 211 glFlush(); |
| 212 |
| 213 // Check it in context 1. |
| 214 gl1_.MakeCurrent(); |
| 215 EXPECT_EQ(source_pixel, ReadTexel(tex1, 0, 0)); |
| 216 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 217 |
| 218 // Change parameters (note: ReadTexel will reset those). |
| 219 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 221 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, |
| 222 GL_LINEAR_MIPMAP_NEAREST); |
| 223 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 224 glFlush(); |
| 225 |
| 226 // Check in context 2. |
| 227 gl2_.MakeCurrent(); |
| 228 GLint parameter = 0; |
| 229 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, ¶meter); |
| 230 EXPECT_EQ(GL_REPEAT, parameter); |
| 231 parameter = 0; |
| 232 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, ¶meter); |
| 233 EXPECT_EQ(GL_LINEAR, parameter); |
| 234 parameter = 0; |
| 235 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ¶meter); |
| 236 EXPECT_EQ(GL_LINEAR_MIPMAP_NEAREST, parameter); |
| 237 |
| 238 // Delete texture in context 1. |
| 239 gl1_.MakeCurrent(); |
| 240 glDeleteTextures(1, &tex1); |
| 241 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 242 |
| 243 // Check texture still exists in context 2. |
| 244 gl2_.MakeCurrent(); |
| 245 EXPECT_EQ(source_pixel, ReadTexel(tex2, 0, 0)); |
| 246 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 247 |
| 248 // The mailbox should still exist too. |
| 249 GLuint tex3; |
| 250 glGenTextures(1, &tex3); |
| 251 glBindTexture(GL_TEXTURE_2D, tex3); |
| 252 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox); |
| 253 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 254 |
| 255 // Delete both textures. |
| 256 glDeleteTextures(1, &tex2); |
| 257 glDeleteTextures(1, &tex3); |
| 258 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 259 |
| 260 // Mailbox should be gone now. |
| 261 glGenTextures(1, &tex2); |
| 262 glBindTexture(GL_TEXTURE_2D, tex2); |
| 263 glConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox); |
| 264 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError()); |
| 265 glDeleteTextures(1, &tex2); |
| 266 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 267 } |
| 268 |
170 } // namespace gpu | 269 } // namespace gpu |
171 | 270 |
OLD | NEW |