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