VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/packer/pack_pixels.c@ 40708

Last change on this file since 40708 was 33475, checked in by vboxsync, 14 years ago

crOpenGL/wddm: multithreading fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.0 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include "packer.h"
8#include "cr_pixeldata.h"
9#include "cr_error.h"
10#include "cr_mem.h"
11#include "cr_version.h"
12
13
14void PACK_APIENTRY crPackDrawPixels(GLsizei width, GLsizei height,
15 GLenum format, GLenum type,
16 const GLvoid *pixels,
17 const CRPixelPackState *unpackstate )
18{
19 unsigned char *data_ptr;
20 int packet_length, imagesize;
21 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
22
23 packet_length =
24 sizeof( width ) +
25 sizeof( height ) +
26 sizeof( format ) +
27 sizeof( type ) + sizeof(int) + sizeof(GLint);
28
29 if (!noimagedata)
30 {
31 imagesize = crImageSize( format, type, width, height );
32
33 if (imagesize<=0)
34 {
35 crDebug("crPackDrawPixels: 0 image size, ignoring");
36 return;
37 }
38 packet_length += imagesize;
39 }
40
41 data_ptr = (unsigned char *) crPackAlloc( packet_length );
42 WRITE_DATA( 0, GLsizei, width );
43 WRITE_DATA( 4, GLsizei, height );
44 WRITE_DATA( 8, GLenum, format );
45 WRITE_DATA( 12, GLenum, type );
46 WRITE_DATA( 16, GLint, noimagedata );
47 WRITE_DATA( 20, GLint, (GLint) (uintptr_t) pixels );
48
49 if (!noimagedata)
50 {
51 crPixelCopy2D(width, height,
52 (void *) (data_ptr + 24), format, type, NULL, /* dst */
53 pixels, format, type, unpackstate); /* src */
54 }
55
56 crHugePacket( CR_DRAWPIXELS_OPCODE, data_ptr );
57 crPackFree( data_ptr );
58}
59
60void PACK_APIENTRY crPackReadPixels(GLint x, GLint y, GLsizei width,
61 GLsizei height, GLenum format,
62 GLenum type, GLvoid *pixels,
63 const CRPixelPackState *packstate,
64 int *writeback)
65{
66 CR_GET_PACKER_CONTEXT(pc);
67 unsigned char *data_ptr;
68 GLint stride = 0;
69 GLint bytes_per_row;
70 int bytes_per_pixel;
71 (void)writeback;
72
73 bytes_per_pixel = crPixelSize(format, type);
74 if (bytes_per_pixel <= 0) {
75 char string[80];
76 sprintf(string, "crPackReadPixels(format 0x%x or type 0x%x)", format, type);
77 __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, string);
78 return;
79 }
80
81 /* default bytes_per_row so crserver can allocate memory */
82 bytes_per_row = width * bytes_per_pixel;
83
84 stride = bytes_per_row;
85 if (packstate->alignment != 1) {
86 GLint remainder = bytes_per_row % packstate->alignment;
87 if (remainder)
88 stride = bytes_per_row + (packstate->alignment - remainder);
89 }
90
91 CR_GET_BUFFERED_POINTER(pc, 48 + sizeof(CRNetworkPointer) );
92 WRITE_DATA( 0, GLint, x );
93 WRITE_DATA( 4, GLint, y );
94 WRITE_DATA( 8, GLsizei, width );
95 WRITE_DATA( 12, GLsizei, height );
96 WRITE_DATA( 16, GLenum, format );
97 WRITE_DATA( 20, GLenum, type );
98 WRITE_DATA( 24, GLint, stride ); /* XXX not really used! */
99 WRITE_DATA( 28, GLint, packstate->alignment );
100 WRITE_DATA( 32, GLint, packstate->skipRows );
101 WRITE_DATA( 36, GLint, packstate->skipPixels );
102 WRITE_DATA( 40, GLint, bytes_per_row );
103 WRITE_DATA( 44, GLint, packstate->rowLength );
104 WRITE_NETWORK_POINTER( 48, (char *) pixels );
105 WRITE_OPCODE( pc, CR_READPIXELS_OPCODE );
106 CR_UNLOCK_PACKER_CONTEXT(pc);
107}
108
109/* Round N up to the next multiple of 8 */
110#define CEIL8(N) (((N) + 7) & ~0x7)
111
112void PACK_APIENTRY crPackBitmap(GLsizei width, GLsizei height,
113 GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,
114 const GLubyte *bitmap, const CRPixelPackState *unpack )
115{
116 const int noimagedata = (bitmap == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
117 unsigned char *data_ptr;
118 int data_length = 0;
119 GLubyte *destBitmap = NULL;
120 int packet_length =
121 sizeof( width ) +
122 sizeof( height ) +
123 sizeof( xorig ) +
124 sizeof( yorig ) +
125 sizeof( xmove ) +
126 sizeof( ymove ) +
127 sizeof( GLuint ) + sizeof(GLint);
128
129 if (!noimagedata)
130 {
131 data_length = CEIL8(width) * height / 8;
132 packet_length += data_length;
133 }
134
135 data_ptr = (unsigned char *) crPackAlloc( packet_length );
136
137 WRITE_DATA( 0, GLsizei, width );
138 WRITE_DATA( 4, GLsizei, height );
139 WRITE_DATA( 8, GLfloat, xorig );
140 WRITE_DATA( 12, GLfloat, yorig );
141 WRITE_DATA( 16, GLfloat, xmove );
142 WRITE_DATA( 20, GLfloat, ymove );
143 WRITE_DATA( 24, GLuint, noimagedata );
144 WRITE_DATA( 28, GLint, (GLint) (uintptr_t) bitmap);
145
146 crBitmapCopy(width, height, (GLubyte *)(data_ptr + 32), bitmap, unpack);
147
148 crHugePacket( CR_BITMAP_OPCODE, data_ptr );
149 crPackFree( data_ptr );
150}
151/*
152 ZPix - compressed DrawPixels
153*/
154void PACK_APIENTRY crPackZPixCR( GLsizei width, GLsizei height,
155 GLenum format, GLenum type,
156 GLenum ztype, GLint zparm, GLint length,
157 const GLvoid *pixels,
158 const CRPixelPackState *unpackstate )
159{
160 unsigned char *data_ptr;
161 int packet_length;
162 (void)unpackstate;
163
164 if (pixels == NULL)
165 {
166 return;
167 }
168
169 packet_length =
170 sizeof( int ) + /* packet size */
171 sizeof( GLenum ) + /* extended opcode */
172 sizeof( width ) +
173 sizeof( height ) +
174 sizeof( format ) +
175 sizeof( type ) +
176 sizeof( ztype ) +
177 sizeof( zparm ) +
178 sizeof( length );
179
180 packet_length += length;
181
182/* XXX JAG
183 crDebug("PackZPixCR: fb %d x %d, state %d, zlen = %d, plen = %d",
184 width, height, ztype, length, packet_length);
185*/
186 data_ptr = (unsigned char *) crPackAlloc( packet_length );
187 WRITE_DATA( 0, GLenum , CR_ZPIXCR_EXTEND_OPCODE );
188 WRITE_DATA( 4, GLsizei, width );
189 WRITE_DATA( 8, GLsizei, height );
190 WRITE_DATA( 12, GLenum, format );
191 WRITE_DATA( 16, GLenum, type );
192 WRITE_DATA( 20, GLenum, ztype );
193 WRITE_DATA( 24, GLint, zparm );
194 WRITE_DATA( 28, GLint, length );
195
196 crMemcpy((void *) (data_ptr+32), pixels, length);
197
198 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
199 crPackFree( data_ptr );
200}
201
202
203void PACK_APIENTRY
204crPackGetTexImage( GLenum target, GLint level, GLenum format, GLenum type,
205 GLvoid * pixels, const CRPixelPackState * packstate,
206 int * writeback )
207{
208 CR_GET_PACKER_CONTEXT(pc);
209 unsigned char *data_ptr;
210 (void) pc;
211 CR_GET_BUFFERED_POINTER( pc, 40 );
212 WRITE_DATA( 0, GLint, 40 );
213 WRITE_DATA( 4, GLenum, CR_GETTEXIMAGE_EXTEND_OPCODE );
214 WRITE_DATA( 8, GLenum, target );
215 WRITE_DATA( 12, GLint, level );
216 WRITE_DATA( 16, GLenum, format );
217 WRITE_DATA( 20, GLenum, type );
218 WRITE_NETWORK_POINTER( 24, (void *) pixels );
219 WRITE_NETWORK_POINTER( 32, (void *) writeback );
220 WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
221 CR_UNLOCK_PACKER_CONTEXT(pc);
222}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette