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

Side by Side Diff: media/tools/shader_bench/painter.cc

Issue 4873002: Benchmark tool for GPU-accelerated video rendering (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up Window/Painter interface a little Created 10 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/tools/shader_bench/painter.h"
6
7 // Vertices for a full screen quad.
8 static const float kVertices[8] = {
9 -1.f, 1.f,
10 -1.f, -1.f,
11 1.f, 1.f,
12 1.f, -1.f,
13 };
14
15 // Texture Coordinates mapping the entire texture.
16 static const float kTextureCoords[8] = {
17 0, 0,
18 0, 1,
19 1, 0,
20 1, 1,
21 };
22
23 // Buffer size for compile errors.
24 static const unsigned int kErrorSize = 4096;
25
26 Painter::Painter()
27 : frames_(0) {
28 }
29
30 void Painter::OnPaint() {
31 if (frames_ && !frames_->empty()) {
32 scoped_refptr<media::VideoFrame> cur_frame = frames_->front();
33 Paint(cur_frame);
34 frames_->pop_front();
35 frames_->push_back(cur_frame);
36 }
37 }
38
39 void Painter::LoadFrames(std::deque<scoped_refptr<media::VideoFrame> >* frames) {
40 frames_ = frames;
41 }
42
43 GLuint Painter::LoadShader(gfx::GLContext* context, unsigned type, const char* s hader_source) {
44 // TODO(vrk) assert context is current
45 GLuint shader = glCreateShader(type);
46 glShaderSource(shader, 1, &shader_source, NULL);
47 glCompileShader(shader);
48 int result = GL_FALSE;
49 glGetShaderiv(shader, GL_COMPILE_STATUS, &result);
50 if (!result) {
51 char log[kErrorSize];
52 int len;
53 glGetShaderInfoLog(shader, kErrorSize - 1, &len, log);
54 log[kErrorSize - 1] = 0;
55 printf("Shader did not compile: %s\n", log);
56 }
57 return shader;
58 }
59
60 GLuint Painter::CreateShaderProgram(gfx::GLContext* context, const char* vertex_ shader_source,
61 const char* fragment_shader_source) {
62 // Create vertex and pixel shaders.
63 GLuint vertex_shader =
64 LoadShader(context, GL_VERTEX_SHADER, vertex_shader_source);
65 GLuint fragment_shader =
66 LoadShader(context, GL_FRAGMENT_SHADER, fragment_shader_source);
67
68 // Create program and attach shaders.
69 GLuint program = glCreateProgram();
70 glAttachShader(program, vertex_shader);
71 glAttachShader(program, fragment_shader);
72 glDeleteShader(vertex_shader);
73 glDeleteShader(fragment_shader);
74 glLinkProgram(program);
75 int result = GL_FALSE;
76 glGetProgramiv(program, GL_LINK_STATUS, &result);
77 if (!result) {
78 char log[kErrorSize];
79 int len;
80 glGetProgramInfoLog(program, kErrorSize - 1, &len, log);
81 log[kErrorSize - 1] = 0;
82 printf("Program did not link: %s\n", log);
83 }
84 glUseProgram(program);
85
86 // Set common vertex parameters.
87 int pos_location = glGetAttribLocation(program, "in_pos");
88 glEnableVertexAttribArray(pos_location);
89 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices);
90
91 int tc_location = glGetAttribLocation(program, "in_tc");
92 glEnableVertexAttribArray(tc_location);
93 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0,
94 kTextureCoords);
95 return program;
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698