annotate src/video/win32/SDL_gapirender.c @ 3520:83518f8fcd61

Fixed calls to SDL_AddRenderDriver()
author Sam Lantinga <slouken@libsdl.org>
date Fri, 04 Dec 2009 08:45:08 +0000
parents 6338b7f2d024
children ce7d4942d18b
rev   line source
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 Stefan Klug
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 klug.stefan@gmx.de
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #include "SDL_config.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 #if SDL_VIDEO_RENDER_GAPI
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include "SDL_win32video.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 //#include "../SDL_sysvideo.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include "../SDL_yuv_sw_c.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #include "../SDL_renderer_sw.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include "SDL_gapirender_c.h"
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #define GAPI_RENDERER_DEBUG 1
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 /* GAPI renderer implementation */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 static SDL_Renderer *GAPI_CreateRenderer(SDL_Window * window, Uint32 flags);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 static int GAPI_RenderPoint(SDL_Renderer * renderer, int x, int y);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 static int GAPI_RenderLine(SDL_Renderer * renderer, int x1, int y1,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 int x2, int y2);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 static int GAPI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 static int GAPI_RenderCopy(SDL_Renderer * renderer,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 const SDL_Rect * srcrect,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 const SDL_Rect * dstrect);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 static void GAPI_RenderPresent(SDL_Renderer * renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 static void GAPI_DestroyRenderer(SDL_Renderer * renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 SDL_RenderDriver GAPI_RenderDriver = {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 GAPI_CreateRenderer,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 "gapi",
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 (SDL_RENDERER_SINGLEBUFFER),
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 static HMODULE g_hGapiLib = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 // for testing with GapiEmu
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 #define USE_GAPI_EMU 0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 #define EMULATE_AXIM_X30 0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 #if 0
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 #define GAPI_LOG(...) printf(__VA_ARGS__)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 #else
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 #define GAPI_LOG(...)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 #endif
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 #if USE_GAPI_EMU && !REPORT_VIDEO_INFO
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 #pragma message("Warning: Using GapiEmu in release build. I assume you'd like to set USE_GAPI_EMU to zero.")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 #endif
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 GAPI_SetError(const char *prefix, HRESULT result)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 const char *error;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 switch (result) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 default:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 error = "UNKNOWN";
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 SDL_SetError("%s: %s", prefix, error);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 GAPI_AddRenderDriver(_THIS)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 {
3520
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3168
diff changeset
95 int i;
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3168
diff changeset
96
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 /* TODO: should we check for support of GetRawFramebuffer here?
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 #if USE_GAPI_EMU
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 g_hGapiLib = LoadLibrary(L"GAPI_Emu.dll");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 #else
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 g_hGapiLib = LoadLibrary(L"\\Windows\\gx.dll");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 #endif
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 if (g_hGapiLib) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 #define LINK(name,import) gx.name = (PFN##name)GetProcAddress( g_hGapiLib, L##import );
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 LINK(GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 LINK(GXCloseDisplay, "?GXCloseDisplay@@YAHXZ")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 LINK(GXBeginDraw, "?GXBeginDraw@@YAPAXXZ")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 LINK(GXEndDraw, "?GXEndDraw@@YAHXZ")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 LINK(GXOpenInput, "?GXOpenInput@@YAHXZ")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 LINK(GXCloseInput, "?GXCloseInput@@YAHXZ")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 LINK(GXGetDisplayProperties,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 "?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 LINK(GXGetDefaultKeys, "?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 LINK(GXSuspend, "?GXSuspend@@YAHXZ")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 LINK(GXResume, "?GXResume@@YAHXZ")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 LINK(GXSetViewport, "?GXSetViewport@@YAHKKKK@Z")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 LINK(GXIsDisplayDRAMBuffer, "?GXIsDisplayDRAMBuffer@@YAHXZ")
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 /* wrong gapi.dll */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 if (!gx.GXOpenDisplay) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 FreeLibrary(g_hGapiLib);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 g_hGapiLib = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 #undef LINK
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129
3520
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3168
diff changeset
130 for (i = 0; i < _this->num_displays; ++i) {
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3168
diff changeset
131 SDL_AddRenderDriver(&_this->displays[i], &GAPI_RenderDriver);
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3168
diff changeset
132 }
3168
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 typedef enum
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 USAGE_GX_FUNCS = 0x0001, /* enable to use GXOpen/GXClose/GXBeginDraw... */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 USAGE_DATA_PTR_CONSTANT = 0x0002 /* the framebuffer is at a constant location, don't use values from GXBeginDraw() */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 } GAPI_UsageFlags;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 typedef struct
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 int w;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 int h;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 int xPitch; /* bytes to move to go to the next pixel */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 int yPitch; /* bytes to move to go to the next line */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 int offset; /* data offset, to add to the data returned from GetFramebuffer, before processing */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 void *data;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 Uint32 usageFlags; /* these flags contain options to define screen handling and to reliably workarounds */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 Uint32 format; /* pixel format as defined in SDL_pixels.h */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 } GAPI_RenderData;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 static Uint32
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 GuessPixelFormatFromBpp(int bpp)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 switch (bpp) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 case 15:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 return SDL_PIXELFORMAT_RGB555;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 case 16:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 return SDL_PIXELFORMAT_RGB565;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 default:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 return SDL_PIXELFORMAT_UNKNOWN;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 static GAPI_RenderData *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 FillRenderDataRawFramebuffer(SDL_Window * window)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 RawFrameBufferInfo rbi;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 GAPI_RenderData *renderdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 HDC hdc;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 //TODO should we use the hdc of the window?
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 hdc = GetDC(NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 int result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 sizeof(RawFrameBufferInfo),
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 (char *) &rbi);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 ReleaseDC(NULL, hdc);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 if (!(result > 0)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 /* Asus A696 returns wrong results so we do a sanity check
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 See:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 http://groups.google.com/group/microsoft.public.smartphone.developer/browse_thread/thread/4fde5bddd477de81
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 if (rbi.cxPixels <= 0 ||
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 rbi.cyPixels <= 0 ||
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 rbi.cxStride == 0 || rbi.cyStride == 0 || rbi.pFramePointer == 0) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 renderdata = (GAPI_RenderData *) SDL_calloc(1, sizeof(*renderdata));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 if (!renderdata) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 //Try to match the window size
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 //TODO add rotation support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 if (rbi.cxPixels != window->w || rbi.cyPixels != window->h) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 SDL_free(renderdata);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 //Check that the display uses a known display format
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 switch (rbi.wFormat) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 case FORMAT_565:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 renderdata->format = SDL_PIXELFORMAT_RGB565;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 case FORMAT_555:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 renderdata->format = SDL_PIXELFORMAT_RGB555;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 default:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 //TODO we should add support for other formats
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 SDL_free(renderdata);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 renderdata->usageFlags = USAGE_DATA_PTR_CONSTANT;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 renderdata->data = rbi.pFramePointer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 renderdata->w = rbi.cxPixels;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 renderdata->h = rbi.cyPixels;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 renderdata->xPitch = rbi.cxStride;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 renderdata->yPitch = rbi.cyStride;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 return renderdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 static GAPI_RenderData *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 FillRenderDataGAPI(SDL_Window * window)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 GAPI_RenderData *renderdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 struct GXDisplayProperties gxdp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 int tmp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 #ifdef _ARM_
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 WCHAR oemstr[100];
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 #endif
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 if (!g_hGapiLib) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 renderdata = (GAPI_RenderData *) SDL_calloc(1, sizeof(GAPI_RenderData));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 if (!renderdata) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 gxdp = gx.GXGetDisplayProperties();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 renderdata->usageFlags = USAGE_GX_FUNCS;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 renderdata->w = gxdp.cxWidth;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 renderdata->h = gxdp.cyHeight;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 renderdata->xPitch = gxdp.cbxPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 renderdata->yPitch = gxdp.cbyPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 //Check that the display uses a known display format
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 if (gxdp.ffFormat & kfDirect565) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 renderdata->format = SDL_PIXELFORMAT_RGB565;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 } else if (gxdp.ffFormat & kfDirect555) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 renderdata->format = SDL_PIXELFORMAT_RGB555;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 renderdata->format = SDL_PIXELFORMAT_UNKNOWN;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 /* apply some device specific corrections */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 #ifdef _ARM_
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 SystemParametersInfo(SPI_GETOEMINFO, sizeof(oemstr), oemstr, 0);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 // buggy iPaq38xx
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 if ((oemstr[12] == 'H') && (oemstr[13] == '3')
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 && (oemstr[14] == '8')
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 && (gxdp.cbxPitch > 0)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 renderdata->data = (void *) 0xac0755a0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 renderdata->xPitch = -640;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 renderdata->yPitch = 2;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 #if (EMULATE_AXIM_X30 == 0)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 // buggy Dell Axim X30
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 if (_tcsncmp(oemstr, L"Dell Axim X30", 13) == 0)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 #endif
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 GXDeviceInfo gxInfo = { 0 };
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 HDC hdc = GetDC(NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 int result;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 gxInfo.Version = 100;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 result =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 ExtEscape(hdc, GETGXINFO, 0, NULL, sizeof(gxInfo),
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 (char *) &gxInfo);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 if (result > 0) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 renderdata->usageFlags = USAGE_DATA_PTR_CONSTANT; /* no more GAPI usage from now */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 renderdata->data = gxInfo.pvFrameBuffer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 this->hidden->needUpdate = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 renderdata->xPitch = 2;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 renderdata->yPitch = 480;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 renderdata->w = gxInfo.cxWidth;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 renderdata->h = gxInfo.cyHeight;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 //Check that the display uses a known display format
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 switch (rbi->wFormat) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 case FORMAT_565:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 renderdata->format = SDL_PIXELFORMAT_RGB565;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 case FORMAT_555:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 renderdata->format = SDL_PIXELFORMAT_RGB555;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 break;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 default:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 //TODO we should add support for other formats
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 SDL_free(renderdata);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 #endif
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 if (renderdata->format == SDL_PIXELFORMAT_UNKNOWN) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 SDL_SetError("Gapi Pixelformat is unknown");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 SDL_free(renderdata);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 /* Gapi always returns values in standard orientation, so we manually apply
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 the current orientation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 DEVMODE settings;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 SDL_memset(&settings, 0, sizeof(DEVMODE));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 settings.dmSize = sizeof(DEVMODE);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 settings.dmFields = DM_DISPLAYORIENTATION;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 if (settings.dmDisplayOrientation == DMDO_90) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 tmp = renderdata->w;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 renderdata->w = renderdata->h;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 renderdata->h = tmp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 tmp = renderdata->xPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 renderdata->xPitch = -renderdata->yPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 renderdata->yPitch = tmp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 renderdata->offset = -renderdata->w * renderdata->xPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 } else if (settings.dmDisplayOrientation == DMDO_180) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 renderdata->xPitch = -renderdata->xPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 renderdata->yPitch = -renderdata->yPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 renderdata->offset = -renderdata->h * renderdata->yPitch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 - renderdata->w * renderdata->xPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 } else if (settings.dmDisplayOrientation == DMDO_270) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 tmp = renderdata->w;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 renderdata->w = renderdata->h;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 renderdata->h = tmp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 tmp = renderdata->xPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 renderdata->xPitch = renderdata->yPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 renderdata->yPitch = -tmp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 renderdata->offset = -renderdata->h * renderdata->yPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 if (renderdata->w != window->w || renderdata->h != window->h) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 GAPI_LOG("GAPI open failed, wrong size %i %i %i %i\n", renderdata->w,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 renderdata->h, renderdata->xPitch, renderdata->yPitch);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 SDL_free(renderdata);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 return renderdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 /* This function does the whole encapsulation of Gapi/RAWFRAMEBUFFER
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 it should handle all the device dependent details and fill the device INDEPENDENT
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 RenderData structure.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 GAPI_RenderData *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 FillRenderData(SDL_Window * window)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 /* We try to match the requested window to the modes available by GAPI and RAWFRAMEBUFFER.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 First RAWFRAMEBUFFER is tried, as it is the most reliable one
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 Look here for detailed discussions:
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 http://pdaphonehome.com/forums/samsung-i700/28087-just-saw.html
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 http://blogs.msdn.com/windowsmobile/archive/2007/08/13/have-you-migrated-to-directdraw-yet.aspx
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 GAPI_RenderData *res;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 res = FillRenderDataRawFramebuffer(window);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 GAPI_LOG("FillRenderDataRawFramebuffer: %p\n", res);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 if (res) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 return res;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 //Now we try gapi
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 res = FillRenderDataGAPI(window);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 GAPI_LOG("FillRenderDataGAPI: %p\n", res);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 return res;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 void *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 GetFramebuffer()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 SDL_Renderer *
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427 GAPI_CreateRenderer(SDL_Window * window, Uint32 flags)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 SDL_DisplayMode *displayMode = &display->current_mode;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 SDL_Renderer *renderer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433 GAPI_RenderData *data;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434 int i, n;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 int bpp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 Uint32 Rmask, Gmask, Bmask, Amask;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 SDL_SetError("Gapi supports only fullscreen windows");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 if (!SDL_PixelFormatEnumToMasks
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444 (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 SDL_SetError("Unknown display format");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 if (!renderer) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455 data = FillRenderData(window);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 if (!data) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 GAPI_DestroyRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
462 renderer->RenderPoint = GAPI_RenderPoint;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463 renderer->RenderLine = GAPI_RenderLine;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 renderer->RenderFill = GAPI_RenderFill;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
465 renderer->RenderCopy = GAPI_RenderCopy;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466 renderer->RenderPresent = GAPI_RenderPresent;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467 renderer->DestroyRenderer = GAPI_DestroyRenderer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468 renderer->info.name = GAPI_RenderDriver.info.name;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 renderer->info.flags = 0;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 renderer->window = window->id;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 renderer->driverdata = data;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 /* Gapi provides only a framebuffer so lets use software implementation */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 Setup_SoftwareRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476 #ifdef GAPI_RENDERER_DEBUG
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 printf("Created gapi renderer\n");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478 printf("use GX functions: %i\n", data->usageFlags & USAGE_GX_FUNCS);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 printf("framebuffer is constant: %i\n",
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480 data->usageFlags & USAGE_DATA_PTR_CONSTANT);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 printf("w: %i h: %i\n", data->w, data->h);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 printf("data ptr: %p\n", data->data); /* this can be 0 in case of GAPI usage */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483 printf("xPitch: %i\n", data->xPitch);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484 printf("yPitch: %i\n", data->yPitch);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 printf("offset: %i\n", data->offset);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 printf("format: %x\n", data->format);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487 #endif
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 if (data->usageFlags & USAGE_GX_FUNCS) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 if (gx.GXOpenDisplay(windowdata->hwnd, GX_FULLSCREEN) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 GAPI_DestroyRenderer(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492 return NULL;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 return renderer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 GAPI_RenderPoint(SDL_Renderer * renderer, int x, int y)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 //TODO implement
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 GAPI_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509 //TODO implement
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510 return -11;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 GAPI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 //TODO implement
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 /* Video memory is very slow so lets optimize as much as possible */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 updateLine16to16(char *src, int srcXPitch, int srcYPitch,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 char *dst, int dstXPitch, int dstYPitch, int width,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 int height)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 char *srcLine, *dstLine;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 char *srcPix, *dstPix;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529 int x, y;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 //First dumb solution
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 if (srcXPitch == 2 && dstXPitch == 2) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533 srcLine = src;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534 dstLine = dst;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
535 y = height;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536 while (y--) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537 SDL_memcpy(dstLine, srcLine, width * sizeof(Uint16));
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538 srcLine += srcYPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 dstLine += dstYPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 } else {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542 //printf("GAPI uses slow blit path %i, %i\n", dstXPitch, dstYPitch);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543 srcLine = src;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544 dstLine = dst;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545 y = height;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546 while (y--) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
547 srcPix = srcLine;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
548 dstPix = dstLine;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
549 x = width;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
550 while (x--) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
551 *((Uint16 *) dstPix) = *((Uint16 *) srcPix);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 dstPix += dstXPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553 srcPix += srcXPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 srcLine += srcYPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556 dstLine += dstYPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
560
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
561 static int
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 GAPI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 GAPI_RenderData *data = (GAPI_RenderData *) renderer->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566 int bpp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 int bytespp;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 int status;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 Uint32 Rmask, Gmask, Bmask, Amask;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571 if (texture->format != data->format) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 SDL_SetError("Gapi got wrong texture");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 return -1;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 GAPI_LOG("GAPI_RenderCopy\n");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 if (data->usageFlags & USAGE_GX_FUNCS) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 char *buffer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580 buffer = gx.GXBeginDraw();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 if (!(data->usageFlags & USAGE_DATA_PTR_CONSTANT)) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 data->data = buffer;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586 GAPI_LOG("GAPI_RenderCopy blit\n");
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587 /* If our framebuffer has an xPitch which matches the pixelsize, we
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 can convert the framebuffer to a SDL_surface and blit there,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589 otherwise, we have to use our own blitting routine
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591 SDL_PixelFormatEnumToMasks(data->format, &bpp, &Rmask, &Gmask, &Bmask,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592 &Amask);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593 bytespp = bpp >> 3;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594 if (data->xPitch == bytespp && 0) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
595 SDL_Surface *screen =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596 SDL_CreateRGBSurfaceFrom(data->data, data->w, data->h,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 bpp, data->yPitch, Rmask, Gmask, Bmask,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598 Amask);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599 status =
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600 SDL_UpperBlit((SDL_Surface *) texture->driverdata, srcrect,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601 screen, dstrect);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 SDL_FreeSurface(screen);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
603 } else { /* screen is rotated, we have to blit on our own */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
604 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 char *src, *dst;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607 src = surface->pixels;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 src += srcrect->y * surface->pitch + srcrect->x * 2;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
609
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
610 dst = data->data + data->offset;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611 dst += dstrect->y * data->yPitch + dstrect->x * data->xPitch;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
612
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
613 updateLine16to16(src, 2, surface->pitch,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614 dst, data->xPitch, data->yPitch,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
615 srcrect->w, srcrect->h);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
616
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
617 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
618
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
619 Uint32 ticks = SDL_GetTicks();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
620 if (data->usageFlags & USAGE_GX_FUNCS) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621 gx.GXEndDraw();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
622 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623 GAPI_LOG("GAPI_RenderCopy %i\n", SDL_GetTicks() - ticks);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
624 return status;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
625 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
626
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
627 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
628 GAPI_RenderPresent(SDL_Renderer * renderer)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
629 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
630 /* Nothing todo as we rendered directly to the screen on RenderCopy */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
631 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
632
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
633 static void
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
634 GAPI_DestroyRenderer(SDL_Renderer * renderer)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
635 {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
636 GAPI_RenderData *data = (GAPI_RenderData *) renderer->driverdata;
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
637
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
638 if (data->usageFlags & USAGE_GX_FUNCS) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
639 gx.GXCloseDisplay();
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
640 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
641
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
642 if (data) {
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
643 SDL_free(data);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
644 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
645 SDL_free(renderer);
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
646 }
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
647
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
648 #endif /* SDL_VIDEO_RENDER_GAPI */
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
649
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
650 /* vi: set ts=4 sw=4 expandtab: */