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

Side by Side Diff: src/views/win/skia_win.cpp

Issue 1187643002: VisualBench on windows (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 6 months 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
« no previous file with comments | « src/views/win/SkOSWindow_win.cpp ('k') | tools/VisualBench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include <windows.h> 8 #include <windows.h>
9 #include <tchar.h> 9 #include <tchar.h>
10 10
11 #include "SkApplication.h" 11 #include "SkApplication.h"
12 12
13 #define MAX_LOADSTRING 100 13 #define MAX_LOADSTRING 100
14 14
15 // Global Variables: 15 // Global Variables:
16 HINSTANCE hInst; // current instance 16 HINSTANCE gHInst; // current instance
17 TCHAR szTitle[] = _T("SampleApp"); // The title bar text 17 TCHAR gSZWindowClass[] = _T("SkiaApp"); // the main window class name
18 TCHAR szWindowClass[] = _T("SAMPLEAPP"); // the main window class name
19 18
20 // Forward declarations of functions included in this code module: 19 // Forward declarations of functions included in this code module:
21 ATOM MyRegisterClass(HINSTANCE hInstance); 20 ATOM MyRegisterClass(HINSTANCE hInstance);
22 BOOL InitInstance(HINSTANCE, int, LPTSTR); 21 BOOL InitInstance(HINSTANCE, int, LPTSTR);
23 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 22 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
24 INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); 23 INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
25 24
26 int APIENTRY _tWinMain(HINSTANCE hInstance, 25 int APIENTRY _tWinMain(HINSTANCE hInstance,
27 HINSTANCE hPrevInstance, 26 HINSTANCE hPrevInstance,
28 LPTSTR lpCmdLine, 27 LPTSTR lpCmdLine,
29 int nCmdShow) 28 int nCmdShow)
30 { 29 {
31 UNREFERENCED_PARAMETER(hPrevInstance); 30 UNREFERENCED_PARAMETER(hPrevInstance);
32 31
33 MSG msg; 32 MSG msg;
34 33
35 // Initialize global strings 34 // Initialize global strings
36 MyRegisterClass(hInstance); 35 MyRegisterClass(hInstance);
37 36
38 // Perform application initialization: 37 // Perform application initialization:
39 if (!InitInstance (hInstance, nCmdShow, lpCmdLine)) 38 if (!InitInstance (hInstance, nCmdShow, lpCmdLine))
(...skipping 30 matching lines...) Expand all
70 // function that was added to Windows 95. It is important to call this functi on 69 // function that was added to Windows 95. It is important to call this functi on
71 // so that the application will get 'well formed' small icons associated 70 // so that the application will get 'well formed' small icons associated
72 // with it. 71 // with it.
73 // 72 //
74 ATOM MyRegisterClass(HINSTANCE hInstance) 73 ATOM MyRegisterClass(HINSTANCE hInstance)
75 { 74 {
76 WNDCLASSEX wcex; 75 WNDCLASSEX wcex;
77 76
78 wcex.cbSize = sizeof(WNDCLASSEX); 77 wcex.cbSize = sizeof(WNDCLASSEX);
79 78
80 wcex.style = CS_HREDRAW | CS_VREDRAW; 79 wcex.style = CS_HREDRAW | CS_VREDRAW;
81 wcex.lpfnWndProc = WndProc; 80 wcex.lpfnWndProc = WndProc;
82 wcex.cbClsExtra = 0; 81 wcex.cbClsExtra = 0;
83 wcex.cbWndExtra = 0; 82 wcex.cbWndExtra = 0;
84 wcex.hInstance = hInstance; 83 wcex.hInstance = hInstance;
85 wcex.hIcon = NULL; 84 wcex.hIcon = NULL;
86 wcex.hCursor = NULL; 85 wcex.hCursor = NULL;
87 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 86 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
88 wcex.lpszMenuName = NULL; 87 wcex.lpszMenuName = NULL;
89 wcex.lpszClassName = szWindowClass; 88 wcex.lpszClassName = gSZWindowClass;
90 wcex.hIconSm = NULL; 89 wcex.hIconSm = NULL;
91 90
92 return RegisterClassEx(&wcex); 91 return RegisterClassEx(&wcex);
93 } 92 }
94 93
95 #include "SkOSWindow_Win.h" 94 #include "SkOSWindow_Win.h"
96 extern SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv); 95 extern SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv);
97 96
98 static SkOSWindow* gSkWind;
99
100 char* tchar_to_utf8(const TCHAR* str) { 97 char* tchar_to_utf8(const TCHAR* str) {
101 #ifdef _UNICODE 98 #ifdef _UNICODE
102 int size = WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), NULL, 0, NULL, NULL); 99 int size = WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), NULL, 0, NULL, NULL);
103 char* str8 = (char*) sk_malloc_throw(size+1); 100 char* str8 = (char*) sk_malloc_throw(size+1);
104 WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), str8, size, NULL, NULL); 101 WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), str8, size, NULL, NULL);
105 str8[size] = '\0'; 102 str8[size] = '\0';
106 return str8; 103 return str8;
107 #else 104 #else
108 return _strdup(str); 105 return _strdup(str);
109 #endif 106 #endif
110 } 107 }
111 108
112 // 109 //
113 // FUNCTION: InitInstance(HINSTANCE, int, LPTSTR) 110 // FUNCTION: InitInstance(HINSTANCE, int, LPTSTR)
114 // 111 //
115 // PURPOSE: Saves instance handle and creates main window 112 // PURPOSE: Saves instance handle and creates main window
116 // 113 //
117 // COMMENTS: 114 // COMMENTS:
118 // 115 //
119 // In this function, we save the instance handle in a global variable and 116 // In this function, we save the instance handle in a global variable and
120 // create and display the main program window. 117 // create and display the main program window.
121 // 118 //
122 119
123 120
124 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow, LPTSTR lpCmdLine) 121 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow, LPTSTR lpCmdLine)
125 { 122 {
126 application_init(); 123 application_init();
127 124
128 hInst = hInstance; // Store instance handle in our global variable 125 gHInst = hInstance; // Store instance handle in our global variable
129
130 HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
131 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hIns tance, NULL);
132
133 if (!hWnd)
134 {
135 return FALSE;
136 }
137
138 char* argv[4096]; 126 char* argv[4096];
139 int argc = 0; 127 int argc = 0;
140 TCHAR exename[1024], *next; 128 TCHAR exename[1024], *next;
141 int exenameLen = GetModuleFileName(NULL, exename, SK_ARRAY_COUNT(exename)); 129 int exenameLen = GetModuleFileName(NULL, exename, SK_ARRAY_COUNT(exename));
142 // we're ignoring the possibility that the exe name exceeds the exename buffe r 130 // we're ignoring the possibility that the exe name exceeds the exename buffe r
143 (void) exenameLen; 131 (void) exenameLen;
144 argv[argc++] = tchar_to_utf8(exename); 132 argv[argc++] = tchar_to_utf8(exename);
145 TCHAR* arg = _tcstok_s(lpCmdLine, _T(" "), &next); 133 TCHAR* arg = _tcstok_s(lpCmdLine, _T(" "), &next);
146 while (arg != NULL) { 134 while (arg != NULL) {
147 argv[argc++] = tchar_to_utf8(arg); 135 argv[argc++] = tchar_to_utf8(arg);
148 arg = _tcstok_s(NULL, _T(" "), &next); 136 arg = _tcstok_s(NULL, _T(" "), &next);
149 } 137 }
150 138
151 gSkWind = create_sk_window(hWnd, argc, argv); 139 SkOSWindow::WindowInit winInit;
140 winInit.fInstance = gHInst;
141 winInit.fClass = gSZWindowClass;
142
143 create_sk_window(&winInit, argc, argv);
152 for (int i = 0; i < argc; ++i) { 144 for (int i = 0; i < argc; ++i) {
153 sk_free(argv[i]); 145 sk_free(argv[i]);
154 } 146 }
155 ShowWindow(hWnd, nCmdShow); 147 SkOSWindow::ForAllWindows([nCmdShow](void* hWnd, SkOSWindow**){
156 UpdateWindow(hWnd); 148 ShowWindow((HWND)hWnd, nCmdShow);
149 UpdateWindow((HWND)hWnd); }
150 );
157 151
158 return TRUE; 152 return TRUE;
159 } 153 }
160 154
161 // 155 //
162 // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) 156 // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
163 // 157 //
164 // PURPOSE: Processes messages for the main window. 158 // PURPOSE: Processes messages for the main window.
165 // 159 //
166 // WM_COMMAND - process the application menu 160 // WM_COMMAND - process the application menu
167 // WM_PAINT - Paint the main window 161 // WM_PAINT - Paint the main window
168 // WM_DESTROY - post a quit message and return 162 // WM_DESTROY - post a quit message and return
169 // 163 //
170 // 164 //
171 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 165 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
172 { 166 {
173 switch (message) { 167 switch (message) {
174 case WM_COMMAND: 168 case WM_COMMAND:
175 return DefWindowProc(hWnd, message, wParam, lParam);
176 case WM_DESTROY:
177 PostQuitMessage(0);
178 break;
179 default:
180 if (gSkWind->wndProc(hWnd, message, wParam, lParam)) {
181 return 0;
182 } else {
183 return DefWindowProc(hWnd, message, wParam, lParam); 169 return DefWindowProc(hWnd, message, wParam, lParam);
170 case WM_DESTROY:
171 PostQuitMessage(0);
172 break;
173 default: {
174 SkOSWindow* window = SkOSWindow::GetOSWindowForHWND(hWnd);
175 if (window && window->wndProc(hWnd, message, wParam, lParam)) {
176 return 0;
177 } else {
178 return DefWindowProc(hWnd, message, wParam, lParam);
179 }
184 } 180 }
185 } 181 }
186 return 0; 182 return 0;
187 } 183 }
188 184
189 // Message handler for about box. 185 // Message handler for about box.
190 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 186 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
191 { 187 {
192 UNREFERENCED_PARAMETER(lParam); 188 UNREFERENCED_PARAMETER(lParam);
193 switch (message) 189 switch (message)
194 { 190 {
195 case WM_INITDIALOG: 191 case WM_INITDIALOG:
196 return (INT_PTR)TRUE; 192 return (INT_PTR)TRUE;
197 193
198 case WM_COMMAND: 194 case WM_COMMAND:
199 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 195 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
200 { 196 {
201 EndDialog(hDlg, LOWORD(wParam)); 197 EndDialog(hDlg, LOWORD(wParam));
202 return (INT_PTR)TRUE; 198 return (INT_PTR)TRUE;
203 } 199 }
204 break; 200 break;
205 } 201 }
206 return (INT_PTR)FALSE; 202 return (INT_PTR)FALSE;
207 } 203 }
OLDNEW
« no previous file with comments | « src/views/win/SkOSWindow_win.cpp ('k') | tools/VisualBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698