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

Side by Side Diff: src/gpu/gl/win/SkCreatePlatformGLContext_win.cpp

Issue 1194783003: Implement SkGLContext swapBuffers with fence syncs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: windows build 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/gpu/gl/mesa/SkMesaGLContext.cpp ('k') | no next file » | 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 8
9 #include "gl/SkGLContext.h" 9 #include "gl/SkGLContext.h"
10 10
11 #include <windows.h> 11 #include <windows.h>
12 #include <GL/GL.h> 12 #include <GL/GL.h>
13 #include "win/SkWGL.h" 13 #include "win/SkWGL.h"
14 14
15 #define WIN32_LEAN_AND_MEAN 15 #define WIN32_LEAN_AND_MEAN
16 #include <windows.h> 16 #include <windows.h>
17 17
18 namespace { 18 namespace {
19 19
20 class WinGLContext : public SkGLContext { 20 class WinGLContext : public SkGLContext {
21 public: 21 public:
22 WinGLContext(GrGLStandard forcedGpuAPI); 22 WinGLContext(GrGLStandard forcedGpuAPI);
23 ~WinGLContext() override; 23 ~WinGLContext() override;
24 void makeCurrent() const override;
25 void swapBuffers() const override;
26 24
27 private: 25 private:
28 void destroyGLContext(); 26 void destroyGLContext();
29 27
28 void onPlatformMakeCurrent() const override;
29 void onPlatformSwapBuffers() const override;
30 GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override;
31
30 HWND fWindow; 32 HWND fWindow;
31 HDC fDeviceContext; 33 HDC fDeviceContext;
32 HGLRC fGlRenderContext; 34 HGLRC fGlRenderContext;
33 static ATOM gWC; 35 static ATOM gWC;
34 SkWGLPbufferContext* fPbufferContext; 36 SkWGLPbufferContext* fPbufferContext;
35 }; 37 };
36 38
37 ATOM WinGLContext::gWC = 0; 39 ATOM WinGLContext::gWC = 0;
38 40
39 WinGLContext::WinGLContext(GrGLStandard forcedGpuAPI) 41 WinGLContext::WinGLContext(GrGLStandard forcedGpuAPI)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 dc = fPbufferContext->getDC(); 108 dc = fPbufferContext->getDC();
107 glrc = fPbufferContext->getGLRC(); 109 glrc = fPbufferContext->getGLRC();
108 } 110 }
109 111
110 if (!(wglMakeCurrent(dc, glrc))) { 112 if (!(wglMakeCurrent(dc, glrc))) {
111 SkDebugf("Could not set the context.\n"); 113 SkDebugf("Could not set the context.\n");
112 this->destroyGLContext(); 114 this->destroyGLContext();
113 return; 115 return;
114 } 116 }
115 117
116 fGL.reset(GrGLCreateNativeInterface()); 118 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateNativeInterface());
117 if (NULL == fGL.get()) { 119 if (NULL == gl.get()) {
118 SkDebugf("Could not create GL interface.\n"); 120 SkDebugf("Could not create GL interface.\n");
119 this->destroyGLContext(); 121 this->destroyGLContext();
120 return; 122 return;
121 } 123 }
122 if (!fGL->validate()) { 124 if (!gl->validate()) {
123 SkDebugf("Could not validate GL interface.\n"); 125 SkDebugf("Could not validate GL interface.\n");
124 this->destroyGLContext(); 126 this->destroyGLContext();
125 return; 127 return;
126 } 128 }
129
130 this->init(gl.detach());
127 } 131 }
128 132
129 WinGLContext::~WinGLContext() { 133 WinGLContext::~WinGLContext() {
134 this->teardown();
130 this->destroyGLContext(); 135 this->destroyGLContext();
131 } 136 }
132 137
133 void WinGLContext::destroyGLContext() { 138 void WinGLContext::destroyGLContext() {
134 fGL.reset(NULL);
135 SkSafeSetNull(fPbufferContext); 139 SkSafeSetNull(fPbufferContext);
136 if (fGlRenderContext) { 140 if (fGlRenderContext) {
137 wglDeleteContext(fGlRenderContext); 141 wglDeleteContext(fGlRenderContext);
138 fGlRenderContext = 0; 142 fGlRenderContext = 0;
139 } 143 }
140 if (fWindow && fDeviceContext) { 144 if (fWindow && fDeviceContext) {
141 ReleaseDC(fWindow, fDeviceContext); 145 ReleaseDC(fWindow, fDeviceContext);
142 fDeviceContext = 0; 146 fDeviceContext = 0;
143 } 147 }
144 if (fWindow) { 148 if (fWindow) {
145 DestroyWindow(fWindow); 149 DestroyWindow(fWindow);
146 fWindow = 0; 150 fWindow = 0;
147 } 151 }
148 } 152 }
149 153
150 void WinGLContext::makeCurrent() const { 154 void WinGLContext::onPlatformMakeCurrent() const {
151 HDC dc; 155 HDC dc;
152 HGLRC glrc; 156 HGLRC glrc;
153 157
154 if (NULL == fPbufferContext) { 158 if (NULL == fPbufferContext) {
155 dc = fDeviceContext; 159 dc = fDeviceContext;
156 glrc = fGlRenderContext; 160 glrc = fGlRenderContext;
157 } else { 161 } else {
158 dc = fPbufferContext->getDC(); 162 dc = fPbufferContext->getDC();
159 glrc = fPbufferContext->getGLRC(); 163 glrc = fPbufferContext->getGLRC();
160 } 164 }
161 165
162 if (!wglMakeCurrent(dc, glrc)) { 166 if (!wglMakeCurrent(dc, glrc)) {
163 SkDebugf("Could not create rendering context.\n"); 167 SkDebugf("Could not create rendering context.\n");
164 } 168 }
165 } 169 }
166 170
167 void WinGLContext::swapBuffers() const { 171 void WinGLContext::onPlatformSwapBuffers() const {
168 HDC dc; 172 HDC dc;
169 173
170 if (NULL == fPbufferContext) { 174 if (NULL == fPbufferContext) {
171 dc = fDeviceContext; 175 dc = fDeviceContext;
172 } else { 176 } else {
173 dc = fPbufferContext->getDC(); 177 dc = fPbufferContext->getDC();
174 } 178 }
175 if (!SwapBuffers(dc)) { 179 if (!SwapBuffers(dc)) {
176 SkDebugf("Could not complete SwapBuffers.\n"); 180 SkDebugf("Could not complete SwapBuffers.\n");
177 } 181 }
178 } 182 }
179 183
184 GrGLFuncPtr WinGLContext::onPlatformGetProcAddress(const char* name) const {
185 return reinterpret_cast<GrGLFuncPtr>(wglGetProcAddress(name));
186 }
187
180 } // anonymous namespace 188 } // anonymous namespace
181 189
182 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { 190 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) {
183 WinGLContext* ctx = SkNEW_ARGS(WinGLContext, (forcedGpuAPI)); 191 WinGLContext* ctx = SkNEW_ARGS(WinGLContext, (forcedGpuAPI));
184 if (!ctx->isValid()) { 192 if (!ctx->isValid()) {
185 SkDELETE(ctx); 193 SkDELETE(ctx);
186 return NULL; 194 return NULL;
187 } 195 }
188 return ctx; 196 return ctx;
189 } 197 }
190 198
OLDNEW
« no previous file with comments | « src/gpu/gl/mesa/SkMesaGLContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698