/*
* Mesa 3-D graphics library
- * Version: 7.9
*
* Copyright (C) 2010 LunarG Inc.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
*
* Authors:
* Chia-I Wu <olv@lunarg.com>
unsigned texture_mask;
};
-static INLINE struct stw_st_framebuffer *
-stw_st_framebuffer(struct st_framebuffer_iface *stfb)
+static uint32_t stwfb_ID = 0;
+
+/**
+ * Is the given mutex held by the calling thread?
+ */
+bool
+stw_own_mutex(const CRITICAL_SECTION *cs)
{
- return (struct stw_st_framebuffer *) stfb;
+ // We can't compare OwningThread with our thread handle/id (see
+ // http://stackoverflow.com/a/12675635 ) but we can compare with the
+ // OwningThread member of a critical section we know we own.
+ CRITICAL_SECTION dummy;
+ InitializeCriticalSection(&dummy);
+ EnterCriticalSection(&dummy);
+ if (0)
+ _debug_printf("%p %p\n", cs->OwningThread, dummy.OwningThread);
+ bool ret = cs->OwningThread == dummy.OwningThread;
+ LeaveCriticalSection(&dummy);
+ DeleteCriticalSection(&dummy);
+ return ret;
}
+
/**
* Remove outdated textures and create the requested ones.
*/
templ.depth0 = 1;
templ.array_size = 1;
templ.last_level = 0;
+ templ.nr_samples = stwfb->stvis.samples;
+ templ.nr_storage_samples = stwfb->stvis.samples;;
for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
enum pipe_format format;
case ST_ATTACHMENT_BACK_LEFT:
format = stwfb->stvis.color_format;
bind = PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SAMPLER_VIEW |
PIPE_BIND_RENDER_TARGET;
break;
case ST_ATTACHMENT_DEPTH_STENCIL:
}
static boolean
-stw_st_framebuffer_validate(struct st_framebuffer_iface *stfb,
+stw_st_framebuffer_validate(struct st_context_iface *stctx,
+ struct st_framebuffer_iface *stfb,
const enum st_attachment_type *statts,
unsigned count,
struct pipe_resource **out)
for (i = 0; i < count; i++)
statt_mask |= 1 << statts[i];
- pipe_mutex_lock(stwfb->fb->mutex);
+ stw_framebuffer_lock(stwfb->fb);
if (stwfb->fb->must_resize || (statt_mask & ~stwfb->texture_mask)) {
stw_st_framebuffer_validate_locked(&stwfb->base,
stwfb->fb->must_resize = FALSE;
}
- for (i = 0; i < count; i++) {
- out[i] = NULL;
+ for (i = 0; i < count; i++)
pipe_resource_reference(&out[i], stwfb->textures[statts[i]]);
- }
- stw_framebuffer_release(stwfb->fb);
+ stw_framebuffer_unlock(stwfb->fb);
return TRUE;
}
struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb);
struct pipe_resource *resource;
+ assert(stw_own_mutex(&stwfb->fb->mutex));
+
resource = stwfb->textures[statt];
if (resource) {
stw_framebuffer_present_locked(hdc, stwfb->fb, resource);
}
+ else {
+ stw_framebuffer_unlock(stwfb->fb);
+ }
+
+ assert(!stw_own_mutex(&stwfb->fb->mutex));
return TRUE;
}
boolean ret;
HDC hDC;
- pipe_mutex_lock(stwfb->fb->mutex);
+ stw_framebuffer_lock(stwfb->fb);
/* We must not cache HDCs anywhere, as they can be invalidated by the
* application, or screen resolution changes. */
stwfb->fb = fb;
stwfb->stvis = fb->pfi->stvis;
+ stwfb->base.ID = p_atomic_inc_return(&stwfb_ID);
+ stwfb->base.state_manager = stw_dev->smapi;
stwfb->base.visual = &stwfb->stvis;
p_atomic_set(&stwfb->base.stamp, 1);
for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
pipe_resource_reference(&stwfb->textures[i], NULL);
+ /* Notify the st manager that the framebuffer interface is no
+ * longer valid.
+ */
+ stw_dev->stapi->destroy_drawable(stw_dev->stapi, &stwfb->base);
+
FREE(stwfb);
}