OLD | NEW |
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 | 8 |
9 #include "gl/SkNativeGLContext.h" | 9 #include "gl/SkNativeGLContext.h" |
| 10 #include "SkWGL.h" |
10 | 11 |
11 #define WIN32_LEAN_AND_MEAN | 12 #define WIN32_LEAN_AND_MEAN |
12 #include <Windows.h> | 13 #include <Windows.h> |
13 | 14 |
14 SkNativeGLContext::AutoContextRestore::AutoContextRestore() { | 15 SkNativeGLContext::AutoContextRestore::AutoContextRestore() { |
15 fOldHGLRC = wglGetCurrentContext(); | 16 fOldHGLRC = wglGetCurrentContext(); |
16 fOldHDC = wglGetCurrentDC(); | 17 fOldHDC = wglGetCurrentDC(); |
17 } | 18 } |
18 | 19 |
19 SkNativeGLContext::AutoContextRestore::~AutoContextRestore() { | 20 SkNativeGLContext::AutoContextRestore::~AutoContextRestore() { |
(...skipping 22 matching lines...) Expand all Loading... |
42 ReleaseDC(fWindow, fDeviceContext); | 43 ReleaseDC(fWindow, fDeviceContext); |
43 } | 44 } |
44 if (fWindow) { | 45 if (fWindow) { |
45 DestroyWindow(fWindow); | 46 DestroyWindow(fWindow); |
46 } | 47 } |
47 } | 48 } |
48 | 49 |
49 const GrGLInterface* SkNativeGLContext::createGLContext() { | 50 const GrGLInterface* SkNativeGLContext::createGLContext() { |
50 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL); | 51 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL); |
51 | 52 |
52 if (!gWC) { | |
53 WNDCLASS wc; | |
54 wc.cbClsExtra = 0; | |
55 wc.cbWndExtra = 0; | |
56 wc.hbrBackground = NULL; | |
57 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
58 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); | |
59 wc.hInstance = hInstance; | |
60 wc.lpfnWndProc = (WNDPROC) DefWindowProc; | |
61 wc.lpszClassName = TEXT("Griffin"); | |
62 wc.lpszMenuName = NULL; | |
63 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; | |
64 | |
65 gWC = RegisterClass(&wc); | |
66 if (!gWC) { | |
67 SkDebugf("Could not register window class.\n"); | |
68 return NULL; | |
69 } | |
70 } | |
71 | |
72 if (!(fWindow = CreateWindow(TEXT("Griffin"), | |
73 TEXT("The Invisible Man"), | |
74 WS_OVERLAPPEDWINDOW, | |
75 0, 0, 1, 1, | |
76 NULL, NULL, | |
77 hInstance, NULL))) { | |
78 SkDebugf("Could not create window.\n"); | |
79 return NULL; | |
80 } | |
81 | 53 |
82 if (!(fDeviceContext = GetDC(fWindow))) { | 54 if (!(fDeviceContext = GetDC(fWindow))) { |
83 SkDebugf("Could not get device context.\n"); | 55 SkDebugf("Could not get device context.\n"); |
84 this->destroyGLContext(); | 56 this->destroyGLContext(); |
85 return NULL; | 57 return NULL; |
86 } | 58 } |
87 | 59 |
88 PIXELFORMATDESCRIPTOR pfd; | 60 if (!(fGlRenderContext = SkCreateWGLContext(fDeviceContext, 0, true))) { |
89 ZeroMemory(&pfd, sizeof(pfd)); | |
90 pfd.nSize = sizeof(pfd); | |
91 pfd.nVersion = 1; | |
92 pfd.dwFlags = PFD_SUPPORT_OPENGL; | |
93 pfd.iPixelType = PFD_TYPE_RGBA; | |
94 pfd.cColorBits = 32; | |
95 pfd.cDepthBits = 0; | |
96 pfd.cStencilBits = 0; | |
97 pfd.iLayerType = PFD_MAIN_PLANE; | |
98 | |
99 int pixelFormat = 0; | |
100 if (!(pixelFormat = ChoosePixelFormat(fDeviceContext, &pfd))) { | |
101 SkDebugf("No matching pixel format descriptor.\n"); | |
102 this->destroyGLContext(); | |
103 return NULL; | |
104 } | |
105 | |
106 if (!SetPixelFormat(fDeviceContext, pixelFormat, &pfd)) { | |
107 SkDebugf("Could not set the pixel format %d.\n", pixelFormat); | |
108 this->destroyGLContext(); | |
109 return NULL; | |
110 } | |
111 | |
112 if (!(fGlRenderContext = wglCreateContext(fDeviceContext))) { | |
113 SkDebugf("Could not create rendering context.\n"); | 61 SkDebugf("Could not create rendering context.\n"); |
114 this->destroyGLContext(); | 62 this->destroyGLContext(); |
115 return NULL; | 63 return NULL; |
116 } | 64 } |
117 | 65 |
118 if (!(wglMakeCurrent(fDeviceContext, fGlRenderContext))) { | 66 if (!(wglMakeCurrent(fDeviceContext, fGlRenderContext))) { |
119 SkDebugf("Could not set the context.\n"); | 67 SkDebugf("Could not set the context.\n"); |
120 this->destroyGLContext(); | 68 this->destroyGLContext(); |
121 return NULL; | 69 return NULL; |
122 } | 70 } |
123 const GrGLInterface* interface = GrGLCreateNativeInterface(); | 71 const GrGLInterface* interface = GrGLCreateNativeInterface(); |
124 if (NULL == interface) { | 72 if (NULL == interface) { |
125 SkDebugf("Could not create GL interface.\n"); | 73 SkDebugf("Could not create GL interface.\n"); |
126 this->destroyGLContext(); | 74 this->destroyGLContext(); |
127 return NULL; | 75 return NULL; |
128 } | 76 } |
129 | 77 |
130 return interface; | 78 return interface; |
131 } | 79 } |
132 | 80 |
133 void SkNativeGLContext::makeCurrent() const { | 81 void SkNativeGLContext::makeCurrent() const { |
134 if (!wglMakeCurrent(fDeviceContext, fGlRenderContext)) { | 82 if (!wglMakeCurrent(fDeviceContext, fGlRenderContext)) { |
135 SkDebugf("Could not create rendering context.\n"); | 83 SkDebugf("Could not create rendering context.\n"); |
136 } | 84 } |
137 } | 85 } |
OLD | NEW |