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.h" | 9 #include "../GLWindowContext.h" |
10 #include "WindowContextFactory_mac.h" | 10 #include "WindowContextFactory_mac.h" |
11 | 11 |
12 //#include <GL/gl.h> | 12 #include "SDL.h" |
| 13 |
| 14 #include <OpenGL/gl.h> |
13 | 15 |
14 using sk_app::DisplayParams; | 16 using sk_app::DisplayParams; |
15 using sk_app::window_context_factory::MacWindowInfo; | 17 using sk_app::window_context_factory::MacWindowInfo; |
16 using sk_app::GLWindowContext; | 18 using sk_app::GLWindowContext; |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 class GLWindowContext_mac : public GLWindowContext { | 22 class GLWindowContext_mac : public GLWindowContext { |
21 public: | 23 public: |
22 GLWindowContext_mac(const MacWindowInfo&, const DisplayParams&); | 24 GLWindowContext_mac(const MacWindowInfo&, const DisplayParams&); |
23 | 25 |
24 ~GLWindowContext_mac() override; | 26 ~GLWindowContext_mac() override; |
25 | 27 |
26 void onSwapBuffers() override; | 28 void onSwapBuffers() override; |
27 | 29 |
28 void onInitializeContext() override; | 30 void onInitializeContext() override; |
29 void onDestroyContext() override; | 31 void onDestroyContext() override; |
30 | 32 |
31 private: | 33 private: |
32 | 34 SDL_Window* fWindow; |
33 #if 0 | 35 SDL_GLContext fGLContext; |
34 // TODO: add Mac-specific GL display objects | 36 |
35 Display* fDisplay; | 37 typedef GLWindowContext INHERITED; |
36 XWindow fWindow; | |
37 XVisualInfo* fVisualInfo; | |
38 GLXContext fGLContext; | |
39 #endif | |
40 }; | 38 }; |
41 | 39 |
42 GLWindowContext_mac::GLWindowContext_mac(const MacWindowInfo& info, const Displa
yParams& params) | 40 GLWindowContext_mac::GLWindowContext_mac(const MacWindowInfo& info, const Displa
yParams& params) |
43 : GLWindowContext(params) | 41 : INHERITED(params) |
44 #if 0 | 42 , fWindow(info.fWindow) |
45 // TODO: init Mac-specific OpenGL objects | 43 , fGLContext(nullptr) { |
46 , fDisplay(nullptr) | |
47 , fWindow(0) | |
48 , fGLContext(0) | |
49 #endif | |
50 { | |
51 | 44 |
52 // any config code here (particularly for msaa)? | 45 // any config code here (particularly for msaa)? |
53 | 46 |
54 this->initializeContext(); | 47 this->initializeContext(); |
55 } | 48 } |
56 | 49 |
57 GLWindowContext_mac::~GLWindowContext_mac() { | 50 GLWindowContext_mac::~GLWindowContext_mac() { |
58 this->destroyContext(); | 51 this->destroyContext(); |
59 } | 52 } |
60 | 53 |
61 void GLWindowContext_mac::onInitializeContext() { | 54 void GLWindowContext_mac::onInitializeContext() { |
62 #if 0 | 55 SkASSERT(fWindow); |
63 // TODO: Init for Mac | |
64 SkASSERT(fDisplay); | |
65 | 56 |
66 fGLContext = glXCreateContext(fDisplay, fVisualInfo, nullptr, GL_TRUE); | 57 fGLContext = SDL_GL_CreateContext(fWindow); |
67 if (!fGLContext) { | 58 if (!fGLContext) { |
| 59 SkDebugf("%s\n", SDL_GetError()); |
68 return; | 60 return; |
69 } | 61 } |
70 | 62 |
71 if (glXMakeCurrent(fDisplay, fWindow, fGLContext)) { | 63 if (0 == SDL_GL_MakeCurrent(fWindow, fGLContext)) { |
72 glClearStencil(0); | 64 glClearStencil(0); |
73 glClearColor(0, 0, 0, 0); | 65 glClearColor(0, 0, 0, 0); |
74 glStencilMask(0xffffffff); | 66 glStencilMask(0xffffffff); |
75 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); | 67 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); |
76 | 68 |
77 int redBits, greenBits, blueBits; | 69 int redBits, greenBits, blueBits; |
78 glXGetConfig(fDisplay, fVisualInfo, GLX_RED_SIZE, &redBits); | 70 SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &redBits); |
79 glXGetConfig(fDisplay, fVisualInfo, GLX_GREEN_SIZE, &greenBits); | 71 SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &greenBits); |
80 glXGetConfig(fDisplay, fVisualInfo, GLX_BLUE_SIZE, &blueBits); | 72 SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &blueBits); |
81 fColorBits = redBits + greenBits + blueBits; | 73 fColorBits = redBits + greenBits + blueBits; |
82 glXGetConfig(fDisplay, fVisualInfo, GLX_STENCIL_SIZE, &fStencilBits); | |
83 glXGetConfig(fDisplay, fVisualInfo, GLX_SAMPLES_ARB, &fSampleCount); | |
84 | 74 |
85 XWindow root; | 75 SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &fStencilBits); |
86 int x, y; | 76 SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &fSampleCount); |
87 unsigned int border_width, depth; | 77 |
88 XGetGeometry(fDisplay, fWindow, &root, &x, &y, | 78 SDL_GetWindowSize(fWindow, &fWidth, &fHeight); |
89 (unsigned int*)&fWidth, (unsigned int*)&fHeight, &border_wi
dth, &depth); | |
90 glViewport(0, 0, fWidth, fHeight); | 79 glViewport(0, 0, fWidth, fHeight); |
| 80 } else { |
| 81 SkDebugf("MakeCurrent failed: %s\n", SDL_GetError()); |
91 } | 82 } |
92 #endif | |
93 } | 83 } |
94 | 84 |
95 void GLWindowContext_mac::onDestroyContext() { | 85 void GLWindowContext_mac::onDestroyContext() { |
96 #if 0 | 86 if (!fWindow || !fGLContext) { |
97 // TODO: teardown for Mac | |
98 if (!fDisplay || !fGLContext) { | |
99 return; | 87 return; |
100 } | 88 } |
101 glXMakeCurrent(fDisplay, None, nullptr); | 89 SDL_GL_DeleteContext(fGLContext); |
102 glXDestroyContext(fDisplay, fGLContext); | |
103 fGLContext = nullptr; | 90 fGLContext = nullptr; |
104 #endif | |
105 } | 91 } |
106 | 92 |
107 | 93 |
108 void GLWindowContext_mac::onSwapBuffers() { | 94 void GLWindowContext_mac::onSwapBuffers() { |
109 #if 0 | 95 if (fWindow && fGLContext) { |
110 // TODO: swap for Mac | 96 SDL_GL_SwapWindow(fWindow); |
111 if (fDisplay && fGLContext) { | |
112 glXSwapBuffers(fDisplay, fWindow); | |
113 } | 97 } |
114 #endif | |
115 } | 98 } |
116 | 99 |
117 } // anonymous namespace | 100 } // anonymous namespace |
118 | 101 |
119 | |
120 namespace sk_app { | 102 namespace sk_app { |
121 namespace window_context_factory { | 103 namespace window_context_factory { |
122 | 104 |
123 WindowContext* MakeGLForMac(const MacWindowInfo& info, const DisplayParams& para
ms) { | 105 WindowContext* NewGLForMac(const MacWindowInfo& info, const DisplayParams& param
s) { |
124 WindowContext* ctx = new GLWindowContext_mac(info, params); | 106 WindowContext* ctx = new GLWindowContext_mac(info, params); |
125 if (!ctx->isValid()) { | 107 if (!ctx->isValid()) { |
126 delete ctx; | 108 delete ctx; |
127 return nullptr; | 109 return nullptr; |
128 } | 110 } |
129 return ctx; | 111 return ctx; |
130 } | 112 } |
131 | 113 |
132 } // namespace window_context_factory | 114 } // namespace window_context_factory |
133 } // namespace sk_app | 115 } // namespace sk_app |
OLD | NEW |