+
+static uint32_t
+st_framebuffer_iface_hash(const void *key)
+{
+ return (uintptr_t)key;
+}
+
+
+static bool
+st_framebuffer_iface_equal(const void *a, const void *b)
+{
+ return (struct st_framebuffer_iface *)a == (struct st_framebuffer_iface *)b;
+}
+
+
+static boolean
+st_framebuffer_iface_lookup(struct st_manager *smapi,
+ const struct st_framebuffer_iface *stfbi)
+{
+ struct st_manager_private *smPriv =
+ (struct st_manager_private *)smapi->st_manager_private;
+ struct hash_entry *entry;
+
+ assert(smPriv);
+ assert(smPriv->stfbi_ht);
+
+ mtx_lock(&smPriv->st_mutex);
+ entry = _mesa_hash_table_search(smPriv->stfbi_ht, stfbi);
+ mtx_unlock(&smPriv->st_mutex);
+
+ return entry != NULL;
+}
+
+
+static boolean
+st_framebuffer_iface_insert(struct st_manager *smapi,
+ struct st_framebuffer_iface *stfbi)
+{
+ struct st_manager_private *smPriv =
+ (struct st_manager_private *)smapi->st_manager_private;
+ struct hash_entry *entry;
+
+ assert(smPriv);
+ assert(smPriv->stfbi_ht);
+
+ mtx_lock(&smPriv->st_mutex);
+ entry = _mesa_hash_table_insert(smPriv->stfbi_ht, stfbi, stfbi);
+ mtx_unlock(&smPriv->st_mutex);
+
+ return entry != NULL;
+}
+
+
+static void
+st_framebuffer_iface_remove(struct st_manager *smapi,
+ struct st_framebuffer_iface *stfbi)
+{
+ struct st_manager_private *smPriv =
+ (struct st_manager_private *)smapi->st_manager_private;
+ struct hash_entry *entry;
+
+ if (!smPriv || !smPriv->stfbi_ht)
+ return;
+
+ mtx_lock(&smPriv->st_mutex);
+ entry = _mesa_hash_table_search(smPriv->stfbi_ht, stfbi);
+ if (!entry)
+ goto unlock;
+
+ _mesa_hash_table_remove(smPriv->stfbi_ht, entry);
+
+unlock:
+ mtx_unlock(&smPriv->st_mutex);
+}
+
+
+/**
+ * The framebuffer interface object is no longer valid.
+ * Remove the object from the framebuffer interface hash table.
+ */
+static void
+st_api_destroy_drawable(struct st_api *stapi,
+ struct st_framebuffer_iface *stfbi)
+{
+ if (!stfbi)
+ return;
+
+ st_framebuffer_iface_remove(stfbi->state_manager, stfbi);
+}
+
+
+/**
+ * Purge the winsys buffers list to remove any references to
+ * non-existing framebuffer interface objects.
+ */
+static void
+st_framebuffers_purge(struct st_context *st)
+{
+ struct st_context_iface *st_iface = &st->iface;
+ struct st_manager *smapi = st_iface->state_manager;
+ struct st_framebuffer *stfb, *next;
+
+ assert(smapi);
+
+ LIST_FOR_EACH_ENTRY_SAFE_REV(stfb, next, &st->winsys_buffers, head) {
+ struct st_framebuffer_iface *stfbi = stfb->iface;
+
+ assert(stfbi);
+
+ /**
+ * If the corresponding framebuffer interface object no longer exists,
+ * remove the framebuffer object from the context's winsys buffers list,
+ * and unreference the framebuffer object, so its resources can be
+ * deleted.
+ */
+ if (!st_framebuffer_iface_lookup(smapi, stfbi)) {
+ LIST_DEL(&stfb->head);
+ st_framebuffer_reference(&stfb, NULL);
+ }
+ }
+}
+
+