summaryrefslogtreecommitdiffstats
path: root/src/VBox/Additions/common/crOpenGL/pack/packspu_swapbuf.c
blob: bc1895fe3fd49a9a1ec4cccab21c1f8be7a4b057 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* Copyright (c) 2001, Stanford University
 * All rights reserved
 *
 * See the file LICENSE.txt for information on redistributing this software.
 */

#include "cr_packfunctions.h"
#include "cr_error.h"
#include "cr_net.h"
#include "packspu.h"
#include "packspu_proto.h"

#if 0

void PACKSPU_APIENTRY packspu_SwapBuffers( GLint window, GLint flags )
{
    GET_THREAD(thread);
    if (pack_spu.swap)
    {
        crPackSwapBuffersSWAP( window, flags );
    }
    else
    {
        crPackSwapBuffers( window, flags );
    }
    packspuFlush( (void *) thread );
}


#else

void PACKSPU_APIENTRY packspu_SwapBuffers( GLint window, GLint flags )
{
    GET_THREAD(thread);

    if (pack_spu.swap)
    {
        crPackSwapBuffersSWAP( window, flags );
    }
    else
    {
        crPackSwapBuffers( window, flags );
    }
    packspuFlush( (void *) thread );

    if (!(thread->netServer.conn->actual_network))
    {
        /* no synchronization needed */
        return;
    }

    if (pack_spu.swapbuffer_sync) {
        /* This won't block unless there has been more than 1 frame
         * since we received a writeback acknowledgement.  In the
         * normal case there's no performance penalty for doing this
         * (beyond the cost of packing the writeback request into the
         * stream and receiving the reply), but it eliminates the
         * problem of runaway rendering that can occur, eg when
         * rendering frames consisting of a single large display list
         * in a tight loop.
         *
         * Note that this is *not* the same as doing a sync after each
         * swapbuffers, which would force a round-trip 'bubble' into
         * the network stream under normal conditions.
         *
         * This is complicated because writeback in the pack spu is
         * overridden to always set the value to zero when the
         * reply is received, rather than decrementing it:
         */
        switch( thread->writeback ) {
        case 0:
            /* Request writeback.
             */
            thread->writeback = 1;
            if (pack_spu.swap)
            {
                crPackWritebackSWAP( (GLint *) &thread->writeback );
            }
            else
            {
                crPackWriteback( (GLint *) &thread->writeback );
            }
            break;
        case 1:
            /* Make sure writeback from previous frame has been received.
             */
            CRPACKSPU_WRITEBACK_WAIT(thread, thread->writeback);
            break;
        }
    }

    /* want to emit a parameter here */
    if (pack_spu.emit_GATHER_POST_SWAPBUFFERS)
    {
        if (pack_spu.swap)
            crPackChromiumParameteriCRSWAP(GL_GATHER_POST_SWAPBUFFERS_CR, 1);
        else
            crPackChromiumParameteriCR(GL_GATHER_POST_SWAPBUFFERS_CR, 1);
    }
}

#endif