annotate src/video/SDL_renderer_sw.c @ 1920:8a162bfdc838

Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations. OpenGL renderer in progress
author Sam Lantinga <slouken@libsdl.org>
date Sat, 22 Jul 2006 08:33:18 +0000
parents 092bd3a019c5
children 595ac54a8f9f
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
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2006 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
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);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
34 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
35 static int SW_QueryTexturePixels(SDL_Renderer * renderer,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
36 SDL_Texture * texture, void **pixels,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
37 int *pitch);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
38 static int SW_SetTexturePalette(SDL_Renderer * renderer,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
39 SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
40 const SDL_Color * colors, int firstcolor,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
41 int ncolors);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
42 static int SW_GetTexturePalette(SDL_Renderer * renderer,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
43 SDL_Texture * texture, SDL_Color * colors,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
44 int firstcolor, int ncolors);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
45 static int SW_UpdateTexture(SDL_Renderer * renderer,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
46 SDL_Texture * texture, const SDL_Rect * rect,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
47 const void *pixels, int pitch);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
48 static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
49 const SDL_Rect * rect, int markDirty,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
50 void **pixels, int *pitch);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
51 static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
52 static void SW_DirtyTexture(SDL_Renderer * renderer,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
53 SDL_Texture * texture, int numrects,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
54 const SDL_Rect * rects);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
55 static int SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
56 Uint32 color);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
57 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
58 const SDL_Rect * srcrect,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
59 const SDL_Rect * dstrect, int blendMode,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
60 int scaleMode);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
61 static void SW_RenderPresent(SDL_Renderer * renderer);
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
62 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
63 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
64
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
66 SDL_RenderDriver SW_RenderDriver = {
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
67 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
68 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 "software",
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
70 (SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy |
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
71 SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 |
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
72 SDL_Renderer_PresentDiscard | SDL_Renderer_PresentVSync),
1897
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
73 (SDL_TextureBlendMode_None | SDL_TextureBlendMode_Mask |
c2a27da60b18 Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
74 SDL_TextureBlendMode_Blend),
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 (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
c121d94672cb 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 11,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 SDL_PixelFormat_Index8,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 SDL_PixelFormat_RGB555,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 SDL_PixelFormat_RGB565,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 SDL_PixelFormat_RGB888,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 SDL_PixelFormat_BGR888,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 SDL_PixelFormat_ARGB8888,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 SDL_PixelFormat_RGBA8888,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 SDL_PixelFormat_ABGR8888,
c121d94672cb 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 SDL_PixelFormat_BGRA8888,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 SDL_PixelFormat_YUY2,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 SDL_PixelFormat_UYVY},
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 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
90 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
91 };
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 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
94 {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
95 Uint32 format;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
96 int current_texture;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
97 SDL_Texture *texture[3];
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
98 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
99 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
100 SDL_DirtyRectList dirty;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
101 } 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
102
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
103 static SDL_Texture *
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
104 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
105 {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
106 SDL_Texture *texture;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
107
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
108 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
109 if (!texture) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
110 SDL_OutOfMemory();
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
111 return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
112 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
113
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
114 texture->format = format;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
115 texture->access = SDL_TextureAccess_Local;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
116 texture->w = w;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
117 texture->h = h;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
118 texture->renderer = renderer;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
119
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
120 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
121 SDL_free(texture);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
122 return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
123 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
124 return texture;
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 static void
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
128 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
129 {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
130 renderer->DestroyTexture(renderer, texture);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
131 SDL_free(texture);
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
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
134 static int
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
135 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
136 {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
137 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
138 int i;
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 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
141 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
142 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
143 data->texture[i],
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
144 palette->colors, 0,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
145 palette->ncolors);
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 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
148 return 0;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
149 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
150
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
151 SDL_Renderer *
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
152 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
153 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 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
155 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
156 SDL_Renderer *renderer;
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
157 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
158 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
159 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
160 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
161 Uint32 renderer_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
162
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 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
164 (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
165 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
166 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
167 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 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
170 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
171 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
172 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
173 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174
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
175 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
176 if (!data) {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
177 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
178 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
179 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
180 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
182 renderer->CreateTexture = SW_CreateTexture;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
183 renderer->QueryTexturePixels = SW_QueryTexturePixels;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
184 renderer->SetTexturePalette = SW_SetTexturePalette;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
185 renderer->GetTexturePalette = SW_GetTexturePalette;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
186 renderer->UpdateTexture = SW_UpdateTexture;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
187 renderer->LockTexture = SW_LockTexture;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
188 renderer->UnlockTexture = SW_UnlockTexture;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
189 renderer->DirtyTexture = SW_DirtyTexture;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
190 renderer->RenderFill = SW_RenderFill;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
191 renderer->RenderCopy = SW_RenderCopy;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
192 renderer->RenderPresent = SW_RenderPresent;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
193 renderer->DestroyTexture = SW_DestroyTexture;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
194 renderer->DestroyRenderer = SW_DestroyRenderer;
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
195 renderer->info = SW_RenderDriver.info;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 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
197 renderer->driverdata = data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
199 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
200
c121d94672cb 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 if (flags & SDL_Renderer_PresentFlip2) {
c121d94672cb 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 renderer->info.flags |= SDL_Renderer_PresentFlip2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 n = 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 } else if (flags & SDL_Renderer_PresentFlip3) {
c121d94672cb 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 renderer->info.flags |= SDL_Renderer_PresentFlip3;
c121d94672cb 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 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
207 } 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
208 renderer->info.flags |= SDL_Renderer_PresentCopy;
c121d94672cb 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 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
210 }
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
211 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
212
c121d94672cb 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 /* Find a render driver that we can use to display data */
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
214 renderer_flags = (SDL_Renderer_SingleBuffer |
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
215 SDL_Renderer_PresentDiscard);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
216 if (flags & SDL_Renderer_PresentVSync) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
217 renderer_flags |= SDL_Renderer_PresentVSync;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
218 }
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 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
220 SDL_RenderDriver *driver = &display->render_drivers[i];
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
221 if (driver->info.name != SW_RenderDriver.info.name) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
222 data->renderer = driver->CreateRenderer(window, renderer_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
223 if (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
224 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 if (i == display->num_render_drivers) {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
229 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
230 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
231 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
232 }
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
233 if (data->renderer->info.flags & SDL_Renderer_PresentVSync) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
234 renderer->info.flags |= SDL_Renderer_PresentVSync;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
235 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
236
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
237 /* 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
238 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
239 data->texture[i] =
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
240 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
241 if (!data->texture[i]) {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
242 SW_DestroyRenderer(renderer);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
243 return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
244 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
245 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
246 data->current_texture = 0;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
247
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
248 /* 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
249 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
250 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
251 if (!data->surface.format) {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
252 SW_DestroyRenderer(renderer);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
253 return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
254 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
255 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
256
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
257 /* 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
258 if (display->palette) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
259 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
260 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
261
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
262 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
263 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
266 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
267 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 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
269 texture->driverdata = SDL_SW_CreateYUVTexture(texture);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 } 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
271 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
272 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
273
c121d94672cb 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 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
275 (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
276 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
277 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
278 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 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
281 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
282 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
283 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 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
286 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
287 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 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
289 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
292 SW_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
293 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
294 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 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
296 return SDL_SW_QueryYUVTexturePixels((SDL_SW_YUVTexture *) texture->
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 driverdata, pixels, pitch);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 } 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
299 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
300
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 *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
302 *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
303 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
304 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 }
c121d94672cb 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
c121d94672cb 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 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
308 SW_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
309 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
310 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 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
312 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
313 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
314 } 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
315 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
316
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 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
318 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
319 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
323 SW_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
324 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
325 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 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
327 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
328 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
329 } 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
330 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
331
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 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
333 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
334 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
335 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
339 SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
340 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
341 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 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
343 return SDL_SW_UpdateYUVTexture((SDL_SW_YUVTexture *) texture->
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 driverdata, rect, pixels, pitch);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 } 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
346 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
347 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
348 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
349 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
350
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 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
352 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
353 (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
354 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
355 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
356 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
357 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
358 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
359 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
360 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 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
362 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
366 SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
367 const SDL_Rect * rect, int markDirty, void **pixels,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
368 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
369 {
c121d94672cb 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 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
371 return SDL_SW_LockYUVTexture((SDL_SW_YUVTexture *) texture->
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 driverdata, rect, markDirty, pixels,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 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
374 } 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
375 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
376
c121d94672cb 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 *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
378 (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
379 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
380 *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
381 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
382 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 static void
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
386 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
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 (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
389 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
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 }
c121d94672cb 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 static void
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
394 SW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
395 int numrects, const SDL_Rect * rects)
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
396 {
c121d94672cb 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
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
400 SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 color)
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
401 {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
402 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
403 Uint8 r, g, b, a;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
404 void *pixels;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
405 int pitch;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
406 SDL_Rect real_rect;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
407 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
408
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
409 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
410 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
411 }
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
412
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 a = (Uint8) ((color >> 24) & 0xFF);
c121d94672cb 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 r = (Uint8) ((color >> 16) & 0xFF);
c121d94672cb 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 g = (Uint8) ((color >> 8) & 0xFF);
c121d94672cb 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 b = (Uint8) (color & 0xFF);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
417 color = SDL_MapRGBA(data->surface.format, r, g, b, a);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
419 if (data->renderer->
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
420 LockTexture(data->renderer, 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
421 rect, 1, &data->surface.pixels,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
422 &data->surface.pitch) < 0) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
423 return -1;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
424 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
425 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
426 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
427 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
428 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
429 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
430
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
431 status = SDL_FillRect(&data->surface, &real_rect, color);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
432
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
433 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
434 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
435 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
436 }
c121d94672cb 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
c121d94672cb 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 static int
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
439 SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
440 const SDL_Rect * srcrect, const SDL_Rect * dstrect,
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
441 int blendMode, int scaleMode)
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
442 {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
443 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
444 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
445 int status;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
446
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
447 if (data->renderer->info.flags & SDL_Renderer_PresentCopy) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
448 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
449 }
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
450
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
451 if (data->renderer->
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
452 LockTexture(data->renderer, 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
453 dstrect, 1, &data->surface.pixels,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
454 &data->surface.pitch) < 0) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
455 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
456 }
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
457
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 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
459 status =
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
460 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
461 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
462 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
463 } 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
464 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
465 SDL_Rect real_srcrect = *srcrect;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
466 SDL_Rect real_dstrect;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
467
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
468 data->surface.w = dstrect->w;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
469 data->surface.h = dstrect->h;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
470 data->surface.clip_rect.w = dstrect->w;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
471 data->surface.clip_rect.h = dstrect->h;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
472 real_dstrect = data->surface.clip_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
473
c121d94672cb 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 if (blendMode &
c121d94672cb 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 (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476 SDL_SetAlpha(surface, SDL_SRCALPHA, 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
477 } 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
478 SDL_SetAlpha(surface, 0, 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
479 }
c121d94672cb 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 if (scaleMode != SDL_TextureScaleMode_None &&
c121d94672cb 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 (srcrect->w != dstrect->w || srcrect->h != dstrect->h)) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
482 status =
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
483 SDL_SoftStretch(surface, &real_srcrect, &data->surface,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
484 &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
485 } else {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
486 status =
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
487 SDL_LowerBlit(surface, &real_srcrect, &data->surface,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
488 &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
489 }
c121d94672cb 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 }
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
491 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
492 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
493 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
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
c121d94672cb 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 static void
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
497 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
498 {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
499 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
500 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
501
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 /* Send the data to the display */
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
503 if (data->renderer->info.flags & SDL_Renderer_PresentCopy) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
504 SDL_DirtyRect *dirty;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
505 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
506 data->renderer->RenderCopy(data->renderer, texture, &dirty->rect,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
507 &dirty->rect,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
508 SDL_TextureBlendMode_None,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
509 SDL_TextureScaleMode_None);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
510 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
511 SDL_ClearDirtyRects(&data->dirty);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
512 } else {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
513 SDL_Rect rect;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
514 rect.x = 0;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
515 rect.y = 0;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
516 rect.w = texture->w;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
517 rect.h = texture->h;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
518 data->renderer->RenderCopy(data->renderer, texture, &rect, &rect,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
519 SDL_TextureBlendMode_None,
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
520 SDL_TextureScaleMode_None);
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 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
523
c121d94672cb 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 /* Update the flipping chain, if any */
c121d94672cb 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 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
526 data->current_texture = (data->current_texture + 1) % 2;
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
527 } 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
528 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
529 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 static void
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
533 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
534 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
535 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
536 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
537 } 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
538 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
539
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 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
541 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544 static void
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
545 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
546 {
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
547 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
548 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
549 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
550 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
551
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 if (data) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
553 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
554 if (data->texture[i]) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
555 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
556 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557 }
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
558 if (data->surface.format) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
559 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
560 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
561 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
562 if (display->palette) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
563 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
564 data);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
565 }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
566 if (data->renderer) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1897
diff changeset
567 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
568 }
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
569 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
570 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
571 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 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
573 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 /* vi: set ts=4 sw=4 expandtab: */