offscreen: rename _new_to_texture to _new_with_texture

This renames cogl_offscreen_new_to_texture to
cogl_offscreen_new_with_texture. The intention is to then cherry-pick
this back to the cogl-1.16 branch so we can maintain a parallel
cogl_offscreen_new_to_texture() function which keeps the synchronous
allocation semantics that some clutter applications are currently
relying on.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit ecc6d2f64481626992b2fe6cdfa7b999270b28f5)

Note: Since we can't break the 1.x api on this branch this keeps a
thin shim around cogl_offscreen_new_with_texture to implement
cogl_offscreen_new_to_texture with its synchronous allocation
semantics.
This commit is contained in:
Robert Bragg 2013-08-16 22:43:19 +01:00
parent 64aa6092ce
commit 1317a25a91
20 changed files with 85 additions and 38 deletions

View File

@ -51,7 +51,7 @@ _cogl_blit_texture_render_begin (CoglBlitData *data)
unsigned int dst_width, dst_height; unsigned int dst_width, dst_height;
CoglError *ignore_error = NULL; CoglError *ignore_error = NULL;
offscreen = _cogl_offscreen_new_to_texture_full offscreen = _cogl_offscreen_new_with_texture_full
(data->dst_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */); (data->dst_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */);
fb = COGL_FRAMEBUFFER (offscreen); fb = COGL_FRAMEBUFFER (offscreen);
@ -156,7 +156,7 @@ _cogl_blit_framebuffer_begin (CoglBlitData *data)
!(ctx->private_feature_flags & COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT)) !(ctx->private_feature_flags & COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT))
return FALSE; return FALSE;
dst_offscreen = _cogl_offscreen_new_to_texture_full dst_offscreen = _cogl_offscreen_new_with_texture_full
(data->dst_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */); (data->dst_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */);
dst_fb = COGL_FRAMEBUFFER (dst_offscreen); dst_fb = COGL_FRAMEBUFFER (dst_offscreen);
@ -166,7 +166,7 @@ _cogl_blit_framebuffer_begin (CoglBlitData *data)
goto error; goto error;
} }
src_offscreen= _cogl_offscreen_new_to_texture_full src_offscreen= _cogl_offscreen_new_with_texture_full
(data->src_tex, (data->src_tex,
COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL,
0 /* level */); 0 /* level */);
@ -227,7 +227,7 @@ _cogl_blit_copy_tex_sub_image_begin (CoglBlitData *data)
if (!cogl_is_texture_2d (data->dst_tex)) if (!cogl_is_texture_2d (data->dst_tex))
return FALSE; return FALSE;
offscreen = _cogl_offscreen_new_to_texture_full offscreen = _cogl_offscreen_new_with_texture_full
(data->src_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */); (data->src_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */);
fb = COGL_FRAMEBUFFER (offscreen); fb = COGL_FRAMEBUFFER (offscreen);

View File

