comparison src/video/win32/SDL_gdirender.c @ 3097:0d12e8f1de3c

Date: Thu, 05 Feb 2009 18:07:35 +0100 From: Stefan Klug Subject: [SDL] SDL 1.3 WinCE backend as promised, I've started to work on the WinCE backend of SDL 1.3 I've modified the win32 video backend and the gdi renderer, to work properly in WinCE. The results till now are great, but there is still some work to do. Attached are two patches with my changes. I would be happy if someone could review and propably commit them. The first one (configure.in.patch) should be straight forward without any side effects. The second one does the necessary changes to the win32 backend. I was really unhappy to start slicing this shiny new backend with #ifdef/#endif but I saw no other option. The most problematic issues are: - WinCe has no GetDIBits, so its practically impossible to fill a BITMAPINFO with correct values. I therefore removed the bmi member from the GDI_RenderData in SDL_gdirender.c to prevent usage of a not or not properly initialized bmi. - In SDL_win32window.c I exchanged some ASCII function by their general counterparts, (In CE only the Unicode versions are available). I don't know if this has a negative effect when running in win32 Cheers Stefan
author Sam Lantinga <slouken@libsdl.org>
date Mon, 23 Mar 2009 05:35:21 +0000
parents a434fe6360df
children 7f684f249ec9
comparison
equal deleted inserted replaced
3096:ae4e80dbe330 3097:0d12e8f1de3c
25 25
26 #include "SDL_win32video.h" 26 #include "SDL_win32video.h"
27 #include "../SDL_rect_c.h" 27 #include "../SDL_rect_c.h"
28 #include "../SDL_yuv_sw_c.h" 28 #include "../SDL_yuv_sw_c.h"
29 #include "../SDL_alphamult.h" 29 #include "../SDL_alphamult.h"
30
31 #ifdef _WIN32_WCE
32 #define NO_GETDIBBITS 1
33 #endif
30 34
31 /* GDI renderer implementation */ 35 /* GDI renderer implementation */
32 36
33 static SDL_Renderer *GDI_CreateRenderer(SDL_Window * window, Uint32 flags); 37 static SDL_Renderer *GDI_CreateRenderer(SDL_Window * window, Uint32 flags);
34 static int GDI_DisplayModeChanged(SDL_Renderer * renderer); 38 static int GDI_DisplayModeChanged(SDL_Renderer * renderer);
104 HWND hwnd; 108 HWND hwnd;
105 HDC window_hdc; 109 HDC window_hdc;
106 HDC render_hdc; 110 HDC render_hdc;
107 HDC memory_hdc; 111 HDC memory_hdc;
108 HDC current_hdc; 112 HDC current_hdc;
113 #ifndef NO_GETDIBBITS
109 LPBITMAPINFO bmi; 114 LPBITMAPINFO bmi;
115 #endif
110 HBITMAP hbm[3]; 116 HBITMAP hbm[3];
111 int current_hbm; 117 int current_hbm;
112 SDL_DirtyRectList dirty; 118 SDL_DirtyRectList dirty;
113 SDL_bool makedirty; 119 SDL_bool makedirty;
114 } GDI_RenderData; 120 } GDI_RenderData;
195 data->hwnd = windowdata->hwnd; 201 data->hwnd = windowdata->hwnd;
196 data->window_hdc = windowdata->hdc; 202 data->window_hdc = windowdata->hdc;
197 data->render_hdc = CreateCompatibleDC(data->window_hdc); 203 data->render_hdc = CreateCompatibleDC(data->window_hdc);
198 data->memory_hdc = CreateCompatibleDC(data->window_hdc); 204 data->memory_hdc = CreateCompatibleDC(data->window_hdc);
199 205
206 #ifndef NO_GETDIBBITS
200 /* Fill in the compatible bitmap info */ 207 /* Fill in the compatible bitmap info */
201 bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD); 208 bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
202 data->bmi = (LPBITMAPINFO) SDL_calloc(1, bmi_size); 209 data->bmi = (LPBITMAPINFO) SDL_calloc(1, bmi_size);
203 if (!data->bmi) { 210 if (!data->bmi) {
204 GDI_DestroyRenderer(renderer); 211 GDI_DestroyRenderer(renderer);
209 216
210 hbm = CreateCompatibleBitmap(data->window_hdc, 1, 1); 217 hbm = CreateCompatibleBitmap(data->window_hdc, 1, 1);
211 GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS); 218 GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
212 GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS); 219 GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
213 DeleteObject(hbm); 220 DeleteObject(hbm);
221 #endif
214 222
215 if (flags & SDL_RENDERER_SINGLEBUFFER) { 223 if (flags & SDL_RENDERER_SINGLEBUFFER) {
216 renderer->info.flags |= 224 renderer->info.flags |=
217 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY); 225 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY);
218 n = 0; 226 n = 0;
471 case SDL_BLENDMODE_NONE: 479 case SDL_BLENDMODE_NONE:
472 if (data->premultiplied) { 480 if (data->premultiplied) {
473 /* Crap, we've lost the original pixel data... *sigh* */ 481 /* Crap, we've lost the original pixel data... *sigh* */
474 } 482 }
475 return 0; 483 return 0;
484 #ifndef _WIN32_WCE /* WinCE has no alphablend */
476 case SDL_BLENDMODE_MASK: 485 case SDL_BLENDMODE_MASK:
477 case SDL_BLENDMODE_BLEND: 486 case SDL_BLENDMODE_BLEND:
478 if (!data->premultiplied && data->pixels) { 487 if (!data->premultiplied && data->pixels) {
479 switch (texture->format) { 488 switch (texture->format) {
480 case SDL_PIXELFORMAT_ARGB8888: 489 case SDL_PIXELFORMAT_ARGB8888:
502 data->premultiplied = SDL_TRUE; 511 data->premultiplied = SDL_TRUE;
503 break; 512 break;
504 } 513 }
505 } 514 }
506 return 0; 515 return 0;
516 #endif
507 default: 517 default:
508 SDL_Unsupported(); 518 SDL_Unsupported();
509 texture->blendMode = SDL_BLENDMODE_NONE; 519 texture->blendMode = SDL_BLENDMODE_NONE;
510 return -1; 520 return -1;
511 } 521 }
583 data->pitch); 593 data->pitch);
584 break; 594 break;
585 } 595 }
586 } 596 }
587 } else if (rect->w == texture->w && pitch == data->pitch) { 597 } else if (rect->w == texture->w && pitch == data->pitch) {
598 #ifndef NO_GETDIBBITS
588 if (!SetDIBits 599 if (!SetDIBits
589 (renderdata->window_hdc, data->hbm, rect->y, rect->h, pixels, 600 (renderdata->window_hdc, data->hbm, rect->y, rect->h, pixels,
590 renderdata->bmi, DIB_RGB_COLORS)) { 601 renderdata->bmi, DIB_RGB_COLORS)) {
591 WIN_SetError("SetDIBits()"); 602 WIN_SetError("SetDIBits()");
592 return -1; 603 return -1;
593 } 604 }
605 #else
606 SDL_SetError("FIXME: Update Texture");
607 return -1;
608 #endif
594 } else { 609 } else {
595 SDL_SetError 610 SDL_SetError
596 ("FIXME: Need to allocate temporary memory and do GetDIBits() followed by SetDIBits(), since we can only set blocks of scanlines at a time"); 611 ("FIXME: Need to allocate temporary memory and do GetDIBits() followed by SetDIBits(), since we can only set blocks of scanlines at a time");
597 return -1; 612 return -1;
598 } 613 }
609 624
610 if (data->yuv) { 625 if (data->yuv) {
611 return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels, 626 return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
612 pitch); 627 pitch);
613 } else if (data->pixels) { 628 } else if (data->pixels) {
629 #ifndef _WIN32_WCE
630 /* WinCE has no GdiFlush */
614 GdiFlush(); 631 GdiFlush();
632 #endif
615 *pixels = 633 *pixels =
616 (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + 634 (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
617 rect->x * SDL_BYTESPERPIXEL(texture->format)); 635 rect->x * SDL_BYTESPERPIXEL(texture->format));
618 *pitch = data->pitch; 636 *pitch = data->pitch;
619 return 0; 637 return 0;
758 if (texturedata->hpal) { 776 if (texturedata->hpal) {
759 SelectPalette(data->memory_hdc, texturedata->hpal, TRUE); 777 SelectPalette(data->memory_hdc, texturedata->hpal, TRUE);
760 RealizePalette(data->memory_hdc); 778 RealizePalette(data->memory_hdc);
761 } 779 }
762 if (texture->blendMode & (SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND)) { 780 if (texture->blendMode & (SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND)) {
781 #ifdef _WIN32_WCE
782 SDL_SetError("Texture has blendmode not supported under WinCE");
783 return -1;
784 #else
763 BLENDFUNCTION blendFunc = { 785 BLENDFUNCTION blendFunc = {
764 AC_SRC_OVER, 786 AC_SRC_OVER,
765 0, 787 0,
766 texture->a, 788 texture->a,
767 AC_SRC_ALPHA 789 AC_SRC_ALPHA
771 dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w, 793 dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w,
772 srcrect->h, blendFunc)) { 794 srcrect->h, blendFunc)) {
773 WIN_SetError("AlphaBlend()"); 795 WIN_SetError("AlphaBlend()");
774 return -1; 796 return -1;
775 } 797 }
798 #endif
776 } else { 799 } else {
777 if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) { 800 if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
778 if (!BitBlt 801 if (!BitBlt
779 (data->current_hdc, dstrect->x, dstrect->y, dstrect->w, 802 (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
780 srcrect->h, data->memory_hdc, srcrect->x, srcrect->y, 803 srcrect->h, data->memory_hdc, srcrect->x, srcrect->y,
849 int i; 872 int i;
850 873
851 if (data) { 874 if (data) {
852 DeleteDC(data->render_hdc); 875 DeleteDC(data->render_hdc);
853 DeleteDC(data->memory_hdc); 876 DeleteDC(data->memory_hdc);
877 #ifndef NO_GETDIBBITS
854 if (data->bmi) { 878 if (data->bmi) {
855 SDL_free(data->bmi); 879 SDL_free(data->bmi);
856 } 880 }
881 #endif
857 for (i = 0; i < SDL_arraysize(data->hbm); ++i) { 882 for (i = 0; i < SDL_arraysize(data->hbm); ++i) {
858 if (data->hbm[i]) { 883 if (data->hbm[i]) {
859 DeleteObject(data->hbm[i]); 884 DeleteObject(data->hbm[i]);
860 } 885 }
861 } 886 }