summaryrefslogtreecommitdiffstats
path: root/media/tools/shader_bench/gpu_painter.cc
diff options
context:
space:
mode:
authorvrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-01 19:31:52 +0000
committervrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-01 19:31:52 +0000
commit7b923c6547a3619e4f0727d98e4b882c4d06eb77 (patch)
tree14fa82f6fe8a55659ec1befd1832062a3a05144e /media/tools/shader_bench/gpu_painter.cc
parent92ccbddc2fff4fe5afd5b7552f419adfa9d3b877 (diff)
downloadchromium_src-7b923c6547a3619e4f0727d98e4b882c4d06eb77.zip
chromium_src-7b923c6547a3619e4f0727d98e4b882c4d06eb77.tar.gz
chromium_src-7b923c6547a3619e4f0727d98e4b882c4d06eb77.tar.bz2
Benchmark tool for GPU-accelerated video rendering
This is a benchmarking program that times how fast a shader can color-convert and render video frames to the screen. The program takes a file with raw YUV frames, the number of frames in the file, and the dimensions of the video file as parameters and outputs the max frames per second obtained when rendering the video using various painting/shading techniques. BUG=48633 TEST=compiles Review URL: http://codereview.chromium.org/4873002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67887 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/tools/shader_bench/gpu_painter.cc')
-rw-r--r--media/tools/shader_bench/gpu_painter.cc89
1 files changed, 89 insertions, 0 deletions
diff --git a/media/tools/shader_bench/gpu_painter.cc b/media/tools/shader_bench/gpu_painter.cc
new file mode 100644
index 0000000..c1fe5ae
--- /dev/null
+++ b/media/tools/shader_bench/gpu_painter.cc
@@ -0,0 +1,89 @@
+// 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 "base/logging.h"
+#include "media/tools/shader_bench/gpu_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;
+
+GPUPainter::GPUPainter()
+ : context_(NULL) {
+}
+
+GPUPainter::~GPUPainter() {
+}
+
+void GPUPainter::SetGLContext(gfx::GLContext* context) {
+ context_ = context;
+}
+
+GLuint GPUPainter::LoadShader(unsigned type, const char* shader_source) {
+ 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;
+ LOG(FATAL) << "Shader did not compile: " << log;
+ }
+ return shader;
+}
+
+GLuint GPUPainter::CreateShaderProgram(const char* vertex_shader_source,
+ const char* fragment_shader_source) {
+
+ // Create vertex and pixel shaders.
+ GLuint vertex_shader = LoadShader(GL_VERTEX_SHADER, vertex_shader_source);
+ GLuint fragment_shader =
+ LoadShader(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;
+ LOG(FATAL) << "Program did not link: " << 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;
+}