@ -56,7 +56,7 @@ typedef struct
CoglBool depth_texture_enabled; CoglBool depth_texture_enabled;
} CoglFramebufferConfig; } CoglFramebufferConfig;
/* Flags to pass to _cogl_offscreen_new_to_texture_full */ /* Flags to pass to _cogl_offscreen_new_with_texture_full */
typedef enum typedef enum
{ {
COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL = 1 COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL = 1
@ -209,7 +209,7 @@ struct _CoglOffscreen
CoglOffscreenAllocateFlags allocation_flags; CoglOffscreenAllocateFlags allocation_flags;
/* FIXME: _cogl_offscreen_new_to_texture_full should be made to use /* FIXME: _cogl_offscreen_new_with_texture_full should be made to use
* fb->config to configure if we want a depth or stencil buffer so * fb->config to configure if we want a depth or stencil buffer so
* we can get rid of these flags */ * we can get rid of these flags */
CoglOffscreenFlags create_flags; CoglOffscreenFlags create_flags;
@ -302,7 +302,7 @@ void
_cogl_free_framebuffer_stack (GSList *stack); _cogl_free_framebuffer_stack (GSList *stack);
/* /*
* _cogl_offscreen_new_to_texture_full: * _cogl_offscreen_new_with_texture_full:
* @texture: A #CoglTexture pointer * @texture: A #CoglTexture pointer
* @create_flags: Flags specifying how to create the FBO * @create_flags: Flags specifying how to create the FBO
* @level: The mipmap level within the texture to target * @level: The mipmap level within the texture to target
@ -315,9 +315,9 @@ _cogl_free_framebuffer_stack (GSList *stack);
* Return value: the new CoglOffscreen object. * Return value: the new CoglOffscreen object.
*/ */
CoglOffscreen * CoglOffscreen *
_cogl_offscreen_new_to_texture_full (CoglTexture *texture, _cogl_offscreen_new_with_texture_full (CoglTexture *texture,
CoglOffscreenFlags create_flags, CoglOffscreenFlags create_flags,
int level); int level);
/* /*
* _cogl_push_framebuffers: * _cogl_push_framebuffers:

View File

@ -607,9 +607,9 @@ _cogl_framebuffer_flush_dependency_journals (CoglFramebuffer *framebuffer)
} }
CoglOffscreen * CoglOffscreen *
_cogl_offscreen_new_to_texture_full (CoglTexture *texture, _cogl_offscreen_new_with_texture_full (CoglTexture *texture,
CoglOffscreenFlags create_flags, CoglOffscreenFlags create_flags,
int level) int level)
{ {
CoglContext *ctx = texture->context; CoglContext *ctx = texture->context;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
@ -617,7 +617,6 @@ _cogl_offscreen_new_to_texture_full (CoglTexture *texture,
int level_width; int level_width;
int level_height; int level_height;
CoglOffscreen *ret; CoglOffscreen *ret;
CoglError *error = NULL;
_COGL_RETURN_VAL_IF_FAIL (cogl_is_texture (texture), NULL); _COGL_RETURN_VAL_IF_FAIL (cogl_is_texture (texture), NULL);
_COGL_RETURN_VAL_IF_FAIL (level < _cogl_texture_get_n_levels (texture), _COGL_RETURN_VAL_IF_FAIL (level < _cogl_texture_get_n_levels (texture),
@ -649,9 +648,19 @@ _cogl_offscreen_new_to_texture_full (CoglTexture *texture,
_cogl_texture_associate_framebuffer (texture, fb); _cogl_texture_associate_framebuffer (texture, fb);
if (!cogl_framebuffer_allocate (ret, &error)) return ret;
}
/* XXX: deprecated api */
CoglOffscreen *
cogl_offscreen_new_to_texture (CoglTexture *texture)
{
CoglOffscreen *ret = _cogl_offscreen_new_with_texture_full (texture, 0, 0);
CoglError *error = NULL;
if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (ret), &error))
{ {
cogl_object_unref (offscreen); cogl_object_unref (ret);
cogl_error_free (error); cogl_error_free (error);
ret = NULL; ret = NULL;
} }
@ -660,9 +669,9 @@ _cogl_offscreen_new_to_texture_full (CoglTexture *texture,
} }
CoglOffscreen * CoglOffscreen *
cogl_offscreen_new_to_texture (CoglTexture *texture) cogl_offscreen_new_with_texture (CoglTexture *texture)
{ {
return _cogl_offscreen_new_to_texture_full (texture, 0, 0); return _cogl_offscreen_new_with_texture_full (texture, 0, 0);
} }
static void static void

View File

