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 "media/tools/shader_bench/window.h" | |
6 | |
7 #include "base/utf_string_conversions.h" | |
8 | |
9 namespace { | |
10 | |
11 LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, | |
12 WPARAM w_param, LPARAM l_param) { | |
13 LRESULT result = 0; | |
14 switch (msg) { | |
15 case WM_CLOSE: | |
16 ::DestroyWindow(hwnd); | |
17 break; | |
18 case WM_DESTROY: | |
19 ::PostQuitMessage(0); | |
20 break; | |
21 case WM_ERASEBKGND: | |
22 // Return a non-zero value to indicate that the background has been | |
23 // erased. | |
24 result = 1; | |
25 break; | |
26 case WM_PAINT: { | |
27 media::Window* window = | |
28 reinterpret_cast<media::Window*>( | |
29 GetWindowLongPtr(hwnd, GWL_USERDATA)); | |
30 if (window != NULL) window->OnPaint(); | |
31 ::ValidateRect(hwnd, NULL); | |
32 break; | |
33 } | |
34 default: | |
35 result = ::DefWindowProc(hwnd, msg, w_param, l_param); | |
36 break; | |
37 } | |
38 return result; | |
39 } | |
40 | |
41 } // namespace | |
42 | |
43 namespace media { | |
44 | |
45 gfx::NativeWindow Window::CreateNativeWindow(int width, int height) { | |
46 WNDCLASS wnd_class = {0}; | |
47 HINSTANCE instance = GetModuleHandle(NULL); | |
48 wnd_class.style = CS_OWNDC; | |
49 wnd_class.lpfnWndProc = WindowProc; | |
50 wnd_class.hInstance = instance; | |
51 wnd_class.hbrBackground = | |
52 reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)); | |
53 wnd_class.lpszClassName = L"gpu_demo"; | |
54 if (!RegisterClass(&wnd_class)) return NULL; | |
55 | |
56 DWORD wnd_style = WS_OVERLAPPED | WS_SYSMENU; | |
57 RECT wnd_rect; | |
58 wnd_rect.left = 0; | |
59 wnd_rect.top = 0; | |
60 wnd_rect.right = width; | |
61 wnd_rect.bottom = height; | |
62 AdjustWindowRect(&wnd_rect, wnd_style, FALSE); | |
63 | |
64 HWND hwnd = CreateWindow( | |
65 wnd_class.lpszClassName, | |
66 L"", | |
67 wnd_style, | |
68 0, | |
69 0, | |
70 wnd_rect.right - wnd_rect.left, | |
71 wnd_rect.bottom - wnd_rect.top, | |
72 NULL, | |
73 NULL, | |
74 instance, | |
75 NULL); | |
76 if (hwnd == NULL) return NULL; | |
77 | |
78 return hwnd; | |
79 } | |
80 | |
81 gfx::PluginWindowHandle Window::PluginWindow() { | |
82 return window_handle_; | |
83 } | |
84 | |
85 void Window::Start(int limit, Task* done_task, Painter* painter) { | |
86 running_ = true; | |
87 count_ = 0; | |
88 limit_ = limit; | |
89 done_task_ = done_task; | |
90 painter_ = painter; | |
91 | |
92 SetWindowLongPtr(window_handle_, GWL_USERDATA, | |
93 reinterpret_cast<LONG_PTR>(this)); | |
94 | |
95 ShowWindow(window_handle_, SW_SHOWNORMAL); | |
96 | |
97 // Post first invalidate call to kick off painting. | |
98 ::InvalidateRect(window_handle_, NULL, FALSE); | |
99 | |
100 MainLoop(); | |
101 } | |
102 | |
103 void Window::OnPaint() { | |
104 if (!running_) | |
105 return; | |
106 | |
107 if (count_ < limit_) { | |
108 painter_->OnPaint(); | |
109 count_++; | |
110 } else { | |
111 running_ = false; | |
112 if (done_task_) { | |
113 ShowWindow(window_handle_, SW_HIDE); | |
114 done_task_->Run(); | |
115 delete done_task_; | |
116 } | |
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 } | |
Alpha Left Google
2010/11/19 23:33:51
// namespace media
vrk (LEFT CHROMIUM)
2010/11/24 22:01:30
Done.
| |
OLD | NEW |