From 0d0286d59ecf618d5fe84e8bb20f6f5bda9d8c5a Mon Sep 17 00:00:00 2001 From: Niels De Graef Date: Wed, 20 Feb 2019 14:53:01 +0100 Subject: [PATCH] cogl: Remove COGL_INVALID_HANDLE Just use `NULL`, which is the normal C convention https://gitlab.gnome.org/GNOME/mutter/merge_requests/451 --- clutter/clutter/clutter-backend.c | 4 +-- clutter/clutter/clutter-offscreen-effect.c | 4 +-- clutter/clutter/clutter-shader-effect.c | 30 +++++++++---------- .../deprecated/clutter-cairo-texture.c | 2 +- cogl/cogl/cogl-pipeline-state.c | 8 ++--- cogl/cogl/cogl-pipeline-state.h | 2 +- cogl/cogl/cogl-pipeline.c | 8 ++--- cogl/cogl/cogl-types.h | 8 ----- cogl/cogl/deprecated/cogl-material-compat.h | 4 +-- cogl/cogl/deprecated/cogl-program.c | 7 ++--- cogl/cogl/deprecated/cogl-shader.c | 4 +-- cogl/cogl/deprecated/cogl-shader.h | 4 +-- cogl/cogl/deprecated/cogl-vertex-buffer.c | 12 ++++---- cogl/tests/conform/test-just-vertex-shader.c | 4 +-- .../clutter/interactive/test-cogl-offscreen.c | 4 +-- .../interactive/test-cogl-shader-glsl.c | 2 +- .../interactive/test-cogl-tex-polygon.c | 4 +-- 17 files changed, 51 insertions(+), 60 deletions(-) diff --git a/clutter/clutter/clutter-backend.c b/clutter/clutter/clutter-backend.c index 4652bc7b8..4d3adc953 100644 --- a/clutter/clutter/clutter-backend.c +++ b/clutter/clutter/clutter-backend.c @@ -627,7 +627,7 @@ clutter_backend_init (ClutterBackend *self) self->units_per_em = -1.0; self->units_serial = 1; - self->dummy_onscreen = COGL_INVALID_HANDLE; + self->dummy_onscreen = NULL; } void @@ -1012,7 +1012,7 @@ _clutter_backend_get_keymap_direction (ClutterBackend *backend) void _clutter_backend_reset_cogl_framebuffer (ClutterBackend *backend) { - if (backend->dummy_onscreen == COGL_INVALID_HANDLE) + if (backend->dummy_onscreen == NULL) { GError *internal_error = NULL; diff --git a/clutter/clutter/clutter-offscreen-effect.c b/clutter/clutter/clutter-offscreen-effect.c index 54f5fbb7e..9e3756765 100644 --- a/clutter/clutter/clutter-offscreen-effect.c +++ b/clutter/clutter/clutter-offscreen-effect.c @@ -537,7 +537,7 @@ clutter_offscreen_effect_init (ClutterOffscreenEffect *self) * used instead of clutter_offscreen_effect_get_target() when the * effect subclass wants to paint using its own material. * - * Return value: (transfer none): a #CoglHandle or %COGL_INVALID_HANDLE. The + * Return value: (transfer none): a #CoglHandle or %NULL. The * returned texture is owned by Clutter and it should not be * modified or freed * @@ -602,7 +602,7 @@ clutter_offscreen_effect_paint_target (ClutterOffscreenEffect *effect) * Calls the create_texture() virtual function of the @effect * * Return value: (transfer full): a handle to a Cogl texture, or - * %COGL_INVALID_HANDLE. The returned handle has its reference + * %NULL. The returned handle has its reference * count increased. * * Since: 1.4 diff --git a/clutter/clutter/clutter-shader-effect.c b/clutter/clutter/clutter-shader-effect.c index 4a36f973d..2d98d1bb6 100644 --- a/clutter/clutter/clutter-shader-effect.c +++ b/clutter/clutter/clutter-shader-effect.c @@ -177,18 +177,18 @@ clutter_shader_effect_clear (ClutterShaderEffect *self, { ClutterShaderEffectPrivate *priv = self->priv; - if (priv->shader != COGL_INVALID_HANDLE) + if (priv->shader != NULL) { cogl_object_unref (priv->shader); - priv->shader = COGL_INVALID_HANDLE; + priv->shader = NULL; } - if (priv->program != COGL_INVALID_HANDLE) + if (priv->program != NULL) { cogl_object_unref (priv->program); - priv->program = COGL_INVALID_HANDLE; + priv->program = NULL; } if (reset_uniforms && priv->uniforms != NULL) @@ -208,7 +208,7 @@ clutter_shader_effect_update_uniforms (ClutterShaderEffect *effect) gpointer key, value; gsize size; - if (priv->program == COGL_INVALID_HANDLE) + if (priv->program == NULL) return; if (priv->uniforms == NULL) @@ -333,7 +333,7 @@ clutter_shader_effect_create_shader (ClutterShaderEffect *self) default: g_assert_not_reached (); - return COGL_INVALID_HANDLE; + return NULL; } } @@ -353,7 +353,7 @@ clutter_shader_effect_try_static_source (ClutterShaderEffect *self) CLUTTER_TYPE_SHADER_EFFECT, ClutterShaderEffectClassPrivate); - if (class_priv->shader == COGL_INVALID_HANDLE) + if (class_priv->shader == NULL) { gchar *source; @@ -389,7 +389,7 @@ clutter_shader_effect_try_static_source (ClutterShaderEffect *self) priv->shader = cogl_object_ref (class_priv->shader); - if (class_priv->program != COGL_INVALID_HANDLE) + if (class_priv->program != NULL) priv->program = cogl_object_ref (class_priv->program); } } @@ -404,13 +404,13 @@ clutter_shader_effect_paint_target (ClutterOffscreenEffect *effect) /* If the source hasn't been set then we'll try to get it from the static source instead */ - if (priv->shader == COGL_INVALID_HANDLE) + if (priv->shader == NULL) clutter_shader_effect_try_static_source (self); /* we haven't been prepared or we don't have support for * GLSL shaders in Clutter */ - if (priv->program == COGL_INVALID_HANDLE) + if (priv->program == NULL) goto out; CLUTTER_NOTE (SHADER, "Applying the shader effect of type '%s'", @@ -534,7 +534,7 @@ clutter_shader_effect_new (ClutterShaderType shader_type) * Retrieves a pointer to the shader's handle * * Return value: (transfer none): a pointer to the shader's handle, - * or %COGL_INVALID_HANDLE + * or %NULL * * Since: 1.4 */ @@ -542,7 +542,7 @@ CoglHandle clutter_shader_effect_get_shader (ClutterShaderEffect *effect) { g_return_val_if_fail (CLUTTER_IS_SHADER_EFFECT (effect), - COGL_INVALID_HANDLE); + NULL); return effect->priv->shader; } @@ -554,7 +554,7 @@ clutter_shader_effect_get_shader (ClutterShaderEffect *effect) * Retrieves a pointer to the program's handle * * Return value: (transfer none): a pointer to the program's handle, - * or %COGL_INVALID_HANDLE + * or %NULL * * Since: 1.4 */ @@ -562,7 +562,7 @@ CoglHandle clutter_shader_effect_get_program (ClutterShaderEffect *effect) { g_return_val_if_fail (CLUTTER_IS_SHADER_EFFECT (effect), - COGL_INVALID_HANDLE); + NULL); return effect->priv->program; } @@ -892,7 +892,7 @@ clutter_shader_effect_set_shader_source (ClutterShaderEffect *effect, priv = effect->priv; - if (priv->shader != COGL_INVALID_HANDLE) + if (priv->shader != NULL) return TRUE; priv->shader = clutter_shader_effect_create_shader (effect); diff --git a/clutter/clutter/deprecated/clutter-cairo-texture.c b/clutter/clutter/deprecated/clutter-cairo-texture.c index 8d67af038..f8e513728 100644 --- a/clutter/clutter/deprecated/clutter-cairo-texture.c +++ b/clutter/clutter/deprecated/clutter-cairo-texture.c @@ -294,7 +294,7 @@ clutter_cairo_texture_context_destroy (void *data) cogl_texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (cairo)); if (cairo_width == 0 || cairo_height == 0 || - cogl_texture == COGL_INVALID_HANDLE) + cogl_texture == NULL) { draw_context_destroy (ctxt); return; diff --git a/cogl/cogl/cogl-pipeline-state.c b/cogl/cogl/cogl-pipeline-state.c index 58281f97f..585710ee5 100644 --- a/cogl/cogl/cogl-pipeline-state.c +++ b/cogl/cogl/cogl-pipeline-state.c @@ -1070,7 +1070,7 @@ cogl_pipeline_get_user_program (CoglPipeline *pipeline) { CoglPipeline *authority; - g_return_val_if_fail (cogl_is_pipeline (pipeline), COGL_INVALID_HANDLE); + g_return_val_if_fail (cogl_is_pipeline (pipeline), NULL); authority = _cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_USER_SHADER); @@ -1105,7 +1105,7 @@ cogl_pipeline_set_user_program (CoglPipeline *pipeline, */ _cogl_pipeline_pre_change_notify (pipeline, state, NULL, FALSE); - if (program != COGL_INVALID_HANDLE) + if (program != NULL) _cogl_pipeline_set_progend (pipeline, COGL_PIPELINE_PROGEND_UNDEFINED); /* If we are the current authority see if we can revert to one of our @@ -1130,10 +1130,10 @@ cogl_pipeline_set_user_program (CoglPipeline *pipeline, _cogl_pipeline_prune_redundant_ancestry (pipeline); } - if (program != COGL_INVALID_HANDLE) + if (program != NULL) cogl_object_ref (program); if (authority == pipeline && - pipeline->big_state->user_program != COGL_INVALID_HANDLE) + pipeline->big_state->user_program != NULL) cogl_object_unref (pipeline->big_state->user_program); pipeline->big_state->user_program = program; diff --git a/cogl/cogl/cogl-pipeline-state.h b/cogl/cogl/cogl-pipeline-state.h index 6e45da3cf..5fe82d0f2 100644 --- a/cogl/cogl/cogl-pipeline-state.h +++ b/cogl/cogl/cogl-pipeline-state.h @@ -578,7 +578,7 @@ cogl_pipeline_get_per_vertex_point_size (CoglPipeline *pipeline); * Queries what user program has been associated with the given * @pipeline using cogl_pipeline_set_user_program(). * - * Return value: (transfer none): The current user program or %COGL_INVALID_HANDLE. + * Return value: (transfer none): The current user program or %NULL. * * Since: 2.0 * Stability: Unstable diff --git a/cogl/cogl/cogl-pipeline.c b/cogl/cogl/cogl-pipeline.c index efd7d5222..0f98641ed 100644 --- a/cogl/cogl/cogl-pipeline.c +++ b/cogl/cogl/cogl-pipeline.c @@ -182,7 +182,7 @@ _cogl_pipeline_init_default_pipeline (void) blend_state->blend_src_factor_rgb = GL_ONE; blend_state->blend_dst_factor_rgb = GL_ONE_MINUS_SRC_ALPHA; - big_state->user_program = COGL_INVALID_HANDLE; + big_state->user_program = NULL; cogl_depth_state_init (&big_state->depth_state); @@ -749,7 +749,7 @@ _cogl_pipeline_change_implies_transparency (CoglPipeline *pipeline, * * TODO: check that it isn't just a vertex shader! */ - if (_cogl_pipeline_get_user_program (pipeline) != COGL_INVALID_HANDLE) + if (_cogl_pipeline_get_user_program (pipeline) != NULL) return TRUE; } @@ -992,7 +992,7 @@ _cogl_pipeline_copy_differences (CoglPipeline *dest, big_state->user_program = cogl_object_ref (src->big_state->user_program); else - big_state->user_program = COGL_INVALID_HANDLE; + big_state->user_program = NULL; } if (differences & COGL_PIPELINE_STATE_DEPTH) @@ -2558,7 +2558,7 @@ _cogl_pipeline_apply_legacy_state (CoglPipeline *pipeline) /* A program explicitly set on the pipeline has higher precedence than * one associated with the context using cogl_program_use() */ if (ctx->current_program && - cogl_pipeline_get_user_program (pipeline) == COGL_INVALID_HANDLE) + cogl_pipeline_get_user_program (pipeline) == NULL) cogl_pipeline_set_user_program (pipeline, ctx->current_program); if (ctx->legacy_depth_test_enabled) diff --git a/cogl/cogl/cogl-types.h b/cogl/cogl/cogl-types.h index 67b07ab01..da30242cc 100644 --- a/cogl/cogl/cogl-types.h +++ b/cogl/cogl/cogl-types.h @@ -80,14 +80,6 @@ typedef struct { \ */ typedef void * CoglHandle; -/** - * COGL_INVALID_HANDLE: - * - * A COGL handle that is not valid, used for unitialized handles as well as - * error conditions. - */ -#define COGL_INVALID_HANDLE NULL - #define COGL_TYPE_HANDLE (cogl_handle_get_type ()) GType cogl_handle_get_type (void) G_GNUC_CONST; diff --git a/cogl/cogl/deprecated/cogl-material-compat.h b/cogl/cogl/deprecated/cogl-material-compat.h index 96d451d5c..b08676858 100644 --- a/cogl/cogl/deprecated/cogl-material-compat.h +++ b/cogl/cogl/deprecated/cogl-material-compat.h @@ -706,7 +706,7 @@ cogl_material_get_point_size (CoglMaterial *material); * @material using cogl_material_set_user_program(). * * Return value: (transfer none): The current user program - * or %COGL_INVALID_HANDLE. + * or %NULL. * * Since: 1.4 * Deprecated: 1.16: Use #CoglSnippet api instead instead @@ -1021,7 +1021,7 @@ cogl_material_layer_get_type (CoglMaterialLayer *layer); * Extracts a texture handle for a specific layer. * * In the future Cogl may support purely GLSL based layers; for those - * layers this function which will likely return %COGL_INVALID_HANDLE if you + * layers this function which will likely return %NULL if you * try to get the texture handle from them. Considering this scenario, you * should call cogl_material_layer_get_type() first in order check it is of * type %COGL_MATERIAL_LAYER_TYPE_TEXTURE before calling this function. diff --git a/cogl/cogl/deprecated/cogl-program.c b/cogl/cogl/deprecated/cogl-program.c index ed07af7d9..f68bc3a49 100644 --- a/cogl/cogl/deprecated/cogl-program.c +++ b/cogl/cogl/deprecated/cogl-program.c @@ -131,17 +131,16 @@ cogl_program_use (CoglHandle handle) { _COGL_GET_CONTEXT (ctx, NO_RETVAL); - g_return_if_fail (handle == COGL_INVALID_HANDLE || - cogl_is_program (handle)); + g_return_if_fail (handle == NULL || cogl_is_program (handle)); if (ctx->current_program == 0 && handle != 0) ctx->legacy_state_set++; else if (handle == 0 && ctx->current_program != 0) ctx->legacy_state_set--; - if (handle != COGL_INVALID_HANDLE) + if (handle != NULL) cogl_object_ref (handle); - if (ctx->current_program != COGL_INVALID_HANDLE) + if (ctx->current_program != NULL) cogl_object_unref (ctx->current_program); ctx->current_program = handle; } diff --git a/cogl/cogl/deprecated/cogl-shader.c b/cogl/cogl/deprecated/cogl-shader.c index c7e17e1f8..7f105f4ef 100644 --- a/cogl/cogl/deprecated/cogl-shader.c +++ b/cogl/cogl/deprecated/cogl-shader.c @@ -71,7 +71,7 @@ cogl_create_shader (CoglShaderType type) { CoglShader *shader; - _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); + _COGL_GET_CONTEXT (ctx, NULL); switch (type) { @@ -81,7 +81,7 @@ cogl_create_shader (CoglShaderType type) default: g_warning ("Unexpected shader type (0x%08lX) given to " "cogl_create_shader", (unsigned long) type); - return COGL_INVALID_HANDLE; + return NULL; } shader = g_slice_new (CoglShader); diff --git a/cogl/cogl/deprecated/cogl-shader.h b/cogl/cogl/deprecated/cogl-shader.h index 88acc181f..2b4167ee0 100644 --- a/cogl/cogl/deprecated/cogl-shader.h +++ b/cogl/cogl/deprecated/cogl-shader.h @@ -453,10 +453,10 @@ cogl_program_link (CoglHandle handle); /** * cogl_program_use: - * @handle: a #CoglHandle for a shader program or %COGL_INVALID_HANDLE. + * @handle: a #CoglHandle for a shader program or %NULL. * * Activate a specific shader program replacing that part of the GL - * rendering pipeline, if passed in %COGL_INVALID_HANDLE the default + * rendering pipeline, if passed in %NULL the default * behavior of GL is reinstated. * * This function affects the global state of the current Cogl diff --git a/cogl/cogl/deprecated/cogl-vertex-buffer.c b/cogl/cogl/deprecated/cogl-vertex-buffer.c index 709a9a101..24859a30c 100644 --- a/cogl/cogl/deprecated/cogl-vertex-buffer.c +++ b/cogl/cogl/deprecated/cogl-vertex-buffer.c @@ -138,7 +138,7 @@ cogl_vertex_buffer_new (unsigned int n_vertices) buffer->primitive = cogl_primitive_new (COGL_VERTICES_MODE_TRIANGLES, n_vertices, NULL); - /* return COGL_INVALID_HANDLE; */ + /* return NULL; */ return _cogl_vertex_buffer_handle_new (buffer); } @@ -1675,7 +1675,7 @@ cogl_vertex_buffer_indices_new (CoglIndicesType indices_type, { CoglIndices *indices; - _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); + _COGL_GET_CONTEXT (ctx, NULL); indices = cogl_indices_new (ctx, indices_type, indices_array, indices_len); return _cogl_vertex_buffer_indices_new_real (indices); @@ -1749,11 +1749,11 @@ _cogl_vertex_buffer_free (CoglVertexBuffer *buffer) CoglHandle cogl_vertex_buffer_indices_get_for_quads (unsigned int n_indices) { - _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); + _COGL_GET_CONTEXT (ctx, NULL); if (n_indices <= 256 / 4 * 6) { - if (ctx->quad_buffer_indices_byte == COGL_INVALID_HANDLE) + if (ctx->quad_buffer_indices_byte == NULL) { /* NB: cogl_get_quad_indices takes n_quads not n_indices... */ CoglIndices *indices = cogl_get_rectangle_indices (ctx, 256 / 4); @@ -1770,10 +1770,10 @@ cogl_vertex_buffer_indices_get_for_quads (unsigned int n_indices) ctx->quad_buffer_indices_len < n_indices) { cogl_object_unref (ctx->quad_buffer_indices); - ctx->quad_buffer_indices = COGL_INVALID_HANDLE; + ctx->quad_buffer_indices = NULL; } - if (ctx->quad_buffer_indices == COGL_INVALID_HANDLE) + if (ctx->quad_buffer_indices == NULL) { /* NB: cogl_get_quad_indices takes n_quads not n_indices... */ CoglIndices *indices = diff --git a/cogl/tests/conform/test-just-vertex-shader.c b/cogl/tests/conform/test-just-vertex-shader.c index 2d0c20567..da1ab1c4c 100644 --- a/cogl/tests/conform/test-just-vertex-shader.c +++ b/cogl/tests/conform/test-just-vertex-shader.c @@ -91,7 +91,7 @@ paint_legacy (TestState *state) /* Draw it again using the program. It should look exactly the same */ cogl_program_use (program); cogl_rectangle (50, 0, 100, 50); - cogl_program_use (COGL_INVALID_HANDLE); + cogl_program_use (NULL); cogl_object_unref (material); cogl_object_unref (program); @@ -163,7 +163,7 @@ paint (TestState *state) cogl_object_unref (program); cogl_rectangle (50, 0, 100, 50); - cogl_pipeline_set_user_program (pipeline, COGL_INVALID_HANDLE); + cogl_pipeline_set_user_program (pipeline, NULL); cogl_object_unref (pipeline); } diff --git a/src/tests/clutter/interactive/test-cogl-offscreen.c b/src/tests/clutter/interactive/test-cogl-offscreen.c index 116f03120..b06e6d7f3 100644 --- a/src/tests/clutter/interactive/test-cogl-offscreen.c +++ b/src/tests/clutter/interactive/test-cogl-offscreen.c @@ -256,7 +256,7 @@ test_coglbox_map (ClutterActor *actor) cogl_pop_framebuffer (); - if (priv->offscreen_id == COGL_INVALID_HANDLE) + if (priv->offscreen_id == NULL) printf ("Failed creating offscreen to texture!\n"); } @@ -281,7 +281,7 @@ test_coglbox_init (TestCoglbox *self) COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_RGB_888); - if (priv->texture_id == COGL_INVALID_HANDLE) + if (priv->texture_id == NULL) printf ("Failed creating texture with size!\n"); } diff --git a/src/tests/clutter/interactive/test-cogl-shader-glsl.c b/src/tests/clutter/interactive/test-cogl-shader-glsl.c index a269aa476..ed4cf3e92 100644 --- a/src/tests/clutter/interactive/test-cogl-shader-glsl.c +++ b/src/tests/clutter/interactive/test-cogl-shader-glsl.c @@ -320,7 +320,7 @@ test_cogl_shader_glsl_main (int argc, char *argv[]) COGL_TEXTURE_NO_ATLAS, COGL_PIXEL_FORMAT_ANY, &error); - if (redhand == COGL_INVALID_HANDLE) + if (redhand == NULL) g_error ("image load failed: %s", error->message); material = cogl_material_new (); diff --git a/src/tests/clutter/interactive/test-cogl-tex-polygon.c b/src/tests/clutter/interactive/test-cogl-tex-polygon.c index 2a4e78517..3eb5d574c 100644 --- a/src/tests/clutter/interactive/test-cogl-tex-polygon.c +++ b/src/tests/clutter/interactive/test-cogl-tex-polygon.c @@ -259,7 +259,7 @@ test_coglbox_init (TestCoglbox *self) COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_ANY, &error); - if (priv->sliced_tex == COGL_INVALID_HANDLE) + if (priv->sliced_tex == NULL) { if (error) { @@ -276,7 +276,7 @@ test_coglbox_init (TestCoglbox *self) COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_ANY, &error); - if (priv->not_sliced_tex == COGL_INVALID_HANDLE) + if (priv->not_sliced_tex == NULL) { if (error) {