Index: content/shell/android/draw_context.cc |
diff --git a/content/shell/android/draw_context.cc b/content/shell/android/draw_context.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ddf35b0c7372ad53a6d163bdbf3e61774547f707 |
--- /dev/null |
+++ b/content/shell/android/draw_context.cc |
@@ -0,0 +1,111 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/shell/android/draw_context.h" |
+ |
+#include "base/logging.h" |
+#include "content/public/browser/android/graphics_context.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h" |
+ |
+static const char g_vertex_shader[] = |
+ "attribute vec4 a_Position;\n" |
+ "attribute vec2 a_texCoord;\n" |
+ "varying vec2 v_texCoord;\n" |
+ "void main() {\n" |
+ " gl_Position = a_Position;\n" |
+ " v_texCoord = a_texCoord;\n" |
+ "}\n"; |
+ |
+// Minimal texture mapping pixel shader. |
+static const char g_fragment_shader[] = |
+ "precision mediump float;" |
+ "varying vec2 v_texCoord;\n" |
+ "uniform sampler2D s_texture;\n" |
+ "void main() {\n" |
+ " gl_FragColor = texture2D(s_texture, v_texCoord);\n" |
+ "}\n"; |
+ |
+DrawContext::DrawContext(ANativeWindow* window) |
+ : program_(GL_ZERO), |
+ vertex_shader_(0), |
+ fragment_shader_(0), |
+ texture_uniform_(GL_ZERO), |
+ vertex_buffer_(GL_ZERO), |
+ context_(content::GraphicsContext::CreateForUI(window)) { |
+ const GLfloat attribs[] = { |
+ -1.0f, -1.0f, |
Ted C
2012/07/27 20:31:15
increase indent by one or should this be 4 and not
no sievers
2012/07/31 01:28:44
Done.
|
+ 1.0f, -1.0f, |
+ -1.0f, 1.0f, |
+ 1.0f, 1.0f, |
+ 0.0f, 0.0f, |
+ 1.0f, 0.0f, |
+ 0.0f, 1.0f, |
+ 1.0f, 1.0f }; |
+ WebKit::WebGraphicsContext3D* context3D = context_->GetContext3D(); |
+ vertex_buffer_ = context3D->createBuffer(); |
+ context3D->bindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); |
+ context3D->bufferData(GL_ARRAY_BUFFER, 16 * sizeof(GLfloat), attribs, |
+ GL_STATIC_DRAW); |
Ted C
2012/07/27 20:31:15
align with above
no sievers
2012/07/31 01:28:44
Done.
|
+ |
+ |
+ vertex_shader_ = context3D->createShader(GL_VERTEX_SHADER); |
+ context3D->shaderSource(vertex_shader_, g_vertex_shader); |
+ context3D->compileShader(vertex_shader_); |
+ |
+ fragment_shader_ = context3D->createShader(GL_FRAGMENT_SHADER); |
+ context3D->shaderSource(fragment_shader_, g_fragment_shader); |
+ context3D->compileShader(fragment_shader_); |
+ |
+ program_ = context3D->createProgram(); |
+ context3D->attachShader(program_, vertex_shader_); |
+ context3D->attachShader(program_, fragment_shader_); |
+ context3D->linkProgram(program_); |
+ |
+ texture_uniform_ = context3D->getUniformLocation(program_, "s_texture"); |
+ |
Ted C
2012/07/27 20:31:15
remove blank line
no sievers
2012/07/31 01:28:44
Done.
|
+} |
+ |
+DrawContext::~DrawContext() { |
+ if (vertex_buffer_ != GL_ZERO) |
+ context_->GetContext3D()->deleteBuffer(vertex_buffer_); |
+ if (program_ != GL_ZERO) |
+ context_->GetContext3D()->deleteProgram(program_); |
+} |
+ |
+uint32 DrawContext::Draw(int texture) { |
+ DCHECK(program_ != GL_ZERO); |
+ WebKit::WebGraphicsContext3D* context3D = context_->GetContext3D(); |
+ |
+ context3D->useProgram(program_); |
+ |
+ context3D->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
+ context3D->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
+ context3D->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
+ context3D->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
+ |
+ context3D->uniform1i(texture_uniform_, 0); |
+ context3D->activeTexture(GL_TEXTURE0); |
+ context3D->bindTexture(GL_TEXTURE_2D, texture); |
+ |
+ context3D->bindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); |
+ context3D->enableVertexAttribArray(0); |
+ context3D->vertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); |
+ context3D->bindAttribLocation(program_, 0, "a_Position"); |
+ context3D->enableVertexAttribArray(1); |
+ context3D->vertexAttribPointer( |
+ 1, 2, GL_FLOAT, GL_FALSE, 0, 8 * sizeof(GLfloat)); |
+ context3D->bindAttribLocation(program_, 1, "a_texCoord"); |
+ |
+ context3D->drawArrays(GL_TRIANGLE_STRIP, 0, 4); |
+ |
+ context3D->prepareTexture(); |
+ |
+ return context_->InsertSyncPoint(); |
+} |
+ |
+void DrawContext::Reshape(int width, int height) { |
+ WebKit::WebGraphicsContext3D* context3D = context_->GetContext3D(); |
+ context3D->viewport(0, 0, width, height); |
+ context3D->reshape(width, height); |
+} |