Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
895 lines (810 loc) · 27.9 KB

SDL_gdirender.c

File metadata and controls

895 lines (810 loc) · 27.9 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Dec 8, 2008
Dec 8, 2008
3
Copyright (C) 1997-2009 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#if SDL_VIDEO_RENDER_GDI
#include "SDL_win32video.h"
Jul 12, 2006
Jul 12, 2006
27
#include "../SDL_rect_c.h"
28
#include "../SDL_yuv_sw_c.h"
Feb 7, 2009
Feb 7, 2009
29
#include "../SDL_alphamult.h"
Mar 23, 2009
Mar 23, 2009
31
32
33
34
#ifdef _WIN32_WCE
#define NO_GETDIBBITS 1
#endif
35
36
/* GDI renderer implementation */
Jul 17, 2006
Jul 17, 2006
37
static SDL_Renderer *GDI_CreateRenderer(SDL_Window * window, Uint32 flags);
Aug 7, 2006
Aug 7, 2006
38
static int GDI_DisplayModeChanged(SDL_Renderer * renderer);
Jul 17, 2006
Jul 17, 2006
39
40
41
42
43
44
45
46
47
48
49
static int GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int GDI_QueryTexturePixels(SDL_Renderer * renderer,
SDL_Texture * texture, void **pixels,
int *pitch);
static int GDI_SetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture,
const SDL_Color * colors, int firstcolor,
int ncolors);
static int GDI_GetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture, SDL_Color * colors,
int firstcolor, int ncolors);
Aug 28, 2006
Aug 28, 2006
50
51
52
53
54
55
static int GDI_SetTextureAlphaMod(SDL_Renderer * renderer,
SDL_Texture * texture);
static int GDI_SetTextureBlendMode(SDL_Renderer * renderer,
SDL_Texture * texture);
static int GDI_SetTextureScaleMode(SDL_Renderer * renderer,
SDL_Texture * texture);
Jul 17, 2006
Jul 17, 2006
56
57
58
59
60
61
62
static int GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
static int GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty,
void **pixels, int *pitch);
static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
Dec 30, 2008
Dec 30, 2008
63
static int GDI_SetDrawBlendMode(SDL_Renderer * renderer);
Dec 30, 2008
Dec 30, 2008
64
65
66
static int GDI_RenderPoint(SDL_Renderer * renderer, int x, int y);
static int GDI_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
int y2);
Dec 25, 2008
Dec 25, 2008
67
static int GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
Jul 17, 2006
Jul 17, 2006
68
static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
Aug 28, 2006
Aug 28, 2006
69
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
Jul 17, 2006
Jul 17, 2006
70
71
72
73
74
75
76
77
static void GDI_RenderPresent(SDL_Renderer * renderer);
static void GDI_DestroyTexture(SDL_Renderer * renderer,
SDL_Texture * texture);
static void GDI_DestroyRenderer(SDL_Renderer * renderer);
SDL_RenderDriver GDI_RenderDriver = {
GDI_CreateRenderer,
Aug 5, 2006
Aug 5, 2006
80
(SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
Aug 7, 2006
Aug 7, 2006
81
SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
Aug 5, 2006
Aug 5, 2006
82
SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
Aug 28, 2006
Aug 28, 2006
83
(SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_ALPHA),
Dec 30, 2008
Dec 30, 2008
84
(SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK),
Aug 5, 2006
Aug 5, 2006
85
(SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
Nov 30, 2008
Nov 30, 2008
86
14,
Aug 5, 2006
Aug 5, 2006
88
89
90
91
92
93
94
95
96
SDL_PIXELFORMAT_INDEX8,
SDL_PIXELFORMAT_RGB555,
SDL_PIXELFORMAT_RGB565,
SDL_PIXELFORMAT_RGB888,
SDL_PIXELFORMAT_BGR888,
SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_RGBA8888,
SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_BGRA8888,
Nov 30, 2008
Nov 30, 2008
97
98
SDL_PIXELFORMAT_YV12,
SDL_PIXELFORMAT_IYUV,
Aug 5, 2006
Aug 5, 2006
99
SDL_PIXELFORMAT_YUY2,
Nov 30, 2008
Nov 30, 2008
100
101
SDL_PIXELFORMAT_UYVY,
SDL_PIXELFORMAT_YVYU},
102
103
104
105
106
107
108
109
110
111
112
0,
0}
};
typedef struct
{
HWND hwnd;
HDC window_hdc;
HDC render_hdc;
HDC memory_hdc;
HDC current_hdc;
Mar 23, 2009
Mar 23, 2009
113
#ifndef NO_GETDIBBITS
114
LPBITMAPINFO bmi;
Mar 23, 2009
Mar 23, 2009
115
#endif
Jul 12, 2006
Jul 12, 2006
116
117
118
119
HBITMAP hbm[3];
int current_hbm;
SDL_DirtyRectList dirty;
SDL_bool makedirty;
Jul 17, 2006
Jul 17, 2006
120
} GDI_RenderData;
121
122
123
124
125
126
127
128
129
typedef struct
{
SDL_SW_YUVTexture *yuv;
Uint32 format;
HPALETTE hpal;
HBITMAP hbm;
void *pixels;
int pitch;
Feb 7, 2009
Feb 7, 2009
130
SDL_bool premultiplied;
Jul 17, 2006
Jul 17, 2006
131
} GDI_TextureData;
132
133
134
135
static void
UpdateYUVTextureData(SDL_Texture * texture)
{
Jul 17, 2006
Jul 17, 2006
136
GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
137
138
139
140
141
142
143
144
145
146
147
148
149
SDL_Rect rect;
rect.x = 0;
rect.y = 0;
rect.w = texture->w;
rect.h = texture->h;
SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w,
texture->h, data->pixels, data->pitch);
}
void
GDI_AddRenderDriver(_THIS)
{
Jul 17, 2006
Jul 17, 2006
150
SDL_AddRenderDriver(0, &GDI_RenderDriver);
151
152
153
}
SDL_Renderer *
Jul 17, 2006
Jul 17, 2006
154
GDI_CreateRenderer(SDL_Window * window, Uint32 flags)
155
156
157
{
SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
SDL_Renderer *renderer;
Jul 17, 2006
Jul 17, 2006
158
GDI_RenderData *data;
159
160
int bmi_size;
HBITMAP hbm;
Jul 12, 2006
Jul 12, 2006
161
int i, n;
Jul 22, 2006
Jul 22, 2006
163
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
164
165
166
167
168
if (!renderer) {
SDL_OutOfMemory();
return NULL;
}
Jul 22, 2006
Jul 22, 2006
169
data = (GDI_RenderData *) SDL_calloc(1, sizeof(*data));
Jul 17, 2006
Jul 17, 2006
171
GDI_DestroyRenderer(renderer);
172
173
174
175
SDL_OutOfMemory();
return NULL;
}
Aug 7, 2006
Aug 7, 2006
176
renderer->DisplayModeChanged = GDI_DisplayModeChanged;
Jul 17, 2006
Jul 17, 2006
177
178
179
180
renderer->CreateTexture = GDI_CreateTexture;
renderer->QueryTexturePixels = GDI_QueryTexturePixels;
renderer->SetTexturePalette = GDI_SetTexturePalette;
renderer->GetTexturePalette = GDI_GetTexturePalette;
Aug 28, 2006
Aug 28, 2006
181
182
183
renderer->SetTextureAlphaMod = GDI_SetTextureAlphaMod;
renderer->SetTextureBlendMode = GDI_SetTextureBlendMode;
renderer->SetTextureScaleMode = GDI_SetTextureScaleMode;
Jul 17, 2006
Jul 17, 2006
184
185
186
renderer->UpdateTexture = GDI_UpdateTexture;
renderer->LockTexture = GDI_LockTexture;
renderer->UnlockTexture = GDI_UnlockTexture;
Dec 30, 2008
Dec 30, 2008
187
renderer->SetDrawBlendMode = GDI_SetDrawBlendMode;
Dec 30, 2008
Dec 30, 2008
188
189
renderer->RenderPoint = GDI_RenderPoint;
renderer->RenderLine = GDI_RenderLine;
Jul 17, 2006
Jul 17, 2006
190
191
192
193
194
195
renderer->RenderFill = GDI_RenderFill;
renderer->RenderCopy = GDI_RenderCopy;
renderer->RenderPresent = GDI_RenderPresent;
renderer->DestroyTexture = GDI_DestroyTexture;
renderer->DestroyRenderer = GDI_DestroyRenderer;
renderer->info = GDI_RenderDriver.info;
196
197
198
renderer->window = window->id;
renderer->driverdata = data;
Aug 5, 2006
Aug 5, 2006
199
renderer->info.flags = SDL_RENDERER_ACCELERATED;
Jul 12, 2006
Jul 12, 2006
201
data->hwnd = windowdata->hwnd;
Jul 17, 2006
Jul 17, 2006
202
data->window_hdc = windowdata->hdc;
Jul 12, 2006
Jul 12, 2006
203
204
205
data->render_hdc = CreateCompatibleDC(data->window_hdc);
data->memory_hdc = CreateCompatibleDC(data->window_hdc);
Mar 23, 2009
Mar 23, 2009
206
#ifndef NO_GETDIBBITS
Jul 12, 2006
Jul 12, 2006
207
208
/* Fill in the compatible bitmap info */
bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
Jul 22, 2006
Jul 22, 2006
209
data->bmi = (LPBITMAPINFO) SDL_calloc(1, bmi_size);
Jul 12, 2006
Jul 12, 2006
210
if (!data->bmi) {
Jul 17, 2006
Jul 17, 2006
211
GDI_DestroyRenderer(renderer);
Jul 12, 2006
Jul 12, 2006
212
213
214
215
216
217
218
219
220
SDL_OutOfMemory();
return NULL;
}
data->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
hbm = CreateCompatibleBitmap(data->window_hdc, 1, 1);
GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
DeleteObject(hbm);
Mar 23, 2009
Mar 23, 2009
221
#endif
Jul 12, 2006
Jul 12, 2006
222
Aug 5, 2006
Aug 5, 2006
223
if (flags & SDL_RENDERER_SINGLEBUFFER) {
Jul 15, 2006
Jul 15, 2006
224
renderer->info.flags |=
Aug 7, 2006
Aug 7, 2006
225
(SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY);
Jul 12, 2006
Jul 12, 2006
226
n = 0;
Aug 5, 2006
Aug 5, 2006
227
228
} else if (flags & SDL_RENDERER_PRESENTFLIP2) {
renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
Jul 12, 2006
Jul 12, 2006
229
n = 2;
Aug 5, 2006
Aug 5, 2006
230
231
} else if (flags & SDL_RENDERER_PRESENTFLIP3) {
renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
Jul 12, 2006
Jul 12, 2006
232
233
n = 3;
} else {
Aug 5, 2006
Aug 5, 2006
234
renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
Jul 12, 2006
Jul 12, 2006
235
236
237
238
239
240
n = 1;
}
for (i = 0; i < n; ++i) {
data->hbm[i] =
CreateCompatibleBitmap(data->window_hdc, window->w, window->h);
if (!data->hbm[i]) {
Jul 17, 2006
Jul 17, 2006
241
GDI_DestroyRenderer(renderer);
Jul 12, 2006
Jul 12, 2006
242
243
244
245
246
247
248
249
250
251
252
253
254
255
WIN_SetError("CreateCompatibleBitmap()");
return NULL;
}
}
if (n > 0) {
SelectObject(data->render_hdc, data->hbm[0]);
data->current_hdc = data->render_hdc;
data->makedirty = SDL_TRUE;
} else {
data->current_hdc = data->window_hdc;
data->makedirty = SDL_FALSE;
}
data->current_hbm = 0;
256
257
258
return renderer;
}
Aug 7, 2006
Aug 7, 2006
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
static int
GDI_DisplayModeChanged(SDL_Renderer * renderer)
{
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
int i, n;
if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) {
n = 0;
} else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
n = 2;
} else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
n = 3;
} else {
n = 1;
}
for (i = 0; i < n; ++i) {
if (data->hbm[i]) {
DeleteObject(data->hbm[i]);
data->hbm[i] = NULL;
}
}
for (i = 0; i < n; ++i) {
data->hbm[i] =
CreateCompatibleBitmap(data->window_hdc, window->w, window->h);
if (!data->hbm[i]) {
WIN_SetError("CreateCompatibleBitmap()");
return -1;
}
}
if (n > 0) {
SelectObject(data->render_hdc, data->hbm[0]);
}
Nov 30, 2008
Nov 30, 2008
292
293
data->current_hbm = 0;
Aug 7, 2006
Aug 7, 2006
294
295
296
return 0;
}
Jul 17, 2006
Jul 17, 2006
298
GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Jul 17, 2006
Jul 17, 2006
300
GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
301
302
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
Jul 17, 2006
Jul 17, 2006
303
GDI_TextureData *data;
Jul 22, 2006
Jul 22, 2006
305
data = (GDI_TextureData *) SDL_calloc(1, sizeof(*data));
306
307
308
309
310
311
312
313
if (!data) {
SDL_OutOfMemory();
return -1;
}
texture->driverdata = data;
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
Nov 25, 2008
Nov 25, 2008
314
315
data->yuv =
SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
316
317
318
319
320
321
322
323
324
if (!data->yuv) {
return -1;
}
data->format = display->current_mode.format;
} else {
data->format = texture->format;
}
data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
Aug 11, 2007
Aug 11, 2007
325
if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING
Aug 7, 2006
Aug 7, 2006
326
|| texture->format != display->current_mode.format) {
327
328
329
330
int bmi_size;
LPBITMAPINFO bmi;
bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
Jul 22, 2006
Jul 22, 2006
331
bmi = (LPBITMAPINFO) SDL_calloc(1, bmi_size);
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
if (!bmi) {
SDL_OutOfMemory();
return -1;
}
bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi->bmiHeader.biWidth = texture->w;
bmi->bmiHeader.biHeight = -texture->h; /* topdown bitmap */
bmi->bmiHeader.biPlanes = 1;
bmi->bmiHeader.biSizeImage = texture->h * data->pitch;
bmi->bmiHeader.biXPelsPerMeter = 0;
bmi->bmiHeader.biYPelsPerMeter = 0;
bmi->bmiHeader.biClrUsed = 0;
bmi->bmiHeader.biClrImportant = 0;
bmi->bmiHeader.biBitCount = SDL_BYTESPERPIXEL(data->format) * 8;
if (SDL_ISPIXELFORMAT_INDEXED(data->format)) {
int i, ncolors;
LOGPALETTE *palette;
bmi->bmiHeader.biCompression = BI_RGB;
ncolors = (1 << SDL_BITSPERPIXEL(data->format));
palette =
(LOGPALETTE *) SDL_malloc(sizeof(*palette) +
ncolors * sizeof(PALETTEENTRY));
if (!palette) {
SDL_free(bmi);
SDL_OutOfMemory();
return -1;
}
palette->palVersion = 0x300;
palette->palNumEntries = ncolors;
for (i = 0; i < ncolors; ++i) {
palette->palPalEntry[i].peRed = 0xFF;
palette->palPalEntry[i].peGreen = 0xFF;
palette->palPalEntry[i].peBlue = 0xFF;
palette->palPalEntry[i].peFlags = 0;
}
data->hpal = CreatePalette(palette);
SDL_free(palette);
} else {
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
bmi->bmiHeader.biCompression = BI_BITFIELDS;
SDL_PixelFormatEnumToMasks(data->format, &bpp, &Rmask, &Gmask,
&Bmask, &Amask);
((Uint32 *) bmi->bmiColors)[0] = Rmask;
((Uint32 *) bmi->bmiColors)[1] = Gmask;
((Uint32 *) bmi->bmiColors)[2] = Bmask;
data->hpal = NULL;
}
data->hbm =
CreateDIBSection(renderdata->memory_hdc, bmi, DIB_RGB_COLORS,
&data->pixels, NULL, 0);
} else {
data->hbm =
CreateCompatibleBitmap(renderdata->window_hdc, texture->w,
texture->h);
data->pixels = NULL;
}
if (!data->hbm) {
WIN_SetError("Couldn't create bitmap");
return -1;
}
return 0;
}
static int
Jul 17, 2006
Jul 17, 2006
399
400
GDI_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
void **pixels, int *pitch)
Jul 17, 2006
Jul 17, 2006
402
GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
403
404
405
406
407
if (data->yuv) {
return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
} else {
*pixels = data->pixels;
Jul 12, 2006
Jul 12, 2006
408
*pitch = data->pitch;
409
410
411
412
413
return 0;
}
}
static int
Jul 17, 2006
Jul 17, 2006
414
415
GDI_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Color * colors, int firstcolor, int ncolors)
Jul 17, 2006
Jul 17, 2006
417
418
GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
if (data->yuv) {
SDL_SetError("YUV textures don't have a palette");
return -1;
} else {
PALETTEENTRY entries[256];
int i;
for (i = 0; i < ncolors; ++i) {
entries[i].peRed = colors[i].r;
entries[i].peGreen = colors[i].g;
entries[i].peBlue = colors[i].b;
entries[i].peFlags = 0;
}
if (!SetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) {
WIN_SetError("SetPaletteEntries()");
return -1;
}
return 0;
}
}
static int
Jul 17, 2006
Jul 17, 2006
442
443
GDI_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
SDL_Color * colors, int firstcolor, int ncolors)
Jul 17, 2006
Jul 17, 2006
445
GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
if (data->yuv) {
SDL_SetError("YUV textures don't have a palette");
return -1;
} else {
PALETTEENTRY entries[256];
int i;
if (!GetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) {
WIN_SetError("GetPaletteEntries()");
return -1;
}
for (i = 0; i < ncolors; ++i) {
colors[i].r = entries[i].peRed;
colors[i].g = entries[i].peGreen;
colors[i].b = entries[i].peBlue;
}
return 0;
}
}
Aug 28, 2006
Aug 28, 2006
467
468
469
470
471
472
473
474
475
static int
GDI_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
{
return 0;
}
static int
GDI_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
Feb 7, 2009
Feb 7, 2009
476
477
GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
Aug 28, 2006
Aug 28, 2006
478
switch (texture->blendMode) {
Dec 20, 2008
Dec 20, 2008
479
case SDL_BLENDMODE_NONE:
Feb 7, 2009
Feb 7, 2009
480
481
482
483
if (data->premultiplied) {
/* Crap, we've lost the original pixel data... *sigh* */
}
return 0;
Mar 23, 2009
Mar 23, 2009
484
#ifndef _WIN32_WCE /* WinCE has no alphablend */
Dec 20, 2008
Dec 20, 2008
485
486
case SDL_BLENDMODE_MASK:
case SDL_BLENDMODE_BLEND:
Feb 7, 2009
Feb 7, 2009
487
488
489
if (!data->premultiplied && data->pixels) {
switch (texture->format) {
case SDL_PIXELFORMAT_ARGB8888:
Feb 7, 2009
Feb 7, 2009
490
491
492
SDL_PreMultiplyAlphaARGB8888(texture->w, texture->h,
(Uint32 *) data->pixels,
data->pitch);
Feb 7, 2009
Feb 7, 2009
493
494
495
data->premultiplied = SDL_TRUE;
break;
case SDL_PIXELFORMAT_RGBA8888:
Feb 7, 2009
Feb 7, 2009
496
497
498
SDL_PreMultiplyAlphaRGBA8888(texture->w, texture->h,
(Uint32 *) data->pixels,
data->pitch);
Feb 7, 2009
Feb 7, 2009
499
500
501
data->premultiplied = SDL_TRUE;
break;
case SDL_PIXELFORMAT_ABGR8888:
Feb 7, 2009
Feb 7, 2009
502
503
504
SDL_PreMultiplyAlphaABGR8888(texture->w, texture->h,
(Uint32 *) data->pixels,
data->pitch);
Feb 7, 2009
Feb 7, 2009
505
506
507
data->premultiplied = SDL_TRUE;
break;
case SDL_PIXELFORMAT_BGRA8888:
Feb 7, 2009
Feb 7, 2009
508
509
510
SDL_PreMultiplyAlphaBGRA8888(texture->w, texture->h,
(Uint32 *) data->pixels,
data->pitch);
Feb 7, 2009
Feb 7, 2009
511
512
513
514
data->premultiplied = SDL_TRUE;
break;
}
}
Aug 28, 2006
Aug 28, 2006
515
return 0;
Mar 23, 2009
Mar 23, 2009
516
#endif
Aug 28, 2006
Aug 28, 2006
517
518
default:
SDL_Unsupported();
Dec 20, 2008
Dec 20, 2008
519
texture->blendMode = SDL_BLENDMODE_NONE;
Aug 28, 2006
Aug 28, 2006
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
return -1;
}
}
static int
GDI_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
switch (texture->scaleMode) {
case SDL_TEXTURESCALEMODE_NONE:
case SDL_TEXTURESCALEMODE_FAST:
return 0;
case SDL_TEXTURESCALEMODE_SLOW:
case SDL_TEXTURESCALEMODE_BEST:
SDL_Unsupported();
texture->scaleMode = SDL_TEXTURESCALEMODE_FAST;
return -1;
default:
SDL_Unsupported();
texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
return -1;
}
return 0;
}
Jul 17, 2006
Jul 17, 2006
545
546
GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
Jul 17, 2006
Jul 17, 2006
548
GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
549
550
551
552
553
554
555
556
if (data->yuv) {
if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
return -1;
}
UpdateYUVTextureData(texture);
return 0;
} else {
Jul 17, 2006
Jul 17, 2006
557
GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
if (data->pixels) {
Uint8 *src, *dst;
int row;
size_t length;
src = (Uint8 *) pixels;
dst =
(Uint8 *) data->pixels + rect->y * data->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format);
length = rect->w * SDL_BYTESPERPIXEL(texture->format);
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
dst += data->pitch;
}
Feb 7, 2009
Feb 7, 2009
574
if (data->premultiplied) {
Feb 7, 2009
Feb 7, 2009
575
576
577
Uint32 *pixels =
(Uint32 *) data->pixels + rect->y * (data->pitch / 4) +
rect->x;
Feb 7, 2009
Feb 7, 2009
578
579
switch (texture->format) {
case SDL_PIXELFORMAT_ARGB8888:
Feb 7, 2009
Feb 7, 2009
580
581
SDL_PreMultiplyAlphaARGB8888(rect->w, rect->h, pixels,
data->pitch);
Feb 7, 2009
Feb 7, 2009
582
583
break;
case SDL_PIXELFORMAT_RGBA8888:
Feb 7, 2009
Feb 7, 2009
584
585
SDL_PreMultiplyAlphaRGBA8888(rect->w, rect->h, pixels,
data->pitch);
Feb 7, 2009
Feb 7, 2009
586
587
break;
case SDL_PIXELFORMAT_ABGR8888:
Feb 7, 2009
Feb 7, 2009
588
589
SDL_PreMultiplyAlphaABGR8888(rect->w, rect->h, pixels,
data->pitch);
Feb 7, 2009
Feb 7, 2009
590
591
break;
case SDL_PIXELFORMAT_BGRA8888:
Feb 7, 2009
Feb 7, 2009
592
593
SDL_PreMultiplyAlphaBGRA8888(rect->w, rect->h, pixels,
data->pitch);
Feb 7, 2009
Feb 7, 2009
594
595
596
break;
}
}
597
} else if (rect->w == texture->w && pitch == data->pitch) {
Mar 23, 2009
Mar 23, 2009
598
#ifndef NO_GETDIBBITS
599
600
601
602
603
604
if (!SetDIBits
(renderdata->window_hdc, data->hbm, rect->y, rect->h, pixels,
renderdata->bmi, DIB_RGB_COLORS)) {
WIN_SetError("SetDIBits()");
return -1;
}
Mar 23, 2009
Mar 23, 2009
605
606
607
608
#else
SDL_SetError("FIXME: Update Texture");
return -1;
#endif
609
610
611
612
613
614
615
616
617
618
} else {
SDL_SetError
("FIXME: Need to allocate temporary memory and do GetDIBits() followed by SetDIBits(), since we can only set blocks of scanlines at a time");
return -1;
}
return 0;
}
}
static int
Jul 17, 2006
Jul 17, 2006
619
620
621
GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty, void **pixels,
int *pitch)
Jul 17, 2006
Jul 17, 2006
623
GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
624
625
626
627
if (data->yuv) {
return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
pitch);
Jul 12, 2006
Jul 12, 2006
628
} else if (data->pixels) {
Mar 23, 2009
Mar 23, 2009
629
630
#ifndef _WIN32_WCE
/* WinCE has no GdiFlush */
Mar 23, 2009
Mar 23, 2009
632
#endif
633
634
635
636
637
*pixels =
(void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
*pitch = data->pitch;
return 0;
Jul 12, 2006
Jul 12, 2006
638
639
640
} else {
SDL_SetError("No pixels available");
return -1;
641
642
643
644
}
}
static void
Jul 17, 2006
Jul 17, 2006
645
GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Jul 17, 2006
Jul 17, 2006
647
GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
648
649
650
651
652
653
654
if (data->yuv) {
SDL_SW_UnlockYUVTexture(data->yuv);
UpdateYUVTextureData(texture);
}
}
Dec 30, 2008
Dec 30, 2008
655
656
657
658
659
660
661
662
663
664
665
666
667
static int
GDI_SetDrawBlendMode(SDL_Renderer * renderer)
{
switch (renderer->blendMode) {
case SDL_BLENDMODE_NONE:
return 0;
default:
SDL_Unsupported();
renderer->blendMode = SDL_BLENDMODE_NONE;
return -1;
}
}
Dec 30, 2008
Dec 30, 2008
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
static int
GDI_RenderPoint(SDL_Renderer * renderer, int x, int y)
{
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
if (data->makedirty) {
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.w = 1;
rect.h = 1;
SDL_AddDirtyRect(&data->dirty, &rect);
}
Dec 30, 2008
Dec 30, 2008
684
685
SetPixel(data->current_hdc, x, y,
RGB(renderer->r, renderer->g, renderer->b));
Dec 30, 2008
Dec 30, 2008
686
687
688
689
690
691
692
693
return 0;
}
static int
GDI_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
{
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
POINT points[2];
Feb 8, 2009
Feb 8, 2009
694
HPEN pen;
Dec 30, 2008
Dec 30, 2008
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
BOOL status;
if (data->makedirty) {
SDL_Rect rect;
if (x1 < x2) {
rect.x = x1;
rect.w = (x2 - x1) + 1;
} else {
rect.x = x2;
rect.w = (x1 - x2) + 1;
}
if (y1 < y2) {
rect.y = y1;
rect.h = (y2 - y1) + 1;
} else {
rect.y = y2;
rect.h = (y1 - y2) + 1;
}
SDL_AddDirtyRect(&data->dirty, &rect);
}
Feb 8, 2009
Feb 8, 2009
717
718
719
/* Should we cache the pen? .. it looks like GDI does for us. :) */
pen = CreatePen(PS_SOLID, 1, RGB(renderer->r, renderer->g, renderer->b));
SelectObject(data->current_hdc, pen);
Dec 30, 2008
Dec 30, 2008
720
721
722
723
724
points[0].x = x1;
points[0].y = y1;
points[1].x = x2;
points[1].y = y2;
status = Polyline(data->current_hdc, points, 2);
Feb 8, 2009
Feb 8, 2009
725
DeleteObject(pen);
Dec 30, 2008
Dec 30, 2008
726
727
728
729
730
731
732
733
if (!status) {
WIN_SetError("FillRect()");
return -1;
}
return 0;
}
Dec 25, 2008
Dec 25, 2008
735
GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
Jul 17, 2006
Jul 17, 2006
737
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
Jul 12, 2006
Jul 12, 2006
739
HBRUSH brush;
740
741
int status;
Jul 12, 2006
Jul 12, 2006
742
743
744
745
if (data->makedirty) {
SDL_AddDirtyRect(&data->dirty, rect);
}
746
747
748
749
750
751
rc.left = rect->x;
rc.top = rect->y;
rc.right = rect->x + rect->w + 1;
rc.bottom = rect->y + rect->h + 1;
/* Should we cache the brushes? .. it looks like GDI does for us. :) */
Dec 25, 2008
Dec 25, 2008
752
brush = CreateSolidBrush(RGB(renderer->r, renderer->g, renderer->b));
753
754
755
756
757
758
759
760
761
762
763
764
SelectObject(data->current_hdc, brush);
status = FillRect(data->current_hdc, &rc, brush);
DeleteObject(brush);
if (!status) {
WIN_SetError("FillRect()");
return -1;
}
return 0;
}
static int
Jul 17, 2006
Jul 17, 2006
765
GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
Aug 28, 2006
Aug 28, 2006
766
const SDL_Rect * srcrect, const SDL_Rect * dstrect)
Jul 17, 2006
Jul 17, 2006
768
769
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
GDI_TextureData *texturedata = (GDI_TextureData *) texture->driverdata;
Jul 12, 2006
Jul 12, 2006
771
772
773
774
if (data->makedirty) {
SDL_AddDirtyRect(&data->dirty, dstrect);
}
775
776
777
778
779
SelectObject(data->memory_hdc, texturedata->hbm);
if (texturedata->hpal) {
SelectPalette(data->memory_hdc, texturedata->hpal, TRUE);
RealizePalette(data->memory_hdc);
}
Feb 7, 2009
Feb 7, 2009
780
if (texture->blendMode & (SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND)) {
Mar 23, 2009
Mar 23, 2009
781
782
783
784
#ifdef _WIN32_WCE
SDL_SetError("Texture has blendmode not supported under WinCE");
return -1;
#else
Aug 28, 2006
Aug 28, 2006
785
BLENDFUNCTION blendFunc = {
786
787
AC_SRC_OVER,
0,
Aug 28, 2006
Aug 28, 2006
788
texture->a,
789
790
791
792
793
794
795
796
797
AC_SRC_ALPHA
};
if (!AlphaBlend
(data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w,
srcrect->h, blendFunc)) {
WIN_SetError("AlphaBlend()");
return -1;
}
Mar 23, 2009
Mar 23, 2009
798
#endif
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
} else {
if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
if (!BitBlt
(data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
srcrect->h, data->memory_hdc, srcrect->x, srcrect->y,
SRCCOPY)) {
WIN_SetError("BitBlt()");
return -1;
}
} else {
if (!StretchBlt
(data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
dstrect->h, data->memory_hdc, srcrect->x, srcrect->y,
srcrect->w, srcrect->h, SRCCOPY)) {
WIN_SetError("StretchBlt()");
return -1;
}
}
}
return 0;
}
static void
Jul 17, 2006
Jul 17, 2006
822
GDI_RenderPresent(SDL_Renderer * renderer)
Jul 17, 2006
Jul 17, 2006
824
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
Jul 12, 2006
Jul 12, 2006
825
826
827
SDL_DirtyRect *dirty;
/* Send the data to the display */
Aug 5, 2006
Aug 5, 2006
828
if (!(renderer->info.flags & SDL_RENDERER_SINGLEBUFFER)) {
Jul 12, 2006
Jul 12, 2006
829
830
831
832
833
834
835
836
837
for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
const SDL_Rect *rect = &dirty->rect;
BitBlt(data->window_hdc, rect->x, rect->y, rect->w, rect->h,
data->render_hdc, rect->x, rect->y, SRCCOPY);
}
SDL_ClearDirtyRects(&data->dirty);
}
/* Update the flipping chain, if any */
Aug 5, 2006
Aug 5, 2006
838
if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
Jul 12, 2006
Jul 12, 2006
839
840
data->current_hbm = (data->current_hbm + 1) % 2;
SelectObject(data->render_hdc, data->hbm[data->current_hbm]);
Aug 5, 2006
Aug 5, 2006
841
} else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
Jul 12, 2006
Jul 12, 2006
842
843
844
data->current_hbm = (data->current_hbm + 1) % 3;
SelectObject(data->render_hdc, data->hbm[data->current_hbm]);
}
845
846
847
}
static void
Jul 17, 2006
Jul 17, 2006
848
GDI_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Jul 17, 2006
Jul 17, 2006
850
GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
if (!data) {
return;
}
if (data->yuv) {
SDL_SW_DestroyYUVTexture(data->yuv);
}
if (data->hpal) {
DeleteObject(data->hpal);
}
if (data->hbm) {
DeleteObject(data->hbm);
}
SDL_free(data);
texture->driverdata = NULL;
}
Aug 7, 2006
Aug 7, 2006
868
static void
Jul 17, 2006
Jul 17, 2006
869
GDI_DestroyRenderer(SDL_Renderer * renderer)
Jul 17, 2006
Jul 17, 2006
871
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
Jul 12, 2006
Jul 12, 2006
872
int i;
873
874
875
876
if (data) {
DeleteDC(data->render_hdc);
DeleteDC(data->memory_hdc);
Mar 23, 2009
Mar 23, 2009
877
#ifndef NO_GETDIBBITS
878
879
880
if (data->bmi) {
SDL_free(data->bmi);
}
Mar 23, 2009
Mar 23, 2009
881
#endif
Jul 12, 2006
Jul 12, 2006
882
883
884
885
886
887
for (i = 0; i < SDL_arraysize(data->hbm); ++i) {
if (data->hbm[i]) {
DeleteObject(data->hbm[i]);
}
}
SDL_FreeDirtyRects(&data->dirty);
888
889
890
891
892
893
894
895
SDL_free(data);
}
SDL_free(renderer);
}
#endif /* SDL_VIDEO_RENDER_GDI */
/* vi: set ts=4 sw=4 expandtab: */