<commit_before>/*
 * Copyright 2013  <NAME>
 *
 * This file is part of libvdpau-va-gl
 *
 * libvdpau-va-gl is distributed under the terms of LGPLv3. See COPYING for details.
 */

#define GL_GLEXT_PROTOTYPES
#define _XOPEN_SOURCE 500
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#include <vdpau/vdpau.h>
#include <GL/gl.h>
#include "ctx-stack.h"
#include "globals.h"
#include "handle-storage.h"
#include "vdpau-locking.h"
#include "vdpau-soft.h"
#include "vdpau-trace.h"
#include "watermark.h"

static
VdpTime
timespec2vdptime(struct timespec t)
{
    return (uint64_t)t.tv_sec * 1000 * 1000 * 1000 + t.tv_nsec;
}

static
struct timespec
vdptime2timespec(VdpTime t)
{
    struct timespec res;
    res.tv_sec = t / (1000*1000*1000);
    res.tv_nsec = t % (1000*1000*1000);
    return res;
}

VdpStatus
softVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue,
                                              VdpOutputSurface surface,
                                              VdpTime *first_presentation_time)

{
    VdpPresentationQueueData *pqData =
        handlestorage_get(presentation_queue, HANDLETYPE_PRESENTATION_QUEUE);
    if (NULL == pqData)
        return VDP_STATUS_INVALID_HANDLE;

    VdpOutputSurfaceData *surfData = handlestorage_get(surface, HANDLETYPE_OUTPUT_SURFACE);
    if (NULL == surfData)
        return VDP_STATUS_INVALID_HANDLE;

    // TODO: use locking instead of busy loop
    while (surfData->status != VDP_PRESENTATION_QUEUE_STATUS_IDLE) {
        usleep(1000);
    }

    *first_presentation_time = surfData->first_presentation_time;
    return VDP_STATUS_OK;
}

VdpStatus
softVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue,
                                           VdpOutputSurface surface,
                                           VdpPresentationQueueStatus *status,
                                           VdpTime *first_presentation_time)
{
    VdpPresentationQueueData *pqData =
        handlestorage_get(presentation_queue, HANDLETYPE_PRESENTATION_QUEUE);
    if (NULL == pqData)
        return VDP_STATUS_INVALID_HANDLE;
    VdpOutputSurfaceData *surfData = handlestorage_get(surface, HANDLETYPE_OUTPUT_SURFACE);
    if (NULL == surfData)
        return VDP_STATUS_INVALID_HANDLE;
    if (NULL == status)
        return VDP_STATUS_INVALID_POINTER;

    *status = surfData->status;
    *first_presentation_time = surfData->first_presentation_time;

    return VDP_STATUS_OK;
}

static
void
do_presentation_queue_display(VdpPresentationQueueData *pqueueData)
{
    static VdpOutputSurfaceData *previousSurfData = NULL;

    acquire_global_lock();
    pthread_mutex_lock(&pqueueData->queue_mutex);
    assert(pqueueData->queue.used > 0);
    const int entry = pqueueData->queue.head;

    VdpDeviceData *deviceData = pqueueData->device;
    VdpOutputSurfaceData *surfData = pqueueData->queue.item[entry].surfData;
    const uint32_t clip_width = pqueueData->queue.item[entry].clip_width;
    const uint32_t clip_height = pqueueData->queue.item[entry].clip_height;

    // remove first entry from queue
    pqueueData->queue.used --;
    pqueueData->queue.freelist[pqueueData->queue.head] = pqueueData->queue.firstfree;
    pqueueData->queue.firstfree = pqueueData->queue.head;
    pqueueData->queue.head = pqueueData->queue.item[pqueueData->queue.head].next;
    pthread_mutex_unlock(&pqueueData->queue_mutex);

    glx_context_push_global(deviceData->display, pqueueData->target->drawable, pqueueData->target->glc);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    const uint32_t target_width  = (clip_width > 0)  ? clip_width  : surfData->width;
    const uint32_t target_height = (clip_height > 0) ? clip_height : surfData->height;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, target_width, target_height, 0, -1.0, 1.0);
    glViewport(0, 0, target_width, target_height);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();<commit_msg>drop redundant framebuffer selection in presentation queue thread<commit_after>/*
 * Copyright 2013  <NAME>
 *
 * This file is part of libvdpau-va-gl
 *
 * libvdpau-va-gl is distributed under the terms of LGPLv3. See COPYING for details.
 */

