swpipe: Improve context management

* Ensure all context pointers are in a known state
* Destroy all contexts on shutdown
This commit is contained in:
Alexander von Gluck IV
2012-11-28 03:28:26 +00:00
parent 5c13f06d8c
commit 14c416c1b4
2 changed files with 32 additions and 5 deletions
+31 -5
View File
@@ -250,6 +250,11 @@ GalliumContext::GalliumContext(ulong options)
{ {
CALLED(); CALLED();
// Make all contexts a known value
context_id i;
for (i = 0; i < CONTEXT_MAX; i++)
fContext[i] = NULL;
CreateScreen(); CreateScreen();
pipe_mutex_init(fMutex); pipe_mutex_init(fMutex);
@@ -260,16 +265,16 @@ GalliumContext::~GalliumContext()
{ {
CALLED(); CALLED();
// Destroy our contexts
pipe_mutex_lock(fMutex); pipe_mutex_lock(fMutex);
uint32 i; uint32 i;
for (i = 0; i < CONTEXT_MAX; i++) { for (i = 0; i < CONTEXT_MAX; i++)
// TODO: Delete each context DestroyContext(i);
//if (fContext[i])
// hsp_delete_context(i + 1);
}
pipe_mutex_unlock(fMutex); pipe_mutex_unlock(fMutex);
pipe_mutex_destroy(fMutex); pipe_mutex_destroy(fMutex);
// TODO: Destroy fScreen
} }
@@ -478,6 +483,27 @@ GalliumContext::CreateContext(Bitmap *bitmap)
} }
void
GalliumContext::DestroyContext(context_id contextID)
{
// fMutex should be locked *before* calling DestoryContext
// See if context is used
if (!fContext[contextID])
return;
if (fContext[contextID]->st) {
fContext[contextID]->st->flush(fContext[contextID]->st, 0, NULL);
fContext[contextID]->st->destroy(fContext[contextID]->st);
}
if (fContext[contextID]->manager)
FREE(fContext[contextID]->manager);
FREE(fContext[contextID]);
}
status_t status_t
GalliumContext::SetCurrentContext(Bitmap *bitmap, context_id contextID) GalliumContext::SetCurrentContext(Bitmap *bitmap, context_id contextID)
{ {
@@ -52,6 +52,7 @@ public:
~GalliumContext(); ~GalliumContext();
context_id CreateContext(Bitmap* bitmap); context_id CreateContext(Bitmap* bitmap);
void DestroyContext(context_id contextID);
context_id GetCurrentContext() { return fCurrentContext; }; context_id GetCurrentContext() { return fCurrentContext; };
status_t SetCurrentContext(Bitmap *bitmap, status_t SetCurrentContext(Bitmap *bitmap,
context_id contextID); context_id contextID);