comparison src/video/dummy/SDL_nullrender.c @ 1907:06c27a737b7a

Streamlined the API a bit and optimized the software renderer.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 15 Jul 2006 09:46:36 +0000
parents 0c49855a7a3e
children e079dafea2bf
comparison
equal deleted inserted replaced
1906:0c49855a7a3e 1907:06c27a737b7a
29 29
30 static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window, 30 static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window,
31 Uint32 flags); 31 Uint32 flags);
32 static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer, 32 static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer,
33 SDL_Texture * texture); 33 SDL_Texture * texture);
34 static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer,
35 const SDL_Rect * rect, void *pixels,
36 int pitch);
37 static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer,
38 const SDL_Rect * rect,
39 const void *pixels, int pitch);
40 static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer); 34 static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer);
41 static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer); 35 static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer);
42 36
43 37
44 SDL_RenderDriver SDL_DUMMY_RenderDriver = { 38 SDL_RenderDriver SDL_DUMMY_RenderDriver = {
45 SDL_DUMMY_CreateRenderer, 39 SDL_DUMMY_CreateRenderer,
46 { 40 {
47 "dummy", 41 "dummy",
48 (SDL_Renderer_Minimal | SDL_Renderer_PresentDiscard | 42 (SDL_Renderer_PresentDiscard | SDL_Renderer_PresentCopy),
49 SDL_Renderer_PresentCopy),
50 SDL_TextureBlendMode_None, 43 SDL_TextureBlendMode_None,
51 SDL_TextureScaleMode_None, 44 SDL_TextureScaleMode_None,
52 0, 45 0,
53 {0}, 46 {0},
54 0, 47 0,
89 SDL_OutOfMemory(); 82 SDL_OutOfMemory();
90 return NULL; 83 return NULL;
91 } 84 }
92 SDL_zerop(data); 85 SDL_zerop(data);
93 86
94 renderer->RenderReadPixels = SDL_DUMMY_RenderReadPixels;
95 renderer->RenderWritePixels = SDL_DUMMY_RenderWritePixels;
96 renderer->RenderPresent = SDL_DUMMY_RenderPresent; 87 renderer->RenderPresent = SDL_DUMMY_RenderPresent;
97 renderer->DestroyRenderer = SDL_DUMMY_DestroyRenderer; 88 renderer->DestroyRenderer = SDL_DUMMY_DestroyRenderer;
98 renderer->info = SDL_DUMMY_RenderDriver.info; 89 renderer->info = SDL_DUMMY_RenderDriver.info;
99 renderer->window = window->id; 90 renderer->window = window->id;
100 renderer->driverdata = data; 91 renderer->driverdata = data;
107 return NULL; 98 return NULL;
108 } 99 }
109 SDL_SetSurfacePalette(data->surface, display->palette); 100 SDL_SetSurfacePalette(data->surface, display->palette);
110 101
111 return renderer; 102 return renderer;
112 }
113
114 int
115 SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
116 void *pixels, int pitch)
117 {
118 SDL_DUMMY_RenderData *data =
119 (SDL_DUMMY_RenderData *) renderer->driverdata;
120 SDL_Surface *surface = data->surface;
121 Uint8 *src, *dst;
122 int row;
123 size_t length;
124
125 src =
126 (Uint8 *) surface->pixels + rect->y * surface->pitch +
127 rect->x * surface->format->BytesPerPixel;
128 dst = (Uint8 *) pixels;
129 length = rect->w * surface->format->BytesPerPixel;
130 for (row = 0; row < rect->h; ++row) {
131 SDL_memcpy(dst, src, length);
132 src += surface->pitch;
133 dst += pitch;
134 }
135 return 0;
136 }
137
138 int
139 SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
140 const void *pixels, int pitch)
141 {
142 SDL_DUMMY_RenderData *data =
143 (SDL_DUMMY_RenderData *) renderer->driverdata;
144 SDL_Surface *surface = data->surface;
145 Uint8 *src, *dst;
146 int row;
147 size_t length;
148
149 src = (Uint8 *) pixels;
150 dst =
151 (Uint8 *) surface->pixels + rect->y * surface->pitch +
152 rect->x * surface->format->BytesPerPixel;
153 length = rect->w * surface->format->BytesPerPixel;
154 for (row = 0; row < rect->h; ++row) {
155 SDL_memcpy(dst, src, length);
156 src += pitch;
157 dst += surface->pitch;
158 }
159 return 0;
160 } 103 }
161 104
162 void 105 void
163 SDL_DUMMY_RenderPresent(SDL_Renderer * renderer) 106 SDL_DUMMY_RenderPresent(SDL_Renderer * renderer)
164 { 107 {