Index: tools/viewer/sk_app/mac/GLWindowContext_mac.cpp |
diff --git a/tools/viewer/sk_app/mac/GLWindowContext_mac.cpp b/tools/viewer/sk_app/mac/GLWindowContext_mac.cpp |
index c2de0df621b61da53d958e1efebb5d1cda5a1317..bc86df30d0396bfb5fc104063787ce6251688fda 100644 |
--- a/tools/viewer/sk_app/mac/GLWindowContext_mac.cpp |
+++ b/tools/viewer/sk_app/mac/GLWindowContext_mac.cpp |
@@ -9,7 +9,9 @@ |
#include "../GLWindowContext.h" |
#include "WindowContextFactory_mac.h" |
-//#include <GL/gl.h> |
+#include "SDL.h" |
+ |
+#include <OpenGL/gl.h> |
using sk_app::DisplayParams; |
using sk_app::window_context_factory::MacWindowInfo; |
@@ -29,25 +31,16 @@ public: |
void onDestroyContext() override; |
private: |
- |
-#if 0 |
- // TODO: add Mac-specific GL display objects |
- Display* fDisplay; |
- XWindow fWindow; |
- XVisualInfo* fVisualInfo; |
- GLXContext fGLContext; |
-#endif |
+ SDL_Window* fWindow; |
+ SDL_GLContext fGLContext; |
+ |
+ typedef GLWindowContext INHERITED; |
}; |
GLWindowContext_mac::GLWindowContext_mac(const MacWindowInfo& info, const DisplayParams& params) |
- : GLWindowContext(params) |
-#if 0 |
- // TODO: init Mac-specific OpenGL objects |
- , fDisplay(nullptr) |
- , fWindow(0) |
- , fGLContext(0) |
-#endif |
- { |
+ : INHERITED(params) |
+ , fWindow(info.fWindow) |
+ , fGLContext(nullptr) { |
// any config code here (particularly for msaa)? |
@@ -59,68 +52,57 @@ GLWindowContext_mac::~GLWindowContext_mac() { |
} |
void GLWindowContext_mac::onInitializeContext() { |
-#if 0 |
- // TODO: Init for Mac |
- SkASSERT(fDisplay); |
+ SkASSERT(fWindow); |
- fGLContext = glXCreateContext(fDisplay, fVisualInfo, nullptr, GL_TRUE); |
+ fGLContext = SDL_GL_CreateContext(fWindow); |
if (!fGLContext) { |
+ SkDebugf("%s\n", SDL_GetError()); |
return; |
} |
- if (glXMakeCurrent(fDisplay, fWindow, fGLContext)) { |
+ if (0 == SDL_GL_MakeCurrent(fWindow, fGLContext)) { |
glClearStencil(0); |
glClearColor(0, 0, 0, 0); |
glStencilMask(0xffffffff); |
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); |
int redBits, greenBits, blueBits; |
- glXGetConfig(fDisplay, fVisualInfo, GLX_RED_SIZE, &redBits); |
- glXGetConfig(fDisplay, fVisualInfo, GLX_GREEN_SIZE, &greenBits); |
- glXGetConfig(fDisplay, fVisualInfo, GLX_BLUE_SIZE, &blueBits); |
+ SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &redBits); |
+ SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &greenBits); |
+ SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &blueBits); |
fColorBits = redBits + greenBits + blueBits; |
- glXGetConfig(fDisplay, fVisualInfo, GLX_STENCIL_SIZE, &fStencilBits); |
- glXGetConfig(fDisplay, fVisualInfo, GLX_SAMPLES_ARB, &fSampleCount); |
- |
- XWindow root; |
- int x, y; |
- unsigned int border_width, depth; |
- XGetGeometry(fDisplay, fWindow, &root, &x, &y, |
- (unsigned int*)&fWidth, (unsigned int*)&fHeight, &border_width, &depth); |
+ |
+ SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &fStencilBits); |
+ SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &fSampleCount); |
+ |
+ SDL_GetWindowSize(fWindow, &fWidth, &fHeight); |
glViewport(0, 0, fWidth, fHeight); |
+ } else { |
+ SkDebugf("MakeCurrent failed: %s\n", SDL_GetError()); |
} |
-#endif |
} |
void GLWindowContext_mac::onDestroyContext() { |
-#if 0 |
- // TODO: teardown for Mac |
- if (!fDisplay || !fGLContext) { |
+ if (!fWindow || !fGLContext) { |
return; |
} |
- glXMakeCurrent(fDisplay, None, nullptr); |
- glXDestroyContext(fDisplay, fGLContext); |
+ SDL_GL_DeleteContext(fGLContext); |
fGLContext = nullptr; |
-#endif |
} |
void GLWindowContext_mac::onSwapBuffers() { |
-#if 0 |
- // TODO: swap for Mac |
- if (fDisplay && fGLContext) { |
- glXSwapBuffers(fDisplay, fWindow); |
+ if (fWindow && fGLContext) { |
+ SDL_GL_SwapWindow(fWindow); |
} |
-#endif |
} |
} // anonymous namespace |
- |
namespace sk_app { |
namespace window_context_factory { |
-WindowContext* MakeGLForMac(const MacWindowInfo& info, const DisplayParams& params) { |
+WindowContext* NewGLForMac(const MacWindowInfo& info, const DisplayParams& params) { |
WindowContext* ctx = new GLWindowContext_mac(info, params); |
if (!ctx->isValid()) { |
delete ctx; |