annotate src/video/x11/SDL_x11render.c @ 4576:2b98162b536a

Add Xrender support to X11_FillRectangles.
author Sunny Sachanandani <sunnysachanandani@gmail.com>
date Sun, 30 May 2010 20:06:30 +0530
parents 037ddbeee6c3
children 87a2d87786d4
rev   line source
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #if SDL_VIDEO_RENDER_X11
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
3543
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
26 #include <limits.h> /* For INT_MIN and INT_MAX */
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
27
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include "SDL_x11video.h"
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include "../SDL_rect_c.h"
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include "../SDL_pixels_c.h"
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include "../SDL_yuv_sw_c.h"
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 /* X11 renderer implementation */
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 static SDL_Renderer *X11_CreateRenderer(SDL_Window * window, Uint32 flags);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 static int X11_DisplayModeChanged(SDL_Renderer * renderer);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 static int X11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 static int X11_QueryTexturePixels(SDL_Renderer * renderer,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 SDL_Texture * texture, void **pixels,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 int *pitch);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 static int X11_SetTextureBlendMode(SDL_Renderer * renderer,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 SDL_Texture * texture);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 static int X11_SetTextureScaleMode(SDL_Renderer * renderer,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 SDL_Texture * texture);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 static int X11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 const SDL_Rect * rect, const void *pixels,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 int pitch);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 static int X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 const SDL_Rect * rect, int markDirty,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 void **pixels, int *pitch);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
52 static int X11_SetDrawBlendMode(SDL_Renderer * renderer);
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
53 static int X11_RenderDrawPoints(SDL_Renderer * renderer,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
54 const SDL_Point * points, int count);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
55 static int X11_RenderDrawLines(SDL_Renderer * renderer,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
56 const SDL_Point * points, int count);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
57 static int X11_RenderDrawRects(SDL_Renderer * renderer,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
58 const SDL_Rect ** rects, int count);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
59 static int X11_RenderFillRects(SDL_Renderer * renderer,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
60 const SDL_Rect ** rects, int count);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
3559
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
63 static int X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
64 Uint32 format, void * pixels, int pitch);
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
65 static int X11_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
66 Uint32 format, const void * pixels, int pitch);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 static void X11_RenderPresent(SDL_Renderer * renderer);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 static void X11_DestroyTexture(SDL_Renderer * renderer,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 SDL_Texture * texture);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 static void X11_DestroyRenderer(SDL_Renderer * renderer);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 SDL_RenderDriver X11_RenderDriver = {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 X11_CreateRenderer,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 "x11",
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 SDL_TEXTUREMODULATE_NONE,
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
81 SDL_BLENDMODE_NONE,
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 SDL_TEXTURESCALEMODE_NONE,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 0,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 {0},
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 0,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 0}
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 };
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 typedef struct
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 Display *display;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 int screen;
2870
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
93 Visual *visual;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
94 int depth;
2916
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
95 int scanline_pad;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
96 Window xwindow;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 Pixmap pixmaps[3];
4571
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
98 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
99 Picture xwindow_pict;
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
100 Picture pixmap_picts[3];
4576
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
101 Picture drawable_pict;
4571
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
102 XRenderPictFormat* xwindow_pict_fmt;
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
103 XRenderPictureAttributes xwindow_pict_attr;
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
104 unsigned int xwindow_pict_attr_valuemask;
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
105 SDL_bool xrender_available;
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
106 #endif
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 int current_pixmap;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 Drawable drawable;
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
109 SDL_PixelFormat format;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 GC gc;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 SDL_DirtyRectList dirty;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 SDL_bool makedirty;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 } X11_RenderData;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 typedef struct
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 SDL_SW_YUVTexture *yuv;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 Uint32 format;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 Pixmap pixmap;
4571
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
120 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
121 Picture picture;
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
122 XRenderPictFormat* picture_fmt;
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
123 XRenderPictureAttributes picture_attr;
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
124 unsigned int picture_attr_valuemask;
4573
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
125 SDL_bool xrender_available;
4571
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
126 #endif
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 XImage *image;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 #ifndef NO_SHARED_MEMORY
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 /* MIT shared memory extension information */
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 XShmSegmentInfo shminfo;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 #endif
2828
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
132 XImage *scaling_image;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 void *pixels;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 int pitch;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 } X11_TextureData;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 #ifndef NO_SHARED_MEMORY
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 /* Shared memory error handler routine */
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 static int shm_error;
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
140 static int (*X_handler) (Display *, XErrorEvent *) = NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
141 static int
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
142 shm_errhandler(Display * d, XErrorEvent * e)
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 {
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
144 if (e->error_code == BadAccess) {
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
145 shm_error = True;
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
146 return (0);
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
147 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
148 return (X_handler(d, e));
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
149 }
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 #endif /* ! NO_SHARED_MEMORY */
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 static void
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 UpdateYUVTextureData(SDL_Texture * texture)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 X11_TextureData *data = (X11_TextureData *) texture->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 SDL_Rect rect;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 rect.x = 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 rect.y = 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 rect.w = texture->w;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 rect.h = texture->h;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 texture->h, data->pixels, data->pitch);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 void
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 X11_AddRenderDriver(_THIS)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 SDL_RendererInfo *info = &X11_RenderDriver.info;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
171 SDL_DisplayMode *mode = &SDL_CurrentDisplay->desktop_mode;
3520
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3239
diff changeset
172 int i;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173
2870
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
174 info->texture_formats[info->num_texture_formats++] = mode->format;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
175 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YV12;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
176 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_IYUV;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
177 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YUY2;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
178 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_UYVY;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
179 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YVYU;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180
3520
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3239
diff changeset
181 for (i = 0; i < _this->num_displays; ++i) {
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3239
diff changeset
182 SDL_AddRenderDriver(&_this->displays[i], &X11_RenderDriver);
83518f8fcd61 Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents: 3239
diff changeset
183 }
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 SDL_Renderer *
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 X11_CreateRenderer(SDL_Window * window, Uint32 flags)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 {
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
189 SDL_VideoDisplay *display = window->display;
2870
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
190 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 SDL_Renderer *renderer;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 X11_RenderData *data;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 XGCValues gcv;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 int i, n;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 int bpp;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 Uint32 Rmask, Gmask, Bmask, Amask;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 if (!renderer) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 SDL_OutOfMemory();
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 return NULL;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 data = (X11_RenderData *) SDL_calloc(1, sizeof(*data));
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 if (!data) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 X11_DestroyRenderer(renderer);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 SDL_OutOfMemory();
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 return NULL;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 data->display = windowdata->videodata->display;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 data->screen = displaydata->screen;
2870
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
213 data->visual = displaydata->visual;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
214 data->depth = displaydata->depth;
2916
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
215 data->scanline_pad = displaydata->scanline_pad;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
216 data->xwindow = windowdata->xwindow;
4571
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
217 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
218 int event_basep, error_basep;
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
219 if(XRenderQueryExtension(data->display, &event_basep, &error_basep) == True) {
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
220 data->xrender_available = SDL_TRUE;
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
221 data->xwindow_pict_fmt = XRenderFindVisualFormat(data->display, data->visual);
4573
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
222 if(!xwindow_pict_fmt) {
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
223 data->xrender_available = SDL_FALSE;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
224 }
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
225 data->xwindow_pict_attr.graphics_exposures = False;
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
226 data->xwindow_pict_attr_valuemask = CPGraphicsExposure;
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
227 data->xwindow_pict = XRenderCreatePicture(data->display, data->xwindow, data->xwindow_pict_fmt,
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
228 data->xwindow_pict_attr_valuemask, &data->xwindow_pict_attr);
4573
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
229 if(!data->xwindow_pict) {
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
230 data->xrender_available = SDL_FALSE;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
231 }
4571
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
232 }
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
233 else {
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
234 data->xrender_available = SDL_FALSE;
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
235 }
97dcf6f6213c Added a #define option for compile time Xrender support.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4458
diff changeset
236 #endif
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 renderer->DisplayModeChanged = X11_DisplayModeChanged;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 renderer->CreateTexture = X11_CreateTexture;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 renderer->QueryTexturePixels = X11_QueryTexturePixels;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 renderer->SetTextureBlendMode = X11_SetTextureBlendMode;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 renderer->SetTextureScaleMode = X11_SetTextureScaleMode;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 renderer->UpdateTexture = X11_UpdateTexture;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 renderer->LockTexture = X11_LockTexture;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 renderer->UnlockTexture = X11_UnlockTexture;
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
245 renderer->SetDrawBlendMode = X11_SetDrawBlendMode;
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
246 renderer->RenderDrawPoints = X11_RenderDrawPoints;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
247 renderer->RenderDrawLines = X11_RenderDrawLines;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
248 renderer->RenderDrawRects = X11_RenderDrawRects;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
249 renderer->RenderFillRects = X11_RenderFillRects;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 renderer->RenderCopy = X11_RenderCopy;
3559
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
251 renderer->RenderReadPixels = X11_RenderReadPixels;
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
252 renderer->RenderWritePixels = X11_RenderWritePixels;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 renderer->RenderPresent = X11_RenderPresent;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 renderer->DestroyTexture = X11_DestroyTexture;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 renderer->DestroyRenderer = X11_DestroyRenderer;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 renderer->info = X11_RenderDriver.info;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
257 renderer->window = window;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 renderer->driverdata = data;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 renderer->info.flags = SDL_RENDERER_ACCELERATED;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 if (flags & SDL_RENDERER_SINGLEBUFFER) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 renderer->info.flags |=
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 n = 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 } else if (flags & SDL_RENDERER_PRESENTFLIP2) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 n = 2;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 n = 3;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 } else {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 n = 1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 for (i = 0; i < n; ++i) {
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
277 data->pixmaps[i] =
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
278 XCreatePixmap(data->display, data->xwindow, window->w, window->h,
2870
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
279 displaydata->depth);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 if (data->pixmaps[i] == None) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 X11_DestroyRenderer(renderer);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 SDL_SetError("XCreatePixmap() failed");
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 return NULL;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 }
4573
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
285 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
286 if(data->xrender_available == SDL_TRUE) {
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
287 data->pixmap_picts[i] =
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
288 XCreatePicture(data->display, data->pixmap[i], data->xwindow_pict_fmt,
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
289 data->xwindow_pict_attr_valuemask, &xwindow_pict_attr);
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
290 if(!data->pixmap_picts[i]) {
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
291 data->xrender_available = SDL_FALSE;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
292 }
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
293 }
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
294 #endif
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 if (n > 0) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 data->drawable = data->pixmaps[0];
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
298 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
299 if(data->xrender_available == SDL_TRUE)
4576
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
300 data->drawable_pict = data->pixmap_picts[0];
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
301 #endif
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 data->makedirty = SDL_TRUE;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 } else {
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
304 data->drawable = data->xwindow;
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
305 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
306 if(data->xrender_available == SDL_TRUE)
4576
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
307 data->drawable_pict = data->xwindow_pict;
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
308 #endif
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 data->makedirty = SDL_FALSE;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 data->current_pixmap = 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 /* Get the format of the window */
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
314 if (!SDL_PixelFormatEnumToMasks
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
315 (display->current_mode.format, &bpp, &Rmask, &Gmask, &Bmask,
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
316 &Amask)) {
2870
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
317 SDL_SetError("Unknown display format");
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
318 X11_DestroyRenderer(renderer);
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
319 return NULL;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 }
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
321 SDL_InitFormat(&data->format, bpp, Rmask, Gmask, Bmask, Amask);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 /* Create the drawing context */
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 gcv.graphics_exposures = False;
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
325 data->gc =
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
326 XCreateGC(data->display, data->xwindow, GCGraphicsExposures, &gcv);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 if (!data->gc) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 X11_DestroyRenderer(renderer);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 SDL_SetError("XCreateGC() failed");
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 return NULL;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 return renderer;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 static int
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 X11_DisplayModeChanged(SDL_Renderer * renderer)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
340 SDL_Window *window = renderer->window;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 int i, n;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 n = 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 n = 2;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 n = 3;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 } else {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 n = 1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 for (i = 0; i < n; ++i) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 if (data->pixmaps[i] != None) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 XFreePixmap(data->display, data->pixmaps[i]);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 data->pixmaps[i] = None;
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
356 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
357 data->pictures[i] = None;
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
358 #endif
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 for (i = 0; i < n; ++i) {
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
362 data->pixmaps[i] =
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
363 XCreatePixmap(data->display, data->xwindow, window->w, window->h,
2870
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
364 data->depth);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 if (data->pixmaps[i] == None) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 SDL_SetError("XCreatePixmap() failed");
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 return -1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 }
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
369 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
4573
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
370 if(data->xrender_available == SDL_TRUE) {
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
371 data->pictures[i] =
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
372 XCreatePicture(data->display, data->pixmap[i], data->xwindow_pict_fmt,
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
373 data->xwindow_pict_attr_valuemask, &data->xwindow_pict_attr);
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
374 if(!data->pictures[i]) {
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
375 data->xrender_available = SDL_FALSE;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
376 }
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
377 }
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
378 #endif
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 if (n > 0) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 data->drawable = data->pixmaps[0];
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
382 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
4576
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
383 data->drawable_pict = data->pictures[0];
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
384 #endif
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 data->current_pixmap = 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 return 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 static int
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 X11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
395 SDL_Window *window = renderer->window;
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
396 SDL_VideoDisplay *display = window->display;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 X11_TextureData *data;
2916
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
398 int pitch_alignmask = ((renderdata->scanline_pad / 8) - 1);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 data = (X11_TextureData *) SDL_calloc(1, sizeof(*data));
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 if (!data) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 SDL_OutOfMemory();
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 return -1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 texture->driverdata = data;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 data->yuv =
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 if (!data->yuv) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 return -1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 data->format = display->current_mode.format;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 } else {
4573
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
415 /* If Xrender support is builtin we only need to check whether
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
416 Xrender is available at runtime. If it is available there
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
417 can be no BadMatch error since Xrender takes care of that.
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
418 */
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
419 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
4574
bfb4933c0efa Fix initial value of the xrender_available boolean in X11_CreateTexture.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4573
diff changeset
420 // Assume the texture is supported by Xrender
4575
037ddbeee6c3 Fix typo.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4574
diff changeset
421 data->xrender_available = SDL_TRUE;
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
422 if(renderdata->xrender_available == SDL_False) {
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
423 if (texture->format != display->current_mode.format) {
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
424 SDL_SetError("Texture format doesn't match window format");
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
425 return -1;
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
426 }
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
427 }
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
428 #else
4573
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
429 /* The image/pixmap depth must be the same as the window or you
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
430 get a BadMatch error when trying to putimage or copyarea.
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
431 This BadMatch error
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
432 */
2870
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
433 if (texture->format != display->current_mode.format) {
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
434 SDL_SetError("Texture format doesn't match window format");
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
435 return -1;
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
436 }
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
437 #endif
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 data->format = texture->format;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 }
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
440 data->pitch = texture->w * SDL_BYTESPERPIXEL(data->format);
2916
ffdd533f7add Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
441 data->pitch = (data->pitch + pitch_alignmask) & ~pitch_alignmask;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444 #ifndef NO_SHARED_MEMORY
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 XShmSegmentInfo *shminfo = &data->shminfo;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447 shm_error = True;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 if (SDL_X11_HAVE_SHM) {
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
450 shminfo->shmid =
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
451 shmget(IPC_PRIVATE, texture->h * data->pitch,
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
452 IPC_CREAT | 0777);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453 if (shminfo->shmid >= 0) {
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
454 shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455 shminfo->readOnly = False;
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
456 if (shminfo->shmaddr != (char *) -1) {
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 shm_error = False;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 X_handler = XSetErrorHandler(shm_errhandler);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 XShmAttach(renderdata->display, shminfo);
3239
ab5aebd50add Fix suggested by Bob
Sam Lantinga <slouken@libsdl.org>
parents: 3066
diff changeset
460 XSync(renderdata->display, False);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461 XSetErrorHandler(X_handler);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
462 if (shm_error) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463 shmdt(shminfo->shmaddr);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
465 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466 shmctl(shminfo->shmid, IPC_RMID, NULL);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 if (!shm_error) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 data->pixels = shminfo->shmaddr;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
472 data->image =
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
473 XShmCreateImage(renderdata->display, renderdata->visual,
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
474 renderdata->depth, ZPixmap, shminfo->shmaddr,
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
475 shminfo, texture->w, texture->h);
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
476 if (!data->image) {
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 XShmDetach(renderdata->display, shminfo);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478 XSync(renderdata->display, False);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 shmdt(shminfo->shmaddr);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480 shm_error = True;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483 if (shm_error) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484 shminfo->shmaddr = NULL;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 if (!data->image)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487 #endif /* not NO_SHARED_MEMORY */
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 data->pixels = SDL_malloc(texture->h * data->pitch);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 if (!data->pixels) {
2868
3b595278f813 Fixed BadMatch error in X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
491 X11_DestroyTexture(renderer, texture);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492 SDL_OutOfMemory();
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 return -1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
496 data->image =
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
497 XCreateImage(renderdata->display, renderdata->visual,
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
498 renderdata->depth, ZPixmap, 0, data->pixels,
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
499 texture->w, texture->h,
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
500 SDL_BYTESPERPIXEL(data->format) * 8,
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
501 data->pitch);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 if (!data->image) {
2868
3b595278f813 Fixed BadMatch error in X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
503 X11_DestroyTexture(renderer, texture);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 SDL_SetError("XCreateImage() failed");
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 return -1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508 } else {
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
509 data->pixmap =
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
510 XCreatePixmap(renderdata->display, renderdata->xwindow, texture->w,
2870
b801df19835f The X11 window and all pixmaps and images share the same visual and depth.
Sam Lantinga <slouken@libsdl.org>
parents: 2868
diff changeset
511 texture->h, renderdata->depth);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 if (data->pixmap == None) {
2868
3b595278f813 Fixed BadMatch error in X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
513 X11_DestroyTexture(renderer, texture);
3044
b36579172f27 Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
Bob Pendleton <bob@pendleton.com>
parents: 2967
diff changeset
514 SDL_SetError("XCreatePixmap() failed");
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515 return -1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 }
4572
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
517
266ec93f49af Correctly handle the availability of Xrender in X11_CreateRenderer and X11_DisplayModeChanged.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4571
diff changeset
518 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
4573
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
519 if(renderdata->xrender_available) {
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
520 data->xrender_available = SDL_TRUE;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
521 unsigned long x11_fmt_mask; // Format mask
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
522 XRenderPictFormat x11_templ_fmt; // Format template
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
523 x11_fmt_mask =
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
524 (PictFormatDepth | PictFormatRedMask | PictFormatGreenMask
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
525 | PictFormatBlueMask);
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
526 x11_templ_fmt.depth = (data->format).BitsPerPixel;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
527 x11_temp_fmt.direct.redMask = (data->format).Rmask;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
528 x11_temp_fmt.direct.greenMask = (data->format).Gmask;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
529 x11_temp_fmt.direct.blueMask = (data->format).Bmask;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
530 x11_temp_fmt.direct.alphaMask = (data->format).Amask;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
531 /* Return one matching XRenderPictFormat */
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
532 data->pict_fmt =
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
533 XRenderFindFormat(renderdata->display, x11_fmt_mask, &x11_templ_fmt, 1);
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
534 if(!data->pict_fmt) {
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
535 data->xrender_available = SDL_FALSE;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
536 }
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
537 data->picture_attr_valuemask = CPGraphicsExposure;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
538 (data->picture_attr).graphics_exposures = False;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
539 data->picture =
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
540 XCreatePicture(renderdata->display, data->pixmap, data->picture_fmt,
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
541 data->picture_attr_valuemask, &(data->picture_attr));
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
542 if(!data->picture) {
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
543 data->xrender_available = SDL_FALSE;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
544 }
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
545 }
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
546 /* We thought we could render the texture with Xrender but this was
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
547 not possible for some reason. Now we must ensure that texture
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
548 format and window format match to avoid a BadMatch error.
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
549 */
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
550 if(data->xrender_available == SDL_FALSE) {
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
551 if (texture->format != display->current_mode.format) {
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
552 SDL_SetError("Texture format doesn't match window format");
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
553 return -1;
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
554 }
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
555 }
6399178be313 Completed work on X11_CreateTexture. Added lots of safety features.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4572
diff changeset
556 #endif
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
557 data->image =
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
558 XCreateImage(renderdata->display, renderdata->visual,
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
559 renderdata->depth, ZPixmap, 0, NULL, texture->w,
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
560 texture->h, SDL_BYTESPERPIXEL(data->format) * 8,
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
561 data->pitch);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 if (!data->image) {
2868
3b595278f813 Fixed BadMatch error in X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
563 X11_DestroyTexture(renderer, texture);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 SDL_SetError("XCreateImage() failed");
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 return -1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 return 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 static int
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 X11_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 void **pixels, int *pitch)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 X11_TextureData *data = (X11_TextureData *) texture->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 if (data->yuv) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580 } else {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 *pixels = data->pixels;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 *pitch = data->pitch;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583 return 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587 static int
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 X11_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 switch (texture->blendMode) {
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
591 case SDL_BLENDMODE_NONE:
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592 return 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593 default:
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594 SDL_Unsupported();
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
595 texture->blendMode = SDL_BLENDMODE_NONE;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596 return -1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600 static int
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601 X11_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 {
2828
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
603 X11_TextureData *data = (X11_TextureData *) texture->driverdata;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
604
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605 switch (texture->scaleMode) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 case SDL_TEXTURESCALEMODE_NONE:
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607 return 0;
2828
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
608 case SDL_TEXTURESCALEMODE_FAST:
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
609 /* We can sort of fake it for streaming textures */
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
610 if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
611 return 0;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
612 }
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
613 /* Fall through to unsupported case */
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614 default:
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
615 SDL_Unsupported();
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
616 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
617 return -1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
618 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
619 return 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
620 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
622 static int
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623 X11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
624 const SDL_Rect * rect, const void *pixels, int pitch)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
625 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
626 X11_TextureData *data = (X11_TextureData *) texture->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
627
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
628 if (data->yuv) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
629 if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
630 return -1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
631 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
632 UpdateYUVTextureData(texture);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
633 return 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
634 } else {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
635 X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
636
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
637 if (data->pixels) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
638 Uint8 *src, *dst;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
639 int row;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
640 size_t length;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
641
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
642 src = (Uint8 *) pixels;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
643 dst =
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
644 (Uint8 *) data->pixels + rect->y * data->pitch +
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
645 rect->x * SDL_BYTESPERPIXEL(texture->format);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
646 length = rect->w * SDL_BYTESPERPIXEL(texture->format);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
647 for (row = 0; row < rect->h; ++row) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
648 SDL_memcpy(dst, src, length);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
649 src += pitch;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
650 dst += data->pitch;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
651 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
652 } else {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
653 data->image->width = rect->w;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
654 data->image->height = rect->h;
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
655 data->image->data = (char *) pixels;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
656 data->image->bytes_per_line = pitch;
2814
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
657 XPutImage(renderdata->display, data->pixmap, renderdata->gc,
Sam Lantinga <slouken@libsdl.org>
parents: 2811
diff changeset
658 data->image, 0, 0, rect->x, rect->y, rect->w, rect->h);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
659 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
660 return 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
661 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
662 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
663
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
664 static int
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
665 X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
666 const SDL_Rect * rect, int markDirty, void **pixels,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
667 int *pitch)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
668 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
669 X11_TextureData *data = (X11_TextureData *) texture->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
670
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
671 if (data->yuv) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
672 return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
673 pitch);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
674 } else if (data->pixels) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
675 *pixels =
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
676 (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
677 rect->x * SDL_BYTESPERPIXEL(texture->format));
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
678 *pitch = data->pitch;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
679 return 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
680 } else {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
681 SDL_SetError("No pixels available");
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
682 return -1;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
683 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
684 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
685
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
686 static void
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
687 X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
688 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
689 X11_TextureData *data = (X11_TextureData *) texture->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
690
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
691 if (data->yuv) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
692 SDL_SW_UnlockYUVTexture(data->yuv);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
693 UpdateYUVTextureData(texture);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
694 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
695 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
696
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
697 static int
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
698 X11_SetDrawBlendMode(SDL_Renderer * renderer)
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
699 {
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
700 switch (renderer->blendMode) {
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
701 case SDL_BLENDMODE_NONE:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
702 return 0;
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
703 default:
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
704 SDL_Unsupported();
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
705 renderer->blendMode = SDL_BLENDMODE_NONE;
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
706 return -1;
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
707 }
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
708 }
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
709
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
710 static Uint32
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
711 renderdrawcolor(SDL_Renderer * renderer, int premult)
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
712 {
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
713 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
714 Uint8 r = renderer->r;
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
715 Uint8 g = renderer->g;
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
716 Uint8 b = renderer->b;
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
717 Uint8 a = renderer->a;
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
718 if (premult)
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
719 return SDL_MapRGBA(&data->format, ((int) r * (int) a) / 255,
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
720 ((int) g * (int) a) / 255,
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
721 ((int) b * (int) a) / 255, 255);
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
722 else
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2927
diff changeset
723 return SDL_MapRGBA(&data->format, r, g, b, a);
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
724 }
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
725
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
726 static int
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
727 X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
728 int count)
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2894
diff changeset
729 {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2894
diff changeset
730 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
731 SDL_Window *window = renderer->window;
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2894
diff changeset
732 unsigned long foreground;
3538
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
733 XPoint *xpoints, *xpoint;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
734 int i, xcount;
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2894
diff changeset
735
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2894
diff changeset
736 if (data->makedirty) {
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2894
diff changeset
737 SDL_Rect rect;
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2894
diff changeset
738
3538
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
739 /* Get the smallest rectangle that contains everything */
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
740 rect.x = 0;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
741 rect.y = 0;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
742 rect.w = window->w;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
743 rect.h = window->h;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
744 if (!SDL_EnclosePoints(points, count, &rect, &rect)) {
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
745 /* Nothing to draw */
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
746 return 0;
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
747 }
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
748 SDL_AddDirtyRect(&data->dirty, &rect);
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
749 }
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
750
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
751 foreground = renderdrawcolor(renderer, 1);
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
752 XSetForeground(data->display, data->gc, foreground);
3538
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
753
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
754 xpoint = xpoints = SDL_stack_alloc(XPoint, count);
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
755 xcount = 0;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
756 for (i = 0; i < count; ++i) {
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
757 int x = points[i].x;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
758 int y = points[i].y;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
759 if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
760 continue;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
761 }
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
762 xpoint->x = (short)x;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
763 xpoint->y = (short)y;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
764 ++xpoint;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
765 ++xcount;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
766 }
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
767 if (xcount > 0) {
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
768 XDrawPoints(data->display, data->drawable, data->gc, xpoints, xcount,
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
769 CoordModeOrigin);
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
770 }
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
771 SDL_stack_free(xpoints);
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
772
2894
e80f347b6d29 Added missing return
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
773 return 0;
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
774 }
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
775
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
776 static int
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
777 X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
778 int count)
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
779 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
780 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
781 SDL_Window *window = renderer->window;
4458
c9584df65367 Removed unused variables
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
782 SDL_Rect clip;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
783 unsigned long foreground;
3543
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
784 XPoint *xpoints, *xpoint;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
785 int i, xcount;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
786 int minx, miny;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
787 int maxx, maxy;
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
788
3538
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
789 clip.x = 0;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
790 clip.y = 0;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
791 clip.w = window->w;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
792 clip.h = window->h;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
793
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2882
diff changeset
794 foreground = renderdrawcolor(renderer, 1);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
795 XSetForeground(data->display, data->gc, foreground);
3543
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
796
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
797 xpoint = xpoints = SDL_stack_alloc(XPoint, count);
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
798 xcount = 0;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
799 minx = INT_MAX;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
800 miny = INT_MAX;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
801 maxx = INT_MIN;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
802 maxy = INT_MIN;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
803 for (i = 0; i < count; ++i) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
804 int x = points[i].x;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
805 int y = points[i].y;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
806
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
807 /* If the point is inside the window, add it to the list */
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
808 if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
809 if (x < minx) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
810 minx = x;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
811 } else if (x > maxx) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
812 maxx = x;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
813 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
814 if (y < miny) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
815 miny = y;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
816 } else if (y > maxy) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
817 maxy = y;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
818 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
819 xpoint->x = (short)x;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
820 xpoint->y = (short)y;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
821 ++xpoint;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
822 ++xcount;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
823 continue;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
824 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
825
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
826 /* We need to clip the line segments joined by this point */
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
827 if (xcount > 0) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
828 int x1 = xpoint[-1].x;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
829 int y1 = xpoint[-1].y;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
830 int x2 = x;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
831 int y2 = y;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
832 if (SDL_IntersectRectAndLine(&clip, &x1, &y1, &x2, &y2)) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
833 if (x2 < minx) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
834 minx = x2;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
835 } else if (x2 > maxx) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
836 maxx = x2;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
837 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
838 if (y2 < miny) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
839 miny = y2;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
840 } else if (y2 > maxy) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
841 maxy = y2;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
842 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
843 xpoint->x = (short)x2;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
844 xpoint->y = (short)y2;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
845 ++xpoint;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
846 ++xcount;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
847 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
848 XDrawLines(data->display, data->drawable, data->gc,
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
849 xpoints, xcount, CoordModeOrigin);
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
850 if (xpoints[0].x != x2 || xpoints[0].y != y2) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
851 XDrawPoint(data->display, data->drawable, data->gc, x2, y2);
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
852 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
853 if (data->makedirty) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
854 SDL_Rect rect;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
855
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
856 rect.x = minx;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
857 rect.y = miny;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
858 rect.w = (maxx - minx) + 1;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
859 rect.h = (maxy - miny) + 1;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
860 SDL_AddDirtyRect(&data->dirty, &rect);
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
861 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
862 xpoint = xpoints;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
863 xcount = 0;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
864 minx = INT_MAX;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
865 miny = INT_MAX;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
866 maxx = INT_MIN;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
867 maxy = INT_MIN;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
868 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
869 if (i < (count-1)) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
870 int x1 = x;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
871 int y1 = y;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
872 int x2 = points[i+1].x;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
873 int y2 = points[i+1].y;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
874 if (SDL_IntersectRectAndLine(&clip, &x1, &y1, &x2, &y2)) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
875 if (x1 < minx) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
876 minx = x1;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
877 } else if (x1 > maxx) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
878 maxx = x1;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
879 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
880 if (y1 < miny) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
881 miny = y1;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
882 } else if (y1 > maxy) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
883 maxy = y1;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
884 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
885 xpoint->x = (short)x1;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
886 xpoint->y = (short)y1;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
887 ++xpoint;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
888 ++xcount;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
889 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
890 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
891 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
892 if (xcount > 1) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
893 int x2 = xpoint[-1].x;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
894 int y2 = xpoint[-1].y;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
895 XDrawLines(data->display, data->drawable, data->gc, xpoints, xcount,
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
896 CoordModeOrigin);
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
897 if (xpoints[0].x != x2 || xpoints[0].y != y2) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
898 XDrawPoint(data->display, data->drawable, data->gc, x2, y2);
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
899 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
900 if (data->makedirty) {
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
901 SDL_Rect rect;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
902
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
903 rect.x = minx;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
904 rect.y = miny;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
905 rect.w = (maxx - minx) + 1;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
906 rect.h = (maxy - miny) + 1;
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
907 SDL_AddDirtyRect(&data->dirty, &rect);
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
908 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
909 }
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
910 SDL_stack_free(xpoints);
c2154674c0c1 Fixed X11 line implementation - clip lines that are going to go outside the window.
Sam Lantinga <slouken@libsdl.org>
parents: 3538
diff changeset
911
3538
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
912 return 0;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
913 }
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
914
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
915 static int
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
916 X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
917 {
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
918 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
919 SDL_Window *window = renderer->window;
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
920 SDL_Rect clip, rect;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
921 unsigned long foreground;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
922 XRectangle *xrects, *xrect;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
923 int i, xcount;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
924
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
925 clip.x = 0;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
926 clip.y = 0;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
927 clip.w = window->w;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
928 clip.h = window->h;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
929
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
930 foreground = renderdrawcolor(renderer, 1);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
931 XSetForeground(data->display, data->gc, foreground);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
932
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
933 xrect = xrects = SDL_stack_alloc(XRectangle, count);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
934 xcount = 0;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
935 for (i = 0; i < count; ++i) {
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
936 if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
937 continue;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
938 }
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
939
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
940 xrect->x = (short)rect.x;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
941 xrect->y = (short)rect.y;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
942 xrect->width = (unsigned short)rect.w;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
943 xrect->height = (unsigned short)rect.h;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
944 ++xrect;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
945 ++xcount;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
946
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
947 if (data->makedirty) {
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
948 SDL_AddDirtyRect(&data->dirty, &rect);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
949 }
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
950 }
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
951 if (xcount > 0) {
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
952 XDrawRectangles(data->display, data->drawable, data->gc,
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
953 xrects, xcount);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
954 }
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
955 SDL_stack_free(xpoints);
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
956
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
957 return 0;
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
958 }
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
959
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
960 static int
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3559
diff changeset
961 X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
3538
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
962 {
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
963 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
964 SDL_Window *window = renderer->window;
3538
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
965 SDL_Rect clip, rect;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
966 unsigned long foreground;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
967 XRectangle *xrects, *xrect;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
968 int i, xcount;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
969
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
970 clip.x = 0;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
971 clip.y = 0;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
972 clip.w = window->w;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
973 clip.h = window->h;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
974
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
975 foreground = renderdrawcolor(renderer, 1);
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
976 XSetForeground(data->display, data->gc, foreground);
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
977
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
978 xrect = xrects = SDL_stack_alloc(XRectangle, count);
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
979 xcount = 0;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
980 for (i = 0; i < count; ++i) {
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
981 if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
982 continue;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
983 }
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
984
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
985 xrect->x = (short)rect.x;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
986 xrect->y = (short)rect.y;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
987 xrect->width = (unsigned short)rect.w;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
988 xrect->height = (unsigned short)rect.h;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
989 ++xrect;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
990 ++xcount;
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
991
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
992 if (data->makedirty) {
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
993 SDL_AddDirtyRect(&data->dirty, &rect);
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
994 }
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
995 }
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
996 if (xcount > 0) {
4576
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
997 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
998 if(data->xrender_available == SDL_TRUE)
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
999 {
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
1000 XRenderFillRectangles(data->display, PictOpSrc, data->drawable_pict,
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
1001 (XRenderColor)foreground, xrects, xcount);
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
1002 }
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
1003 else
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
1004 #endif
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
1005 {
3538
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
1006 XFillRectangles(data->display, data->drawable, data->gc,
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
1007 xrects, xcount);
4576
2b98162b536a Add Xrender support to X11_FillRectangles.
Sunny Sachanandani <sunnysachanandani@gmail.com>
parents: 4575
diff changeset
1008 }
3538
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
1009 }
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
1010 SDL_stack_free(xpoints);
a1896642a47e X11 driver compiles again, lines are not yet implemented
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
1011
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1012 return 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1013 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1014
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1015 static int
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1016 X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1017 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1018 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1019 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1020 X11_TextureData *texturedata = (X11_TextureData *) texture->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1021
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1022 if (data->makedirty) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1023 SDL_AddDirtyRect(&data->dirty, dstrect);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1024 }
2828
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1025 if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1026 #ifndef NO_SHARED_MEMORY
2828
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1027 if (texturedata->shminfo.shmaddr) {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1028 XShmPutImage(data->display, data->drawable, data->gc,
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1029 texturedata->image, srcrect->x, srcrect->y,
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1030 dstrect->x, dstrect->y, srcrect->w, srcrect->h,
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1031 False);
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1032 } else
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1033 #endif
2828
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1034 if (texturedata->pixels) {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1035 XPutImage(data->display, data->drawable, data->gc,
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1036 texturedata->image, srcrect->x, srcrect->y, dstrect->x,
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1037 dstrect->y, srcrect->w, srcrect->h);
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1038 } else {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1039 XCopyArea(data->display, texturedata->pixmap, data->drawable,
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1040 data->gc, srcrect->x, srcrect->y, dstrect->w,
3066
8cbf68bdf81b Fixed destination of XCopyArea()
Sam Lantinga <slouken@libsdl.org>
parents: 3044
diff changeset
1041 dstrect->h, dstrect->x, dstrect->y);
2828
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1042 }
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1043 } else if (texturedata->yuv
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1044 || texture->access == SDL_TEXTUREACCESS_STREAMING) {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1045 SDL_Surface src, dst;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1046 SDL_PixelFormat fmt;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1047 SDL_Rect rect;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1048 XImage *image = texturedata->scaling_image;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1049
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1050 if (!image) {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1051 void *pixels;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1052 int pitch;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1053
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1054 pitch = dstrect->w * SDL_BYTESPERPIXEL(texturedata->format);
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1055 pixels = SDL_malloc(dstrect->h * pitch);
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1056 if (!pixels) {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1057 SDL_OutOfMemory();
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1058 return -1;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1059 }
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1060
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1061 image =
2874
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
1062 XCreateImage(data->display, data->visual, data->depth,
Sam Lantinga <slouken@libsdl.org>
parents: 2870
diff changeset
1063 ZPixmap, 0, pixels, dstrect->w, dstrect->h,
2828
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1064 SDL_BYTESPERPIXEL(texturedata->format) * 8,
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1065 pitch);
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1066 if (!image) {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1067 SDL_SetError("XCreateImage() failed");
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1068 return -1;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1069 }
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1070 texturedata->scaling_image = image;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1071
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1072 } else if (image->width != dstrect->w || image->height != dstrect->h
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1073 || !image->data) {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1074 image->width = dstrect->w;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1075 image->height = dstrect->h;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1076 image->bytes_per_line =
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1077 image->width * SDL_BYTESPERPIXEL(texturedata->format);
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1078 image->data =
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1079 (char *) SDL_realloc(image->data,
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1080 image->height * image->bytes_per_line);
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1081 if (!image->data) {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1082 SDL_OutOfMemory();
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1083 return -1;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1084 }
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1085 }
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1086
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1087 /* Set up fake surfaces for SDL_SoftStretch() */
2882
04e89201f6ed Fixed crash when resizing YUV textures
Sam Lantinga <slouken@libsdl.org>
parents: 2874
diff changeset
1088 SDL_zero(src);
2828
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1089 src.format = &fmt;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1090 src.w = texture->w;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1091 src.h = texture->h;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1092 #ifndef NO_SHARED_MEMORY
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1093 if (texturedata->shminfo.shmaddr) {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1094 src.pixels = texturedata->shminfo.shmaddr;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1095 } else
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1096 #endif
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1097 src.pixels = texturedata->pixels;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1098 src.pitch = texturedata->pitch;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1099
2882
04e89201f6ed Fixed crash when resizing YUV textures
Sam Lantinga <slouken@libsdl.org>
parents: 2874
diff changeset
1100 SDL_zero(dst);
2828
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1101 dst.format = &fmt;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1102 dst.w = image->width;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1103 dst.h = image->height;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1104 dst.pixels = image->data;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1105 dst.pitch = image->bytes_per_line;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1106
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1107 fmt.BytesPerPixel = SDL_BYTESPERPIXEL(texturedata->format);
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1108
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1109 rect.x = 0;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1110 rect.y = 0;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1111 rect.w = dstrect->w;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1112 rect.h = dstrect->h;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1113 if (SDL_SoftStretch(&src, srcrect, &dst, &rect) < 0) {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1114 return -1;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1115 }
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1116 XPutImage(data->display, data->drawable, data->gc, image, 0, 0,
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1117 dstrect->x, dstrect->y, dstrect->w, dstrect->h);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1118 } else {
2827
aec4399c507a If scaling isn't supported, do an unscaled copy instead of not showing anything.
Sam Lantinga <slouken@libsdl.org>
parents: 2814
diff changeset
1119 XCopyArea(data->display, texturedata->pixmap, data->drawable,
aec4399c507a If scaling isn't supported, do an unscaled copy instead of not showing anything.
Sam Lantinga <slouken@libsdl.org>
parents: 2814
diff changeset
1120 data->gc, srcrect->x, srcrect->y, dstrect->w, dstrect->h,
aec4399c507a If scaling isn't supported, do an unscaled copy instead of not showing anything.
Sam Lantinga <slouken@libsdl.org>
parents: 2814
diff changeset
1121 srcrect->x, srcrect->y);
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1122 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1123 return 0;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1124 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1125
3559
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1126 static int
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1127 X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1128 Uint32 format, void * pixels, int pitch)
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1129 {
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1130 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
1131 SDL_Window *window = renderer->window;
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
1132 SDL_VideoDisplay *display = window->display;
3559
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1133 Uint32 screen_format = display->current_mode.format;
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1134 XImage *image;
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1135
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1136 image = XGetImage(data->display, data->drawable, rect->x, rect->y,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1137 rect->w, rect->h, AllPlanes, ZPixmap);
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1138
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1139 SDL_ConvertPixels(rect->w, rect->h,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1140 screen_format, image->data, image->bytes_per_line,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1141 format, pixels, pitch);
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1142
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1143 XDestroyImage(image);
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1144 return 0;
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1145 }
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1146
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1147 static int
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1148 X11_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1149 Uint32 format, const void * pixels, int pitch)
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1150 {
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1151 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
1152 SDL_Window *window = renderer->window;
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
1153 SDL_VideoDisplay *display = window->display;
3559
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1154 Uint32 screen_format = display->current_mode.format;
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1155 XImage *image;
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1156 void *image_pixels;
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1157 int image_pitch;
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1158
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1159 image_pitch = rect->w * SDL_BYTESPERPIXEL(screen_format);
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1160 image_pixels = SDL_malloc(rect->h * image_pitch);
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1161 if (!image_pixels) {
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1162 SDL_OutOfMemory();
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1163 return -1;
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1164 }
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1165
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1166 image = XCreateImage(data->display, data->visual,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1167 data->depth, ZPixmap, 0, image_pixels,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1168 rect->w, rect->h,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1169 SDL_BYTESPERPIXEL(screen_format) * 8,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1170 image_pitch);
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1171 if (!image) {
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1172 SDL_SetError("XCreateImage() failed");
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1173 return -1;
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1174 }
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1175
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1176 SDL_ConvertPixels(rect->w, rect->h,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1177 format, pixels, pitch,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1178 screen_format, image->data, image->bytes_per_line);
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1179
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1180 XPutImage(data->display, data->drawable, data->gc,
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1181 image, 0, 0, rect->x, rect->y, rect->w, rect->h);
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1182
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1183 image->data = NULL;
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1184 XDestroyImage(image);
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1185
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1186 SDL_free(image_pixels);
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1187 return 0;
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1188 }
5f26a7eb5ff0 Implemented read/write pixels for the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3543
diff changeset
1189
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1190 static void
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1191 X11_RenderPresent(SDL_Renderer * renderer)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1192 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1193 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1194 SDL_DirtyRect *dirty;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1195
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1196 /* Send the data to the display */
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1197 if (!(renderer->info.flags & SDL_RENDERER_SINGLEBUFFER)) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1198 for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1199 const SDL_Rect *rect = &dirty->rect;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
1200 XCopyArea(data->display, data->drawable, data->xwindow,
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1201 data->gc, rect->x, rect->y, rect->w, rect->h,
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1202 rect->x, rect->y);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1203 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1204 SDL_ClearDirtyRects(&data->dirty);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1205 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1206 XSync(data->display, False);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1207
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1208 /* Update the flipping chain, if any */
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1209 if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1210 data->current_pixmap = (data->current_pixmap + 1) % 2;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1211 data->drawable = data->pixmaps[data->current_pixmap];
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1212 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1213 data->current_pixmap = (data->current_pixmap + 1) % 3;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1214 data->drawable = data->pixmaps[data->current_pixmap];
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1215 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1216 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1217
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1218 static void
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1219 X11_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1220 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1221 X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1222 X11_TextureData *data = (X11_TextureData *) texture->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1223
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1224 if (!data) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1225 return;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1226 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1227 if (data->yuv) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1228 SDL_SW_DestroyYUVTexture(data->yuv);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1229 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1230 if (data->pixmap != None) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1231 XFreePixmap(renderdata->display, data->pixmap);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1232 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1233 if (data->image) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1234 data->image->data = NULL;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1235 XDestroyImage(data->image);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1236 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1237 #ifndef NO_SHARED_MEMORY
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1238 if (data->shminfo.shmaddr) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1239 XShmDetach(renderdata->display, &data->shminfo);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1240 XSync(renderdata->display, False);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1241 shmdt(data->shminfo.shmaddr);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1242 data->pixels = NULL;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1243 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1244 #endif
2828
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1245 if (data->scaling_image) {
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1246 SDL_free(data->scaling_image->data);
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1247 data->scaling_image->data = NULL;
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1248 XDestroyImage(data->scaling_image);
7e5ff6cd05bf Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents: 2827
diff changeset
1249 }
2810
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1250 if (data->pixels) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1251 SDL_free(data->pixels);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1252 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1253 SDL_free(data);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1254 texture->driverdata = NULL;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1255 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1256
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1257 static void
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1258 X11_DestroyRenderer(SDL_Renderer * renderer)
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1259 {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1260 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1261 int i;
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1262
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1263 if (data) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1264 for (i = 0; i < SDL_arraysize(data->pixmaps); ++i) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1265 if (data->pixmaps[i] != None) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1266 XFreePixmap(data->display, data->pixmaps[i]);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1267 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1268 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1269 if (data->gc) {
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1270 XFreeGC(data->display, data->gc);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1271 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1272 SDL_FreeDirtyRects(&data->dirty);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1273 SDL_free(data);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1274 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1275 SDL_free(renderer);
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1276 }
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1277
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1278 #endif /* SDL_VIDEO_RENDER_X11 */
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1279
27cb878a278e Implemented the X11 (non-OpenGL) renderer, no alpha or scaling available.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1280 /* vi: set ts=4 sw=4 expandtab: */