static void destruct(struct core_dc *dc)
{
- dc_resource_validate_ctx_destruct(dc->current_context);
+ dc_release_validate_context(dc->current_context);
destroy_links(dc);
goto val_ctx_fail;
}
+ dc->current_context->ref_count++;
+
dc_ctx->cgs_device = init_params->cgs_device;
dc_ctx->driver_context = init_params->driver;
dc_ctx->dc = &dc->public;
if (context == NULL)
goto context_alloc_fail;
+ ++context->ref_count;
+
if (!is_validation_required(core_dc, set, set_count)) {
dc_resource_validate_ctx_copy_construct(core_dc->current_context, context);
return context;
__func__,
result);
- dc_resource_validate_ctx_destruct(context);
- dm_free(context);
+ dc_release_validate_context(context);
context = NULL;
}
if (context == NULL)
goto context_alloc_fail;
+ ++context->ref_count;
+
result = core_dc->res_pool->funcs->validate_with_context(
core_dc, set, set_count, context, NULL);
result);
}
- dc_resource_validate_ctx_destruct(context);
- dm_free(context);
+ dc_release_validate_context(context);
context = NULL;
return result == DC_OK;
if (context == NULL)
goto context_alloc_fail;
+ ++context->ref_count;
+
result = core_dc->res_pool->funcs->validate_guaranteed(
core_dc, stream, context);
- dc_resource_validate_ctx_destruct(context);
- dm_free(context);
+ dc_release_validate_context(context);
context_alloc_fail:
if (result != DC_OK) {
dc_enable_stereo(dc, context, dc_streams, context->stream_count);
- dc_resource_validate_ctx_destruct(core_dc->current_context);
- dm_free(core_dc->current_context);
+ dc_release_validate_context(core_dc->current_context);
+
+ dc_retain_validate_context(context);
+
core_dc->current_context = context;
return (result == DC_OK);
if (context == NULL)
goto context_alloc_fail;
+ ++context->ref_count;
+
result = core_dc->res_pool->funcs->validate_with_context(
core_dc, set, stream_count, context, core_dc->current_context);
if (result != DC_OK){
__func__,
result);
BREAK_TO_DEBUGGER();
- dc_resource_validate_ctx_destruct(context);
goto fail;
}
return (result == DC_OK);
fail:
- dm_free(context);
+ dc_release_validate_context(context);
context_alloc_fail:
return (result == DC_OK);
return true;
}
+void dc_retain_validate_context(struct validate_context *context)
+{
+ ASSERT(context->ref_count > 0);
+ ++context->ref_count;
+}
+
+void dc_release_validate_context(struct validate_context *context)
+{
+ ASSERT(context->ref_count > 0);
+ --context->ref_count;
+
+ if (context->ref_count == 0) {
+ dc_resource_validate_ctx_destruct(context);
+ dm_free(context);
+ }
+}
+
static bool is_surface_in_context(
const struct validate_context *context,
const struct dc_surface *surface)
enum surface_update_type update_type;
const struct dc_stream_status *stream_status;
struct core_stream *stream = DC_STREAM_TO_CORE(dc_stream);
+ struct dc_context *dc_ctx = core_dc->ctx;
stream_status = dc_stream_get_status(dc_stream);
ASSERT(stream_status);
/* initialize scratch memory for building context */
context = dm_alloc(sizeof(*context));
+ if (context == NULL)
+ goto context_alloc_fail;
+
+ ++context->ref_count;
+
dc_resource_validate_ctx_copy_construct(
core_dc->current_context, context);
}
if (core_dc->current_context != context) {
- dc_resource_validate_ctx_destruct(core_dc->current_context);
- dm_free(core_dc->current_context);
-
+ dc_release_validate_context(core_dc->current_context);
+ dc_retain_validate_context(context);
core_dc->current_context = context;
}
return;
fail:
- dc_resource_validate_ctx_destruct(context);
- dm_free(context);
+ dc_release_validate_context(context);
+
+context_alloc_fail:
+ DC_ERROR("Failed to allocate new validate context!\n");
}
uint8_t dc_get_current_stream_count(const struct dc *dc)