commit b32c3d6

Michael Forney  ·  2014-01-31 22:29:24 +0000 UTC
parent 3f29f42
intel: Don't malloc batch structure
3 files changed,  +21, -27
+10, -10
 1@@ -40,7 +40,7 @@ struct intel_context
 2 struct intel_renderer
 3 {
 4     struct wld_renderer base;
 5-    struct intel_batch * batch;
 6+    struct intel_batch batch;
 7     struct intel_buffer * target;
 8 };
 9 
10@@ -99,7 +99,7 @@ struct wld_renderer * context_create_renderer(struct wld_context * base)
11     if (!(renderer = malloc(sizeof *renderer)))
12         goto error0;
13 
14-    if (!(renderer->batch = intel_batch_new(context->bufmgr)))
15+    if (!(intel_batch_initialize(&renderer->batch, context->bufmgr)))
16         goto error1;
17 
18     renderer_initialize(&renderer->base, &renderer_impl);
19@@ -234,7 +234,7 @@ void renderer_fill_rectangle(struct wld_renderer * base, uint32_t color,
20 {
21     struct intel_renderer * renderer = intel_renderer(base);
22 
23-    xy_color_blt(renderer->batch, renderer->target->bo,
24+    xy_color_blt(&renderer->batch, renderer->target->bo,
25                  renderer->target->base.pitch,
26                  x, y, x + width, y + height, color);
27 }
28@@ -252,7 +252,7 @@ void renderer_copy_rectangle(struct wld_renderer * base,
29 
30     struct intel_buffer * buffer = intel_buffer(buffer_base);
31 
32-    xy_src_copy_blt(renderer->batch, buffer->bo, buffer->base.pitch,
33+    xy_src_copy_blt(&renderer->batch, buffer->bo, buffer->base.pitch,
34                     src_x, src_y,
35                     renderer->target->bo, renderer->target->base.pitch,
36                     dst_x, dst_y, width, height);
37@@ -273,7 +273,7 @@ void renderer_draw_text(struct wld_renderer * base,
38     uint8_t * byte;
39     int32_t origin_x = x;
40 
41-    xy_setup_blt(renderer->batch, true, BLT_RASTER_OPERATION_SRC,
42+    xy_setup_blt(&renderer->batch, true, BLT_RASTER_OPERATION_SRC,
43                  0, color, renderer->target->bo, renderer->target->base.pitch);
44 
45     while ((ret = FcUtf8ToUcs4((FcChar8 *) text, &c, length)) > 0 && c != '\0')
46@@ -301,7 +301,7 @@ void renderer_draw_text(struct wld_renderer * base,
47         }
48 
49       retry:
50-        ret = xy_text_immediate_blt(renderer->batch, renderer->target->bo,
51+        ret = xy_text_immediate_blt(&renderer->batch, renderer->target->bo,
52                                     origin_x + glyph->x, y + glyph->y,
53                                     origin_x + glyph->x + glyph->bitmap.width,
54                                     y + glyph->y + glyph->bitmap.rows,
55@@ -310,8 +310,8 @@ void renderer_draw_text(struct wld_renderer * base,
56 
57         if (ret == INTEL_BATCH_NO_SPACE)
58         {
59-            intel_batch_flush(renderer->batch);
60-            xy_setup_blt(renderer->batch, true,
61+            intel_batch_flush(&renderer->batch);
62+            xy_setup_blt(&renderer->batch, true,
63                          BLT_RASTER_OPERATION_SRC, 0, color,
64                          renderer->target->bo, renderer->target->base.pitch);
65             goto retry;
66@@ -329,14 +329,14 @@ void renderer_flush(struct wld_renderer * base)
67 {
68     struct intel_renderer * renderer = intel_renderer(base);
69 
70-    intel_batch_flush(renderer->batch);
71+    intel_batch_flush(&renderer->batch);
72 }
73 
74 void renderer_destroy(struct wld_renderer * base)
75 {
76     struct intel_renderer * renderer = intel_renderer(base);
77 
78-    intel_batch_destroy(renderer->batch);
79+    intel_batch_finalize(&renderer->batch);
80     free(renderer);
81 }
82 
+7, -15
 1@@ -51,38 +51,30 @@ static const struct intel_device_info * device_info(int device_id)
 2     }
 3 }
 4 
 5-struct intel_batch * intel_batch_new(drm_intel_bufmgr * bufmgr)
 6+bool intel_batch_initialize(struct intel_batch * batch,
 7+                            drm_intel_bufmgr * bufmgr)
 8 {
 9-    struct intel_batch * batch;
10     int device_id = drm_intel_bufmgr_gem_get_devid(bufmgr);
11 
12-    batch = malloc(sizeof *batch);
13-
14-    if (!batch)
15-        goto error0;
16-
17     batch->command_count = 0;
18     batch->device_info = device_info(device_id);
19 
20     if (!batch->device_info)
21-        goto error1;
22+        return false;
23 
24     /* Alignment argument (4096) is not used */
25     batch->bo = drm_intel_bo_alloc(bufmgr, "batchbuffer",
26                                    sizeof batch->commands, 4096);
27 
28-    return batch;
29+    if (!batch->bo)
30+        return false;
31 
32-  error1:
33-    free(batch);
34-  error0:
35-    return NULL;
36+    return true;
37 }
38 
39-void intel_batch_destroy(struct intel_batch * batch)
40+void intel_batch_finalize(struct intel_batch * batch)
41 {
42     drm_intel_bo_unreference(batch->bo);
43-    free(batch);
44 }
45 
46 void intel_batch_flush(struct intel_batch * batch)
+4, -2
 1@@ -25,6 +25,7 @@
 2 #define WLD_INTEL_BATCH_H
 3 
 4 #include <stdarg.h>
 5+#include <stdbool.h>
 6 #include <stdint.h>
 7 #include <intel_bufmgr.h>
 8 
 9@@ -51,9 +52,10 @@ struct intel_batch
10     uint32_t command_count;
11 };
12 
13-struct intel_batch * intel_batch_new(drm_intel_bufmgr * bufmgr);
14+bool intel_batch_initialize(struct intel_batch * batch,
15+                            drm_intel_bufmgr * bufmgr);
16 
17-void intel_batch_destroy(struct intel_batch * batch);
18+void intel_batch_finalize(struct intel_batch * batch);
19 
20 void intel_batch_flush(struct intel_batch * batch);
21