comparison src/video/win32/SDL_gdirender.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 69217fdd2c0a
comparison
equal deleted inserted replaced
1919:00816063b9c9 1920:8a162bfdc838
140 GDI_RenderData *data; 140 GDI_RenderData *data;
141 int bmi_size; 141 int bmi_size;
142 HBITMAP hbm; 142 HBITMAP hbm;
143 int i, n; 143 int i, n;
144 144
145 renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer)); 145 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
146 if (!renderer) { 146 if (!renderer) {
147 SDL_OutOfMemory(); 147 SDL_OutOfMemory();
148 return NULL; 148 return NULL;
149 } 149 }
150 SDL_zerop(renderer); 150
151 151 data = (GDI_RenderData *) SDL_calloc(1, sizeof(*data));
152 data = (GDI_RenderData *) SDL_malloc(sizeof(*data));
153 if (!data) { 152 if (!data) {
154 GDI_DestroyRenderer(renderer); 153 GDI_DestroyRenderer(renderer);
155 SDL_OutOfMemory(); 154 SDL_OutOfMemory();
156 return NULL; 155 return NULL;
157 } 156 }
158 SDL_zerop(data);
159 157
160 renderer->CreateTexture = GDI_CreateTexture; 158 renderer->CreateTexture = GDI_CreateTexture;
161 renderer->QueryTexturePixels = GDI_QueryTexturePixels; 159 renderer->QueryTexturePixels = GDI_QueryTexturePixels;
162 renderer->SetTexturePalette = GDI_SetTexturePalette; 160 renderer->SetTexturePalette = GDI_SetTexturePalette;
163 renderer->GetTexturePalette = GDI_GetTexturePalette; 161 renderer->GetTexturePalette = GDI_GetTexturePalette;
181 data->render_hdc = CreateCompatibleDC(data->window_hdc); 179 data->render_hdc = CreateCompatibleDC(data->window_hdc);
182 data->memory_hdc = CreateCompatibleDC(data->window_hdc); 180 data->memory_hdc = CreateCompatibleDC(data->window_hdc);
183 181
184 /* Fill in the compatible bitmap info */ 182 /* Fill in the compatible bitmap info */
185 bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD); 183 bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
186 data->bmi = (LPBITMAPINFO) SDL_malloc(bmi_size); 184 data->bmi = (LPBITMAPINFO) SDL_calloc(1, bmi_size);
187 if (!data->bmi) { 185 if (!data->bmi) {
188 GDI_DestroyRenderer(renderer); 186 GDI_DestroyRenderer(renderer);
189 SDL_OutOfMemory(); 187 SDL_OutOfMemory();
190 return NULL; 188 return NULL;
191 } 189 }
192 SDL_memset(data->bmi, 0, bmi_size);
193 data->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 190 data->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
194 191
195 hbm = CreateCompatibleBitmap(data->window_hdc, 1, 1); 192 hbm = CreateCompatibleBitmap(data->window_hdc, 1, 1);
196 GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS); 193 GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
197 GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS); 194 GetDIBits(data->window_hdc, hbm, 0, 1, NULL, data->bmi, DIB_RGB_COLORS);
239 GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata; 236 GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata;
240 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 237 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
241 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 238 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
242 GDI_TextureData *data; 239 GDI_TextureData *data;
243 240
244 data = (GDI_TextureData *) SDL_malloc(sizeof(*data)); 241 data = (GDI_TextureData *) SDL_calloc(1, sizeof(*data));
245 if (!data) { 242 if (!data) {
246 SDL_OutOfMemory(); 243 SDL_OutOfMemory();
247 return -1; 244 return -1;
248 } 245 }
249 SDL_zerop(data);
250 246
251 texture->driverdata = data; 247 texture->driverdata = data;
252 248
253 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 249 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
254 data->yuv = SDL_SW_CreateYUVTexture(texture); 250 data->yuv = SDL_SW_CreateYUVTexture(texture);
266 || texture->format != SDL_GetCurrentDisplayMode()->format) { 262 || texture->format != SDL_GetCurrentDisplayMode()->format) {
267 int bmi_size; 263 int bmi_size;
268 LPBITMAPINFO bmi; 264 LPBITMAPINFO bmi;
269 265
270 bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD); 266 bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
271 bmi = (LPBITMAPINFO) SDL_malloc(bmi_size); 267 bmi = (LPBITMAPINFO) SDL_calloc(1, bmi_size);
272 if (!bmi) { 268 if (!bmi) {
273 GDI_DestroyTexture(renderer, texture); 269 GDI_DestroyTexture(renderer, texture);
274 SDL_OutOfMemory(); 270 SDL_OutOfMemory();
275 return -1; 271 return -1;
276 } 272 }
277 SDL_memset(bmi, 0, bmi_size);
278 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 273 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
279 bmi->bmiHeader.biWidth = texture->w; 274 bmi->bmiHeader.biWidth = texture->w;
280 bmi->bmiHeader.biHeight = -texture->h; /* topdown bitmap */ 275 bmi->bmiHeader.biHeight = -texture->h; /* topdown bitmap */
281 bmi->bmiHeader.biPlanes = 1; 276 bmi->bmiHeader.biPlanes = 1;
282 bmi->bmiHeader.biSizeImage = texture->h * data->pitch; 277 bmi->bmiHeader.biSizeImage = texture->h * data->pitch;