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

Side by Side Diff: ui/gl/test/gl_image_test_support.cc

Issue 1484473003: gl, ozone: enable GLImageBindTest unittests Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add GLImageBindTest for ozone Created 5 years 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/gl/test/gl_image_test_support.h" 5 #include "ui/gl/test/gl_image_test_support.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/stringize_macros.h"
10 #include "base/strings/stringprintf.h"
11 #include "ui/gl/gl_helper.h"
9 #include "ui/gl/gl_implementation.h" 12 #include "ui/gl/gl_implementation.h"
10 #include "ui/gl/test/gl_surface_test_support.h" 13 #include "ui/gl/test/gl_surface_test_support.h"
11 14
12 #if defined(USE_OZONE)
13 #include "base/message_loop/message_loop.h"
14 #endif
15
16 namespace gl { 15 namespace gl {
17 16
18 // static 17 // static
19 void GLImageTestSupport::InitializeGL() { 18 void GLImageTestSupport::InitializeGL() {
20 #if defined(USE_OZONE)
21 // On Ozone, the backend initializes the event system using a UI thread.
22 base::MessageLoopForUI main_loop;
23 #endif
24
25 std::vector<gfx::GLImplementation> allowed_impls; 19 std::vector<gfx::GLImplementation> allowed_impls;
26 GetAllowedGLImplementations(&allowed_impls); 20 GetAllowedGLImplementations(&allowed_impls);
27 DCHECK(!allowed_impls.empty()); 21 DCHECK(!allowed_impls.empty());
28 22
29 gfx::GLImplementation impl = allowed_impls[0]; 23 gfx::GLImplementation impl = allowed_impls[0];
30 gfx::GLSurfaceTestSupport::InitializeOneOffImplementation(impl, true); 24 gfx::GLSurfaceTestSupport::InitializeOneOffImplementation(impl, true);
31 } 25 }
32 26
33 // static 27 // static
34 void GLImageTestSupport::CleanupGL() { 28 void GLImageTestSupport::CleanupGL() {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 case gfx::BufferFormat::R_8: 117 case gfx::BufferFormat::R_8:
124 case gfx::BufferFormat::RGBA_4444: 118 case gfx::BufferFormat::RGBA_4444:
125 case gfx::BufferFormat::UYVY_422: 119 case gfx::BufferFormat::UYVY_422:
126 case gfx::BufferFormat::YUV_420: 120 case gfx::BufferFormat::YUV_420:
127 NOTREACHED(); 121 NOTREACHED();
128 return; 122 return;
129 } 123 }
130 NOTREACHED(); 124 NOTREACHED();
131 } 125 }
132 126
127 // static
128 GLuint GLImageTestSupport::CreateSingleTextureProgram() {
129 // clang-format off
130 const char kVertexShader[] = STRINGIZE(
131 attribute vec2 a_position;
132 varying vec2 v_texCoord;
133 void main() {
134 gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);
135 v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;
136 }
137 );
138 const char kFragmentShader[] = STRINGIZE(
139 uniform sampler2D a_texture;
140 varying vec2 v_texCoord;
141 void main() {
142 gl_FragColor = texture2D(a_texture, v_texCoord);
143 }
144 );
145 const char kShaderFloatPrecision[] = STRINGIZE(
146 precision mediump float;
147 );
148 // clang-format on
149
150 GLuint vertex_shader =
151 gfx::GLHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader);
152 bool is_gles = gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2;
153 GLuint fragment_shader = gfx::GLHelper::LoadShader(
154 GL_FRAGMENT_SHADER,
155 base::StringPrintf("%s%s", is_gles ? kShaderFloatPrecision : "",
156 kFragmentShader)
157 .c_str());
158 GLuint program = gfx::GLHelper::SetupProgram(vertex_shader, fragment_shader);
159 DCHECK_NE(program, 0u);
160 glUseProgram(program);
161
162 GLint sampler_location = glGetUniformLocation(program, "a_texture");
163 DCHECK_NE(sampler_location, -1);
164 glUniform1i(sampler_location, 0);
165
166 glDeleteShader(vertex_shader);
167 glDeleteShader(fragment_shader);
168
169 return program;
170 }
171
133 } // namespace gl 172 } // namespace gl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698