VirtualBox

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

最後變更 在這個檔案從72723是 69392,由 vboxsync 提交於 7 年 前

GuestHost/OpenGL: scm updates

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 7.1 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 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 *writeback = 0;
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_CMDBLOCK_CHECK_FLUSH(pc);
107 CR_UNLOCK_PACKER_CONTEXT(pc);
108}
109
110/* Round N up to the next multiple of 8 */
111#define CEIL8(N) (((N) + 7) & ~0x7)
112
113void PACK_APIENTRY crPackBitmap(GLsizei width, GLsizei height,
114 GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,
115 const GLubyte *bitmap, const CRPixelPackState *unpack )
116{
117 const int noimagedata = (bitmap == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
118 unsigned char *data_ptr;
119 int data_length = 0;
120 /*GLubyte *destBitmap = NULL; - unused */
121 int packet_length =
122 sizeof( width ) +
123 sizeof( height ) +
124 sizeof( xorig ) +
125 sizeof( yorig ) +
126 sizeof( xmove ) +
127 sizeof( ymove ) +
128 sizeof( GLuint ) + sizeof(GLint);
129
130 if (!noimagedata)
131 {
132 data_length = CEIL8(width) * height / 8;
133 packet_length += data_length;
134 }
135
136 data_ptr = (unsigned char *) crPackAlloc( packet_length );
137
138 WRITE_DATA( 0, GLsizei, width );
139 WRITE_DATA( 4, GLsizei, height );
140 WRITE_DATA( 8, GLfloat, xorig );
141 WRITE_DATA( 12, GLfloat, yorig );
142 WRITE_DATA( 16, GLfloat, xmove );
143 WRITE_DATA( 20, GLfloat, ymove );
144 WRITE_DATA( 24, GLuint, noimagedata );
145 WRITE_DATA( 28, GLint, (GLint) (uintptr_t) bitmap);
146
147 if (!noimagedata)
148 crBitmapCopy(width, height, (GLubyte *)(data_ptr + 32), bitmap, unpack);
149
150 crHugePacket( CR_BITMAP_OPCODE, data_ptr );
151 crPackFree( data_ptr );
152}
153/*
154 ZPix - compressed DrawPixels
155*/
156void PACK_APIENTRY crPackZPixCR( GLsizei width, GLsizei height,
157 GLenum format, GLenum type,
158 GLenum ztype, GLint zparm, GLint length,
159 const GLvoid *pixels,
160 const CRPixelPackState *unpackstate )
161{
162 unsigned char *data_ptr;
163 int packet_length;
164 (void)unpackstate;
165
166 if (pixels == NULL)
167 {
168 return;
169 }
170
171 packet_length =
172 sizeof( int ) + /* packet size */
173 sizeof( GLenum ) + /* extended opcode */
174 sizeof( width ) +
175 sizeof( height ) +
176 sizeof( format ) +
177 sizeof( type ) +
178 sizeof( ztype ) +
179 sizeof( zparm ) +
180 sizeof( length );
181
182 packet_length += length;
183
184/* XXX JAG
185 crDebug("PackZPixCR: fb %d x %d, state %d, zlen = %d, plen = %d",
186 width, height, ztype, length, packet_length);
187*/
188 data_ptr = (unsigned char *) crPackAlloc( packet_length );
189 WRITE_DATA( 0, GLenum , CR_ZPIXCR_EXTEND_OPCODE );
190 WRITE_DATA( 4, GLsizei, width );
191 WRITE_DATA( 8, GLsizei, height );
192 WRITE_DATA( 12, GLenum, format );
193 WRITE_DATA( 16, GLenum, type );
194 WRITE_DATA( 20, GLenum, ztype );
195 WRITE_DATA( 24, GLint, zparm );
196 WRITE_DATA( 28, GLint, length );
197
198 crMemcpy((void *) (data_ptr+32), pixels, length);
199
200 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
201 crPackFree( data_ptr );
202}
203
204
205void PACK_APIENTRY
206crPackGetTexImage( GLenum target, GLint level, GLenum format, GLenum type,
207 GLvoid * pixels, const CRPixelPackState * packstate,
208 int * writeback )
209{
210 CR_GET_PACKER_CONTEXT(pc);
211 unsigned char *data_ptr;
212 (void) pc; (void) packstate;
213 CR_GET_BUFFERED_POINTER( pc, 40 );
214 WRITE_DATA( 0, GLint, 40 );
215 WRITE_DATA( 4, GLenum, CR_GETTEXIMAGE_EXTEND_OPCODE );
216 WRITE_DATA( 8, GLenum, target );
217 WRITE_DATA( 12, GLint, level );
218 WRITE_DATA( 16, GLenum, format );
219 WRITE_DATA( 20, GLenum, type );
220 WRITE_NETWORK_POINTER( 24, (void *) pixels );
221 WRITE_NETWORK_POINTER( 32, (void *) writeback );
222 WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
223 CR_CMDBLOCK_CHECK_FLUSH(pc);
224 CR_UNLOCK_PACKER_CONTEXT(pc);
225}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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