summaryrefslogtreecommitdiff
path: root/boilerplate
diff options
context:
space:
mode:
authorGeorge Matsumura <gmmatsumura01@bvsd.org>2020-07-19 15:22:24 -0600
committerGeorge Matsumura <gmmatsumura01@bvsd.org>2020-08-25 02:30:58 -0600
commit916408481f3123bc6fc0800c90d910716046ec30 (patch)
treef37842c73c421c7430e668e98c27c06fbccbf6d2 /boilerplate
parent9248ba1419b4164207afb982b4d3f9e43ddffe42 (diff)
downloadcairo-916408481f3123bc6fc0800c90d910716046ec30.tar.gz
cogl: Move framebuffer creation functionality out of boilerplate
In order to be more consistent with backends such as gl, support for creating a surface from content, width, and height parameters was moved into the backend itself. The option to pass cairo-cogl a framebuffer to create a texture from still exists, just now it is not the only option. Signed-off-by: George Matsumura <gmmatsumura01@bvsd.org>
Diffstat (limited to 'boilerplate')
-rw-r--r--boilerplate/cairo-boilerplate-cogl.c63
1 files changed, 18 insertions, 45 deletions
diff --git a/boilerplate/cairo-boilerplate-cogl.c b/boilerplate/cairo-boilerplate-cogl.c
index 364654feb..ae42578fd 100644
--- a/boilerplate/cairo-boilerplate-cogl.c
+++ b/boilerplate/cairo-boilerplate-cogl.c
@@ -31,27 +31,23 @@
*/
#include "cairo-boilerplate-private.h"
+#include "cairo-malloc-private.h"
#include <cairo-cogl.h>
#include <cogl/cogl2-experimental.h>
typedef struct _cogl_closure {
cairo_device_t *device;
- CoglFramebuffer *fb;
cairo_surface_t *surface;
} cogl_closure_t;
static const cairo_user_data_key_t cogl_closure_key;
-static CoglContext *context = NULL;
-
static void
_cairo_boilerplate_cogl_cleanup (void *abstract_closure)
{
cogl_closure_t *closure = abstract_closure;
- cogl_object_unref (closure->fb);
-
cairo_device_finish (closure->device);
cairo_device_destroy (closure->device);
@@ -68,9 +64,8 @@ _cairo_boilerplate_cogl_create_offscreen_color_surface (const char *name,
cairo_boilerplate_mode_t mode,
void **abstract_closure)
{
+ CoglContext *context;
cairo_device_t *device;
- CoglTexture *tex;
- CoglFramebuffer *fb;
cogl_closure_t *closure;
cairo_status_t status;
@@ -79,25 +74,17 @@ _cairo_boilerplate_cogl_create_offscreen_color_surface (const char *name,
if (height < 1)
height = 1;
- if (!context)
- context = cogl_context_new (NULL, NULL);
+ context = cogl_context_new (NULL, NULL);
device = cairo_cogl_device_create (context);
- tex = cogl_texture_2d_new_with_size (context, width, height);
- cogl_texture_set_components (tex, COGL_TEXTURE_COMPONENTS_RGBA);
- fb = cogl_offscreen_new_with_texture (tex);
-
- cogl_framebuffer_allocate (fb, NULL);
- cogl_framebuffer_orthographic (fb, 0, 0,
- cogl_framebuffer_get_width (fb),
- cogl_framebuffer_get_height (fb),
- -1, 100);
- closure = malloc (sizeof (cogl_closure_t));
+ closure = _cairo_malloc (sizeof (cogl_closure_t));
*abstract_closure = closure;
closure->device = device;
- closure->fb = fb;
- closure->surface = cairo_cogl_surface_create (device, fb);
+ closure->surface = cairo_cogl_offscreen_surface_create (device,
+ content,
+ width,
+ height);
status = cairo_surface_set_user_data (closure->surface,
&cogl_closure_key, closure, NULL);
@@ -118,8 +105,8 @@ _cairo_boilerplate_cogl_create_onscreen_color_surface (const char *name,
cairo_boilerplate_mode_t mode,
void **abstract_closure)
{
+ CoglContext *context;
cairo_device_t *device;
- CoglFramebuffer *fb;
cogl_closure_t *closure;
cairo_status_t status;
@@ -128,24 +115,17 @@ _cairo_boilerplate_cogl_create_onscreen_color_surface (const char *name,
if (height < 1)
height = 1;
- if (!context)
- context = cogl_context_new (NULL, NULL);
+ context = cogl_context_new (NULL, NULL);
device = cairo_cogl_device_create (context);
- fb = cogl_onscreen_new (context, width, height);
-
- cogl_onscreen_show (fb);
-
- cogl_framebuffer_orthographic (fb, 0, 0,
- cogl_framebuffer_get_width (fb),
- cogl_framebuffer_get_height (fb),
- -1, 100);
- closure = malloc (sizeof (cogl_closure_t));
+ closure = _cairo_malloc (sizeof (cogl_closure_t));
*abstract_closure = closure;
closure->device = device;
- closure->fb = fb;
- closure->surface = cairo_cogl_surface_create (device, fb);
+ closure->surface = cairo_cogl_onscreen_surface_create (device,
+ content,
+ width,
+ height);
status = cairo_surface_set_user_data (closure->surface,
&cogl_closure_key, closure, NULL);
@@ -158,22 +138,15 @@ _cairo_boilerplate_cogl_create_onscreen_color_surface (const char *name,
static cairo_status_t
_cairo_boilerplate_cogl_finish (cairo_surface_t *surface)
-{
- cogl_closure_t *closure = cairo_surface_get_user_data (surface, &cogl_closure_key);
-
- cairo_cogl_surface_end_frame (surface);
-
- if (cogl_is_onscreen (closure->fb))
- cogl_onscreen_swap_buffers (closure->fb);
-
- return CAIRO_STATUS_SUCCESS;
+{
+ return cairo_cogl_surface_end_frame (surface);
}
static void
_cairo_boilerplate_cogl_synchronize (void *abstract_closure)
{
cogl_closure_t *closure = abstract_closure;
- cogl_framebuffer_finish (closure->fb);
+ cairo_cogl_surface_synchronize (closure->surface);
}
static const cairo_boilerplate_target_t targets[] = {