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

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

Issue 4873002: Benchmark tool for GPU-accelerated video rendering (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed media.gyp 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
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/window.h"
6
7 #include "base/task.h"
8 #include "media/tools/shader_bench/painter.h"
9
10 namespace {
11
12 LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg,
13 WPARAM w_param, LPARAM l_param) {
14 LRESULT result = 0;
15 switch (msg) {
16 case WM_CLOSE:
17 ::DestroyWindow(hwnd);
18 break;
19 case WM_DESTROY:
20 ::PostQuitMessage(0);
21 break;
22 case WM_ERASEBKGND:
23 // Return a non-zero value to indicate that the background has been
24 // erased.
25 result = 1;
26 break;
27 case WM_PAINT: {
28 media::Window* window =
29 reinterpret_cast<media::Window*>(
30 GetWindowLongPtr(hwnd, GWL_USERDATA));
31 if (window != NULL) window->OnPaint();
scherkus (not reviewing) 2010/11/30 23:36:10 nit: one-liners
vrk (LEFT CHROMIUM) 2010/12/01 02:46:11 Done.
32 ::ValidateRect(hwnd, NULL);
33 break;
34 }
35 default:
36 result = ::DefWindowProc(hwnd, msg, w_param, l_param);
37 break;
38 }
39 return result;
40 }
41
42 } // namespace
43
44 namespace media {
45
46 gfx::NativeWindow Window::CreateNativeWindow(int width, int height) {
47 WNDCLASS wnd_class = {0};
48 HINSTANCE instance = GetModuleHandle(NULL);
49 wnd_class.style = CS_OWNDC;
50 wnd_class.lpfnWndProc = WindowProc;
51 wnd_class.hInstance = instance;
52 wnd_class.hbrBackground =
53 reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));
54 wnd_class.lpszClassName = L"gpu_demo";
55 if (!RegisterClass(&wnd_class)) return NULL;
scherkus (not reviewing) 2010/11/30 23:36:10 nit: one-liners
vrk (LEFT CHROMIUM) 2010/12/01 02:46:11 Done.
56
57 DWORD wnd_style = WS_OVERLAPPED | WS_SYSMENU;
58 RECT wnd_rect;
59 wnd_rect.left = 0;
60 wnd_rect.top = 0;
61 wnd_rect.right = width;
62 wnd_rect.bottom = height;
63 AdjustWindowRect(&wnd_rect, wnd_style, FALSE);
64
65 HWND hwnd = CreateWindow(
66 wnd_class.lpszClassName,
67 L"",
68 wnd_style,
69 0,
70 0,
71 wnd_rect.right - wnd_rect.left,
72 wnd_rect.bottom - wnd_rect.top,
73 NULL,
74 NULL,
75 instance,
76 NULL);
77 if (hwnd == NULL) return NULL;
scherkus (not reviewing) 2010/11/30 23:36:10 nit: one-liners
vrk (LEFT CHROMIUM) 2010/12/01 02:46:11 Done.
78
79 return hwnd;
80 }
81
82 gfx::PluginWindowHandle Window::PluginWindow() {
83 return window_handle_;
84 }
85
86 void Window::Start(int limit, Task* done_task, Painter* painter) {
87 running_ = true;
88 count_ = 0;
89 limit_ = limit;
90 done_task_ = done_task;
91 painter_ = painter;
92
93 SetWindowLongPtr(window_handle_, GWL_USERDATA,
94 reinterpret_cast<LONG_PTR>(this));
95
96 ShowWindow(window_handle_, SW_SHOWNORMAL);
97
98 // Post first invalidate call to kick off painting.
99 ::InvalidateRect(window_handle_, NULL, FALSE);
100
101 MainLoop();
102 }
103
104 void Window::OnPaint() {
105 if (!running_)
106 return;
107
108 if (count_ < limit_) {
109 painter_->OnPaint();
110 count_++;
111 } else {
112 running_ = false;
113 if (done_task_) {
114 ShowWindow(window_handle_, SW_HIDE);
115 done_task_->Run();
116 delete done_task_;
117 }
118 }
119 }
120 void Window::MainLoop() {
121 MSG msg;
122 bool done = false;
123 while (!done) {
124 while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
125 if (msg.message == WM_QUIT || !running_)
126 done = true;
127 ::TranslateMessage(&msg);
128 ::DispatchMessage(&msg);
129 if (!done)
130 ::InvalidateRect(window_handle_, NULL, FALSE);
131 }
132 }
133 }
134
135 } // namespace media
OLDNEW
« media/tools/shader_bench/window_linux.cc ('K') | « media/tools/shader_bench/window_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698