static void xcc_cleanup(XCompcapMain_private *p)
{
	PLock lock(&p->lock);
	XDisplayLock xlock;

	if (p->gltex) {
		gs_texture_destroy(p->gltex);
		p->gltex = 0;
	}

	if (p->glxpixmap) {
		glXDestroyPixmap(xdisp, p->glxpixmap);
		p->glxpixmap = 0;
	}

	if (p->pixmap) {
		XFreePixmap(xdisp, p->pixmap);
		p->pixmap = 0;
	}

	if (p->win) {
		XCompositeUnredirectWindow(xdisp, p->win,
				CompositeRedirectAutomatic);
		XSelectInput(xdisp, p->win, 0);
		p->win = 0;
	}
}
SceneOpenGL::~SceneOpenGL()
{
    if (!init_ok) {
        // TODO this probably needs to clean up whatever has been created until the failure
        m_overlayWindow->destroy();
        return;
    }
    foreach (Window * w, windows)
    delete w;
    // do cleanup after initBuffer()
    cleanupGL();
    glXMakeCurrent(display(), None, NULL);
    glXDestroyContext(display(), ctxbuffer);
    if (m_overlayWindow->window()) {
        if (hasGLXVersion(1, 3))
            glXDestroyWindow(display(), glxbuffer);
        XDestroyWindow(display(), buffer);
        m_overlayWindow->destroy();
    } else {
        glXDestroyPixmap(display(), glxbuffer);
        XFreeGC(display(), gcroot);
        XFreePixmap(display(), buffer);
    }
    SceneOpenGL::EffectFrame::cleanup();
    checkGLError("Cleanup");
}
Beispiel #3
0
static void
vdpau_reset(glw_video_t *gv)
{
  vdpau_dev_t *vd = gv->w.glw_root->gr_be.gbr_vdpau_dev;
  int i;

  if(gv->gv_vdpau_texture) {
    glDeleteTextures(1, &gv->gv_vdpau_texture);
    gv->gv_vdpau_texture = 0;
  }

  for(i = 0; i < GLW_VIDEO_MAX_SURFACES; i++)
    surface_reset(vd, gv, &gv->gv_surfaces[i]);

  vdpau_mixer_deinit(&gv->gv_vm);
  if(gv->gv_vdpau_pq != VDP_INVALID_HANDLE)
    vd->vdp_presentation_queue_destroy(gv->gv_vdpau_pq);
  if(gv->gv_vdpau_pqt != VDP_INVALID_HANDLE)
    vd->vdp_presentation_queue_target_destroy(gv->gv_vdpau_pqt);

  glXDestroyPixmap(vd->vd_dpy, gv->gv_glx_pixmap);
  XFreePixmap(vd->vd_dpy, gv->gv_xpixmap);

  gv->gv_vdpau_running = 0;
  gv->gv_vdpau_clockdiff = 0;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLX13_nglXDestroyPixmap(JNIEnv *__env, jclass clazz, jlong displayAddress, jlong pixmapAddress, jlong __functionAddress) {
	Display *display = (Display *)(intptr_t)displayAddress;
	GLXPixmap pixmap = (GLXPixmap)(intptr_t)pixmapAddress;
	glXDestroyPixmapPROC glXDestroyPixmap = (glXDestroyPixmapPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	glXDestroyPixmap(display, pixmap);
}
int main( int argc, char *argv[] )
{
   Display *dpy;
   Window win;
   Pixmap pm;
   GLXPixmap glxpm;
   int eventbase, errorbase;

   dpy = XOpenDisplay(NULL);

   if(NULL == dpy) {
       fprintf(stderr, "error: opening display\n");
       return EXIT_FAILURE;
   }

   if(!glXQueryExtension(dpy, &eventbase, &errorbase)) {
       fprintf(stderr, "GLX is not available!\n");
       return EXIT_FAILURE;
   }
   

   win = make_rgb_window( dpy, 300, 300 );

   fprintf(stderr, "This test should produce a GLXBadPixmap error.\n");

   glXDestroyPixmap(dpy, /*intentional*/ win);

   return 0;
}
Beispiel #6
0
void CVDPAU::Close()
{
  CLog::Log(LOGNOTICE, " (VDPAU) %s", __FUNCTION__);

  FiniVDPAUOutput();
  FiniVDPAUProcs();

  if (m_glPixmap)
  {
    CLog::Log(LOGINFO, "GLX: Destroying glPixmap");
    glXReleaseTexImageEXT(m_Display, m_glPixmap, GLX_FRONT_LEFT_EXT);
    glXDestroyPixmap(m_Display, m_glPixmap);
    m_glPixmap = NULL;
  }
  if (m_Pixmap)
  {
    CLog::Log(LOGINFO, "GLX: Destroying XPixmap");
    XFreePixmap(m_Display, m_Pixmap);
    m_Pixmap = NULL;
  }

  if (m_glContext)
  {
    CLog::Log(LOGINFO, "GLX: Destroying glContext");
    glXDestroyContext(m_Display, m_glContext);
    m_glContext = NULL;
  }
}
static
void
ppb_video_decoder_destroy_priv(void *p)
{
    struct pp_video_decoder_s *vd = p;

    if (vd->orig_graphics3d) {
        pp_resource_unref(vd->orig_graphics3d);
        vd->orig_graphics3d = 0;
    }

    if (vd->graphics3d) {
        pp_resource_unref(vd->graphics3d);
        vd->graphics3d = 0;
    }

    if (vd->avparser) {
        av_parser_close(vd->avparser);
        vd->avparser = NULL;
    }

    if (vd->avctx)
        avcodec_free_context(&vd->avctx);

    if (vd->avframe)
        av_frame_free(&vd->avframe);

    if (vd->va_context.context_id) {
        vaDestroyContext(display.va, vd->va_context.context_id);
        vd->va_context.context_id = 0;
    }

    if (vd->va_context.config_id) {
        vaDestroyConfig(display.va, vd->va_context.config_id);
        vd->va_context.config_id = 0;
    }

    vaDestroySurfaces(display.va, vd->surfaces, MAX_VIDEO_SURFACES);
    for (uintptr_t k = 0; k < MAX_VIDEO_SURFACES; k ++) {
        vd->surfaces[k] = VA_INVALID_SURFACE;
        vd->surface_used[k] = 0;

    }

    for (uintptr_t k = 0; k < vd->buffer_count; k ++) {
        vd->ppp_video_decoder_dev->DismissPictureBuffer(vd->instance->id, vd->self_id,
                                                        vd->buffers[k].id);
        pthread_mutex_lock(&display.lock);
        glXDestroyPixmap(display.x, vd->buffers[k].glx_pixmap);
        XFreePixmap(display.x, vd->buffers[k].pixmap);
        pthread_mutex_unlock(&display.lock);
    }

    vd->buffer_count = 0;
    vd->buffers_were_requested = 0;
    free_and_nullify(vd->buffers);
}
Beispiel #8
0
bool CVDPAU::FiniOutputMethod()
{
  VdpStatus vdp_st;

  if (vdp_flip_queue != VDP_INVALID_HANDLE)
  {
    vdp_st = vdp_presentation_queue_destroy(vdp_flip_queue);
    vdp_flip_queue = VDP_INVALID_HANDLE;
    CheckStatus(vdp_st, __LINE__);
  }

  if (vdp_flip_target != VDP_INVALID_HANDLE)
  {
    vdp_st = vdp_presentation_queue_target_destroy(vdp_flip_target);
    vdp_flip_target = VDP_INVALID_HANDLE;
    CheckStatus(vdp_st, __LINE__);
  }

  if (m_glPixmap)
  {
    CLog::Log(LOGDEBUG, "GLX: Destroying glPixmap");
    glXDestroyPixmap(m_Display, m_glPixmap);
    m_glPixmap = NULL;
  }

  if (m_Pixmap)
  {
    CLog::Log(LOGDEBUG, "GLX: Destroying XPixmap");
    XFreePixmap(m_Display, m_Pixmap);
    m_Pixmap = NULL;
  }

  outputSurface = presentSurface = VDP_INVALID_HANDLE;

  for (int i = 0; i < totalAvailableOutputSurfaces; i++)
  {
    if (outputSurfaces[i] == VDP_INVALID_HANDLE)
       continue;
    vdp_st = vdp_output_surface_destroy(outputSurfaces[i]);
    outputSurfaces[i] = VDP_INVALID_HANDLE;
    CheckStatus(vdp_st, __LINE__);
  }

  if (videoMixer != VDP_INVALID_HANDLE)
  {
    vdp_st = vdp_video_mixer_destroy(videoMixer);
    videoMixer = VDP_INVALID_HANDLE;
    if (CheckStatus(vdp_st, __LINE__));
  }

  while (!m_DVDVideoPics.empty())
    m_DVDVideoPics.pop();

  return true;
}
Beispiel #9
0
void glxRelease(GLXContextType *glxContext, Pixmap *pixmaps, GLXPixmap *glxPixmaps, int pixmapCount)
{
    int i;
    for (i=0; i<pixmapCount; i++) {
        glXReleaseTexImageEXT_func(glxContext->x11Display, glxPixmaps[i], GLX_FRONT_LEFT_EXT);
        glXDestroyPixmap(glxContext->x11Display, glxPixmaps[i]);
        XFreePixmap(glxContext->x11Display, pixmaps[i]);
    }
    glXDestroyContext(glxContext->x11Display, glxContext->glxContext);
    ASSERT_GL_ERROR();
}
Beispiel #10
0
    ~GraphicsSurfacePrivate()
    {
        if (m_glxPixmap)
            glXDestroyPixmap(m_display, m_glxPixmap);
        m_glxPixmap = 0;

        if (m_xPixmap)
            XFreePixmap(m_display, m_xPixmap);
        m_xPixmap = 0;

        if (m_glContext)
            glXDestroyContext(m_display, m_glContext);
    }
Beispiel #11
0
    ~GraphicsSurfacePrivate()
    {
        if (m_glxPixmap)
            glXDestroyPixmap(m_display, m_glxPixmap);
        m_glxPixmap = 0;

        if (m_xPixmap)
            XFreePixmap(m_display, m_xPixmap);
        m_xPixmap = 0;

        if (m_display)
            XCloseDisplay(m_display);
        m_display = 0;
    }
Beispiel #12
0
int main(int argc, char* argv[]) 
{
    gtk_init(&argc, &argv);

    display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());

    rand = g_rand_new();

    g_width = 400;
    g_height = 300;

    if (setup_context() != 0) return -1;

    ref = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(ref), g_width, g_height);
    g_object_connect(ref,
            "signal::draw", on_ref_draw, NULL, 
            "signal::configure-event", on_ref_configure, NULL, 
            "signal::map-event", on_ref_mapped, NULL, 
            "signal::delete-event", on_deleted, NULL,
            NULL);

    gtk_widget_show_all(ref);


    top = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(top), g_width, g_height);
    gtk_widget_set_app_paintable(top, TRUE);
    gtk_widget_set_double_buffered(top, FALSE);

    g_object_connect(top,
            "signal::draw", on_draw, NULL, 
            "signal::delete-event", on_deleted, NULL,
            NULL);

    gtk_widget_show_all(top);
    GdkWindow* gdkwin = gtk_widget_get_window(top);
    glxwin = glXCreateWindow(display, bestFbc, GDK_WINDOW_XID(gdkwin), NULL);

    g_timeout_add(1000, on_timeout, NULL);
    gtk_main();

    if (glx_pm) {
        glXDestroyPixmap(display, glx_pm);
        XFreePixmap(display, back_pixmap);
    }
    glXDestroyContext(ctx);
    g_rand_free(rand);
}
Beispiel #13
0
int
main(int argc, char *argv[])
{
   Display *dpy;
   const char *dpyName = NULL;
   GLboolean printInfo = GL_FALSE;
   struct gears gears;
   int i, width = 200, height = 200;

   for (i = 1; i < argc; i++) {
      if (strcmp(argv[i], "-display") == 0) {
         dpyName = argv[i+1];
         i++;
      }
      else if (strcmp(argv[i], "-info") == 0) {
         printInfo = GL_TRUE;
      }
   }

   dpy = XOpenDisplay(dpyName);
   if (!dpy) {
      printf("Error: couldn't open display %s\n", XDisplayName(dpyName));
      return -1;
   }

   make_window(dpy, "glxgears", 0, 0, width, height, &gears);
   XMapWindow(dpy, gears.win);
   glXMakeCurrent(dpy, gears.glxpixmap, gears.ctx);

   if (printInfo) {
      printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
      printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
      printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
      printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
   }

   init(width, height);

   event_loop(dpy, &gears);

   glXDestroyContext(dpy, gears.ctx);
   XDestroyWindow(dpy, gears.win);
   glXDestroyPixmap(dpy, gears.glxpixmap);
   XFreePixmap(dpy, gears.pixmap);
   XCloseDisplay(dpy);

   return 0;
}
int
main(int argc, char **argv)
{
	Pixmap p;
	GLXPixmap g;
	GLXContext ctx;

	dpy = XOpenDisplay(NULL);
	if (dpy == NULL) {
		fprintf(stderr, "couldn't open display\n");
		piglit_report_result(PIGLIT_FAIL);
	}

        piglit_glx_get_error(dpy, NULL);
	piglit_require_glx_version(dpy, 1, 3);

	visinfo = piglit_get_glx_visual(dpy);
	p = XCreatePixmap(dpy, DefaultRootWindow(dpy), piglit_width,
			  piglit_height, visinfo->depth);

	g = glXCreateGLXPixmap(dpy, visinfo, p);

	ctx = piglit_get_glx_context(dpy, visinfo);
	glXMakeCurrent(dpy, g, ctx);
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	/* Clear to green */
	glClearColor(0.0, 1.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	/* Noop */
	XSetErrorHandler(handler);
	glXSwapBuffers(dpy, p);

	/* We want to actually catch any X error that leaks through as
	 * a result of glXSwapBuffers() before we go saying "pass" or
	 * "fail".
	 */
	XSync(dpy, False);

	glXDestroyPixmap(dpy, g);

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);

	return 0;
}
int32_t
ppb_graphics3d_resize_buffers(PP_Resource context, int32_t width, int32_t height)
{
    if (width < 0 || height < 0) {
        trace_error("%s, width or height are negative\n", __func__);
        return PP_ERROR_BADARGUMENT;
    }

    struct pp_graphics3d_s *g3d = pp_resource_acquire(context, PP_RESOURCE_GRAPHICS3D);
    if (!g3d) {
        trace_error("%s, bad resource\n", __func__);
        return PP_ERROR_BADRESOURCE;
    }

    g3d->width = width;
    g3d->height = height;

    GLXPixmap old_glx_pixmap = g3d->glx_pixmap;
    Pixmap    old_pixmap = g3d->pixmap;
    Picture   old_pict = g3d->xr_pict;

    // release possibly bound to other thread g3d->glx_pixmap and bind it to the current one
    pthread_mutex_lock(&display.lock);
    glXMakeCurrent(display.x, g3d->glx_pixmap, g3d->glc);
    g3d->pixmap = XCreatePixmap(display.x, DefaultRootWindow(display.x), g3d->width, g3d->height,
                                g3d->depth);
    g3d->glx_pixmap = glXCreatePixmap(display.x, g3d->fb_config, g3d->pixmap, NULL);
    XFlush(display.x);
    g3d->xr_pict = XRenderCreatePicture(display.x, g3d->pixmap, g3d->xr_pictfmt, 0, 0);

    // make new g3d->glx_pixmap current to the current thread to allow releasing old_glx_pixmap
    glXMakeCurrent(display.x, g3d->glx_pixmap, g3d->glc);

    // clear surface
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);

    // destroy previous glx and x pixmaps
    glXDestroyPixmap(display.x, old_glx_pixmap);
    XRenderFreePicture(display.x, old_pict);
    XFreePixmap(display.x, old_pixmap);

    pthread_mutex_unlock(&display.lock);
    pp_resource_release(context);
    return PP_OK;
}
Beispiel #16
0
static void destroy_texture(struct gl_hwdec *hw)
{
    struct priv *p = hw->priv;
    GL *gl = hw->gl;

    if (p->glxpixmap) {
        p->glXReleaseTexImage(p->xdisplay, p->glxpixmap, GLX_FRONT_EXT);
        glXDestroyPixmap(p->xdisplay, p->glxpixmap);
    }
    p->glxpixmap = 0;

    if (p->pixmap)
        XFreePixmap(p->xdisplay, p->pixmap);
    p->pixmap = 0;

    gl->DeleteTextures(1, &p->gl_texture);
    p->gl_texture = 0;
}
Beispiel #17
0
void X11TextureFromPixmap::destroyClientBuffer(Surface* surface)
{
    LOG_ERROR("X11TextureFromPixmap", "destroying clientBuffer");
    GLXPlatformSurface* platformSurface = (GLXPlatformSurface*)surface->platform;
    LOG_DEBUG("X11TextureFromPixmap", "removing GLX Pixmap");
    if (NULL!=platformSurface)
    {
        //glXReleaseTexImageEXT_func(dpy, x11surf->glxPixmap, GLX_FRONT_LEFT_EXT);
        glXDestroyPixmap(dpy, platformSurface->glxPixmap);
        platformSurface->glxPixmap = 0;
    }
    XSync(dpy, 0);

    LOG_DEBUG("X11TextureFromPixmap", "removing X Pixmap");
    if (NULL!=platformSurface)
    {
        XFreePixmap(dpy, platformSurface->pixmap);
        platformSurface->pixmap = 0;
    }
}
DECLEXPORT(EGLBoolean) eglDestroySurface(EGLDisplay hDisplay, EGLSurface hSurface)
{
    Display *pDisplay = (Display *)hDisplay;

    if (!VALID_PTR(hDisplay))
        return setEGLError(EGL_NOT_INITIALIZED);
    switch ((GLXDrawable)hSurface & VBEGL_ANY_SURFACE)
    {
        case VBEGL_WINDOW_SURFACE:
            glXDestroyWindow(pDisplay, (GLXWindow)hSurface & ~VBEGL_WINDOW_SURFACE);
            return clearEGLError();
        case VBEGL_PBUFFER_SURFACE:
            glXDestroyPbuffer(pDisplay, (GLXPbuffer)hSurface & ~VBEGL_PBUFFER_SURFACE);
            return clearEGLError();
        case VBEGL_PIXMAP_SURFACE:
            glXDestroyPixmap(pDisplay, (GLXPixmap)hSurface & ~VBEGL_PIXMAP_SURFACE);
            return clearEGLError();
        default:
            return setEGLError(EGL_BAD_SURFACE);
    }
}
static
void
ppb_graphics3d_destroy(void *p)
{
    struct pp_graphics3d_s *g3d = p;

    g_hash_table_destroy(g3d->sub_maps);
    pthread_mutex_lock(&display.lock);

    // bringing context to current thread releases it from any others
    glXMakeCurrent(display.x, g3d->glx_pixmap, g3d->glc);
    // free it here, to be able to destroy X Pixmap
    glXMakeCurrent(display.x, None, NULL);

    glXDestroyPixmap(display.x, g3d->glx_pixmap);
    XRenderFreePicture(display.x, g3d->xr_pict);
    XFreePixmap(display.x, g3d->pixmap);

    glXDestroyContext(display.x, g3d->glc);
    pthread_mutex_unlock(&display.lock);
}
Beispiel #20
0
static gboolean on_ref_configure(GtkWidget *widget, GdkEvent  *event,
               gpointer   user_data)
{
    g_debug("%s", __func__);
    GdkEventConfigure *gec = (GdkEventConfigure*)event;
    g_width = gec->width;
    g_height = gec->height;
    gtk_window_resize(GTK_WINDOW(top), g_width, g_height);

    if (!gtk_widget_get_mapped(ref)) return TRUE;

    if (back_pixmap) {
        glXDestroyPixmap(display, glx_pm);
        XFreePixmap(display, back_pixmap);

        GdkWindow* gdkwin = gtk_widget_get_window(ref);
        back_pixmap = XCompositeNameWindowPixmap(display, GDK_WINDOW_XID(gdkwin));
        glx_pm = glXCreatePixmap(display, bestFbc, back_pixmap, pixmap_attribs);
    }

    return TRUE;
}
static void
_cogl_texture_pixmap_x11_free_glx_pixmap (CoglTexturePixmapX11 *tex_pixmap)
{
  if (tex_pixmap->glx_pixmap)
    {
      CoglXlibTrapState trap_state;

      _COGL_GET_CONTEXT (ctx, NO_RETVAL);

      if (tex_pixmap->pixmap_bound)
        glXReleaseTexImage (_cogl_xlib_get_display (), tex_pixmap->glx_pixmap,
                            GLX_FRONT_LEFT_EXT);

      /* FIXME - we need to trap errors and synchronize here because
       * of ordering issues between the XPixmap destruction and the
       * GLXPixmap destruction.
       *
       * If the X pixmap is destroyed, the GLX pixmap is destroyed as
       * well immediately, and thus, when Cogl calls glXDestroyPixmap()
       * it'll cause a BadDrawable error.
       *
       * this is technically a bug in the X server, which should not
       * destroy either pixmaps until the call to glXDestroyPixmap(); so
       * at some point we should revisit this code and remove the
       * trap+sync after verifying that the destruction is indeed safe.
       *
       * for reference, see:
       *   http://bugzilla.clutter-project.org/show_bug.cgi?id=2324
       */
      _cogl_xlib_trap_errors (&trap_state);
      glXDestroyPixmap (_cogl_xlib_get_display (), tex_pixmap->glx_pixmap);
      XSync (_cogl_xlib_get_display (), False);
      _cogl_xlib_untrap_errors (&trap_state);

      tex_pixmap->glx_pixmap = None;
      tex_pixmap->pixmap_bound = FALSE;
    }
}
Beispiel #22
0
static void
free_window(riftwm_t *wm, riftwin_t *win)
{
  if (win->glx_pixmap) {
    glBindTexture(GL_TEXTURE_2D, win->texture);
    wm->glXReleaseTexImageEXT(wm->dpy, win->glx_pixmap, GLX_FRONT_LEFT_EXT);
    glBindTexture(GL_TEXTURE_2D, 0);
    glXDestroyPixmap(wm->dpy, win->glx_pixmap);
    win->glx_pixmap = 0;
  }

  if (win->pixmap) {
    XFreePixmap(wm->dpy, win->pixmap);
    win->pixmap = 0;
  }

  if (win->texture) {
    glDeleteTextures(1, &win->texture);
    win->texture = 0;
  }

  free(win);
}
Beispiel #23
0
static void glx_free_pixmaps(void) {
    glXDestroyPixmap(display, glx_tmp);
    glXDestroyPixmap(display, glx_tmp1);
    XFreePixmap(display, tmp);
    XFreePixmap(display, tmp1);
}
static void
try_create_glx_pixmap (CoglTexturePixmapX11 *tex_pixmap,
                       gboolean mipmap)
{
  Display *dpy;
  /* We have to initialize this *opaque* variable because gcc tries to
   * be too smart for its own good and warns that the variable may be
   * used uninitialized otherwise. */
  GLXFBConfig fb_config = (GLXFBConfig)0;
  int attribs[7];
  int i = 0;
  GLenum target;
  CoglXlibTrapState trap_state;

  _COGL_GET_CONTEXT (ctxt, NO_RETVAL);

  tex_pixmap->pixmap_bound = FALSE;
  tex_pixmap->glx_pixmap = None;

  if ((ctxt->winsys.feature_flags &
       COGL_WINSYS_FEATURE_TEXTURE_FROM_PIXMAP) == 0)
    return;

  dpy = _cogl_xlib_get_display ();

  if (!get_fbconfig_for_depth (tex_pixmap->depth, &fb_config,
                               &tex_pixmap->glx_can_mipmap))
    {
      COGL_NOTE (TEXTURE_PIXMAP, "No suitable FBConfig found for depth %i",
                 tex_pixmap->depth);
      return;
    }

  if (should_use_rectangle ())
    {
      target = GLX_TEXTURE_RECTANGLE_EXT;
      tex_pixmap->glx_can_mipmap = FALSE;
    }
  else
    target = GLX_TEXTURE_2D_EXT;

  if (!tex_pixmap->glx_can_mipmap)
    mipmap = FALSE;

  attribs[i++] = GLX_TEXTURE_FORMAT_EXT;

  if (tex_pixmap->depth == 24)
    attribs[i++] = GLX_TEXTURE_FORMAT_RGB_EXT;
  else if (tex_pixmap->depth == 32)
    attribs[i++] = GLX_TEXTURE_FORMAT_RGBA_EXT;
  else
    return;

  attribs[i++] = GLX_MIPMAP_TEXTURE_EXT;
  attribs[i++] = mipmap;

  attribs[i++] = GLX_TEXTURE_TARGET_EXT;
  attribs[i++] = target;

  attribs[i++] = None;

  /* We need to trap errors from glXCreatePixmap because it can
     sometimes fail during normal usage. For example on NVidia it gets
     upset if you try to create two GLXPixmaps for the same
     drawable. */

  _cogl_xlib_trap_errors (&trap_state);

  tex_pixmap->glx_pixmap = glXCreatePixmap (dpy,
                                            fb_config,
                                            tex_pixmap->pixmap,
                                            attribs);
  tex_pixmap->glx_pixmap_has_mipmap = mipmap;

  XSync (dpy, False);

  if (_cogl_xlib_untrap_errors (&trap_state))
    {
      COGL_NOTE (TEXTURE_PIXMAP, "Failed to create pixmap for %p", tex_pixmap);
      _cogl_xlib_trap_errors (&trap_state);
      glXDestroyPixmap (dpy, tex_pixmap->glx_pixmap);
      XSync (dpy, False);
      _cogl_xlib_untrap_errors (&trap_state);

      tex_pixmap->glx_pixmap = None;
    }
}
Beispiel #25
0
int
main(int argc, char **argv)
{
    Pixmap p;
    GLXPixmap g;
    static const float green_alpha_zero[4] = {0.0, 1.0, 0.0, 0.0};
    static const float green_alpha_one[4] = {0.0, 1.0, 0.0, 1.0};
    GLXContext ctx;
    bool pass;
    GLint alpha_bits;

    dpy = XOpenDisplay(NULL);
    if (dpy == NULL) {
        fprintf(stderr, "couldn't open display\n");
        piglit_report_result(PIGLIT_FAIL);
    }

    piglit_glx_get_error(dpy, NULL);
    piglit_require_glx_version(dpy, 1, 3);

    visinfo = piglit_get_glx_visual(dpy);
    p = XCreatePixmap(dpy, DefaultRootWindow(dpy), piglit_width,
                      piglit_height, visinfo->depth);

    g = glXCreateGLXPixmap(dpy, visinfo, p);

    ctx = piglit_get_glx_context(dpy, visinfo);
    glXMakeCurrent(dpy, g, ctx);
    piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

    /* Clear to green */
    glClearColor(0.0, 1.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);

    /* Noop */
    glXSwapBuffers(dpy, g);

    /* We want to actually catch any X error that leaks through as
     * a result of glXSwapBuffers() before we go saying "pass" or
     * "fail".
     */
    XSync(dpy, False);

    /* If the visual has no alpha, then the GL spec requires that 1.0 be
     * read back.  Otherwise, we should read back the 0.0 that we wrote.
     */
    glGetIntegerv(GL_ALPHA_BITS, &alpha_bits);
    if (alpha_bits == 0) {
        pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
                                      green_alpha_one);
    } else {
        pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
                                      green_alpha_zero);
    }

    glXDestroyPixmap(dpy, g);

    piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);

    return 0;
}
Beispiel #26
0
// -----------------------------------------------------------------------------
// Internal stuff
// -----------------------------------------------------------------------------
static void
create_texture(riftwm_t *wm, riftwin_t *win)
{
  XWindowAttributes attr;

  // Retrieve properties
  if (!XGetWindowAttributes(wm->dpy, win->window, &attr)) {
    riftwm_error(wm, "Cannot retrieve window attributes");
  }

  win->width = attr.width;
  win->height = attr.height;
  if (attr.map_state != IsViewable) {
    return;
  }

  // Free old resources
  if (win->glx_pixmap) {
    glBindTexture(GL_TEXTURE_2D, win->texture);
    wm->glXReleaseTexImageEXT(wm->dpy, win->glx_pixmap, GLX_FRONT_LEFT_EXT);
    glBindTexture(GL_TEXTURE_2D, 0);

    glXDestroyPixmap(wm->dpy, win->glx_pixmap);
    win->glx_pixmap = 0;
  }

  if (win->pixmap) {
    XFreePixmap(wm->dpy, win->pixmap);
    win->pixmap = 0;
  }

  if (!win->texture) {
    glGenTextures(1, &win->texture);
  }

  // Retrieve the pixmap from the XComposite
  win->pixmap = XCompositeNameWindowPixmap(wm->dpy, win->window);

  // Create a backing OpenGL pixmap
  const int ATTR[] =
  {
    GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
    GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
    None
  };

  if (!(win->glx_pixmap = glXCreatePixmap(wm->dpy, wm->fb_config[1].config,
                                          win->pixmap, ATTR)))
  {
    riftwm_error(wm, "Cannot create GLX pixmap");
  }

  // Create the texture
  glBindTexture(GL_TEXTURE_2D, win->texture);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  wm->glXBindTexImageEXT(wm->dpy, win->glx_pixmap, GLX_FRONT_LEFT_EXT, NULL);
  glBindTexture(GL_TEXTURE_2D, 0);

  win->dirty = 0;
}
Beispiel #27
0
void blur_image_gl(int scr, Pixmap pixmap, int width, int height, int radius,
                   float sigma) {
    if (configs == NULL) {
        glx_init(scr, width, height, radius, sigma);
    }

    glx_pixmap = glXCreatePixmap(display, configs[0], pixmap, pixmap_attribs);

    for (uint8_t i = 0; i < 2; ++i) {
        if ((i & 1) == 0) {
            glXMakeCurrent(display, glx_tmp, ctx);
        } else {
            glXMakeCurrent(display, glx_tmp1, ctx);
        }
        glEnable(GL_TEXTURE_2D);
        if (i == 0) {
            glXBindTexImageEXT_f(display, glx_pixmap, GLX_FRONT_EXT, NULL);
        } else {
            glXBindTexImageEXT_f(display, (i & 1) == 1 ? glx_tmp : glx_tmp1,
                                 GLX_FRONT_EXT, NULL);
        }
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

        glViewport(0, 0, (GLsizei)width, (GLsizei)height);
        glClearColor(0.3, 0.3, 0.3, 1.0);
        glClear(GL_COLOR_BUFFER_BIT);

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-1.0, 1.0, -1.0, 1.0, -1., 1);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        glColor3f(0.0, 0.0, 1.0);

        glUseProgram(shader_prog);
        GLint u_Scale = glGetUniformLocation(shader_prog, "u_Scale");
        if ((i & 1) == 0) {
            glUniform2f(u_Scale, 1.0 / width, 0);
        } else {
            glUniform2f(u_Scale, 0, 1.0 / height);
        }

        glBegin(GL_QUADS);
        glTexCoord2f(0.0, 0.0);
        glVertex2f(-1.0, 1.0);
        glTexCoord2f(1.0, 0.0);
        glVertex2f(1.0, 1.0);
        glTexCoord2f(1.0, 1.0);
        glVertex2f(1.0, -1.0);
        glTexCoord2f(0.0, 1.0);
        glVertex2f(-1.0, -1.0);
        glEnd();
        glFlush();

        if (i == 0) {
            glXReleaseTexImageEXT_f(display, glx_pixmap, GLX_FRONT_EXT);
        } else {
            glXReleaseTexImageEXT_f(display, (i & 1) == 1 ? glx_tmp : glx_tmp1,
                                    GLX_FRONT_EXT);
        }
    }
    GC gc = XCreateGC(display, pixmap, 0, NULL);
    XCopyArea(display, tmp1, pixmap, gc, 0, 0, width, height, 0, 0);
    XFreeGC(display, gc);
    glXDestroyPixmap(display, glx_pixmap);
}