annotate src/video/win32/SDL_gdirender.c @ 3556:9c2e92de786a

Added a BLENDMODE_MASK pixel shader so render tests succeed
author Sam Lantinga <slouken@libsdl.org>
date Mon, 14 Dec 2009 04:19:00 +0000
parents 0267b8b1595c
children 0f958e527e5e
rev   line source
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #if SDL_VIDEO_RENDER_GDI
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #include "SDL_win32video.h"
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
27 #include "../SDL_rect_c.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include "../SDL_yuv_sw_c.h"
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
29 #include "../SDL_alphamult.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
31 #ifdef _WIN32_WCE
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
32 #define NO_GETDIBBITS 1
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
33 #endif
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
34
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 /* GDI renderer implementation */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
37 static SDL_Renderer *GDI_CreateRenderer(SDL_Window * window, Uint32 flags);
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
38 static int GDI_DisplayModeChanged(SDL_Renderer * renderer);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
39 static int GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
40 static int GDI_QueryTexturePixels(SDL_Renderer * renderer,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
41 SDL_Texture * texture, void **pixels,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
42 int *pitch);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
43 static int GDI_SetTexturePalette(SDL_Renderer * renderer,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
44 SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
45 const SDL_Color * colors, int firstcolor,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
46 int ncolors);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
47 static int GDI_GetTexturePalette(SDL_Renderer * renderer,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
48 SDL_Texture * texture, SDL_Color * colors,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
49 int firstcolor, int ncolors);
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
50 static int GDI_SetTextureAlphaMod(SDL_Renderer * renderer,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
51 SDL_Texture * texture);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
52 static int GDI_SetTextureBlendMode(SDL_Renderer * renderer,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
53 SDL_Texture * texture);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
54 static int GDI_SetTextureScaleMode(SDL_Renderer * renderer,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
55 SDL_Texture * texture);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
56 static int GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
57 const SDL_Rect * rect, const void *pixels,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
58 int pitch);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
59 static int GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
60 const SDL_Rect * rect, int markDirty,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
61 void **pixels, int *pitch);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
62 static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
2927
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
63 static int GDI_SetDrawBlendMode(SDL_Renderer * renderer);
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
64 static int GDI_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points,
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
65 int count);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
66 static int GDI_RenderLines(SDL_Renderer * renderer, const SDL_Point * points,
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
67 int count);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
68 static int GDI_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
69 int count);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
70 static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
71 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
3534
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
72 static int GDI_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
73 Uint32 format, void * pixels, int pitch);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
74 static int GDI_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
75 Uint32 format, const void * pixels, int pitch);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
76 static void GDI_RenderPresent(SDL_Renderer * renderer);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
77 static void GDI_DestroyTexture(SDL_Renderer * renderer,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
78 SDL_Texture * texture);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
79 static void GDI_DestroyRenderer(SDL_Renderer * renderer);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
82 SDL_RenderDriver GDI_RenderDriver = {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
83 GDI_CreateRenderer,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 "gdi",
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
86 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
87 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
88 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
89 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_ALPHA),
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
90 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK),
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
91 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
2811
7af2419ad5b0 Fixed the list of supported YUV formats
Sam Lantinga <slouken@libsdl.org>
parents: 2810
diff changeset
92 14,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
94 SDL_PIXELFORMAT_INDEX8,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
95 SDL_PIXELFORMAT_RGB555,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
96 SDL_PIXELFORMAT_RGB565,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
97 SDL_PIXELFORMAT_RGB888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
98 SDL_PIXELFORMAT_BGR888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
99 SDL_PIXELFORMAT_ARGB8888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
100 SDL_PIXELFORMAT_RGBA8888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
101 SDL_PIXELFORMAT_ABGR8888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
102 SDL_PIXELFORMAT_BGRA8888,
2811
7af2419ad5b0 Fixed the list of supported YUV formats
Sam Lantinga <slouken@libsdl.org>
parents: 2810
diff changeset
103 SDL_PIXELFORMAT_YV12,
7af2419ad5b0 Fixed the list of supported YUV formats
Sam Lantinga <slouken@libsdl.org>
parents: 2810
diff changeset
104 SDL_PIXELFORMAT_IYUV,
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
105 SDL_PIXELFORMAT_YUY2,
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents: 2786
diff changeset
106 SDL_PIXELFORMAT_UYVY,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents: 2786
diff changeset
107 SDL_PIXELFORMAT_YVYU},
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 0,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 0}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 };
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 typedef struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 HWND hwnd;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 HDC window_hdc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 HDC render_hdc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 HDC memory_hdc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 HDC current_hdc;
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
119 #ifndef NO_GETDIBBITS
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 LPBITMAPINFO bmi;
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
121 #endif
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
122 HBITMAP hbm[3];
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
123 int current_hbm;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
124 SDL_DirtyRectList dirty;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
125 SDL_bool makedirty;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
126 } GDI_RenderData;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 typedef struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 SDL_SW_YUVTexture *yuv;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 Uint32 format;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 HPALETTE hpal;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 HBITMAP hbm;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 void *pixels;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 int pitch;
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
136 SDL_bool premultiplied;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
137 } GDI_TextureData;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 UpdateYUVTextureData(SDL_Texture * texture)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
142 GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 SDL_Rect rect;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 rect.x = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 rect.y = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 rect.w = texture->w;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 rect.h = texture->h;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 texture->h, data->pixels, data->pitch);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 GDI_AddRenderDriver(_THIS)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 {
3520
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
156 int i;
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
157 for (i = 0; i < _this->num_displays; ++i) {
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
158 SDL_AddRenderDriver(&_this->displays[i], &GDI_RenderDriver);
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
159 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 SDL_Renderer *
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
163 GDI_CreateRenderer(SDL_Window * window, Uint32 flags)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 SDL_Renderer *renderer;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
167 GDI_RenderData *data;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 int bmi_size;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 HBITMAP hbm;
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
170 int i, n;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171
1920
8a162bfdc838 Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents: 1918
diff changeset
172 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 if (!renderer) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 return NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177
1920
8a162bfdc838 Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents: 1918
diff changeset
178 data = (GDI_RenderData *) SDL_calloc(1, sizeof(*data));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 if (!data) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
180 GDI_DestroyRenderer(renderer);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 return NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
185 renderer->DisplayModeChanged = GDI_DisplayModeChanged;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
186 renderer->CreateTexture = GDI_CreateTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
187 renderer->QueryTexturePixels = GDI_QueryTexturePixels;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
188 renderer->SetTexturePalette = GDI_SetTexturePalette;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
189 renderer->GetTexturePalette = GDI_GetTexturePalette;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
190 renderer->SetTextureAlphaMod = GDI_SetTextureAlphaMod;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
191 renderer->SetTextureBlendMode = GDI_SetTextureBlendMode;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
192 renderer->SetTextureScaleMode = GDI_SetTextureScaleMode;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
193 renderer->UpdateTexture = GDI_UpdateTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
194 renderer->LockTexture = GDI_LockTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
195 renderer->UnlockTexture = GDI_UnlockTexture;
2927
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
196 renderer->SetDrawBlendMode = GDI_SetDrawBlendMode;
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
197 renderer->RenderPoints = GDI_RenderPoints;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
198 renderer->RenderLines = GDI_RenderLines;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
199 renderer->RenderRects = GDI_RenderRects;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
200 renderer->RenderCopy = GDI_RenderCopy;
3534
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
201 renderer->RenderReadPixels = GDI_RenderReadPixels;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
202 renderer->RenderWritePixels = GDI_RenderWritePixels;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
203 renderer->RenderPresent = GDI_RenderPresent;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
204 renderer->DestroyTexture = GDI_DestroyTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
205 renderer->DestroyRenderer = GDI_DestroyRenderer;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
206 renderer->info = GDI_RenderDriver.info;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 renderer->window = window->id;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 renderer->driverdata = data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
210 renderer->info.flags = SDL_RENDERER_ACCELERATED;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
212 data->hwnd = windowdata->hwnd;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
213 data->window_hdc = windowdata->hdc;
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
214 data->render_hdc = CreateCompatibleDC(data->window_hdc);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
215 data->memory_hdc = CreateCompatibleDC(data->window_hdc);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
216
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
217 #ifndef NO_GETDIBBITS
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
218 /* Fill in the compatible bitmap info */
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
219 bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
1920
8a162bfdc838 Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents: 1918
diff changeset
220 data->bmi = (LPBITMAPINFO) SDL_calloc(1, bmi_size);
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
221 if (!data->bmi) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
222 GDI_DestroyRenderer(renderer);
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
223 SDL_OutOfMemory();
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
224 return NULL;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
225 }
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
226 data->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
227
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
228 hbm = CreateCompatibleBitmap(data->window_hdc, 1, 1);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
229 GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
230 GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
231 DeleteObject(hbm);
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
232 #endif
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
233
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
234 if (flags & SDL_RENDERER_SINGLEBUFFER) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
235 renderer->info.flags |=
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
236 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY);
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
237 n = 0;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
238 } else if (flags & SDL_RENDERER_PRESENTFLIP2) {
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
239 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
240 n = 2;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
241 } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
242 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
243 n = 3;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
244 } else {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
245 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
246 n = 1;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
247 }
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
248 for (i = 0; i < n; ++i) {
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
249 data->hbm[i] =
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
250 CreateCompatibleBitmap(data->window_hdc, window->w, window->h);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
251 if (!data->hbm[i]) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
252 GDI_DestroyRenderer(renderer);
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
253 WIN_SetError("CreateCompatibleBitmap()");
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
254 return NULL;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
255 }
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
256 }
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
257 if (n > 0) {
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
258 SelectObject(data->render_hdc, data->hbm[0]);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
259 data->current_hdc = data->render_hdc;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
260 data->makedirty = SDL_TRUE;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
261 } else {
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
262 data->current_hdc = data->window_hdc;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
263 data->makedirty = SDL_FALSE;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
264 }
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
265 data->current_hbm = 0;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
266
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 return renderer;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 static int
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
271 GDI_DisplayModeChanged(SDL_Renderer * renderer)
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
272 {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
273 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
274 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
275 int i, n;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
276
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
277 if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
278 n = 0;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
279 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
280 n = 2;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
281 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
282 n = 3;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
283 } else {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
284 n = 1;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
285 }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
286 for (i = 0; i < n; ++i) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
287 if (data->hbm[i]) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
288 DeleteObject(data->hbm[i]);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
289 data->hbm[i] = NULL;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
290 }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
291 }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
292 for (i = 0; i < n; ++i) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
293 data->hbm[i] =
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
294 CreateCompatibleBitmap(data->window_hdc, window->w, window->h);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
295 if (!data->hbm[i]) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
296 WIN_SetError("CreateCompatibleBitmap()");
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
297 return -1;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
298 }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
299 }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
300 if (n > 0) {
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
301 SelectObject(data->render_hdc, data->hbm[0]);
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
302 }
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents: 2786
diff changeset
303 data->current_hbm = 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents: 2786
diff changeset
304
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
305 return 0;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
306 }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
307
3534
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
308 static HBITMAP
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
309 GDI_CreateDIBSection(HDC hdc, int w, int h, int pitch, Uint32 format,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
310 HPALETTE * hpal, void ** pixels)
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
311 {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
312 int bmi_size;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
313 LPBITMAPINFO bmi;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
314
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
315 bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
316 bmi = (LPBITMAPINFO) SDL_calloc(1, bmi_size);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
317 if (!bmi) {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
318 SDL_OutOfMemory();
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
319 return NULL;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
320 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
321 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
322 bmi->bmiHeader.biWidth = w;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
323 bmi->bmiHeader.biHeight = -h; /* topdown bitmap */
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
324 bmi->bmiHeader.biPlanes = 1;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
325 bmi->bmiHeader.biSizeImage = h * pitch;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
326 bmi->bmiHeader.biXPelsPerMeter = 0;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
327 bmi->bmiHeader.biYPelsPerMeter = 0;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
328 bmi->bmiHeader.biClrUsed = 0;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
329 bmi->bmiHeader.biClrImportant = 0;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
330 bmi->bmiHeader.biBitCount = SDL_BYTESPERPIXEL(format) * 8;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
331 if (SDL_ISPIXELFORMAT_INDEXED(format)) {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
332 bmi->bmiHeader.biCompression = BI_RGB;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
333 if (hpal) {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
334 int i, ncolors;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
335 LOGPALETTE *palette;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
336
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
337 ncolors = (1 << SDL_BITSPERPIXEL(format));
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
338 palette =
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
339 (LOGPALETTE *) SDL_malloc(sizeof(*palette) +
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
340 ncolors * sizeof(PALETTEENTRY));
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
341 if (!palette) {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
342 SDL_free(bmi);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
343 SDL_OutOfMemory();
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
344 return NULL;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
345 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
346 palette->palVersion = 0x300;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
347 palette->palNumEntries = ncolors;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
348 for (i = 0; i < ncolors; ++i) {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
349 palette->palPalEntry[i].peRed = 0xFF;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
350 palette->palPalEntry[i].peGreen = 0xFF;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
351 palette->palPalEntry[i].peBlue = 0xFF;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
352 palette->palPalEntry[i].peFlags = 0;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
353 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
354 *hpal = CreatePalette(palette);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
355 SDL_free(palette);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
356 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
357 } else {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
358 int bpp;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
359 Uint32 Rmask, Gmask, Bmask, Amask;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
360
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
361 bmi->bmiHeader.biCompression = BI_BITFIELDS;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
362 SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
363 &Amask);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
364 ((Uint32 *) bmi->bmiColors)[0] = Rmask;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
365 ((Uint32 *) bmi->bmiColors)[1] = Gmask;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
366 ((Uint32 *) bmi->bmiColors)[2] = Bmask;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
367 if (hpal) {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
368 *hpal = NULL;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
369 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
370 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
371 return CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, pixels, NULL, 0);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
372 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
373
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
374 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
375 GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
377 GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
380 GDI_TextureData *data;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381
1920
8a162bfdc838 Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents: 1918
diff changeset
382 data = (GDI_TextureData *) SDL_calloc(1, sizeof(*data));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 if (!data) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 texture->driverdata = data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2781
diff changeset
391 data->yuv =
Sam Lantinga <slouken@libsdl.org>
parents: 2781
diff changeset
392 SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 if (!data->yuv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 data->format = display->current_mode.format;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 data->format = texture->format;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401
2222
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
402 if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
403 || texture->format != display->current_mode.format) {
3534
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
404 data->hbm = GDI_CreateDIBSection(renderdata->memory_hdc,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
405 texture->w, texture->h,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
406 data->pitch, data->format,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
407 &data->hpal, &data->pixels);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 } else {
3534
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
409 data->hbm = CreateCompatibleBitmap(renderdata->window_hdc,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
410 texture->w, texture->h);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 if (!data->hbm) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 WIN_SetError("Couldn't create bitmap");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
420 GDI_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
421 void **pixels, int *pitch)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
423 GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 if (data->yuv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428 *pixels = data->pixels;
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
429 *pitch = data->pitch;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
435 GDI_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
436 const SDL_Color * colors, int firstcolor, int ncolors)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
438 GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
439 GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441 if (data->yuv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 SDL_SetError("YUV textures don't have a palette");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 PALETTEENTRY entries[256];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 int i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 for (i = 0; i < ncolors; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 entries[i].peRed = colors[i].r;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 entries[i].peGreen = colors[i].g;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451 entries[i].peBlue = colors[i].b;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 entries[i].peFlags = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454 if (!SetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455 WIN_SetError("SetPaletteEntries()");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
462 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
463 GDI_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
464 SDL_Color * colors, int firstcolor, int ncolors)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
465 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
466 GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468 if (data->yuv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 SDL_SetError("YUV textures don't have a palette");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 PALETTEENTRY entries[256];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 int i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 if (!GetPaletteEntries(data->hpal, firstcolor, ncolors, entries)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476 WIN_SetError("GetPaletteEntries()");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 for (i = 0; i < ncolors; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480 colors[i].r = entries[i].peRed;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 colors[i].g = entries[i].peGreen;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 colors[i].b = entries[i].peBlue;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488 static int
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
489 GDI_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
490 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
491 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
492 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
493
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
494 static int
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
495 GDI_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
496 {
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
497 GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
498
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
499 switch (texture->blendMode) {
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
500 case SDL_BLENDMODE_NONE:
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
501 if (data->premultiplied) {
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
502 /* Crap, we've lost the original pixel data... *sigh* */
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
503 }
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
504 return 0;
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3097
diff changeset
505 #ifndef _WIN32_WCE /* WinCE has no alphablend */
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
506 case SDL_BLENDMODE_MASK:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
507 case SDL_BLENDMODE_BLEND:
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
508 if (!data->premultiplied && data->pixels) {
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
509 switch (texture->format) {
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
510 case SDL_PIXELFORMAT_ARGB8888:
3055
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
511 SDL_PreMultiplyAlphaARGB8888(texture->w, texture->h,
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
512 (Uint32 *) data->pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
513 data->pitch);
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
514 data->premultiplied = SDL_TRUE;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
515 break;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
516 case SDL_PIXELFORMAT_RGBA8888:
3055
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
517 SDL_PreMultiplyAlphaRGBA8888(texture->w, texture->h,
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
518 (Uint32 *) data->pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
519 data->pitch);
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
520 data->premultiplied = SDL_TRUE;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
521 break;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
522 case SDL_PIXELFORMAT_ABGR8888:
3055
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
523 SDL_PreMultiplyAlphaABGR8888(texture->w, texture->h,
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
524 (Uint32 *) data->pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
525 data->pitch);
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
526 data->premultiplied = SDL_TRUE;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
527 break;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
528 case SDL_PIXELFORMAT_BGRA8888:
3055
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
529 SDL_PreMultiplyAlphaBGRA8888(texture->w, texture->h,
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
530 (Uint32 *) data->pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
531 data->pitch);
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
532 data->premultiplied = SDL_TRUE;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
533 break;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
534 }
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
535 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
536 return 0;
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
537 #endif
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
538 default:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
539 SDL_Unsupported();
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
540 texture->blendMode = SDL_BLENDMODE_NONE;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
541 return -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
542 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
543 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
544
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
545 static int
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
546 GDI_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
547 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
548 switch (texture->scaleMode) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
549 case SDL_TEXTURESCALEMODE_NONE:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
550 case SDL_TEXTURESCALEMODE_FAST:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
551 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
552 case SDL_TEXTURESCALEMODE_SLOW:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
553 case SDL_TEXTURESCALEMODE_BEST:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
554 SDL_Unsupported();
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
555 texture->scaleMode = SDL_TEXTURESCALEMODE_FAST;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
556 return -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
557 default:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
558 SDL_Unsupported();
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
559 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
560 return -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
561 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
562 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
563 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
564
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
565 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
566 GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
567 const SDL_Rect * rect, const void *pixels, int pitch)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
569 GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571 if (data->yuv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 UpdateYUVTextureData(texture);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577 } else {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
578 GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580 if (data->pixels) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 Uint8 *src, *dst;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 int row;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583 size_t length;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 src = (Uint8 *) pixels;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586 dst =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587 (Uint8 *) data->pixels + rect->y * data->pitch +
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 rect->x * SDL_BYTESPERPIXEL(texture->format);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589 length = rect->w * SDL_BYTESPERPIXEL(texture->format);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 for (row = 0; row < rect->h; ++row) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591 SDL_memcpy(dst, src, length);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592 src += pitch;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593 dst += data->pitch;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594 }
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
595 if (data->premultiplied) {
3055
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
596 Uint32 *pixels =
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
597 (Uint32 *) data->pixels + rect->y * (data->pitch / 4) +
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
598 rect->x;
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
599 switch (texture->format) {
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
600 case SDL_PIXELFORMAT_ARGB8888:
3055
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
601 SDL_PreMultiplyAlphaARGB8888(rect->w, rect->h, pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
602 data->pitch);
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
603 break;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
604 case SDL_PIXELFORMAT_RGBA8888:
3055
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
605 SDL_PreMultiplyAlphaRGBA8888(rect->w, rect->h, pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
606 data->pitch);
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
607 break;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
608 case SDL_PIXELFORMAT_ABGR8888:
3055
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
609 SDL_PreMultiplyAlphaABGR8888(rect->w, rect->h, pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
610 data->pitch);
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
611 break;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
612 case SDL_PIXELFORMAT_BGRA8888:
3055
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
613 SDL_PreMultiplyAlphaBGRA8888(rect->w, rect->h, pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
614 data->pitch);
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
615 break;
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
616 }
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2929
diff changeset
617 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
618 } else if (rect->w == texture->w && pitch == data->pitch) {
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
619 #ifndef NO_GETDIBBITS
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
620 if (!SetDIBits
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621 (renderdata->window_hdc, data->hbm, rect->y, rect->h, pixels,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
622 renderdata->bmi, DIB_RGB_COLORS)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623 WIN_SetError("SetDIBits()");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
624 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
625 }
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
626 #else
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
627 SDL_SetError("FIXME: Update Texture");
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
628 return -1;
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
629 #endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
630 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
631 SDL_SetError
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
632 ("FIXME: Need to allocate temporary memory and do GetDIBits() followed by SetDIBits(), since we can only set blocks of scanlines at a time");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
633 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
634 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
635 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
636 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
637 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
638
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
639 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
640 GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
641 const SDL_Rect * rect, int markDirty, void **pixels,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
642 int *pitch)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
643 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
644 GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
645
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
646 if (data->yuv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
647 return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
648 pitch);
1898
f89e49e51e89 Playing around, trying to find a fast path with GDI
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
649 } else if (data->pixels) {
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
650 #ifndef _WIN32_WCE
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3097
diff changeset
651 /* WinCE has no GdiFlush */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
652 GdiFlush();
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
653 #endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
654 *pixels =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
655 (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
656 rect->x * SDL_BYTESPERPIXEL(texture->format));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
657 *pitch = data->pitch;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
658 return 0;
1898
f89e49e51e89 Playing around, trying to find a fast path with GDI
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
659 } else {
f89e49e51e89 Playing around, trying to find a fast path with GDI
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
660 SDL_SetError("No pixels available");
f89e49e51e89 Playing around, trying to find a fast path with GDI
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
661 return -1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
662 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
663 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
664
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
665 static void
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
666 GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
667 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
668 GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
669
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
670 if (data->yuv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
671 SDL_SW_UnlockYUVTexture(data->yuv);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
672 UpdateYUVTextureData(texture);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
673 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
674 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
675
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
676 static int
2927
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
677 GDI_SetDrawBlendMode(SDL_Renderer * renderer)
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
678 {
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
679 switch (renderer->blendMode) {
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
680 case SDL_BLENDMODE_NONE:
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
681 return 0;
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
682 default:
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
683 SDL_Unsupported();
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
684 renderer->blendMode = SDL_BLENDMODE_NONE;
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
685 return -1;
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
686 }
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
687 }
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
688
2133d2d300fd SetDrawColor() and SetDrawBlendMode() are optional
Sam Lantinga <slouken@libsdl.org>
parents: 2926
diff changeset
689 static int
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
690 GDI_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
691 {
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
692 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
693 int i;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
694 COLORREF color;
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
695
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
696 if (data->makedirty) {
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
697 /* Get the smallest rectangle that contains everything */
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
698 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
699 SDL_Rect rect;
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
700
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
701 rect.x = 0;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
702 rect.y = 0;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
703 rect.w = window->w;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
704 rect.h = window->h;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
705 if (!SDL_EnclosePoints(points, count, &rect, &rect)) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
706 /* Nothing to draw */
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
707 return 0;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
708 }
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
709
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
710 SDL_AddDirtyRect(&data->dirty, &rect);
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
711 }
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
712
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
713 color = RGB(renderer->r, renderer->g, renderer->b);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
714 for (i = 0; i < count; ++i) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
715 SetPixel(data->current_hdc, points[i].x, points[i].y, color);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
716 }
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
717
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
718 return 0;
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
719 }
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
720
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
721 static int
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
722 GDI_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
723 {
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
724 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
3056
a434fe6360df Oh, Polyline() uses a pen, not a brush. Doh! :)
Sam Lantinga <slouken@libsdl.org>
parents: 3055
diff changeset
725 HPEN pen;
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
726 BOOL status;
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
727
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
728 if (data->makedirty) {
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
729 /* Get the smallest rectangle that contains everything */
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
730 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
731 SDL_Rect clip, rect;
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
732
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
733 clip.x = 0;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
734 clip.y = 0;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
735 clip.w = window->w;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
736 clip.h = window->h;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
737 SDL_EnclosePoints(points, count, NULL, &rect);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
738 if (!SDL_IntersectRect(&rect, &clip, &rect)) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
739 /* Nothing to draw */
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
740 return 0;
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
741 }
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
742
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
743 SDL_AddDirtyRect(&data->dirty, &rect);
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
744 }
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
745
3056
a434fe6360df Oh, Polyline() uses a pen, not a brush. Doh! :)
Sam Lantinga <slouken@libsdl.org>
parents: 3055
diff changeset
746 /* Should we cache the pen? .. it looks like GDI does for us. :) */
a434fe6360df Oh, Polyline() uses a pen, not a brush. Doh! :)
Sam Lantinga <slouken@libsdl.org>
parents: 3055
diff changeset
747 pen = CreatePen(PS_SOLID, 1, RGB(renderer->r, renderer->g, renderer->b));
a434fe6360df Oh, Polyline() uses a pen, not a brush. Doh! :)
Sam Lantinga <slouken@libsdl.org>
parents: 3055
diff changeset
748 SelectObject(data->current_hdc, pen);
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
749 {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
750 LPPOINT p = SDL_stack_alloc(POINT, count);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
751 int i;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
752
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
753 for (i = 0; i < count; ++i) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
754 p[i].x = points[i].x;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
755 p[i].y = points[i].y;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
756 }
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
757 status = Polyline(data->current_hdc, p, count);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
758 SDL_stack_free(p);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
759 }
3056
a434fe6360df Oh, Polyline() uses a pen, not a brush. Doh! :)
Sam Lantinga <slouken@libsdl.org>
parents: 3055
diff changeset
760 DeleteObject(pen);
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
761
3535
b403f790df65 Hey, those automated tests are coming in handy! Fixed GDI rendering semantics
Sam Lantinga <slouken@libsdl.org>
parents: 3534
diff changeset
762 /* Need to close the endpoint of the line */
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
763 if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
764 SetPixel(data->current_hdc, points[count-1].x, points[count-1].y,
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
765 RGB(renderer->r, renderer->g, renderer->b));
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
766 }
3535
b403f790df65 Hey, those automated tests are coming in handy! Fixed GDI rendering semantics
Sam Lantinga <slouken@libsdl.org>
parents: 3534
diff changeset
767
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
768 if (!status) {
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
769 WIN_SetError("Polyline()");
2926
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
770 return -1;
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
771 }
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
772 return 0;
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
773 }
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
774
27f2b5e7e899 In theory this implements GDI rendering, but it doesn't work for some reason.
Sam Lantinga <slouken@libsdl.org>
parents: 2919
diff changeset
775 static int
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
776 GDI_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
777 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
778 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
779 RECT rc;
1899
6a11e61bf805 debug cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
780 HBRUSH brush;
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
781 int i, status = 1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
782
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
783 if (data->makedirty) {
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
784 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
785 SDL_Rect clip, rect;
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
786
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
787 clip.x = 0;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
788 clip.y = 0;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
789 clip.w = window->w;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
790 clip.h = window->h;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
791
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
792 for (i = 0; i < count; ++i) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
793 if (SDL_IntersectRect(rects[i], &clip, &rect)) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
794 SDL_AddDirtyRect(&data->dirty, &rect);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
795 }
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
796 }
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
797 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
798
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
799 /* Should we cache the brushes? .. it looks like GDI does for us. :) */
2919
2f91a3847ae8 Fixed compiling Windows renderers. Lines and points will be implemented later.
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
800 brush = CreateSolidBrush(RGB(renderer->r, renderer->g, renderer->b));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
801 SelectObject(data->current_hdc, brush);
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
802 for (i = 0; i < count; ++i) {
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
803 const SDL_Rect *rect = rects[i];
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
804
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
805 rc.left = rect->x;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
806 rc.top = rect->y;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
807 rc.right = rect->x + rect->w;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
808 rc.bottom = rect->y + rect->h;
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
809
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
810 status &= FillRect(data->current_hdc, &rc, brush);
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3535
diff changeset
811 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
812 DeleteObject(brush);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
813
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
814 if (!status) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
815 WIN_SetError("FillRect()");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
816 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
817 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
818 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
819 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
820
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
821 static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
822 GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
823 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
824 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
825 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
826 GDI_TextureData *texturedata = (GDI_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
827
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
828 if (data->makedirty) {
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
829 SDL_AddDirtyRect(&data->dirty, dstrect);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
830 }
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
831
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
832 SelectObject(data->memory_hdc, texturedata->hbm);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
833 if (texturedata->hpal) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
834 SelectPalette(data->memory_hdc, texturedata->hpal, TRUE);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
835 RealizePalette(data->memory_hdc);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
836 }
3055
Sam Lantinga <slouken@libsdl.org>
parents: 3054
diff changeset
837 if (texture->blendMode & (SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND)) {
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
838 #ifdef _WIN32_WCE
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
839 SDL_SetError("Texture has blendmode not supported under WinCE");
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
840 return -1;
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
841 #else
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
842 BLENDFUNCTION blendFunc = {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
843 AC_SRC_OVER,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
844 0,
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1975
diff changeset
845 texture->a,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
846 AC_SRC_ALPHA
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
847 };
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
848 if (!AlphaBlend
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
849 (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
850 dstrect->h, data->memory_hdc, srcrect->x, srcrect->y, srcrect->w,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
851 srcrect->h, blendFunc)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
852 WIN_SetError("AlphaBlend()");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
853 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
854 }
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
855 #endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
856 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
857 if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
858 if (!BitBlt
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
859 (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
860 srcrect->h, data->memory_hdc, srcrect->x, srcrect->y,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
861 SRCCOPY)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
862 WIN_SetError("BitBlt()");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
863 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
864 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
865 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
866 if (!StretchBlt
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
867 (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
868 dstrect->h, data->memory_hdc, srcrect->x, srcrect->y,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
869 srcrect->w, srcrect->h, SRCCOPY)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
870 WIN_SetError("StretchBlt()");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
871 return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
872 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
873 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
874 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
875 return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
876 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
877
3534
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
878 static int
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
879 GDI_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
880 Uint32 format, void * pixels, int pitch)
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
881 {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
882 GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
883 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
884 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
885 struct {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
886 HBITMAP hbm;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
887 void *pixels;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
888 int pitch;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
889 Uint32 format;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
890 } data;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
891
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
892 data.format = display->current_mode.format;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
893 data.pitch = (rect->w * SDL_BYTESPERPIXEL(data.format));
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
894
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
895 data.hbm = GDI_CreateDIBSection(renderdata->memory_hdc, rect->w, rect->h,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
896 data.pitch, data.format, NULL,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
897 &data.pixels);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
898 if (!data.hbm) {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
899 WIN_SetError("Couldn't create bitmap");
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
900 return -1;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
901 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
902
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
903 SelectObject(renderdata->memory_hdc, data.hbm);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
904 if (!BitBlt(renderdata->memory_hdc, 0, 0, rect->w, rect->h,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
905 renderdata->current_hdc, rect->x, rect->y, SRCCOPY)) {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
906 WIN_SetError("BitBlt()");
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
907 DeleteObject(data.hbm);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
908 return -1;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
909 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
910
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
911 SDL_ConvertPixels(rect->w, rect->h,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
912 data.format, data.pixels, data.pitch,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
913 format, pixels, pitch);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
914
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
915 DeleteObject(data.hbm);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
916 return 0;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
917 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
918
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
919 static int
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
920 GDI_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
921 Uint32 format, const void * pixels, int pitch)
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
922 {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
923 GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
924 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
925 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
926 struct {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
927 HBITMAP hbm;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
928 void *pixels;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
929 int pitch;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
930 Uint32 format;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
931 } data;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
932
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
933 data.format = display->current_mode.format;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
934 data.pitch = (rect->w * SDL_BYTESPERPIXEL(data.format));
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
935
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
936 data.hbm = GDI_CreateDIBSection(renderdata->memory_hdc, rect->w, rect->h,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
937 data.pitch, data.format,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
938 NULL, &data.pixels);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
939 if (!data.hbm) {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
940 WIN_SetError("Couldn't create bitmap");
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
941 return -1;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
942 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
943
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
944 SDL_ConvertPixels(rect->w, rect->h, format, pixels, pitch,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
945 data.format, data.pixels, data.pitch);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
946
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
947 SelectObject(renderdata->memory_hdc, data.hbm);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
948 if (!BitBlt(renderdata->current_hdc, rect->x, rect->y, rect->w, rect->h,
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
949 renderdata->memory_hdc, 0, 0, SRCCOPY)) {
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
950 WIN_SetError("BitBlt()");
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
951 DeleteObject(data.hbm);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
952 return -1;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
953 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
954
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
955 DeleteObject(data.hbm);
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
956 return 0;
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
957 }
9d129e1d0782 Implemented RenderReadPixels() and RenderWritePixels() for GDI renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
958
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
959 static void
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
960 GDI_RenderPresent(SDL_Renderer * renderer)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
961 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
962 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
963 SDL_DirtyRect *dirty;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
964
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
965 /* Send the data to the display */
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
966 if (!(renderer->info.flags & SDL_RENDERER_SINGLEBUFFER)) {
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
967 for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
968 const SDL_Rect *rect = &dirty->rect;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
969 BitBlt(data->window_hdc, rect->x, rect->y, rect->w, rect->h,
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
970 data->render_hdc, rect->x, rect->y, SRCCOPY);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
971 }
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
972 SDL_ClearDirtyRects(&data->dirty);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
973 }
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
974
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
975 /* Update the flipping chain, if any */
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
976 if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
977 data->current_hbm = (data->current_hbm + 1) % 2;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
978 SelectObject(data->render_hdc, data->hbm[data->current_hbm]);
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
979 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
980 data->current_hbm = (data->current_hbm + 1) % 3;
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
981 SelectObject(data->render_hdc, data->hbm[data->current_hbm]);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
982 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
983 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
984
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
985 static void
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
986 GDI_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
987 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
988 GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
989
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
990 if (!data) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
991 return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
992 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
993 if (data->yuv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
994 SDL_SW_DestroyYUVTexture(data->yuv);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
995 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
996 if (data->hpal) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
997 DeleteObject(data->hpal);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
998 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
999 if (data->hbm) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1000 DeleteObject(data->hbm);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1001 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1002 SDL_free(data);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1003 texture->driverdata = NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1004 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1005
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
1006 static void
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
1007 GDI_DestroyRenderer(SDL_Renderer * renderer)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1008 {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
1009 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
1010 int i;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1011
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1012 if (data) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1013 DeleteDC(data->render_hdc);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1014 DeleteDC(data->memory_hdc);
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
1015 #ifndef NO_GETDIBBITS
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1016 if (data->bmi) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1017 SDL_free(data->bmi);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1018 }
3097
0d12e8f1de3c Date: Thu, 05 Feb 2009 18:07:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 3056
diff changeset
1019 #endif
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
1020 for (i = 0; i < SDL_arraysize(data->hbm); ++i) {
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
1021 if (data->hbm[i]) {
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
1022 DeleteObject(data->hbm[i]);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
1023 }
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
1024 }
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
1025 SDL_FreeDirtyRects(&data->dirty);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1026 SDL_free(data);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1027 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1028 SDL_free(renderer);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1029 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1030
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1031 #endif /* SDL_VIDEO_RENDER_GDI */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1032
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1033 /* vi: set ts=4 sw=4 expandtab: */