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

Side by Side Diff: tools/vulkan/win/Window_win.cpp

Issue 1848833005: First pass at VulkanViewer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments, plus add GM rendering Created 4 years, 8 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Window_win.h"
9
10 #include <tchar.h>
11 #include <windows.h>
12 #include <windowsx.h>
13
14 #include "VulkanTestContext_win.h"
15
16 Window* Window::CreateNativeWindow(void* platformData) {
17 HINSTANCE hInstance = (HINSTANCE)platformData;
18
19 Window_win* window = new Window_win();
20 if (!window->init(hInstance)) {
21 delete window;
22 return nullptr;
23 }
24
25 return window;
26 }
27
28 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
29
30 bool Window_win::init(HINSTANCE hInstance) {
31 fHInstance = hInstance ? hInstance : GetModuleHandle(nullptr);
32
33 WNDCLASSEX wcex;
34 // The main window class name
35 static const TCHAR gSZWindowClass[] = _T("SkiaApp");
36
37 wcex.cbSize = sizeof(WNDCLASSEX);
38
39 wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
40 wcex.lpfnWndProc = WndProc;
41 wcex.cbClsExtra = 0;
42 wcex.cbWndExtra = 0;
43 wcex.hInstance = fHInstance;
44 wcex.hIcon = LoadIcon(fHInstance, (LPCTSTR)IDI_WINLOGO);
45 wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);;
46 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
47 wcex.lpszMenuName = nullptr;
48 wcex.lpszClassName = gSZWindowClass;
49 wcex.hIconSm = LoadIcon(fHInstance, (LPCTSTR)IDI_WINLOGO);;
50
51 if (!RegisterClassEx(&wcex)) {
52 return false;
53 }
54
55 /*
56 if (fullscreen)
57 {
58 DEVMODE dmScreenSettings;
59 // If full screen set the screen to maximum size of the users desktop an d 32bit.
60 memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
61 dmScreenSettings.dmSize = sizeof(dmScreenSettings);
62 dmScreenSettings.dmPelsWidth = (unsigned long)width;
63 dmScreenSettings.dmPelsHeight = (unsigned long)height;
64 dmScreenSettings.dmBitsPerPel = 32;
65 dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT ;
66
67 // Change the display settings to full screen.
68 ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
69
70 // Set the position of the window to the top left corner.
71 posX = posY = 0;
72 }
73 */
74 // gIsFullscreen = fullscreen;
75
76 fHWnd = CreateWindow(gSZWindowClass, nullptr, WS_OVERLAPPEDWINDOW,
77 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, f HInstance, nullptr);
78 if (!fHWnd)
79 {
80 return false;
81 }
82
83 SetWindowLongPtr(fHWnd, GWLP_USERDATA, (LONG_PTR)this);
84
85 return true;
86 }
87
88
89 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
90 {
91 PAINTSTRUCT ps;
92 HDC hdc;
93
94 Window_win* window = (Window_win*) GetWindowLongPtr(hWnd, GWLP_USERDATA);
95
96 switch (message)
97 {
98 case WM_PAINT:
99 hdc = BeginPaint(hWnd, &ps);
100 window->onPaint();
101 EndPaint(hWnd, &ps);
102 break;
103
104 case WM_CLOSE:
105 case WM_DESTROY:
106 PostQuitMessage(0);
107 break;
108
109 case WM_ACTIVATE:
110 // disable/enable rendering here, depending on wParam != WA_INACTIVE
111 break;
112
113 case WM_SIZE:
114 window->onSize();
115 break;
116
117 case WM_KEYDOWN:
118 case WM_SYSKEYDOWN:
119 {
120 DWORD dwMask = (1 << 29);
121 bool bAltDown = ((lParam & dwMask) != 0);
122 UINT theChar = MapVirtualKey((UINT)wParam, 2);
123 // Handle Extended ASCII only
124 if (theChar < 256) {
125 return window->onKeyboard(theChar, true, bAltDown);
126 }
127 }
128 break;
129
130 case WM_KEYUP:
131 case WM_SYSKEYUP:
132 {
133 DWORD dwMask = (1 << 29);
134 bool bAltDown = ((lParam & dwMask) != 0);
135 UINT theChar = MapVirtualKey((UINT)wParam, 2);
136 // Handle Extended ASCII only
137 if (theChar < 256) {
138 return window->onKeyboard(theChar, false, bAltDown);
139 }
140 }
141 break;
142
143 case WM_LBUTTONDOWN:
144 case WM_RBUTTONDOWN:
145 case WM_MBUTTONDOWN:
146 case WM_LBUTTONUP:
147 case WM_RBUTTONUP:
148 case WM_MBUTTONUP:
149 {
150 bool bLeftDown = ((wParam & MK_LBUTTON) != 0);
151 bool bRightDown = ((wParam & MK_RBUTTON) != 0);
152 bool bMiddleDown = ((wParam & MK_MBUTTON) != 0);
153
154 int xPos = GET_X_LPARAM(lParam);
155 int yPos = GET_Y_LPARAM(lParam);
156 //if (!gIsFullscreen)
157 //{
158 // RECT rc = { 0, 0, 640, 480 };
159 // AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
160 // xPos -= rc.left;
161 // yPos -= rc.top;
162 //}
163
164 return window->onMouse(bLeftDown, bRightDown, bMiddleDown, false, fa lse, 0, xPos, yPos);
165 }
166 break;
167
168 default:
169 return DefWindowProc(hWnd, message, wParam, lParam);
170 }
171
172 return 0;
173 }
174
175 bool Window_win::onKeyboard(UINT nChar, bool bKeyDown, bool bAltDown) {
176 return fKeyFunc(nChar, bKeyDown, fKeyUserData);
177 }
178
179 bool Window_win::onMouse(bool bLeftButtonDown, bool bRightButtonDown, bool bMidd leButtonDown,
180 bool bSideButton1Down, bool bSideButton2Down, int nMous eWheelDelta,
181 int xPos, int yPos) {
182 return fMouseFunc(xPos, yPos, bLeftButtonDown, fMouseUserData);
183 }
184
185 void Window_win::setTitle(const char* title) {
186 SetWindowTextA(fHWnd, title);
187 }
188
189 void Window_win::show() {
190 ShowWindow(fHWnd, SW_SHOW);
191 }
192
193
194 bool Window_win::attach(BackEndTypes attachType, int msaaSampleCount, Attachment Info*) {
195 if (kVulkan_BackendType != attachType) {
196 return false;
197 }
198
199 ContextPlatformData_win platformData;
200 platformData.fHInstance = fHInstance;
201 platformData.fHWnd = fHWnd;
202
203 fTestContext = VulkanTestContext::Create((void*)&platformData, msaaSampleCou nt);
204
205 return (SkToBool(fTestContext));
206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698