Commit 84a58d8f authored by Sunny Sachanandani's avatar Sunny Sachanandani

Use XDamage to optimise drawing operations.

parent e3cf0eb0
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
#include "../SDL_pixels_c.h" #include "../SDL_pixels_c.h"
#include "../SDL_yuv_sw_c.h" #include "../SDL_yuv_sw_c.h"
#include <X11/extensions/Xdamage.h>
#include <X11/extensions/Xfixes.h>
/* 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);
...@@ -108,6 +111,8 @@ typedef struct ...@@ -108,6 +111,8 @@ typedef struct
XRenderPictFormat* xwindow_pict_fmt; XRenderPictFormat* xwindow_pict_fmt;
GC stencil_gc; GC stencil_gc;
SDL_bool use_xrender; SDL_bool use_xrender;
Damage stencil_damage;
XserverRegion stencil_parts;
#endif #endif
int current_pixmap; int current_pixmap;
Drawable drawable; Drawable drawable;
...@@ -295,12 +300,18 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -295,12 +300,18 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags)
data->stencil_gc = XCreateGC(data->display, data->stencil, data->stencil_gc = XCreateGC(data->display, data->stencil,
GCGraphicsExposures, &gcv); GCGraphicsExposures, &gcv);
XSetBackground(data->display, data->stencil_gc, 0x00); XSetBackground(data->display, data->stencil_gc, 0x00);
XSetForeground(data->display, data->stencil_gc, 0x00);
XFillRectangle(data->display, data->stencil, data->stencil_gc,
0, 0, window->w, window->h);
XSetForeground(data->display, data->stencil_gc, 0xFF); XSetForeground(data->display, data->stencil_gc, 0xFF);
data->stencil_pict = data->stencil_pict =
XRenderCreatePicture(data->display, data->stencil, XRenderCreatePicture(data->display, data->stencil,
XRenderFindStandardFormat(data->display, XRenderFindStandardFormat(data->display,
PictStandardA8), PictStandardA8),
0, NULL); 0, NULL);
data->stencil_damage =
XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty);
XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
data->brush = data->brush =
XCreatePixmap(data->display, data->xwindow, 1, 1, 32); XCreatePixmap(data->display, data->xwindow, 1, 1, 32);
XRenderPictureAttributes brush_attr; XRenderPictureAttributes brush_attr;
...@@ -1001,6 +1012,8 @@ X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, ...@@ -1001,6 +1012,8 @@ X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
XPoint *xpoints, *xpoint; XPoint *xpoints, *xpoint;
int i, xcount; int i, xcount;
SDL_Rect clip, rect; SDL_Rect clip, rect;
/*Damage damage;
XserverRegion parts;*/
clip.x = 0; clip.x = 0;
clip.y = 0; clip.y = 0;
...@@ -1033,32 +1046,39 @@ X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, ...@@ -1033,32 +1046,39 @@ 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);
XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, data->stencil_parts);
XFillRectangle(data->display, data->stencil, data->stencil_gc, XFillRectangle(data->display, data->stencil, data->stencil_gc,
rect.x, rect.y, rect.w, rect.h); rect.x, rect.y, rect.w, rect.h);
XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, None);
XSetForeground(data->display, data->stencil_gc, 0xFF); XSetForeground(data->display, data->stencil_gc, 0xFF);
/*damage =
XDamageCreate(data->display, data->stencil, XDamageReportRawRectangles);*/
XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount, XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount,
CoordModeOrigin); CoordModeOrigin);
XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
} }
#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;
foreground = xrenderdrawcolor(renderer); foreground = xrenderdrawcolor(renderer);
XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict, XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
&foreground, 0, 0, 1, 1); &foreground, 0, 0, 1, 1);
XFixesSetPictureClipRegion(data->display, data->drawable_pict, 0, 0, data->stencil_parts);
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,
rect.x, rect.y, rect.x, rect.y, rect.x, rect.y, rect.w, rect.h); rect.x, rect.y, rect.x, rect.y, rect.x, rect.y, rect.w, rect.h);
XFixesSetPictureClipRegion(data->display, data->drawable_pict, 0, 0, None);
//XDamageDestroy(data->display, damage);
} }
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);
...@@ -1087,6 +1107,8 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, ...@@ -1087,6 +1107,8 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
int i, xcount; int i, xcount;
int minx, miny; int minx, miny;
int maxx, maxy; int maxx, maxy;
XserverRegion parts;
Damage damage;
clip.x = 0; clip.x = 0;
clip.y = 0; clip.y = 0;
...@@ -1095,19 +1117,21 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, ...@@ -1095,19 +1117,21 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
{ {
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;
gc = data->stencil_gc; gc = data->stencil_gc;
XSetForeground(data->display, data->stencil_gc, 0x00); XSetForeground(data->display, data->stencil_gc, 0x00);
XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, data->stencil_parts);
XFillRectangle(data->display, data->stencil, data->stencil_gc, XFillRectangle(data->display, data->stencil, data->stencil_gc,
0, 0, window->w, window->h); 0, 0, window->w, window->h);
XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, None);
XSetForeground(data->display, data->stencil_gc, 0xFF); XSetForeground(data->display, data->stencil_gc, 0xFF);
/*damage =
XDamageCreate(data->display, data->stencil, XDamageReportRawRectangles);*/
} }
else else
#endif #endif
*/
{ {
drawable = data->drawable; drawable = data->drawable;
gc = data->gc; gc = data->gc;
...@@ -1230,18 +1254,20 @@ X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, ...@@ -1230,18 +1254,20 @@ 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);
XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict, XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
&xrforeground, 0, 0, 1, 1); &xrforeground, 0, 0, 1, 1);
XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
XFixesSetPictureClipRegion(data->display, data->drawable_pict, 0, 0, data->stencil_parts);
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);
XFixesSetPictureClipRegion(data->display, data->drawable_pict, 0, 0, None);
//XDamageDestroy(data->display, damage);
} }
#endif #endif
*/
SDL_stack_free(xpoints); SDL_stack_free(xpoints);
return 0; return 0;
......
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