annotate src/video/SDL_renderer_sw.c @ 2993:2fad80c77c17

Technically more correct
author Sam Lantinga <slouken@libsdl.org>
date Sun, 04 Jan 2009 19:26:50 +0000
parents 2133d2d300fd
children aa34d1180d30
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 #include "SDL_video.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
25 #include "SDL_sysvideo.h"
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
26 #include "SDL_pixels_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
27 #include "SDL_rect_c.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
28 #include "SDL_yuv_sw_c.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
29
c121d94672cb 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
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 /* SDL surface based 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
32
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
33 static SDL_Renderer *SW_CreateRenderer(SDL_Window * window, Uint32 flags);
1970
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
34 static int SW_ActivateRenderer(SDL_Renderer * renderer);
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
35 static int SW_DisplayModeChanged(SDL_Renderer * renderer);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
36 static int SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
37 static int SW_QueryTexturePixels(SDL_Renderer * renderer,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
38 SDL_Texture * texture, void **pixels,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
39 int *pitch);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
40 static int SW_SetTexturePalette(SDL_Renderer * renderer,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
41 SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
42 const SDL_Color * colors, int firstcolor,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
43 int ncolors);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
44 static int SW_GetTexturePalette(SDL_Renderer * renderer,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
45 SDL_Texture * texture, SDL_Color * colors,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
46 int firstcolor, int ncolors);
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
47 static int SW_SetTextureColorMod(SDL_Renderer * renderer,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
48 SDL_Texture * texture);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
49 static int SW_SetTextureAlphaMod(SDL_Renderer * renderer,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
50 SDL_Texture * texture);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
51 static int SW_SetTextureBlendMode(SDL_Renderer * renderer,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
52 SDL_Texture * texture);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
53 static int SW_SetTextureScaleMode(SDL_Renderer * renderer,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
54 SDL_Texture * texture);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
55 static int SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
56 const SDL_Rect * rect, const void *pixels,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
57 int pitch);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
58 static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
59 const SDL_Rect * rect, int markDirty, void **pixels,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
60 int *pitch);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
61 static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
62 static int SW_RenderPoint(SDL_Renderer * renderer, int x, int y);
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
63 static int SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
64 int y2);
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
65 static int SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
66 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
67 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
68 static void SW_RenderPresent(SDL_Renderer * renderer);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
69 static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
70 static void SW_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
71
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
73 SDL_RenderDriver SW_RenderDriver = {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
74 SW_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
75 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 "software",
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
77 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
78 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
79 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_PRESENTVSYNC),
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
80 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
81 SDL_TEXTUREMODULATE_ALPHA),
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
82 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
83 SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
84 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
2811
7af2419ad5b0 Fixed the list of supported YUV formats
Sam Lantinga <slouken@libsdl.org>
parents: 2810
diff changeset
85 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
86 {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
87 SDL_PIXELFORMAT_INDEX8,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
88 SDL_PIXELFORMAT_RGB555,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
89 SDL_PIXELFORMAT_RGB565,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
90 SDL_PIXELFORMAT_RGB888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
91 SDL_PIXELFORMAT_BGR888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
92 SDL_PIXELFORMAT_ARGB8888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
93 SDL_PIXELFORMAT_RGBA8888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
94 SDL_PIXELFORMAT_ABGR8888,
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
95 SDL_PIXELFORMAT_BGRA8888,
2811
7af2419ad5b0 Fixed the list of supported YUV formats
Sam Lantinga <slouken@libsdl.org>
parents: 2810
diff changeset
96 SDL_PIXELFORMAT_YV12,
7af2419ad5b0 Fixed the list of supported YUV formats
Sam Lantinga <slouken@libsdl.org>
parents: 2810
diff changeset
97 SDL_PIXELFORMAT_IYUV,
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
98 SDL_PIXELFORMAT_YUY2,
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents: 2802
diff changeset
99 SDL_PIXELFORMAT_UYVY,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents: 2802
diff changeset
100 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
101 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
102 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
103 };
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 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
106 {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
107 Uint32 format;
1972
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
108 SDL_bool updateSize;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
109 int current_texture;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
110 SDL_Texture *texture[3];
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
111 SDL_Surface surface;
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
112 SDL_Renderer *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
113 SDL_DirtyRectList dirty;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
114 } SW_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
115
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
116 static SDL_Texture *
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
117 CreateTexture(SDL_Renderer * renderer, Uint32 format, int w, int h)
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
118 {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
119 SDL_Texture *texture;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
120
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
121 texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
122 if (!texture) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
123 SDL_OutOfMemory();
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
124 return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
125 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
126
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
127 texture->format = format;
2222
926294b2bb4e Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents: 2130
diff changeset
128 texture->access = SDL_TEXTUREACCESS_STREAMING;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
129 texture->w = w;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
130 texture->h = h;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
131 texture->renderer = renderer;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
132
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
133 if (renderer->CreateTexture(renderer, texture) < 0) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
134 SDL_free(texture);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
135 return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
136 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
137 return texture;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
138 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
139
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
140 static void
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
141 DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
142 {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
143 renderer->DestroyTexture(renderer, texture);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
144 SDL_free(texture);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
145 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
146
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
147 static int
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
148 DisplayPaletteChanged(void *userdata, SDL_Palette * palette)
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
149 {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
150 SW_RenderData *data = (SW_RenderData *) userdata;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
151 int i;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
152
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
153 for (i = 0; i < SDL_arraysize(data->texture); ++i) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
154 if (data->texture[i] && data->renderer->SetTexturePalette) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
155 data->renderer->SetTexturePalette(data->renderer,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
156 data->texture[i],
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
157 palette->colors, 0,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
158 palette->ncolors);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
159 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
160 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
161 return 0;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
162 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
163
2227
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
164 void
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
165 Setup_SoftwareRenderer(SDL_Renderer * renderer)
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
166 {
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
167 renderer->CreateTexture = SW_CreateTexture;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
168 renderer->QueryTexturePixels = SW_QueryTexturePixels;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
169 renderer->SetTexturePalette = SW_SetTexturePalette;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
170 renderer->GetTexturePalette = SW_GetTexturePalette;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
171 renderer->SetTextureColorMod = SW_SetTextureColorMod;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
172 renderer->SetTextureAlphaMod = SW_SetTextureAlphaMod;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
173 renderer->SetTextureBlendMode = SW_SetTextureBlendMode;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
174 renderer->SetTextureScaleMode = SW_SetTextureScaleMode;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
175 renderer->UpdateTexture = SW_UpdateTexture;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
176 renderer->LockTexture = SW_LockTexture;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
177 renderer->UnlockTexture = SW_UnlockTexture;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
178 renderer->DestroyTexture = SW_DestroyTexture;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
179
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
180 renderer->info.mod_modes = SW_RenderDriver.info.mod_modes;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
181 renderer->info.blend_modes = SW_RenderDriver.info.blend_modes;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
182 renderer->info.scale_modes = SW_RenderDriver.info.scale_modes;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
183 renderer->info.num_texture_formats =
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
184 SW_RenderDriver.info.num_texture_formats;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
185 SDL_memcpy(renderer->info.texture_formats,
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
186 SW_RenderDriver.info.texture_formats,
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
187 sizeof(renderer->info.texture_formats));;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
188 renderer->info.max_texture_width = SW_RenderDriver.info.max_texture_width;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
189 renderer->info.max_texture_height =
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
190 SW_RenderDriver.info.max_texture_height;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
191 }
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
192
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
193 SDL_Renderer *
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
194 SW_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
195 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(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
197 SDL_DisplayMode *displayMode = &display->current_mode;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 SDL_Renderer *renderer;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
199 SW_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
200 int i, n;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 int bpp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 Uint32 Rmask, Gmask, Bmask, Amask;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
203 Uint32 renderer_flags;
1929
595ac54a8f9f Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
204 const char *desired_driver;
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
205
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 if (!SDL_PixelFormatEnumToMasks
c121d94672cb 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 (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
c121d94672cb 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 SDL_SetError("Unknown display 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
209 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
210 }
c121d94672cb 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
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*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
213 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
214 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
215 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
216 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217
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
218 data = (SW_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
219 if (!data) {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
220 SW_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
221 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
222 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
223 }
1970
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
224 renderer->ActivateRenderer = SW_ActivateRenderer;
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
225 renderer->DisplayModeChanged = SW_DisplayModeChanged;
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
226
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
227 renderer->RenderPoint = SW_RenderPoint;
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
228 renderer->RenderLine = SW_RenderLine;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
229 renderer->RenderFill = SW_RenderFill;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
230 renderer->RenderCopy = SW_RenderCopy;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
231 renderer->RenderPresent = SW_RenderPresent;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
232 renderer->DestroyRenderer = SW_DestroyRenderer;
2227
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
233 renderer->info.name = SW_RenderDriver.info.name;
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
234 renderer->info.flags = 0;
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
235 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
236 renderer->driverdata = data;
2227
b252359547ed Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
237 Setup_SoftwareRenderer(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
238
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
239 if (flags & SDL_RENDERER_PRESENTFLIP2) {
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
240 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
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
241 n = 2;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
242 } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
243 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
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
244 n = 3;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 } else {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
246 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
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
247 n = 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
248 }
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
249 data->format = displayMode->format;
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
250
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 /* Find a render driver that we can use to display data */
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
252 renderer_flags = (SDL_RENDERER_SINGLEBUFFER |
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
253 SDL_RENDERER_PRESENTDISCARD);
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
254 if (flags & SDL_RENDERER_PRESENTVSYNC) {
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
255 renderer_flags |= SDL_RENDERER_PRESENTVSYNC;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
256 }
1929
595ac54a8f9f Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
257 desired_driver = SDL_getenv("SDL_VIDEO_RENDERER_SWDRIVER");
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
258 for (i = 0; i < display->num_render_drivers; ++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
259 SDL_RenderDriver *driver = &display->render_drivers[i];
1929
595ac54a8f9f Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
260 if (driver->info.name == SW_RenderDriver.info.name) {
595ac54a8f9f Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
261 continue;
595ac54a8f9f Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
262 }
595ac54a8f9f Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
263 if (desired_driver
595ac54a8f9f Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
264 && SDL_strcasecmp(desired_driver, driver->info.name) != 0) {
595ac54a8f9f Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
265 continue;
595ac54a8f9f Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
266 }
595ac54a8f9f Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
267 data->renderer = driver->CreateRenderer(window, renderer_flags);
595ac54a8f9f Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
268 if (data->renderer) {
595ac54a8f9f Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
269 break;
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
270 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 if (i == display->num_render_drivers) {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
273 SW_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
274 SDL_SetError("Couldn't find display render driver");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 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
276 }
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
277 if (data->renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
278 renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
279 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
280
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
281 /* Create the textures we'll use for display */
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
282 for (i = 0; i < n; ++i) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
283 data->texture[i] =
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
284 CreateTexture(data->renderer, data->format, window->w, window->h);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
285 if (!data->texture[i]) {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
286 SW_DestroyRenderer(renderer);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
287 return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
288 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
289 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
290 data->current_texture = 0;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
291
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
292 /* Create a surface we'll use for rendering */
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
293 data->surface.flags = SDL_PREALLOC;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
294 data->surface.format = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
295 if (!data->surface.format) {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
296 SW_DestroyRenderer(renderer);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
297 return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
298 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
299 SDL_SetSurfacePalette(&data->surface, display->palette);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
300
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
301 /* Set up a palette watch on the display palette */
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
302 if (display->palette) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
303 SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
304 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
305
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
306 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
307 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 static int
1970
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
310 SW_ActivateRenderer(SDL_Renderer * renderer)
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
311 {
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
312 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
1972
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
313 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
314 int i, n;
1970
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
315
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
316 if (data->renderer && data->renderer->ActivateRenderer) {
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
317 if (data->renderer->ActivateRenderer(data->renderer) < 0) {
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
318 return -1;
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
319 }
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
320 }
1972
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
321 if (data->updateSize) {
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
322 /* Recreate the textures for the new window size */
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
323 if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
324 n = 2;
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
325 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
326 n = 3;
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
327 } else {
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
328 n = 1;
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
329 }
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
330 for (i = 0; i < n; ++i) {
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
331 if (data->texture[i]) {
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
332 DestroyTexture(data->renderer, data->texture[i]);
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
333 data->texture[i] = 0;
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
334 }
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
335 }
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
336 for (i = 0; i < n; ++i) {
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
337 data->texture[i] =
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
338 CreateTexture(data->renderer, data->format, window->w,
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
339 window->h);
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
340 if (!data->texture[i]) {
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
341 return -1;
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
342 }
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
343 }
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
344 data->updateSize = SDL_FALSE;
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
345 }
1970
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
346 return 0;
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
347 }
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
348
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
349 static int
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
350 SW_DisplayModeChanged(SDL_Renderer * renderer)
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
351 {
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
352 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
353
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
354 if (data->renderer && data->renderer->DisplayModeChanged) {
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
355 if (data->renderer->DisplayModeChanged(data->renderer) < 0) {
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
356 return -1;
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
357 }
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
358 }
2905
d214e791c77c Fixed crash when resizing the window with the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2904
diff changeset
359 /* Rebind the context to the window area */
1972
a0e278364188 Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents: 1971
diff changeset
360 data->updateSize = SDL_TRUE;
2905
d214e791c77c Fixed crash when resizing the window with the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2904
diff changeset
361 return SW_ActivateRenderer(renderer);
1970
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
362 }
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
363
db3ba6c0d0df Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
364 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
365 SW_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
366 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2781
diff changeset
368 texture->driverdata =
Sam Lantinga <slouken@libsdl.org>
parents: 2781
diff changeset
369 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
370 } 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
371 int bpp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 Uint32 Rmask, Gmask, Bmask, Amask;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 if (!SDL_PixelFormatEnumToMasks
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
c121d94672cb 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 SDL_SetError("Unknown 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
377 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
378 }
c121d94672cb 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
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 texture->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
381 SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 Bmask, Amask);
2802
c2834344ca44 Fixed SW_SetTextureScaleMode()
Sam Lantinga <slouken@libsdl.org>
parents: 2786
diff changeset
383 if (texture->access == SDL_TEXTUREACCESS_STATIC) {
c2834344ca44 Fixed SW_SetTextureScaleMode()
Sam Lantinga <slouken@libsdl.org>
parents: 2786
diff changeset
384 SDL_SetSurfaceRLE(texture->driverdata, 1);
c2834344ca44 Fixed SW_SetTextureScaleMode()
Sam Lantinga <slouken@libsdl.org>
parents: 2786
diff changeset
385 }
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
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 if (!texture->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
389 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
390 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 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
392 }
c121d94672cb 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
c121d94672cb 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 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
395 SW_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
396 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
397 {
c121d94672cb 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 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
399 return SDL_SW_QueryYUVTexturePixels((SDL_SW_YUVTexture *)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
400 texture->driverdata, pixels,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
401 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
402 } 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
403 SDL_Surface *surface = (SDL_Surface *) texture->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
404
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 *pixels = surface->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
406 *pitch = surface->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
407 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
408 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410
c121d94672cb 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 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
412 SW_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
413 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
414 {
c121d94672cb 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 if (SDL_ISPIXELFORMAT_FOURCC(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
416 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
417 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
418 } 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
419 SDL_Surface *surface = (SDL_Surface *) texture->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
420
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421 return SDL_SetPaletteColors(surface->format->palette, 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
422 firstcolor, ncolors);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 }
c121d94672cb 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
c121d94672cb 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 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
427 SW_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
428 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
429 {
c121d94672cb 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 if (SDL_ISPIXELFORMAT_FOURCC(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
431 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
432 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
433 } 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
434 SDL_Surface *surface = (SDL_Surface *) texture->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
435
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 SDL_memcpy(colors, &surface->format->palette->colors[firstcolor],
c121d94672cb 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 ncolors * sizeof(*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
438 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
439 }
c121d94672cb 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
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
442 static int
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
443 SW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
444 {
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
445 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
446 return SDL_SetSurfaceColorMod(surface, texture->r, texture->g,
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
447 texture->b);
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
448 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
449
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
450 static int
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
451 SW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
452 {
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
453 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
454 return SDL_SetSurfaceAlphaMod(surface, texture->a);
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
455 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
456
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
457 static int
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
458 SW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
459 {
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
460 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
461 return SDL_SetSurfaceBlendMode(surface, texture->blendMode);
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
462 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
463
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
464 static int
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
465 SW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
466 {
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
467 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
2802
c2834344ca44 Fixed SW_SetTextureScaleMode()
Sam Lantinga <slouken@libsdl.org>
parents: 2786
diff changeset
468 return SDL_SetSurfaceScaleMode(surface, texture->scaleMode);
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
469 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
470
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
471 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
472 SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
473 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
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 (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
476 return SDL_SW_UpdateYUVTexture((SDL_SW_YUVTexture *)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
477 texture->driverdata, rect, pixels,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
478 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
479 } 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
480 SDL_Surface *surface = (SDL_Surface *) texture->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
481 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
482 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
483 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
484
c121d94672cb 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 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
486 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
487 (Uint8 *) surface->pixels + rect->y * surface->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
488 rect->x * surface->format->BytesPerPixel;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 length = rect->w * surface->format->BytesPerPixel;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 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
491 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
492 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
493 dst += surface->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
494 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 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
496 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
500 SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
501 const SDL_Rect * rect, int markDirty, void **pixels,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
502 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
503 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
505 return SDL_SW_LockYUVTexture((SDL_SW_YUVTexture *)
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
506 texture->driverdata, rect, markDirty,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
507 pixels, 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
508 } 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
509 SDL_Surface *surface = (SDL_Surface *) texture->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
510
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 *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
512 (void *) ((Uint8 *) surface->pixels + rect->y * surface->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
513 rect->x * surface->format->BytesPerPixel);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 *pitch = surface->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
515 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
516 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 static void
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
520 SW_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
521 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 if (SDL_ISPIXELFORMAT_FOURCC(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
523 SDL_SW_UnlockYUVTexture((SDL_SW_YUVTexture *) texture->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
524 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 static int
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
528 SW_RenderPoint(SDL_Renderer * renderer, int x, int y)
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
529 {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
530 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
2904
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
531 SDL_Rect rect;
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
532 int status;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
533
2904
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
534 rect.x = x;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
535 rect.y = y;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
536 rect.w = 1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
537 rect.h = 1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
538
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
539 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
540 SDL_AddDirtyRect(&data->dirty, &rect);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
541 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
542
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
543 if (data->renderer->LockTexture(data->renderer,
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
544 data->texture[data->current_texture],
2904
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
545 &rect, 1,
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
546 &data->surface.pixels,
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
547 &data->surface.pitch) < 0) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
548 return -1;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
549 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
550
2904
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
551 data->surface.w = 1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
552 data->surface.h = 1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
553 data->surface.clip_rect.w = 1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
554 data->surface.clip_rect.h = 1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
555
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
556 if (renderer->blendMode == SDL_BLENDMODE_NONE ||
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
557 renderer->blendMode == SDL_BLENDMODE_MASK) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
558 Uint32 color =
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
559 SDL_MapRGBA(data->surface.format, renderer->r, renderer->g,
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
560 renderer->b, renderer->a);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
561
2904
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
562 status = SDL_DrawPoint(&data->surface, 0, 0, color);
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
563 } else {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
564 status =
2904
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
565 SDL_BlendPoint(&data->surface, 0, 0, renderer->blendMode,
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
566 renderer->r, renderer->g, renderer->b,
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
567 renderer->a);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
568 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
569
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
570 data->renderer->UnlockTexture(data->renderer,
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
571 data->texture[data->current_texture]);
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
572 return status;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
573 }
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
574
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
575 static int
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
576 SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
577 {
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
578 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
2904
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
579 SDL_Rect rect;
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
580 int status;
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
581
2904
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
582 if (x1 < x2) {
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
583 rect.x = x1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
584 rect.w = (x2 - x1) + 1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
585 x2 -= x1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
586 x1 = 0;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
587 } else {
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
588 rect.x = x2;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
589 rect.w = (x1 - x2) + 1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
590 x1 -= x2;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
591 x2 = 0;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
592 }
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
593 if (y1 < y2) {
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
594 rect.y = y1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
595 rect.h = (y2 - y1) + 1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
596 y2 -= y1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
597 y1 = 0;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
598 } else {
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
599 rect.y = y2;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
600 rect.h = (y1 - y2) + 1;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
601 y1 -= y2;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
602 y2 = 0;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
603 }
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
604
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
605 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
606 SDL_AddDirtyRect(&data->dirty, &rect);
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
607 }
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
608
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
609 if (data->renderer->LockTexture(data->renderer,
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
610 data->texture[data->current_texture],
2904
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
611 &rect, 1,
2891
Sam Lantinga <slouken@libsdl.org>
parents: 2889
diff changeset
612 &data->surface.pixels,
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
613 &data->surface.pitch) < 0) {
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
614 return -1;
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
615 }
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
616
2904
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
617 data->surface.w = rect.w;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
618 data->surface.h = rect.h;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
619 data->surface.clip_rect.w = rect.w;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
620 data->surface.clip_rect.h = rect.h;
fa81cc1ef3d0 Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
621
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
622 if (renderer->blendMode == SDL_BLENDMODE_NONE ||
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2891
diff changeset
623 renderer->blendMode == SDL_BLENDMODE_MASK) {
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
624 Uint32 color =
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
625 SDL_MapRGBA(data->surface.format, renderer->r, renderer->g,
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
626 renderer->b, renderer->a);
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
627
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
628 status = SDL_DrawLine(&data->surface, x1, y1, x2, y2, color);
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
629 } else {
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
630 status =
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
631 SDL_BlendLine(&data->surface, x1, y1, x2, y2, renderer->blendMode,
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
632 renderer->r, renderer->g, renderer->b, renderer->a);
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
633 }
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
634
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
635 data->renderer->UnlockTexture(data->renderer,
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
636 data->texture[data->current_texture]);
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
637 return status;
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
638 }
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
639
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
640 static int
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
641 SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
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
642 {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
643 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
644 SDL_Rect real_rect;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
645 int status;
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
646
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
647 if (data->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
648 SDL_AddDirtyRect(&data->dirty, rect);
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
649 }
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
650
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
651 if (data->renderer->LockTexture(data->renderer,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
652 data->texture[data->current_texture],
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
653 rect, 1, &data->surface.pixels,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
654 &data->surface.pitch) < 0) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
655 return -1;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
656 }
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
657
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
658 data->surface.w = rect->w;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
659 data->surface.h = rect->h;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
660 data->surface.clip_rect.w = rect->w;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
661 data->surface.clip_rect.h = rect->h;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
662 real_rect = data->surface.clip_rect;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
663
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
664 if (renderer->blendMode == SDL_BLENDMODE_NONE) {
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
665 Uint32 color =
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
666 SDL_MapRGBA(data->surface.format, renderer->r, renderer->g,
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
667 renderer->b, renderer->a);
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
668
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
669 status = SDL_FillRect(&data->surface, &real_rect, color);
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
670 } else {
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
671 status =
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
672 SDL_BlendRect(&data->surface, &real_rect, renderer->blendMode,
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
673 renderer->r, renderer->g, renderer->b, renderer->a);
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2884
diff changeset
674 }
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
675
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
676 data->renderer->UnlockTexture(data->renderer,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
677 data->texture[data->current_texture]);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
678 return status;
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
679 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
680
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
681 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
682 SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
683 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
684 {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
685 SW_RenderData *data = (SW_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
686 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
687 int status;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
688
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
689 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
690 SDL_AddDirtyRect(&data->dirty, dstrect);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
691 }
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
692
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
693 if (data->renderer->LockTexture(data->renderer,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
694 data->texture[data->current_texture],
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
695 dstrect, 1, &data->surface.pixels,
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
696 &data->surface.pitch) < 0) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
697 return -1;
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
698 }
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
699
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
700 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
701 status =
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
702 SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
703 srcrect, data->format, dstrect->w, dstrect->h,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
704 data->surface.pixels, data->surface.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
705 } 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
706 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
707 SDL_Rect real_srcrect = *srcrect;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
708 SDL_Rect real_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
709
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
710 data->surface.w = dstrect->w;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
711 data->surface.h = dstrect->h;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
712 data->surface.clip_rect.w = dstrect->w;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
713 data->surface.clip_rect.h = dstrect->h;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
714 real_dstrect = data->surface.clip_rect;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
715
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
716 status =
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
717 SDL_LowerBlit(surface, &real_srcrect, &data->surface,
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
718 &real_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
719 }
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
720 data->renderer->UnlockTexture(data->renderer,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
721 data->texture[data->current_texture]);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
722 return status;
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
723 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
724
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
725 static void
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
726 SW_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
727 {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
728 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
729 SDL_Texture *texture = data->texture[data->current_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
730
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
731 /* Send the data to the display */
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
732 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
733 SDL_DirtyRect *dirty;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
734 for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
735 data->renderer->RenderCopy(data->renderer, texture, &dirty->rect,
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
736 &dirty->rect);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
737 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
738 SDL_ClearDirtyRects(&data->dirty);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
739 } else {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
740 SDL_Rect rect;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
741 rect.x = 0;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
742 rect.y = 0;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
743 rect.w = texture->w;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
744 rect.h = texture->h;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1972
diff changeset
745 data->renderer->RenderCopy(data->renderer, texture, &rect, &rect);
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
746 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
747 data->renderer->RenderPresent(data->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
748
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
749 /* Update the flipping chain, if any */
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
750 if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
751 data->current_texture = (data->current_texture + 1) % 2;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1930
diff changeset
752 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
753 data->current_texture = (data->current_texture + 1) % 3;
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
754 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
755 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
756
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
757 static void
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
758 SW_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
759 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
760 if (SDL_ISPIXELFORMAT_FOURCC(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
761 SDL_SW_DestroyYUVTexture((SDL_SW_YUVTexture *) texture->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
762 } 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
763 SDL_Surface *surface = (SDL_Surface *) texture->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
764
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
765 SDL_FreeSurface(surface);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
766 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
767 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
768
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
769 static void
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
770 SW_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
771 {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
772 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
773 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
774 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
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
775 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
776
c121d94672cb 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 if (data) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
778 for (i = 0; i < SDL_arraysize(data->texture); ++i) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
779 if (data->texture[i]) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
780 DestroyTexture(data->renderer, data->texture[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
781 }
c121d94672cb 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 }
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
783 if (data->surface.format) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
784 SDL_SetSurfacePalette(&data->surface, NULL);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
785 SDL_FreeFormat(data->surface.format);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
786 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
787 if (display->palette) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
788 SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
789 data);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
790 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
791 if (data->renderer) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
792 data->renderer->DestroyRenderer(data->renderer);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
793 }
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
794 SDL_FreeDirtyRects(&data->dirty);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
795 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
796 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
797 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
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
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
800 /* vi: set ts=4 sw=4 expandtab: */