mirror of https://gitlab.com/nakst/essence
reference counting on API instances
This commit is contained in:
parent
f4f69ea9c8
commit
2b288a82a6
|
@ -203,6 +203,8 @@ struct EsUndoManager {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct APIInstance {
|
struct APIInstance {
|
||||||
|
uintptr_t referenceCount;
|
||||||
|
|
||||||
HashStore<uint32_t, EsCommand *> commands;
|
HashStore<uint32_t, EsCommand *> commands;
|
||||||
|
|
||||||
_EsApplicationStartupInformation *startupInformation;
|
_EsApplicationStartupInformation *startupInformation;
|
||||||
|
@ -814,6 +816,7 @@ APIInstance *InstanceSetup(EsInstance *instance) {
|
||||||
APIInstance *apiInstance = (APIInstance *) EsHeapAllocate(sizeof(APIInstance), true);
|
APIInstance *apiInstance = (APIInstance *) EsHeapAllocate(sizeof(APIInstance), true);
|
||||||
|
|
||||||
instance->_private = apiInstance;
|
instance->_private = apiInstance;
|
||||||
|
apiInstance->referenceCount = 1;
|
||||||
|
|
||||||
instance->undoManager = &apiInstance->undoManager;
|
instance->undoManager = &apiInstance->undoManager;
|
||||||
instance->undoManager->instance = instance;
|
instance->undoManager->instance = instance;
|
||||||
|
@ -885,6 +888,7 @@ EsInstance *_EsInstanceCreate(size_t bytes, EsMessage *message, const char *appl
|
||||||
if (message) {
|
if (message) {
|
||||||
apiInstance->mainWindowHandle = message->createInstance.window;
|
apiInstance->mainWindowHandle = message->createInstance.window;
|
||||||
instance->window = EsWindowCreate(instance, ES_WINDOW_NORMAL);
|
instance->window = EsWindowCreate(instance, ES_WINDOW_NORMAL);
|
||||||
|
EsInstanceOpenReference(instance);
|
||||||
EsWindowSetTitle(instance->window, nullptr, 0);
|
EsWindowSetTitle(instance->window, nullptr, 0);
|
||||||
|
|
||||||
if (apiInstance->startupInformation && apiInstance->startupInformation->readHandle) {
|
if (apiInstance->startupInformation && apiInstance->startupInformation->readHandle) {
|
||||||
|
@ -912,7 +916,28 @@ EsApplicationStartupRequest EsInstanceGetStartupRequest(EsInstance *_instance) {
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EsInstanceOpenReference(EsInstance *_instance) {
|
||||||
|
EsMessageMutexCheck();
|
||||||
|
APIInstance *instance = (APIInstance *) _instance->_private;
|
||||||
|
EsAssert(instance->referenceCount);
|
||||||
|
instance->referenceCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EsInstanceCloseReference(EsInstance *_instance) {
|
||||||
|
EsMessageMutexCheck();
|
||||||
|
APIInstance *instance = (APIInstance *) _instance->_private;
|
||||||
|
instance->referenceCount--;
|
||||||
|
|
||||||
|
if (!instance->referenceCount) {
|
||||||
|
EsMessage m = {};
|
||||||
|
m.type = ES_MSG_INSTANCE_DESTROY;
|
||||||
|
m.instanceDestroy.instance = _instance;
|
||||||
|
EsMessagePost(nullptr, &m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EsInstanceDestroy(EsInstance *instance) {
|
void EsInstanceDestroy(EsInstance *instance) {
|
||||||
|
EsMessageMutexCheck();
|
||||||
InspectorWindow **inspector = &((APIInstance *) instance->_private)->attachedInspector;
|
InspectorWindow **inspector = &((APIInstance *) instance->_private)->attachedInspector;
|
||||||
|
|
||||||
if (*inspector) {
|
if (*inspector) {
|
||||||
|
@ -923,8 +948,8 @@ void EsInstanceDestroy(EsInstance *instance) {
|
||||||
|
|
||||||
UndoManagerDestroy(instance->undoManager);
|
UndoManagerDestroy(instance->undoManager);
|
||||||
EsAssert(instance->window->instance == instance);
|
EsAssert(instance->window->instance == instance);
|
||||||
instance->window->destroyInstanceAfterClose = true;
|
|
||||||
EsElementDestroy(instance->window);
|
EsElementDestroy(instance->window);
|
||||||
|
EsInstanceCloseReference(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
EsWindow *WindowFromWindowID(EsObjectID id) {
|
EsWindow *WindowFromWindowID(EsObjectID id) {
|
||||||
|
|
|
@ -463,7 +463,7 @@ struct EsWindow : EsElement {
|
||||||
uint32_t windowWidth, windowHeight;
|
uint32_t windowWidth, windowHeight;
|
||||||
|
|
||||||
// TODO Replace this with a bitset?
|
// TODO Replace this with a bitset?
|
||||||
bool willUpdate, toolbarFillMode, destroyInstanceAfterClose, doNotPaint;
|
bool willUpdate, toolbarFillMode, doNotPaint;
|
||||||
bool restoreOnNextMove, resetPositionOnNextMove, receivedFirstResize, isMaximised;
|
bool restoreOnNextMove, resetPositionOnNextMove, receivedFirstResize, isMaximised;
|
||||||
bool hovering, activated, appearActivated;
|
bool hovering, activated, appearActivated;
|
||||||
bool visualizeRepaints, visualizeLayoutBounds, visualizePaintSteps; // Inspector properties.
|
bool visualizeRepaints, visualizeLayoutBounds, visualizePaintSteps; // Inspector properties.
|
||||||
|
@ -7253,14 +7253,10 @@ void UIProcessWindowManagerMessage(EsWindow *window, EsMessage *message, Process
|
||||||
// Check if the window has been destroyed.
|
// Check if the window has been destroyed.
|
||||||
|
|
||||||
if (message->type == ES_MSG_WINDOW_DESTROYED) {
|
if (message->type == ES_MSG_WINDOW_DESTROYED) {
|
||||||
if (window->destroyInstanceAfterClose) {
|
if (window->instance) {
|
||||||
EsMessage m = {};
|
|
||||||
m.type = ES_MSG_INSTANCE_DESTROY;
|
|
||||||
m.instanceDestroy.instance = window->instance;
|
|
||||||
EsAssert(window->instance->window == window);
|
EsAssert(window->instance->window == window);
|
||||||
window->instance->window = nullptr;
|
window->instance->window = nullptr;
|
||||||
window->instance = nullptr;
|
EsInstanceCloseReference(window->instance);
|
||||||
EsMessagePost(nullptr, &m);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EsAssert(window->handle == ES_INVALID_HANDLE);
|
EsAssert(window->handle == ES_INVALID_HANDLE);
|
||||||
|
@ -7546,7 +7542,7 @@ struct InspectorWindow : EsInstance {
|
||||||
EsInstance *instance; // The instance being inspected.
|
EsInstance *instance; // The instance being inspected.
|
||||||
|
|
||||||
EsListView *elementList;
|
EsListView *elementList;
|
||||||
Array<InspectorElementEntry> elements;
|
Array<InspectorElementEntry> elements; // TODO This is being leaked.
|
||||||
InspectorElementEntry hoveredElement;
|
InspectorElementEntry hoveredElement;
|
||||||
char *cCategoryFilter;
|
char *cCategoryFilter;
|
||||||
|
|
||||||
|
@ -8028,6 +8024,8 @@ void InspectorSetup(EsWindow *window) {
|
||||||
InspectorWindow *inspector = (InspectorWindow *) EsHeapAllocate(sizeof(InspectorWindow), true); // TODO Freeing this.
|
InspectorWindow *inspector = (InspectorWindow *) EsHeapAllocate(sizeof(InspectorWindow), true); // TODO Freeing this.
|
||||||
inspector->window = window;
|
inspector->window = window;
|
||||||
InstanceSetup(inspector);
|
InstanceSetup(inspector);
|
||||||
|
EsInstanceOpenReference(inspector);
|
||||||
|
|
||||||
inspector->instance = window->instance;
|
inspector->instance = window->instance;
|
||||||
((APIInstance *) inspector->_private)->internalOnly = true;
|
((APIInstance *) inspector->_private)->internalOnly = true;
|
||||||
window->instance = inspector;
|
window->instance = inspector;
|
||||||
|
|
|
@ -2366,6 +2366,8 @@ function void EsCommandSetCallback(EsCommand *command, EsCommandCallback callbac
|
||||||
function void EsCommandSetDisabled(EsCommand *command, bool disabled);
|
function void EsCommandSetDisabled(EsCommand *command, bool disabled);
|
||||||
function void EsCommandSetCheck(EsCommand *command, EsCheckState check, bool sendUpdatedMessage);
|
function void EsCommandSetCheck(EsCommand *command, EsCheckState check, bool sendUpdatedMessage);
|
||||||
|
|
||||||
|
function void EsInstanceOpenReference(EsInstance *_instance);
|
||||||
|
function void EsInstanceCloseReference(EsInstance *_instance);
|
||||||
function void EsInstanceDestroy(ES_INSTANCE_TYPE *instance);
|
function void EsInstanceDestroy(ES_INSTANCE_TYPE *instance);
|
||||||
function void EsInstanceSetActiveUndoManager(ES_INSTANCE_TYPE *instance, EsUndoManager *manager);
|
function void EsInstanceSetActiveUndoManager(ES_INSTANCE_TYPE *instance, EsUndoManager *manager);
|
||||||
function void EsInstanceSetClassEditor(ES_INSTANCE_TYPE *instance, const EsInstanceClassEditorSettings *settings);
|
function void EsInstanceSetClassEditor(ES_INSTANCE_TYPE *instance, const EsInstanceClassEditorSettings *settings);
|
||||||
|
|
|
@ -131,9 +131,11 @@ EsPipeRead=129
|
||||||
EsListViewInsert=130
|
EsListViewInsert=130
|
||||||
EsListViewRemove=131
|
EsListViewRemove=131
|
||||||
EsEventCreate=132
|
EsEventCreate=132
|
||||||
|
EsInstanceOpenReference=133
|
||||||
EsBufferFormat=134
|
EsBufferFormat=134
|
||||||
EsEventReset=135
|
EsEventReset=135
|
||||||
EsEventSet=136
|
EsEventSet=136
|
||||||
|
EsInstanceCloseReference=137
|
||||||
EsMutexAcquire=140
|
EsMutexAcquire=140
|
||||||
EsMutexDestroy=141
|
EsMutexDestroy=141
|
||||||
EsMutexRelease=142
|
EsMutexRelease=142
|
||||||
|
|
Loading…
Reference in New Issue