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 "gpu/demos/framework/window.h" |
| 6 |
| 7 namespace { |
| 8 LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, |
| 9 WPARAM w_param, LPARAM l_param) { |
| 10 LRESULT result = 0; |
| 11 switch (msg) { |
| 12 case WM_CLOSE: |
| 13 ::DestroyWindow(hwnd); |
| 14 break; |
| 15 case WM_DESTROY: |
| 16 ::PostQuitMessage(0); |
| 17 break; |
| 18 case WM_ERASEBKGND: |
| 19 break; |
| 20 case WM_PAINT: { |
| 21 gpu::demos::Window* window = reinterpret_cast<gpu::demos::Window*>( |
| 22 GetWindowLongPtr(hwnd, GWL_USERDATA)); |
| 23 if (window != NULL) window->OnPaint(); |
| 24 ::ValidateRect(hwnd, NULL); |
| 25 break; |
| 26 } |
| 27 default: |
| 28 result = ::DefWindowProc(hwnd, msg, w_param, l_param); |
| 29 break; |
| 30 } |
| 31 return result; |
| 32 } |
| 33 } // namespace. |
| 34 |
| 35 namespace gpu { |
| 36 namespace demos { |
| 37 |
| 38 void Window::MainLoop() { |
| 39 // Set this to the GWL_USERDATA so that it is available to WindowProc. |
| 40 SetWindowLongPtr(window_handle_, GWL_USERDATA, |
| 41 reinterpret_cast<LONG_PTR>(this)); |
| 42 |
| 43 MSG msg; |
| 44 bool done = false; |
| 45 while (!done) { |
| 46 while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { |
| 47 if (msg.message == WM_QUIT) done = true; |
| 48 ::TranslateMessage(&msg); |
| 49 ::DispatchMessage(&msg); |
| 50 } |
| 51 // Message queue is empty and application has not quit yet - keep painting. |
| 52 if (!done) ::UpdateWindow(window_handle_); |
| 53 } |
| 54 } |
| 55 |
| 56 gfx::NativeWindow Window::CreateNativeWindow(const wchar_t* title, |
| 57 int width, int height) { |
| 58 WNDCLASS wnd_class = {0}; |
| 59 HINSTANCE instance = GetModuleHandle(NULL); |
| 60 wnd_class.style = CS_OWNDC; |
| 61 wnd_class.lpfnWndProc = WindowProc; |
| 62 wnd_class.hInstance = instance; |
| 63 wnd_class.hbrBackground = |
| 64 reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)); |
| 65 wnd_class.lpszClassName = L"gpu_demo"; |
| 66 if (!RegisterClass(&wnd_class)) return NULL; |
| 67 |
| 68 DWORD wnd_style = WS_VISIBLE | WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION; |
| 69 RECT wnd_rect; |
| 70 wnd_rect.left = 0; |
| 71 wnd_rect.top = 0; |
| 72 wnd_rect.right = width; |
| 73 wnd_rect.bottom = height; |
| 74 AdjustWindowRect(&wnd_rect, wnd_style, FALSE); |
| 75 |
| 76 HWND hwnd = CreateWindow( |
| 77 wnd_class.lpszClassName, |
| 78 title, |
| 79 wnd_style, |
| 80 0, |
| 81 0, |
| 82 wnd_rect.right - wnd_rect.left, |
| 83 wnd_rect.bottom - wnd_rect.top, |
| 84 NULL, |
| 85 NULL, |
| 86 instance, |
| 87 NULL); |
| 88 if (hwnd == NULL) return NULL; |
| 89 |
| 90 ShowWindow(hwnd, SW_SHOWNORMAL); |
| 91 return hwnd; |
| 92 } |
| 93 |
| 94 gfx::PluginWindowHandle Window::PluginWindow(gfx::NativeWindow hwnd) { |
| 95 return hwnd; |
| 96 } |
| 97 |
| 98 } // namespace demos |
| 99 } // namespace gpu |
| 100 |
OLD | NEW |