| Index: media/tools/shader_bench/painter.cc
|
| diff --git a/media/tools/shader_bench/painter.cc b/media/tools/shader_bench/painter.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..191b8522df016f41c9ebc261b493a89935f88a58
|
| --- /dev/null
|
| +++ b/media/tools/shader_bench/painter.cc
|
| @@ -0,0 +1,96 @@
|
| +// Copyright (c) 2010 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 "media/tools/shader_bench/painter.h"
|
| +
|
| +// Vertices for a full screen quad.
|
| +static const float kVertices[8] = {
|
| + -1.f, 1.f,
|
| + -1.f, -1.f,
|
| + 1.f, 1.f,
|
| + 1.f, -1.f,
|
| +};
|
| +
|
| +// Texture Coordinates mapping the entire texture.
|
| +static const float kTextureCoords[8] = {
|
| + 0, 0,
|
| + 0, 1,
|
| + 1, 0,
|
| + 1, 1,
|
| +};
|
| +
|
| +// Buffer size for compile errors.
|
| +static const unsigned int kErrorSize = 4096;
|
| +
|
| +Painter::Painter()
|
| + : frames_(0) {
|
| +}
|
| +
|
| +void Painter::OnPaint() {
|
| + if (frames_ && !frames_->empty()) {
|
| + scoped_refptr<media::VideoFrame> cur_frame = frames_->front();
|
| + Paint(cur_frame);
|
| + frames_->pop_front();
|
| + frames_->push_back(cur_frame);
|
| + }
|
| +}
|
| +
|
| +void Painter::LoadFrames(std::deque<scoped_refptr<media::VideoFrame> >* frames) {
|
| + frames_ = frames;
|
| +}
|
| +
|
| +GLuint Painter::LoadShader(gfx::GLContext* context, unsigned type, const char* shader_source) {
|
| + // TODO(vrk) assert context is current
|
| + GLuint shader = glCreateShader(type);
|
| + glShaderSource(shader, 1, &shader_source, NULL);
|
| + glCompileShader(shader);
|
| + int result = GL_FALSE;
|
| + glGetShaderiv(shader, GL_COMPILE_STATUS, &result);
|
| + if (!result) {
|
| + char log[kErrorSize];
|
| + int len;
|
| + glGetShaderInfoLog(shader, kErrorSize - 1, &len, log);
|
| + log[kErrorSize - 1] = 0;
|
| + printf("Shader did not compile: %s\n", log);
|
| + }
|
| + return shader;
|
| +}
|
| +
|
| +GLuint Painter::CreateShaderProgram(gfx::GLContext* context, const char* vertex_shader_source,
|
| + const char* fragment_shader_source) {
|
| + // Create vertex and pixel shaders.
|
| + GLuint vertex_shader =
|
| + LoadShader(context, GL_VERTEX_SHADER, vertex_shader_source);
|
| + GLuint fragment_shader =
|
| + LoadShader(context, GL_FRAGMENT_SHADER, fragment_shader_source);
|
| +
|
| + // Create program and attach shaders.
|
| + GLuint program = glCreateProgram();
|
| + glAttachShader(program, vertex_shader);
|
| + glAttachShader(program, fragment_shader);
|
| + glDeleteShader(vertex_shader);
|
| + glDeleteShader(fragment_shader);
|
| + glLinkProgram(program);
|
| + int result = GL_FALSE;
|
| + glGetProgramiv(program, GL_LINK_STATUS, &result);
|
| + if (!result) {
|
| + char log[kErrorSize];
|
| + int len;
|
| + glGetProgramInfoLog(program, kErrorSize - 1, &len, log);
|
| + log[kErrorSize - 1] = 0;
|
| + printf("Program did not link: %s\n", log);
|
| + }
|
| + glUseProgram(program);
|
| +
|
| + // Set common vertex parameters.
|
| + int pos_location = glGetAttribLocation(program, "in_pos");
|
| + glEnableVertexAttribArray(pos_location);
|
| + glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices);
|
| +
|
| + int tc_location = glGetAttribLocation(program, "in_tc");
|
| + glEnableVertexAttribArray(tc_location);
|
| + glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0,
|
| + kTextureCoords);
|
| + return program;
|
| +}
|
|
|