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

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

Issue 4873002: Benchmark tool for GPU-accelerated video rendering (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits Created 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/tools/shader_bench/painter.cc ('k') | media/tools/shader_bench/window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <deque>
6 #include <iostream>
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #include "app/gfx/gl/gl_bindings.h"
11 #include "app/gfx/gl/gl_context.h"
12 #include "app/gfx/gl/gl_implementation.h"
13 #include "base/at_exit.h"
14 #include "base/command_line.h"
15 #include "base/scoped_ptr.h"
16 #include "base/string_number_conversions.h"
17 #include "base/time.h"
18 #include "gfx/native_widget_types.h"
19 #include "media/base/callback.h"
20 #include "media/base/video_frame.h"
21 #include "media/tools/shader_bench/cpu_color_painter.h"
22 #include "media/tools/shader_bench/gpu_color_painter.h"
23 #include "media/tools/shader_bench/gpu_color_painter_exp.h"
24 #include "media/tools/shader_bench/painter.h"
25 #include "media/tools/shader_bench/window.h"
26
27 #if defined(OS_LINUX)
28 #include <gtk/gtk.h>
29 #endif
30
31 static const int kNumFramesToPaint = 500;
32 static base::TimeTicks g_start_;
33 static base::TimeTicks g_end_;
34
35 long CalculateYUVFrameSize(FILE* file_handle, int num_frames) {
36 fseek(file_handle, 0, SEEK_END);
37 long file_size = (long) ftell(file_handle);
38 rewind(file_handle);
39 return file_size / num_frames;
40 }
41
42 void GetFrames(std::string file_name,
43 int width, int height, int num_frames,
44 std::deque<scoped_refptr<media::VideoFrame> >& out_frames) {
45 FILE* file_handle = fopen(file_name.c_str(), "rb");
46 if (!file_handle) {
47 printf("Could not open %s\n", file_name.c_str());
48 exit(1);
49 }
50
51 long frame_size = CalculateYUVFrameSize(file_handle, num_frames);
52
53 for (int i = 0; i < num_frames; i++) {
54 scoped_refptr<media::VideoFrame> video_frame;
55
56 media::VideoFrame::CreateFrame(media::VideoFrame::YV12,
57 width,
58 height,
59 base::TimeDelta(),
60 base::TimeDelta(),
61 &video_frame);
62 long bytes_read =
63 fread(video_frame->data(0), 1, frame_size, file_handle);
64
65 if (bytes_read != frame_size) {
66 printf("Could not read %s\n", file_name.c_str());
67 fclose(file_handle);
68 exit(1);
69 }
70 out_frames.push_back(video_frame);
71 }
72
73 fclose(file_handle);
74 }
75
76 void TestFinished() {
77 g_end_ = base::TimeTicks::HighResNow();
78 double time_in_seconds =
79 static_cast<double>((g_end_ - g_start_).InMilliseconds()) / 1000;
80 double fps = kNumFramesToPaint / time_in_seconds;
81 printf("Printed %f frames per second.\n", fps);
82 }
83
84 void RunTest(media::Window* window, Painter* painter) {
85 g_start_ = base::TimeTicks::HighResNow();
86 window->Start(kNumFramesToPaint, NewRunnableFunction(&TestFinished), painter);
87 }
88
89 int main(int argc, char** argv) {
90 // Read arguments.
91 if (argc == 1) {
92 printf("Usage: %s --file=FILE --wxh=DIMENSIONS --frames=NUM_FRAMES\n"
93 "FILE is a raw .yuv file with 1+ frames in it\n"
94 "DIMENSIONS is the width and height of the frame in pixels\n"
95 "NUM_FRAMES is the number of frames in FILE\n", argv[0]);
96 return 1;
97 }
98
99 // Read command line.
100 #if defined(OS_LINUX)
101 gtk_init(&argc, &argv);
102 #endif
103 CommandLine::Init(argc, argv);
104
105 // Determine file name.
106 std::string file_name =
107 CommandLine::ForCurrentProcess()->GetSwitchValueASCII("file");
108
109 // Determine number of frames.
110 int num_frames = 0;
111 std::string str_num_frames =
112 CommandLine::ForCurrentProcess()->GetSwitchValueASCII("frames");
113 base::StringToInt(str_num_frames, &num_frames);
114
115 // Determine video dimensions.
116 int width = 0;
117 int height = 0;
118 std::string dimensions =
119 CommandLine::ForCurrentProcess()->GetSwitchValueASCII("wxh");
120 int x_index = dimensions.find('x');
121 std::string str_width = dimensions.substr(0, x_index);
122 std::string str_height =
123 dimensions.substr(x_index + 1, dimensions.length() - x_index - 1);
124 base::StringToInt(str_width, &width);
125 base::StringToInt(str_height, &height);
126
127 // Process files.
128 std::deque<scoped_refptr<media::VideoFrame> > frames;
129 GetFrames(file_name, width, height, num_frames, frames);
130
131 // Initialize window and graphics context.
132 base::AtExitManager at_exit_manager;
133 gfx::GLContext::InitializeOneOff();
134 scoped_ptr<media::Window> window(new media::Window(width, height));
135 gfx::GLContext* context =
136 gfx::GLContext::CreateViewGLContext(window->PluginWindow(), false);
137 context->MakeCurrent();
138 // This sets D3DPRESENT_INTERVAL_IMMEDIATE on Windows.
139 context->SetSwapInterval(0);
140
141 // Initialize and name GPU painters.
142 static const int kNumPainters = 3;
143 static const struct {
144 const char* name;
145 GPUPainter* painter;
146 } painters[] = {
147 { "CPU CSC + GPU Render", new CPUColorPainter() },
148 { "GPU CSC/Render", new GPUColorWithLuminancePainter() },
149 { "GPU CSC/Render (experimental)", new GPUColorRGBALumHackPainter() },
150 };
151
152 // Run GPU painter tests.
153 for (int i = 0; i < kNumPainters; i++) {
154 scoped_ptr<GPUPainter> painter(painters[i].painter);
155 painter->LoadFrames(&frames);
156 painter->SetGLContext(context);
157 painter->Initialize(width, height);
158 printf("Running %s tests...", painters[i].name);
159 RunTest(window.get(), painter.get());
160 }
161
162 return 0;
163 }
OLDNEW
« no previous file with comments | « media/tools/shader_bench/painter.cc ('k') | media/tools/shader_bench/window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698