Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: gpu/command_buffer/tests/gl_gpu_memory_buffer_unittest.cc

Issue 1066073002: Test gpu memory buffers drawing directly to the backbuffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits. Fix cleanup. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 20 matching lines...) Expand all
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
38 : public testing::TestWithParam<gfx::GpuMemoryBuffer::Format> { 38 : public testing::TestWithParam<gfx::GpuMemoryBuffer::Format> {
39 protected: 39 protected:
40 void SetUp() override { 40 void SetUp() override {
41 gl_.Initialize(GLManager::Options()); 41 auto options = GLManager::Options();
piman 2015/04/07 20:55:56 nit: GLManager::Options options;
Daniele Castagna 2015/04/07 21:02:57 Done.
42 options.size = gfx::Size(kImageWidth, kImageHeight);
43 gl_.Initialize(options);
42 gl_.MakeCurrent(); 44 gl_.MakeCurrent();
43
44 glGenTextures(2, texture_ids_);
45 glBindTexture(GL_TEXTURE_2D, texture_ids_[1]);
46
47 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
48 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
49 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
51
52 glGenFramebuffers(1, &framebuffer_id_);
53 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_);
54 glFramebufferTexture2D(GL_FRAMEBUFFER,
55 GL_COLOR_ATTACHMENT0,
56 GL_TEXTURE_2D,
57 texture_ids_[1],
58 0);
59 } 45 }
60 46
61 void TearDown() override { 47 void TearDown() override {
62 glDeleteTextures(2, texture_ids_);
63 glDeleteFramebuffers(1, &framebuffer_id_);
64
65 gl_.Destroy(); 48 gl_.Destroy();
66 } 49 }
67 50
68 GLManager gl_; 51 GLManager gl_;
69 GLuint texture_ids_[2];
70 GLuint framebuffer_id_;
71 }; 52 };
72 53
73 namespace { 54 namespace {
74 55
56 #define SHADER(Src) #Src
57
58 // clang-format off
59 const char kVertexShader[] =
60 SHADER(
61 attribute vec4 a_position;
62 varying vec2 v_texCoord;
63 void main() {
64 gl_Position = a_position;
65 v_texCoord = vec2((a_position.x + 1.0) * 0.5, (a_position.y + 1.0) * 0.5);
66 }
67 );
68
69 const char* kFragmentShader =
70 SHADER(
71 precision mediump float;
72 uniform sampler2D a_texture;
73 varying vec2 v_texCoord;
74 void main() {
75 gl_FragColor = texture2D(a_texture, v_texCoord);
76 }
77 );
78 // clang-format on
79
75 std::vector<uint8> GetTexturePixel(const gfx::GpuMemoryBuffer::Format format) { 80 std::vector<uint8> GetTexturePixel(const gfx::GpuMemoryBuffer::Format format) {
76 std::vector<uint8> pixel; 81 std::vector<uint8> pixel;
77 switch (format) { 82 switch (format) {
78 case gfx::GpuMemoryBuffer::RGBA_8888: 83 case gfx::GpuMemoryBuffer::RGBA_8888:
79 pixel.push_back(255u); 84 pixel.push_back(255u);
80 pixel.push_back(0u); 85 pixel.push_back(0u);
81 pixel.push_back(0u); 86 pixel.push_back(0u);
82 pixel.push_back(255u); 87 pixel.push_back(255u);
83 return pixel; 88 return pixel;
84 case gfx::GpuMemoryBuffer::BGRA_8888: 89 case gfx::GpuMemoryBuffer::BGRA_8888:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 148 }
144 149
145 NOTREACHED(); 150 NOTREACHED();
146 return 0; 151 return 0;
147 } 152 }
148 153
149 } // namespace 154 } // namespace
150 155
151 // An end to end test that tests the whole GpuMemoryBuffer lifecycle. 156 // An end to end test that tests the whole GpuMemoryBuffer lifecycle.
152 TEST_P(GpuMemoryBufferTest, Lifecycle) { 157 TEST_P(GpuMemoryBufferTest, Lifecycle) {
158 GLuint texture_id = 0;
159 glGenTextures(1, &texture_id);
160 ASSERT_NE(0u, texture_id);
161 glBindTexture(GL_TEXTURE_2D, texture_id);
162 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
163 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
165 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
166
167 // Create the gpu memory buffer.
153 scoped_ptr<gfx::GpuMemoryBuffer> buffer(gl_.CreateGpuMemoryBuffer( 168 scoped_ptr<gfx::GpuMemoryBuffer> buffer(gl_.CreateGpuMemoryBuffer(
154 gfx::Size(kImageWidth, kImageHeight), GetParam())); 169 gfx::Size(kImageWidth, kImageHeight), GetParam()));
155 170
156 // Map buffer for writing. 171 // Map buffer for writing.
157 void* data; 172 void* data;
158 bool rv = buffer->Map(&data); 173 bool rv = buffer->Map(&data);
159 DCHECK(rv); 174 DCHECK(rv);
160 175
161 uint8* mapped_buffer = static_cast<uint8*>(data); 176 uint8* mapped_buffer = static_cast<uint8*>(data);
162 ASSERT_TRUE(mapped_buffer != NULL); 177 ASSERT_TRUE(mapped_buffer != NULL);
(...skipping 10 matching lines...) Expand all
173 } 188 }
174 } 189 }
175 190
176 // Unmap the buffer. 191 // Unmap the buffer.
177 buffer->Unmap(); 192 buffer->Unmap();
178 193
179 // Create the image. This should add the image ID to the ImageManager. 194 // Create the image. This should add the image ID to the ImageManager.
180 GLuint image_id = 195 GLuint image_id =
181 glCreateImageCHROMIUM(buffer->AsClientBuffer(), kImageWidth, kImageHeight, 196 glCreateImageCHROMIUM(buffer->AsClientBuffer(), kImageWidth, kImageHeight,
182 InternalFormat(GetParam())); 197 InternalFormat(GetParam()));
183 EXPECT_NE(0u, image_id); 198 ASSERT_NE(0u, image_id);
184 EXPECT_TRUE(gl_.decoder()->GetImageManager()->LookupImage(image_id) != NULL); 199 ASSERT_TRUE(gl_.decoder()->GetImageManager()->LookupImage(image_id) != NULL);
185 200
186 // Bind the texture and the image. 201 // Bind the image.
187 glBindTexture(GL_TEXTURE_2D, texture_ids_[0]);
188 glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); 202 glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id);
189 203
190 // Copy texture so we can verify result using CheckPixels. 204 // Build program, buffers and draw the texture.
191 glCopyTextureCHROMIUM(GL_TEXTURE_2D, texture_ids_[0], texture_ids_[1], 205 GLuint vertex_shader =
192 InternalFormat(GetParam()), GL_UNSIGNED_BYTE); 206 GLTestHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader);
193 EXPECT_TRUE(glGetError() == GL_NO_ERROR); 207 GLuint fragment_shader =
208 GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, kFragmentShader);
209 GLuint program = GLTestHelper::SetupProgram(vertex_shader, fragment_shader);
210 ASSERT_NE(0u, program);
211 glUseProgram(program);
212
213 GLint sampler_location = glGetUniformLocation(program, "a_texture");
214 ASSERT_NE(-1, sampler_location);
215 glUniform1i(sampler_location, 0);
216
217 GLuint vbo =
218 GLTestHelper::SetupUnitQuad(glGetAttribLocation(program, "a_position"));
219 ASSERT_NE(0u, vbo);
220 glViewport(0, 0, kImageWidth, kImageHeight);
221 glDrawArrays(GL_TRIANGLES, 0, 6);
222 ASSERT_TRUE(glGetError() == GL_NO_ERROR);
194 223
195 // Check if pixels match the values that were assigned to the mapped buffer. 224 // Check if pixels match the values that were assigned to the mapped buffer.
196 GLTestHelper::CheckPixels(0, 0, kImageWidth, kImageHeight, 0, 225 GLTestHelper::CheckPixels(0, 0, kImageWidth, kImageHeight, 0,
197 &GetFramebufferPixel(GetParam()).front()); 226 &GetFramebufferPixel(GetParam()).front());
198 EXPECT_TRUE(GL_NO_ERROR == glGetError()); 227 EXPECT_TRUE(GL_NO_ERROR == glGetError());
199 228
200 // Release the image. 229 // Release the image.
201 glReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id); 230 glReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id);
202 231
203 // Destroy the image. 232 // Clean up.
233 glDeleteProgram(program);
234 glDeleteShader(vertex_shader);
235 glDeleteShader(fragment_shader);
236 glDeleteBuffers(1, &vbo);
204 glDestroyImageCHROMIUM(image_id); 237 glDestroyImageCHROMIUM(image_id);
238 glDeleteTextures(1, &texture_id);
205 } 239 }
206 240
207 INSTANTIATE_TEST_CASE_P(GpuMemoryBufferTests, 241 INSTANTIATE_TEST_CASE_P(GpuMemoryBufferTests,
208 GpuMemoryBufferTest, 242 GpuMemoryBufferTest,
209 ::testing::Values(gfx::GpuMemoryBuffer::RGBA_8888, 243 ::testing::Values(gfx::GpuMemoryBuffer::RGBA_8888,
210 gfx::GpuMemoryBuffer::BGRA_8888)); 244 gfx::GpuMemoryBuffer::BGRA_8888));
211 245
212 } // namespace gles2 246 } // namespace gles2
213 } // namespace gpu 247 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698