Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: tools/viewer/sk_app/mac/GLWindowContext_mac.cpp

Issue 2210603003: Get Mac viewer working with SDL (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix patch Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/libsdl/mac/sdl_mac.gypi ('k') | tools/viewer/sk_app/mac/WindowContextFactory_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « third_party/libsdl/mac/sdl_mac.gypi ('k') | tools/viewer/sk_app/mac/WindowContextFactory_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698