OLD | NEW |
---|---|
(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 base::TimeTicks start_; | |
Alpha Left Google
2010/11/29 20:06:13
global variables should be called g_***_.
vrk (LEFT CHROMIUM)
2010/11/30 01:21:35
Done.
| |
33 base::TimeTicks end_; | |
34 | |
35 long CalculateYUVFrameSize(FILE* file_handle, int num_frames) { | |
36 fseek(file_handle, 0, SEEK_END); | |
37 uint64 file_size = 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 end_ = base::TimeTicks::HighResNow(); | |
78 double time_in_seconds = | |
79 static_cast<double>((end_ - 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 start_ = base::TimeTicks::HighResNow(); | |
86 window->Start(kNumFramesToPaint, NewRunnableFunction(&TestFinished), painter); | |
87 } | |
88 | |
89 int main(int argc, char** argv) { | |
90 // Read command line. | |
91 #if defined(OS_LINUX) | |
92 gtk_init(&argc, &argv); | |
93 #endif | |
94 CommandLine::Init(argc, argv); | |
95 | |
96 // Determine file name. | |
97 std::string file_name = | |
98 CommandLine::ForCurrentProcess()->GetSwitchValueASCII("file"); | |
99 | |
100 // Determine number of frames. | |
101 int num_frames = 0; | |
102 std::string str_num_frames = | |
103 CommandLine::ForCurrentProcess()->GetSwitchValueASCII("frames"); | |
104 base::StringToInt(str_num_frames, &num_frames); | |
105 | |
106 // Determine video dimensions. | |
107 int width = 0; | |
108 int height = 0; | |
109 std::string dimensions = | |
110 CommandLine::ForCurrentProcess()->GetSwitchValueASCII("wxh"); | |
111 int x_index = dimensions.find('x'); | |
112 std::string str_width = dimensions.substr(0, x_index); | |
113 std::string str_height = | |
114 dimensions.substr(x_index + 1, dimensions.length() - x_index - 1); | |
115 base::StringToInt(str_width, &width); | |
116 base::StringToInt(str_height, &height); | |
117 | |
118 // Process files. | |
119 std::deque<scoped_refptr<media::VideoFrame> > frames; | |
120 GetFrames(file_name, width, height, num_frames, frames); | |
121 | |
122 // Initialize window and graphics context. | |
123 base::AtExitManager at_exit_manager; | |
124 gfx::GLContext::InitializeOneOff(); | |
125 scoped_ptr<media::Window> window(new media::Window(width, height)); | |
126 gfx::GLContext* context = | |
127 gfx::GLContext::CreateViewGLContext(window->PluginWindow(), false); | |
128 context->MakeCurrent(); | |
129 // This sets D3DPRESENT_INTERVAL_IMMEDIATE on Windows. | |
130 context->SetSwapInterval(0); | |
131 | |
132 // Initialize and name GPU painters. | |
133 static const int kNumPainters = 3; | |
134 static const struct { | |
135 const char* name; | |
136 GPUPainter* painter; | |
137 } painters[] = { | |
138 { "CPU CSC + GPU Render", new CPUColorPainter() }, | |
139 { "GPU CSC/Render", new GPUColorWithLuminancePainter() }, | |
140 { "GPU CSC/Render (experimental)", new GPUColorRGBALumHackPainter() }, | |
141 }; | |
142 | |
143 // Run GPU painter tests. | |
144 for (int i = 0; i < kNumPainters; i++) { | |
145 scoped_ptr<GPUPainter> painter(painters[i].painter); | |
146 painter->LoadFrames(&frames); | |
147 painter->SetGLContext(context); | |
148 painter->Initialize(width, height); | |
149 printf("Running %s tests...", painters[i].name); | |
150 RunTest(window.get(), painter.get()); | |
151 } | |
152 | |
153 return 0; | |
154 } | |
OLD | NEW |