comparison src/video/win32/SDL_gdirender.c @ 1975:ccef0d0c40c6

Added resize support for GDI and Direct3D renderers
author Sam Lantinga <slouken@libsdl.org>
date Mon, 07 Aug 2006 05:24:13 +0000
parents a788656ca29a
children 8055185ae4ed
comparison
equal deleted inserted replaced
1974:70deaf574153 1975:ccef0d0c40c6
28 #include "../SDL_yuv_sw_c.h" 28 #include "../SDL_yuv_sw_c.h"
29 29
30 /* GDI renderer implementation */ 30 /* GDI renderer implementation */
31 31
32 static SDL_Renderer *GDI_CreateRenderer(SDL_Window * window, Uint32 flags); 32 static SDL_Renderer *GDI_CreateRenderer(SDL_Window * window, Uint32 flags);
33 static int GDI_DisplayModeChanged(SDL_Renderer * renderer);
33 static int GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); 34 static int GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
34 static int GDI_QueryTexturePixels(SDL_Renderer * renderer, 35 static int GDI_QueryTexturePixels(SDL_Renderer * renderer,
35 SDL_Texture * texture, void **pixels, 36 SDL_Texture * texture, void **pixels,
36 int *pitch); 37 int *pitch);
37 static int GDI_SetTexturePalette(SDL_Renderer * renderer, 38 static int GDI_SetTexturePalette(SDL_Renderer * renderer,
64 SDL_RenderDriver GDI_RenderDriver = { 65 SDL_RenderDriver GDI_RenderDriver = {
65 GDI_CreateRenderer, 66 GDI_CreateRenderer,
66 { 67 {
67 "gdi", 68 "gdi",
68 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY | 69 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
69 SDL_RENDERER_PRESENTFLIP2 | sDL_RENDERER_PRESENTFLIP3 | 70 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
70 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED), 71 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
71 (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK | 72 (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
72 SDL_TEXTUREBLENDMODE_BLEND), 73 SDL_TEXTUREBLENDMODE_BLEND),
73 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST), 74 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
74 11, 75 11,
153 GDI_DestroyRenderer(renderer); 154 GDI_DestroyRenderer(renderer);
154 SDL_OutOfMemory(); 155 SDL_OutOfMemory();
155 return NULL; 156 return NULL;
156 } 157 }
157 158
159 renderer->DisplayModeChanged = GDI_DisplayModeChanged;
158 renderer->CreateTexture = GDI_CreateTexture; 160 renderer->CreateTexture = GDI_CreateTexture;
159 renderer->QueryTexturePixels = GDI_QueryTexturePixels; 161 renderer->QueryTexturePixels = GDI_QueryTexturePixels;
160 renderer->SetTexturePalette = GDI_SetTexturePalette; 162 renderer->SetTexturePalette = GDI_SetTexturePalette;
161 renderer->GetTexturePalette = GDI_GetTexturePalette; 163 renderer->GetTexturePalette = GDI_GetTexturePalette;
162 renderer->UpdateTexture = GDI_UpdateTexture; 164 renderer->UpdateTexture = GDI_UpdateTexture;
194 GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS); 196 GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
195 DeleteObject(hbm); 197 DeleteObject(hbm);
196 198
197 if (flags & SDL_RENDERER_SINGLEBUFFER) { 199 if (flags & SDL_RENDERER_SINGLEBUFFER) {
198 renderer->info.flags |= 200 renderer->info.flags |=
199 (SDL_RENDERER_SINGLEBUFFER | sDL_RENDERER_PRESENTCOPY); 201 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY);
200 n = 0; 202 n = 0;
201 } else if (flags & SDL_RENDERER_PRESENTFLIP2) { 203 } else if (flags & SDL_RENDERER_PRESENTFLIP2) {
202 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2; 204 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
203 n = 2; 205 n = 2;
204 } else if (flags & SDL_RENDERER_PRESENTFLIP3) { 206 } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
229 231
230 return renderer; 232 return renderer;
231 } 233 }
232 234
233 static int 235 static int
236 GDI_DisplayModeChanged(SDL_Renderer * renderer)
237 {
238 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
239 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
240 int i, n;
241
242 if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) {
243 n = 0;
244 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
245 n = 2;
246 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
247 n = 3;
248 } else {
249 n = 1;
250 }
251 for (i = 0; i < n; ++i) {
252 if (data->hbm[i]) {
253 DeleteObject(data->hbm[i]);
254 data->hbm[i] = NULL;
255 }
256 }
257 for (i = 0; i < n; ++i) {
258 data->hbm[i] =
259 CreateCompatibleBitmap(data->window_hdc, window->w, window->h);
260 if (!data->hbm[i]) {
261 WIN_SetError("CreateCompatibleBitmap()");
262 return -1;
263 }
264 }
265 if (n > 0) {
266 SelectObject(data->render_hdc, data->hbm[0]);
267 }
268 return 0;
269 }
270
271 static int
234 GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) 272 GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
235 { 273 {
236 GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata; 274 GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
237 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 275 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
238 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 276 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
256 data->format = texture->format; 294 data->format = texture->format;
257 } 295 }
258 data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format)); 296 data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
259 297
260 if (data->yuv || texture->access == SDL_TEXTUREACCESS_LOCAL 298 if (data->yuv || texture->access == SDL_TEXTUREACCESS_LOCAL
261 || texture->format != SDL_GetCurrentDisplayMode()->format) { 299 || texture->format != display->current_mode.format) {
262 int bmi_size; 300 int bmi_size;
263 LPBITMAPINFO bmi; 301 LPBITMAPINFO bmi;
264 302
265 bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD); 303 bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
266 bmi = (LPBITMAPINFO) SDL_calloc(1, bmi_size); 304 bmi = (LPBITMAPINFO) SDL_calloc(1, bmi_size);
619 } 657 }
620 SDL_free(data); 658 SDL_free(data);
621 texture->driverdata = NULL; 659 texture->driverdata = NULL;
622 } 660 }
623 661
624 void 662 static void
625 GDI_DestroyRenderer(SDL_Renderer * renderer) 663 GDI_DestroyRenderer(SDL_Renderer * renderer)
626 { 664 {
627 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata; 665 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
628 int i; 666 int i;
629 667