GraphicsContext3DPrivate::GraphicsContext3DPrivate(GraphicsContext3D* context, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle) : m_context(context) , m_hostWindow(hostWindow) , m_evasGL(0) , m_evasGLContext(0) , m_evasGLSurface(0) , m_glContext(0) , m_glSurface(0) , m_api(0) , m_renderStyle(renderStyle) { if (renderStyle == GraphicsContext3D::RenderToCurrentGLContext) return; if (m_hostWindow && m_hostWindow->platformPageClient()) { // FIXME: Implement this code path for WebKit1. // Get Evas object from platformPageClient and set EvasGL related members. return; } // For WebKit2, we need to create a dummy ecoreEvas object for the WebProcess in order to use EvasGL APIs. #ifdef HAVE_ECORE_X ecore_evas_init(); m_ecoreEvas = adoptPtr(ecore_evas_gl_x11_new(0, 0, 0, 0, 1, 1)); if (!m_ecoreEvas) return; #else return; #endif Evas* evas = ecore_evas_get(m_ecoreEvas.get()); if (!evas) return; // Create a new Evas_GL object for gl rendering on efl. m_evasGL = evas_gl_new(evas); if (!m_evasGL) return; // Get the API for rendering using OpenGL. // This returns a structure that contains all the OpenGL functions we can use to render in Evas m_api = evas_gl_api_get(m_evasGL); if (!m_api) return; // Create a context m_evasGLContext = evas_gl_context_create(m_evasGL, 0); if (!m_evasGLContext) return; // Create a surface if (!createSurface(0, renderStyle == GraphicsContext3D::RenderDirectlyToHostWindow)) return; makeContextCurrent(); }
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); }
bool GraphicsContext3DPrivate::initialize(GraphicsContext3D::Attributes attributes, HostWindow* hostWindow, bool renderDirectlyToHostWindow) { PageClientEfl* pageClient = static_cast<PageClientEfl*>(hostWindow->platformPageClient()); Evas* evas = evas_object_evas_get(pageClient->view()); // Create a new Evas_GL object for gl rendering on efl. m_evasGL = evas_gl_new(evas); if (!m_evasGL) return false; // Get the API for rendering using OpenGL. // This returns a structure that contains all the OpenGL functions we can use to render in Evas m_api = evas_gl_api_get(m_evasGL); if (!m_api) return false; Evas_GL_Context* shareContext = 0; #if USE(ACCELERATED_COMPOSITING) // GC3D with RenderOffscreen style for WebGL has to be shared with AC's context when AC is enabled. if (!renderDirectlyToHostWindow) { GraphicsContext3D* context = pageClient->acceleratedCompositingContext(); if (context) shareContext = static_cast<Evas_GL_Context*>(context->platformGraphicsContext3D()); } #endif // Create a context m_context = evas_gl_context_create(m_evasGL, shareContext); if (!m_context) return false; // Create a surface if (!createSurface(pageClient, renderDirectlyToHostWindow)) return false; return makeContextCurrent(); }