VirtualBox

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

最後變更 在這個檔案從24684是 21854,由 vboxsync 提交於 16 年 前

crOpenGL: ignore gldrawpixels with incorrect type/format

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 7.2 KB
 
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
22 if (pixels == NULL)
23 {
24 return;
25 }
26
27#if 0
28 /* WHAT IS THIS FOR? Disabled by Brian on 3 Dec 2003 */
29 if (type == GL_BITMAP)
30 {
31 crPackBitmap( width, height, 0, 0, 0, 0,
32 (const GLubyte *) pixels, unpackstate );
33 }
34#endif
35
36 packet_length =
37 sizeof( width ) +
38 sizeof( height ) +
39 sizeof( format ) +
40 sizeof( type );
41
42 imagesize = crImageSize( format, type, width, height );
43
44 if (imagesize<=0)
45 {
46 crDebug("crPackDrawPixels: 0 image size, ignoring");
47 return;
48 }
49
50 packet_length += imagesize;
51
52 data_ptr = (unsigned char *) crPackAlloc( packet_length );
53 WRITE_DATA( 0, GLsizei, width );
54 WRITE_DATA( 4, GLsizei, height );
55 WRITE_DATA( 8, GLenum, format );
56 WRITE_DATA( 12, GLenum, type );
57
58 crPixelCopy2D( width, height,
59 (void *) (data_ptr + 16), format, type, NULL, /* dst */
60 pixels, format, type, unpackstate ); /* src */
61
62 crHugePacket( CR_DRAWPIXELS_OPCODE, data_ptr );
63 crPackFree( data_ptr );
64}
65
66void PACK_APIENTRY crPackReadPixels( GLint x, GLint y, GLsizei width,
67 GLsizei height, GLenum format,
68 GLenum type, GLvoid *pixels,
69 const CRPixelPackState *packstate,
70 int *writeback)
71{
72 GET_PACKER_CONTEXT(pc);
73 unsigned char *data_ptr;
74 GLint stride = 0;
75 GLint bytes_per_row;
76 int bytes_per_pixel;
77 (void)writeback;
78
79 bytes_per_pixel = crPixelSize(format, type);
80 if (bytes_per_pixel <= 0) {
81 char string[80];
82 sprintf(string, "crPackReadPixels(format 0x%x or type 0x%x)", format, type);
83 __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, string);
84 return;
85 }
86
87 /* default bytes_per_row so crserver can allocate memory */
88 bytes_per_row = width * bytes_per_pixel;
89
90 stride = bytes_per_row;
91 if (packstate->alignment != 1) {
92 GLint remainder = bytes_per_row % packstate->alignment;
93 if (remainder)
94 stride = bytes_per_row + (packstate->alignment - remainder);
95 }
96
97 GET_BUFFERED_POINTER(pc, 48 + sizeof(CRNetworkPointer) );
98 WRITE_DATA( 0, GLint, x );
99 WRITE_DATA( 4, GLint, y );
100 WRITE_DATA( 8, GLsizei, width );
101 WRITE_DATA( 12, GLsizei, height );
102 WRITE_DATA( 16, GLenum, format );
103 WRITE_DATA( 20, GLenum, type );
104 WRITE_DATA( 24, GLint, stride ); /* XXX not really used! */
105 WRITE_DATA( 28, GLint, packstate->alignment );
106 WRITE_DATA( 32, GLint, packstate->skipRows );
107 WRITE_DATA( 36, GLint, packstate->skipPixels );
108 WRITE_DATA( 40, GLint, bytes_per_row );
109 WRITE_DATA( 44, GLint, packstate->rowLength );
110 WRITE_NETWORK_POINTER( 48, (char *) pixels );
111 WRITE_OPCODE( pc, CR_READPIXELS_OPCODE );
112}
113
114/* Round N up to the next multiple of 8 */
115#define CEIL8(N) (((N) + 7) & ~0x7)
116
117void PACK_APIENTRY crPackBitmap( GLsizei width, GLsizei height,
118 GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,
119 const GLubyte *bitmap, const CRPixelPackState *unpack )
120{
121 const int isnull = (bitmap == NULL);
122 unsigned char *data_ptr;
123 int data_length = 0;
124 GLubyte *destBitmap = NULL;
125 int packet_length =
126 sizeof( width ) +
127 sizeof( height ) +
128 sizeof( xorig ) +
129 sizeof( yorig ) +
130 sizeof( xmove ) +
131 sizeof( ymove ) +
132 sizeof( GLuint );
133
134 if ( bitmap )
135 {
136 data_length = CEIL8(width) * height / 8;
137 packet_length += data_length;
138
139 data_ptr = (unsigned char *) crPackAlloc( packet_length );
140 destBitmap = data_ptr + 28;
141
142 crBitmapCopy(width, height, destBitmap, bitmap, unpack);
143 /*
144 crMemcpy(destBitmap, bitmap, data_length);
145 */
146 }
147 else {
148 data_ptr = (unsigned char *) crPackAlloc( packet_length );
149 }
150
151 WRITE_DATA( 0, GLsizei, width );
152 WRITE_DATA( 4, GLsizei, height );
153 WRITE_DATA( 8, GLfloat, xorig );
154 WRITE_DATA( 12, GLfloat, yorig );
155 WRITE_DATA( 16, GLfloat, xmove );
156 WRITE_DATA( 20, GLfloat, ymove );
157 WRITE_DATA( 24, GLuint, isnull );
158
159 crHugePacket( CR_BITMAP_OPCODE, data_ptr );
160 crPackFree( data_ptr );
161}
162/*
163 ZPix - compressed DrawPixels
164*/
165void PACK_APIENTRY crPackZPixCR( GLsizei width, GLsizei height,
166 GLenum format, GLenum type,
167 GLenum ztype, GLint zparm, GLint length,
168 const GLvoid *pixels,
169 const CRPixelPackState *unpackstate )
170{
171 unsigned char *data_ptr;
172 int packet_length;
173 (void)unpackstate;
174
175 if (pixels == NULL)
176 {
177 return;
178 }
179
180 packet_length =
181 sizeof( int ) + /* packet size */
182 sizeof( GLenum ) + /* extended opcode */
183 sizeof( width ) +
184 sizeof( height ) +
185 sizeof( format ) +
186 sizeof( type ) +
187 sizeof( ztype ) +
188 sizeof( zparm ) +
189 sizeof( length );
190
191 packet_length += length;
192
193/* XXX JAG
194 crDebug("PackZPixCR: fb %d x %d, state %d, zlen = %d, plen = %d",
195 width, height, ztype, length, packet_length);
196*/
197 data_ptr = (unsigned char *) crPackAlloc( packet_length );
198 WRITE_DATA( 0, GLenum , CR_ZPIXCR_EXTEND_OPCODE );
199 WRITE_DATA( 4, GLsizei, width );
200 WRITE_DATA( 8, GLsizei, height );
201 WRITE_DATA( 12, GLenum, format );
202 WRITE_DATA( 16, GLenum, type );
203 WRITE_DATA( 20, GLenum, ztype );
204 WRITE_DATA( 24, GLint, zparm );
205 WRITE_DATA( 28, GLint, length );
206
207 crMemcpy((void *) (data_ptr+32), pixels, length);
208
209 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
210 crPackFree( data_ptr );
211}
212
213
214void PACK_APIENTRY
215crPackGetTexImage( GLenum target, GLint level, GLenum format, GLenum type,
216 GLvoid * pixels, const CRPixelPackState * packstate,
217 int * writeback )
218{
219 GET_PACKER_CONTEXT(pc);
220 unsigned char *data_ptr;
221 (void) pc;
222 GET_BUFFERED_POINTER( pc, 40 );
223 WRITE_DATA( 0, GLint, 40 );
224 WRITE_DATA( 4, GLenum, CR_GETTEXIMAGE_EXTEND_OPCODE );
225 WRITE_DATA( 8, GLenum, target );
226 WRITE_DATA( 12, GLint, level );
227 WRITE_DATA( 16, GLenum, format );
228 WRITE_DATA( 20, GLenum, type );
229 WRITE_NETWORK_POINTER( 24, (void *) pixels );
230 WRITE_NETWORK_POINTER( 32, (void *) writeback );
231 WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
232}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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