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 16 matching lines...) Expand all Loading... |
27 using testing::Return; | 27 using testing::Return; |
28 using testing::SetArgPointee; | 28 using testing::SetArgPointee; |
29 using testing::StrictMock; | 29 using testing::StrictMock; |
30 | 30 |
31 namespace gpu { | 31 namespace gpu { |
32 namespace gles2 { | 32 namespace gles2 { |
33 | 33 |
34 static const int kImageWidth = 32; | 34 static const int kImageWidth = 32; |
35 static const int kImageHeight = 32; | 35 static const int kImageHeight = 32; |
36 | 36 |
37 class GpuMemoryBufferTest | 37 class GpuMemoryBufferTest : public testing::TestWithParam<gfx::BufferFormat> { |
38 : public testing::TestWithParam<gfx::GpuMemoryBuffer::Format> { | |
39 protected: | 38 protected: |
40 void SetUp() override { | 39 void SetUp() override { |
41 GLManager::Options options; | 40 GLManager::Options options; |
42 options.size = gfx::Size(kImageWidth, kImageHeight); | 41 options.size = gfx::Size(kImageWidth, kImageHeight); |
43 gl_.Initialize(options); | 42 gl_.Initialize(options); |
44 gl_.MakeCurrent(); | 43 gl_.MakeCurrent(); |
45 } | 44 } |
46 | 45 |
47 void TearDown() override { | 46 void TearDown() override { |
48 gl_.Destroy(); | 47 gl_.Destroy(); |
(...skipping 21 matching lines...) Expand all Loading... |
70 SHADER( | 69 SHADER( |
71 precision mediump float; | 70 precision mediump float; |
72 uniform sampler2D a_texture; | 71 uniform sampler2D a_texture; |
73 varying vec2 v_texCoord; | 72 varying vec2 v_texCoord; |
74 void main() { | 73 void main() { |
75 gl_FragColor = texture2D(a_texture, v_texCoord); | 74 gl_FragColor = texture2D(a_texture, v_texCoord); |
76 } | 75 } |
77 ); | 76 ); |
78 // clang-format on | 77 // clang-format on |
79 | 78 |
80 void SetRow(gfx::GpuMemoryBuffer::Format format, | 79 void SetRow(gfx::BufferFormat format, |
81 uint8_t* buffer, | 80 uint8_t* buffer, |
82 int width, | 81 int width, |
83 uint8_t pixel[4]) { | 82 uint8_t pixel[4]) { |
84 switch (format) { | 83 switch (format) { |
85 case gfx::GpuMemoryBuffer::R_8: | 84 case gfx::BufferFormat::R_8: |
86 for (int i = 0; i < width; ++i) | 85 for (int i = 0; i < width; ++i) |
87 buffer[i] = pixel[0]; | 86 buffer[i] = pixel[0]; |
88 return; | 87 return; |
89 case gfx::GpuMemoryBuffer::RGBA_4444: | 88 case gfx::BufferFormat::RGBA_4444: |
90 for (int i = 0; i < width * 2; i += 2) { | 89 for (int i = 0; i < width * 2; i += 2) { |
91 buffer[i + 0] = (pixel[1] << 4) | (pixel[0] & 0xf); | 90 buffer[i + 0] = (pixel[1] << 4) | (pixel[0] & 0xf); |
92 buffer[i + 1] = (pixel[3] << 4) | (pixel[2] & 0xf); | 91 buffer[i + 1] = (pixel[3] << 4) | (pixel[2] & 0xf); |
93 } | 92 } |
94 return; | 93 return; |
95 case gfx::GpuMemoryBuffer::RGBA_8888: | 94 case gfx::BufferFormat::RGBA_8888: |
96 for (int i = 0; i < width * 4; i += 4) { | 95 for (int i = 0; i < width * 4; i += 4) { |
97 buffer[i + 0] = pixel[0]; | 96 buffer[i + 0] = pixel[0]; |
98 buffer[i + 1] = pixel[1]; | 97 buffer[i + 1] = pixel[1]; |
99 buffer[i + 2] = pixel[2]; | 98 buffer[i + 2] = pixel[2]; |
100 buffer[i + 3] = pixel[3]; | 99 buffer[i + 3] = pixel[3]; |
101 } | 100 } |
102 return; | 101 return; |
103 case gfx::GpuMemoryBuffer::BGRA_8888: | 102 case gfx::BufferFormat::BGRA_8888: |
104 for (int i = 0; i < width * 4; i += 4) { | 103 for (int i = 0; i < width * 4; i += 4) { |
105 buffer[i + 0] = pixel[2]; | 104 buffer[i + 0] = pixel[2]; |
106 buffer[i + 1] = pixel[1]; | 105 buffer[i + 1] = pixel[1]; |
107 buffer[i + 2] = pixel[0]; | 106 buffer[i + 2] = pixel[0]; |
108 buffer[i + 3] = pixel[3]; | 107 buffer[i + 3] = pixel[3]; |
109 } | 108 } |
110 return; | 109 return; |
111 case gfx::GpuMemoryBuffer::ATC: | 110 case gfx::BufferFormat::ATC: |
112 case gfx::GpuMemoryBuffer::ATCIA: | 111 case gfx::BufferFormat::ATCIA: |
113 case gfx::GpuMemoryBuffer::DXT1: | 112 case gfx::BufferFormat::DXT1: |
114 case gfx::GpuMemoryBuffer::DXT5: | 113 case gfx::BufferFormat::DXT5: |
115 case gfx::GpuMemoryBuffer::ETC1: | 114 case gfx::BufferFormat::ETC1: |
116 case gfx::GpuMemoryBuffer::RGBX_8888: | 115 case gfx::BufferFormat::RGBX_8888: |
117 case gfx::GpuMemoryBuffer::YUV_420: | 116 case gfx::BufferFormat::YUV_420: |
118 NOTREACHED(); | 117 NOTREACHED(); |
119 return; | 118 return; |
120 } | 119 } |
121 | 120 |
122 NOTREACHED(); | 121 NOTREACHED(); |
123 } | 122 } |
124 | 123 |
125 GLenum InternalFormat(gfx::GpuMemoryBuffer::Format format) { | 124 GLenum InternalFormat(gfx::BufferFormat format) { |
126 switch (format) { | 125 switch (format) { |
127 case gfx::GpuMemoryBuffer::R_8: | 126 case gfx::BufferFormat::R_8: |
128 return GL_R8; | 127 return GL_R8; |
129 case gfx::GpuMemoryBuffer::RGBA_4444: | 128 case gfx::BufferFormat::RGBA_4444: |
130 case gfx::GpuMemoryBuffer::RGBA_8888: | 129 case gfx::BufferFormat::RGBA_8888: |
131 return GL_RGBA; | 130 return GL_RGBA; |
132 case gfx::GpuMemoryBuffer::BGRA_8888: | 131 case gfx::BufferFormat::BGRA_8888: |
133 return GL_BGRA_EXT; | 132 return GL_BGRA_EXT; |
134 case gfx::GpuMemoryBuffer::ATC: | 133 case gfx::BufferFormat::ATC: |
135 case gfx::GpuMemoryBuffer::ATCIA: | 134 case gfx::BufferFormat::ATCIA: |
136 case gfx::GpuMemoryBuffer::DXT1: | 135 case gfx::BufferFormat::DXT1: |
137 case gfx::GpuMemoryBuffer::DXT5: | 136 case gfx::BufferFormat::DXT5: |
138 case gfx::GpuMemoryBuffer::ETC1: | 137 case gfx::BufferFormat::ETC1: |
139 case gfx::GpuMemoryBuffer::RGBX_8888: | 138 case gfx::BufferFormat::RGBX_8888: |
140 case gfx::GpuMemoryBuffer::YUV_420: | 139 case gfx::BufferFormat::YUV_420: |
141 NOTREACHED(); | 140 NOTREACHED(); |
142 return 0; | 141 return 0; |
143 } | 142 } |
144 | 143 |
145 NOTREACHED(); | 144 NOTREACHED(); |
146 return 0; | 145 return 0; |
147 } | 146 } |
148 | 147 |
149 } // namespace | 148 } // namespace |
150 | 149 |
151 // An end to end test that tests the whole GpuMemoryBuffer lifecycle. | 150 // An end to end test that tests the whole GpuMemoryBuffer lifecycle. |
152 TEST_P(GpuMemoryBufferTest, Lifecycle) { | 151 TEST_P(GpuMemoryBufferTest, Lifecycle) { |
153 ASSERT_TRUE((GetParam() != gfx::GpuMemoryBuffer::R_8) || | 152 ASSERT_TRUE((GetParam() != gfx::BufferFormat::R_8) || |
154 gl_.GetCapabilities().texture_rg); | 153 gl_.GetCapabilities().texture_rg); |
155 | 154 |
156 GLuint texture_id = 0; | 155 GLuint texture_id = 0; |
157 glGenTextures(1, &texture_id); | 156 glGenTextures(1, &texture_id); |
158 ASSERT_NE(0u, texture_id); | 157 ASSERT_NE(0u, texture_id); |
159 glBindTexture(GL_TEXTURE_2D, texture_id); | 158 glBindTexture(GL_TEXTURE_2D, texture_id); |
160 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 159 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
161 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 160 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
163 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 glDeleteProgram(program); | 226 glDeleteProgram(program); |
228 glDeleteShader(vertex_shader); | 227 glDeleteShader(vertex_shader); |
229 glDeleteShader(fragment_shader); | 228 glDeleteShader(fragment_shader); |
230 glDeleteBuffers(1, &vbo); | 229 glDeleteBuffers(1, &vbo); |
231 glDestroyImageCHROMIUM(image_id); | 230 glDestroyImageCHROMIUM(image_id); |
232 glDeleteTextures(1, &texture_id); | 231 glDeleteTextures(1, &texture_id); |
233 } | 232 } |
234 | 233 |
235 INSTANTIATE_TEST_CASE_P(GpuMemoryBufferTests, | 234 INSTANTIATE_TEST_CASE_P(GpuMemoryBufferTests, |
236 GpuMemoryBufferTest, | 235 GpuMemoryBufferTest, |
237 ::testing::Values(gfx::GpuMemoryBuffer::R_8, | 236 ::testing::Values(gfx::BufferFormat::R_8, |
238 gfx::GpuMemoryBuffer::RGBA_4444, | 237 gfx::BufferFormat::RGBA_4444, |
239 gfx::GpuMemoryBuffer::RGBA_8888, | 238 gfx::BufferFormat::RGBA_8888, |
240 gfx::GpuMemoryBuffer::BGRA_8888)); | 239 gfx::BufferFormat::BGRA_8888)); |
241 | 240 |
242 } // namespace gles2 | 241 } // namespace gles2 |
243 } // namespace gpu | 242 } // namespace gpu |
OLD | NEW |