| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file implements a standalone executable demo of using GLES2 over | 5 // This file implements a standalone executable demo of using GLES2 over |
| 6 // command buffers. This code is temporary as the setup that happens | 6 // command buffers. This code is temporary as the setup that happens |
| 7 // here is in a state of flux. Eventually there will be several versions of | 7 // here is in a state of flux. Eventually there will be several versions of |
| 8 // setup, one for trusted code, one for pepper, one for NaCl, and maybe others. | 8 // setup, one for trusted code, one for pepper, one for NaCl, and maybe others. |
| 9 | 9 |
| 10 #include <windows.h> | 10 #include <windows.h> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "gpu/command_buffer/client/gles2_demo_c.h" | 24 #include "gpu/command_buffer/client/gles2_demo_c.h" |
| 25 #include "gpu/command_buffer/client/gles2_demo_cc.h" | 25 #include "gpu/command_buffer/client/gles2_demo_cc.h" |
| 26 | 26 |
| 27 using base::SharedMemory; | 27 using base::SharedMemory; |
| 28 using gpu::Buffer; | 28 using gpu::Buffer; |
| 29 using gpu::GPUProcessor; | 29 using gpu::GPUProcessor; |
| 30 using gpu::CommandBufferService; | 30 using gpu::CommandBufferService; |
| 31 using gpu::gles2::GLES2CmdHelper; | 31 using gpu::gles2::GLES2CmdHelper; |
| 32 using gpu::gles2::GLES2Implementation; | 32 using gpu::gles2::GLES2Implementation; |
| 33 | 33 |
| 34 #if defined(OS_WIN) |
| 35 HINSTANCE g_instance; |
| 36 #endif |
| 37 |
| 34 class GLES2Demo { | 38 class GLES2Demo { |
| 35 public: | 39 public: |
| 36 GLES2Demo(); | 40 GLES2Demo(); |
| 37 | 41 |
| 38 bool GLES2Demo::Setup(void* hwnd, int32 size); | 42 bool GLES2Demo::Setup(void* hwnd, int32 size); |
| 39 | 43 |
| 40 private: | 44 private: |
| 41 DISALLOW_COPY_AND_ASSIGN(GLES2Demo); | 45 DISALLOW_COPY_AND_ASSIGN(GLES2Demo); |
| 42 }; | 46 }; |
| 43 | 47 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // TODO(gman): Not sure how SwapBuffer should be exposed. | 101 // TODO(gman): Not sure how SwapBuffer should be exposed. |
| 98 gles2::GetGLContext()->SwapBuffers(); | 102 gles2::GetGLContext()->SwapBuffers(); |
| 99 break; | 103 break; |
| 100 } | 104 } |
| 101 default: | 105 default: |
| 102 return ::DefWindowProc(hwnd, msg, w_param, l_param); | 106 return ::DefWindowProc(hwnd, msg, w_param, l_param); |
| 103 } | 107 } |
| 104 return 0; | 108 return 0; |
| 105 } | 109 } |
| 106 | 110 |
| 107 HINSTANCE GetInstance(void) { | |
| 108 HWND hwnd = GetConsoleWindow(); | |
| 109 return reinterpret_cast<HINSTANCE>(GetWindowLong(hwnd, GWL_HINSTANCE)); | |
| 110 } | |
| 111 | |
| 112 void ProcessMessages(void* in_hwnd) { | 111 void ProcessMessages(void* in_hwnd) { |
| 113 HWND hwnd = reinterpret_cast<HWND>(in_hwnd); | 112 HWND hwnd = reinterpret_cast<HWND>(in_hwnd); |
| 114 MSG msg; | 113 MSG msg; |
| 115 | 114 |
| 116 bool done = false; | 115 bool done = false; |
| 117 while (!done) { | 116 while (!done) { |
| 118 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { | 117 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { |
| 119 if (msg.message == WM_QUIT) { | 118 if (msg.message == WM_QUIT) { |
| 120 done = true; | 119 done = true; |
| 121 } | 120 } |
| 122 // dispatch the message | 121 // dispatch the message |
| 123 TranslateMessage(&msg); | 122 TranslateMessage(&msg); |
| 124 DispatchMessage(&msg); | 123 DispatchMessage(&msg); |
| 125 } | 124 } |
| 126 if (!done) { | 125 if (!done) { |
| 127 InvalidateRect(hwnd, NULL, TRUE); | 126 InvalidateRect(hwnd, NULL, TRUE); |
| 128 } | 127 } |
| 129 } | 128 } |
| 130 } | 129 } |
| 131 | 130 |
| 132 #endif | 131 #endif |
| 133 | 132 |
| 134 void* SetupWindow() { | 133 void* SetupWindow() { |
| 135 #if defined(OS_WIN) | 134 #if defined(OS_WIN) |
| 136 HINSTANCE instance = GetInstance(); | |
| 137 WNDCLASSEX wc = {0}; | 135 WNDCLASSEX wc = {0}; |
| 138 wc.lpszClassName = L"MY_WINDOWS_CLASS"; | 136 wc.lpszClassName = L"MY_WINDOWS_CLASS"; |
| 139 wc.cbSize = sizeof(WNDCLASSEX); | 137 wc.cbSize = sizeof(WNDCLASSEX); |
| 140 wc.style = CS_HREDRAW | CS_VREDRAW; | 138 wc.style = CS_HREDRAW | CS_VREDRAW; |
| 141 wc.lpfnWndProc = ::WindowProc; | 139 wc.lpfnWndProc = ::WindowProc; |
| 142 wc.cbClsExtra = 0; | 140 wc.cbClsExtra = 0; |
| 143 wc.cbWndExtra = 0; | 141 wc.cbWndExtra = 0; |
| 144 wc.hInstance = instance; | 142 wc.hInstance = g_instance; |
| 145 wc.hIcon = ::LoadIcon(instance, IDI_APPLICATION); | 143 wc.hIcon = ::LoadIcon(g_instance, IDI_APPLICATION); |
| 146 wc.hIconSm = NULL; | 144 wc.hIconSm = NULL; |
| 147 wc.hCursor = ::LoadCursor(instance, IDC_ARROW); | 145 wc.hCursor = ::LoadCursor(g_instance, IDC_ARROW); |
| 148 wc.hbrBackground = static_cast<HBRUSH>(::GetStockObject(BLACK_BRUSH)); | 146 wc.hbrBackground = static_cast<HBRUSH>(::GetStockObject(BLACK_BRUSH)); |
| 149 wc.lpszMenuName = NULL; | 147 wc.lpszMenuName = NULL; |
| 150 | 148 |
| 151 if (!::RegisterClassEx(&wc)) | 149 if (!::RegisterClassEx(&wc)) |
| 152 return false; | 150 return false; |
| 153 | 151 |
| 154 // Leaving this window onscreen leads to a redraw error which makes it | 152 // Leaving this window onscreen leads to a redraw error which makes it |
| 155 // a hassle to debug tests in an IDE, so we place the window somewhere that | 153 // a hassle to debug tests in an IDE, so we place the window somewhere that |
| 156 // won't happen. | 154 // won't happen. |
| 157 HWND hwnd = ::CreateWindowExW( | 155 HWND hwnd = ::CreateWindowExW( |
| 158 NULL, | 156 NULL, |
| 159 wc.lpszClassName, | 157 wc.lpszClassName, |
| 160 L"", | 158 L"", |
| 161 WS_OVERLAPPEDWINDOW, | 159 WS_OVERLAPPEDWINDOW, |
| 162 10, | 160 10, |
| 163 0, | 161 0, |
| 164 512, | 162 512, |
| 165 512, | 163 512, |
| 166 0, | 164 0, |
| 167 0, | 165 0, |
| 168 instance, | 166 g_instance, |
| 169 0); | 167 0); |
| 170 | 168 |
| 171 if (hwnd == NULL) { | 169 if (hwnd == NULL) { |
| 172 return false; | 170 return false; |
| 173 } | 171 } |
| 174 | 172 |
| 175 ::ShowWindow(hwnd, SW_SHOWNORMAL); | 173 ::ShowWindow(hwnd, SW_SHOWNORMAL); |
| 176 | 174 |
| 177 | 175 |
| 178 return hwnd; | 176 return hwnd; |
| 179 #else | 177 #else |
| 180 #error Need code. | 178 #error Need code. |
| 181 #endif | 179 #endif |
| 182 } | 180 } |
| 183 | 181 |
| 184 int main(int argc, const char** argv) { | 182 #if defined(OS_WIN) |
| 183 int WINAPI WinMain(HINSTANCE instance, |
| 184 HINSTANCE prev_instance, |
| 185 LPSTR command_line, |
| 186 int command_show) { |
| 187 g_instance = instance; |
| 188 #else |
| 189 int main(int argc, char** argv) { |
| 190 #endif |
| 191 |
| 185 const int32 kCommandBufferSize = 1024 * 1024; | 192 const int32 kCommandBufferSize = 1024 * 1024; |
| 186 | 193 |
| 187 base::AtExitManager at_exit_manager; | 194 base::AtExitManager at_exit_manager; |
| 188 MessageLoopForUI message_loop; | 195 MessageLoopForUI message_loop; |
| 189 | 196 |
| 190 GLES2Demo* demo = new GLES2Demo(); | 197 GLES2Demo* demo = new GLES2Demo(); |
| 191 | 198 |
| 192 void* hwnd = SetupWindow(); | 199 void* hwnd = SetupWindow(); |
| 193 if (!hwnd) { | 200 if (!hwnd) { |
| 194 ::fprintf(stdout, "Could not setup window.\n"); | 201 ::fprintf(stdout, "Could not setup window.\n"); |
| 195 return EXIT_FAILURE; | 202 return EXIT_FAILURE; |
| 196 } | 203 } |
| 197 | 204 |
| 198 demo->Setup(hwnd, kCommandBufferSize); | 205 demo->Setup(hwnd, kCommandBufferSize); |
| 199 | 206 |
| 200 ProcessMessages(hwnd); | 207 ProcessMessages(hwnd); |
| 201 | 208 |
| 202 return EXIT_SUCCESS; | 209 return EXIT_SUCCESS; |
| 203 } | 210 } |
| 204 | 211 |
| 205 | 212 |
| OLD | NEW |