| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 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 "GLWindowContext_win.h" | 9 #include "WindowContextFactory_win.h" |
| 10 | |
| 11 #include <GL/gl.h> | 10 #include <GL/gl.h> |
| 12 | 11 |
| 13 // windows stuff | 12 // windows stuff |
| 14 #include "win/SkWGL.h" | 13 #include "win/SkWGL.h" |
| 15 #include "Window_win.h" | |
| 16 | 14 |
| 17 namespace sk_app { | 15 #include "../GLWindowContext.h" |
| 18 | 16 |
| 19 // platform-dependent create | 17 using sk_app::GLWindowContext; |
| 20 GLWindowContext* GLWindowContext::Create(void* platformData, const DisplayParams
& params) { | 18 using sk_app::DisplayParams; |
| 21 GLWindowContext_win* ctx = new GLWindowContext_win(platformData, params); | |
| 22 if (!ctx->isValid()) { | |
| 23 delete ctx; | |
| 24 return nullptr; | |
| 25 } | |
| 26 return ctx; | |
| 27 } | |
| 28 | 19 |
| 29 GLWindowContext_win::GLWindowContext_win(void* platformData, const DisplayParams
& params) | 20 namespace { |
| 30 : GLWindowContext(platformData, params) | 21 |
| 31 , fHWND(0) | 22 class GLWindowContext_win : public GLWindowContext { |
| 23 public: |
| 24 GLWindowContext_win(HWND, const DisplayParams&); |
| 25 ~GLWindowContext_win() override; |
| 26 |
| 27 protected: |
| 28 void onSwapBuffers() override; |
| 29 |
| 30 void onInitializeContext() override; |
| 31 void onDestroyContext() override; |
| 32 |
| 33 private: |
| 34 HWND fHWND; |
| 35 HGLRC fHGLRC; |
| 36 }; |
| 37 |
| 38 GLWindowContext_win::GLWindowContext_win(HWND wnd, const DisplayParams& params) |
| 39 : GLWindowContext(params) |
| 40 , fHWND(wnd) |
| 32 , fHGLRC(NULL) { | 41 , fHGLRC(NULL) { |
| 33 | 42 |
| 34 // any config code here (particularly for msaa)? | 43 // any config code here (particularly for msaa)? |
| 35 | 44 |
| 36 this->initializeContext(platformData, params); | 45 this->initializeContext(); |
| 37 } | 46 } |
| 38 | 47 |
| 39 GLWindowContext_win::~GLWindowContext_win() { | 48 GLWindowContext_win::~GLWindowContext_win() { |
| 40 this->destroyContext(); | 49 this->destroyContext(); |
| 41 } | 50 } |
| 42 | 51 |
| 43 void GLWindowContext_win::onInitializeContext(void* platformData, const DisplayP
arams& params) { | 52 void GLWindowContext_win::onInitializeContext() { |
| 44 | |
| 45 ContextPlatformData_win* winPlatformData = | |
| 46 reinterpret_cast<ContextPlatformData_win*>(platformData); | |
| 47 | |
| 48 if (winPlatformData) { | |
| 49 fHWND = winPlatformData->fHWnd; | |
| 50 } | |
| 51 HDC dc = GetDC(fHWND); | 53 HDC dc = GetDC(fHWND); |
| 52 | 54 |
| 53 fHGLRC = SkCreateWGLContext(dc, params.fMSAASampleCount, params.fDeepColor, | 55 fHGLRC = SkCreateWGLContext(dc, fDisplayParams.fMSAASampleCount, fDisplayPar
ams.fDeepColor, |
| 54 kGLPreferCompatibilityProfile_SkWGLContextReques
t); | 56 kGLPreferCompatibilityProfile_SkWGLContextReques
t); |
| 55 if (NULL == fHGLRC) { | 57 if (NULL == fHGLRC) { |
| 56 return; | 58 return; |
| 57 } | 59 } |
| 58 | 60 |
| 59 if (wglMakeCurrent(dc, fHGLRC)) { | 61 if (wglMakeCurrent(dc, fHGLRC)) { |
| 60 glClearStencil(0); | 62 glClearStencil(0); |
| 61 glClearColor(0, 0, 0, 0); | 63 glClearColor(0, 0, 0, 0); |
| 62 glStencilMask(0xffffffff); | 64 glStencilMask(0xffffffff); |
| 63 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); | 65 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 102 } |
| 101 | 103 |
| 102 | 104 |
| 103 void GLWindowContext_win::onSwapBuffers() { | 105 void GLWindowContext_win::onSwapBuffers() { |
| 104 HDC dc = GetDC((HWND)fHWND); | 106 HDC dc = GetDC((HWND)fHWND); |
| 105 SwapBuffers(dc); | 107 SwapBuffers(dc); |
| 106 ReleaseDC((HWND)fHWND, dc); | 108 ReleaseDC((HWND)fHWND, dc); |
| 107 } | 109 } |
| 108 | 110 |
| 109 | 111 |
| 110 } //namespace sk_app | 112 } // anonymous namespace |
| 113 |
| 114 namespace sk_app { |
| 115 namespace window_context_factory { |
| 116 |
| 117 WindowContext* NewGLForWin(HWND wnd, const DisplayParams& params) { |
| 118 GLWindowContext_win* ctx = new GLWindowContext_win(wnd, params); |
| 119 if (!ctx->isValid()) { |
| 120 delete ctx; |
| 121 return nullptr; |
| 122 } |
| 123 return ctx; |
| 124 } |
| 125 |
| 126 } // namespace window_context_factory |
| 127 } // namespace sk_app |
| OLD | NEW |