diff options
author | Eric Anholt <eric@anholt.net> | 2014-02-28 13:02:11 -0500 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@gmail.com> | 2014-03-13 21:52:25 +0800 |
commit | 073a7d37ee70d52cb1db3857b3521af5805fdd15 (patch) | |
tree | 6a7b56a0438d6f638f37fa96e47cd1d7ae4e870b | |
parent | b951818ab40834530c7d9b9e2c29ff259401ce18 (diff) |
glamor: Rename more solid fill variables to clean up the code.
Now the error path of allocation is more obvious: We leave things in
the a-few-boxes-at-a-time stack memory state.
Ported from Eric's xserver glamor tree.
Signed-off-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r-- | src/glamor_fill.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/glamor_fill.c b/src/glamor_fill.c index 1c0b393..e93a849 100644 --- a/src/glamor_fill.c +++ b/src/glamor_fill.c @@ -190,9 +190,9 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) glamor_get_pixmap_private(pixmap); glamor_gl_dispatch *dispatch; GLfloat xscale, yscale; - float vertices[32]; - float *pvertices = vertices; - int valid_nbox = ARRAY_SIZE(vertices); + float stack_vertices[32]; + float *vertices = stack_vertices; + int valid_nbox = ARRAY_SIZE(stack_vertices) / (4 * 2); glamor_set_destination_pixmap_priv_nc(pixmap_priv); @@ -205,18 +205,17 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) pixmap_priv_get_dest_scale(pixmap_priv, &xscale, &yscale); if (nbox > valid_nbox) { - int allocated_box; - - if (nbox > GLAMOR_COMPOSITE_VBO_VERT_CNT / 6) { - allocated_box = GLAMOR_COMPOSITE_VBO_VERT_CNT / 6; - } else - allocated_box = nbox; - pvertices = malloc(allocated_box * 4 * 2 * sizeof(float)); - if (pvertices) - valid_nbox = allocated_box; - else { - pvertices = vertices; - valid_nbox = ARRAY_SIZE(vertices) / (4*2); + int allocated_nbox; + float *new_vertices; + + if (nbox > GLAMOR_COMPOSITE_VBO_VERT_CNT / 6) + allocated_nbox = GLAMOR_COMPOSITE_VBO_VERT_CNT / 6; + else + allocated_nbox = nbox; + new_vertices = malloc(allocated_nbox * 4 * 2 * sizeof(float)); + if (new_vertices) { + vertices = new_vertices; + valid_nbox = allocated_nbox; } } @@ -225,14 +224,14 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), - pvertices); + vertices); dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); while(nbox) { int box_cnt, i; float *next_box; - next_box = pvertices; + next_box = vertices; box_cnt = nbox > valid_nbox ? valid_nbox : nbox; for (i = 0; i < box_cnt; i++) { glamor_set_normalize_vcoords(pixmap_priv, xscale, yscale, @@ -262,8 +261,8 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) box += box_cnt; } - if (pvertices != vertices) - free(pvertices); + if (vertices != stack_vertices) + free(vertices); dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); dispatch->glUseProgram(0); |