GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
{
    if (m_context) {
        // This may be necessary to prevent crashes with NVidia's closed source drivers. Originally
        // from Mozilla's 3D canvas implementation at: http://bitbucket.org/ilmari/canvas3d/
        ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

        ::glXMakeContextCurrent(sharedDisplay(), 0, 0, 0);
        ::glXDestroyContext(sharedDisplay(), m_context);
        m_context = 0;
    }

    if (m_pbuffer) {
        ::glXDestroyPbuffer(sharedDisplay(), m_pbuffer);
        m_pbuffer = 0;
    }
    if (m_glxPixmap) {
        glXDestroyGLXPixmap(sharedDisplay(), m_glxPixmap);
        m_glxPixmap = 0;
    }
    if (m_pixmap) {
        XFreePixmap(sharedDisplay(), m_pixmap);
        m_pixmap = 0;
    }
}
bool GraphicsContext3DPrivate::makeContextCurrent()
{
    if (::glXGetCurrentContext() == m_context)
        return true;
    if (!m_context)
        return false;
    if (m_pbuffer)
        return ::glXMakeCurrent(sharedDisplay(), m_pbuffer, m_context);

    ASSERT(m_glxPixmap);
    return ::glXMakeCurrent(sharedDisplay(), m_glxPixmap, m_context);
}
Example #3
0
void GraphicsContext3DPrivate::makeContextCurrent()
{
    if (::glXGetCurrentContext() == m_context)
        return;
    if (!m_context)
        return;
    if (m_pbuffer) {
        ::glXMakeCurrent(sharedDisplay(), m_pbuffer, m_context);
        return;
    }

    ASSERT(m_glxPixmap);
    ::glXMakeCurrent(sharedDisplay(), m_glxPixmap, m_context);
}
GraphicsContext3DPrivate* GraphicsContext3DPrivate::createPbufferContext()
{
    int fbConfigAttributes[] = {
        GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
        GLX_RENDER_TYPE, GLX_RGBA_BIT,
        GLX_RED_SIZE, 1,
        GLX_GREEN_SIZE, 1,
        GLX_BLUE_SIZE, 1,
        GLX_ALPHA_SIZE, 1,
        GLX_DEPTH_SIZE, 1,
        GLX_STENCIL_SIZE, 1,
        GLX_SAMPLE_BUFFERS, 1,
        GLX_DOUBLEBUFFER, GL_FALSE,
        GLX_SAMPLES, 4,
        0
    };
    int returnedElements;
    GLXFBConfig* configs = glXChooseFBConfig(sharedDisplay(), 0, fbConfigAttributes, &returnedElements);
    if (!configs) {
        fbConfigAttributes[20] = 0; // Attempt without anti-aliasing.
        configs = glXChooseFBConfig(sharedDisplay(), 0, fbConfigAttributes, &returnedElements);
    }
    if (!returnedElements) {
        XFree(configs);
        return 0;
    }

    // We will be rendering to a texture, so our pbuffer does not need to be large.
    static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };
    GLXPbuffer pbuffer = glXCreatePbuffer(sharedDisplay(), configs[0], pbufferAttributes);
    if (!pbuffer) {
        XFree(configs);
        return 0;
    }

    GLXContext context = glXCreateNewContext(sharedDisplay(), configs[0], GLX_RGBA_TYPE, 0, GL_TRUE);
    XFree(configs);
    if (!context)
        return 0;
    return new GraphicsContext3DPrivate(context, pbuffer);
}
Example #5
0
NodeMap::NodeMap(v8::Local<v8::Object> options) :
    view(sharedDisplay(), [&] {
        Nan::HandleScope scope;
        return Nan::Has(options, Nan::New("ratio").ToLocalChecked()).FromJust() ? Nan::Get(options, Nan::New("ratio").ToLocalChecked()).ToLocalChecked()->NumberValue() : 1.0;
    }()),
    map(std::make_unique<mbgl::Map>(view, *this, mbgl::MapMode::Still)),
    async(new uv_async_t) {

    async->data = this;
    uv_async_init(uv_default_loop(), async, [](UV_ASYNC_PARAMS(h)) {
        reinterpret_cast<NodeMap *>(h->data)->renderFinished();
    });

    // Make sure the async handle doesn't keep the loop alive.
    uv_unref(reinterpret_cast<uv_handle_t *>(async));
}
PassOwnPtr<GraphicsContext3DPrivate> GraphicsContext3DPrivate::create()
{
    if (!sharedDisplay())
        return nullptr;

    static bool initialized = false;
    static bool success = true;
    if (!initialized) {
        success = initializeOpenGLShims();
        initialized = true;
    }
    if (!success)
        return nullptr;

    GraphicsContext3DPrivate* internal = createPbufferContext();
    if (!internal)
        internal = createPixmapContext();
    if (!internal)
        return nullptr;

    // The GraphicsContext3D constructor requires that this context is the current OpenGL context.
    internal->makeContextCurrent();
    return adoptPtr(internal);
}
GraphicsContext3DPrivate* GraphicsContext3DPrivate::createPixmapContext()
{
    static int visualAttributes[] = {
        GLX_RGBA,
        GLX_RED_SIZE, 1,
        GLX_GREEN_SIZE, 1,
        GLX_BLUE_SIZE, 1,
        GLX_ALPHA_SIZE, 1,
        GLX_DOUBLEBUFFER,
        0
    };

    XVisualInfo* visualInfo = glXChooseVisual(sharedDisplay(), DefaultScreen(sharedDisplay()), visualAttributes);
    if (!visualInfo)
        return 0;
 
    GLXContext context = glXCreateContext(sharedDisplay(), visualInfo, 0, GL_TRUE);
    if (!context) {
        XFree(visualInfo);
        return 0;
    }

    Pixmap pixmap = XCreatePixmap(sharedDisplay(), DefaultRootWindow(sharedDisplay()), 1, 1, visualInfo->depth);
    if (!pixmap) {
        XFree(visualInfo);
        return 0;
    }

    GLXPixmap glxPixmap = glXCreateGLXPixmap(sharedDisplay(), visualInfo, pixmap);
    if (!glxPixmap) {
        XFreePixmap(sharedDisplay(), pixmap);
        XFree(visualInfo);
        return 0;
    }

    return new GraphicsContext3DPrivate(context, pixmap, glxPixmap);
}
Example #8
0
PlatformDisplay& PlatformDisplay::sharedDisplayForCompositing()
{
    return s_sharedDisplayForCompositing ? *s_sharedDisplayForCompositing : sharedDisplay();
}
Example #9
0
template<> void XUniqueResource<XResource::GLXPixmap>::deleteXResource(unsigned long resource)
{
    if (resource)
        glXDestroyGLXPixmap(sharedDisplay(), resource);
}
Example #10
0
template<> void XUniqueResource<XResource::Window>::deleteXResource(unsigned long resource)
{
    if (resource)
        XDestroyWindow(sharedDisplay(), resource);
}
Example #11
0
template<> void XUniqueResource<XResource::Pixmap>::deleteXResource(unsigned long resource)
{
    if (resource)
        XFreePixmap(sharedDisplay(), resource);
}
Example #12
0
template<> void XUniqueResource<XResource::Damage>::deleteXResource(unsigned long resource)
{
    if (resource)
        XDamageDestroy(sharedDisplay(), resource);
}