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); } }
void cairo_perf_set_thread_aware (cairo_t *cr, cairo_bool_t thread_aware) { #if CAIRO_HAS_GL_SURFACE || CAIRO_HAS_GLESV2_SURFACE cairo_device_t *device = cairo_surface_get_device (cairo_get_target (cr)); if (cairo_device_get_type (device) == CAIRO_DEVICE_TYPE_GL) cairo_gl_device_set_thread_aware (device, thread_aware); #endif }
static void cairo_evasgl_drawing(appdata_s *ad) { /* Window */ elm_config_accel_preference_set("opengl"); ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE); elm_win_autodel_set(ad->win, EINA_TRUE); if (elm_win_wm_rotation_supported_get(ad->win)) { int rots[4] = { 0, 90, 180, 270 }; elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4); } evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL); eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad); evas_object_event_callback_add(ad->win, EVAS_CALLBACK_RESIZE, win_resize_cb, ad); evas_object_show(ad->win); /* Image */ ad->img = evas_object_image_filled_add(evas_object_evas_get(ad->win)); evas_object_show(ad->img); evas_object_geometry_get(ad->win, NULL, NULL, &ad->width, &ad->height); /* Init EVASGL */ Evas_Native_Surface ns; ad->evas_gl = evas_gl_new(evas_object_evas_get(ad->img)); ad->evas_gl_config = evas_gl_config_new(); ad->evas_gl_config->color_format = EVAS_GL_RGBA_8888; ad->evas_gl_surface = evas_gl_surface_create(ad->evas_gl, ad->evas_gl_config, ad->width, ad->height); ad->evas_gl_context = evas_gl_context_create(ad->evas_gl, NULL); 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_get_callback_set(ad->img, cairo_drawing_rt, ad); /* cairo & cairo device create with evasgl */ setenv("CAIRO_GL_COMPOSITOR", "msaa", 1); 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); }