#define GL_GLEXT_PROTOTYPES
#define _XOPEN_SOURCE 500
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#include <vdpau/vdpau.h>
#include <GL/gl.h>
#include "ctx-stack.h"
#include "globals.h"
#include "handle-storage.h"
#include "vdpau-locking.h"
#include "vdpau-soft.h"
#include "vdpau-trace.h"
#include "watermark.h"

static
VdpTime
timespec2vdptime(struct timespec t)
{
    return (uint64_t)t.tv_sec * 1000 * 1000 * 1000 + t.tv_nsec;
}

static
struct timespec
vdptime2timespec(VdpTime t)
{
    struct timespec res;
    res.tv_sec = t / (1000*1000*1000);
    res.tv_nsec = t % (1000*1000*1000);
    return res;
}

VdpStatus
softVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue,
                                              VdpOutputSurface surface,
                                              VdpTime *first_presentation_time)

{
    VdpPresentationQueueData *pqData =
        handlestorage_get(presentation_queue, HANDLETYPE_PRESENTATION_QUEUE);
    if (NULL == pqData)
        return VDP_STATUS_INVALID_HANDLE;

    VdpOutputSurfaceData *surfData = handlestorage_get(surface, HANDLETYPE_OUTPUT_SURFACE);
    if (NULL == surfData)
        return VDP_STATUS_INVALID_HANDLE;

    // TODO: use locking instead of busy loop
    while (surfData->status != VDP_PRESENTATION_QUEUE_STATUS_IDLE) {
        usleep(1000);
    }

    *first_presentation_time = surfData->first_presentation_time;
    return VDP_STATUS_OK;
}

VdpStatus
softVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue,
                                           VdpOutputSurface surface,
                                           VdpPresentationQueueStatus *status,
                                           VdpTime *first_presentation_time)
{
    VdpPresentationQueueData *pqData =
        handlestorage_get(presentation_queue, HANDLETYPE_PRESENTATION_QUEUE);
    if (NULL == pqData)
        return VDP_STATUS_INVALID_HANDLE;
    VdpOutputSurfaceData *surfData = handlestorage_get(surface, HANDLETYPE_OUTPUT_SURFACE);
    if (NULL == surfData)
        return VDP_STATUS_INVALID_HANDLE;
    if (NULL == status)
        return VDP_STATUS_INVALID_POINTER;

    *status = surfData->status;
    *first_presentation_time = surfData->first_presentation_time;

    return VDP_STATUS_OK;
}

static
void
do_presentation_queue_display(VdpPresentationQueueData *pqueueData)
{
    static VdpOutputSurfaceData *previousSurfData = NULL;

    acquire_global_lock();
    pthread_mutex_lock(&pqueueData->queue_mutex);
    assert(pqueueData->queue.used > 0);
    const int entry = pqueueData->queue.head;

    VdpDeviceData *deviceData = pqueueData->device;
    VdpOutputSurfaceData *surfData = pqueueData->queue.item[entry].surfData;
    const uint32_t clip_width = pqueueData->queue.item[entry].clip_width;
    const uint32_t clip_height = pqueueData->queue.item[entry].clip_height;

    // remove first entry from queue
    pqueueData->queue.used --;
    pqueueData->queue.freelist[pqueueData->queue.head] = pqueueData->queue.firstfree;
    pqueueData->queue.firstfree = pqueueData->queue.head;
    pqueueData->queue.head = pqueueData->queue.item[pqueueData->queue.head].next;
    pthread_mutex_unlock(&pqueueData->queue_mutex);

    glx_context_push_global(deviceData->display, pqueueData->target->drawable, pqueueData->target->glc);

    const uint32_t target_width  = (clip_width > 0)  ? clip_width  : surfData->width;
    const uint32_t target_height = (clip_height > 0) ? clip_height : surfData->height;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, target_width, target_height, 0, -1.0, 1.0);
    glViewport(0, 0, target_width, target_height);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
{'fraction_non_alphanumeric': 0.09623015873015874, 'fraction_numerical': 0.01773313492063492, 'mean_word_length': 3.5462232243517473, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4400158', 'n_tokens_mistral': 2778, 'n_tokens_neox': 2592, 'n_words': 476}