blob: 620bd7189c244de3d3063b556637c08995455275 [file] [log] [blame]
bsalomon@google.com2858b312012-04-02 20:44:38 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#include "SkTypes.h"
9
10#if defined(SK_BUILD_FOR_WIN)
11
12#include <GL/gl.h>
bsalomon@google.com2858b312012-04-02 20:44:38 +000013#include <WindowsX.h>
14#include "SkWGL.h"
15#include "SkWindow.h"
16#include "SkCanvas.h"
17#include "SkOSMenu.h"
18#include "SkTime.h"
19#include "SkUtils.h"
20
21#include "SkGraphics.h"
22
23#if SK_ANGLE
24#include "gl/GrGLInterface.h"
25
26#include "GLES2/gl2.h"
borenet@google.com0dd5ceb2012-08-28 15:15:49 +000027
28#define ANGLE_GL_CALL(IFACE, X) \
29 do { \
30 (IFACE)->f##X; \
31 } while (false)
32
bsalomon@google.com2858b312012-04-02 20:44:38 +000033#endif
34
35#define INVALIDATE_DELAY_MS 200
36
37static SkOSWindow* gCurrOSWin;
38static HWND gEventTarget;
39
40#define WM_EVENT_CALLBACK (WM_USER+0)
41
42void post_skwinevent()
43{
44 PostMessage(gEventTarget, WM_EVENT_CALLBACK, 0, 0);
45}
46
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000047SkOSWindow::SkOSWindow(void* hWnd) {
48 fHWND = hWnd;
49#if SK_SUPPORT_GPU
bsalomon@google.com2858b312012-04-02 20:44:38 +000050#if SK_ANGLE
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000051 fDisplay = EGL_NO_DISPLAY;
52 fContext = EGL_NO_CONTEXT;
53 fSurface = EGL_NO_SURFACE;
bsalomon@google.com2858b312012-04-02 20:44:38 +000054#endif
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000055 fHGLRC = NULL;
56#endif
57 fAttached = kNone_BackEndType;
bsalomon@google.com2858b312012-04-02 20:44:38 +000058 gEventTarget = (HWND)hWnd;
59}
60
61SkOSWindow::~SkOSWindow() {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000062#if SK_SUPPORT_GPU
bsalomon@google.com2858b312012-04-02 20:44:38 +000063 if (NULL != fHGLRC) {
64 wglDeleteContext((HGLRC)fHGLRC);
65 }
66#if SK_ANGLE
67 if (EGL_NO_CONTEXT != fContext) {
68 eglDestroyContext(fDisplay, fContext);
69 fContext = EGL_NO_CONTEXT;
70 }
71
72 if (EGL_NO_SURFACE != fSurface) {
73 eglDestroySurface(fDisplay, fSurface);
74 fSurface = EGL_NO_SURFACE;
75 }
76
77 if (EGL_NO_DISPLAY != fDisplay) {
78 eglTerminate(fDisplay);
79 fDisplay = EGL_NO_DISPLAY;
80 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000081#endif // SK_ANGLE
82#endif // SK_SUPPORT_GPU
bsalomon@google.com2858b312012-04-02 20:44:38 +000083}
84
85static SkKey winToskKey(WPARAM vk) {
86 static const struct {
87 WPARAM fVK;
88 SkKey fKey;
89 } gPair[] = {
90 { VK_BACK, kBack_SkKey },
91 { VK_CLEAR, kBack_SkKey },
92 { VK_RETURN, kOK_SkKey },
93 { VK_UP, kUp_SkKey },
94 { VK_DOWN, kDown_SkKey },
95 { VK_LEFT, kLeft_SkKey },
96 { VK_RIGHT, kRight_SkKey }
97 };
98 for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
99 if (gPair[i].fVK == vk) {
100 return gPair[i].fKey;
101 }
102 }
103 return kNONE_SkKey;
104}
105
reed@google.com4d5c26d2013-01-08 16:17:50 +0000106static unsigned getModifiers(UINT message) {
107 return 0; // TODO
108}
109
bsalomon@google.com2858b312012-04-02 20:44:38 +0000110bool SkOSWindow::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
111 switch (message) {
112 case WM_KEYDOWN: {
113 SkKey key = winToskKey(wParam);
114 if (kNONE_SkKey != key) {
115 this->handleKey(key);
116 return true;
117 }
118 } break;
119 case WM_KEYUP: {
120 SkKey key = winToskKey(wParam);
121 if (kNONE_SkKey != key) {
122 this->handleKeyUp(key);
123 return true;
124 }
125 } break;
126 case WM_UNICHAR:
127 this->handleChar(wParam);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000128 return true;
bsalomon@google.com2858b312012-04-02 20:44:38 +0000129 case WM_CHAR: {
130 this->handleChar(SkUTF8_ToUnichar((char*)&wParam));
131 return true;
132 } break;
133 case WM_SIZE:
134 this->resize(lParam & 0xFFFF, lParam >> 16);
135 break;
136 case WM_PAINT: {
137 PAINTSTRUCT ps;
138 HDC hdc = BeginPaint(hWnd, &ps);
139 this->doPaint(hdc);
140 EndPaint(hWnd, &ps);
141 return true;
142 } break;
143
144 case WM_TIMER: {
145 RECT* rect = (RECT*)wParam;
146 InvalidateRect(hWnd, rect, FALSE);
147 KillTimer(hWnd, (UINT_PTR)rect);
148 delete rect;
149 return true;
150 } break;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000151
152 case WM_LBUTTONDOWN:
reed@google.com4d5c26d2013-01-08 16:17:50 +0000153 this->handleClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
reed@google.com72708fa2013-01-08 16:22:44 +0000154 Click::kDown_State, NULL, getModifiers(message));
bsalomon@google.com2858b312012-04-02 20:44:38 +0000155 return true;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000156
bsalomon@google.com2858b312012-04-02 20:44:38 +0000157 case WM_MOUSEMOVE:
reed@google.com4d5c26d2013-01-08 16:17:50 +0000158 this->handleClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
reed@google.com72708fa2013-01-08 16:22:44 +0000159 Click::kMoved_State, NULL, getModifiers(message));
bsalomon@google.com2858b312012-04-02 20:44:38 +0000160 return true;
161
162 case WM_LBUTTONUP:
reed@google.com4d5c26d2013-01-08 16:17:50 +0000163 this->handleClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
reed@google.com72708fa2013-01-08 16:22:44 +0000164 Click::kUp_State, NULL, getModifiers(message));
bsalomon@google.com2858b312012-04-02 20:44:38 +0000165 return true;
166
167 case WM_EVENT_CALLBACK:
168 if (SkEvent::ProcessEvent()) {
169 post_skwinevent();
170 }
171 return true;
172 }
173 return false;
174}
175
176void SkOSWindow::doPaint(void* ctx) {
177 this->update(NULL);
178
179 if (kNone_BackEndType == fAttached)
180 {
181 HDC hdc = (HDC)ctx;
182 const SkBitmap& bitmap = this->getBitmap();
183
184 BITMAPINFO bmi;
185 memset(&bmi, 0, sizeof(bmi));
186 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
187 bmi.bmiHeader.biWidth = bitmap.width();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000188 bmi.bmiHeader.biHeight = -bitmap.height(); // top-down image
bsalomon@google.com2858b312012-04-02 20:44:38 +0000189 bmi.bmiHeader.biPlanes = 1;
190 bmi.bmiHeader.biBitCount = 32;
191 bmi.bmiHeader.biCompression = BI_RGB;
192 bmi.bmiHeader.biSizeImage = 0;
193
rmistry@google.comd6176b02012-08-23 18:14:13 +0000194 //
195 // Do the SetDIBitsToDevice.
196 //
bsalomon@google.com2858b312012-04-02 20:44:38 +0000197 // TODO(wjmaclean):
198 // Fix this call to handle SkBitmaps that have rowBytes != width,
199 // i.e. may have padding at the end of lines. The SkASSERT below
200 // may be ignored by builds, and the only obviously safe option
201 // seems to be to copy the bitmap to a temporary (contiguous)
202 // buffer before passing to SetDIBitsToDevice().
203 SkASSERT(bitmap.width() * bitmap.bytesPerPixel() == bitmap.rowBytes());
204 bitmap.lockPixels();
205 int iRet = SetDIBitsToDevice(hdc,
206 0, 0,
207 bitmap.width(), bitmap.height(),
208 0, 0,
209 0, bitmap.height(),
210 bitmap.getPixels(),
211 &bmi,
212 DIB_RGB_COLORS);
213 bitmap.unlockPixels();
214 }
215}
216
217#if 0
218void SkOSWindow::updateSize()
219{
220 RECT r;
221 GetWindowRect((HWND)this->getHWND(), &r);
222 this->resize(r.right - r.left, r.bottom - r.top);
223}
224#endif
225
226void SkOSWindow::onHandleInval(const SkIRect& r) {
227 RECT* rect = new RECT;
228 rect->left = r.fLeft;
229 rect->top = r.fTop;
230 rect->right = r.fRight;
231 rect->bottom = r.fBottom;
232 SetTimer((HWND)fHWND, (UINT_PTR)rect, INVALIDATE_DELAY_MS, NULL);
233}
234
235void SkOSWindow::onAddMenu(const SkOSMenu* sk_menu)
236{
237}
238
239void SkOSWindow::onSetTitle(const char title[]){
240 SetWindowTextA((HWND)fHWND, title);
241}
242
243enum {
244 SK_MacReturnKey = 36,
245 SK_MacDeleteKey = 51,
246 SK_MacEndKey = 119,
247 SK_MacLeftKey = 123,
248 SK_MacRightKey = 124,
249 SK_MacDownKey = 125,
250 SK_MacUpKey = 126,
rmistry@google.comd6176b02012-08-23 18:14:13 +0000251
bsalomon@google.com2858b312012-04-02 20:44:38 +0000252 SK_Mac0Key = 0x52,
253 SK_Mac1Key = 0x53,
254 SK_Mac2Key = 0x54,
255 SK_Mac3Key = 0x55,
256 SK_Mac4Key = 0x56,
257 SK_Mac5Key = 0x57,
258 SK_Mac6Key = 0x58,
259 SK_Mac7Key = 0x59,
260 SK_Mac8Key = 0x5b,
261 SK_Mac9Key = 0x5c
262};
rmistry@google.comd6176b02012-08-23 18:14:13 +0000263
bsalomon@google.com2858b312012-04-02 20:44:38 +0000264static SkKey raw2key(uint32_t raw)
265{
266 static const struct {
267 uint32_t fRaw;
268 SkKey fKey;
269 } gKeys[] = {
270 { SK_MacUpKey, kUp_SkKey },
271 { SK_MacDownKey, kDown_SkKey },
272 { SK_MacLeftKey, kLeft_SkKey },
273 { SK_MacRightKey, kRight_SkKey },
274 { SK_MacReturnKey, kOK_SkKey },
275 { SK_MacDeleteKey, kBack_SkKey },
276 { SK_MacEndKey, kEnd_SkKey },
277 { SK_Mac0Key, k0_SkKey },
278 { SK_Mac1Key, k1_SkKey },
279 { SK_Mac2Key, k2_SkKey },
280 { SK_Mac3Key, k3_SkKey },
281 { SK_Mac4Key, k4_SkKey },
282 { SK_Mac5Key, k5_SkKey },
283 { SK_Mac6Key, k6_SkKey },
284 { SK_Mac7Key, k7_SkKey },
285 { SK_Mac8Key, k8_SkKey },
286 { SK_Mac9Key, k9_SkKey }
287 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000288
bsalomon@google.com2858b312012-04-02 20:44:38 +0000289 for (unsigned i = 0; i < SK_ARRAY_COUNT(gKeys); i++)
290 if (gKeys[i].fRaw == raw)
291 return gKeys[i].fKey;
292 return kNONE_SkKey;
293}
294
295///////////////////////////////////////////////////////////////////////////////////////
296
297void SkEvent::SignalNonEmptyQueue()
298{
299 post_skwinevent();
300 //SkDebugf("signal nonempty\n");
301}
302
303static UINT_PTR gTimer;
304
305VOID CALLBACK sk_timer_proc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
306{
307 SkEvent::ServiceQueueTimer();
308 //SkDebugf("timer task fired\n");
309}
310
311void SkEvent::SignalQueueTimer(SkMSec delay)
312{
313 if (gTimer)
314 {
315 KillTimer(NULL, gTimer);
316 gTimer = NULL;
317 }
318 if (delay)
rmistry@google.comd6176b02012-08-23 18:14:13 +0000319 {
bsalomon@google.com2858b312012-04-02 20:44:38 +0000320 gTimer = SetTimer(NULL, 0, delay, sk_timer_proc);
321 //SkDebugf("SetTimer of %d returned %d\n", delay, gTimer);
322 }
323}
324
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000325#if SK_SUPPORT_GPU
bsalomon@google.com2858b312012-04-02 20:44:38 +0000326
bsalomon@google.com11959252012-04-06 20:13:38 +0000327bool SkOSWindow::attachGL(int msaaSampleCount) {
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000328 HDC dc = GetDC((HWND)fHWND);
bsalomon@google.com2858b312012-04-02 20:44:38 +0000329 if (NULL == fHGLRC) {
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000330 fHGLRC = SkCreateWGLContext(dc, msaaSampleCount, false);
bsalomon@google.com2858b312012-04-02 20:44:38 +0000331 if (NULL == fHGLRC) {
332 return false;
333 }
334 glClearStencil(0);
335 glClearColor(0, 0, 0, 0);
336 glStencilMask(0xffffffff);
337 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
338 }
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000339 if (wglMakeCurrent(dc, (HGLRC)fHGLRC)) {
bsalomon@google.com2858b312012-04-02 20:44:38 +0000340 glViewport(0, 0, SkScalarRound(this->width()),
341 SkScalarRound(this->height()));
342 return true;
343 }
344 return false;
345}
346
347void SkOSWindow::detachGL() {
348 wglMakeCurrent(GetDC((HWND)fHWND), 0);
349 wglDeleteContext((HGLRC)fHGLRC);
350 fHGLRC = NULL;
351}
352
353void SkOSWindow::presentGL() {
354 glFlush();
355 SwapBuffers(GetDC((HWND)fHWND));
356}
357
358#if SK_ANGLE
bsalomon@google.com11959252012-04-06 20:13:38 +0000359bool create_ANGLE(EGLNativeWindowType hWnd,
360 int msaaSampleCount,
361 EGLDisplay* eglDisplay,
362 EGLContext* eglContext,
363 EGLSurface* eglSurface) {
364 static const EGLint contextAttribs[] = {
365 EGL_CONTEXT_CLIENT_VERSION, 2,
rmistry@google.comd6176b02012-08-23 18:14:13 +0000366 EGL_NONE, EGL_NONE
bsalomon@google.com2858b312012-04-02 20:44:38 +0000367 };
bsalomon@google.com11959252012-04-06 20:13:38 +0000368 static const EGLint configAttribList[] = {
bsalomon@google.com2858b312012-04-02 20:44:38 +0000369 EGL_RED_SIZE, 8,
370 EGL_GREEN_SIZE, 8,
371 EGL_BLUE_SIZE, 8,
372 EGL_ALPHA_SIZE, 8,
373 EGL_DEPTH_SIZE, 8,
374 EGL_STENCIL_SIZE, 8,
375 EGL_NONE
376 };
bsalomon@google.com11959252012-04-06 20:13:38 +0000377 static const EGLint surfaceAttribList[] = {
bsalomon@google.com2858b312012-04-02 20:44:38 +0000378 EGL_NONE, EGL_NONE
379 };
380
381 EGLDisplay display = eglGetDisplay(GetDC(hWnd));
382 if (display == EGL_NO_DISPLAY ) {
383 return false;
384 }
385
386 // Initialize EGL
387 EGLint majorVersion, minorVersion;
388 if (!eglInitialize(display, &majorVersion, &minorVersion)) {
389 return false;
390 }
391
392 EGLint numConfigs;
393 if (!eglGetConfigs(display, NULL, 0, &numConfigs)) {
394 return false;
395 }
396
397 // Choose config
398 EGLConfig config;
bsalomon@google.com11959252012-04-06 20:13:38 +0000399 bool foundConfig = false;
400 if (msaaSampleCount) {
401 static const int kConfigAttribListCnt =
402 SK_ARRAY_COUNT(configAttribList);
403 EGLint msaaConfigAttribList[kConfigAttribListCnt + 4];
404 memcpy(msaaConfigAttribList,
405 configAttribList,
406 sizeof(configAttribList));
407 SkASSERT(EGL_NONE == msaaConfigAttribList[kConfigAttribListCnt - 1]);
408 msaaConfigAttribList[kConfigAttribListCnt - 1] = EGL_SAMPLE_BUFFERS;
409 msaaConfigAttribList[kConfigAttribListCnt + 0] = 1;
410 msaaConfigAttribList[kConfigAttribListCnt + 1] = EGL_SAMPLES;
411 msaaConfigAttribList[kConfigAttribListCnt + 2] = msaaSampleCount;
412 msaaConfigAttribList[kConfigAttribListCnt + 3] = EGL_NONE;
413 if (eglChooseConfig(display, configAttribList,
414 &config, 1, &numConfigs)) {
415 SkASSERT(numConfigs > 0);
416 foundConfig = true;
417 }
418 }
419 if (!foundConfig) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000420 if (!eglChooseConfig(display, configAttribList,
bsalomon@google.com11959252012-04-06 20:13:38 +0000421 &config, 1, &numConfigs)) {
422 return false;
423 }
bsalomon@google.com2858b312012-04-02 20:44:38 +0000424 }
425
426 // Create a surface
rmistry@google.comd6176b02012-08-23 18:14:13 +0000427 EGLSurface surface = eglCreateWindowSurface(display, config,
428 (EGLNativeWindowType)hWnd,
bsalomon@google.com2858b312012-04-02 20:44:38 +0000429 surfaceAttribList);
430 if (surface == EGL_NO_SURFACE) {
431 return false;
432 }
433
434 // Create a GL context
rmistry@google.comd6176b02012-08-23 18:14:13 +0000435 EGLContext context = eglCreateContext(display, config,
bsalomon@google.com2858b312012-04-02 20:44:38 +0000436 EGL_NO_CONTEXT,
437 contextAttribs );
438 if (context == EGL_NO_CONTEXT ) {
439 return false;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000440 }
441
bsalomon@google.com2858b312012-04-02 20:44:38 +0000442 // Make the context current
443 if (!eglMakeCurrent(display, surface, surface, context)) {
444 return false;
445 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000446
bsalomon@google.com2858b312012-04-02 20:44:38 +0000447 *eglDisplay = display;
448 *eglContext = context;
449 *eglSurface = surface;
450 return true;
451}
452
bsalomon@google.com11959252012-04-06 20:13:38 +0000453bool SkOSWindow::attachANGLE(int msaaSampleCount) {
bsalomon@google.com2858b312012-04-02 20:44:38 +0000454 if (EGL_NO_DISPLAY == fDisplay) {
bsalomon@google.com11959252012-04-06 20:13:38 +0000455 bool bResult = create_ANGLE((HWND)fHWND,
456 msaaSampleCount,
457 &fDisplay,
458 &fContext,
459 &fSurface);
bsalomon@google.com2858b312012-04-02 20:44:38 +0000460 if (false == bResult) {
461 return false;
462 }
bsalomon@google.com82502e22013-01-24 20:47:18 +0000463 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface());
bsalomon@google.com2858b312012-04-02 20:44:38 +0000464
465 if (intf) {
borenet@google.com0dd5ceb2012-08-28 15:15:49 +0000466 ANGLE_GL_CALL(intf, ClearStencil(0));
467 ANGLE_GL_CALL(intf, ClearColor(0, 0, 0, 0));
468 ANGLE_GL_CALL(intf, StencilMask(0xffffffff));
469 ANGLE_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT));
bsalomon@google.com2858b312012-04-02 20:44:38 +0000470 }
471 }
472 if (eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
bsalomon@google.com82502e22013-01-24 20:47:18 +0000473 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface());
bsalomon@google.com2858b312012-04-02 20:44:38 +0000474
475 if (intf ) {
borenet@google.com0dd5ceb2012-08-28 15:15:49 +0000476 ANGLE_GL_CALL(intf, Viewport(0, 0, SkScalarRound(this->width()),
bsalomon@google.com2858b312012-04-02 20:44:38 +0000477 SkScalarRound(this->height())));
478 }
479 return true;
480 }
481 return false;
482}
483
484void SkOSWindow::detachANGLE() {
485 eglMakeCurrent(fDisplay, EGL_NO_SURFACE , EGL_NO_SURFACE , EGL_NO_CONTEXT);
486
487 eglDestroyContext(fDisplay, fContext);
488 fContext = EGL_NO_CONTEXT;
489
490 eglDestroySurface(fDisplay, fSurface);
491 fSurface = EGL_NO_SURFACE;
492
493 eglTerminate(fDisplay);
494 fDisplay = EGL_NO_DISPLAY;
495}
496
497void SkOSWindow::presentANGLE() {
bsalomon@google.com82502e22013-01-24 20:47:18 +0000498 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface());
bsalomon@google.com2858b312012-04-02 20:44:38 +0000499
500 if (intf) {
borenet@google.com0dd5ceb2012-08-28 15:15:49 +0000501 ANGLE_GL_CALL(intf, Flush());
bsalomon@google.com2858b312012-04-02 20:44:38 +0000502 }
503
504 eglSwapBuffers(fDisplay, fSurface);
505}
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000506#endif // SK_ANGLE
507#endif // SK_SUPPORT_GPU
bsalomon@google.com2858b312012-04-02 20:44:38 +0000508
bsalomon@google.com2858b312012-04-02 20:44:38 +0000509// return true on success
bsalomon@google.com11959252012-04-06 20:13:38 +0000510bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount) {
bsalomon@google.com2858b312012-04-02 20:44:38 +0000511
512 // attach doubles as "windowResize" so we need to allo
513 // already bound states to pass through again
514 // TODO: split out the resize functionality
515// SkASSERT(kNone_BackEndType == fAttached);
516 bool result = true;
517
518 switch (attachType) {
519 case kNone_BackEndType:
520 // nothing to do
rmistry@google.comd6176b02012-08-23 18:14:13 +0000521 break;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000522#if SK_SUPPORT_GPU
bsalomon@google.com2858b312012-04-02 20:44:38 +0000523 case kNativeGL_BackEndType:
bsalomon@google.com11959252012-04-06 20:13:38 +0000524 result = attachGL(msaaSampleCount);
bsalomon@google.com2858b312012-04-02 20:44:38 +0000525 break;
526#if SK_ANGLE
527 case kANGLE_BackEndType:
bsalomon@google.com11959252012-04-06 20:13:38 +0000528 result = attachANGLE(msaaSampleCount);
bsalomon@google.com2858b312012-04-02 20:44:38 +0000529 break;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000530#endif // SK_ANGLE
531#endif // SK_SUPPORT_GPU
bsalomon@google.com2858b312012-04-02 20:44:38 +0000532 default:
533 SkASSERT(false);
534 result = false;
535 break;
536 }
537
538 if (result) {
539 fAttached = attachType;
540 }
541
542 return result;
543}
544
545void SkOSWindow::detach() {
546 switch (fAttached) {
547 case kNone_BackEndType:
548 // nothing to do
rmistry@google.comd6176b02012-08-23 18:14:13 +0000549 break;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000550#if SK_SUPPORT_GPU
bsalomon@google.com2858b312012-04-02 20:44:38 +0000551 case kNativeGL_BackEndType:
552 detachGL();
553 break;
554#if SK_ANGLE
555 case kANGLE_BackEndType:
556 detachANGLE();
557 break;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000558#endif // SK_ANGLE
559#endif // SK_SUPPORT_GPU
bsalomon@google.com2858b312012-04-02 20:44:38 +0000560 default:
561 SkASSERT(false);
562 break;
563 }
564 fAttached = kNone_BackEndType;
565}
566
567void SkOSWindow::present() {
568 switch (fAttached) {
569 case kNone_BackEndType:
570 // nothing to do
rmistry@google.comd6176b02012-08-23 18:14:13 +0000571 return;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000572#if SK_SUPPORT_GPU
bsalomon@google.com2858b312012-04-02 20:44:38 +0000573 case kNativeGL_BackEndType:
574 presentGL();
575 break;
576#if SK_ANGLE
577 case kANGLE_BackEndType:
578 presentANGLE();
579 break;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000580#endif // SK_ANGLE
581#endif // SK_SUPPORT_GPU
bsalomon@google.com2858b312012-04-02 20:44:38 +0000582 default:
583 SkASSERT(false);
584 break;
585 }
586}
587
588#endif