static void win_resize_cb(void *data, Evas *e , Evas_Object *obj , void *event_info) { appdata_s *ad = data; if(ad->evas_gl_surface) { cairo_surface_destroy(ad->surface); cairo_destroy(ad->cairo); cairo_device_destroy(ad->cairo_device); evas_gl_surface_destroy(ad->evas_gl, ad->evas_gl_surface); ad->evas_gl_surface = NULL; } evas_object_geometry_get(obj, NULL, NULL, &ad->width, &ad->height); evas_object_image_size_set(ad->img, ad->width, ad->height); evas_object_resize(ad->img, ad->width, ad->height); evas_object_show(ad->img); if(!ad->evas_gl_surface) { Evas_Native_Surface ns; ad->evas_gl_surface = evas_gl_surface_create(ad->evas_gl, ad->evas_gl_config, ad->width, ad->height); evas_gl_native_surface_get(ad->evas_gl, ad->evas_gl_surface, &ns); evas_object_image_native_surface_set(ad->img, &ns); evas_object_image_pixels_dirty_set (ad->img, EINA_TRUE); ad->cairo_device = (cairo_device_t *)cairo_evas_gl_device_create (ad->evas_gl, ad->evas_gl_context); cairo_gl_device_set_thread_aware(ad->cairo_device, 0); ad->surface = (cairo_surface_t *)cairo_gl_surface_create_for_evas_gl(ad->cairo_device, ad->evas_gl_surface, ad->evas_gl_config, ad->width, ad->height); ad->cairo = cairo_create (ad->surface); } }
static void _cairo_boilerplate_xcb_cleanup (void *closure) { xcb_target_closure_t *xtc = closure; cairo_status_t status; cairo_surface_finish (xtc->surface); if (xtc->is_pixmap) xcb_free_pixmap (xtc->c, xtc->drawable); else xcb_destroy_window (xtc->c, xtc->drawable); cairo_surface_destroy (xtc->surface); cairo_device_finish (xtc->device); cairo_device_destroy (xtc->device); /* First synchronize with the X server to make sure there are no more errors * in-flight which we would miss otherwise */ _cairo_boilerplate_xcb_sync_server (xtc); status = _cairo_boilerplate_xcb_handle_errors (xtc); assert (status == CAIRO_STATUS_SUCCESS); xcb_disconnect (xtc->c); free (xtc); }
static void cr_device_free (void *ptr) { cairo_device_t *device = ptr; if (device) cairo_device_destroy (device); }
static cairo_surface_t* create_source_surface(int width, int height) { int rgba_attribs[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_ALPHA_SIZE, 1, GLX_DOUBLEBUFFER, None }; XVisualInfo *visinfo; GLXContext ctx; struct closure *arg; cairo_device_t *device; cairo_surface_t *surface; Display *dpy; dpy = XOpenDisplay(NULL); if (dpy == NULL) return NULL; visinfo = glXChooseVisual (dpy, DefaultScreen (dpy), rgba_attribs); if (visinfo == NULL) { XCloseDisplay (dpy); return NULL; } ctx = glXCreateContext (dpy, visinfo, NULL, True); XFree (visinfo); if (ctx == NULL) { XCloseDisplay (dpy); return NULL; } arg = (struct closure*)(malloc (sizeof (struct closure))); arg->dpy = dpy; arg->ctx = ctx; device = cairo_glx_device_create (dpy, ctx); if (cairo_device_set_user_data (device, (cairo_user_data_key_t *) cleanup, arg, cleanup)) { cleanup (arg); return NULL; } surface = cairo_gl_surface_create (device, CAIRO_CONTENT_COLOR_ALPHA, width, height); cairo_device_destroy (device); return surface; }
VALUE rb_cairo_device_to_ruby_object_with_destroy (cairo_device_t *device) { VALUE rb_device; rb_device = rb_cairo_device_to_ruby_object (device); if (device) cairo_device_destroy (device); return rb_device; }
/* Backend device manipulation */ static VALUE cr_device_destroy (VALUE self) { cairo_device_t *device; device = _SELF; cairo_device_destroy (device); DATA_PTR (self) = NULL; return self; }
static int gc_Device (lua_State *L) { Device *o = check_Device_ud(L, 1); if (o->dev_ && o->havedev_) { cairo_device_destroy (o->dev_); o->dev_ = NULL; o->havedev_ = 0; } return 0; }
static void cleanup (void *data) { struct closure *arg = data; cairo_device_finish (arg->device); cairo_device_destroy (arg->device); xcb_free_pixmap (arg->connection, arg->pixmap); xcb_disconnect (arg->connection); free (arg); }
static void _cairo_boilerplate_egl_cleanup (void *closure) { egl_target_closure_t *gltc = closure; cairo_device_finish (gltc->device); cairo_device_destroy (gltc->device); eglDestroyContext (gltc->dpy, gltc->ctx); eglMakeCurrent (gltc->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglTerminate (gltc->dpy); free (gltc); }
void GLContextGLX::clear() { if (!m_context) return; if (m_cairoDevice) { cairo_device_destroy(m_cairoDevice); m_cairoDevice = nullptr; } glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glXMakeCurrent(m_x11Display, None, None); m_context = nullptr; }
GLContextEGL::~GLContextEGL() { if (m_cairoDevice) cairo_device_destroy(m_cairoDevice); EGLDisplay display = sharedEGLDisplay(); if (m_context) { glBindFramebuffer(GL_FRAMEBUFFER, 0); eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(display, m_context); } if (m_surface) eglDestroySurface(display, m_surface); }
static void _cairo_boilerplate_gl_cleanup (void *closure) { gl_target_closure_t *gltc = closure; cairo_device_finish (gltc->device); cairo_device_destroy (gltc->device); glXDestroyContext (gltc->dpy, gltc->ctx); if (gltc->drawable) XDestroyWindow (gltc->dpy, gltc->drawable); XCloseDisplay (gltc->dpy); free (gltc); }
static void win_delete_request_cb(void *data, Evas_Object *obj, void *event_info) { appdata_s *ad = data; cairo_surface_destroy(ad->surface); cairo_destroy(ad->cairo); cairo_device_destroy(ad->cairo_device); evas_gl_surface_destroy(ad->evas_gl, ad->evas_gl_surface); evas_gl_context_destroy(ad->evas_gl, ad->evas_gl_context); evas_gl_config_free(ad->evas_gl_config); evas_gl_free(ad->evas_gl); ui_app_exit(); }
static void _cairo_boilerplate_xcb_cleanup (void *closure) { xcb_target_closure_t *xtc = closure; if (xtc->is_pixmap) xcb_free_pixmap (xtc->c, xtc->drawable); else xcb_destroy_window (xtc->c, xtc->drawable); cairo_surface_destroy (xtc->surface); cairo_device_finish (xtc->device); cairo_device_destroy (xtc->device); xcb_disconnect (xtc->c); free (xtc); }
/** * cairo_win32_surface_create: * @hdc: the DC to create a surface for * * Creates a cairo surface that targets the given DC. The DC will be * queried for its initial clip extents, and this will be used as the * size of the cairo surface. The resulting surface will always be of * format %CAIRO_FORMAT_RGB24; should you need another surface format, * you will need to create one through * cairo_win32_surface_create_with_dib(). * * Return value: the newly created surface * * Since: 1.0 **/ cairo_surface_t * cairo_win32_surface_create (HDC hdc) { cairo_win32_display_surface_t *surface; cairo_format_t format; cairo_status_t status; cairo_device_t *device; /* Assume that everything coming in as a HDC is RGB24 */ format = CAIRO_FORMAT_RGB24; surface = malloc (sizeof (*surface)); if (surface == NULL) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); status = _cairo_win32_save_initial_clip (hdc, surface); if (status) { free (surface); return _cairo_surface_create_in_error (status); } surface->image = NULL; surface->fallback = NULL; surface->win32.format = format; surface->win32.dc = hdc; surface->bitmap = NULL; surface->is_dib = FALSE; surface->saved_dc_bitmap = NULL; surface->win32.flags = _cairo_win32_flags_for_dc (surface->win32.dc); device = _cairo_win32_device_get (); _cairo_surface_init (&surface->win32.base, &cairo_win32_display_surface_backend, device, _cairo_content_from_format (format)); cairo_device_destroy (device); return &surface->win32.base; }
void Surface::release() { ILOG_TRACE(ILX_SURFACE); lock(); #ifdef ILIXI_HAVE_CAIRO if (_cairoContext) { cairo_destroy(_cairoContext); _cairoContext = NULL; } if (_cairoSurface) { cairo_surface_destroy(_cairoSurface); _cairoSurface = NULL; } #ifdef ILIXI_HAVE_CAIROGLES if(_deviceGL) { cairo_surface_destroy(_surfaceGL); cairo_device_finish(_deviceGL); cairo_device_destroy(_deviceGL); } #endif #endif // ILIXI_HAVE_CAIRO #ifdef ILIXI_STEREO_OUTPUT if (_rightSurface) { _rightSurface->Release(_rightSurface); _rightSurface = NULL; } #endif if (_dfbSurface) { _dfbSurface->Release(_dfbSurface); _dfbSurface = NULL; } unlock(); }
GLContextEGL::~GLContextEGL() { #if USE(CAIRO) if (m_cairoDevice) cairo_device_destroy(m_cairoDevice); #endif EGLDisplay display = m_display.eglDisplay(); if (m_context) { glBindFramebuffer(GL_FRAMEBUFFER, 0); eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(display, m_context); } if (m_surface) eglDestroySurface(display, m_surface); #if PLATFORM(WAYLAND) destroyWaylandWindow(); #endif }
int main (int argc, char **argv) { cairo_surface_t *surface = NULL; const cairo_script_interpreter_hooks_t hooks = { .closure = &surface, .surface_create = _surface_create, }; cairo_script_interpreter_t *csi; FILE *in = stdin, *out = stdout; if (argc >= 2 && strcmp (argv[1], "-")) in = fopen (argv[1], "r"); if (argc >= 3 && strcmp (argv[2], "-")) out = fopen (argv[2], "w"); csi = cairo_script_interpreter_create (); cairo_script_interpreter_install_hooks (csi, &hooks); cairo_script_interpreter_feed_stream (csi, in); cairo_script_interpreter_finish (csi); cairo_script_interpreter_destroy (csi); if (surface != NULL) { cairo_device_t *xml; xml = cairo_xml_create_for_stream (stdio_write, out); cairo_xml_for_recording_surface (xml, surface); cairo_device_destroy (xml); cairo_surface_destroy (surface); } if (in != stdin) fclose (in); if (out != stdout) fclose (out); return 0; }
CairoGLRenderer::~CairoGLRenderer() { cairo_destroy(m_cr); cairo_surface_destroy(m_surface); cairo_device_destroy(m_device); }
cairo_surface_t * _cairo_boilerplate_get_image_surface (cairo_surface_t *src, int page, int width, int height) { cairo_surface_t *surface, *image; cairo_t *cr; cairo_status_t status; cairo_format_t format; if (cairo_surface_status (src)) return cairo_surface_reference (src); if (page != 0) return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); /* extract sub-surface */ switch (cairo_surface_get_content (src)) { case CAIRO_CONTENT_ALPHA: format = CAIRO_FORMAT_A8; break; case CAIRO_CONTENT_COLOR: format = CAIRO_FORMAT_RGB24; break; default: case CAIRO_CONTENT_COLOR_ALPHA: format = CAIRO_FORMAT_ARGB32; break; } surface = cairo_image_surface_create (format, width, height); assert (cairo_surface_get_content (surface) == cairo_surface_get_content (src)); image = cairo_surface_reference (surface); /* open a logging channel (only interesting for recording surfaces) */ #if CAIRO_HAS_SCRIPT_SURFACE && CAIRO_HAS_RECORDING_SURFACE if (cairo_surface_get_type (src) == CAIRO_SURFACE_TYPE_RECORDING) { const char *test_name; test_name = cairo_surface_get_user_data (src, &cairo_boilerplate_output_basename_key); if (test_name != NULL) { cairo_device_t *ctx; char *filename; cairo_surface_destroy (surface); xasprintf (&filename, "%s.out.trace", test_name); ctx = cairo_script_create (filename); surface = cairo_script_surface_create_for_target (ctx, image); cairo_device_destroy (ctx); free (filename); } } #endif cr = cairo_create (surface); cairo_surface_destroy (surface); cairo_set_source_surface (cr, src, 0, 0); cairo_paint (cr); status = cairo_status (cr); if (status) { cairo_surface_destroy (image); image = cairo_surface_reference (cairo_get_target (cr)); } cairo_destroy (cr); return image; }
static MechEGLConfigPrivate * _create_egl_config (gint renderable_type) { EGLint major, minor, n_configs; MechBackendWayland *backend; MechEGLConfigPrivate *priv; const gchar *extensions; MechEGLConfig *config; GError *error; EGLenum api; const EGLint argb_config_attributes[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 24, EGL_RENDERABLE_TYPE, renderable_type, EGL_NONE }; priv = g_new0 (MechEGLConfigPrivate, 1); config = (MechEGLConfig *) priv; if (renderable_type != EGL_OPENGL_BIT && renderable_type != EGL_OPENGL_ES_BIT && renderable_type != EGL_OPENGL_ES2_BIT) { error = g_error_new (mech_surface_egl_error_quark (), 0, "Not a valid renderable type"); goto init_failed; } backend = _mech_backend_wayland_get (); config->egl_display = eglGetDisplay (backend->wl_display); if (eglInitialize (config->egl_display, &major, &minor) == EGL_FALSE) { error = g_error_new (mech_surface_egl_error_quark (), 0, "Could not initialize EGL"); goto init_failed; } api = (renderable_type == EGL_OPENGL_BIT) ? EGL_OPENGL_API : EGL_OPENGL_ES_API; if (eglBindAPI (api) == EGL_FALSE) { error = g_error_new (mech_surface_egl_error_quark (), 0, "Could not bind a rendering API"); goto init_failed; } if (eglChooseConfig (config->egl_display, argb_config_attributes, &config->egl_argb_config, 1, &n_configs) == EGL_FALSE) { error = g_error_new (mech_surface_egl_error_quark (), 0, "Could not find a matching configuration"); goto init_failed; } config->egl_argb_context = eglCreateContext (config->egl_display, config->egl_argb_config, EGL_NO_CONTEXT, NULL); if (config->egl_argb_context == EGL_NO_CONTEXT) { error = g_error_new (mech_surface_egl_error_quark (), 0, "Could not create an EGL context"); goto init_failed; } if (eglMakeCurrent (config->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, config->egl_argb_context) == EGL_FALSE) { error = g_error_new (mech_surface_egl_error_quark (), 0, "Could not make EGL context current"); goto init_failed; } config->argb_device = cairo_egl_device_create (config->egl_display, config->egl_argb_context); if (cairo_device_status (config->argb_device) != CAIRO_STATUS_SUCCESS) { error = g_error_new (mech_surface_egl_error_quark (), 0, "Could not create a cairo EGL device"); goto init_failed; } extensions = eglQueryString (config->egl_display, EGL_EXTENSIONS); if (strstr (extensions, "EGL_EXT_buffer_age")) config->has_buffer_age_ext = TRUE; if (strstr (extensions, "EGL_EXT_swap_buffers_with_damage")) config->has_swap_buffers_with_damage_ext = TRUE; return priv; init_failed: if (config->egl_argb_context != EGL_NO_CONTEXT) { eglDestroyContext (config->egl_display, config->egl_argb_context); config->egl_argb_context = EGL_NO_CONTEXT; } if (config->argb_device) { cairo_device_destroy (config->argb_device); config->argb_device = NULL; } priv->error = error; return priv; }
static cairo_surface_t * _cairo_win32_display_surface_create_for_dc (HDC original_dc, cairo_format_t format, int width, int height) { cairo_status_t status; cairo_device_t *device; cairo_win32_display_surface_t *surface; unsigned char *bits; int rowstride; surface = malloc (sizeof (*surface)); if (surface == NULL) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); surface->fallback = NULL; status = _create_dc_and_bitmap (surface, original_dc, format, width, height, &bits, &rowstride); if (status) goto FAIL; surface->image = cairo_image_surface_create_for_data (bits, format, width, height, rowstride); status = surface->image->status; if (status) goto FAIL; _cairo_image_surface_set_parent (to_image_surface(surface->image), &surface->win32.base); surface->win32.format = format; surface->win32.extents.x = 0; surface->win32.extents.y = 0; surface->win32.extents.width = width; surface->win32.extents.height = height; surface->initial_clip_rgn = NULL; surface->had_simple_clip = FALSE; device = _cairo_win32_device_get (); _cairo_surface_init (&surface->win32.base, &cairo_win32_display_surface_backend, device, _cairo_content_from_format (format)); cairo_device_destroy (device); return &surface->win32.base; FAIL: if (surface->bitmap) { SelectObject (surface->win32.dc, surface->saved_dc_bitmap); DeleteObject (surface->bitmap); DeleteDC (surface->win32.dc); } free (surface); return _cairo_surface_create_in_error (status); }