@ -70,7 +70,7 @@ COGL_BEGIN_DECLS
* *
* If you want to create a new framebuffer then you should start by * If you want to create a new framebuffer then you should start by
* looking at the #CoglOnscreen and #CoglOffscreen constructor * looking at the #CoglOnscreen and #CoglOffscreen constructor
* functions, such as cogl_offscreen_new_to_texture() or * functions, such as cogl_offscreen_new_with_texture() or
* cogl_onscreen_new(). The #CoglFramebuffer interface deals with * cogl_onscreen_new(). The #CoglFramebuffer interface deals with
* all aspects that are common between those two types of framebuffer. * all aspects that are common between those two types of framebuffer.
* *
@ -795,7 +795,7 @@ cogl_framebuffer_set_color_mask (CoglFramebuffer *framebuffer,
* *
* Queries the common #CoglPixelFormat of all color buffers attached * Queries the common #CoglPixelFormat of all color buffers attached
* to this framebuffer. For an offscreen framebuffer created with * to this framebuffer. For an offscreen framebuffer created with
* cogl_offscreen_new_to_texture() this will correspond to the format * cogl_offscreen_new_with_texture() this will correspond to the format
* of the texture. * of the texture.
* *
* Since: 1.8 * Since: 1.8

View File

@ -330,7 +330,7 @@ copy_flipped_texture (CoglGLES2Context *gles2_ctx,
CoglPipeline *pipeline = cogl_pipeline_new (ctx); CoglPipeline *pipeline = cogl_pipeline_new (ctx);
const CoglOffscreenFlags flags = COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL; const CoglOffscreenFlags flags = COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL;
CoglOffscreen *offscreen = CoglOffscreen *offscreen =
_cogl_offscreen_new_to_texture_full (COGL_TEXTURE (dst_texture), _cogl_offscreen_new_with_texture_full (COGL_TEXTURE (dst_texture),
flags, level); flags, level);
int src_width = cogl_texture_get_width (src_texture); int src_width = cogl_texture_get_width (src_texture);
int src_height = cogl_texture_get_height (src_texture); int src_height = cogl_texture_get_height (src_texture);

View File

@ -47,6 +47,41 @@ typedef struct _CoglOffscreen CoglOffscreen;
/* Offscreen api */ /* Offscreen api */
/**
* cogl_offscreen_new_with_texture:
* @texture: A #CoglTexture pointer
*
* This creates an offscreen framebuffer object using the given
* @texture as the primary color buffer. It doesn't just initialize
* the contents of the offscreen buffer with the @texture; they are
* tightly bound so that drawing to the offscreen buffer effectively
* updates the contents of the given texture. You don't need to
* destroy the offscreen buffer before you can use the @texture again.
*
* <note>This api only works with low-level #CoglTexture types such as
* #CoglTexture2D, #CoglTexture3D and #CoglTextureRectangle, and not
* with meta-texture types such as #CoglTexture2DSliced.</note>
*
* The storage for the framebuffer is actually allocated lazily
* so this function will never return %NULL to indicate a runtime
* error. This means it is still possible to configure the framebuffer
* before it is really allocated.
*
* Simple applications without full error handling can simply rely on
* Cogl to lazily allocate the storage of framebuffers but you should
* be aware that if Cogl encounters an error (such as running out of
* GPU memory) then your application will simply abort with an error
* message. If you need to be able to catch such exceptions at runtime
* then you can explicitly allocate your framebuffer when you have
* finished configuring it by calling cogl_framebuffer_allocate() and
* passing in a #CoglError argument to catch any exceptions.
*
* Return value: (transfer full): a newly instantiated #CoglOffscreen
* framebuffer.
*/
CoglOffscreen *
cogl_offscreen_new_with_texture (CoglTexture *texture);
/** /**
* cogl_offscreen_new_to_texture: * cogl_offscreen_new_to_texture:
* @texture: A #CoglTexture pointer * @texture: A #CoglTexture pointer
@ -65,9 +100,11 @@ typedef struct _CoglOffscreen CoglOffscreen;
* Return value: (transfer full): a newly instantiated #CoglOffscreen * Return value: (transfer full): a newly instantiated #CoglOffscreen
* framebuffer or %NULL if it wasn't possible to create the * framebuffer or %NULL if it wasn't possible to create the
* buffer. * buffer.
* Deprecated: 1.16: Use cogl_offscreen_new_with_texture instead.
*/ */
CoglOffscreen * CoglOffscreen *
cogl_offscreen_new_to_texture (CoglTexture *texture); cogl_offscreen_new_to_texture (CoglTexture *texture)
COGL_DEPRECATED_IN_1_16_FOR (cogl_offscreen_new_with_texture);
/** /**
* cogl_is_offscreen: * cogl_is_offscreen:

View File

@ -854,7 +854,7 @@ get_texture_bits_via_offscreen (CoglTexture *texture,
if (!cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN)) if (!cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
return FALSE; return FALSE;
offscreen = _cogl_offscreen_new_to_texture_full offscreen = _cogl_offscreen_new_with_texture_full
(texture, (texture,
COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL,
0); 0);

View File

@ -513,7 +513,7 @@ cogl_object_ref
cogl_object_set_user_data cogl_object_set_user_data
cogl_object_unref cogl_object_unref
cogl_offscreen_new_to_texture cogl_offscreen_new_with_texture
cogl_onscreen_add_frame_callback cogl_onscreen_add_frame_callback
cogl_onscreen_add_resize_handler cogl_onscreen_add_resize_handler

View File

@ -650,7 +650,7 @@ CoglOffscreen
cogl_is_offscreen cogl_is_offscreen
<SUBSECTION> <SUBSECTION>
cogl_offscreen_new_to_texture cogl_offscreen_new_with_texture
</SECTION> </SECTION>
<SECTION> <SECTION>

View File

@ -267,6 +267,7 @@ cogl_program_set_uniform_matrix
<SECTION> <SECTION>
<FILE>cogl-offscreen</FILE> <FILE>cogl-offscreen</FILE>
<TITLE>Offscreen Buffers</TITLE> <TITLE>Offscreen Buffers</TITLE>
cogl_offscreen_new_with_texture
cogl_offscreen_new_to_texture cogl_offscreen_new_to_texture
cogl_is_offscreen cogl_is_offscreen
cogl_set_framebuffer cogl_set_framebuffer

View File

@ -100,7 +100,7 @@ main (int argc, char **argv)
OFFSCREEN_WIDTH, OFFSCREEN_WIDTH,
OFFSCREEN_HEIGHT, OFFSCREEN_HEIGHT,
COGL_PIXEL_FORMAT_ANY)); COGL_PIXEL_FORMAT_ANY));
data.offscreen = cogl_offscreen_new_to_texture (data.offscreen_texture); data.offscreen = cogl_offscreen_new_with_texture (data.offscreen_texture);
data.gles2_ctx = cogl_gles2_context_new (data.ctx, &error); data.gles2_ctx = cogl_gles2_context_new (data.ctx, &error);
if (!data.gles2_ctx) { if (!data.gles2_ctx) {

View File

@ -65,7 +65,7 @@ main (int argc, char **argv)
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
320, 480, 320, 480,
COGL_PIXEL_FORMAT_ANY)); COGL_PIXEL_FORMAT_ANY));
offscreen = cogl_offscreen_new_to_texture (tex); offscreen = cogl_offscreen_new_with_texture (tex);
offscreen_fb = COGL_FRAMEBUFFER (offscreen); offscreen_fb = COGL_FRAMEBUFFER (offscreen);
cogl_framebuffer_set_samples_per_pixel (offscreen_fb, 4); cogl_framebuffer_set_samples_per_pixel (offscreen_fb, 4);
if (!cogl_framebuffer_allocate (offscreen_fb, &error)) if (!cogl_framebuffer_allocate (offscreen_fb, &error))

View File

@ -179,7 +179,7 @@ test_utils_init (TestFlags requirement_flags,
CoglTexture2D *tex = cogl_texture_2d_new_with_size (test_ctx, CoglTexture2D *tex = cogl_texture_2d_new_with_size (test_ctx,
FB_WIDTH, FB_HEIGHT, FB_WIDTH, FB_HEIGHT,
COGL_PIXEL_FORMAT_ANY); COGL_PIXEL_FORMAT_ANY);
offscreen = cogl_offscreen_new_to_texture (COGL_TEXTURE (tex)); offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex));
test_fb = COGL_FRAMEBUFFER (offscreen); test_fb = COGL_FRAMEBUFFER (offscreen);
} }

View File

@ -298,7 +298,7 @@ test_backface_culling (void)
TEST_UTILS_TEXTURE_NO_SLICING, TEST_UTILS_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_ANY); /* internal COGL_PIXEL_FORMAT_ANY); /* internal
format */ format */
state.offscreen = COGL_FRAMEBUFFER (cogl_offscreen_new_to_texture (tex)); state.offscreen = COGL_FRAMEBUFFER (cogl_offscreen_new_with_texture (tex));
state.offscreen_tex = tex; state.offscreen_tex = tex;
paint (&state); paint (&state);

View File

@ -87,7 +87,7 @@ test_color_mask (void)
state.fbo[i] = COGL_FRAMEBUFFER ( state.fbo[i] = COGL_FRAMEBUFFER (
cogl_offscreen_new_to_texture (state.tex[i])); cogl_offscreen_new_with_texture (state.tex[i]));
/* Clear the texture color bits */ /* Clear the texture color bits */
cogl_framebuffer_clear4f (state.fbo[i], cogl_framebuffer_clear4f (state.fbo[i],

View File

@ -10,14 +10,14 @@ test_framebuffer_get_bits (void)
16, 16, /* width/height */ 16, 16, /* width/height */
COGL_PIXEL_FORMAT_A_8); COGL_PIXEL_FORMAT_A_8);
CoglOffscreen *offscreen_a = CoglOffscreen *offscreen_a =
cogl_offscreen_new_to_texture (COGL_TEXTURE (tex_a)); cogl_offscreen_new_with_texture (COGL_TEXTURE (tex_a));
CoglFramebuffer *fb_a = COGL_FRAMEBUFFER (offscreen_a); CoglFramebuffer *fb_a = COGL_FRAMEBUFFER (offscreen_a);
CoglTexture2D *tex_rgba = CoglTexture2D *tex_rgba =
cogl_texture_2d_new_with_size (test_ctx, cogl_texture_2d_new_with_size (test_ctx,
16, 16, /* width/height */ 16, 16, /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888); COGL_PIXEL_FORMAT_RGBA_8888);
CoglOffscreen *offscreen_rgba = CoglOffscreen *offscreen_rgba =
cogl_offscreen_new_to_texture (COGL_TEXTURE (tex_rgba)); cogl_offscreen_new_with_texture (COGL_TEXTURE (tex_rgba));
CoglFramebuffer *fb_rgba = COGL_FRAMEBUFFER (offscreen_rgba); CoglFramebuffer *fb_rgba = COGL_FRAMEBUFFER (offscreen_rgba);
cogl_framebuffer_allocate (fb_a, NULL); cogl_framebuffer_allocate (fb_a, NULL);

View File

@ -28,7 +28,7 @@ test_push_pop_single_context (void)
cogl_framebuffer_get_width (test_fb), cogl_framebuffer_get_width (test_fb),
cogl_framebuffer_get_height (test_fb), cogl_framebuffer_get_height (test_fb),
COGL_PIXEL_FORMAT_ANY)); COGL_PIXEL_FORMAT_ANY));
offscreen = cogl_offscreen_new_to_texture (offscreen_texture); offscreen = cogl_offscreen_new_with_texture (offscreen_texture);
pipeline = cogl_pipeline_new (test_ctx); pipeline = cogl_pipeline_new (test_ctx);
cogl_pipeline_set_layer_texture (pipeline, 0, offscreen_texture); cogl_pipeline_set_layer_texture (pipeline, 0, offscreen_texture);
@ -152,7 +152,7 @@ create_gles2_context (CoglTexture **offscreen_texture,
cogl_framebuffer_get_width (test_fb), cogl_framebuffer_get_width (test_fb),
cogl_framebuffer_get_height (test_fb), cogl_framebuffer_get_height (test_fb),
COGL_PIXEL_FORMAT_ANY)); COGL_PIXEL_FORMAT_ANY));
*offscreen = cogl_offscreen_new_to_texture (*offscreen_texture); *offscreen = cogl_offscreen_new_with_texture (*offscreen_texture);
*pipeline = cogl_pipeline_new (test_ctx); *pipeline = cogl_pipeline_new (test_ctx);
cogl_pipeline_set_layer_texture (*pipeline, 0, *offscreen_texture); cogl_pipeline_set_layer_texture (*pipeline, 0, *offscreen_texture);

