Mercurial > sdl-ios-xcode
comparison src/video/windows/SDL_gapirender.c @ 5088:c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 24 Jan 2011 15:46:11 -0800 |
parents | e8916fe9cfc8 |
children | 327f181542f1 |
comparison
equal
deleted
inserted
replaced
5087:e7680e2c9f3c | 5088:c2539ff054c8 |
---|---|
90 | 90 |
91 //#ifndef DM_DISPLAYORIENTATION | 91 //#ifndef DM_DISPLAYORIENTATION |
92 //#define DM_DISPLAYORIENTATION 0x00800000L | 92 //#define DM_DISPLAYORIENTATION 0x00800000L |
93 //#endif | 93 //#endif |
94 | 94 |
95 #define FORMAT_565 1 | 95 #define FORMAT_565 1 |
96 #define FORMAT_555 2 | 96 #define FORMAT_555 2 |
97 #define FORMAT_OTHER 3 | 97 #define FORMAT_OTHER 3 |
98 | 98 |
99 #define GETRAWFRAMEBUFFER 0x00020001 | 99 #define GETRAWFRAMEBUFFER 0x00020001 |
100 #define GETGXINFO 0x00020000 | 100 #define GETGXINFO 0x00020000 |
101 | 101 |
102 #define kfPalette 0x10 | 102 #define kfPalette 0x10 |
103 #define kfDirect 0x20 | 103 #define kfDirect 0x20 |
104 #define kfDirect555 0x40 | 104 #define kfDirect555 0x40 |
105 #define kfDirect565 0x80 | 105 #define kfDirect565 0x80 |
106 | 106 |
107 #define GX_FULLSCREEN 0x01 | 107 #define GX_FULLSCREEN 0x01 |
108 | 108 |
109 enum ScreenOrientation { ORIENTATION_UNKNOWN = -1, ORIENTATION_UP = DMDO_0, ORIENTATION_DOWN = DMDO_180, ORIENTATION_LEFT = DMDO_270, ORIENTATION_RIGHT = DMDO_90 }; | 109 enum ScreenOrientation { ORIENTATION_UNKNOWN = -1, ORIENTATION_UP = DMDO_0, ORIENTATION_DOWN = DMDO_180, ORIENTATION_LEFT = DMDO_270, ORIENTATION_RIGHT = DMDO_90 }; |
110 enum ScreenGeometry { GEOMETRY_UNKNOWN, GEOMETRY_PORTRAIT, GEOMETRY_LANDSCAPE, GEOMETRY_SQUARE }; | 110 enum ScreenGeometry { GEOMETRY_UNKNOWN, GEOMETRY_PORTRAIT, GEOMETRY_LANDSCAPE, GEOMETRY_SQUARE }; |
111 enum FrameBufferFlags { FB_SKIP_OFFSET = 0x0001, FB_RAW_MODE = 0x0002, FB_SUSPENDED = 0x0004 }; | 111 enum FrameBufferFlags { FB_SKIP_OFFSET = 0x0001, FB_RAW_MODE = 0x0002, FB_SUSPENDED = 0x0004 }; |
112 | 112 |
121 } FrameBufferInfo; | 121 } FrameBufferInfo; |
122 | 122 |
123 // private display data | 123 // private display data |
124 typedef struct | 124 typedef struct |
125 { | 125 { |
126 unsigned char* pixels; // video memory | 126 unsigned char* pixels; // video memory |
127 int format; // video format | 127 int format; // video format |
128 FrameBufferInfo fb; // framebuffer geometry | 128 FrameBufferInfo fb; // framebuffer geometry |
129 GapiInfo* gapi; // GAPI module | 129 GapiInfo* gapi; // GAPI module |
130 int userOrientation; | 130 int userOrientation; |
131 int systemOrientation; | 131 int systemOrientation; |
132 int hardwareGeometry; | 132 int hardwareGeometry; |
133 int flags; // fb flags | 133 int flags; // fb flags |
134 float scale; // scale pointer position | 134 float scale; // scale pointer position |
135 int debug; | 135 int debug; |
136 | 136 |
137 } WINCE_RenderData; | 137 } WINCE_RenderData; |
138 | 138 |
139 typedef struct | 139 typedef struct |
145 | 145 |
146 } WINCE_TextureData; | 146 } WINCE_TextureData; |
147 | 147 |
148 | 148 |
149 // system func | 149 // system func |
150 SDL_Renderer* WINCE_CreateRenderer(SDL_Window* window, Uint32 flags); | 150 SDL_Renderer* WINCE_CreateRenderer(SDL_Window* window, Uint32 flags); |
151 void WINCE_DestroyRenderer(SDL_Renderer* renderer); | 151 void WINCE_DestroyRenderer(SDL_Renderer* renderer); |
152 | 152 |
153 int WINCE_CreateTexture(SDL_Renderer* renderer, SDL_Texture* texture); | 153 int WINCE_CreateTexture(SDL_Renderer* renderer, SDL_Texture* texture); |
154 void WINCE_DestroyTexture(SDL_Renderer* renderer, SDL_Texture* texture); | 154 void WINCE_DestroyTexture(SDL_Renderer* renderer, SDL_Texture* texture); |
155 int WINCE_QueryTexturePixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch); | 155 int WINCE_QueryTexturePixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch); |
156 int WINCE_UpdateTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch); | 156 int WINCE_UpdateTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch); |
157 int WINCE_LockTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int dirty, void** pixels, int* pitch); | 157 int WINCE_LockTexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int dirty, void** pixels, int* pitch); |
158 void WINCE_UnlockTexture(SDL_Renderer* renderer, SDL_Texture* texture); | 158 void WINCE_UnlockTexture(SDL_Renderer* renderer, SDL_Texture* texture); |
159 | 159 |
160 int WINCE_Available(void); | 160 int WINCE_Available(void); |
161 void WINCE_SetupOrientation(WINCE_RenderData* data, int width, int height); | 161 void WINCE_SetupOrientation(WINCE_RenderData* data, int width, int height); |
162 | 162 |
163 int WINCE_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srect, const SDL_Rect* drect); | 163 int WINCE_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srect, const SDL_Rect* drect); |
164 void WINCE_ShowWindow(_THIS, SDL_Window* window, int visible); | 164 void WINCE_ShowWindow(_THIS, SDL_Window* window, int visible); |
165 | 165 |
166 void WINCE_RenderPresent(SDL_Renderer* renderer); | 166 void WINCE_RenderPresent(SDL_Renderer* renderer); |
167 int WINCE_RenderDrawPoints(SDL_Renderer* renderer, const SDL_Point* points, int count); | 167 int WINCE_RenderDrawPoints(SDL_Renderer* renderer, const SDL_Point* points, int count); |
168 int WINCE_RenderDrawLines(SDL_Renderer* renderer, const SDL_Point* points, int count); | 168 int WINCE_RenderDrawLines(SDL_Renderer* renderer, const SDL_Point* points, int count); |
169 int WINCE_RenderDrawRects(SDL_Renderer* renderer, const SDL_Rect ** rects, int count); | 169 int WINCE_RenderDrawRects(SDL_Renderer* renderer, const SDL_Rect ** rects, int count); |
170 int WINCE_RenderFillRects(SDL_Renderer* renderer, const SDL_Rect** rects, int count); | 170 int WINCE_RenderFillRects(SDL_Renderer* renderer, const SDL_Rect** rects, int count); |
171 | 171 |
172 void WINCE_PointerCoordinateTransform(SDL_Window* window, POINT* pt); | 172 void WINCE_PointerCoordinateTransform(SDL_Window* window, POINT* pt); |
173 void WINCE_DumpVideoInfo(WINCE_RenderData* data); | 173 void WINCE_DumpVideoInfo(WINCE_RenderData* data); |
174 void WINCE_PortraitTransform(WINCE_RenderData* data, int width, int height); | 174 void WINCE_PortraitTransform(WINCE_RenderData* data, int width, int height); |
175 void WINCE_LandscapeTransform(WINCE_RenderData* data, int width, int height); | 175 void WINCE_LandscapeTransform(WINCE_RenderData* data, int width, int height); |
176 void WINCE_SquareTransform(WINCE_RenderData* data, int width, int height); | 176 void WINCE_SquareTransform(WINCE_RenderData* data, int width, int height); |
177 int WINCE_FixedGeometry(FrameBufferInfo* fb, int bpp, int debug); | 177 int WINCE_FixedGeometry(FrameBufferInfo* fb, int bpp, int debug); |
178 int WINCE_GetDMOrientation(void); | 178 int WINCE_GetDMOrientation(void); |
179 int WINCE_SetDMOrientation(int orientation); | 179 int WINCE_SetDMOrientation(int orientation); |
180 void WINCE_UpdateYUVTextureData(SDL_Texture* texture); | 180 void WINCE_UpdateYUVTextureData(SDL_Texture* texture); |
181 | 181 |
182 // gapi engine specific | 182 // gapi engine specific |
183 int GAPI_Init(WINCE_RenderData* data, HWND hwnd); | 183 int GAPI_Init(WINCE_RenderData* data, HWND hwnd); |
184 void GAPI_Quit(WINCE_RenderData* data); | 184 void GAPI_Quit(WINCE_RenderData* data); |
185 | 185 |
186 // raw engine specific | 186 // raw engine specific |
187 int RAW_Init(WINCE_RenderData* data); | 187 int RAW_Init(WINCE_RenderData* data); |
188 void RAW_Quit(WINCE_RenderData* data); | 188 void RAW_Quit(WINCE_RenderData* data); |
189 | 189 |
190 // tools | 190 // tools |
191 void FrameBufferRotate(FrameBufferInfo* src, int orientation); | 191 void FrameBufferRotate(FrameBufferInfo* src, int orientation); |
192 int GetFrameBufferOrientation(const FrameBufferInfo* src); | 192 int GetFrameBufferOrientation(const FrameBufferInfo* src); |
193 void PointerRotate(POINT* pt, const FrameBufferInfo* fb, int orientation); | 193 void PointerRotate(POINT* pt, const FrameBufferInfo* fb, int orientation); |
194 void FrameBufferInitialize(FrameBufferInfo* fb); | 194 void FrameBufferInitialize(FrameBufferInfo* fb); |
195 void FrameBufferDumpInfo(const FrameBufferInfo* fb, const char*); | 195 void FrameBufferDumpInfo(const FrameBufferInfo* fb, const char*); |
196 const char* GetOrientationName(int orientation); | 196 const char* GetOrientationName(int orientation); |
197 void UpdateLine16to16(const FrameBufferInfo* fb, const Uint16* src, Uint16* dst, Uint16 width); | 197 void UpdateLine16to16(const FrameBufferInfo* fb, const Uint16* src, Uint16* dst, Uint16 width); |
198 | 198 |
199 // stdlib | 199 // stdlib |
200 inline int __abs(int x){ return x < 0 ? -x : x; }; | 200 static __inline__ int __abs(int x){ return x < 0 ? -x : x; }; |
201 inline void __swap(int* a, int* b){ int t = *a; *a = *b; *b = t; }; | 201 static __inline__ void __swap(int* a, int* b){ int t = *a; *a = *b; *b = t; }; |
202 | 202 |
203 #define GAPI_RENDER_NAME "gapi" | 203 #define GAPI_RENDER_NAME "gapi" |
204 #define RAW_RENDER_NAME "raw" | 204 #define RAW_RENDER_NAME "raw" |
205 // | 205 // |
206 SDL_RenderDriver GAPI_RenderDriver = { | 206 SDL_RenderDriver GAPI_RenderDriver = { |
207 WINCE_CreateRenderer, | 207 WINCE_CreateRenderer, |
208 { | 208 { |
209 GAPI_RENDER_NAME, | 209 GAPI_RENDER_NAME, |
210 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD), | 210 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD), |
211 (SDL_TEXTUREMODULATE_NONE), | 211 (SDL_TEXTUREMODULATE_NONE), |
212 (SDL_BLENDMODE_NONE), | 212 (SDL_BLENDMODE_NONE), |
213 (SDL_SCALEMODE_NONE), | 213 (SDL_SCALEMODE_NONE), |
214 7, | 214 7, |
215 { | 215 { |
216 SDL_PIXELFORMAT_RGB555, | 216 SDL_PIXELFORMAT_RGB555, |
217 SDL_PIXELFORMAT_RGB565, | 217 SDL_PIXELFORMAT_RGB565, |
218 SDL_PIXELFORMAT_YV12, | 218 SDL_PIXELFORMAT_YV12, |
219 SDL_PIXELFORMAT_IYUV, | 219 SDL_PIXELFORMAT_IYUV, |
220 SDL_PIXELFORMAT_YUY2, | 220 SDL_PIXELFORMAT_YUY2, |
221 SDL_PIXELFORMAT_UYVY, | 221 SDL_PIXELFORMAT_UYVY, |
222 SDL_PIXELFORMAT_YVYU | 222 SDL_PIXELFORMAT_YVYU |
223 }, | 223 }, |
224 0, | 224 0, |
225 0 | 225 0 |
226 } | 226 } |
227 }; | 227 }; |
228 | 228 |
229 SDL_RenderDriver RAW_RenderDriver = { | 229 SDL_RenderDriver RAW_RenderDriver = { |
230 WINCE_CreateRenderer, | 230 WINCE_CreateRenderer, |
231 { | 231 { |
232 RAW_RENDER_NAME, | 232 RAW_RENDER_NAME, |
233 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD), | 233 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD), |
234 (SDL_TEXTUREMODULATE_NONE), | 234 (SDL_TEXTUREMODULATE_NONE), |
235 (SDL_BLENDMODE_NONE), | 235 (SDL_BLENDMODE_NONE), |
236 (SDL_SCALEMODE_NONE), | 236 (SDL_SCALEMODE_NONE), |
237 7, | 237 7, |
238 { | 238 { |
239 SDL_PIXELFORMAT_RGB555, | 239 SDL_PIXELFORMAT_RGB555, |
240 SDL_PIXELFORMAT_RGB565, | 240 SDL_PIXELFORMAT_RGB565, |
241 SDL_PIXELFORMAT_YV12, | 241 SDL_PIXELFORMAT_YV12, |
242 SDL_PIXELFORMAT_IYUV, | 242 SDL_PIXELFORMAT_IYUV, |
243 SDL_PIXELFORMAT_YUY2, | 243 SDL_PIXELFORMAT_YUY2, |
244 SDL_PIXELFORMAT_UYVY, | 244 SDL_PIXELFORMAT_UYVY, |
245 SDL_PIXELFORMAT_YVYU | 245 SDL_PIXELFORMAT_YVYU |
246 }, | 246 }, |
247 0, | 247 0, |
248 0 | 248 0 |
249 } | 249 } |
250 }; | 250 }; |
251 | 251 |
252 int WINCE_Available(void) | 252 int WINCE_Available(void) |
253 { | 253 { |
254 HMODULE render_gapi; | |
254 const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); | 255 const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); |
255 | 256 |
256 // raw check | 257 // raw check |
257 RawFrameBufferInfo rfbi = { 0 }; | 258 RawFrameBufferInfo rfbi = { 0 }; |
258 HDC hdc = GetDC(NULL); | 259 HDC hdc = GetDC(NULL); |
259 int render_raw = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi); | 260 int render_raw = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi); |
260 ReleaseDC(NULL, hdc); | 261 ReleaseDC(NULL, hdc); |
261 | 262 |
262 if(render_raw != 0 && rfbi.cxPixels != 0 && rfbi.cyPixels != 0 && | 263 if(render_raw != 0 && rfbi.cxPixels != 0 && rfbi.cyPixels != 0 && |
263 rfbi.pFramePointer != 0 && rfbi.cxStride != 0 && rfbi.cyStride != 0) | 264 rfbi.pFramePointer != 0 && rfbi.cxStride != 0 && rfbi.cyStride != 0) |
264 render_raw = 1; | 265 render_raw = 1; |
265 | 266 |
266 if(preferably && 0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0 != render_raw; | 267 if(preferably && 0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0 != render_raw; |
267 | 268 |
268 // gapi check | 269 // gapi check |
269 HMODULE render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); | 270 render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); |
270 if(0 == render_gapi) | 271 if(0 == render_gapi) |
271 render_gapi = LoadLibrary(TEXT("gx.dll")); | 272 render_gapi = LoadLibrary(TEXT("gx.dll")); |
272 FreeLibrary(render_gapi); | 273 FreeLibrary(render_gapi); |
273 | 274 |
274 if(preferably && 0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0 != render_gapi; | 275 if(preferably && 0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0 != render_gapi; |
288 hdc = GetDC(NULL); | 289 hdc = GetDC(NULL); |
289 render_raw = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi); | 290 render_raw = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi); |
290 ReleaseDC(NULL, hdc); | 291 ReleaseDC(NULL, hdc); |
291 | 292 |
292 if(render_raw != 0 && rfbi.cxPixels != 0 && rfbi.cyPixels != 0 && | 293 if(render_raw != 0 && rfbi.cxPixels != 0 && rfbi.cyPixels != 0 && |
293 rfbi.pFramePointer != 0 && rfbi.cxStride != 0 && rfbi.cyStride != 0) | 294 rfbi.pFramePointer != 0 && rfbi.cxStride != 0 && rfbi.cyStride != 0) |
294 render_raw = 1; | 295 render_raw = 1; |
295 | 296 |
296 // gapi check | 297 // gapi check |
297 render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); | 298 render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); |
298 if(0 == render_gapi) | 299 if(0 == render_gapi) |
299 render_gapi = LoadLibrary(TEXT("gx.dll")); | 300 render_gapi = LoadLibrary(TEXT("gx.dll")); |
300 | 301 |
301 if(render_gapi) | 302 if(render_gapi) |
302 FreeLibrary(render_gapi); | 303 FreeLibrary(render_gapi); |
303 | 304 |
304 for(ii = 0; ii < _this->num_displays; ++ii) | 305 for(ii = 0; ii < _this->num_displays; ++ii) |
305 { | 306 { |
306 if(preferably) | 307 if(preferably) |
307 { | 308 { |
308 if(0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME) && render_raw) | 309 if(0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME) && render_raw) |
309 SDL_AddRenderDriver(&_this->displays[ii], &RAW_RenderDriver); | 310 SDL_AddRenderDriver(&_this->displays[ii], &RAW_RenderDriver); |
310 else | 311 else |
311 if(0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME) && render_gapi) | 312 if(0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME) && render_gapi) |
312 SDL_AddRenderDriver(&_this->displays[ii], &GAPI_RenderDriver); | 313 SDL_AddRenderDriver(&_this->displays[ii], &GAPI_RenderDriver); |
313 } | 314 } |
314 else | 315 else |
315 { | 316 { |
316 if(render_raw) | 317 if(render_raw) |
317 SDL_AddRenderDriver(&_this->displays[ii], &RAW_RenderDriver); | 318 SDL_AddRenderDriver(&_this->displays[ii], &RAW_RenderDriver); |
318 if(render_gapi) | 319 if(render_gapi) |
319 SDL_AddRenderDriver(&_this->displays[ii], &GAPI_RenderDriver); | 320 SDL_AddRenderDriver(&_this->displays[ii], &GAPI_RenderDriver); |
320 } | 321 } |
321 } | 322 } |
322 } | 323 } |
323 | 324 |
324 SDL_Renderer* WINCE_CreateRenderer(SDL_Window* window, Uint32 flags) | 325 SDL_Renderer* WINCE_CreateRenderer(SDL_Window* window, Uint32 flags) |
325 { | 326 { |
330 WINCE_RenderData* data; | 331 WINCE_RenderData* data; |
331 int bpp; | 332 int bpp; |
332 Uint32 Rmask, Gmask, Bmask, Amask; | 333 Uint32 Rmask, Gmask, Bmask, Amask; |
333 | 334 |
334 if(!(window->flags & SDL_WINDOW_FULLSCREEN)) | 335 if(!(window->flags & SDL_WINDOW_FULLSCREEN)) |
335 window->flags |= SDL_WINDOW_FULLSCREEN; | 336 window->flags |= SDL_WINDOW_FULLSCREEN; |
336 | 337 |
337 if(!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) | 338 if(!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) |
338 { | 339 { |
339 SDL_SetError("Unknown display format"); | 340 SDL_SetError("Unknown display format"); |
340 return NULL; | 341 return NULL; |
341 } | 342 } |
342 | 343 |
343 switch(window->fullscreen_mode.format) | 344 switch(window->fullscreen_mode.format) |
344 { | 345 { |
345 case SDL_PIXELFORMAT_RGB555: | 346 case SDL_PIXELFORMAT_RGB555: |
346 case SDL_PIXELFORMAT_RGB565: | 347 case SDL_PIXELFORMAT_RGB565: |
347 break; | 348 break; |
348 | 349 |
349 default: | 350 default: |
350 SDL_SetError("Support only 16 or 15 bpp"); | 351 SDL_SetError("Support only 16 or 15 bpp"); |
351 return NULL; | 352 return NULL; |
352 } | 353 } |
353 | 354 |
354 renderer = (SDL_Renderer*) SDL_calloc(1, sizeof(SDL_Renderer)); | 355 renderer = (SDL_Renderer*) SDL_calloc(1, sizeof(SDL_Renderer)); |
355 if(!renderer) | 356 if(!renderer) |
356 { | 357 { |
373 return NULL; | 374 return NULL; |
374 } | 375 } |
375 | 376 |
376 | 377 |
377 // set debug | 378 // set debug |
378 data->debug = SDL_getenv("DEBUG_VIDEO_GAPI") || SDL_getenv("GAPI_RENDERER_DEBUG") ? 1 : 0; | 379 data->debug = SDL_getenv("DEBUG_VIDEO_GAPI") || SDL_getenv("GAPI_RENDERER_DEBUG") ? 1 : 0; |
379 #if defined(DEBUG_VIDEO_GAPI) || defined(GAPI_RENDERER_DEBUG) | 380 #if defined(DEBUG_VIDEO_GAPI) || defined(GAPI_RENDERER_DEBUG) |
380 data->debug = 1; | 381 data->debug = 1; |
381 #endif | 382 #endif |
382 | 383 |
383 windowdata->videodata->render = data->gapi ? RENDER_GAPI : RENDER_RAW; | 384 windowdata->videodata->render = data->gapi ? RENDER_GAPI : RENDER_RAW; |
384 windowdata->videodata->CoordTransform = WINCE_PointerCoordinateTransform; | 385 windowdata->videodata->CoordTransform = WINCE_PointerCoordinateTransform; |
385 | 386 |
416 { | 417 { |
417 WINCE_RenderData *renderdata = (WINCE_RenderData*) renderer->driverdata; | 418 WINCE_RenderData *renderdata = (WINCE_RenderData*) renderer->driverdata; |
418 | 419 |
419 if(renderdata) | 420 if(renderdata) |
420 { | 421 { |
421 if(renderdata->gapi) | 422 if(renderdata->gapi) |
422 GAPI_Quit(renderdata); | 423 GAPI_Quit(renderdata); |
423 else | 424 else |
424 RAW_Quit(renderdata); | 425 RAW_Quit(renderdata); |
425 | 426 |
426 SDL_free(renderdata); | 427 SDL_free(renderdata); |
427 } | 428 } |
428 | 429 |
429 SDL_free(renderer); | 430 SDL_free(renderer); |
446 return -1; | 447 return -1; |
447 } | 448 } |
448 | 449 |
449 if(SDL_ISPIXELFORMAT_FOURCC(texture->format)) | 450 if(SDL_ISPIXELFORMAT_FOURCC(texture->format)) |
450 { | 451 { |
451 texturedata->yuv = SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h); | 452 SDL_Window* window = renderer->window; |
453 SDL_VideoDisplay* display = window->display; | |
454 | |
455 texturedata->yuv = SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h); | |
452 if(NULL == texturedata->yuv) | 456 if(NULL == texturedata->yuv) |
453 { | 457 { |
454 SDL_OutOfMemory(); | 458 SDL_OutOfMemory(); |
455 return -1; | 459 return -1; |
456 } | 460 } |
457 SDL_Window* window = renderer->window; | 461 texturedata->format = display->current_mode.format; |
458 SDL_VideoDisplay* display = window->display; | |
459 texturedata->format = display->current_mode.format; | |
460 } | 462 } |
461 else | 463 else |
462 { | 464 { |
463 texturedata->yuv = NULL; | 465 texturedata->yuv = NULL; |
464 texturedata->format = texture->format; | 466 texturedata->format = texture->format; |
465 } | 467 } |
466 | 468 |
467 texture->driverdata = texturedata; | 469 texture->driverdata = texturedata; |
468 | 470 |
469 return 0; | 471 return 0; |
473 { | 475 { |
474 WINCE_TextureData *texturedata = (WINCE_TextureData*) texture->driverdata; | 476 WINCE_TextureData *texturedata = (WINCE_TextureData*) texture->driverdata; |
475 | 477 |
476 if(texturedata) | 478 if(texturedata) |
477 { | 479 { |
478 if(texturedata->yuv) SDL_SW_DestroyYUVTexture(texturedata->yuv); | 480 if(texturedata->yuv) SDL_SW_DestroyYUVTexture(texturedata->yuv); |
479 if(texturedata->pixels) SDL_free(texturedata->pixels); | 481 if(texturedata->pixels) SDL_free(texturedata->pixels); |
480 SDL_free(texturedata); | 482 SDL_free(texturedata); |
481 texture->driverdata = NULL; | 483 texture->driverdata = NULL; |
482 } | 484 } |
483 } | 485 } |
484 | 486 |
485 int WINCE_QueryTexturePixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch) | 487 int WINCE_QueryTexturePixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch) |
486 { | 488 { |
507 return 0; | 509 return 0; |
508 } | 510 } |
509 | 511 |
510 if(0 < rect->w && 0 < rect->h) | 512 if(0 < rect->w && 0 < rect->h) |
511 { | 513 { |
512 const unsigned char *src = ((const unsigned char*) pixels); | 514 const unsigned char *src = ((const unsigned char*) pixels); |
513 unsigned char *dst = ((unsigned char*) texturedata->pixels) + | 515 unsigned char *dst = ((unsigned char*) texturedata->pixels) + |
514 rect->y * texturedata->pitch + | 516 rect->y * texturedata->pitch + |
515 rect->x * SDL_BYTESPERPIXEL(texture->format); | 517 rect->x * SDL_BYTESPERPIXEL(texture->format); |
516 int length = rect->w * SDL_BYTESPERPIXEL(texture->format); | 518 int length = rect->w * SDL_BYTESPERPIXEL(texture->format); |
517 int height = rect->h; | 519 int height = rect->h; |
518 | 520 |
519 while(height--) | 521 while(height--) |
520 { | 522 { |
521 SDL_memcpy(dst, src, length); | 523 SDL_memcpy(dst, src, length); |
522 dst += texturedata->pitch; | 524 dst += texturedata->pitch; |
523 src += pitch; | 525 src += pitch; |
524 } | 526 } |
525 } | 527 } |
526 | 528 |
527 return 0; | 529 return 0; |
528 } | 530 } |
529 | 531 |
533 | 535 |
534 if(texturedata->yuv) | 536 if(texturedata->yuv) |
535 return SDL_SW_LockYUVTexture(texturedata->yuv, rect, dirty, pixels, pitch); | 537 return SDL_SW_LockYUVTexture(texturedata->yuv, rect, dirty, pixels, pitch); |
536 | 538 |
537 *pixels = (void *) ((unsigned char*) texturedata->pixels + | 539 *pixels = (void *) ((unsigned char*) texturedata->pixels + |
538 rect->y * texturedata->pitch + | 540 rect->y * texturedata->pitch + |
539 rect->x * SDL_BYTESPERPIXEL(texture->format)); | 541 rect->x * SDL_BYTESPERPIXEL(texture->format)); |
540 *pitch = texturedata->pitch; | 542 *pitch = texturedata->pitch; |
543 return 0; | |
541 } | 544 } |
542 | 545 |
543 void WINCE_UnlockTexture(SDL_Renderer* renderer, SDL_Texture* texture) | 546 void WINCE_UnlockTexture(SDL_Renderer* renderer, SDL_Texture* texture) |
544 { | 547 { |
545 WINCE_TextureData *texturedata = (WINCE_TextureData*) texture->driverdata; | 548 WINCE_TextureData *texturedata = (WINCE_TextureData*) texture->driverdata; |
546 | 549 |
547 if(texturedata->yuv) | 550 if(texturedata->yuv) |
548 { | 551 { |
549 SDL_SW_UnlockYUVTexture(texturedata->yuv); | 552 SDL_SW_UnlockYUVTexture(texturedata->yuv); |
550 WINCE_UpdateYUVTextureData(texture); | 553 WINCE_UpdateYUVTextureData(texture); |
551 } | 554 } |
552 } | 555 } |
553 | 556 |
554 int WINCE_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srect, const SDL_Rect* drect) | 557 int WINCE_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srect, const SDL_Rect* drect) |
555 { | 558 { |
556 WINCE_RenderData* dstdata = (WINCE_RenderData*) renderer->driverdata; | 559 WINCE_RenderData* dstdata = (WINCE_RenderData*) renderer->driverdata; |
557 WINCE_TextureData* srcdata = (WINCE_TextureData*) texture->driverdata; | 560 WINCE_TextureData* srcdata = (WINCE_TextureData*) texture->driverdata; |
561 const unsigned char *src; | |
562 unsigned char *dst; | |
558 | 563 |
559 if((dstdata->flags & FB_SUSPENDED) || | 564 if((dstdata->flags & FB_SUSPENDED) || |
560 0 >= srect->w || 0 >= srect->h) return; | 565 0 >= srect->w || 0 >= srect->h) return 0; |
561 | 566 |
562 // lock gapi | 567 // lock gapi |
563 if(dstdata->gapi) dstdata->gapi->GXBeginDraw(); | 568 if(dstdata->gapi) dstdata->gapi->GXBeginDraw(); |
564 | 569 |
565 const unsigned char *src = ((const unsigned char*) srcdata->pixels); | 570 src = ((const unsigned char*) srcdata->pixels); |
566 unsigned char *dst = dstdata->pixels + (dstdata->flags & FB_SKIP_OFFSET ? 0 : dstdata->fb.offset) + | 571 dst = dstdata->pixels + (dstdata->flags & FB_SKIP_OFFSET ? 0 : dstdata->fb.offset) + |
567 drect->y * dstdata->fb.ypitch + | 572 drect->y * dstdata->fb.ypitch + |
568 drect->x * dstdata->fb.xpitch; | 573 drect->x * dstdata->fb.xpitch; |
569 if(srcdata->yuv) | 574 if(srcdata->yuv) |
570 { | 575 { |
571 return SDL_SW_CopyYUVToRGB(srcdata->yuv, | 576 return SDL_SW_CopyYUVToRGB(srcdata->yuv, |
572 srect, srcdata->format, | 577 srect, srcdata->format, |
573 drect->w, drect->h, dst, | 578 drect->w, drect->h, dst, |
574 dstdata->fb.ypitch); | 579 dstdata->fb.ypitch); |
575 } | 580 } |
576 else | 581 else |
577 { | 582 { |
578 int height = drect->h; | 583 int height = drect->h; |
579 int length = drect->w * SDL_BYTESPERPIXEL(texture->format); // in bytes | 584 int length = drect->w * SDL_BYTESPERPIXEL(texture->format); // in bytes |
580 | 585 |
581 while(height--) | 586 while(height--) |
582 { | 587 { |
583 switch(SDL_BYTESPERPIXEL(texture->format)) | 588 switch(SDL_BYTESPERPIXEL(texture->format)) |
584 { | 589 { |
585 case 2: UpdateLine16to16(&dstdata->fb, (Uint16*) src, (Uint16*) dst, length >> 1); break; | 590 case 2: UpdateLine16to16(&dstdata->fb, (Uint16*) src, (Uint16*) dst, length >> 1); break; |
586 | 591 |
587 default: break; | 592 default: break; |
588 } | 593 } |
589 | 594 |
590 dst += dstdata->fb.ypitch; | 595 dst += dstdata->fb.ypitch; |
591 src += srcdata->pitch; | 596 src += srcdata->pitch; |
592 } | 597 } |
593 } | 598 } |
594 | 599 |
595 // unlock gapi | 600 // unlock gapi |
596 if(dstdata->gapi) dstdata->gapi->GXEndDraw(); | 601 if(dstdata->gapi) dstdata->gapi->GXEndDraw(); |
597 | 602 |
628 | 633 |
629 | 634 |
630 | 635 |
631 void WINCE_SetupOrientation(WINCE_RenderData* data, int width, int height) | 636 void WINCE_SetupOrientation(WINCE_RenderData* data, int width, int height) |
632 { | 637 { |
633 const float maxW1 = GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN) ? GetSystemMetrics(SM_CXSCREEN) : GetSystemMetrics(SM_CYSCREEN); | 638 const float maxW1 = (float)(GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN) ? GetSystemMetrics(SM_CXSCREEN) : GetSystemMetrics(SM_CYSCREEN)); |
634 const float maxW2 = data->fb.width > data->fb.height ? data->fb.width : data->fb.height; | 639 const float maxW2 = (float)(data->fb.width > data->fb.height ? data->fb.width : data->fb.height); |
635 | 640 |
636 // scale define | 641 // scale define |
637 data->scale = maxW2 / maxW1; | 642 data->scale = maxW2 / maxW1; |
638 | 643 |
639 // init fb values | 644 // init fb values |
641 | 646 |
642 // orientation values | 647 // orientation values |
643 data->userOrientation = ORIENTATION_UP; | 648 data->userOrientation = ORIENTATION_UP; |
644 data->systemOrientation = WINCE_GetDMOrientation(); | 649 data->systemOrientation = WINCE_GetDMOrientation(); |
645 data->hardwareGeometry = data->fb.width == data->fb.height ? GEOMETRY_SQUARE : | 650 data->hardwareGeometry = data->fb.width == data->fb.height ? GEOMETRY_SQUARE : |
646 (data->fb.width < data->fb.height ? GEOMETRY_PORTRAIT : GEOMETRY_LANDSCAPE); | 651 (data->fb.width < data->fb.height ? GEOMETRY_PORTRAIT : GEOMETRY_LANDSCAPE); |
647 | 652 |
648 if(data->debug) | 653 if(data->debug) |
649 WINCE_DumpVideoInfo(data); | 654 WINCE_DumpVideoInfo(data); |
650 | 655 |
651 if(data->systemOrientation == ORIENTATION_UNKNOWN) | 656 if(data->systemOrientation == ORIENTATION_UNKNOWN) |
652 data->systemOrientation == ORIENTATION_UP; | 657 data->systemOrientation = ORIENTATION_UP; |
653 | 658 |
654 data->userOrientation = ORIENTATION_UP; | 659 data->userOrientation = ORIENTATION_UP; |
655 | 660 |
656 switch(data->hardwareGeometry) | 661 switch(data->hardwareGeometry) |
657 { | 662 { |
658 case GEOMETRY_PORTRAIT: WINCE_PortraitTransform(data, width, height); break; | 663 case GEOMETRY_PORTRAIT: WINCE_PortraitTransform(data, width, height); break; |
659 case GEOMETRY_LANDSCAPE: WINCE_LandscapeTransform(data, width, height); break; | 664 case GEOMETRY_LANDSCAPE: WINCE_LandscapeTransform(data, width, height); break; |
660 case GEOMETRY_SQUARE: WINCE_SquareTransform(data, width, height); break; | 665 case GEOMETRY_SQUARE: WINCE_SquareTransform(data, width, height); break; |
661 default: break; | 666 default: break; |
662 } | 667 } |
663 | 668 |
664 // debug | 669 // debug |
665 if(data->debug) | 670 if(data->debug) |
666 { | 671 { |
667 printf("\n"); | 672 printf("\n"); |
668 printf("user video width: %d\n", width); | 673 printf("user video width: %d\n", width); |
669 printf("user video height: %d\n", height); | 674 printf("user video height: %d\n", height); |
670 FrameBufferDumpInfo(&data->fb, "user"); | 675 FrameBufferDumpInfo(&data->fb, "user"); |
671 } | 676 } |
672 } | 677 } |
673 | 678 |
674 void WINCE_DumpVideoInfo(WINCE_RenderData* data) | 679 void WINCE_DumpVideoInfo(WINCE_RenderData* data) |
675 { | 680 { |
703 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; | 708 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; |
704 SDL_Renderer* renderer = (SDL_Renderer*) window->renderer; | 709 SDL_Renderer* renderer = (SDL_Renderer*) window->renderer; |
705 | 710 |
706 if(visible) | 711 if(visible) |
707 { | 712 { |
708 if(window->flags & SDL_WINDOW_FULLSCREEN) | 713 if(window->flags & SDL_WINDOW_FULLSCREEN) |
709 { | 714 { |
710 if(videodata->SHFullScreen) | 715 if(videodata->SHFullScreen) |
711 videodata->SHFullScreen(windowdata->hwnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON); | 716 videodata->SHFullScreen(windowdata->hwnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON); |
712 ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_HIDE); | 717 ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_HIDE); |
713 } | 718 } |
714 | 719 |
715 ShowWindow(windowdata->hwnd, SW_SHOW); | 720 ShowWindow(windowdata->hwnd, SW_SHOW); |
716 SetForegroundWindow(windowdata->hwnd); | 721 SetForegroundWindow(windowdata->hwnd); |
717 | 722 |
718 if(renderer && | 723 if(renderer && |
719 (videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW)) | 724 (videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW)) |
720 { | 725 { |
721 WINCE_RenderData* renderdata = (WINCE_RenderData*) renderer->driverdata; | 726 WINCE_RenderData* renderdata = (WINCE_RenderData*) renderer->driverdata; |
722 renderdata->flags &= ~FB_SUSPENDED; | 727 renderdata->flags &= ~FB_SUSPENDED; |
723 if(renderdata->gapi) renderdata->gapi->GXResume(); | 728 if(renderdata->gapi) renderdata->gapi->GXResume(); |
724 } | 729 } |
725 } | 730 } |
726 else | 731 else |
727 { | 732 { |
728 if(renderer && | 733 if(renderer && |
729 (videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW)) | 734 (videodata->render == RENDER_GAPI || videodata->render == RENDER_RAW)) |
730 { | 735 { |
731 WINCE_RenderData* renderdata = (WINCE_RenderData*) renderer->driverdata; | 736 WINCE_RenderData* renderdata = (WINCE_RenderData*) renderer->driverdata; |
732 if(renderdata->gapi) renderdata->gapi->GXSuspend(); | 737 if(renderdata->gapi) renderdata->gapi->GXSuspend(); |
733 renderdata->flags |= FB_SUSPENDED; | 738 renderdata->flags |= FB_SUSPENDED; |
734 } | 739 } |
735 | 740 |
736 ShowWindow(windowdata->hwnd, SW_HIDE); | 741 ShowWindow(windowdata->hwnd, SW_HIDE); |
737 | 742 |
738 if(window->flags & SDL_WINDOW_FULLSCREEN) | 743 if(window->flags & SDL_WINDOW_FULLSCREEN) |
739 { | 744 { |
740 if(videodata->SHFullScreen) | 745 if(videodata->SHFullScreen) |
741 videodata->SHFullScreen(windowdata->hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON); | 746 videodata->SHFullScreen(windowdata->hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON); |
742 ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_SHOW); | 747 ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_SHOW); |
743 } | 748 } |
744 } | 749 } |
745 } | 750 } |
746 | 751 |
747 | 752 |
748 void WINCE_PointerCoordinateTransform(SDL_Window* window, POINT* pt) | 753 void WINCE_PointerCoordinateTransform(SDL_Window* window, POINT* pt) |
749 { | 754 { |
750 WINCE_RenderData* data = (WINCE_RenderData*) window->renderer->driverdata; | 755 WINCE_RenderData* data = (WINCE_RenderData*) window->renderer->driverdata; |
751 | 756 |
752 pt->x *= data->scale; | 757 pt->x = (LONG)(pt->x * data->scale); |
753 pt->y *= data->scale; | 758 pt->y = (LONG)(pt->y * data->scale); |
754 | 759 |
755 PointerRotate(pt, &data->fb, data->userOrientation); | 760 PointerRotate(pt, &data->fb, data->userOrientation); |
756 } | 761 } |
757 | 762 |
758 void WINCE_PortraitTransform(WINCE_RenderData* data, int width, int height) | 763 void WINCE_PortraitTransform(WINCE_RenderData* data, int width, int height) |
759 { | 764 { |
760 if(data->systemOrientation != ORIENTATION_UP) | 765 if(data->systemOrientation != ORIENTATION_UP) |
761 FrameBufferRotate(&data->fb, data->systemOrientation); | 766 FrameBufferRotate(&data->fb, data->systemOrientation); |
767 | |
768 if(data->fb.width != width || data->fb.height != height) { | |
769 switch(data->systemOrientation) | |
770 { | |
771 case ORIENTATION_UP: | |
772 case ORIENTATION_LEFT: data->userOrientation = ORIENTATION_RIGHT; break; | |
773 case ORIENTATION_RIGHT: | |
774 case ORIENTATION_DOWN: data->userOrientation = ORIENTATION_LEFT; break; | |
775 default: break; | |
776 } | |
777 } | |
778 | |
779 if(data->userOrientation != ORIENTATION_UP) | |
780 FrameBufferRotate(&data->fb, data->userOrientation); | |
781 } | |
782 | |
783 void WINCE_LandscapeTransform(WINCE_RenderData* data, int width, int height) | |
784 { | |
785 switch(data->systemOrientation) | |
786 { | |
787 case ORIENTATION_UP: FrameBufferRotate(&data->fb, ORIENTATION_LEFT); break; | |
788 case ORIENTATION_LEFT:FrameBufferRotate(&data->fb, ORIENTATION_DOWN); break; | |
789 case ORIENTATION_DOWN:FrameBufferRotate(&data->fb, ORIENTATION_RIGHT); break; | |
790 default: break; | |
791 } | |
762 | 792 |
763 if(data->fb.width != width || data->fb.height != height) | 793 if(data->fb.width != width || data->fb.height != height) |
764 switch(data->systemOrientation) | 794 switch(data->systemOrientation) |
765 { | 795 { |
766 case ORIENTATION_UP: | 796 case ORIENTATION_UP: |
767 case ORIENTATION_LEFT: data->userOrientation = ORIENTATION_RIGHT; break; | 797 case ORIENTATION_LEFT: data->userOrientation = ORIENTATION_RIGHT; break; |
768 case ORIENTATION_RIGHT: | 798 case ORIENTATION_RIGHT: |
769 case ORIENTATION_DOWN: data->userOrientation = ORIENTATION_LEFT; break; | 799 case ORIENTATION_DOWN: data->userOrientation = ORIENTATION_LEFT; break; |
770 default: break; | 800 default: break; |
771 } | 801 } |
772 | 802 |
773 if(data->userOrientation != ORIENTATION_UP) | 803 if(data->userOrientation != ORIENTATION_UP) |
774 FrameBufferRotate(&data->fb, data->userOrientation); | 804 FrameBufferRotate(&data->fb, data->userOrientation); |
775 } | |
776 | |
777 void WINCE_LandscapeTransform(WINCE_RenderData* data, int width, int height) | |
778 { | |
779 switch(data->systemOrientation) | |
780 { | |
781 case ORIENTATION_UP: FrameBufferRotate(&data->fb, ORIENTATION_LEFT); break; | |
782 case ORIENTATION_LEFT:FrameBufferRotate(&data->fb, ORIENTATION_DOWN); break; | |
783 case ORIENTATION_DOWN:FrameBufferRotate(&data->fb, ORIENTATION_RIGHT); break; | |
784 default: break; | |
785 } | |
786 | |
787 if(data->fb.width != width || data->fb.height != height) | |
788 switch(data->systemOrientation) | |
789 { | |
790 case ORIENTATION_UP: | |
791 case ORIENTATION_LEFT: data->userOrientation = ORIENTATION_RIGHT; break; | |
792 case ORIENTATION_RIGHT: | |
793 case ORIENTATION_DOWN: data->userOrientation = ORIENTATION_LEFT; break; | |
794 default: break; | |
795 } | |
796 | |
797 if(data->userOrientation != ORIENTATION_UP) | |
798 FrameBufferRotate(&data->fb, data->userOrientation); | |
799 } | 805 } |
800 | 806 |
801 void WINCE_SquareTransform(WINCE_RenderData* data, int width, int height) | 807 void WINCE_SquareTransform(WINCE_RenderData* data, int width, int height) |
802 { | 808 { |
803 WINCE_PortraitTransform(data, width, height); | 809 WINCE_PortraitTransform(data, width, height); |
805 | 811 |
806 int WINCE_FixedGeometry(FrameBufferInfo* fb, int bpp, int debug) | 812 int WINCE_FixedGeometry(FrameBufferInfo* fb, int bpp, int debug) |
807 { | 813 { |
808 // check square | 814 // check square |
809 if(GetSystemMetrics(SM_CXSCREEN) == GetSystemMetrics(SM_CYSCREEN) && | 815 if(GetSystemMetrics(SM_CXSCREEN) == GetSystemMetrics(SM_CYSCREEN) && |
810 fb->width != fb->height) | 816 fb->width != fb->height) |
811 { | 817 { |
812 if(fb->width < fb->height) | 818 if(fb->width < fb->height) |
813 fb->height = fb->width; | 819 fb->height = fb->width; |
814 else | 820 else |
815 if(fb->height < fb->width) | 821 if(fb->height < fb->width) |
816 fb->width = fb->height; | 822 fb->width = fb->height; |
817 } | 823 } |
818 | 824 |
819 // check width | 825 // check width |
820 if(__abs(fb->xpitch) == bpp && | 826 if(__abs(fb->xpitch) == bpp && |
821 fb->width != __abs(fb->ypitch) / bpp) | 827 fb->width != __abs(fb->ypitch) / bpp) |
822 { | 828 { |
823 if(fb->height == __abs(fb->ypitch) / bpp) | 829 if(fb->height == __abs(fb->ypitch) / bpp) |
824 { | 830 { |
825 __swap(&fb->width, &fb->height); | 831 __swap(&fb->width, &fb->height); |
826 | 832 |
827 if(debug) | 833 if(debug) |
828 printf("WINCE_FixedGeometry: width: %d, height: %d\n", fb->width, fb->height); | 834 printf("WINCE_FixedGeometry: width: %d, height: %d\n", fb->width, fb->height); |
829 } | 835 } |
830 else | 836 else |
831 return -1; | 837 return -1; |
832 } | 838 } |
833 else | 839 else |
834 // check height | 840 // check height |
835 if(__abs(fb->ypitch) == bpp && | 841 if(__abs(fb->ypitch) == bpp && |
836 fb->height != __abs(fb->xpitch) / bpp) | 842 fb->height != __abs(fb->xpitch) / bpp) |
837 { | 843 { |
838 if(fb->width == __abs(fb->xpitch) / bpp) | 844 if(fb->width == __abs(fb->xpitch) / bpp) |
839 { | 845 { |
840 __swap(&fb->width, &fb->height); | 846 __swap(&fb->width, &fb->height); |
841 | 847 |
842 if(debug) | 848 if(debug) |
843 printf("WINCE_FixedGeometry: width: %d, height: %d\n", fb->width, fb->height); | 849 printf("WINCE_FixedGeometry: width: %d, height: %d\n", fb->width, fb->height); |
844 } | 850 } |
845 else | 851 else |
846 return -1; | 852 return -1; |
847 } | 853 } |
848 | 854 |
849 return 0; | 855 return 0; |
850 } | 856 } |
851 | 857 |
863 | 869 |
864 int GAPI_Init(WINCE_RenderData* data, HWND hwnd) | 870 int GAPI_Init(WINCE_RenderData* data, HWND hwnd) |
865 { | 871 { |
866 if(NULL == data->gapi) | 872 if(NULL == data->gapi) |
867 { | 873 { |
868 const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); | 874 struct GXDisplayProperties gxProperties; |
869 if(preferably && 0 != SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0; | 875 GXDeviceInfo gxInfo = { 0 }; |
876 HDC hdc; | |
877 int enable, result; | |
878 const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); | |
879 if(preferably && 0 != SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0; | |
870 | 880 |
871 data->gapi = (GapiInfo *) SDL_calloc(1, sizeof(GapiInfo)); | 881 data->gapi = (GapiInfo *) SDL_calloc(1, sizeof(GapiInfo)); |
872 if(NULL == data->gapi) | 882 if(NULL == data->gapi) |
873 { | 883 { |
874 SDL_OutOfMemory(); | 884 SDL_OutOfMemory(); |
875 return 0; | 885 return 0; |
876 } | 886 } |
877 | 887 |
878 data->gapi->hGapiLib = LoadLibrary(TEXT("\\Windows\\gx.dll")); | 888 data->gapi->hGapiLib = LoadLibrary(TEXT("\\Windows\\gx.dll")); |
879 if(0 == data->gapi->hGapiLib) | 889 if(0 == data->gapi->hGapiLib) |
880 { | 890 { |
881 data->gapi->hGapiLib = LoadLibrary(TEXT("gx.dll")); | 891 data->gapi->hGapiLib = LoadLibrary(TEXT("gx.dll")); |
882 if(0 == data->gapi->hGapiLib) return 0; | 892 if(0 == data->gapi->hGapiLib) return 0; |
883 } | 893 } |
884 | 894 |
885 // load gapi library | 895 // load gapi library |
886 #define LINK(type,name,import) name=(PFN##type)GetProcAddress(data->gapi->hGapiLib,TEXT(import)) | 896 #define LINK(type,name,import) name=(PFN##type)GetProcAddress(data->gapi->hGapiLib,TEXT(import)) |
887 LINK(GXOpenDisplay, data->gapi->GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z"); | 897 LINK(GXOpenDisplay, data->gapi->GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z"); |
888 LINK(GXCloseDisplay, data->gapi->GXCloseDisplay, "?GXCloseDisplay@@YAHXZ"); | 898 LINK(GXCloseDisplay, data->gapi->GXCloseDisplay, "?GXCloseDisplay@@YAHXZ"); |
889 LINK(GXBeginDraw, data->gapi->GXBeginDraw, "?GXBeginDraw@@YAPAXXZ"); | 899 LINK(GXBeginDraw, data->gapi->GXBeginDraw, "?GXBeginDraw@@YAPAXXZ"); |
890 LINK(GXEndDraw, data->gapi->GXEndDraw, "?GXEndDraw@@YAHXZ"); | 900 LINK(GXEndDraw, data->gapi->GXEndDraw, "?GXEndDraw@@YAHXZ"); |
891 LINK(GXGetDisplayProperties,data->gapi->GXGetDisplayProperties,"?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ"); | 901 LINK(GXGetDisplayProperties,data->gapi->GXGetDisplayProperties,"?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ"); |
892 LINK(GXSuspend, data->gapi->GXSuspend, "?GXSuspend@@YAHXZ"); | 902 LINK(GXSuspend, data->gapi->GXSuspend, "?GXSuspend@@YAHXZ"); |
893 LINK(GXResume, data->gapi->GXResume, "?GXResume@@YAHXZ"); | 903 LINK(GXResume, data->gapi->GXResume, "?GXResume@@YAHXZ"); |
894 #undef LINK | 904 #undef LINK |
895 | 905 |
896 int enable = data->gapi->GXGetDisplayProperties && data->gapi->GXCloseDisplay && data->gapi->GXOpenDisplay && | 906 enable = data->gapi->GXGetDisplayProperties && data->gapi->GXCloseDisplay && data->gapi->GXOpenDisplay && |
897 data->gapi->GXBeginDraw && data->gapi->GXEndDraw && data->gapi->GXSuspend && data->gapi->GXResume; | 907 data->gapi->GXBeginDraw && data->gapi->GXEndDraw && data->gapi->GXSuspend && data->gapi->GXResume; |
898 | 908 |
899 if(!enable) | 909 if(!enable) |
900 { | 910 { |
901 SDL_SetError("GAPI_Init: error gx.dll: internal error"); | 911 SDL_SetError("GAPI_Init: error gx.dll: internal error"); |
902 GAPI_Quit(data); | 912 GAPI_Quit(data); |
903 return 0; | 913 return 0; |
904 } | 914 } |
905 | 915 |
906 if(0 == data->gapi->GXOpenDisplay(hwnd, GX_FULLSCREEN)) | 916 if(0 == data->gapi->GXOpenDisplay(hwnd, GX_FULLSCREEN)) |
907 { | 917 { |
908 SDL_SetError("GAPI_Init: couldn't initialize GAPI"); | 918 SDL_SetError("GAPI_Init: couldn't initialize GAPI"); |
909 GAPI_Quit(data); | 919 GAPI_Quit(data); |
910 return 0; | 920 return 0; |
911 } | 921 } |
912 | 922 |
913 struct GXDisplayProperties gxProperties = data->gapi->GXGetDisplayProperties(); | 923 gxProperties = data->gapi->GXGetDisplayProperties(); |
914 | 924 |
915 // fill FrameBufferInfo | 925 // fill FrameBufferInfo |
916 data->fb.xpitch = gxProperties.cbxPitch; | 926 data->fb.xpitch = gxProperties.cbxPitch; |
917 data->fb.ypitch = gxProperties.cbyPitch; | 927 data->fb.ypitch = gxProperties.cbyPitch; |
918 data->fb.width = gxProperties.cxWidth; | 928 data->fb.width = gxProperties.cxWidth; |
919 data->fb.height = gxProperties.cyHeight; | 929 data->fb.height = gxProperties.cyHeight; |
920 data->fb.offset = 0; | 930 data->fb.offset = 0; |
921 | 931 |
922 if((gxProperties.ffFormat & kfDirect565) || 16 == gxProperties.cBPP) | 932 if((gxProperties.ffFormat & kfDirect565) || 16 == gxProperties.cBPP) |
923 data->format = SDL_PIXELFORMAT_RGB565; | 933 data->format = SDL_PIXELFORMAT_RGB565; |
924 else | 934 else |
925 if((gxProperties.ffFormat & kfDirect555) || 15 == gxProperties.cBPP) | 935 if((gxProperties.ffFormat & kfDirect555) || 15 == gxProperties.cBPP) |
926 data->format = SDL_PIXELFORMAT_RGB555; | 936 data->format = SDL_PIXELFORMAT_RGB555; |
927 else | 937 else |
928 data->format = 0; | 938 data->format = 0; |
929 | 939 |
930 // get pixels | 940 // get pixels |
931 GXDeviceInfo gxInfo = { 0 }; | 941 hdc = GetDC(NULL); |
932 HDC hdc = GetDC(NULL); | 942 |
933 | 943 gxInfo.Version = 100; |
934 gxInfo.Version = 100; | 944 result = ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo), (char *) &gxInfo); |
935 int result = ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo), (char *) &gxInfo); | 945 ReleaseDC(NULL, hdc); |
936 ReleaseDC(NULL, hdc); | 946 |
937 | 947 if(result > 0) |
938 if(result > 0) | 948 { |
939 { | 949 // more debug |
940 // more debug | 950 if(data->debug) |
941 if(data->debug) | 951 { |
942 { | 952 int i; |
943 printf("GXDeviceInfo.pvFrameBuffer: %p\n", gxInfo.pvFrameBuffer); | 953 |
944 printf("GXDeviceInfo.cxWidth: %d\n", gxInfo.cxWidth); | 954 printf("GXDeviceInfo.pvFrameBuffer: %p\n", gxInfo.pvFrameBuffer); |
945 printf("GXDeviceInfo.cyHeight: %d\n", gxInfo.cyHeight); | 955 printf("GXDeviceInfo.cxWidth: %d\n", gxInfo.cxWidth); |
946 printf("GXDeviceInfo.cbStride: %d\n", gxInfo.cbStride); | 956 printf("GXDeviceInfo.cyHeight: %d\n", gxInfo.cyHeight); |
947 printf("GXDeviceInfo.cBPP: %d\n", gxInfo.cBPP); | 957 printf("GXDeviceInfo.cbStride: %d\n", gxInfo.cbStride); |
948 printf("GXDeviceInfo.ffFormat: 0x%x\n", gxInfo.ffFormat); | 958 printf("GXDeviceInfo.cBPP: %d\n", gxInfo.cBPP); |
949 | 959 printf("GXDeviceInfo.ffFormat: 0x%x\n", gxInfo.ffFormat); |
950 printf("GXDeviceInfo.unk:\n"); | 960 |
951 int ii; for(ii = 0; ii < sizeof(gxInfo.unknown); ++ii) | 961 printf("GXDeviceInfo.unk:\n"); |
952 printf("0x%02hhX,", gxInfo.unknown[ii]); | 962 for(i = 0; i < sizeof(gxInfo.unknown); ++i) |
953 printf("\n"); | 963 printf("0x%02hhX,", gxInfo.unknown[i]); |
954 } | 964 printf("\n"); |
955 | 965 } |
956 if(gxInfo.ffFormat && gxInfo.ffFormat != gxProperties.ffFormat) | 966 |
957 { | 967 if(gxInfo.ffFormat && gxInfo.ffFormat != gxProperties.ffFormat) { |
958 if((gxInfo.ffFormat & kfDirect565) || 16 == gxInfo.cBPP) | 968 if((gxInfo.ffFormat & kfDirect565) || 16 == gxInfo.cBPP) |
959 data->format = SDL_PIXELFORMAT_RGB565; | 969 data->format = SDL_PIXELFORMAT_RGB565; |
960 else | 970 else |
961 if((gxInfo.ffFormat & kfDirect555) || 15 == gxInfo.cBPP) | 971 if((gxInfo.ffFormat & kfDirect555) || 15 == gxInfo.cBPP) |
962 data->format = SDL_PIXELFORMAT_RGB555; | 972 data->format = SDL_PIXELFORMAT_RGB555; |
963 } | 973 } |
964 | 974 |
965 data->pixels = gxInfo.pvFrameBuffer; | 975 data->pixels = gxInfo.pvFrameBuffer; |
966 } | 976 } |
967 else | 977 else |
968 { | 978 { |
969 data->flags |= FB_SKIP_OFFSET; | 979 data->flags |= FB_SKIP_OFFSET; |
970 data->pixels = data->gapi->GXBeginDraw(); | 980 data->pixels = data->gapi->GXBeginDraw(); |
971 data->gapi->GXEndDraw(); | 981 data->gapi->GXEndDraw(); |
972 | 982 |
973 if(data->debug) | 983 if(data->debug) |
974 { | 984 { |
975 printf("GAPI_Init\n"); | 985 printf("GAPI_Init\n"); |
976 printf("use GXBeginDraw: %p\n", data->pixels); | 986 printf("use GXBeginDraw: %p\n", data->pixels); |
977 printf("use skip offset\n"); | 987 printf("use skip offset\n"); |
978 } | 988 } |
979 } | 989 } |
980 | 990 |
981 if(0 == data->format || | 991 if(0 == data->format || |
982 0 > WINCE_FixedGeometry(&data->fb, SDL_BYTESPERPIXEL(data->format), data->debug)) | 992 0 > WINCE_FixedGeometry(&data->fb, SDL_BYTESPERPIXEL(data->format), data->debug)) |
983 { | 993 { |
984 SDL_SetError("GAPI_Init: unknown hardware"); | 994 SDL_SetError("GAPI_Init: unknown hardware"); |
985 GAPI_Quit(data); | 995 GAPI_Quit(data); |
986 return 0; | 996 return 0; |
987 } | 997 } |
988 } | 998 } |
989 | 999 |
990 return data->gapi && data->pixels ? 1 : 0; | 1000 return data->gapi && data->pixels ? 1 : 0; |
991 } | 1001 } |
992 | 1002 |
993 void GAPI_Quit(WINCE_RenderData* data) | 1003 void GAPI_Quit(WINCE_RenderData* data) |
994 { | 1004 { |
995 if(data->gapi) | 1005 if(data->gapi) |
996 { | 1006 { |
997 if(data->gapi->GXCloseDisplay) data->gapi->GXCloseDisplay(); | 1007 if(data->gapi->GXCloseDisplay) data->gapi->GXCloseDisplay(); |
998 if(data->gapi->hGapiLib) FreeLibrary(data->gapi->hGapiLib); | 1008 if(data->gapi->hGapiLib) FreeLibrary(data->gapi->hGapiLib); |
999 | 1009 |
1000 SDL_free(data->gapi); | 1010 SDL_free(data->gapi); |
1001 data->gapi = NULL; | 1011 data->gapi = NULL; |
1002 } | 1012 } |
1003 } | 1013 } |
1004 | 1014 |
1005 int RAW_Init(WINCE_RenderData* data) | 1015 int RAW_Init(WINCE_RenderData* data) |
1006 { | 1016 { |
1017 RawFrameBufferInfo rfbi = { 0 }; | |
1018 HDC hdc; | |
1019 int result; | |
1007 const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); | 1020 const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); |
1008 if(preferably && 0 != SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0; | 1021 if(preferably && 0 != SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0; |
1009 | 1022 |
1010 RawFrameBufferInfo rfbi = { 0 }; | 1023 hdc = GetDC(NULL); |
1011 HDC hdc = GetDC(NULL); | 1024 result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi); |
1012 int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi); | |
1013 ReleaseDC(NULL, hdc); | 1025 ReleaseDC(NULL, hdc); |
1014 | 1026 |
1015 //disable | 1027 //disable |
1016 if(result == 0 || rfbi.pFramePointer == 0 || | 1028 if(result == 0 || rfbi.pFramePointer == 0 || |
1017 rfbi.cxPixels == 0 || rfbi.cyPixels == 0 || | 1029 rfbi.cxPixels == 0 || rfbi.cyPixels == 0 || |
1018 rfbi.cxStride == 0 || rfbi.cyStride == 0) return 0; | 1030 rfbi.cxStride == 0 || rfbi.cyStride == 0) return 0; |
1019 | 1031 |
1020 data->flags = FB_RAW_MODE; | 1032 data->flags = FB_RAW_MODE; |
1021 | 1033 |
1022 // fill FrameBufferInfo | 1034 // fill FrameBufferInfo |
1023 SDL_memset(&data->fb, 0, sizeof(FrameBufferInfo)); | 1035 SDL_memset(&data->fb, 0, sizeof(FrameBufferInfo)); |
1027 data->fb.width = rfbi.cxPixels; | 1039 data->fb.width = rfbi.cxPixels; |
1028 data->fb.height = rfbi.cyPixels; | 1040 data->fb.height = rfbi.cyPixels; |
1029 data->fb.offset = 0; | 1041 data->fb.offset = 0; |
1030 | 1042 |
1031 if((FORMAT_565 & rfbi.wFormat) || 16 == rfbi.wBPP) | 1043 if((FORMAT_565 & rfbi.wFormat) || 16 == rfbi.wBPP) |
1032 data->format = SDL_PIXELFORMAT_RGB565; | 1044 data->format = SDL_PIXELFORMAT_RGB565; |
1033 else | 1045 else |
1034 if((FORMAT_555 & rfbi.wFormat) || 15 == rfbi.wBPP) | 1046 if((FORMAT_555 & rfbi.wFormat) || 15 == rfbi.wBPP) |
1035 data->format = SDL_PIXELFORMAT_RGB555; | 1047 data->format = SDL_PIXELFORMAT_RGB555; |
1036 else | 1048 else |
1037 data->format = 0; | 1049 data->format = 0; |
1038 | 1050 |
1039 if(0 == data->format || | 1051 if(0 == data->format || |
1040 0 > WINCE_FixedGeometry(&data->fb, SDL_BYTESPERPIXEL(data->format), data->debug)) | 1052 0 > WINCE_FixedGeometry(&data->fb, SDL_BYTESPERPIXEL(data->format), data->debug)) |
1041 { | 1053 { |
1042 SDL_SetError("RAW_Init: unknown hardware"); | 1054 SDL_SetError("RAW_Init: unknown hardware"); |
1043 RAW_Quit(data); | 1055 RAW_Quit(data); |
1044 return 0; | 1056 return 0; |
1045 } | 1057 } |
1046 | 1058 |
1047 data->pixels = rfbi.pFramePointer; | 1059 data->pixels = rfbi.pFramePointer; |
1048 | 1060 |
1049 return data->pixels ? 1 : 0; | 1061 return data->pixels ? 1 : 0; |
1058 int orientation = GetFrameBufferOrientation(fb); | 1070 int orientation = GetFrameBufferOrientation(fb); |
1059 | 1071 |
1060 // set correct start offset | 1072 // set correct start offset |
1061 switch(orientation) | 1073 switch(orientation) |
1062 { | 1074 { |
1063 case ORIENTATION_UP: | 1075 case ORIENTATION_UP: |
1064 fb->offset = 0; | 1076 fb->offset = 0; |
1065 break; | 1077 break; |
1066 | 1078 |
1067 case ORIENTATION_LEFT: | 1079 case ORIENTATION_LEFT: |
1068 fb->offset = __abs(fb->ypitch * (fb->height - 1)); | 1080 fb->offset = __abs(fb->ypitch * (fb->height - 1)); |
1069 break; | 1081 break; |
1070 | 1082 |
1071 case ORIENTATION_RIGHT: | 1083 case ORIENTATION_RIGHT: |
1072 fb->offset = __abs(fb->xpitch * (fb->width - 1)); | 1084 fb->offset = __abs(fb->xpitch * (fb->width - 1)); |
1073 break; | 1085 break; |
1074 | 1086 |
1075 case ORIENTATION_DOWN: | 1087 case ORIENTATION_DOWN: |
1076 fb->offset = __abs(fb->xpitch * (fb->width - 1) + | 1088 fb->offset = __abs(fb->xpitch * (fb->width - 1) + |
1077 fb->ypitch * (fb->height - 1)); | 1089 fb->ypitch * (fb->height - 1)); |
1078 break; | 1090 break; |
1079 | 1091 |
1080 default: break; | 1092 default: break; |
1081 } | 1093 } |
1082 | 1094 |
1083 //if(orientation != ORIENTATION_UP) | 1095 //if(orientation != ORIENTATION_UP) |
1084 switch(orientation) | 1096 switch(orientation) |
1085 { | 1097 { |
1086 case ORIENTATION_LEFT: FrameBufferRotate(fb, ORIENTATION_RIGHT); break; | 1098 case ORIENTATION_LEFT: FrameBufferRotate(fb, ORIENTATION_RIGHT); break; |
1087 case ORIENTATION_RIGHT:FrameBufferRotate(fb, ORIENTATION_LEFT); break; | 1099 case ORIENTATION_RIGHT:FrameBufferRotate(fb, ORIENTATION_LEFT); break; |
1088 case ORIENTATION_DOWN: FrameBufferRotate(fb, ORIENTATION_DOWN); break; | 1100 case ORIENTATION_DOWN: FrameBufferRotate(fb, ORIENTATION_DOWN); break; |
1089 | 1101 |
1090 default: break; | 1102 default: break; |
1091 } | 1103 } |
1092 } | 1104 } |
1093 | 1105 |
1094 int GetFrameBufferOrientation(const FrameBufferInfo* src) | 1106 int GetFrameBufferOrientation(const FrameBufferInfo* src) |
1095 { | 1107 { |
1096 if(src->xpitch > 0 && src->ypitch > 0) | 1108 if(src->xpitch > 0 && src->ypitch > 0) |
1097 return ORIENTATION_UP; | 1109 return ORIENTATION_UP; |
1098 else | 1110 else |
1099 if(src->xpitch > 0 && src->ypitch < 0) | 1111 if(src->xpitch > 0 && src->ypitch < 0) |
1100 return ORIENTATION_LEFT; | 1112 return ORIENTATION_LEFT; |
1101 else | 1113 else |
1102 if(src->xpitch < 0 && src->ypitch > 0) | 1114 if(src->xpitch < 0 && src->ypitch > 0) |
1103 return ORIENTATION_RIGHT; | 1115 return ORIENTATION_RIGHT; |
1104 else | 1116 else |
1105 if(src->xpitch < 0 && src->ypitch < 0) | 1117 if(src->xpitch < 0 && src->ypitch < 0) |
1106 return ORIENTATION_DOWN; | 1118 return ORIENTATION_DOWN; |
1107 | 1119 |
1108 return ORIENTATION_UNKNOWN; | 1120 return ORIENTATION_UNKNOWN; |
1109 } | 1121 } |
1110 | 1122 |
1111 void FrameBufferRotate(FrameBufferInfo* dst, int orientation) | 1123 void FrameBufferRotate(FrameBufferInfo* dst, int orientation) |
1115 SDL_memcpy(&src, dst, sizeof(FrameBufferInfo)); | 1127 SDL_memcpy(&src, dst, sizeof(FrameBufferInfo)); |
1116 | 1128 |
1117 switch(orientation) | 1129 switch(orientation) |
1118 { | 1130 { |
1119 case ORIENTATION_LEFT: | 1131 case ORIENTATION_LEFT: |
1120 dst->width = src.height; | 1132 dst->width = src.height; |
1121 dst->height = src.width; | 1133 dst->height = src.width; |
1122 dst->xpitch = src.ypitch; | 1134 dst->xpitch = src.ypitch; |
1123 dst->ypitch = -src.xpitch; | 1135 dst->ypitch = -src.xpitch; |
1124 dst->offset = src.offset + src.xpitch * (src.width - 1); | 1136 dst->offset = src.offset + src.xpitch * (src.width - 1); |
1125 break; | 1137 break; |
1126 | 1138 |
1127 case ORIENTATION_RIGHT: | 1139 case ORIENTATION_RIGHT: |
1128 dst->width = src.height; | 1140 dst->width = src.height; |
1129 dst->height = src.width; | 1141 dst->height = src.width; |
1130 dst->xpitch = -src.ypitch; | 1142 dst->xpitch = -src.ypitch; |
1131 dst->ypitch = src.xpitch; | 1143 dst->ypitch = src.xpitch; |
1132 dst->offset = src.offset + src.ypitch * (src.height - 1); | 1144 dst->offset = src.offset + src.ypitch * (src.height - 1); |
1133 break; | 1145 break; |
1134 | 1146 |
1135 case ORIENTATION_DOWN: | 1147 case ORIENTATION_DOWN: |
1136 FrameBufferRotate(dst, ORIENTATION_LEFT); | 1148 FrameBufferRotate(dst, ORIENTATION_LEFT); |
1137 FrameBufferRotate(dst, ORIENTATION_LEFT); | 1149 FrameBufferRotate(dst, ORIENTATION_LEFT); |
1138 break; | 1150 break; |
1139 | 1151 |
1140 default: | 1152 default: |
1141 break; | 1153 break; |
1142 } | 1154 } |
1143 } | 1155 } |
1144 | 1156 |
1145 void PointerRotate(POINT* pt, const FrameBufferInfo* fb, int orientation) | 1157 void PointerRotate(POINT* pt, const FrameBufferInfo* fb, int orientation) |
1146 { | 1158 { |
1147 switch(orientation) | 1159 switch(orientation) |
1148 { | 1160 { |
1149 case ORIENTATION_UP: | 1161 case ORIENTATION_UP: |
1150 break; | 1162 break; |
1151 | 1163 |
1152 case ORIENTATION_LEFT: | 1164 case ORIENTATION_LEFT: |
1153 { | 1165 { |
1154 int temp = pt->y; | 1166 int temp = pt->y; |
1155 pt->y = fb->height - pt->x; | 1167 pt->y = fb->height - pt->x; |
1156 pt->x = temp; | 1168 pt->x = temp; |
1157 } | 1169 } |
1158 break; | 1170 break; |
1159 | 1171 |
1160 case ORIENTATION_RIGHT: | 1172 case ORIENTATION_RIGHT: |
1161 { | 1173 { |
1162 int temp = pt->x; | 1174 int temp = pt->x; |
1163 pt->x = fb->width - pt->y; | 1175 pt->x = fb->width - pt->y; |
1164 pt->y = temp; | 1176 pt->y = temp; |
1165 } | 1177 } |
1166 break; | 1178 break; |
1167 | 1179 |
1168 case ORIENTATION_DOWN: | 1180 case ORIENTATION_DOWN: |
1169 pt->x = fb->width - pt->x; | 1181 pt->x = fb->width - pt->x; |
1170 pt->y = fb->height - pt->y; | 1182 pt->y = fb->height - pt->y; |
1171 break; | 1183 break; |
1172 | 1184 |
1173 default: break; | 1185 default: break; |
1174 } | 1186 } |
1175 } | 1187 } |
1176 | 1188 |
1177 const char* GetOrientationName(int orientation) | 1189 const char* GetOrientationName(int orientation) |
1178 { | 1190 { |
1194 sDevMode.dmSize = sizeof(DEVMODE); | 1206 sDevMode.dmSize = sizeof(DEVMODE); |
1195 sDevMode.dmFields = DM_DISPLAYORIENTATION; | 1207 sDevMode.dmFields = DM_DISPLAYORIENTATION; |
1196 | 1208 |
1197 // DMDO_0, DMDO_90, DMDO_180, DMDO_270 | 1209 // DMDO_0, DMDO_90, DMDO_180, DMDO_270 |
1198 if(DISP_CHANGE_BADMODE != ChangeDisplaySettingsEx(NULL, &sDevMode, 0, CDS_TEST, NULL)) | 1210 if(DISP_CHANGE_BADMODE != ChangeDisplaySettingsEx(NULL, &sDevMode, 0, CDS_TEST, NULL)) |
1199 switch(sDevMode.dmDisplayOrientation) | 1211 switch(sDevMode.dmDisplayOrientation) |
1200 { | 1212 { |
1201 case DMDO_0: return DMDO_0; | 1213 case DMDO_0: return DMDO_0; |
1202 case DMDO_90: return DMDO_90; | 1214 case DMDO_90: return DMDO_90; |
1203 case DMDO_180: return DMDO_180; | 1215 case DMDO_180: return DMDO_180; |
1204 case DMDO_270: return DMDO_270; | 1216 case DMDO_270: return DMDO_270; |
1205 default: break; | 1217 default: break; |
1206 } | 1218 } |
1207 | 1219 |
1208 SDL_SetError("WINCE_GetDMOrientation: ChangeDisplaySettingsEx return BADMODE"); | 1220 SDL_SetError("WINCE_GetDMOrientation: ChangeDisplaySettingsEx return BADMODE"); |
1209 return -1; | 1221 return -1; |
1210 } | 1222 } |
1211 | 1223 |
1215 sDevMode.dmSize = sizeof(DEVMODE); | 1227 sDevMode.dmSize = sizeof(DEVMODE); |
1216 sDevMode.dmFields = DM_DISPLAYORIENTATION; | 1228 sDevMode.dmFields = DM_DISPLAYORIENTATION; |
1217 | 1229 |
1218 switch(orientation) | 1230 switch(orientation) |
1219 { | 1231 { |
1220 case DMDO_0: sDevMode.dmDisplayOrientation = DMDO_0; break; | 1232 case DMDO_0: sDevMode.dmDisplayOrientation = DMDO_0; break; |
1221 case DMDO_90: sDevMode.dmDisplayOrientation = DMDO_90; break; | 1233 case DMDO_90: sDevMode.dmDisplayOrientation = DMDO_90; break; |
1222 case DMDO_180: sDevMode.dmDisplayOrientation = DMDO_180; break; | 1234 case DMDO_180: sDevMode.dmDisplayOrientation = DMDO_180; break; |
1223 case DMDO_270: sDevMode.dmDisplayOrientation = DMDO_270; break; | 1235 case DMDO_270: sDevMode.dmDisplayOrientation = DMDO_270; break; |
1224 default: return 0; | 1236 default: return 0; |
1225 } | 1237 } |
1226 | 1238 |
1227 if(DISP_CHANGE_BADMODE != ChangeDisplaySettingsEx(NULL, &sDevMode, 0, CDS_RESET, NULL)) | 1239 if(DISP_CHANGE_BADMODE != ChangeDisplaySettingsEx(NULL, &sDevMode, 0, CDS_RESET, NULL)) |
1228 return 1; | 1240 return 1; |
1229 | 1241 |
1230 SDL_SetError("WINCE_SetDMOrientation: ChangeDisplaySettingsEx return BADMODE"); | 1242 SDL_SetError("WINCE_SetDMOrientation: ChangeDisplaySettingsEx return BADMODE"); |
1231 return -1; | 1243 return -1; |
1232 } | 1244 } |
1233 | 1245 |
1234 void FrameBufferDumpInfo(const FrameBufferInfo* fb, const char* name) | 1246 void FrameBufferDumpInfo(const FrameBufferInfo* fb, const char* name) |
1235 { | 1247 { |
1248 int orientation; | |
1249 | |
1236 printf("%s fb.width: %d\n", name, fb->width); | 1250 printf("%s fb.width: %d\n", name, fb->width); |
1237 printf("%s fb.height: %d\n", name, fb->height); | 1251 printf("%s fb.height: %d\n", name, fb->height); |
1238 printf("%s fb.xpitch: %d\n", name, fb->xpitch); | 1252 printf("%s fb.xpitch: %d\n", name, fb->xpitch); |
1239 printf("%s fb.ypitch: %d\n", name, fb->ypitch); | 1253 printf("%s fb.ypitch: %d\n", name, fb->ypitch); |
1240 printf("%s fb.offset: %d\n", name, fb->offset); | 1254 printf("%s fb.offset: %d\n", name, fb->offset); |
1241 | 1255 |
1242 int orientation = GetFrameBufferOrientation(fb); | 1256 orientation = GetFrameBufferOrientation(fb); |
1243 printf("%s fb.orientation: %d, %s\n", name, orientation, GetOrientationName(orientation)); | 1257 printf("%s fb.orientation: %d, %s\n", name, orientation, GetOrientationName(orientation)); |
1244 } | 1258 } |
1245 | 1259 |
1246 void UpdateLine16to16(const FrameBufferInfo* fb, const Uint16* src, Uint16* dst, Uint16 width) | 1260 void UpdateLine16to16(const FrameBufferInfo* fb, const Uint16* src, Uint16* dst, Uint16 width) |
1247 { | 1261 { |
1248 if(2 == fb->xpitch) | 1262 if(2 == fb->xpitch) |
1249 { | 1263 { |
1250 switch(width) | 1264 switch(width) |
1251 { | 1265 { |
1252 case 1: | 1266 case 1: |
1253 *dst = *src; | 1267 *dst = *src; |
1254 break; | 1268 break; |
1255 | 1269 |
1256 case 2: | 1270 case 2: |
1257 *((Uint32*) dst) = *((Uint32*) src); | 1271 *((Uint32*) dst) = *((Uint32*) src); |
1258 break; | 1272 break; |
1259 | 1273 |
1260 default: | 1274 default: |
1261 SDL_memcpy(dst, src, width * 2); | 1275 SDL_memcpy(dst, src, width * 2); |
1262 break; | 1276 break; |
1263 } | 1277 } |
1264 } | 1278 } |
1265 else | 1279 else |
1266 if(-2 == fb->xpitch) | 1280 if(-2 == fb->xpitch) |
1267 { | 1281 { |
1268 while(width--) | 1282 while(width--) |
1269 *dst-- = *src++; | 1283 *dst-- = *src++; |
1270 } | 1284 } |
1271 else | 1285 else |
1272 { | 1286 { |
1273 while(width--) | 1287 while(width--) |
1274 { | 1288 { |
1275 *dst = *src++; | 1289 *dst = *src++; |
1276 dst += fb->xpitch / 2; | 1290 dst += fb->xpitch / 2; |
1277 } | 1291 } |
1278 } | 1292 } |
1279 } | 1293 } |
1280 | 1294 |
1281 #endif // SDL_VIDEO_RENDER_GAPI | 1295 #endif // SDL_VIDEO_RENDER_GAPI |