annotate src/video/SDL_renderer_sw.c @ 1735:8dd28c4ef746 SDL-1.3

SDL_Rect now uses int for position and size. Added a few more rectangle functions. Added a dirty rectangle list implementation.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 07:34:50 +0000
parents a1ebb17f9c52
children
rev   line source
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_video.h"
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #include "SDL_sysvideo.h"
1735
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
26 #include "SDL_rect_c.h"
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
27 #include "SDL_yuv_sw_c.h"
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 /* SDL surface based renderer implementation */
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 static SDL_Renderer *SDL_SW_CreateRenderer(SDL_Window * window, Uint32 flags);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 static int SDL_SW_CreateTexture(SDL_Renderer * renderer,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 SDL_Texture * texture);
1678
90bf530ced8e SDL_SetVideoMode() compiles now...
Sam Lantinga <slouken@libsdl.org>
parents: 1676
diff changeset
35 static int SDL_SW_QueryTexturePixels(SDL_Renderer * renderer,
90bf530ced8e SDL_SetVideoMode() compiles now...
Sam Lantinga <slouken@libsdl.org>
parents: 1676
diff changeset
36 SDL_Texture * texture, void **pixels,
90bf530ced8e SDL_SetVideoMode() compiles now...
Sam Lantinga <slouken@libsdl.org>
parents: 1676
diff changeset
37 int *pitch);
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
38 static int SDL_SW_SetTexturePalette(SDL_Renderer * renderer,
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
39 SDL_Texture * texture,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
40 const SDL_Color * colors, int firstcolor,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
41 int ncolors);
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
42 static int SDL_SW_GetTexturePalette(SDL_Renderer * renderer,
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
43 SDL_Texture * texture, SDL_Color * colors,
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
44 int firstcolor, int ncolors);
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 static int SDL_SW_UpdateTexture(SDL_Renderer * renderer,
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
46 SDL_Texture * texture, const SDL_Rect * rect,
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 const void *pixels, int pitch);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 static int SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
49 const SDL_Rect * rect, int markDirty,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
50 void **pixels, int *pitch);
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 static void SDL_SW_UnlockTexture(SDL_Renderer * renderer,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 SDL_Texture * texture);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 static void SDL_SW_DirtyTexture(SDL_Renderer * renderer,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 SDL_Texture * texture, int numrects,
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
55 const SDL_Rect * rects);
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 static void SDL_SW_SelectRenderTexture(SDL_Renderer * renderer,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 SDL_Texture * texture);
1720
a1ebb17f9c52 Cleaned up a bunch of warnings, started adding Win32 event support
Sam Lantinga <slouken@libsdl.org>
parents: 1706
diff changeset
58 static int SDL_SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
a1ebb17f9c52 Cleaned up a bunch of warnings, started adding Win32 event support
Sam Lantinga <slouken@libsdl.org>
parents: 1706
diff changeset
59 Uint32 color);
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 static int SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
61 const SDL_Rect * srcrect,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
62 const SDL_Rect * dstrect, int blendMode,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
63 int scaleMode);
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
64 static int SDL_SW_RenderReadPixels(SDL_Renderer * renderer,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
65 const SDL_Rect * rect, void *pixels,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
66 int pitch);
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
67 static int SDL_SW_RenderWritePixels(SDL_Renderer * renderer,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
68 const SDL_Rect * rect, const void *pixels,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
69 int pitch);
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 static void SDL_SW_RenderPresent(SDL_Renderer * renderer);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 static void SDL_SW_DestroyTexture(SDL_Renderer * renderer,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 SDL_Texture * texture);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 static void SDL_SW_DestroyRenderer(SDL_Renderer * renderer);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 SDL_RenderDriver SDL_SW_RenderDriver = {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 SDL_SW_CreateRenderer,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 "software",
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 (SDL_Renderer_PresentDiscard |
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 SDL_Renderer_PresentCopy |
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 SDL_Renderer_PresentFlip2 |
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 SDL_Renderer_PresentFlip3 | SDL_Renderer_RenderTarget),
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 (SDL_TextureBlendMode_None |
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 11,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 SDL_PixelFormat_Index8,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 SDL_PixelFormat_RGB555,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 SDL_PixelFormat_RGB565,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 SDL_PixelFormat_RGB888,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 SDL_PixelFormat_BGR888,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 SDL_PixelFormat_ARGB8888,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 SDL_PixelFormat_RGBA8888,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 SDL_PixelFormat_ABGR8888,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 SDL_PixelFormat_BGRA8888,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 SDL_PixelFormat_YUY2,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 SDL_PixelFormat_UYVY},
1735
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
100 0,
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
101 0}
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 };
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 typedef struct
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 int current_screen;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 SDL_Surface *screens[3];
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 SDL_Surface *target;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 SDL_Renderer *renderer;
1735
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
110 SDL_DirtyRectList dirty;
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 } SDL_SW_RenderData;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 SDL_Renderer *
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 SDL_SW_CreateRenderer(SDL_Window * window, Uint32 flags)
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 {
1706
1577404809f0 Added a multi-window version of testsprite using the new API.
Sam Lantinga <slouken@libsdl.org>
parents: 1684
diff changeset
116 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1577404809f0 Added a multi-window version of testsprite using the new API.
Sam Lantinga <slouken@libsdl.org>
parents: 1684
diff changeset
117 SDL_DisplayMode *displayMode = &display->current_mode;
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 SDL_Renderer *renderer;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 SDL_SW_RenderData *data;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 int i, n;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 int bpp;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 Uint32 Rmask, Gmask, Bmask, Amask;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 if (!SDL_PixelFormatEnumToMasks
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 SDL_SetError("Unknown display format");
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 return NULL;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129
1735
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
130 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 if (!renderer) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 SDL_OutOfMemory();
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 return NULL;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 data = (SDL_SW_RenderData *) SDL_malloc(sizeof(*data));
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 if (!data) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 SDL_SW_DestroyRenderer(renderer);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 SDL_OutOfMemory();
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 return NULL;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 SDL_zerop(data);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 renderer->CreateTexture = SDL_SW_CreateTexture;
1678
90bf530ced8e SDL_SetVideoMode() compiles now...
Sam Lantinga <slouken@libsdl.org>
parents: 1676
diff changeset
145 renderer->QueryTexturePixels = SDL_SW_QueryTexturePixels;
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
146 renderer->SetTexturePalette = SDL_SW_SetTexturePalette;
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
147 renderer->GetTexturePalette = SDL_SW_GetTexturePalette;
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 renderer->UpdateTexture = SDL_SW_UpdateTexture;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 renderer->LockTexture = SDL_SW_LockTexture;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 renderer->UnlockTexture = SDL_SW_UnlockTexture;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 renderer->DirtyTexture = SDL_SW_DirtyTexture;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 renderer->SelectRenderTexture = SDL_SW_SelectRenderTexture;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 renderer->RenderFill = SDL_SW_RenderFill;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 renderer->RenderCopy = SDL_SW_RenderCopy;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 renderer->RenderReadPixels = SDL_SW_RenderReadPixels;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 renderer->RenderWritePixels = SDL_SW_RenderWritePixels;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 renderer->RenderPresent = SDL_SW_RenderPresent;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 renderer->DestroyTexture = SDL_SW_DestroyTexture;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 renderer->DestroyRenderer = SDL_SW_DestroyRenderer;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 renderer->info = SDL_SW_RenderDriver.info;
1706
1577404809f0 Added a multi-window version of testsprite using the new API.
Sam Lantinga <slouken@libsdl.org>
parents: 1684
diff changeset
161 renderer->window = window->id;
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 renderer->driverdata = data;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 renderer->info.flags = SDL_Renderer_RenderTarget;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 if (flags & SDL_Renderer_PresentFlip2) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 renderer->info.flags |= SDL_Renderer_PresentFlip2;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 n = 2;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 } else if (flags & SDL_Renderer_PresentFlip3) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 renderer->info.flags |= SDL_Renderer_PresentFlip3;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 n = 3;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 } else {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 renderer->info.flags |= SDL_Renderer_PresentCopy;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 n = 1;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 for (i = 0; i < n; ++i) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 data->screens[i] =
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask,
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 Bmask, Amask);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 if (!data->screens[i]) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 SDL_SW_DestroyRenderer(renderer);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 return NULL;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 }
1706
1577404809f0 Added a multi-window version of testsprite using the new API.
Sam Lantinga <slouken@libsdl.org>
parents: 1684
diff changeset
184 SDL_SetSurfacePalette(data->screens[i], display->palette);
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 data->current_screen = 0;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 data->target = data->screens[0];
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 /* Find a render driver that we can use to display data */
1706
1577404809f0 Added a multi-window version of testsprite using the new API.
Sam Lantinga <slouken@libsdl.org>
parents: 1684
diff changeset
190 for (i = 0; i < display->num_render_drivers; ++i) {
1577404809f0 Added a multi-window version of testsprite using the new API.
Sam Lantinga <slouken@libsdl.org>
parents: 1684
diff changeset
191 SDL_RenderDriver *driver = &display->render_drivers[i];
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 if (driver->info.name != SDL_SW_RenderDriver.info.name) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 data->renderer =
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 driver->CreateRenderer(window, SDL_Renderer_PresentDiscard);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 if (data->renderer) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 break;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 }
1706
1577404809f0 Added a multi-window version of testsprite using the new API.
Sam Lantinga <slouken@libsdl.org>
parents: 1684
diff changeset
200 if (i == display->num_render_drivers) {
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 SDL_SW_DestroyRenderer(renderer);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 SDL_SetError("Couldn't find display render driver");
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 return NULL;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 return renderer;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
208 static int
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 SDL_SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 {
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
211 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
212 if (texture->access == SDL_TextureAccess_Render) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
213 SDL_SetError("Rendering to YUV format textures is not supported");
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
214 return -1;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
215 }
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
216 texture->driverdata = SDL_SW_CreateYUVTexture(texture);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
217 } else {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
218 int bpp;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
219 Uint32 Rmask, Gmask, Bmask, Amask;
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
221 if (!SDL_PixelFormatEnumToMasks
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
222 (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
223 SDL_SetError("Unknown texture format");
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
224 return -1;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
225 }
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
226
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
227 texture->driverdata =
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
228 SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
229 Bmask, Amask);
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
232 if (!texture->driverdata) {
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 return -1;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 return 0;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
238 static int
1678
90bf530ced8e SDL_SetVideoMode() compiles now...
Sam Lantinga <slouken@libsdl.org>
parents: 1676
diff changeset
239 SDL_SW_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
90bf530ced8e SDL_SetVideoMode() compiles now...
Sam Lantinga <slouken@libsdl.org>
parents: 1676
diff changeset
240 void **pixels, int *pitch)
90bf530ced8e SDL_SetVideoMode() compiles now...
Sam Lantinga <slouken@libsdl.org>
parents: 1676
diff changeset
241 {
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
242 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
243 return SDL_SW_QueryYUVTexturePixels((SDL_SW_YUVTexture *) texture->
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
244 driverdata, pixels, pitch);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
245 } else {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
246 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
1678
90bf530ced8e SDL_SetVideoMode() compiles now...
Sam Lantinga <slouken@libsdl.org>
parents: 1676
diff changeset
247
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
248 *pixels = surface->pixels;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
249 *pitch = surface->pitch;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
250 return 0;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
251 }
1678
90bf530ced8e SDL_SetVideoMode() compiles now...
Sam Lantinga <slouken@libsdl.org>
parents: 1676
diff changeset
252 }
90bf530ced8e SDL_SetVideoMode() compiles now...
Sam Lantinga <slouken@libsdl.org>
parents: 1676
diff changeset
253
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
254 static int
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
255 SDL_SW_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
256 const SDL_Color * colors, int firstcolor,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
257 int ncolors)
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
258 {
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
259 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
260 SDL_SetError("YUV textures don't have a palette");
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
261 return -1;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
262 } else {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
263 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
264
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
265 return SDL_SetPaletteColors(surface->format->palette, colors,
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
266 firstcolor, ncolors);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
267 }
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
268 }
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
269
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
270 static int
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
271 SDL_SW_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
272 SDL_Color * colors, int firstcolor, int ncolors)
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
273 {
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
274 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
275 SDL_SetError("YUV textures don't have a palette");
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
276 return -1;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
277 } else {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
278 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
279
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
280 SDL_memcpy(colors, &surface->format->palette->colors[firstcolor],
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
281 ncolors * sizeof(*colors));
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
282 return 0;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
283 }
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
284 }
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
285
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
286 static int
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 SDL_SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
288 const SDL_Rect * rect, const void *pixels, int pitch)
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 {
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
290 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
291 return SDL_SW_UpdateYUVTexture((SDL_SW_YUVTexture *) texture->
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
292 driverdata, rect, pixels, pitch);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
293 } else {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
294 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
295 Uint8 *src, *dst;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
296 int row;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
297 size_t length;
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
299 src = (Uint8 *) pixels;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
300 dst =
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
301 (Uint8 *) surface->pixels + rect->y * surface->pitch +
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
302 rect->x * surface->format->BytesPerPixel;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
303 length = rect->w * surface->format->BytesPerPixel;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
304 for (row = 0; row < rect->h; ++row) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
305 SDL_memcpy(dst, src, length);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
306 src += pitch;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
307 dst += surface->pitch;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
308 }
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
309 return 0;
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
313 static int
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
315 const SDL_Rect * rect, int markDirty, void **pixels,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
316 int *pitch)
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 {
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
318 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
319 return SDL_SW_LockYUVTexture((SDL_SW_YUVTexture *) texture->
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
320 driverdata, rect, markDirty, pixels,
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
321 pitch);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
322 } else {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
323 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
325 *pixels =
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
326 (void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch +
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
327 rect->x * surface->format->BytesPerPixel);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
328 *pitch = surface->pitch;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
329 return 0;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
330 }
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
333 static void
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 SDL_SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 {
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
336 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
337 SDL_SW_UnlockYUVTexture((SDL_SW_YUVTexture *) texture->driverdata);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
338 }
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
341 static void
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 SDL_SW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
343 int numrects, const SDL_Rect * rects)
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
347 static void
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 SDL_SW_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
1683
396a35389351 Finished palettized display handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1681
diff changeset
351
396a35389351 Finished palettized display handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1681
diff changeset
352 if (texture) {
396a35389351 Finished palettized display handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1681
diff changeset
353 data->target = (SDL_Surface *) texture->driverdata;
396a35389351 Finished palettized display handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1681
diff changeset
354 } else {
396a35389351 Finished palettized display handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1681
diff changeset
355 data->target = data->screens[data->current_screen];
396a35389351 Finished palettized display handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1681
diff changeset
356 }
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358
1720
a1ebb17f9c52 Cleaned up a bunch of warnings, started adding Win32 event support
Sam Lantinga <slouken@libsdl.org>
parents: 1706
diff changeset
359 static int
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
360 SDL_SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
361 Uint32 color)
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
364 SDL_Rect real_rect = *rect;
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 Uint8 r, g, b, a;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366
1735
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
367 SDL_AddDirtyRect(&data->dirty, rect);
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
368
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 a = (Uint8) ((color >> 24) & 0xFF);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 r = (Uint8) ((color >> 16) & 0xFF);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 g = (Uint8) ((color >> 8) & 0xFF);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 b = (Uint8) (color & 0xFF);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 color = SDL_MapRGBA(data->target->format, r, g, b, a);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374
1720
a1ebb17f9c52 Cleaned up a bunch of warnings, started adding Win32 event support
Sam Lantinga <slouken@libsdl.org>
parents: 1706
diff changeset
375 return SDL_FillRect(data->target, &real_rect, color);
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
378 static int
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
380 const SDL_Rect * srcrect, const SDL_Rect * dstrect,
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
381 int blendMode, int scaleMode)
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
1706
1577404809f0 Added a multi-window version of testsprite using the new API.
Sam Lantinga <slouken@libsdl.org>
parents: 1684
diff changeset
384 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
1577404809f0 Added a multi-window version of testsprite using the new API.
Sam Lantinga <slouken@libsdl.org>
parents: 1684
diff changeset
385 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386
1735
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
387 SDL_AddDirtyRect(&data->dirty, dstrect);
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
388
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
389 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
390 SDL_Surface *target = data->target;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
391 void *pixels =
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
392 (Uint8 *) target->pixels + dstrect->y * target->pitch +
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
393 dstrect->x * target->format->BytesPerPixel;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
394 return SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata,
1706
1577404809f0 Added a multi-window version of testsprite using the new API.
Sam Lantinga <slouken@libsdl.org>
parents: 1684
diff changeset
395 srcrect, display->current_mode.format,
1577404809f0 Added a multi-window version of testsprite using the new API.
Sam Lantinga <slouken@libsdl.org>
parents: 1684
diff changeset
396 dstrect->w, dstrect->h, pixels,
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
397 target->pitch);
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 } else {
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
399 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
400 SDL_Rect real_srcrect = *srcrect;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
401 SDL_Rect real_dstrect = *dstrect;
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
402
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
403 if (blendMode &
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
404 (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
405 SDL_SetAlpha(surface, SDL_SRCALPHA, 0);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
406 } else {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
407 SDL_SetAlpha(surface, 0, 0);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
408 }
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
409 if (scaleMode != SDL_TextureScaleMode_None &&
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
410 (srcrect->w != dstrect->w || srcrect->h != dstrect->h)) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
411 return SDL_SoftStretch(surface, &real_srcrect, data->target,
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
412 &real_dstrect);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
413 } else {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
414 return SDL_LowerBlit(surface, &real_srcrect, data->target,
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
415 &real_dstrect);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
416 }
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
420 static int
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
421 SDL_SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 void *pixels, int pitch)
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 SDL_Surface *surface = data->target;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 Uint8 *src, *dst;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427 int row;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428 size_t length;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 src =
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 (Uint8 *) surface->pixels + rect->y * surface->pitch +
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 rect->x * surface->format->BytesPerPixel;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433 dst = (Uint8 *) pixels;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434 length = rect->w * surface->format->BytesPerPixel;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 for (row = 0; row < rect->h; ++row) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 SDL_memcpy(dst, src, length);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 src += surface->pitch;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 dst += pitch;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440 return 0;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
443 static int
1681
80a5e6a4e1e2 Working on paletted display and texture support (two different issues)
Sam Lantinga <slouken@libsdl.org>
parents: 1680
diff changeset
444 SDL_SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 const void *pixels, int pitch)
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 SDL_Surface *surface = data->target;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 Uint8 *src, *dst;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 int row;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451 size_t length;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452
1735
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
453 SDL_AddDirtyRect(&data->dirty, rect);
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
454
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455 src = (Uint8 *) pixels;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 dst =
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 (Uint8 *) surface->pixels + rect->y * surface->pitch +
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 rect->x * surface->format->BytesPerPixel;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 length = rect->w * surface->format->BytesPerPixel;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460 for (row = 0; row < rect->h; ++row) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461 SDL_memcpy(dst, src, length);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
462 src += pitch;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463 dst += surface->pitch;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
465 return 0;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
468 static void
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 SDL_SW_RenderPresent(SDL_Renderer * renderer)
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 SDL_Surface *surface = data->screens[data->current_screen];
1735
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
473 SDL_DirtyRect *dirty;
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 int new_screen;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476 /* Send the data to the display */
1735
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
477 for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
478 void *pixels =
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
479 (void *) ((Uint8 *) surface->pixels +
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
480 dirty->rect.y * surface->pitch +
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
481 dirty->rect.x * surface->format->BytesPerPixel);
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
482 data->renderer->RenderWritePixels(data->renderer, &dirty->rect,
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
483 pixels, surface->pitch);
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
484 }
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
485 SDL_ClearDirtyRects(&data->dirty);
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 data->renderer->RenderPresent(data->renderer);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487
1735
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
488
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 /* Update the flipping chain, if any */
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 if (renderer->info.flags & SDL_Renderer_PresentFlip2) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 new_screen = (data->current_screen + 1) % 2;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492 } else if (renderer->info.flags & SDL_Renderer_PresentFlip3) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 new_screen = (data->current_screen + 1) % 3;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 } else {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 new_screen = 0;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497 if (data->target == data->screens[data->current_screen]) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498 data->target = data->screens[new_screen];
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 data->current_screen = new_screen;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
503 static void
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 SDL_SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 {
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
506 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
507 SDL_SW_DestroyYUVTexture((SDL_SW_YUVTexture *) texture->driverdata);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
508 } else {
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
509 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510
1684
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
511 SDL_FreeSurface(surface);
c4aa1a2f48f1 Software YUV texture support in progress...
Sam Lantinga <slouken@libsdl.org>
parents: 1683
diff changeset
512 }
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514
1680
9488fca10677 Dummy video driver works again in high color video modes. Yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1678
diff changeset
515 static void
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 SDL_SW_DestroyRenderer(SDL_Renderer * renderer)
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 int i;
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521 if (data) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 for (i = 0; i < SDL_arraysize(data->screens); ++i) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 if (data->screens[i]) {
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 SDL_FreeSurface(data->screens[i]);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 }
1735
8dd28c4ef746 SDL_Rect now uses int for position and size.
Sam Lantinga <slouken@libsdl.org>
parents: 1720
diff changeset
527 SDL_FreeDirtyRects(&data->dirty);
1676
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528 SDL_free(data);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530 SDL_free(renderer);
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 }
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532
e136f3ffdc1b Adding software renderer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533 /* vi: set ts=4 sw=4 expandtab: */