| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "gpu/GLES2/gl2extchromium.h" |
| 9 #include "gpu/command_buffer/tests/gl_manager.h" | 10 #include "gpu/command_buffer/tests/gl_manager.h" |
| 10 #include "gpu/command_buffer/tests/gl_test_utils.h" | 11 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 12 #include "gpu/command_buffer/tests/texture_image_factory.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 15 |
| 14 namespace gpu { | 16 namespace gpu { |
| 15 | 17 |
| 16 class TextureStorageTest : public testing::Test { | 18 class TextureStorageTest : public testing::Test { |
| 17 protected: | 19 protected: |
| 18 static const GLsizei kResolution = 64; | 20 static const GLsizei kResolution = 64; |
| 19 void SetUp() override { | 21 void SetUp() override { |
| 20 GLManager::Options options; | 22 GLManager::Options options; |
| 23 image_factory_.SetRequiredTextureType(GL_TEXTURE_2D); |
| 21 options.size = gfx::Size(kResolution, kResolution); | 24 options.size = gfx::Size(kResolution, kResolution); |
| 25 options.image_factory = &image_factory_; |
| 22 gl_.Initialize(options); | 26 gl_.Initialize(options); |
| 23 gl_.MakeCurrent(); | 27 gl_.MakeCurrent(); |
| 24 | 28 |
| 25 glGenTextures(1, &tex_); | 29 glGenTextures(1, &tex_); |
| 26 glBindTexture(GL_TEXTURE_2D, tex_); | 30 glBindTexture(GL_TEXTURE_2D, tex_); |
| 27 | 31 |
| 28 glGenFramebuffers(1, &fbo_); | 32 glGenFramebuffers(1, &fbo_); |
| 29 glBindFramebuffer(GL_FRAMEBUFFER, fbo_); | 33 glBindFramebuffer(GL_FRAMEBUFFER, fbo_); |
| 30 glFramebufferTexture2D(GL_FRAMEBUFFER, | 34 glFramebufferTexture2D(GL_FRAMEBUFFER, |
| 31 GL_COLOR_ATTACHMENT0, | 35 GL_COLOR_ATTACHMENT0, |
| 32 GL_TEXTURE_2D, | 36 GL_TEXTURE_2D, |
| 33 tex_, | 37 tex_, |
| 34 0); | 38 0); |
| 35 | 39 |
| 36 const GLubyte* extensions = glGetString(GL_EXTENSIONS); | 40 const GLubyte* extensions = glGetString(GL_EXTENSIONS); |
| 37 extension_available_ = strstr(reinterpret_cast<const char*>( | 41 extension_available_ = strstr(reinterpret_cast<const char*>( |
| 38 extensions), "GL_EXT_texture_storage"); | 42 extensions), "GL_EXT_texture_storage"); |
| 39 } | 43 } |
| 40 | 44 |
| 41 void TearDown() override { gl_.Destroy(); } | 45 void TearDown() override { gl_.Destroy(); } |
| 42 | 46 |
| 47 TextureImageFactory image_factory_; |
| 43 GLManager gl_; | 48 GLManager gl_; |
| 44 GLuint tex_; | 49 GLuint tex_; |
| 45 GLuint fbo_; | 50 GLuint fbo_; |
| 46 bool extension_available_; | 51 bool extension_available_; |
| 47 }; | 52 }; |
| 48 | 53 |
| 49 TEST_F(TextureStorageTest, CorrectPixels) { | 54 TEST_F(TextureStorageTest, CorrectPixels) { |
| 50 if (!extension_available_) | 55 if (!extension_available_) |
| 51 return; | 56 return; |
| 52 | 57 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 if (!extension_available_) | 159 if (!extension_available_) |
| 155 return; | 160 return; |
| 156 | 161 |
| 157 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 162 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 158 // The context is ES2 context. | 163 // The context is ES2 context. |
| 159 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8_OES, 4, 4, 0, GL_RGBA, | 164 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8_OES, 4, 4, 0, GL_RGBA, |
| 160 GL_UNSIGNED_BYTE, nullptr); | 165 GL_UNSIGNED_BYTE, nullptr); |
| 161 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError()); | 166 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError()); |
| 162 } | 167 } |
| 163 | 168 |
| 169 TEST_F(TextureStorageTest, CorrectImagePixels) { |
| 170 if (!extension_available_) |
| 171 return; |
| 172 |
| 173 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BUFFER_USAGE_CHROMIUM, |
| 174 GL_TEXTURE_BUFFER_SCANOUT_CHROMIUM); |
| 175 |
| 176 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 2, 2); |
| 177 |
| 178 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 179 tex_, 0); |
| 180 |
| 181 uint8_t source_pixels[16] = {1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}; |
| 182 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, |
| 183 source_pixels); |
| 184 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 2, 2, 0, source_pixels, nullptr)); |
| 185 } |
| 186 |
| 164 } // namespace gpu | 187 } // namespace gpu |
| 165 | 188 |
| 166 | 189 |
| 167 | 190 |
| OLD | NEW |