commit b32c3d6ab060810905d49dec18b475557de31d36
parent 3f29f42d13e3ed7166d23707fd4f1f5cda46db2b
Author: Michael Forney <mforney@mforney.org>
Date: Fri, 31 Jan 2014 14:29:24 -0800
intel: Don't malloc batch structure
Diffstat:
3 files changed, 21 insertions(+), 27 deletions(-)
diff --git a/intel.c b/intel.c
@@ -40,7 +40,7 @@ struct intel_context
struct intel_renderer
{
struct wld_renderer base;
- struct intel_batch * batch;
+ struct intel_batch batch;
struct intel_buffer * target;
};
@@ -99,7 +99,7 @@ struct wld_renderer * context_create_renderer(struct wld_context * base)
if (!(renderer = malloc(sizeof *renderer)))
goto error0;
- if (!(renderer->batch = intel_batch_new(context->bufmgr)))
+ if (!(intel_batch_initialize(&renderer->batch, context->bufmgr)))
goto error1;
renderer_initialize(&renderer->base, &renderer_impl);
@@ -234,7 +234,7 @@ void renderer_fill_rectangle(struct wld_renderer * base, uint32_t color,
{
struct intel_renderer * renderer = intel_renderer(base);
- xy_color_blt(renderer->batch, renderer->target->bo,
+ xy_color_blt(&renderer->batch, renderer->target->bo,
renderer->target->base.pitch,
x, y, x + width, y + height, color);
}
@@ -252,7 +252,7 @@ void renderer_copy_rectangle(struct wld_renderer * base,
struct intel_buffer * buffer = intel_buffer(buffer_base);
- xy_src_copy_blt(renderer->batch, buffer->bo, buffer->base.pitch,
+ xy_src_copy_blt(&renderer->batch, buffer->bo, buffer->base.pitch,
src_x, src_y,
renderer->target->bo, renderer->target->base.pitch,
dst_x, dst_y, width, height);
@@ -273,7 +273,7 @@ void renderer_draw_text(struct wld_renderer * base,
uint8_t * byte;
int32_t origin_x = x;
- xy_setup_blt(renderer->batch, true, BLT_RASTER_OPERATION_SRC,
+ xy_setup_blt(&renderer->batch, true, BLT_RASTER_OPERATION_SRC,
0, color, renderer->target->bo, renderer->target->base.pitch);
while ((ret = FcUtf8ToUcs4((FcChar8 *) text, &c, length)) > 0 && c != '\0')
@@ -301,7 +301,7 @@ void renderer_draw_text(struct wld_renderer * base,
}
retry:
- ret = xy_text_immediate_blt(renderer->batch, renderer->target->bo,
+ ret = xy_text_immediate_blt(&renderer->batch, renderer->target->bo,
origin_x + glyph->x, y + glyph->y,
origin_x + glyph->x + glyph->bitmap.width,
y + glyph->y + glyph->bitmap.rows,
@@ -310,8 +310,8 @@ void renderer_draw_text(struct wld_renderer * base,
if (ret == INTEL_BATCH_NO_SPACE)
{
- intel_batch_flush(renderer->batch);
- xy_setup_blt(renderer->batch, true,
+ intel_batch_flush(&renderer->batch);
+ xy_setup_blt(&renderer->batch, true,
BLT_RASTER_OPERATION_SRC, 0, color,
renderer->target->bo, renderer->target->base.pitch);
goto retry;
@@ -329,14 +329,14 @@ void renderer_flush(struct wld_renderer * base)
{
struct intel_renderer * renderer = intel_renderer(base);
- intel_batch_flush(renderer->batch);
+ intel_batch_flush(&renderer->batch);
}
void renderer_destroy(struct wld_renderer * base)
{
struct intel_renderer * renderer = intel_renderer(base);
- intel_batch_destroy(renderer->batch);
+ intel_batch_finalize(&renderer->batch);
free(renderer);
}
diff --git a/intel/batch.c b/intel/batch.c
@@ -51,38 +51,30 @@ static const struct intel_device_info * device_info(int device_id)
}
}
-struct intel_batch * intel_batch_new(drm_intel_bufmgr * bufmgr)
+bool intel_batch_initialize(struct intel_batch * batch,
+ drm_intel_bufmgr * bufmgr)
{
- struct intel_batch * batch;
int device_id = drm_intel_bufmgr_gem_get_devid(bufmgr);
- batch = malloc(sizeof *batch);
-
- if (!batch)
- goto error0;
-
batch->command_count = 0;
batch->device_info = device_info(device_id);
if (!batch->device_info)
- goto error1;
+ return false;
/* Alignment argument (4096) is not used */
batch->bo = drm_intel_bo_alloc(bufmgr, "batchbuffer",
sizeof batch->commands, 4096);
- return batch;
+ if (!batch->bo)
+ return false;
- error1:
- free(batch);
- error0:
- return NULL;
+ return true;
}
-void intel_batch_destroy(struct intel_batch * batch)
+void intel_batch_finalize(struct intel_batch * batch)
{
drm_intel_bo_unreference(batch->bo);
- free(batch);
}
void intel_batch_flush(struct intel_batch * batch)
diff --git a/intel/batch.h b/intel/batch.h
@@ -25,6 +25,7 @@
#define WLD_INTEL_BATCH_H
#include <stdarg.h>
+#include <stdbool.h>
#include <stdint.h>
#include <intel_bufmgr.h>
@@ -51,9 +52,10 @@ struct intel_batch
uint32_t command_count;
};
-struct intel_batch * intel_batch_new(drm_intel_bufmgr * bufmgr);
+bool intel_batch_initialize(struct intel_batch * batch,
+ drm_intel_bufmgr * bufmgr);
-void intel_batch_destroy(struct intel_batch * batch);
+void intel_batch_finalize(struct intel_batch * batch);
void intel_batch_flush(struct intel_batch * batch);