comparison src/video/x11/SDL_x11render.c @ 3685:64ce267332c6

Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 21 Jan 2010 06:21:52 +0000
parents f638ded38b8a
children f7b03b6838cb
comparison
equal deleted inserted replaced
3684:cc564f08884f 3685:64ce267332c6
91 Display *display; 91 Display *display;
92 int screen; 92 int screen;
93 Visual *visual; 93 Visual *visual;
94 int depth; 94 int depth;
95 int scanline_pad; 95 int scanline_pad;
96 Window window; 96 Window xwindow;
97 Pixmap pixmaps[3]; 97 Pixmap pixmaps[3];
98 int current_pixmap; 98 int current_pixmap;
99 Drawable drawable; 99 Drawable drawable;
100 SDL_PixelFormat format; 100 SDL_PixelFormat format;
101 GC gc; 101 GC gc;
151 void 151 void
152 X11_AddRenderDriver(_THIS) 152 X11_AddRenderDriver(_THIS)
153 { 153 {
154 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 154 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
155 SDL_RendererInfo *info = &X11_RenderDriver.info; 155 SDL_RendererInfo *info = &X11_RenderDriver.info;
156 SDL_DisplayMode *mode = &SDL_CurrentDisplay.desktop_mode; 156 SDL_DisplayMode *mode = &SDL_CurrentDisplay->desktop_mode;
157 int i; 157 int i;
158 158
159 info->texture_formats[info->num_texture_formats++] = mode->format; 159 info->texture_formats[info->num_texture_formats++] = mode->format;
160 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YV12; 160 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YV12;
161 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_IYUV; 161 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_IYUV;
169 } 169 }
170 170
171 SDL_Renderer * 171 SDL_Renderer *
172 X11_CreateRenderer(SDL_Window * window, Uint32 flags) 172 X11_CreateRenderer(SDL_Window * window, Uint32 flags)
173 { 173 {
174 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 174 SDL_VideoDisplay *display = window->display;
175 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; 175 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
176 SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata; 176 SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
177 SDL_Renderer *renderer; 177 SDL_Renderer *renderer;
178 SDL_RendererInfo *info; 178 SDL_RendererInfo *info;
179 X11_RenderData *data; 179 X11_RenderData *data;
197 data->display = windowdata->videodata->display; 197 data->display = windowdata->videodata->display;
198 data->screen = displaydata->screen; 198 data->screen = displaydata->screen;
199 data->visual = displaydata->visual; 199 data->visual = displaydata->visual;
200 data->depth = displaydata->depth; 200 data->depth = displaydata->depth;
201 data->scanline_pad = displaydata->scanline_pad; 201 data->scanline_pad = displaydata->scanline_pad;
202 data->window = windowdata->window; 202 data->xwindow = windowdata->xwindow;
203 203
204 renderer->DisplayModeChanged = X11_DisplayModeChanged; 204 renderer->DisplayModeChanged = X11_DisplayModeChanged;
205 renderer->CreateTexture = X11_CreateTexture; 205 renderer->CreateTexture = X11_CreateTexture;
206 renderer->QueryTexturePixels = X11_QueryTexturePixels; 206 renderer->QueryTexturePixels = X11_QueryTexturePixels;
207 renderer->SetTextureBlendMode = X11_SetTextureBlendMode; 207 renderer->SetTextureBlendMode = X11_SetTextureBlendMode;
219 renderer->RenderWritePixels = X11_RenderWritePixels; 219 renderer->RenderWritePixels = X11_RenderWritePixels;
220 renderer->RenderPresent = X11_RenderPresent; 220 renderer->RenderPresent = X11_RenderPresent;
221 renderer->DestroyTexture = X11_DestroyTexture; 221 renderer->DestroyTexture = X11_DestroyTexture;
222 renderer->DestroyRenderer = X11_DestroyRenderer; 222 renderer->DestroyRenderer = X11_DestroyRenderer;
223 renderer->info = X11_RenderDriver.info; 223 renderer->info = X11_RenderDriver.info;
224 renderer->window = window->id; 224 renderer->window = window;
225 renderer->driverdata = data; 225 renderer->driverdata = data;
226 226
227 renderer->info.flags = SDL_RENDERER_ACCELERATED; 227 renderer->info.flags = SDL_RENDERER_ACCELERATED;
228 228
229 if (flags & SDL_RENDERER_SINGLEBUFFER) { 229 if (flags & SDL_RENDERER_SINGLEBUFFER) {
240 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY; 240 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
241 n = 1; 241 n = 1;
242 } 242 }
243 for (i = 0; i < n; ++i) { 243 for (i = 0; i < n; ++i) {
244 data->pixmaps[i] = 244 data->pixmaps[i] =
245 XCreatePixmap(data->display, data->window, window->w, window->h, 245 XCreatePixmap(data->display, data->xwindow, window->w, window->h,
246 displaydata->depth); 246 displaydata->depth);
247 if (data->pixmaps[i] == None) { 247 if (data->pixmaps[i] == None) {
248 X11_DestroyRenderer(renderer); 248 X11_DestroyRenderer(renderer);
249 SDL_SetError("XCreatePixmap() failed"); 249 SDL_SetError("XCreatePixmap() failed");
250 return NULL; 250 return NULL;
252 } 252 }
253 if (n > 0) { 253 if (n > 0) {
254 data->drawable = data->pixmaps[0]; 254 data->drawable = data->pixmaps[0];
255 data->makedirty = SDL_TRUE; 255 data->makedirty = SDL_TRUE;
256 } else { 256 } else {
257 data->drawable = data->window; 257 data->drawable = data->xwindow;
258 data->makedirty = SDL_FALSE; 258 data->makedirty = SDL_FALSE;
259 } 259 }
260 data->current_pixmap = 0; 260 data->current_pixmap = 0;
261 261
262 /* Get the format of the window */ 262 /* Get the format of the window */
270 SDL_InitFormat(&data->format, bpp, Rmask, Gmask, Bmask, Amask); 270 SDL_InitFormat(&data->format, bpp, Rmask, Gmask, Bmask, Amask);
271 271
272 /* Create the drawing context */ 272 /* Create the drawing context */
273 gcv.graphics_exposures = False; 273 gcv.graphics_exposures = False;
274 data->gc = 274 data->gc =
275 XCreateGC(data->display, data->window, GCGraphicsExposures, &gcv); 275 XCreateGC(data->display, data->xwindow, GCGraphicsExposures, &gcv);
276 if (!data->gc) { 276 if (!data->gc) {
277 X11_DestroyRenderer(renderer); 277 X11_DestroyRenderer(renderer);
278 SDL_SetError("XCreateGC() failed"); 278 SDL_SetError("XCreateGC() failed");
279 return NULL; 279 return NULL;
280 } 280 }
284 284
285 static int 285 static int
286 X11_DisplayModeChanged(SDL_Renderer * renderer) 286 X11_DisplayModeChanged(SDL_Renderer * renderer)
287 { 287 {
288 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; 288 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
289 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 289 SDL_Window *window = renderer->window;
290 int i, n; 290 int i, n;
291 291
292 if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) { 292 if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) {
293 n = 0; 293 n = 0;
294 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) { 294 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
304 data->pixmaps[i] = None; 304 data->pixmaps[i] = None;
305 } 305 }
306 } 306 }
307 for (i = 0; i < n; ++i) { 307 for (i = 0; i < n; ++i) {
308 data->pixmaps[i] = 308 data->pixmaps[i] =
309 XCreatePixmap(data->display, data->window, window->w, window->h, 309 XCreatePixmap(data->display, data->xwindow, window->w, window->h,
310 data->depth); 310 data->depth);
311 if (data->pixmaps[i] == None) { 311 if (data->pixmaps[i] == None) {
312 SDL_SetError("XCreatePixmap() failed"); 312 SDL_SetError("XCreatePixmap() failed");
313 return -1; 313 return -1;
314 } 314 }
323 323
324 static int 324 static int
325 X11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) 325 X11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
326 { 326 {
327 X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata; 327 X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
328 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 328 SDL_Window *window = renderer->window;
329 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 329 SDL_VideoDisplay *display = window->display;
330 X11_TextureData *data; 330 X11_TextureData *data;
331 int pitch_alignmask = ((renderdata->scanline_pad / 8) - 1); 331 int pitch_alignmask = ((renderdata->scanline_pad / 8) - 1);
332 332
333 data = (X11_TextureData *) SDL_calloc(1, sizeof(*data)); 333 data = (X11_TextureData *) SDL_calloc(1, sizeof(*data));
334 if (!data) { 334 if (!data) {
423 return -1; 423 return -1;
424 } 424 }
425 } 425 }
426 } else { 426 } else {
427 data->pixmap = 427 data->pixmap =
428 XCreatePixmap(renderdata->display, renderdata->window, texture->w, 428 XCreatePixmap(renderdata->display, renderdata->xwindow, texture->w,
429 texture->h, renderdata->depth); 429 texture->h, renderdata->depth);
430 if (data->pixmap == None) { 430 if (data->pixmap == None) {
431 X11_DestroyTexture(renderer, texture); 431 X11_DestroyTexture(renderer, texture);
432 SDL_SetError("XCreatePixmap() failed"); 432 SDL_SetError("XCreatePixmap() failed");
433 return -1; 433 return -1;
605 static int 605 static int
606 X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, 606 X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
607 int count) 607 int count)
608 { 608 {
609 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; 609 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
610 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 610 SDL_Window *window = renderer->window;
611 unsigned long foreground; 611 unsigned long foreground;
612 XPoint *xpoints, *xpoint; 612 XPoint *xpoints, *xpoint;
613 int i, xcount; 613 int i, xcount;
614 614
615 if (data->makedirty) { 615 if (data->makedirty) {
655 static int 655 static int
656 X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, 656 X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
657 int count) 657 int count)
658 { 658 {
659 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; 659 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
660 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 660 SDL_Window *window = renderer->window;
661 SDL_Rect clip, rect; 661 SDL_Rect clip, rect;
662 unsigned long foreground; 662 unsigned long foreground;
663 XPoint *xpoints, *xpoint; 663 XPoint *xpoints, *xpoint;
664 int i, xcount; 664 int i, xcount;
665 int minx, miny; 665 int minx, miny;
793 793
794 static int 794 static int
795 X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) 795 X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
796 { 796 {
797 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; 797 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
798 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 798 SDL_Window *window = renderer->window;
799 SDL_Rect clip, rect; 799 SDL_Rect clip, rect;
800 unsigned long foreground; 800 unsigned long foreground;
801 XRectangle *xrects, *xrect; 801 XRectangle *xrects, *xrect;
802 int i, xcount; 802 int i, xcount;
803 803
838 838
839 static int 839 static int
840 X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) 840 X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
841 { 841 {
842 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; 842 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
843 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 843 SDL_Window *window = renderer->window;
844 SDL_Rect clip, rect; 844 SDL_Rect clip, rect;
845 unsigned long foreground; 845 unsigned long foreground;
846 XRectangle *xrects, *xrect; 846 XRectangle *xrects, *xrect;
847 int i, xcount; 847 int i, xcount;
848 848
996 static int 996 static int
997 X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, 997 X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
998 Uint32 format, void * pixels, int pitch) 998 Uint32 format, void * pixels, int pitch)
999 { 999 {
1000 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; 1000 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
1001 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 1001 SDL_Window *window = renderer->window;
1002 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 1002 SDL_VideoDisplay *display = window->display;
1003 Uint32 screen_format = display->current_mode.format; 1003 Uint32 screen_format = display->current_mode.format;
1004 XImage *image; 1004 XImage *image;
1005 1005
1006 image = XGetImage(data->display, data->drawable, rect->x, rect->y, 1006 image = XGetImage(data->display, data->drawable, rect->x, rect->y,
1007 rect->w, rect->h, AllPlanes, ZPixmap); 1007 rect->w, rect->h, AllPlanes, ZPixmap);
1017 static int 1017 static int
1018 X11_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, 1018 X11_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
1019 Uint32 format, const void * pixels, int pitch) 1019 Uint32 format, const void * pixels, int pitch)
1020 { 1020 {
1021 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; 1021 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
1022 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 1022 SDL_Window *window = renderer->window;
1023 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 1023 SDL_VideoDisplay *display = window->display;
1024 Uint32 screen_format = display->current_mode.format; 1024 Uint32 screen_format = display->current_mode.format;
1025 XImage *image; 1025 XImage *image;
1026 void *image_pixels; 1026 void *image_pixels;
1027 int image_pitch; 1027 int image_pitch;
1028 1028
1065 1065
1066 /* Send the data to the display */ 1066 /* Send the data to the display */
1067 if (!(renderer->info.flags & SDL_RENDERER_SINGLEBUFFER)) { 1067 if (!(renderer->info.flags & SDL_RENDERER_SINGLEBUFFER)) {
1068 for (dirty = data->dirty.list; dirty; dirty = dirty->next) { 1068 for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
1069 const SDL_Rect *rect = &dirty->rect; 1069 const SDL_Rect *rect = &dirty->rect;
1070 XCopyArea(data->display, data->drawable, data->window, 1070 XCopyArea(data->display, data->drawable, data->xwindow,
1071 data->gc, rect->x, rect->y, rect->w, rect->h, 1071 data->gc, rect->x, rect->y, rect->w, rect->h,
1072 rect->x, rect->y); 1072 rect->x, rect->y);
1073 } 1073 }
1074 SDL_ClearDirtyRects(&data->dirty); 1074 SDL_ClearDirtyRects(&data->dirty);
1075 } 1075 }