summaryrefslogtreecommitdiffstats
path: root/src/VBox/GuestHost/OpenGL/packer/pack_context.c
blob: 775a3d4159efbb26721fad372f31d03ded502c59 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* Copyright (c) 2001, Stanford University
 * All rights reserved
 *
 * See the file LICENSE.txt for information on redistributing this software.
 */

#include "packer.h"
#include "cr_opcodes.h"
#include "cr_mem.h"
#include "cr_string.h"


/* XXX duplicated in unpack_context.c */
#define DISPLAY_NAME_LEN 256

#define WRITE_BYTES( offset, data, len ) \
  crMemcpy( data_ptr + (offset), data, len )

void PACK_APIENTRY
crPackCreateContext( const char *dpyName, GLint visual, GLint shareCtx,
                     GLint *return_value, int *writeback )
{
	char displayName[DISPLAY_NAME_LEN];
	CR_GET_PACKER_CONTEXT(pc);
	unsigned char *data_ptr;
        int len = DISPLAY_NAME_LEN + 32;

	/* clear the buffer, to silence valgrind */
	crMemZero(displayName, DISPLAY_NAME_LEN);

	if (dpyName) {
		crStrncpy( displayName, dpyName, DISPLAY_NAME_LEN );
		displayName[DISPLAY_NAME_LEN - 1] = 0;
	}
	else {
		displayName[0] = 0;
	}

	CR_GET_BUFFERED_POINTER(pc, len);
	WRITE_DATA( 0, GLint, len );
	WRITE_DATA( 4, GLenum, CR_CREATECONTEXT_EXTEND_OPCODE );
	WRITE_BYTES( 8, displayName, DISPLAY_NAME_LEN );
	WRITE_DATA( DISPLAY_NAME_LEN + 8, GLint, visual );
	WRITE_DATA( DISPLAY_NAME_LEN + 12, GLint, shareCtx );
	WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 16, (void *) return_value );
	WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 24, (void *) writeback );
	WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
	CR_CMDBLOCK_CHECK_FLUSH(pc);
    CR_UNLOCK_PACKER_CONTEXT(pc);
}

void PACK_APIENTRY
crPackCreateContextSWAP( const char *dpyName, GLint visual, GLint shareCtx,
                         GLint *return_value, int *writeback )
{
	char displayName[DISPLAY_NAME_LEN];
	CR_GET_PACKER_CONTEXT(pc);
	unsigned char *data_ptr;
        int len = DISPLAY_NAME_LEN + 32;

	/* clear the buffer, to silence valgrind */
	crMemZero(displayName, DISPLAY_NAME_LEN);

	if (dpyName) {
		crStrncpy( displayName, dpyName, DISPLAY_NAME_LEN );
		displayName[DISPLAY_NAME_LEN - 1] = 0;
	}
	else {
		displayName[0] = 0;
	}

	CR_GET_BUFFERED_POINTER(pc, len);
	WRITE_DATA( 0, GLint, SWAP32(len) );
	WRITE_DATA( 4, GLenum, SWAP32(CR_CREATECONTEXT_EXTEND_OPCODE) );
	WRITE_BYTES( 8, displayName, DISPLAY_NAME_LEN );
	WRITE_DATA( DISPLAY_NAME_LEN + 8, GLenum, SWAP32(visual) );
	WRITE_DATA( DISPLAY_NAME_LEN + 12, GLenum, SWAP32(shareCtx) );
	WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 16, (void *) return_value );
	WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 24, (void *) writeback );
	WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
	CR_CMDBLOCK_CHECK_FLUSH(pc);
    CR_UNLOCK_PACKER_CONTEXT(pc);
}


void PACK_APIENTRY crPackWindowCreate( const char *dpyName, GLint visBits, GLint *return_value, int *writeback )
{
	char displayName[DISPLAY_NAME_LEN];
	CR_GET_PACKER_CONTEXT(pc);
	unsigned char *data_ptr;

	/* clear the buffer, to silence valgrind */
	crMemZero(displayName, DISPLAY_NAME_LEN);

	if (dpyName) {
		crStrncpy( displayName, dpyName, DISPLAY_NAME_LEN );
		displayName[DISPLAY_NAME_LEN - 1] = 0;
	}
	else {
		displayName[0] = 0;
	}

	CR_GET_BUFFERED_POINTER(pc, DISPLAY_NAME_LEN + 28 );
	WRITE_DATA( 0, GLint, 28 );
	WRITE_DATA( 4, GLenum, CR_WINDOWCREATE_EXTEND_OPCODE );
	WRITE_BYTES( 8, displayName, DISPLAY_NAME_LEN );
	WRITE_DATA( DISPLAY_NAME_LEN + 8, GLint, visBits );
	WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 12, (void *) return_value );
	WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 20, (void *) writeback );
	WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
	CR_CMDBLOCK_CHECK_FLUSH(pc);
    CR_UNLOCK_PACKER_CONTEXT(pc);
}

void PACK_APIENTRY crPackWindowCreateSWAP( const char *dpyName, GLint visBits, GLint *return_value, int *writeback )
{
	char displayName[DISPLAY_NAME_LEN];
	CR_GET_PACKER_CONTEXT(pc);
	unsigned char *data_ptr;

	/* clear the buffer, to silence valgrind */
	crMemZero(displayName, DISPLAY_NAME_LEN);

	if (dpyName) {
		crStrncpy( displayName, dpyName, DISPLAY_NAME_LEN );
		displayName[DISPLAY_NAME_LEN - 1] = 0;
	}
	else {
		displayName[0] = 0;
	}

	CR_GET_BUFFERED_POINTER(pc, DISPLAY_NAME_LEN + 28 );
	WRITE_DATA( 0, GLint, SWAP32(28) );
	WRITE_DATA( 4, GLenum, SWAP32(CR_WINDOWCREATE_EXTEND_OPCODE) );
	WRITE_BYTES( 8, displayName, DISPLAY_NAME_LEN );
	WRITE_DATA( DISPLAY_NAME_LEN + 8, GLint, SWAP32(visBits) );
	WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 12, (void *) return_value );
	WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 20, (void *) writeback );
	WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
	CR_CMDBLOCK_CHECK_FLUSH(pc);
    CR_UNLOCK_PACKER_CONTEXT(pc);
}