From 2a8f0c2801f42186ef8b6d57218a07cdf6854108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 22 Nov 2019 12:07:59 +0100 Subject: [PATCH] cogl/tests: Port away from legacy implicit stack based API Use the new API where state (framebuffer, pipeline) is always passed as parameters, instead of using the implicit material and framebuffer stack. https://gitlab.gnome.org/GNOME/mutter/merge_requests/935 --- cogl/tests/conform/test-blend-strings.c | 59 ++++++++------- cogl/tests/conform/test-depth-test.c | 26 ++++--- cogl/tests/conform/test-just-vertex-shader.c | 15 ++-- cogl/tests/conform/test-offscreen.c | 77 ++++++++++---------- cogl/tests/conform/test-path.c | 4 +- cogl/tests/conform/test-wrap-modes.c | 13 ++-- 6 files changed, 94 insertions(+), 100 deletions(-) diff --git a/cogl/tests/conform/test-blend-strings.c b/cogl/tests/conform/test-blend-strings.c index e61ee0acf..d440a5eaf 100644 --- a/cogl/tests/conform/test-blend-strings.c +++ b/cogl/tests/conform/test-blend-strings.c @@ -63,11 +63,12 @@ test_blend_paint (TestState *state, pipeline = cogl_pipeline_new (test_ctx); cogl_pipeline_set_color4ub (pipeline, Dr, Dg, Db, Da); cogl_pipeline_set_blend (pipeline, "RGBA = ADD (SRC_COLOR, 0)", NULL); - cogl_set_source (pipeline); - cogl_rectangle (x * QUAD_WIDTH, - y * QUAD_WIDTH, - x * QUAD_WIDTH + QUAD_WIDTH, - y * QUAD_WIDTH + QUAD_WIDTH); + cogl_framebuffer_draw_rectangle (test_fb, + pipeline, + x * QUAD_WIDTH, + y * QUAD_WIDTH, + x * QUAD_WIDTH + QUAD_WIDTH, + y * QUAD_WIDTH + QUAD_WIDTH); cogl_object_unref (pipeline); /* @@ -94,11 +95,12 @@ test_blend_paint (TestState *state, cogl_color_init_from_4ub (&blend_const_color, Br, Bg, Bb, Ba); cogl_pipeline_set_blend_constant (pipeline, &blend_const_color); - cogl_set_source (pipeline); - cogl_rectangle (x * QUAD_WIDTH, - y * QUAD_WIDTH, - x * QUAD_WIDTH + QUAD_WIDTH, - y * QUAD_WIDTH + QUAD_WIDTH); + cogl_framebuffer_draw_rectangle (test_fb, + pipeline, + x * QUAD_WIDTH, + y * QUAD_WIDTH, + x * QUAD_WIDTH + QUAD_WIDTH, + y * QUAD_WIDTH + QUAD_WIDTH); cogl_object_unref (pipeline); /* See what we got... */ @@ -175,7 +177,7 @@ test_tex_combine (TestState *state, uint8_t Ca = MASK_ALPHA (combine_constant); CoglColor combine_const_color; - CoglHandle material; + CoglPipeline *pipeline; gboolean status; GError *error = NULL; int y_off; @@ -185,17 +187,17 @@ test_tex_combine (TestState *state, tex0 = make_texture (tex0_color); tex1 = make_texture (tex1_color); - material = cogl_material_new (); + pipeline = cogl_pipeline_new (test_ctx); - cogl_material_set_color4ub (material, 0x80, 0x80, 0x80, 0x80); - cogl_material_set_blend (material, "RGBA = ADD (SRC_COLOR, 0)", NULL); + cogl_pipeline_set_color4ub (pipeline, 0x80, 0x80, 0x80, 0x80); + cogl_pipeline_set_blend (pipeline, "RGBA = ADD (SRC_COLOR, 0)", NULL); - cogl_material_set_layer (material, 0, tex0); - cogl_material_set_layer_combine (material, 0, + cogl_pipeline_set_layer_texture (pipeline, 0, tex0); + cogl_pipeline_set_layer_combine (pipeline, 0, "RGBA = REPLACE (TEXTURE)", NULL); - cogl_material_set_layer (material, 1, tex1); - status = cogl_material_set_layer_combine (material, 1, + cogl_pipeline_set_layer_texture (pipeline, 1, tex1); + status = cogl_pipeline_set_layer_combine (pipeline, 1, combine_string, &error); if (!status) { @@ -206,15 +208,16 @@ test_tex_combine (TestState *state, } cogl_color_init_from_4ub (&combine_const_color, Cr, Cg, Cb, Ca); - cogl_material_set_layer_combine_constant (material, 1, &combine_const_color); + cogl_pipeline_set_layer_combine_constant (pipeline, 1, &combine_const_color); - cogl_set_source (material); - cogl_rectangle (x * QUAD_WIDTH, - y * QUAD_WIDTH, - x * QUAD_WIDTH + QUAD_WIDTH, - y * QUAD_WIDTH + QUAD_WIDTH); + cogl_framebuffer_draw_rectangle (test_fb, + pipeline, + x * QUAD_WIDTH, + y * QUAD_WIDTH, + x * QUAD_WIDTH + QUAD_WIDTH, + y * QUAD_WIDTH + QUAD_WIDTH); - cogl_object_unref (material); + cogl_object_unref (pipeline); cogl_object_unref (tex0); cogl_object_unref (tex1); @@ -297,7 +300,7 @@ paint (TestState *state) "A = MODULATE (PREVIOUS, TEXTURE)", /* tex combine */ 0xffffff20); /* expected */ - /* XXX: we are assuming test_tex_combine creates a material with + /* XXX: we are assuming test_tex_combine creates a pipeline with * a color of 0x80808080 (i.e. the "PRIMARY" color) */ test_tex_combine (state, 7, 0, /* position */ 0xffffff80, /* texture 0 color (alpha = 0.5) */ @@ -365,11 +368,7 @@ test_blend_strings (void) -1, 100); - /* XXX: we have to push/pop a framebuffer since this test currently - * uses the legacy cogl_rectangle() api. */ - cogl_push_framebuffer (test_fb); paint (&state); - cogl_pop_framebuffer (); if (cogl_test_verbose ()) g_print ("OK\n"); diff --git a/cogl/tests/conform/test-depth-test.c b/cogl/tests/conform/test-depth-test.c index 2ac29bbf0..b6ed98d9d 100644 --- a/cogl/tests/conform/test-depth-test.c +++ b/cogl/tests/conform/test-depth-test.c @@ -83,16 +83,22 @@ draw_rectangle (TestState *state, } else { - cogl_push_framebuffer (test_fb); - cogl_push_matrix (); - cogl_set_source_color4ub (Cr, Cg, Cb, Ca); - cogl_translate (0, 0, rect_state->depth); - cogl_rectangle (x * QUAD_WIDTH, - y * QUAD_WIDTH, - x * QUAD_WIDTH + QUAD_WIDTH, - y * QUAD_WIDTH + QUAD_WIDTH); - cogl_pop_matrix (); - cogl_pop_framebuffer (); + CoglPipeline *legacy_pipeline; + + legacy_pipeline = cogl_pipeline_new (test_ctx); + + cogl_framebuffer_push_matrix (test_fb); + cogl_pipeline_set_color4ub (pipeline, Cr, Cg, Cb, Ca); + cogl_framebuffer_translate (test_fb, 0, 0, rect_state->depth); + cogl_framebuffer_draw_rectangle (test_fb, + pipeline, + x * QUAD_WIDTH, + y * QUAD_WIDTH, + x * QUAD_WIDTH + QUAD_WIDTH, + y * QUAD_WIDTH + QUAD_WIDTH); + cogl_framebuffer_pop_matrix (test_fb); + + cogl_object_unref (legacy_pipeline); } cogl_object_unref (pipeline); diff --git a/cogl/tests/conform/test-just-vertex-shader.c b/cogl/tests/conform/test-just-vertex-shader.c index d54b20149..ea7b2ac12 100644 --- a/cogl/tests/conform/test-just-vertex-shader.c +++ b/cogl/tests/conform/test-just-vertex-shader.c @@ -37,7 +37,7 @@ paint (TestState *state) CoglHandle shader, program; cogl_color_init_from_4ub (&color, 0, 0, 0, 255); - cogl_clear (&color, COGL_BUFFER_BIT_COLOR); + cogl_framebuffer_clear (test_fb, COGL_BUFFER_BIT_COLOR, &color); /* Set the primary vertex color as red */ cogl_color_init_from_4ub (&color, 0xff, 0x00, 0x00, 0xff); @@ -85,14 +85,15 @@ paint (TestState *state) cogl_object_unref (shader); /* Draw something without the program */ - cogl_set_source (pipeline); - cogl_rectangle (0, 0, 50, 50); + cogl_framebuffer_draw_rectangle (test_fb, pipeline, + 0, 0, 50, 50); /* Draw it again using the program. It should look exactly the same */ cogl_pipeline_set_user_program (pipeline, program); cogl_object_unref (program); - cogl_rectangle (50, 0, 100, 50); + cogl_framebuffer_draw_rectangle (test_fb, pipeline, + 50, 0, 100, 50); cogl_pipeline_set_user_program (pipeline, NULL); cogl_object_unref (pipeline); @@ -119,15 +120,9 @@ test_just_vertex_shader (void) -1, 100); - /* XXX: we have to push/pop a framebuffer since this test currently - * uses the legacy cogl_rectangle() api. */ - cogl_push_framebuffer (test_fb); - paint (&state); validate_result (test_fb); - cogl_pop_framebuffer (); - if (cogl_test_verbose ()) g_print ("OK\n"); } diff --git a/cogl/tests/conform/test-offscreen.c b/cogl/tests/conform/test-offscreen.c index 6dcc6a55f..d5f779947 100644 --- a/cogl/tests/conform/test-offscreen.c +++ b/cogl/tests/conform/test-offscreen.c @@ -44,6 +44,8 @@ test_paint (TestState *state) CoglTexture2D *tex_2d; CoglTexture *tex; CoglOffscreen *offscreen; + CoglPipeline *opaque_pipeline; + CoglPipeline *texture_pipeline; tex_2d = cogl_texture_2d_new_with_size (test_ctx, state->fb_width, @@ -62,41 +64,41 @@ test_paint (TestState *state) * quarter of the window size and slide it to the top right of the * window. */ - cogl_push_matrix (); - cogl_translate (0.5, 0.5, 0); - cogl_scale (-0.5, 0.5, 1); + cogl_framebuffer_push_matrix (test_fb); + cogl_framebuffer_translate (test_fb, 0.5, 0.5, 0); + cogl_framebuffer_scale (test_fb, -0.5, 0.5, 1); - cogl_push_framebuffer (offscreen); + /* Setup something other than the identity matrix for the modelview so we can + * verify it gets restored when we call cogl_pop_framebuffer () */ + cogl_framebuffer_scale (test_fb, 2, 2, 1); + + opaque_pipeline = cogl_pipeline_new (test_ctx); + /* red, top left */ + cogl_pipeline_set_color4ub (opaque_pipeline, 0xff, 0x00, 0x00, 0xff); + cogl_framebuffer_draw_rectangle (offscreen, opaque_pipeline, -0.5, 0.5, 0, 0); + /* green, top right */ + cogl_pipeline_set_color4ub (opaque_pipeline, 0x00, 0xff, 0x00, 0xff); + cogl_framebuffer_draw_rectangle (offscreen, opaque_pipeline, 0, 0.5, 0.5, 0); + /* blue, bottom left */ + cogl_pipeline_set_color4ub (opaque_pipeline, 0x00, 0x00, 0xff, 0xff); + cogl_framebuffer_draw_rectangle (offscreen, opaque_pipeline, -0.5, 0, 0, -0.5); + /* white, bottom right */ + cogl_pipeline_set_color4ub (opaque_pipeline, 0xff, 0xff, 0xff, 0xff); + cogl_framebuffer_draw_rectangle (offscreen, opaque_pipeline, 0, 0, 0.5, -0.5); /* Cogl should release the last reference when we call cogl_pop_framebuffer() */ cogl_object_unref (offscreen); - /* Setup something other than the identity matrix for the modelview so we can - * verify it gets restored when we call cogl_pop_framebuffer () */ - cogl_scale (2, 2, 1); - - /* red, top left */ - cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff); - cogl_rectangle (-0.5, 0.5, 0, 0); - /* green, top right */ - cogl_set_source_color4ub (0x00, 0xff, 0x00, 0xff); - cogl_rectangle (0, 0.5, 0.5, 0); - /* blue, bottom left */ - cogl_set_source_color4ub (0x00, 0x00, 0xff, 0xff); - cogl_rectangle (-0.5, 0, 0, -0.5); - /* white, bottom right */ - cogl_set_source_color4ub (0xff, 0xff, 0xff, 0xff); - cogl_rectangle (0, 0, 0.5, -0.5); - - cogl_pop_framebuffer (); - - cogl_set_source_texture (tex); - cogl_rectangle (-1, 1, 1, -1); + texture_pipeline = cogl_pipeline_new (test_ctx); + cogl_pipeline_set_layer_texture (texture_pipeline, 0, tex); + cogl_framebuffer_draw_rectangle (test_fb, texture_pipeline, -1, 1, 1, -1); + cogl_object_unref (opaque_pipeline); + cogl_object_unref (texture_pipeline); cogl_object_unref (tex_2d); - cogl_pop_matrix (); + cogl_framebuffer_pop_matrix (test_fb); /* NB: The texture is drawn flipped horizontally and scaled to fit in the * top right corner of the window. */ @@ -114,12 +116,16 @@ test_paint (TestState *state) static void test_flush (TestState *state) { + CoglPipeline *pipeline; CoglTexture2D *tex_2d; CoglTexture *tex; CoglOffscreen *offscreen; CoglColor clear_color; int i; + pipeline = cogl_pipeline_new (test_ctx); + cogl_pipeline_set_color4ub (pipeline, 255, 0, 0, 255); + for (i = 0; i < 3; i++) { /* This tests that rendering to a framebuffer and then reading back @@ -132,13 +138,10 @@ test_flush (TestState *state) offscreen = cogl_offscreen_new_with_texture (tex); - cogl_push_framebuffer (offscreen); - cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 255); - cogl_clear (&clear_color, COGL_BUFFER_BIT_COLOR); + cogl_framebuffer_clear (offscreen, COGL_BUFFER_BIT_COLOR, &clear_color); - cogl_set_source_color4ub (255, 0, 0, 255); - cogl_rectangle (-1, -1, 1, 1); + cogl_framebuffer_draw_rectangle (offscreen, pipeline, -1, -1, 1, 1); if (i == 0) /* First time check using read pixels on the offscreen */ @@ -161,13 +164,11 @@ test_flush (TestState *state) 0xff0000ff); } - cogl_pop_framebuffer (); - if (i == 2) { /* Third time try drawing the texture to the screen */ - cogl_set_source_texture (tex); - cogl_rectangle (-1, -1, 1, 1); + cogl_framebuffer_draw_rectangle (test_fb, pipeline, + -1, -1, 1, 1); test_utils_check_region (test_fb, 2, 2, /* x/y */ state->fb_width - 4, @@ -178,6 +179,8 @@ test_flush (TestState *state) cogl_object_unref (tex_2d); cogl_object_unref (offscreen); } + + cogl_object_unref (pipeline); } void @@ -188,12 +191,8 @@ test_offscreen (void) state.fb_width = cogl_framebuffer_get_width (test_fb); state.fb_height = cogl_framebuffer_get_height (test_fb); - /* XXX: we have to push/pop a framebuffer since this test currently - * uses the legacy cogl_rectangle() api. */ - cogl_push_framebuffer (test_fb); test_paint (&state); test_flush (&state); - cogl_pop_framebuffer (); if (cogl_test_verbose ()) g_print ("OK\n"); diff --git a/cogl/tests/conform/test-path.c b/cogl/tests/conform/test-path.c index 93779ebe2..f9287d4b4 100644 --- a/cogl/tests/conform/test-path.c +++ b/cogl/tests/conform/test-path.c @@ -22,9 +22,7 @@ draw_path_at (CoglPath *path, CoglPipeline *pipeline, int x, int y) cogl_framebuffer_push_matrix (test_fb); cogl_framebuffer_translate (test_fb, x * BLOCK_SIZE, y * BLOCK_SIZE, 0.0f); - cogl_set_framebuffer (test_fb); - cogl_set_source (pipeline); - cogl_path_fill (path); + cogl_framebuffer_fill_path (test_fb, pipeline, path); cogl_framebuffer_pop_matrix (test_fb); } diff --git a/cogl/tests/conform/test-wrap-modes.c b/cogl/tests/conform/test-wrap-modes.c index d44322707..9bd525ebc 100644 --- a/cogl/tests/conform/test-wrap-modes.c +++ b/cogl/tests/conform/test-wrap-modes.c @@ -210,15 +210,16 @@ paint (TestState *state) cogl_framebuffer_push_matrix (test_fb); cogl_framebuffer_translate (test_fb, 0.0f, TEX_SIZE * 2.0f, 0.0f); draw_tests (state); - cogl_pop_matrix (); + cogl_framebuffer_pop_matrix (test_fb); cogl_object_unref (state->texture); /* Draw the tests using CoglPrimitive */ state->texture = create_texture (TEST_UTILS_TEXTURE_NO_ATLAS); - cogl_push_matrix (); - cogl_translate (0.0f, TEX_SIZE * 4.0f, 0.0f); + cogl_framebuffer_push_matrix (test_fb); + cogl_framebuffer_translate (test_fb, + 0.0f, TEX_SIZE * 4.0f, 0.0f); draw_tests_polygon (state); - cogl_pop_matrix (); + cogl_framebuffer_pop_matrix (test_fb); cogl_object_unref (state->texture); validate_result (state); @@ -239,11 +240,7 @@ test_wrap_modes (void) -1, 100); - /* XXX: we have to push/pop a framebuffer since this test currently - * uses the legacy cogl_vertex_buffer_draw() api. */ - cogl_push_framebuffer (test_fb); paint (&state); - cogl_pop_framebuffer (); if (cogl_test_verbose ()) g_print ("OK\n");