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

Latest commit

 

History

History
721 lines (643 loc) · 23.3 KB

SDL_gdirender.c

File metadata and controls

721 lines (643 loc) · 23.3 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
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"
Jul 8, 2006
Jul 8, 2006
24
25
#if SDL_VIDEO_RENDER_GDI
26
27
28
29
30
#include "SDL_win32video.h"
#include "../SDL_yuv_sw_c.h"
/* GDI renderer implementation */
Jul 8, 2006
Jul 8, 2006
31
static SDL_Renderer *SDL_GDI_CreateRenderer(SDL_Window * window,
Jul 8, 2006
Jul 8, 2006
33
static int SDL_GDI_CreateTexture(SDL_Renderer * renderer,
34
SDL_Texture * texture);
Jul 8, 2006
Jul 8, 2006
35
static int SDL_GDI_QueryTexturePixels(SDL_Renderer * renderer,
36
37
SDL_Texture * texture, void **pixels,
int *pitch);
Jul 8, 2006
Jul 8, 2006
38
static int SDL_GDI_SetTexturePalette(SDL_Renderer * renderer,
39
40
41
SDL_Texture * texture,
const SDL_Color * colors, int firstcolor,
int ncolors);
Jul 8, 2006
Jul 8, 2006
42
static int SDL_GDI_GetTexturePalette(SDL_Renderer * renderer,
43
44
45
SDL_Texture * texture,
SDL_Color * colors, int firstcolor,
int ncolors);
Jul 8, 2006
Jul 8, 2006
46
static int SDL_GDI_UpdateTexture(SDL_Renderer * renderer,
47
48
SDL_Texture * texture, const SDL_Rect * rect,
const void *pixels, int pitch);
Jul 8, 2006
Jul 8, 2006
49
static int SDL_GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
50
51
const SDL_Rect * rect, int markDirty,
void **pixels, int *pitch);
Jul 8, 2006
Jul 8, 2006
52
static void SDL_GDI_UnlockTexture(SDL_Renderer * renderer,
53
SDL_Texture * texture);
Jul 8, 2006
Jul 8, 2006
54
static void SDL_GDI_DirtyTexture(SDL_Renderer * renderer,
55
56
SDL_Texture * texture, int numrects,
const SDL_Rect * rects);
Jul 8, 2006
Jul 8, 2006
57
static void SDL_GDI_SelectRenderTexture(SDL_Renderer * renderer,
58
SDL_Texture * texture);
Jul 8, 2006
Jul 8, 2006
59
static int SDL_GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
Jul 8, 2006
Jul 8, 2006
61
static int SDL_GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
62
63
64
const SDL_Rect * srcrect,
const SDL_Rect * dstrect, int blendMode,
int scaleMode);
Jul 8, 2006
Jul 8, 2006
65
static int SDL_GDI_RenderReadPixels(SDL_Renderer * renderer,
66
67
const SDL_Rect * rect, void *pixels,
int pitch);
Jul 8, 2006
Jul 8, 2006
68
static int SDL_GDI_RenderWritePixels(SDL_Renderer * renderer,
69
70
const SDL_Rect * rect,
const void *pixels, int pitch);
Jul 8, 2006
Jul 8, 2006
71
72
static void SDL_GDI_RenderPresent(SDL_Renderer * renderer);
static void SDL_GDI_DestroyTexture(SDL_Renderer * renderer,
73
SDL_Texture * texture);
Jul 8, 2006
Jul 8, 2006
74
static void SDL_GDI_DestroyRenderer(SDL_Renderer * renderer);
Jul 8, 2006
Jul 8, 2006
77
78
SDL_RenderDriver SDL_GDI_RenderDriver = {
SDL_GDI_CreateRenderer,
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
"gdi",
(SDL_Renderer_PresentDiscard |
SDL_Renderer_PresentCopy | SDL_Renderer_RenderTarget),
(SDL_TextureBlendMode_None |
SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),
(SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
11,
{
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,
SDL_PixelFormat_YUY2,
SDL_PixelFormat_UYVY},
0,
0}
};
typedef struct
{
HWND hwnd;
HDC window_hdc;
HDC render_hdc;
HDC memory_hdc;
HDC current_hdc;
LPBITMAPINFO bmi;
HBITMAP window_bmp;
void *window_pixels;
int window_pitch;
Jul 8, 2006
Jul 8, 2006
114
} SDL_GDI_RenderData;
115
116
117
118
119
120
121
122
123
typedef struct
{
SDL_SW_YUVTexture *yuv;
Uint32 format;
HPALETTE hpal;
HBITMAP hbm;
void *pixels;
int pitch;
Jul 8, 2006
Jul 8, 2006
124
} SDL_GDI_TextureData;
125
126
127
128
static void
UpdateYUVTextureData(SDL_Texture * texture)
{
Jul 8, 2006
Jul 8, 2006
129
SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
130
131
132
133
134
135
136
137
138
139
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);
}
Jul 8, 2006
Jul 8, 2006
140
141
142
143
144
145
void
GDI_AddRenderDriver(_THIS)
{
SDL_AddRenderDriver(0, &SDL_GDI_RenderDriver);
}
Jul 8, 2006
Jul 8, 2006
147
SDL_GDI_CreateRenderer(SDL_Window * window, Uint32 flags)
148
149
150
{
SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
SDL_Renderer *renderer;
Jul 8, 2006
Jul 8, 2006
151
SDL_GDI_RenderData *data;
152
153
154
155
156
157
158
159
160
161
int bmi_size;
HBITMAP hbm;
renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer));
if (!renderer) {
SDL_OutOfMemory();
return NULL;
}
SDL_zerop(renderer);
Jul 8, 2006
Jul 8, 2006
162
data = (SDL_GDI_RenderData *) SDL_malloc(sizeof(*data));
Jul 8, 2006
Jul 8, 2006
164
SDL_GDI_DestroyRenderer(renderer);
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
SDL_OutOfMemory();
return NULL;
}
SDL_zerop(data);
data->hwnd = windowdata->hwnd;
data->window_hdc = GetDC(data->hwnd);
data->render_hdc = CreateCompatibleDC(data->window_hdc);
data->memory_hdc = CreateCompatibleDC(data->window_hdc);
data->current_hdc = data->window_hdc;
/* Fill in the compatible bitmap info */
bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
data->bmi = (LPBITMAPINFO) SDL_malloc(bmi_size);
if (!data->bmi) {
Jul 8, 2006
Jul 8, 2006
180
SDL_GDI_DestroyRenderer(renderer);
181
182
183
184
185
186
187
188
189
190
191
SDL_OutOfMemory();
return NULL;
}
SDL_memset(data->bmi, 0, bmi_size);
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);
Jul 8, 2006
Jul 8, 2006
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
renderer->CreateTexture = SDL_GDI_CreateTexture;
renderer->QueryTexturePixels = SDL_GDI_QueryTexturePixels;
renderer->SetTexturePalette = SDL_GDI_SetTexturePalette;
renderer->GetTexturePalette = SDL_GDI_GetTexturePalette;
renderer->UpdateTexture = SDL_GDI_UpdateTexture;
renderer->LockTexture = SDL_GDI_LockTexture;
renderer->UnlockTexture = SDL_GDI_UnlockTexture;
renderer->DirtyTexture = SDL_GDI_DirtyTexture;
renderer->SelectRenderTexture = SDL_GDI_SelectRenderTexture;
renderer->RenderFill = SDL_GDI_RenderFill;
renderer->RenderCopy = SDL_GDI_RenderCopy;
renderer->RenderReadPixels = SDL_GDI_RenderReadPixels;
renderer->RenderWritePixels = SDL_GDI_RenderWritePixels;
renderer->RenderPresent = SDL_GDI_RenderPresent;
renderer->DestroyTexture = SDL_GDI_DestroyTexture;
renderer->DestroyRenderer = SDL_GDI_DestroyRenderer;
renderer->info = SDL_GDI_RenderDriver.info;
209
210
211
212
213
214
215
216
217
renderer->window = window->id;
renderer->driverdata = data;
renderer->info.flags = SDL_Renderer_RenderTarget;
return renderer;
}
static int
Jul 8, 2006
Jul 8, 2006
218
SDL_GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Jul 8, 2006
Jul 8, 2006
220
221
SDL_GDI_RenderData *renderdata =
(SDL_GDI_RenderData *) renderer->driverdata;
222
223
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
Jul 8, 2006
Jul 8, 2006
224
SDL_GDI_TextureData *data;
Jul 8, 2006
Jul 8, 2006
226
data = (SDL_GDI_TextureData *) SDL_malloc(sizeof(*data));
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
if (!data) {
SDL_OutOfMemory();
return -1;
}
SDL_zerop(data);
texture->driverdata = data;
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
if (texture->access == SDL_TextureAccess_Render) {
SDL_SetError("Rendering to YUV format textures is not supported");
return -1;
}
data->yuv = SDL_SW_CreateYUVTexture(texture);
if (!data->yuv) {
Jul 8, 2006
Jul 8, 2006
242
SDL_GDI_DestroyTexture(renderer, texture);
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
return -1;
}
data->format = display->current_mode.format;
} else {
data->format = texture->format;
}
data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
if (data->yuv || texture->access == SDL_TextureAccess_Local
|| texture->format != SDL_GetCurrentDisplayMode()->format) {
int bmi_size;
LPBITMAPINFO bmi;
bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
bmi = (LPBITMAPINFO) SDL_malloc(bmi_size);
if (!bmi) {
Jul 8, 2006
Jul 8, 2006
259
SDL_GDI_DestroyTexture(renderer, texture);
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
SDL_OutOfMemory();
return -1;
}
SDL_memset(bmi, 0, bmi_size);
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);
Jul 8, 2006
Jul 8, 2006
285
SDL_GDI_DestroyTexture(renderer, texture);
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
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) {
Jul 8, 2006
Jul 8, 2006
321
SDL_GDI_DestroyTexture(renderer, texture);
322
323
324
325
326
327
328
WIN_SetError("Couldn't create bitmap");
return -1;
}
return 0;
}
static int
Jul 8, 2006
Jul 8, 2006
329
SDL_GDI_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
330
331
void **pixels, int *pitch)
{
Jul 8, 2006
Jul 8, 2006
332
SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
333
334
335
336
337
338
339
340
341
342
343
if (data->yuv) {
return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
} else {
*pixels = data->pixels;
*pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
return 0;
}
}
static int
Jul 8, 2006
Jul 8, 2006
344
SDL_GDI_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
345
346
347
const SDL_Color * colors, int firstcolor,
int ncolors)
{
Jul 8, 2006
Jul 8, 2006
348
349
350
SDL_GDI_RenderData *renderdata =
(SDL_GDI_RenderData *) renderer->driverdata;
SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
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 8, 2006
Jul 8, 2006
374
SDL_GDI_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
375
376
SDL_Color * colors, int firstcolor, int ncolors)
{
Jul 8, 2006
Jul 8, 2006
377
SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
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;
}
}
static int
Jul 8, 2006
Jul 8, 2006
400
SDL_GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
401
402
const SDL_Rect * rect, const void *pixels, int pitch)
{
Jul 8, 2006
Jul 8, 2006
403
SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
404
405
406
407
408
409
410
411
if (data->yuv) {
if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
return -1;
}
UpdateYUVTextureData(texture);
return 0;
} else {
Jul 8, 2006
Jul 8, 2006
412
413
SDL_GDI_RenderData *renderdata =
(SDL_GDI_RenderData *) renderer->driverdata;
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
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;
}
} else if (rect->w == texture->w && pitch == data->pitch) {
if (!SetDIBits
(renderdata->window_hdc, data->hbm, rect->y, rect->h, pixels,
renderdata->bmi, DIB_RGB_COLORS)) {
WIN_SetError("SetDIBits()");
return -1;
}
} 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 8, 2006
Jul 8, 2006
447
SDL_GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
448
449
450
const SDL_Rect * rect, int markDirty, void **pixels,
int *pitch)
{
Jul 8, 2006
Jul 8, 2006
451
SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
if (data->yuv) {
return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
pitch);
} else {
GdiFlush();
*pixels =
(void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
*pitch = data->pitch;
return 0;
}
}
static void
Jul 8, 2006
Jul 8, 2006
467
SDL_GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Jul 8, 2006
Jul 8, 2006
469
SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
470
471
472
473
474
475
476
477
if (data->yuv) {
SDL_SW_UnlockYUVTexture(data->yuv);
UpdateYUVTextureData(texture);
}
}
static void
Jul 8, 2006
Jul 8, 2006
478
SDL_GDI_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
479
480
481
482
483
int numrects, const SDL_Rect * rects)
{
}
static void
Jul 8, 2006
Jul 8, 2006
484
SDL_GDI_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Jul 8, 2006
Jul 8, 2006
486
SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
Jul 8, 2006
Jul 8, 2006
489
490
SDL_GDI_TextureData *texturedata =
(SDL_GDI_TextureData *) texture->driverdata;
491
492
493
494
495
496
497
498
499
500
501
502
SelectObject(data->render_hdc, texturedata->hbm);
if (texturedata->hpal) {
SelectPalette(data->render_hdc, texturedata->hpal, TRUE);
RealizePalette(data->render_hdc);
}
data->current_hdc = data->render_hdc;
} else {
data->current_hdc = data->current_hdc;
}
}
static int
Jul 8, 2006
Jul 8, 2006
503
SDL_GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
Jul 8, 2006
Jul 8, 2006
506
SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
Uint8 r, g, b;
RECT rc;
static HBRUSH brush;
int status;
r = (Uint8) ((color >> 16) & 0xFF);
g = (Uint8) ((color >> 8) & 0xFF);
b = (Uint8) (color & 0xFF);
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. :) */
brush = CreateSolidBrush(RGB(r, g, b));
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 8, 2006
Jul 8, 2006
535
SDL_GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
536
537
538
const SDL_Rect * srcrect, const SDL_Rect * dstrect,
int blendMode, int scaleMode)
{
Jul 8, 2006
Jul 8, 2006
539
540
541
SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
SDL_GDI_TextureData *texturedata =
(SDL_GDI_TextureData *) texture->driverdata;
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
SelectObject(data->memory_hdc, texturedata->hbm);
if (texturedata->hpal) {
SelectPalette(data->memory_hdc, texturedata->hpal, TRUE);
RealizePalette(data->memory_hdc);
}
if (blendMode & (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) {
static BLENDFUNCTION blendFunc = {
AC_SRC_OVER,
0,
255,
AC_SRC_ALPHA
};
/* FIXME: GDI uses premultiplied 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;
}
} 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,
Jul 7, 2006
Jul 7, 2006
575
dstrect->h, data->memory_hdc, srcrect->x, srcrect->y,
576
577
578
579
580
581
582
583
584
585
srcrect->w, srcrect->h, SRCCOPY)) {
WIN_SetError("StretchBlt()");
return -1;
}
}
}
return 0;
}
static int
Jul 8, 2006
Jul 8, 2006
586
CreateWindowDIB(SDL_GDI_RenderData * data, SDL_Window * window)
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
{
data->window_pitch = window->w * (data->bmi->bmiHeader.biBitCount / 8);
data->bmi->bmiHeader.biWidth = window->w;
data->bmi->bmiHeader.biHeight = -window->h;
data->bmi->bmiHeader.biSizeImage =
window->h * (data->bmi->bmiHeader.biBitCount / 8);
data->window_bmp =
CreateDIBSection(data->window_hdc, data->bmi, DIB_RGB_COLORS,
&data->window_pixels, NULL, 0);
if (!data->window_bmp) {
WIN_SetError("CreateDIBSection()");
return -1;
}
return 0;
}
static int
Jul 8, 2006
Jul 8, 2006
604
SDL_GDI_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
605
606
607
void *pixels, int pitch)
{
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
Jul 8, 2006
Jul 8, 2006
608
SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
if (!data->window_bmp) {
if (CreateWindowDIB(data, window) < 0) {
return -1;
}
}
SelectObject(data->memory_hdc, data->window_bmp);
BitBlt(data->memory_hdc, rect->x, rect->y, rect->w, rect->h,
data->window_hdc, rect->x, rect->y, SRCCOPY);
{
int bpp = data->bmi->bmiHeader.biBitCount / 8;
Uint8 *src =
(Uint8 *) data->window_pixels + rect->y * data->window_pitch +
rect->x * bpp;
Uint8 *dst = (Uint8 *) pixels;
int row;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, rect->w * bpp);
src += data->window_pitch;
dst += pitch;
}
}
return 0;
}
static int
Jul 8, 2006
Jul 8, 2006
639
SDL_GDI_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
640
641
642
const void *pixels, int pitch)
{
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
Jul 8, 2006
Jul 8, 2006
643
SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
if (!data->window_bmp) {
if (CreateWindowDIB(data, window) < 0) {
return -1;
}
}
{
int bpp = data->bmi->bmiHeader.biBitCount / 8;
Uint8 *src = (Uint8 *) pixels;
Uint8 *dst =
(Uint8 *) data->window_pixels + rect->y * data->window_pitch +
rect->x * bpp;
int row;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, rect->w * bpp);
src += pitch;
dst += data->window_pitch;
}
}
SelectObject(data->memory_hdc, data->window_bmp);
BitBlt(data->window_hdc, rect->x, rect->y, rect->w, rect->h,
data->memory_hdc, rect->x, rect->y, SRCCOPY);
return 0;
}
static void
Jul 8, 2006
Jul 8, 2006
674
SDL_GDI_RenderPresent(SDL_Renderer * renderer)
675
676
677
678
{
}
static void
Jul 8, 2006
Jul 8, 2006
679
SDL_GDI_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Jul 8, 2006
Jul 8, 2006
681
SDL_GDI_TextureData *data = (SDL_GDI_TextureData *) texture->driverdata;
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
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;
}
void
Jul 8, 2006
Jul 8, 2006
700
SDL_GDI_DestroyRenderer(SDL_Renderer * renderer)
Jul 8, 2006
Jul 8, 2006
702
SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
if (data) {
ReleaseDC(data->hwnd, data->window_hdc);
DeleteDC(data->render_hdc);
DeleteDC(data->memory_hdc);
if (data->bmi) {
SDL_free(data->bmi);
}
if (data->window_bmp) {
DeleteObject(data->window_bmp);
}
SDL_free(data);
}
SDL_free(renderer);
}
Jul 8, 2006
Jul 8, 2006
719
720
#endif /* SDL_VIDEO_RENDER_GDI */
721
/* vi: set ts=4 sw=4 expandtab: */