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

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

Issue 1736093002: Add a workaround for copyTexImage2D as it is sometimes broken on OSX. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from kbr. Created 4 years, 9 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
OLDNEW
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 "gpu/command_buffer/tests/gl_test_utils.h" 5 #include "gpu/command_buffer/tests/gl_test_utils.h"
6 6
7 #include <GLES2/gl2extchromium.h>
7 #include <stdint.h> 8 #include <stdint.h>
8 #include <stdio.h> 9 #include <stdio.h>
9 10
10 #include <string> 11 #include <string>
11 12
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/stringize_macros.h"
15 #include "base/strings/stringprintf.h"
13 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/gfx/geometry/size.h"
14 18
15 // GCC requires these declarations, but MSVC requires they not be present. 19 // GCC requires these declarations, but MSVC requires they not be present.
16 #ifndef COMPILER_MSVC 20 #ifndef COMPILER_MSVC
17 const uint8_t GLTestHelper::kCheckClearValue; 21 const uint8_t GLTestHelper::kCheckClearValue;
18 #endif 22 #endif
19 23
24 // Compiles a fragment shader for sampling out of a texture of |size| bound to
25 // |target| and checks for compilation errors.
26 GLuint LoadFragmentShader(unsigned target, const gfx::Size& size) {
27 // clang-format off
28 const char kFragmentShader[] = STRINGIZE(
29 uniform SamplerType a_texture;
30 varying vec2 v_texCoord;
31 void main() {
32 gl_FragColor = TextureLookup(a_texture, v_texCoord * TextureScale);
33 }
34 );
35 const char kShaderFloatPrecision[] = STRINGIZE(
36 precision mediump float;
37 );
38 // clang-format on
39
40 switch (target) {
41 case GL_TEXTURE_2D:
42 return GLTestHelper::LoadShader(
43 GL_FRAGMENT_SHADER,
44 base::StringPrintf("%s\n"
45 "#define SamplerType sampler2D\n"
46 "#define TextureLookup texture2D\n"
47 "#define TextureScale vec2(1.0, 1.0)\n"
48 "%s",
49 kShaderFloatPrecision,
50 kFragmentShader)
51 .c_str());
52 case GL_TEXTURE_RECTANGLE_ARB:
53 return GLTestHelper::LoadShader(
54 GL_FRAGMENT_SHADER,
55 base::StringPrintf("%s\n"
56 "#extension GL_ARB_texture_rectangle : require\n"
57 "#define SamplerType sampler2DRect\n"
58 "#define TextureLookup texture2DRect\n"
59 "#define TextureScale vec2(%f, %f)\n"
60 "%s",
61 kShaderFloatPrecision,
62 static_cast<double>(size.width()),
63 static_cast<double>(size.height()),
64 kFragmentShader)
65 .c_str());
66 default:
67 NOTREACHED();
68 return 0;
69 }
70 }
71
20 bool GLTestHelper::HasExtension(const char* extension) { 72 bool GLTestHelper::HasExtension(const char* extension) {
21 std::string extensions( 73 std::string extensions(
22 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); 74 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
23 return extensions.find(extension) != std::string::npos; 75 return extensions.find(extension) != std::string::npos;
24 } 76 }
25 77
26 bool GLTestHelper::CheckGLError(const char* msg, int line) { 78 bool GLTestHelper::CheckGLError(const char* msg, int line) {
27 bool success = true; 79 bool success = true;
28 GLenum error = GL_NO_ERROR; 80 GLenum error = GL_NO_ERROR;
29 while ((error = glGetError()) != GL_NO_ERROR) { 81 while ((error = glGetError()) != GL_NO_ERROR) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 Set32BitValue(bih.y_pels_per_meter, 0); 304 Set32BitValue(bih.y_pels_per_meter, 0);
253 Set32BitValue(bih.clr_used, 0); 305 Set32BitValue(bih.clr_used, 0);
254 Set32BitValue(bih.clr_important, 0); 306 Set32BitValue(bih.clr_important, 0);
255 307
256 fwrite(&bhf, sizeof(bhf), 1, fp); 308 fwrite(&bhf, sizeof(bhf), 1, fp);
257 fwrite(&bih, sizeof(bih), 1, fp); 309 fwrite(&bih, sizeof(bih), 1, fp);
258 fwrite(pixels, size, 1, fp); 310 fwrite(pixels, size, 1, fp);
259 fclose(fp); 311 fclose(fp);
260 return true; 312 return true;
261 } 313 }
314
315 void GLTestHelper::DrawTextureQuad(GLenum target, const gfx::Size& size) {
316 // clang-format off
317 const char kVertexShader[] = STRINGIZE(
318 attribute vec2 a_position;
319 varying vec2 v_texCoord;
320 void main() {
321 gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);
322 v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;
323 }
324 );
325 // clang-format on
326
327 // Setup program.
328 GLuint vertex_shader =
329 GLTestHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader);
330 GLuint fragment_shader = LoadFragmentShader(target, size);
331 GLuint program = GLTestHelper::SetupProgram(vertex_shader, fragment_shader);
332 EXPECT_NE(program, 0u);
333 glUseProgram(program);
334
335 GLint sampler_location = glGetUniformLocation(program, "a_texture");
336 ASSERT_NE(sampler_location, -1);
337
338 GLuint vertex_buffer = GLTestHelper::SetupUnitQuad(sampler_location);
339 glDrawArrays(GL_TRIANGLES, 0, 6);
340
341 glDeleteShader(vertex_shader);
342 glDeleteShader(fragment_shader);
343 glDeleteProgram(program);
344 glDeleteBuffers(1, &vertex_buffer);
345 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698