Commit c0545183 authored by Sunny Sachanandani's avatar Sunny Sachanandani

Major changes to drawing. Reverted back to core X11 functions due to regressions.

parent 6a534a40
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include "../SDL_yuv_sw_c.h" #include "../SDL_yuv_sw_c.h"
#include "SDL_surface.h" #include "SDL_surface.h"
//#define EXPT
/* X11 renderer implementation */ /* X11 renderer implementation */
static SDL_Renderer *X11_CreateRenderer(SDL_Window * window, Uint32 flags); static SDL_Renderer *X11_CreateRenderer(SDL_Window * window, Uint32 flags);
...@@ -102,9 +104,11 @@ typedef struct ...@@ -102,9 +104,11 @@ typedef struct
Pixmap brush; Pixmap brush;
Picture brush_pict; Picture brush_pict;
#ifndef NO_SHARED_MEMORY #ifndef NO_SHARED_MEMORY
#ifdef EXPT
XImage *stencil_image; XImage *stencil_image;
SDL_Surface *stencil_surface; SDL_Surface *stencil_surface;
XShmSegmentInfo stencil_shminfo; XShmSegmentInfo stencil_shminfo;
#endif
#endif #endif
Picture xwindow_pict; Picture xwindow_pict;
Picture pixmap_picts[3]; Picture pixmap_picts[3];
...@@ -135,7 +139,6 @@ typedef struct ...@@ -135,7 +139,6 @@ typedef struct
Picture picture; Picture picture;
XRenderPictFormat* picture_fmt; XRenderPictFormat* picture_fmt;
int blend_op; int blend_op;
// SDL_bool use_xrender;
#endif #endif
XImage *image; XImage *image;
#ifndef NO_SHARED_MEMORY #ifndef NO_SHARED_MEMORY
...@@ -318,6 +321,7 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -318,6 +321,7 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags)
PictStandardARGB32), PictStandardARGB32),
CPRepeat, &brush_attr); CPRepeat, &brush_attr);
#ifndef NO_SHARED_MEMORY #ifndef NO_SHARED_MEMORY
#ifdef EXPT
/* Create a mask image using MIT-SHM */ /* Create a mask image using MIT-SHM */
data->stencil_image = NULL; data->stencil_image = NULL;
data->stencil_surface = NULL; data->stencil_surface = NULL;
...@@ -326,22 +330,10 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -326,22 +330,10 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags)
data->stencil_image = data->stencil_image =
XShmCreateImage(data->display, data->visual, 8, ZPixmap, XShmCreateImage(data->display, data->visual, 8, ZPixmap,
NULL, shminfo, window->w, window->h); NULL, shminfo, window->w, window->h);
if (!data->stencil_image) {
printf("XShmCreateImage() failed");
break;
} else {
printf("image created\n");
}
shminfo->shmid = shmget(IPC_PRIVATE, shminfo->shmid = shmget(IPC_PRIVATE,
data->stencil_image->bytes_per_line * data->stencil_image->bytes_per_line *
data->stencil_image->height, data->stencil_image->height,
IPC_CREAT|0777); IPC_CREAT|0777);
if (!shminfo->shmid) {
printf("shmget() failed");
break;
} else {
printf("shmid aquired\n");
}
shminfo->shmaddr = data->stencil_image->data = shmat(shminfo->shmid, 0, 0); shminfo->shmaddr = data->stencil_image->data = shmat(shminfo->shmid, 0, 0);
shminfo->readOnly = False; shminfo->readOnly = False;
XShmAttach(data->display, shminfo); XShmAttach(data->display, shminfo);
...@@ -354,14 +346,9 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -354,14 +346,9 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags)
8, 8,
data->stencil_image->bytes_per_line, data->stencil_image->bytes_per_line,
0, 0, 0, 0xFF); 0, 0, 0, 0xFF);
if (!data->stencil_surface) {
printf("SDL_CreateRGBSurfaceFrom() failed");
break;
} else {
printf("surface created\n");
}
break; break;
} }
#endif
#endif #endif
// Set the default blending mode. // Set the default blending mode.
renderer->blendMode = SDL_BLENDMODE_BLEND; renderer->blendMode = SDL_BLENDMODE_BLEND;
...@@ -461,7 +448,7 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -461,7 +448,7 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags)
/* Create the drawing context */ /* Create the drawing context */
gcv.graphics_exposures = False; gcv.graphics_exposures = False;
data->gc = data->gc =
XCreateGC(data->display, data->xwindow, GCGraphicsExposures, &gcv); XCreateGC(data->display, data->drawable, GCGraphicsExposures, &gcv);
if (!data->gc) { if (!data->gc) {
X11_DestroyRenderer(renderer); X11_DestroyRenderer(renderer);
SDL_SetError("XCreateGC() failed"); SDL_SetError("XCreateGC() failed");
...@@ -1059,35 +1046,40 @@ X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, ...@@ -1059,35 +1046,40 @@ X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
clip.y = 0; clip.y = 0;
clip.w = window->w; clip.w = window->w;
clip.h = window->h; clip.h = window->h;
if (data->makedirty) {
/* Get the smallest rectangle that contains everything */
rect.x = 0;
rect.y = 0;
rect.w = window->w;
rect.h = window->h;
if (!SDL_EnclosePoints(points, count, &rect, &rect)) {
/* Nothing to draw */
return 0;
}
SDL_AddDirtyRect(&data->dirty, &rect);
}
/*
#ifdef SDL_VIDEO_DRIVER_X11_XRENDER #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
#ifndef NO_SHARED_MEMORY #ifndef NO_SHARED_MEMORY
#ifdef EXPT
if (data->use_xrender && data->stencil_image && data->stencil_surface) { if (data->use_xrender && data->stencil_image && data->stencil_surface) {
SDL_FillRect(data->stencil_surface, NULL, 0x00); SDL_FillRect(data->stencil_surface, &rect, 0x00);
SDL_SetClipRect(data->stencil_surface, NULL); SDL_SetClipRect(data->stencil_surface, NULL);
SDL_DrawPoints(data->stencil_surface, points, count, 0xFF); SDL_DrawPoints(data->stencil_surface, points, count, 0xFF);
XShmPutImage(data->display, data->stencil, data->stencil_gc, data->stencil_image, XShmPutImage(data->display, data->stencil, data->stencil_gc, data->stencil_image,
0, 0, 0, 0, window->w, window->h, False); rect.x, rect.y, rect.x, rect.y, rect.w, rect.h, False);
XSync(data->display, False);
} else } else
#endif #endif
#endif #endif
#endif
*/
{ {
if (data->makedirty) {
/* Get the smallest rectangle that contains everything */
rect.x = 0;
rect.y = 0;
rect.w = window->w;
rect.h = window->h;
if (!SDL_EnclosePoints(points, count, &rect, &rect)) {
/* Nothing to draw */
return 0;
}
SDL_AddDirtyRect(&data->dirty, &rect);
}
xpoint = xpoints = SDL_stack_alloc(XPoint, count); xpoint = xpoints = SDL_stack_alloc(XPoint, count);
xcount = 0; xcount = 0;
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
...@@ -1101,17 +1093,19 @@ X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, ...@@ -1101,17 +1093,19 @@ X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
++xpoint; ++xpoint;
++xcount; ++xcount;
} }
/*
#ifdef SDL_VIDEO_DRIVER_X11_XRENDER #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
if (data->use_xrender) { if (data->use_xrender) {
XSetForeground(data->display, data->stencil_gc, 0x00); XSetForeground(data->display, data->stencil_gc, 0x00);
XFillRectangle(data->display, data->stencil, data->stencil_gc, XFillRectangle(data->display, data->stencil, data->stencil_gc,
0, 0, window->w, window->h); rect.x, rect.y, rect.w, rect.h);
XSetForeground(data->display, data->stencil_gc, 0xFF); XSetForeground(data->display, data->stencil_gc, 0xFF);
XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount, XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount,
CoordModeOrigin); CoordModeOrigin);
} }
#endif #endif*/
} }
/*
#ifdef SDL_VIDEO_DRIVER_X11_XRENDER #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
if (data->use_xrender) { if (data->use_xrender) {
XRenderColor foreground; XRenderColor foreground;
...@@ -1120,10 +1114,11 @@ X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, ...@@ -1120,10 +1114,11 @@ X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
&foreground, 0, 0, 1, 1); &foreground, 0, 0, 1, 1);
XRenderComposite(data->display, data->blend_op, data->brush_pict, XRenderComposite(data->display, data->blend_op, data->brush_pict,
data->stencil_pict, data->drawable_pict, data->stencil_pict, data->drawable_pict,
0, 0, 0, 0, 0, 0, window->w, window->h); rect.x, rect.y, rect.x, rect.y, rect.x, rect.y, rect.w, rect.h);
} }
else else
#endif #endif
*/
{ {
unsigned long foreground = renderdrawcolor(renderer, 1); unsigned long foreground = renderdrawcolor(renderer, 1);
XSetForeground(data->display, data->gc, foreground); XSetForeground(data->display, data->gc, foreground);
...@@ -1157,22 +1152,30 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, ...@@ -1157,22 +1152,30 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
clip.y = 0; clip.y = 0;
clip.w = window->w; clip.w = window->w;
clip.h = window->h; clip.h = window->h;
/*
#ifdef SDL_VIDEO_DRIVER_X11_XRENDER #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
#ifndef NO_SHARED_MEMORY #ifndef NO_SHARED_MEMORY
#ifdef EXPT
if (data->use_xrender && data->stencil_image && data->stencil_surface) { if (data->use_xrender && data->stencil_image && data->stencil_surface) {
SDL_FillRect(data->stencil_surface, NULL, 0x00); SDL_FillRect(data->stencil_surface, NULL, 0x00);
SDL_SetClipRect(data->stencil_surface, NULL);
SDL_DrawLines(data->stencil_surface, points, count, 0xFF); SDL_DrawLines(data->stencil_surface, points, count, 0xFF);
SDL_SetClipRect(data->stencil_surface, NULL);
XShmPutImage(data->display, data->stencil, data->stencil_gc, data->stencil_image, XShmPutImage(data->display, data->stencil, data->stencil_gc, data->stencil_image,
0, 0, 0, 0, window->w, window->h, False); 0, 0, 0, 0, window->w, window->h, False);
XSync(data->display, False);
} else } else
#endif #endif
#endif #endif
#endif
*/
{ {
Pixmap drawable; Pixmap drawable;
GC gc; GC gc;
/*
#ifdef SDL_VIDEO_DRIVER_X11_XRENDER #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
if (data->use_xrender) { if (data->use_xrender) {
drawable = data->stencil; drawable = data->stencil;
...@@ -1184,6 +1187,7 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, ...@@ -1184,6 +1187,7 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
} }
else else
#endif #endif
*/
{ {
drawable = data->drawable; drawable = data->drawable;
gc = data->gc; gc = data->gc;
...@@ -1306,6 +1310,7 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, ...@@ -1306,6 +1310,7 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
} }
} }
} }
/*
#ifdef SDL_VIDEO_DRIVER_X11_XRENDER #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
if (data->use_xrender) { if (data->use_xrender) {
XRenderColor xrforeground = xrenderdrawcolor(renderer); XRenderColor xrforeground = xrenderdrawcolor(renderer);
...@@ -1316,6 +1321,7 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, ...@@ -1316,6 +1321,7 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
0, 0, 0, 0, 0, 0, window->w, window->h); 0, 0, 0, 0, 0, 0, window->w, window->h);
} }
#endif #endif
*/
SDL_stack_free(xpoints); SDL_stack_free(xpoints);
return 0; return 0;
...@@ -1336,21 +1342,27 @@ X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) ...@@ -1336,21 +1342,27 @@ X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
clip.y = 0; clip.y = 0;
clip.w = window->w; clip.w = window->w;
clip.h = window->h; clip.h = window->h;
/*
#ifdef SDL_VIDEO_DRIVER_X11_XRENDER #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
#ifndef NO_SHARED_MEMORY #ifndef NO_SHARED_MEMORY
#ifdef EXPT
if (data->use_xrender && data->stencil_image && data->stencil_surface) { if (data->use_xrender && data->stencil_image && data->stencil_surface) {
SDL_FillRect(data->stencil_surface, NULL, 0x00); SDL_FillRect(data->stencil_surface, NULL, 0x00);
SDL_SetClipRect(data->stencil_surface, NULL); SDL_SetClipRect(data->stencil_surface, NULL);
SDL_DrawRects(data->stencil_surface, rects, count, 1); SDL_DrawRects(data->stencil_surface, rects, count, 1);
XShmPutImage(data->display, data->stencil, data->stencil_gc, data->stencil_image, XShmPutImage(data->display, data->stencil, data->stencil_gc, data->stencil_image,
0, 0, 0, 0, window->w, window->h, False); 0, 0, 0, 0, window->w, window->h, False);
XSync(data->display, False);
} }
else else
#endif #endif
#endif #endif
#endif
*/
{ {
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
...@@ -1369,6 +1381,7 @@ X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) ...@@ -1369,6 +1381,7 @@ X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
SDL_AddDirtyRect(&data->dirty, &rect); SDL_AddDirtyRect(&data->dirty, &rect);
} }
} }
/*
#ifdef SDL_VIDEO_DRIVER_X11_XRENDER #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
if (data->use_xrender) { if (data->use_xrender) {
XSetForeground(data->display, data->stencil_gc, 0x00); XSetForeground(data->display, data->stencil_gc, 0x00);
...@@ -1379,7 +1392,9 @@ X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) ...@@ -1379,7 +1392,9 @@ X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
XDrawRectangles(data->display, data->stencil, data->stencil_gc, xrects, xcount); XDrawRectangles(data->display, data->stencil, data->stencil_gc, xrects, xcount);
} }
#endif #endif
} */
}
/*
#ifdef SDL_VIDEO_DRIVER_X11_XRENDER #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
if (data->use_xrender) { if (data->use_xrender) {
XRenderColor foreground; XRenderColor foreground;
...@@ -1387,13 +1402,13 @@ X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) ...@@ -1387,13 +1402,13 @@ X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict, XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
&foreground, 0, 0, 1, 1); &foreground, 0, 0, 1, 1);
XRenderComposite(data->display, data->blend_op, data->brush_pict, XRenderComposite(data->display, data->blend_op, data->brush_pict,
data->stencil_pict, data->drawable_pict, data->stencil_pict, data->drawable_pict,
0, 0, 0, 0, 0, 0, window->w, window->h); 0, 0, 0, 0, 0, 0, window->w, window->h);
} }
else else
#endif #endif
*/
{ {
unsigned long foreground; unsigned long foreground;
...@@ -1447,8 +1462,15 @@ X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) ...@@ -1447,8 +1462,15 @@ X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
if (data->use_xrender) { if (data->use_xrender) {
XRenderColor foreground; XRenderColor foreground;
foreground = xrenderdrawcolor(renderer); foreground = xrenderdrawcolor(renderer);
XRenderFillRectangles(data->display, data->blend_op, data->drawable_pict, if (xcount == 1) {
&foreground, xrects, xcount); XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict,
&foreground, xrects[0].x, xrects[0].y,
xrects[0].width, xrects[0].height);
}
else if (xcount > 1) {
XRenderFillRectangles(data->display, data->blend_op, data->drawable_pict,
&foreground, xrects, xcount);
}
} }
else else
#endif #endif
...@@ -1705,7 +1727,7 @@ X11_RenderPresent(SDL_Renderer * renderer) ...@@ -1705,7 +1727,7 @@ X11_RenderPresent(SDL_Renderer * renderer)
for (dirty = data->dirty.list; dirty; dirty = dirty->next) { for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
const SDL_Rect *rect = &dirty->rect; const SDL_Rect *rect = &dirty->rect;
#ifdef SDL_VIDEO_DRIVER_X11_XRENDER #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
if(data->use_xrender == SDL_TRUE) if (data->use_xrender)
{ {
XRenderComposite(data->display, XRenderComposite(data->display,
data->blend_op, data->blend_op,
...@@ -1726,7 +1748,7 @@ X11_RenderPresent(SDL_Renderer * renderer) ...@@ -1726,7 +1748,7 @@ X11_RenderPresent(SDL_Renderer * renderer)
} }
} }
SDL_ClearDirtyRects(&data->dirty); SDL_ClearDirtyRects(&data->dirty);
} }
XSync(data->display, False); XSync(data->display, False);
/* Update the flipping chain, if any */ /* Update the flipping chain, if any */
......
...@@ -144,8 +144,8 @@ MoveSprites(SDL_Window * window, SDL_Texture * sprite) ...@@ -144,8 +144,8 @@ MoveSprites(SDL_Window * window, SDL_Texture * sprite)
/* Test points */ /* Test points */
SDL_SetRenderDrawColor(0xFF, 0x00, 0x00, 0xFF); SDL_SetRenderDrawColor(0xFF, 0x00, 0x00, 0xFF);
SDL_RenderDrawPoint(0, 0); SDL_RenderDrawPoint(0, 0);
SDL_RenderDrawPoint(window_w-1, 0); SDL_RenderDrawPoint(window_w/2-1, window_h/2-1);
SDL_RenderDrawPoint(0, window_h-1); SDL_RenderDrawPoint(window_w/2-1, window_h/2-1);
SDL_RenderDrawPoint(window_w-1, window_h-1); SDL_RenderDrawPoint(window_w-1, window_h-1);
/* Test horizontal and vertical lines */ /* Test horizontal and vertical lines */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment