comparison src/video/directfb/SDL_DirectFB_mouse.c @ 2226:0e70b4b8cf84

Date: Sat, 11 Aug 2007 02:03:16 +0200 (CEST) From: couriersud arcor.de To: slouken@libsdl.org Subject: Directfb driver for SDL1.3 Hi, the attachment contains a patch for a SDL1.3 directfb driver. It supports: - Renderer "directfb": Hardware acceleration as supported by the underlying directfb driver. With a radeon X850, testsprite2 runs at 50% to 70% of OpenGL (X11, dri) performance. Also supports hardware accelerated yuv overlays. This must be enabled by sett ing: export SDL_DIRECTFB_YUV_DIRECT=1 - Renderer "opengl" Supports software opengl using mesa opengl (make linux-directfb). Some more information may be found in README.DirectFB There will certainly still be some bugs, and there is some debug code around. When I find some time, I will compile against directfb-0.9.25 as distributed with ubuntu 7.04. The diff also contains a fix for SDL_LockYUVOverlay fixing a bug in *pixels and pitches initialization. Kind regards, couriersud
author Sam Lantinga <slouken@libsdl.org>
date Sat, 11 Aug 2007 21:51:19 +0000
parents
children 1e690901ecd7
comparison
equal deleted inserted replaced
2225:3bca1b7ca25b 2226:0e70b4b8cf84
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22 #include "SDL_config.h"
23
24 #include "SDL_DirectFB_video.h"
25 #include "SDL_DirectFB_mouse.h"
26
27 #include "../SDL_sysvideo.h"
28 #include "../../events/SDL_mouse_c.h"
29
30 static SDL_Cursor *DirectFB_CreateCursor(SDL_Surface * surface, int hot_x,
31 int hot_y);
32 static int DirectFB_ShowCursor(SDL_Cursor * cursor);
33 static void DirectFB_MoveCursor(SDL_Cursor * cursor);
34 static void DirectFB_FreeCursor(SDL_Cursor * cursor);
35 static void DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_WindowID windowID,
36 int x, int y);
37 static void DirectFB_FreeMouse(SDL_Mouse * mouse);
38
39 void
40 DirectFB_InitMouse(_THIS)
41 {
42 SDL_DFB_DEVICEDATA(_this);
43 SDL_Mouse mouse;
44
45 SDL_zero(mouse);
46 mouse.CreateCursor = DirectFB_CreateCursor;
47 mouse.ShowCursor = DirectFB_ShowCursor;
48 mouse.MoveCursor = DirectFB_MoveCursor;
49 mouse.FreeCursor = DirectFB_FreeCursor;
50 mouse.WarpMouse = DirectFB_WarpMouse;
51 mouse.FreeMouse = DirectFB_FreeMouse;
52 devdata->mouse = SDL_AddMouse(&mouse, -1);
53 }
54
55 void
56 DirectFB_QuitMouse(_THIS)
57 {
58 SDL_DFB_DEVICEDATA(_this);
59
60 SDL_DelMouse(devdata->mouse);
61 }
62
63 /* Create a cursor from a surface */
64 static SDL_Cursor *
65 DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
66 {
67 SDL_VideoDevice *dev = SDL_GetVideoDevice();
68
69 SDL_DFB_DEVICEDATA(dev);
70 DFB_CursorData *curdata;
71 DFBResult ret;
72 DFBSurfaceDescription dsc;
73 SDL_Cursor *cursor;
74 Uint32 *dest;
75 Uint32 *p;
76 int pitch, i;
77
78 SDL_DFB_CALLOC(cursor, 1, sizeof(*cursor));
79 SDL_DFB_CALLOC(curdata, 1, sizeof(*curdata));
80
81 dsc.flags =
82 DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
83 dsc.caps = DSCAPS_NONE; //DSCAPS_SYSTEMONLY;
84 dsc.width = surface->w;
85 dsc.height = surface->h;
86 dsc.pixelformat = DSPF_ARGB;
87
88 SDL_DFB_CHECKERR(devdata->dfb->
89 CreateSurface(devdata->dfb, &dsc, &curdata->surf));
90 curdata->hotx = hot_x;
91 curdata->hoty = hot_y;
92 cursor->driverdata = curdata;
93
94 SDL_DFB_CHECKERR(curdata->surf->
95 Lock(curdata->surf, DSLF_WRITE, (void *) &dest, &pitch));
96
97 //FIXME: Implies a lot of things, e.g. rgba format for SDL_SURFACE ....
98 p = surface->pixels;
99 for (i = 0; i < surface->w * surface->h; i++)
100 if (p[i] == 0x00000000)
101 dest[i] = 0x00000000;
102 else
103 dest[i] = p[i];
104 //memcpy(dest, surface->pixels, surface->w * surface->h * 4);
105 curdata->surf->Unlock(curdata->surf);
106 return cursor;
107 error:
108 return NULL;
109 }
110
111 /* Show the specified cursor, or hide if cursor is NULL */
112 static int
113 DirectFB_ShowCursor(SDL_Cursor * cursor)
114 {
115 SDL_DFB_CURSORDATA(cursor);
116 SDL_VideoDevice *dev = SDL_GetVideoDevice();
117 SDL_DFB_DEVICEDATA(dev);
118 #if 0
119 DFB_DisplayData *dispdata =
120 (DFB_DisplayData *) dev->displays[dev->current_display].driverdata;
121 #endif
122 DFBResult ret;
123 SDL_WindowID wid;
124
125 wid = SDL_GetFocusWindow();
126 if (!wid)
127 return -1;
128 else {
129 SDL_Window *window = SDL_GetWindowFromID(wid);
130 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
131 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
132 DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
133 SDL_DFB_CHECKERR(windata->window->
134 SetCursorShape(windata->window, curdata->surf,
135 curdata->hotx, curdata->hoty));
136 //FIXME: This is somehow a directfb issue
137 SDL_DFB_CHECKERR(dispdata->layer->
138 SetCooperativeLevel(dispdata->layer,
139 DLSCL_ADMINISTRATIVE));
140 SDL_DFB_CHECKERR(dispdata->layer->
141 SetCursorOpacity(dispdata->layer, 0xC0));
142 SDL_DFB_CHECKERR(dispdata->layer->
143 SetCooperativeLevel(dispdata->layer, DLSCL_SHARED));
144 }
145 #if 0
146 //TODO: Check administrative
147 SDL_DFB_CHECKERR(dispdata->layer->
148 SetCooperativeLevel(dispdata->layer,
149 DLSCL_ADMINISTRATIVE));
150 SDL_DFB_CHECKERR(dispdata->layer->
151 SetCursorShape(dispdata->layer, curdata->surf,
152 curdata->hotx, curdata->hoty));
153 SDL_DFB_CHECKERR(dispdata->layer->
154 SetCursorOpacity(dispdata->layer, 0xC0));
155 SDL_DFB_CHECKERR(dispdata->layer->
156 SetCooperativeLevel(dispdata->layer, DLSCL_SHARED));
157
158 #endif
159
160 return 0;
161 error:
162 return -1;
163 }
164
165 /* This is called when a mouse motion event occurs */
166 static void
167 DirectFB_MoveCursor(SDL_Cursor * cursor)
168 {
169 SDL_DFB_CURSORDATA(cursor);
170 /* Do we need to do something here ? */
171 }
172
173 /* Free a window manager cursor */
174 static void
175 DirectFB_FreeCursor(SDL_Cursor * cursor)
176 {
177 SDL_DFB_CURSORDATA(cursor);
178
179 SDL_DFB_RELEASE(curdata->surf);
180 SDL_DFB_FREE(cursor->driverdata);
181 SDL_DFB_FREE(cursor);
182 }
183
184 /* Warp the mouse to (x,y) */
185 static void
186 DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y)
187 {
188 // SDL_DFB_CURSORDATA(cursor);
189 SDL_Window *window = SDL_GetWindowFromID(windowID);
190 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
191 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
192 DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
193 DFBResult ret;
194 int cx, cy;
195
196 SDL_DFB_CHECKERR(windata->window->GetPosition(windata->window, &cx, &cy));
197 SDL_DFB_CHECKERR(dispdata->layer->
198 WarpCursor(dispdata->layer, cx + x, cy + y));
199
200 error:
201 return;
202 }
203
204 /* Free the mouse when it's time */
205 static void
206 DirectFB_FreeMouse(SDL_Mouse * mouse)
207 {
208 // nothing yet
209
210 }
211
212 /* vi: set ts=4 sw=4 expandtab: */