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