| 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/gl2chromium.h> | 6 #include <GLES2/gl2chromium.h> |
| 7 #include <GLES2/gl2ext.h> | 7 #include <GLES2/gl2ext.h> |
| 8 #include <GLES2/gl2extchromium.h> | 8 #include <GLES2/gl2extchromium.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 case gfx::GpuMemoryBuffer::ETC1: | 119 case gfx::GpuMemoryBuffer::ETC1: |
| 120 case gfx::GpuMemoryBuffer::RGBX_8888: | 120 case gfx::GpuMemoryBuffer::RGBX_8888: |
| 121 NOTREACHED(); | 121 NOTREACHED(); |
| 122 return std::vector<uint8>(); | 122 return std::vector<uint8>(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 NOTREACHED(); | 125 NOTREACHED(); |
| 126 return std::vector<uint8>(); | 126 return std::vector<uint8>(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 GLenum TextureFormat(gfx::GpuMemoryBuffer::Format format) { | 129 GLenum InternalFormat(gfx::GpuMemoryBuffer::Format format) { |
| 130 switch (format) { | 130 switch (format) { |
| 131 case gfx::GpuMemoryBuffer::RGBA_8888: | 131 case gfx::GpuMemoryBuffer::RGBA_8888: |
| 132 return GL_RGBA; | 132 return GL_RGBA; |
| 133 case gfx::GpuMemoryBuffer::BGRA_8888: | 133 case gfx::GpuMemoryBuffer::BGRA_8888: |
| 134 return GL_BGRA_EXT; | 134 return GL_BGRA_EXT; |
| 135 case gfx::GpuMemoryBuffer::ATC: | 135 case gfx::GpuMemoryBuffer::ATC: |
| 136 case gfx::GpuMemoryBuffer::ATCIA: | 136 case gfx::GpuMemoryBuffer::ATCIA: |
| 137 case gfx::GpuMemoryBuffer::DXT1: | 137 case gfx::GpuMemoryBuffer::DXT1: |
| 138 case gfx::GpuMemoryBuffer::DXT5: | 138 case gfx::GpuMemoryBuffer::DXT5: |
| 139 case gfx::GpuMemoryBuffer::ETC1: | 139 case gfx::GpuMemoryBuffer::ETC1: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 170 for (int x = 0; x < kImageWidth; ++x) { | 170 for (int x = 0; x < kImageWidth; ++x) { |
| 171 std::copy(pixel.begin(), pixel.end(), | 171 std::copy(pixel.begin(), pixel.end(), |
| 172 mapped_buffer + y * stride + x * pixel.size()); | 172 mapped_buffer + y * stride + x * pixel.size()); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 // Unmap the buffer. | 176 // Unmap the buffer. |
| 177 buffer->Unmap(); | 177 buffer->Unmap(); |
| 178 | 178 |
| 179 // Create the image. This should add the image ID to the ImageManager. | 179 // Create the image. This should add the image ID to the ImageManager. |
| 180 GLuint image_id = glCreateImageCHROMIUM( | 180 GLuint image_id = |
| 181 buffer->AsClientBuffer(), kImageWidth, kImageHeight, GL_RGBA); | 181 glCreateImageCHROMIUM(buffer->AsClientBuffer(), kImageWidth, kImageHeight, |
| 182 InternalFormat(GetParam())); |
| 182 EXPECT_NE(0u, image_id); | 183 EXPECT_NE(0u, image_id); |
| 183 EXPECT_TRUE(gl_.decoder()->GetImageManager()->LookupImage(image_id) != NULL); | 184 EXPECT_TRUE(gl_.decoder()->GetImageManager()->LookupImage(image_id) != NULL); |
| 184 | 185 |
| 185 // Bind the texture and the image. | 186 // Bind the texture and the image. |
| 186 glBindTexture(GL_TEXTURE_2D, texture_ids_[0]); | 187 glBindTexture(GL_TEXTURE_2D, texture_ids_[0]); |
| 187 glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); | 188 glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); |
| 188 | 189 |
| 189 // Copy texture so we can verify result using CheckPixels. | 190 // Copy texture so we can verify result using CheckPixels. |
| 190 glCopyTextureCHROMIUM(GL_TEXTURE_2D, texture_ids_[0], texture_ids_[1], | 191 glCopyTextureCHROMIUM(GL_TEXTURE_2D, texture_ids_[0], texture_ids_[1], |
| 191 TextureFormat(GetParam()), GL_UNSIGNED_BYTE); | 192 InternalFormat(GetParam()), GL_UNSIGNED_BYTE); |
| 192 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 193 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 193 | 194 |
| 194 // Check if pixels match the values that were assigned to the mapped buffer. | 195 // Check if pixels match the values that were assigned to the mapped buffer. |
| 195 GLTestHelper::CheckPixels(0, 0, kImageWidth, kImageHeight, 0, | 196 GLTestHelper::CheckPixels(0, 0, kImageWidth, kImageHeight, 0, |
| 196 &GetFramebufferPixel(GetParam()).front()); | 197 &GetFramebufferPixel(GetParam()).front()); |
| 197 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 198 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 198 | 199 |
| 199 // Release the image. | 200 // Release the image. |
| 200 glReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); | 201 glReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); |
| 201 | 202 |
| 202 // Destroy the image. | 203 // Destroy the image. |
| 203 glDestroyImageCHROMIUM(image_id); | 204 glDestroyImageCHROMIUM(image_id); |
| 204 } | 205 } |
| 205 | 206 |
| 206 INSTANTIATE_TEST_CASE_P(GpuMemoryBufferTests, | 207 INSTANTIATE_TEST_CASE_P(GpuMemoryBufferTests, |
| 207 GpuMemoryBufferTest, | 208 GpuMemoryBufferTest, |
| 208 ::testing::Values(gfx::GpuMemoryBuffer::RGBA_8888, | 209 ::testing::Values(gfx::GpuMemoryBuffer::RGBA_8888, |
| 209 gfx::GpuMemoryBuffer::BGRA_8888)); | 210 gfx::GpuMemoryBuffer::BGRA_8888)); |
| 210 | 211 |
| 211 } // namespace gles2 | 212 } // namespace gles2 |
| 212 } // namespace gpu | 213 } // namespace gpu |
| OLD | NEW |