View File

@ -50,7 +50,7 @@ test_paint (TestState *state)
COGL_PIXEL_FORMAT_RGBA_8888_PRE); COGL_PIXEL_FORMAT_RGBA_8888_PRE);
tex = COGL_TEXTURE (tex_2d); tex = COGL_TEXTURE (tex_2d);
offscreen = cogl_offscreen_new_to_texture (tex); offscreen = cogl_offscreen_new_with_texture (tex);
/* Set a scale and translate transform on the window framebuffer /* Set a scale and translate transform on the window framebuffer
* before switching to the offscreen framebuffer so we can verify it * before switching to the offscreen framebuffer so we can verify it
@ -131,7 +131,7 @@ test_flush (TestState *state)
COGL_PIXEL_FORMAT_RGBA_8888_PRE); COGL_PIXEL_FORMAT_RGBA_8888_PRE);
tex = COGL_TEXTURE (tex_2d); tex = COGL_TEXTURE (tex_2d);
offscreen = cogl_offscreen_new_to_texture (tex); offscreen = cogl_offscreen_new_with_texture (tex);
cogl_push_framebuffer (COGL_FRAMEBUFFER (offscreen)); cogl_push_framebuffer (COGL_FRAMEBUFFER (offscreen));

View File

@ -51,7 +51,7 @@ on_paint (ClutterActor *actor, void *state)
FRAMEBUFFER_WIDTH * 4, /* rowstride */ FRAMEBUFFER_WIDTH * 4, /* rowstride */
data); data);
g_free (data); g_free (data);
offscreen = cogl_offscreen_new_to_texture (tex); offscreen = cogl_offscreen_new_with_texture (tex);
cogl_push_framebuffer (offscreen); cogl_push_framebuffer (offscreen);

View File

@ -217,7 +217,7 @@ on_paint (ClutterActor *actor, void *state)
FRAMEBUFFER_WIDTH * 4, /* rowstride */ FRAMEBUFFER_WIDTH * 4, /* rowstride */
data); data);
g_free (data); g_free (data);
offscreen = cogl_offscreen_new_to_texture (tex); offscreen = cogl_offscreen_new_with_texture (tex);
cogl_push_framebuffer (offscreen); cogl_push_framebuffer (offscreen);