OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2016 Google Inc. | 3 * Copyright 2016 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_mac.h" | 9 #include "../GLWindowContext.h" |
| 10 #include "WindowContextFactory_mac.h" |
10 | 11 |
11 //#include <GL/gl.h> | 12 //#include <GL/gl.h> |
12 | 13 |
13 #include "Window_mac.h" | 14 using sk_app::DisplayParams; |
| 15 using sk_app::window_context_factory::MacWindowInfo; |
| 16 using sk_app::GLWindowContext; |
14 | 17 |
15 namespace sk_app { | 18 namespace { |
16 | 19 |
17 // platform-dependent create | 20 class GLWindowContext_mac : public GLWindowContext { |
18 GLWindowContext* GLWindowContext::Create(void* platformData, const DisplayParams
& params) { | 21 public: |
19 GLWindowContext_mac* ctx = new GLWindowContext_mac(platformData, params); | 22 GLWindowContext_mac(const MacWindowInfo&, const DisplayParams&); |
20 if (!ctx->isValid()) { | 23 |
21 delete ctx; | 24 ~GLWindowContext_mac() override; |
22 return nullptr; | 25 |
23 } | 26 void onSwapBuffers() override; |
24 return ctx; | 27 |
25 } | 28 void onInitializeContext() override; |
| 29 void onDestroyContext() override; |
| 30 |
| 31 private: |
| 32 |
| 33 #if 0 |
| 34 // TODO: add Mac-specific GL display objects |
| 35 Display* fDisplay; |
| 36 XWindow fWindow; |
| 37 XVisualInfo* fVisualInfo; |
| 38 GLXContext fGLContext; |
| 39 #endif |
| 40 }; |
26 | 41 |
27 GLWindowContext_mac::GLWindowContext_mac(void* platformData, const DisplayParams
& params) | 42 GLWindowContext_mac::GLWindowContext_mac(const MacWindowInfo& info, const Displa
yParams& params) |
28 : GLWindowContext(platformData, params) | 43 : GLWindowContext(params) |
29 #if 0 | 44 #if 0 |
30 // TODO: init Mac-specific OpenGL objects | 45 // TODO: init Mac-specific OpenGL objects |
31 , fDisplay(nullptr) | 46 , fDisplay(nullptr) |
32 , fWindow(0) | 47 , fWindow(0) |
33 , fGLContext(0) | 48 , fGLContext(0) |
34 #endif | 49 #endif |
35 { | 50 { |
36 | 51 |
37 // any config code here (particularly for msaa)? | 52 // any config code here (particularly for msaa)? |
38 | 53 |
39 this->initializeContext(platformData, params); | 54 this->initializeContext(); |
40 } | 55 } |
41 | 56 |
42 GLWindowContext_mac::~GLWindowContext_mac() { | 57 GLWindowContext_mac::~GLWindowContext_mac() { |
43 this->destroyContext(); | 58 this->destroyContext(); |
44 } | 59 } |
45 | 60 |
46 void GLWindowContext_mac::onInitializeContext(void* platformData, const DisplayP
arams& params) { | 61 void GLWindowContext_mac::onInitializeContext() { |
47 #if 0 | 62 #if 0 |
48 // TODO: Init for Mac | 63 // TODO: Init for Mac |
49 ContextPlatformData_mac* unixPlatformData = | |
50 reinterpret_cast<ContextPlatformData_mac*>(platformData); | |
51 | |
52 if (unixPlatformData) { | |
53 fDisplay = unixPlatformData->fDisplay; | |
54 fWindow = unixPlatformData->fWindow; | |
55 fVisualInfo = unixPlatformData->fVisualInfo; | |
56 } | |
57 SkASSERT(fDisplay); | 64 SkASSERT(fDisplay); |
58 | 65 |
59 fGLContext = glXCreateContext(fDisplay, fVisualInfo, nullptr, GL_TRUE); | 66 fGLContext = glXCreateContext(fDisplay, fVisualInfo, nullptr, GL_TRUE); |
60 if (!fGLContext) { | 67 if (!fGLContext) { |
61 return; | 68 return; |
62 } | 69 } |
63 | 70 |
64 if (glXMakeCurrent(fDisplay, fWindow, fGLContext)) { | 71 if (glXMakeCurrent(fDisplay, fWindow, fGLContext)) { |
65 glClearStencil(0); | 72 glClearStencil(0); |
66 glClearColor(0, 0, 0, 0); | 73 glClearColor(0, 0, 0, 0); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 107 |
101 void GLWindowContext_mac::onSwapBuffers() { | 108 void GLWindowContext_mac::onSwapBuffers() { |
102 #if 0 | 109 #if 0 |
103 // TODO: swap for Mac | 110 // TODO: swap for Mac |
104 if (fDisplay && fGLContext) { | 111 if (fDisplay && fGLContext) { |
105 glXSwapBuffers(fDisplay, fWindow); | 112 glXSwapBuffers(fDisplay, fWindow); |
106 } | 113 } |
107 #endif | 114 #endif |
108 } | 115 } |
109 | 116 |
| 117 } // anonymous namespace |
110 | 118 |
111 } //namespace sk_app | 119 |
| 120 namespace sk_app { |
| 121 namespace window_context_factory { |
| 122 |
| 123 WindowContext* MakeGLForMac(const MacWindowInfo& info, const DisplayParams& para
ms) { |
| 124 WindowContext* ctx = new GLWindowContext_mac(info, params); |
| 125 if (!ctx->isValid()) { |
| 126 delete ctx; |
| 127 return nullptr; |
| 128 } |
| 129 return ctx; |
| 130 } |
| 131 |
| 132 } // namespace window_context_factory |
| 133 } // namespace sk_app |
OLD | NEW |