1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2010 Thomas Balling Sørensen. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include <stdio.h> 29bf215546Sopenharmony_ci#include <vdpau/vdpau.h> 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci#include "util/u_debug.h" 32bf215546Sopenharmony_ci#include "util/u_memory.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci#include "vdpau_private.h" 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci/** 37bf215546Sopenharmony_ci * Create a VdpPresentationQueue. 38bf215546Sopenharmony_ci */ 39bf215546Sopenharmony_ciVdpStatus 40bf215546Sopenharmony_civlVdpPresentationQueueCreate(VdpDevice device, 41bf215546Sopenharmony_ci VdpPresentationQueueTarget presentation_queue_target, 42bf215546Sopenharmony_ci VdpPresentationQueue *presentation_queue) 43bf215546Sopenharmony_ci{ 44bf215546Sopenharmony_ci vlVdpPresentationQueue *pq = NULL; 45bf215546Sopenharmony_ci VdpStatus ret; 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci if (!presentation_queue) 48bf215546Sopenharmony_ci return VDP_STATUS_INVALID_POINTER; 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_ci vlVdpDevice *dev = vlGetDataHTAB(device); 51bf215546Sopenharmony_ci if (!dev) 52bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci vlVdpPresentationQueueTarget *pqt = vlGetDataHTAB(presentation_queue_target); 55bf215546Sopenharmony_ci if (!pqt) 56bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci if (dev != pqt->device) 59bf215546Sopenharmony_ci return VDP_STATUS_HANDLE_DEVICE_MISMATCH; 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_ci pq = CALLOC(1, sizeof(vlVdpPresentationQueue)); 62bf215546Sopenharmony_ci if (!pq) 63bf215546Sopenharmony_ci return VDP_STATUS_RESOURCES; 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci DeviceReference(&pq->device, dev); 66bf215546Sopenharmony_ci pq->drawable = pqt->drawable; 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_ci mtx_lock(&dev->mutex); 69bf215546Sopenharmony_ci if (!vl_compositor_init_state(&pq->cstate, dev->context)) { 70bf215546Sopenharmony_ci mtx_unlock(&dev->mutex); 71bf215546Sopenharmony_ci ret = VDP_STATUS_ERROR; 72bf215546Sopenharmony_ci goto no_compositor; 73bf215546Sopenharmony_ci } 74bf215546Sopenharmony_ci mtx_unlock(&dev->mutex); 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci *presentation_queue = vlAddDataHTAB(pq); 77bf215546Sopenharmony_ci if (*presentation_queue == 0) { 78bf215546Sopenharmony_ci ret = VDP_STATUS_ERROR; 79bf215546Sopenharmony_ci goto no_handle; 80bf215546Sopenharmony_ci } 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci return VDP_STATUS_OK; 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_cino_handle: 85bf215546Sopenharmony_cino_compositor: 86bf215546Sopenharmony_ci DeviceReference(&pq->device, NULL); 87bf215546Sopenharmony_ci FREE(pq); 88bf215546Sopenharmony_ci return ret; 89bf215546Sopenharmony_ci} 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_ci/** 92bf215546Sopenharmony_ci * Destroy a VdpPresentationQueue. 93bf215546Sopenharmony_ci */ 94bf215546Sopenharmony_ciVdpStatus 95bf215546Sopenharmony_civlVdpPresentationQueueDestroy(VdpPresentationQueue presentation_queue) 96bf215546Sopenharmony_ci{ 97bf215546Sopenharmony_ci vlVdpPresentationQueue *pq; 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_ci pq = vlGetDataHTAB(presentation_queue); 100bf215546Sopenharmony_ci if (!pq) 101bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci mtx_lock(&pq->device->mutex); 104bf215546Sopenharmony_ci vl_compositor_cleanup_state(&pq->cstate); 105bf215546Sopenharmony_ci mtx_unlock(&pq->device->mutex); 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ci vlRemoveDataHTAB(presentation_queue); 108bf215546Sopenharmony_ci DeviceReference(&pq->device, NULL); 109bf215546Sopenharmony_ci FREE(pq); 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci return VDP_STATUS_OK; 112bf215546Sopenharmony_ci} 113bf215546Sopenharmony_ci 114bf215546Sopenharmony_ci/** 115bf215546Sopenharmony_ci * Configure the background color setting. 116bf215546Sopenharmony_ci */ 117bf215546Sopenharmony_ciVdpStatus 118bf215546Sopenharmony_civlVdpPresentationQueueSetBackgroundColor(VdpPresentationQueue presentation_queue, 119bf215546Sopenharmony_ci VdpColor *const background_color) 120bf215546Sopenharmony_ci{ 121bf215546Sopenharmony_ci vlVdpPresentationQueue *pq; 122bf215546Sopenharmony_ci union pipe_color_union color; 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_ci if (!background_color) 125bf215546Sopenharmony_ci return VDP_STATUS_INVALID_POINTER; 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci pq = vlGetDataHTAB(presentation_queue); 128bf215546Sopenharmony_ci if (!pq) 129bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ci color.f[0] = background_color->red; 132bf215546Sopenharmony_ci color.f[1] = background_color->green; 133bf215546Sopenharmony_ci color.f[2] = background_color->blue; 134bf215546Sopenharmony_ci color.f[3] = background_color->alpha; 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_ci mtx_lock(&pq->device->mutex); 137bf215546Sopenharmony_ci vl_compositor_set_clear_color(&pq->cstate, &color); 138bf215546Sopenharmony_ci mtx_unlock(&pq->device->mutex); 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ci return VDP_STATUS_OK; 141bf215546Sopenharmony_ci} 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_ci/** 144bf215546Sopenharmony_ci * Retrieve the current background color setting. 145bf215546Sopenharmony_ci */ 146bf215546Sopenharmony_ciVdpStatus 147bf215546Sopenharmony_civlVdpPresentationQueueGetBackgroundColor(VdpPresentationQueue presentation_queue, 148bf215546Sopenharmony_ci VdpColor *const background_color) 149bf215546Sopenharmony_ci{ 150bf215546Sopenharmony_ci vlVdpPresentationQueue *pq; 151bf215546Sopenharmony_ci union pipe_color_union color; 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_ci if (!background_color) 154bf215546Sopenharmony_ci return VDP_STATUS_INVALID_POINTER; 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_ci pq = vlGetDataHTAB(presentation_queue); 157bf215546Sopenharmony_ci if (!pq) 158bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 159bf215546Sopenharmony_ci 160bf215546Sopenharmony_ci mtx_lock(&pq->device->mutex); 161bf215546Sopenharmony_ci vl_compositor_get_clear_color(&pq->cstate, &color); 162bf215546Sopenharmony_ci mtx_unlock(&pq->device->mutex); 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci background_color->red = color.f[0]; 165bf215546Sopenharmony_ci background_color->green = color.f[1]; 166bf215546Sopenharmony_ci background_color->blue = color.f[2]; 167bf215546Sopenharmony_ci background_color->alpha = color.f[3]; 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_ci return VDP_STATUS_OK; 170bf215546Sopenharmony_ci} 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_ci/** 173bf215546Sopenharmony_ci * Retrieve the presentation queue's "current" time. 174bf215546Sopenharmony_ci */ 175bf215546Sopenharmony_ciVdpStatus 176bf215546Sopenharmony_civlVdpPresentationQueueGetTime(VdpPresentationQueue presentation_queue, 177bf215546Sopenharmony_ci VdpTime *current_time) 178bf215546Sopenharmony_ci{ 179bf215546Sopenharmony_ci vlVdpPresentationQueue *pq; 180bf215546Sopenharmony_ci 181bf215546Sopenharmony_ci if (!current_time) 182bf215546Sopenharmony_ci return VDP_STATUS_INVALID_POINTER; 183bf215546Sopenharmony_ci 184bf215546Sopenharmony_ci pq = vlGetDataHTAB(presentation_queue); 185bf215546Sopenharmony_ci if (!pq) 186bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 187bf215546Sopenharmony_ci 188bf215546Sopenharmony_ci mtx_lock(&pq->device->mutex); 189bf215546Sopenharmony_ci *current_time = pq->device->vscreen->get_timestamp(pq->device->vscreen, 190bf215546Sopenharmony_ci (void *)pq->drawable); 191bf215546Sopenharmony_ci mtx_unlock(&pq->device->mutex); 192bf215546Sopenharmony_ci 193bf215546Sopenharmony_ci return VDP_STATUS_OK; 194bf215546Sopenharmony_ci} 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ci/** 197bf215546Sopenharmony_ci * Enter a surface into the presentation queue. 198bf215546Sopenharmony_ci */ 199bf215546Sopenharmony_ciVdpStatus 200bf215546Sopenharmony_civlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue, 201bf215546Sopenharmony_ci VdpOutputSurface surface, 202bf215546Sopenharmony_ci uint32_t clip_width, 203bf215546Sopenharmony_ci uint32_t clip_height, 204bf215546Sopenharmony_ci VdpTime earliest_presentation_time) 205bf215546Sopenharmony_ci{ 206bf215546Sopenharmony_ci static int dump_window = -1; 207bf215546Sopenharmony_ci 208bf215546Sopenharmony_ci vlVdpPresentationQueue *pq; 209bf215546Sopenharmony_ci vlVdpOutputSurface *surf; 210bf215546Sopenharmony_ci 211bf215546Sopenharmony_ci struct pipe_context *pipe; 212bf215546Sopenharmony_ci struct pipe_resource *tex; 213bf215546Sopenharmony_ci struct pipe_surface surf_templ, *surf_draw = NULL; 214bf215546Sopenharmony_ci struct u_rect src_rect, dst_clip, *dirty_area; 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_ci struct vl_compositor *compositor; 217bf215546Sopenharmony_ci struct vl_compositor_state *cstate; 218bf215546Sopenharmony_ci struct vl_screen *vscreen; 219bf215546Sopenharmony_ci 220bf215546Sopenharmony_ci pq = vlGetDataHTAB(presentation_queue); 221bf215546Sopenharmony_ci if (!pq) 222bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 223bf215546Sopenharmony_ci 224bf215546Sopenharmony_ci surf = vlGetDataHTAB(surface); 225bf215546Sopenharmony_ci if (!surf) 226bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 227bf215546Sopenharmony_ci 228bf215546Sopenharmony_ci pipe = pq->device->context; 229bf215546Sopenharmony_ci compositor = &pq->device->compositor; 230bf215546Sopenharmony_ci cstate = &pq->cstate; 231bf215546Sopenharmony_ci vscreen = pq->device->vscreen; 232bf215546Sopenharmony_ci 233bf215546Sopenharmony_ci mtx_lock(&pq->device->mutex); 234bf215546Sopenharmony_ci if (vscreen->set_back_texture_from_output && surf->send_to_X) 235bf215546Sopenharmony_ci vscreen->set_back_texture_from_output(vscreen, surf->surface->texture, clip_width, clip_height); 236bf215546Sopenharmony_ci tex = vscreen->texture_from_drawable(vscreen, (void *)pq->drawable); 237bf215546Sopenharmony_ci if (!tex) { 238bf215546Sopenharmony_ci mtx_unlock(&pq->device->mutex); 239bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 240bf215546Sopenharmony_ci } 241bf215546Sopenharmony_ci 242bf215546Sopenharmony_ci if (!vscreen->set_back_texture_from_output || !surf->send_to_X) { 243bf215546Sopenharmony_ci dirty_area = vscreen->get_dirty_area(vscreen); 244bf215546Sopenharmony_ci 245bf215546Sopenharmony_ci memset(&surf_templ, 0, sizeof(surf_templ)); 246bf215546Sopenharmony_ci surf_templ.format = tex->format; 247bf215546Sopenharmony_ci surf_draw = pipe->create_surface(pipe, tex, &surf_templ); 248bf215546Sopenharmony_ci 249bf215546Sopenharmony_ci dst_clip.x0 = 0; 250bf215546Sopenharmony_ci dst_clip.y0 = 0; 251bf215546Sopenharmony_ci dst_clip.x1 = clip_width ? clip_width : surf_draw->width; 252bf215546Sopenharmony_ci dst_clip.y1 = clip_height ? clip_height : surf_draw->height; 253bf215546Sopenharmony_ci 254bf215546Sopenharmony_ci src_rect.x0 = 0; 255bf215546Sopenharmony_ci src_rect.y0 = 0; 256bf215546Sopenharmony_ci src_rect.x1 = surf_draw->width; 257bf215546Sopenharmony_ci src_rect.y1 = surf_draw->height; 258bf215546Sopenharmony_ci 259bf215546Sopenharmony_ci vl_compositor_clear_layers(cstate); 260bf215546Sopenharmony_ci vl_compositor_set_rgba_layer(cstate, compositor, 0, surf->sampler_view, &src_rect, NULL, NULL); 261bf215546Sopenharmony_ci vl_compositor_set_dst_clip(cstate, &dst_clip); 262bf215546Sopenharmony_ci vl_compositor_render(cstate, compositor, surf_draw, dirty_area, true); 263bf215546Sopenharmony_ci } 264bf215546Sopenharmony_ci 265bf215546Sopenharmony_ci vscreen->set_next_timestamp(vscreen, earliest_presentation_time); 266bf215546Sopenharmony_ci 267bf215546Sopenharmony_ci // flush before calling flush_frontbuffer so that rendering is flushed 268bf215546Sopenharmony_ci // to back buffer so the texture can be copied in flush_frontbuffer 269bf215546Sopenharmony_ci pipe->screen->fence_reference(pipe->screen, &surf->fence, NULL); 270bf215546Sopenharmony_ci pipe->flush(pipe, &surf->fence, 0); 271bf215546Sopenharmony_ci pipe->screen->flush_frontbuffer(pipe->screen, pipe, tex, 0, 0, 272bf215546Sopenharmony_ci vscreen->get_private(vscreen), NULL); 273bf215546Sopenharmony_ci 274bf215546Sopenharmony_ci pq->last_surf = surf; 275bf215546Sopenharmony_ci 276bf215546Sopenharmony_ci if (dump_window == -1) { 277bf215546Sopenharmony_ci dump_window = debug_get_num_option("VDPAU_DUMP", 0); 278bf215546Sopenharmony_ci } 279bf215546Sopenharmony_ci 280bf215546Sopenharmony_ci if (dump_window) { 281bf215546Sopenharmony_ci static unsigned int framenum = 0; 282bf215546Sopenharmony_ci char cmd[256]; 283bf215546Sopenharmony_ci 284bf215546Sopenharmony_ci if (framenum) { 285bf215546Sopenharmony_ci sprintf(cmd, "xwd -id %d -silent -out vdpau_frame_%08d.xwd", (int)pq->drawable, framenum); 286bf215546Sopenharmony_ci if (system(cmd) != 0) 287bf215546Sopenharmony_ci VDPAU_MSG(VDPAU_ERR, "[VDPAU] Dumping surface %d failed.\n", surface); 288bf215546Sopenharmony_ci } 289bf215546Sopenharmony_ci framenum++; 290bf215546Sopenharmony_ci } 291bf215546Sopenharmony_ci 292bf215546Sopenharmony_ci if (!vscreen->set_back_texture_from_output || !surf->send_to_X) { 293bf215546Sopenharmony_ci pipe_resource_reference(&tex, NULL); 294bf215546Sopenharmony_ci pipe_surface_reference(&surf_draw, NULL); 295bf215546Sopenharmony_ci } 296bf215546Sopenharmony_ci mtx_unlock(&pq->device->mutex); 297bf215546Sopenharmony_ci 298bf215546Sopenharmony_ci return VDP_STATUS_OK; 299bf215546Sopenharmony_ci} 300bf215546Sopenharmony_ci 301bf215546Sopenharmony_ci/** 302bf215546Sopenharmony_ci * Wait for a surface to finish being displayed. 303bf215546Sopenharmony_ci */ 304bf215546Sopenharmony_ciVdpStatus 305bf215546Sopenharmony_civlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue, 306bf215546Sopenharmony_ci VdpOutputSurface surface, 307bf215546Sopenharmony_ci VdpTime *first_presentation_time) 308bf215546Sopenharmony_ci{ 309bf215546Sopenharmony_ci vlVdpPresentationQueue *pq; 310bf215546Sopenharmony_ci vlVdpOutputSurface *surf; 311bf215546Sopenharmony_ci struct pipe_screen *screen; 312bf215546Sopenharmony_ci 313bf215546Sopenharmony_ci if (!first_presentation_time) 314bf215546Sopenharmony_ci return VDP_STATUS_INVALID_POINTER; 315bf215546Sopenharmony_ci 316bf215546Sopenharmony_ci pq = vlGetDataHTAB(presentation_queue); 317bf215546Sopenharmony_ci if (!pq) 318bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 319bf215546Sopenharmony_ci 320bf215546Sopenharmony_ci surf = vlGetDataHTAB(surface); 321bf215546Sopenharmony_ci if (!surf) 322bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 323bf215546Sopenharmony_ci 324bf215546Sopenharmony_ci mtx_lock(&pq->device->mutex); 325bf215546Sopenharmony_ci if (surf->fence) { 326bf215546Sopenharmony_ci screen = pq->device->vscreen->pscreen; 327bf215546Sopenharmony_ci screen->fence_finish(screen, NULL, surf->fence, PIPE_TIMEOUT_INFINITE); 328bf215546Sopenharmony_ci screen->fence_reference(screen, &surf->fence, NULL); 329bf215546Sopenharmony_ci } 330bf215546Sopenharmony_ci mtx_unlock(&pq->device->mutex); 331bf215546Sopenharmony_ci 332bf215546Sopenharmony_ci return vlVdpPresentationQueueGetTime(presentation_queue, first_presentation_time); 333bf215546Sopenharmony_ci} 334bf215546Sopenharmony_ci 335bf215546Sopenharmony_ci/** 336bf215546Sopenharmony_ci * Poll the current queue status of a surface. 337bf215546Sopenharmony_ci */ 338bf215546Sopenharmony_ciVdpStatus 339bf215546Sopenharmony_civlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue, 340bf215546Sopenharmony_ci VdpOutputSurface surface, 341bf215546Sopenharmony_ci VdpPresentationQueueStatus *status, 342bf215546Sopenharmony_ci VdpTime *first_presentation_time) 343bf215546Sopenharmony_ci{ 344bf215546Sopenharmony_ci vlVdpPresentationQueue *pq; 345bf215546Sopenharmony_ci vlVdpOutputSurface *surf; 346bf215546Sopenharmony_ci struct pipe_screen *screen; 347bf215546Sopenharmony_ci 348bf215546Sopenharmony_ci if (!(status && first_presentation_time)) 349bf215546Sopenharmony_ci return VDP_STATUS_INVALID_POINTER; 350bf215546Sopenharmony_ci 351bf215546Sopenharmony_ci pq = vlGetDataHTAB(presentation_queue); 352bf215546Sopenharmony_ci if (!pq) 353bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 354bf215546Sopenharmony_ci 355bf215546Sopenharmony_ci surf = vlGetDataHTAB(surface); 356bf215546Sopenharmony_ci if (!surf) 357bf215546Sopenharmony_ci return VDP_STATUS_INVALID_HANDLE; 358bf215546Sopenharmony_ci 359bf215546Sopenharmony_ci *first_presentation_time = 0; 360bf215546Sopenharmony_ci 361bf215546Sopenharmony_ci if (!surf->fence) { 362bf215546Sopenharmony_ci if (pq->last_surf == surf) 363bf215546Sopenharmony_ci *status = VDP_PRESENTATION_QUEUE_STATUS_VISIBLE; 364bf215546Sopenharmony_ci else 365bf215546Sopenharmony_ci *status = VDP_PRESENTATION_QUEUE_STATUS_IDLE; 366bf215546Sopenharmony_ci } else { 367bf215546Sopenharmony_ci mtx_lock(&pq->device->mutex); 368bf215546Sopenharmony_ci screen = pq->device->vscreen->pscreen; 369bf215546Sopenharmony_ci if (screen->fence_finish(screen, NULL, surf->fence, 0)) { 370bf215546Sopenharmony_ci screen->fence_reference(screen, &surf->fence, NULL); 371bf215546Sopenharmony_ci *status = VDP_PRESENTATION_QUEUE_STATUS_VISIBLE; 372bf215546Sopenharmony_ci mtx_unlock(&pq->device->mutex); 373bf215546Sopenharmony_ci 374bf215546Sopenharmony_ci // We actually need to query the timestamp of the last VSYNC event from the hardware 375bf215546Sopenharmony_ci vlVdpPresentationQueueGetTime(presentation_queue, first_presentation_time); 376bf215546Sopenharmony_ci *first_presentation_time += 1; 377bf215546Sopenharmony_ci } else { 378bf215546Sopenharmony_ci *status = VDP_PRESENTATION_QUEUE_STATUS_QUEUED; 379bf215546Sopenharmony_ci mtx_unlock(&pq->device->mutex); 380bf215546Sopenharmony_ci } 381bf215546Sopenharmony_ci } 382bf215546Sopenharmony_ci 383bf215546Sopenharmony_ci return VDP_STATUS_OK; 384bf215546Sopenharmony_ci} 385