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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: media/tools/shader_bench/shader_bench.cc
diff --git a/media/tools/shader_bench/shader_bench.cc b/media/tools/shader_bench/shader_bench.cc
new file mode 100644
index 0000000000000000000000000000000000000000..52eb094b8baef4bf072a4ac4b68d33906792d0e2
--- /dev/null
+++ b/media/tools/shader_bench/shader_bench.cc
@@ -0,0 +1,135 @@
+// 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 <deque>
+#include <iostream>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "app/gfx/gl/gl_bindings.h"
+#include "app/gfx/gl/gl_context.h"
+#include "app/gfx/gl/gl_implementation.h"
+#include "base/at_exit.h"
+#include "base/command_line.h"
+#include "base/scoped_ptr.h"
+#include "base/string_number_conversions.h"
+#include "base/time.h"
+#include "gfx/native_widget_types.h"
+#include "media/base/callback.h"
+#include "media/base/video_frame.h"
+#include "media/tools/shader_bench/gl_painter.h"
+#include "media/tools/shader_bench/painter.h"
+#include "media/tools/shader_bench/window.h"
+
+#if defined(OS_LINUX)
+#include <gtk/gtk.h>
+#endif
+
+static const int kNumFramesToPaint = 500;
+
+unsigned long CalculateYUVFrameSize(FILE* file_handle, unsigned int num_frames) {
Alpha Left Google 2010/11/15 20:43:51 nit: 80 chars.
Alpha Left Google 2010/11/15 20:43:51 in general don't need unsigned unless necessary, j
Alpha Left Google 2010/11/15 20:43:51 use uint64 for file size and for frame size just i
+ fseek(file_handle, 0, SEEK_END);
+ unsigned long file_size = ftell(file_handle);
+ rewind(file_handle);
+ return file_size / num_frames;
+}
+
+void GetFrames(std::string file_name,
+ std::deque<scoped_refptr<media::VideoFrame> >& out_frames,
Alpha Left Google 2010/11/15 20:43:51 output object use * instead of reference also out
+ int width, int height, int num_frames) {
+ FILE* file_handle = fopen(file_name.c_str(), "rb");
+ if (!file_handle) {
+ printf("Could not open %s\n", file_name.c_str());
+ exit(1);
+ }
+
+ unsigned long frame_size = CalculateYUVFrameSize(file_handle, num_frames);
+
+ for (int i = 0; i < num_frames; i++) {
+ scoped_refptr<media::VideoFrame> video_frame;
+ media::VideoFrame::CreateFrame(media::VideoFrame::YV12,
+ width,
+ height,
+ base::TimeDelta(),
+ base::TimeDelta(),
+ &video_frame);
+ unsigned long bytes_read =
Alpha Left Google 2010/11/15 20:43:51 use int
+ fread(video_frame->data(0), 1, frame_size, file_handle);
+
+ if (bytes_read != frame_size) {
+ printf("Could not read %s\n", file_name.c_str());
+ fclose(file_handle);
+ exit(1);
+ }
+ out_frames.push_back(video_frame);
+ }
+
+ fclose(file_handle);
+}
+
+void RunTest(std::deque<scoped_refptr<media::VideoFrame> >& frames,
+ media::Window* window) {
+ base::TimeTicks start = base::TimeTicks::HighResNow();
+ for (int i = 0; i < kNumFramesToPaint; i++)
+ window->Paint();
Alpha Left Google 2010/11/15 20:43:51 This block of code won't actually measure how fast
+ base::TimeTicks end = base::TimeTicks::HighResNow();
+
+ printf("Printed %d frames in %f ms\n", kNumFramesToPaint,
+ static_cast<double>((end - start).InMilliseconds()) / kNumFramesToPaint);
+}
+
+int main(int argc, char** argv) {
+ // Read command line.
+#if defined(OS_LINUX)
+ gtk_init(&argc, &argv);
+#endif
+ CommandLine::Init(argc, argv);
+
+ // Determine file name.
+ std::string file_name =
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII("file");
+
+ // Determine number of frames.
+ int num_frames = 0;
+ std::string str_num_frames =
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII("frames");
+ base::StringToInt(str_num_frames, &num_frames);
+
+ // Determine video dimensions.
+ int width = 0;
+ int height = 0;
+ std::string dimensions =
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII("wxh");
+ int x_index = dimensions.find('x');
+ std::string str_width = dimensions.substr(0, x_index);
+ std::string str_height =
+ dimensions.substr(x_index + 1, dimensions.length() - x_index - 1);
+ base::StringToInt(str_width, &width);
+ base::StringToInt(str_height, &height);
+
+ // Process files.
+ std::deque<scoped_refptr<media::VideoFrame> > frames;
+ GetFrames(file_name, frames, width, height, num_frames);
scherkus (not reviewing) 2010/11/12 07:45:53 just to make sure.. we load everything into memory
+
+ // Initialize window and graphics context.
+ base::AtExitManager at_exit_manager;
+ gfx::GLContext::InitializeOneOff();
+ media::Window* window = new media::Window(width, height);
+ gfx::GLContext* context =
+ gfx::GLContext::CreateViewGLContext(window->PluginWindow(), false);
+ context->MakeCurrent();
+
+ // Paint and benchmark.
+ GLPainter* gl_painter = new GLPainter();
+ gl_painter->LoadFrames(&frames);
+ gl_painter->SetGLContext(context);
+ gl_painter->Initialize(width, height);
+ window->SetPainter(gl_painter);
+ printf("Running GL shader tests...");
+ RunTest(frames, window);
+
+ delete gl_painter;
+ delete window;
+ return 0;
+}

Powered by Google App Engine
This is Rietveld 408576698