Implemented read/write pixels for the X11 renderer
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404307
This commit is contained in:
parent
c2767e72dd
commit
1bd0c772d9
2 changed files with 71 additions and 0 deletions
|
@ -58,6 +58,10 @@ static int X11_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
|
||||||
int count);
|
int count);
|
||||||
static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||||
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
|
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
|
||||||
|
static int X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||||
|
Uint32 format, void * pixels, int pitch);
|
||||||
|
static int X11_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||||
|
Uint32 format, const void * pixels, int pitch);
|
||||||
static void X11_RenderPresent(SDL_Renderer * renderer);
|
static void X11_RenderPresent(SDL_Renderer * renderer);
|
||||||
static void X11_DestroyTexture(SDL_Renderer * renderer,
|
static void X11_DestroyTexture(SDL_Renderer * renderer,
|
||||||
SDL_Texture * texture);
|
SDL_Texture * texture);
|
||||||
|
@ -208,6 +212,8 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||||
renderer->RenderLines = X11_RenderLines;
|
renderer->RenderLines = X11_RenderLines;
|
||||||
renderer->RenderRects = X11_RenderRects;
|
renderer->RenderRects = X11_RenderRects;
|
||||||
renderer->RenderCopy = X11_RenderCopy;
|
renderer->RenderCopy = X11_RenderCopy;
|
||||||
|
renderer->RenderReadPixels = X11_RenderReadPixels;
|
||||||
|
renderer->RenderWritePixels = X11_RenderWritePixels;
|
||||||
renderer->RenderPresent = X11_RenderPresent;
|
renderer->RenderPresent = X11_RenderPresent;
|
||||||
renderer->DestroyTexture = X11_DestroyTexture;
|
renderer->DestroyTexture = X11_DestroyTexture;
|
||||||
renderer->DestroyRenderer = X11_DestroyRenderer;
|
renderer->DestroyRenderer = X11_DestroyRenderer;
|
||||||
|
@ -937,6 +943,70 @@ X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||||
|
Uint32 format, void * pixels, int pitch)
|
||||||
|
{
|
||||||
|
X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
|
||||||
|
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
|
||||||
|
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
|
||||||
|
Uint32 screen_format = display->current_mode.format;
|
||||||
|
XImage *image;
|
||||||
|
|
||||||
|
image = XGetImage(data->display, data->drawable, rect->x, rect->y,
|
||||||
|
rect->w, rect->h, AllPlanes, ZPixmap);
|
||||||
|
|
||||||
|
SDL_ConvertPixels(rect->w, rect->h,
|
||||||
|
screen_format, image->data, image->bytes_per_line,
|
||||||
|
format, pixels, pitch);
|
||||||
|
|
||||||
|
XDestroyImage(image);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
X11_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||||
|
Uint32 format, const void * pixels, int pitch)
|
||||||
|
{
|
||||||
|
X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
|
||||||
|
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
|
||||||
|
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
|
||||||
|
Uint32 screen_format = display->current_mode.format;
|
||||||
|
XImage *image;
|
||||||
|
void *image_pixels;
|
||||||
|
int image_pitch;
|
||||||
|
|
||||||
|
image_pitch = rect->w * SDL_BYTESPERPIXEL(screen_format);
|
||||||
|
image_pixels = SDL_malloc(rect->h * image_pitch);
|
||||||
|
if (!image_pixels) {
|
||||||
|
SDL_OutOfMemory();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
image = XCreateImage(data->display, data->visual,
|
||||||
|
data->depth, ZPixmap, 0, image_pixels,
|
||||||
|
rect->w, rect->h,
|
||||||
|
SDL_BYTESPERPIXEL(screen_format) * 8,
|
||||||
|
image_pitch);
|
||||||
|
if (!image) {
|
||||||
|
SDL_SetError("XCreateImage() failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_ConvertPixels(rect->w, rect->h,
|
||||||
|
format, pixels, pitch,
|
||||||
|
screen_format, image->data, image->bytes_per_line);
|
||||||
|
|
||||||
|
XPutImage(data->display, data->drawable, data->gc,
|
||||||
|
image, 0, 0, rect->x, rect->y, rect->w, rect->h);
|
||||||
|
|
||||||
|
image->data = NULL;
|
||||||
|
XDestroyImage(image);
|
||||||
|
|
||||||
|
SDL_free(image_pixels);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
X11_RenderPresent(SDL_Renderer * renderer)
|
X11_RenderPresent(SDL_Renderer * renderer)
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,6 +63,7 @@ SDL_X11_SYM(int,XFreeGC,(Display* a,GC b),(a,b),return)
|
||||||
SDL_X11_SYM(int,XFreeModifiermap,(XModifierKeymap* a),(a),return)
|
SDL_X11_SYM(int,XFreeModifiermap,(XModifierKeymap* a),(a),return)
|
||||||
SDL_X11_SYM(int,XFreePixmap,(Display* a,Pixmap b),(a,b),return)
|
SDL_X11_SYM(int,XFreePixmap,(Display* a,Pixmap b),(a,b),return)
|
||||||
SDL_X11_SYM(int,XGetErrorDatabaseText,(Display* a,_Xconst char* b,_Xconst char* c,_Xconst char* d,char* e,int f),(a,b,c,d,e,f),return)
|
SDL_X11_SYM(int,XGetErrorDatabaseText,(Display* a,_Xconst char* b,_Xconst char* c,_Xconst char* d,char* e,int f),(a,b,c,d,e,f),return)
|
||||||
|
SDL_X11_SYM(XImage*,XGetImage,(Display* a,Drawable b,int c,int d,unsigned int e,unsigned int f,unsigned long g, int h),(a,b,c,d,e,f,g,h),return)
|
||||||
SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display* a),(a),return)
|
SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display* a),(a),return)
|
||||||
SDL_X11_SYM(int,XGetPointerControl,(Display* a,int* b,int* c,int* d),(a,b,c,d),return)
|
SDL_X11_SYM(int,XGetPointerControl,(Display* a,int* b,int* c,int* d),(a,b,c,d),return)
|
||||||
SDL_X11_SYM(int,XGetRGBColormaps,(Display* a,Window b,XStandardColormap **c,int *d,Atom e),(a,b,c,d,e),return)
|
SDL_X11_SYM(int,XGetRGBColormaps,(Display* a,Window b,XStandardColormap **c,int *d,Atom e),(a,b,c,d,e),return)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue