2016-07-19 21:17:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
#include "../GLWindowContext.h"
|
|
|
|
#include "WindowContextFactory_mac.h"
|
2016-07-19 21:17:20 +00:00
|
|
|
|
|
|
|
//#include <GL/gl.h>
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
using sk_app::DisplayParams;
|
|
|
|
using sk_app::window_context_factory::MacWindowInfo;
|
|
|
|
using sk_app::GLWindowContext;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class GLWindowContext_mac : public GLWindowContext {
|
|
|
|
public:
|
|
|
|
GLWindowContext_mac(const MacWindowInfo&, const DisplayParams&);
|
|
|
|
|
|
|
|
~GLWindowContext_mac() override;
|
|
|
|
|
|
|
|
void onSwapBuffers() override;
|
|
|
|
|
|
|
|
void onInitializeContext() override;
|
|
|
|
void onDestroyContext() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// TODO: add Mac-specific GL display objects
|
|
|
|
Display* fDisplay;
|
|
|
|
XWindow fWindow;
|
|
|
|
XVisualInfo* fVisualInfo;
|
|
|
|
GLXContext fGLContext;
|
|
|
|
#endif
|
|
|
|
};
|
2016-07-19 21:17:20 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
GLWindowContext_mac::GLWindowContext_mac(const MacWindowInfo& info, const DisplayParams& params)
|
|
|
|
: GLWindowContext(params)
|
2016-07-19 21:17:20 +00:00
|
|
|
#if 0
|
|
|
|
// TODO: init Mac-specific OpenGL objects
|
|
|
|
, fDisplay(nullptr)
|
|
|
|
, fWindow(0)
|
|
|
|
, fGLContext(0)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
|
|
|
|
// any config code here (particularly for msaa)?
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
this->initializeContext();
|
2016-07-19 21:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLWindowContext_mac::~GLWindowContext_mac() {
|
|
|
|
this->destroyContext();
|
|
|
|
}
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
void GLWindowContext_mac::onInitializeContext() {
|
2016-07-19 21:17:20 +00:00
|
|
|
#if 0
|
|
|
|
// TODO: Init for Mac
|
|
|
|
SkASSERT(fDisplay);
|
|
|
|
|
|
|
|
fGLContext = glXCreateContext(fDisplay, fVisualInfo, nullptr, GL_TRUE);
|
|
|
|
if (!fGLContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glXMakeCurrent(fDisplay, 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);
|
|
|
|
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);
|
|
|
|
glViewport(0, 0, fWidth, fHeight);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindowContext_mac::onDestroyContext() {
|
|
|
|
#if 0
|
|
|
|
// TODO: teardown for Mac
|
|
|
|
if (!fDisplay || !fGLContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
glXMakeCurrent(fDisplay, None, nullptr);
|
|
|
|
glXDestroyContext(fDisplay, fGLContext);
|
|
|
|
fGLContext = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GLWindowContext_mac::onSwapBuffers() {
|
|
|
|
#if 0
|
|
|
|
// TODO: swap for Mac
|
|
|
|
if (fDisplay && fGLContext) {
|
|
|
|
glXSwapBuffers(fDisplay, fWindow);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
|
|
namespace sk_app {
|
|
|
|
namespace window_context_factory {
|
|
|
|
|
|
|
|
WindowContext* MakeGLForMac(const MacWindowInfo& info, const DisplayParams& params) {
|
|
|
|
WindowContext* ctx = new GLWindowContext_mac(info, params);
|
|
|
|
if (!ctx->isValid()) {
|
|
|
|
delete ctx;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return ctx;
|
|
|
|
}
|
2016-07-19 21:17:20 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
} // namespace window_context_factory
|
|
|
|
} // namespace sk_app
|