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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/gl/test/gl_image_test_support.cc
diff --git a/ui/gl/test/gl_image_test_support.cc b/ui/gl/test/gl_image_test_support.cc
index 79996d5edf11fc86a70cb6675bcef1de2bd4e3b4..74058de3df5de99febaef9bb392f5dce3e24dc7f 100644
--- a/ui/gl/test/gl_image_test_support.cc
+++ b/ui/gl/test/gl_image_test_support.cc
@@ -6,22 +6,16 @@
#include <vector>
+#include "base/strings/stringize_macros.h"
+#include "base/strings/stringprintf.h"
+#include "ui/gl/gl_helper.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/test/gl_surface_test_support.h"
-#if defined(USE_OZONE)
-#include "base/message_loop/message_loop.h"
-#endif
-
namespace gl {
// static
void GLImageTestSupport::InitializeGL() {
-#if defined(USE_OZONE)
- // On Ozone, the backend initializes the event system using a UI thread.
- base::MessageLoopForUI main_loop;
-#endif
-
std::vector<gfx::GLImplementation> allowed_impls;
GetAllowedGLImplementations(&allowed_impls);
DCHECK(!allowed_impls.empty());
@@ -130,4 +124,49 @@ void GLImageTestSupport::SetBufferDataToColor(int width,
NOTREACHED();
}
+// static
+GLuint GLImageTestSupport::CreateSingleTextureProgram() {
+ // clang-format off
+ const char kVertexShader[] = STRINGIZE(
+ attribute vec2 a_position;
+ varying vec2 v_texCoord;
+ void main() {
+ gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);
+ v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;
+ }
+ );
+ const char kFragmentShader[] = STRINGIZE(
+ uniform sampler2D a_texture;
+ varying vec2 v_texCoord;
+ void main() {
+ gl_FragColor = texture2D(a_texture, v_texCoord);
+ }
+ );
+ const char kShaderFloatPrecision[] = STRINGIZE(
+ precision mediump float;
+ );
+ // clang-format on
+
+ GLuint vertex_shader =
+ gfx::GLHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader);
+ bool is_gles = gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2;
+ GLuint fragment_shader = gfx::GLHelper::LoadShader(
+ GL_FRAGMENT_SHADER,
+ base::StringPrintf("%s%s", is_gles ? kShaderFloatPrecision : "",
+ kFragmentShader)
+ .c_str());
+ GLuint program = gfx::GLHelper::SetupProgram(vertex_shader, fragment_shader);
+ DCHECK_NE(program, 0u);
+ glUseProgram(program);
+
+ GLint sampler_location = glGetUniformLocation(program, "a_texture");
+ DCHECK_NE(sampler_location, -1);
+ glUniform1i(sampler_location, 0);
+
+ glDeleteShader(vertex_shader);
+ glDeleteShader(fragment_shader);
+
+ return program;
+}
+
} // namespace gl

Powered by Google App Engine
This is Rietveld 408576698