1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Copyright (C) 1998-1999 Tor Lillqvist
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 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
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21 /*
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team.
24 */
25
26 /*
27 * GTK+ DirectFB backend
28 * Copyright (C) 2001-2002 convergence integrated media GmbH
29 * Copyright (C) 2002-2004 convergence GmbH
30 * Written by Denis Oliver Kropp <dok@convergence.de> and
31 * Sven Neumann <sven@convergence.de>
32 */
33
34 #include "config.h"
35 #include "gdk.h"
36
37 #include <stdlib.h>
38 #include <string.h>
39
40 #include "gdkdirectfb.h"
41 #include "gdkprivate-directfb.h"
42
43 #include "gdkinternals.h"
44
45 #include "gdkpixmap.h"
46 #include "gdkalias.h"
47
48
49 static void gdk_pixmap_impl_directfb_init (GdkPixmapImplDirectFB *pixmap);
50 static void gdk_pixmap_impl_directfb_class_init (GdkPixmapImplDirectFBClass *klass);
51 static void gdk_pixmap_impl_directfb_finalize (GObject *object);
52
53
54 static gpointer parent_class = NULL;
55
56 G_DEFINE_TYPE (GdkPixmapImplDirectFB,
57 gdk_pixmap_impl_directfb,
58 GDK_TYPE_DRAWABLE_IMPL_DIRECTFB);
59
60 GType
_gdk_pixmap_impl_get_type(void)61 _gdk_pixmap_impl_get_type (void)
62 {
63 return gdk_pixmap_impl_directfb_get_type ();
64 }
65
66 static void
gdk_pixmap_impl_directfb_init(GdkPixmapImplDirectFB * impl)67 gdk_pixmap_impl_directfb_init (GdkPixmapImplDirectFB *impl)
68 {
69 GdkDrawableImplDirectFB *draw_impl = GDK_DRAWABLE_IMPL_DIRECTFB (impl);
70 draw_impl->width = 1;
71 draw_impl->height = 1;
72 }
73
74 static void
gdk_pixmap_impl_directfb_class_init(GdkPixmapImplDirectFBClass * klass)75 gdk_pixmap_impl_directfb_class_init (GdkPixmapImplDirectFBClass *klass)
76 {
77 GObjectClass *object_class = G_OBJECT_CLASS (klass);
78
79 parent_class = g_type_class_peek_parent (klass);
80
81 object_class->finalize = gdk_pixmap_impl_directfb_finalize;
82 }
83
84 static void
gdk_pixmap_impl_directfb_finalize(GObject * object)85 gdk_pixmap_impl_directfb_finalize (GObject *object)
86 {
87 if (G_OBJECT_CLASS (parent_class)->finalize)
88 G_OBJECT_CLASS (parent_class)->finalize (object);
89 }
90
91 GdkPixmap *
_gdk_pixmap_new(GdkDrawable * drawable,gint width,gint height,gint depth)92 _gdk_pixmap_new (GdkDrawable *drawable,
93 gint width,
94 gint height,
95 gint depth)
96 {
97 DFBSurfacePixelFormat format;
98 IDirectFBSurface *surface;
99 GdkPixmap *pixmap;
100 GdkDrawableImplDirectFB *draw_impl;
101
102 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
103 g_return_val_if_fail (drawable != NULL || depth != -1, NULL);
104 g_return_val_if_fail (width > 0 && height > 0, NULL);
105
106 if (!drawable)
107 drawable = _gdk_parent_root;
108
109 if (GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
110 return NULL;
111
112 GDK_NOTE (MISC, g_print ("gdk_pixmap_new: %dx%dx%d\n",
113 width, height, depth));
114
115 if (depth == -1)
116 depth = gdk_drawable_get_depth (GDK_DRAWABLE (drawable));
117
118 switch (depth)
119 {
120 case 1:
121 format = DSPF_A8;
122 break;
123 case 8:
124 format = DSPF_LUT8;
125 break;
126 case 15:
127 format = DSPF_ARGB1555;
128 break;
129 case 16:
130 format = DSPF_RGB16;
131 break;
132 case 24:
133 format = DSPF_RGB24;
134 break;
135 case 32:
136 format = DSPF_RGB32;
137 break;
138 default:
139 g_message ("unimplemented %s for depth %d", G_STRFUNC, depth);
140 return NULL;
141 }
142
143 if (!(surface =
144 gdk_display_dfb_create_surface (_gdk_display, format, width, height))) {
145 g_assert (surface != NULL);
146 return NULL;
147 }
148
149 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
150 draw_impl = GDK_DRAWABLE_IMPL_DIRECTFB (GDK_PIXMAP_OBJECT (pixmap)->impl);
151 draw_impl->surface = surface;
152 surface->Clear (surface, 0x0, 0x0, 0x0, 0x0);
153 surface->GetSize (surface, &draw_impl->width, &draw_impl->height);
154 surface->GetPixelFormat (surface, &draw_impl->format);
155
156 draw_impl->abs_x = draw_impl->abs_y = 0;
157
158 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
159
160 return pixmap;
161 }
162
163 GdkPixmap *
_gdk_bitmap_create_from_data(GdkDrawable * drawable,const gchar * data,gint width,gint height)164 _gdk_bitmap_create_from_data (GdkDrawable *drawable,
165 const gchar *data,
166 gint width,
167 gint height)
168 {
169 GdkPixmap *pixmap;
170
171 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
172 g_return_val_if_fail (data != NULL, NULL);
173 g_return_val_if_fail (width > 0 && height > 0, NULL);
174
175 GDK_NOTE (MISC, g_print ("gdk_bitmap_create_from_data: %dx%d\n",
176 width, height));
177
178 pixmap = gdk_pixmap_new (drawable, width, height, 1);
179
180 #define GET_PIXEL(data,pixel) \
181 ((data[(pixel / 8)] & (0x1 << ((pixel) % 8))) >> ((pixel) % 8))
182
183 if (pixmap)
184 {
185 guchar *dst;
186 gint pitch;
187
188 IDirectFBSurface *surface;
189
190 surface = GDK_DRAWABLE_IMPL_DIRECTFB (GDK_PIXMAP_OBJECT (pixmap)->impl)->surface;
191
192 if (surface->Lock (surface, DSLF_WRITE, (void**)(&dst), &pitch) == DFB_OK)
193 {
194 gint i, j;
195
196 for (i = 0; i < height; i++)
197 {
198 for (j = 0; j < width; j++)
199 {
200 dst[j] = GET_PIXEL (data, j) * 255;
201 }
202
203 data += (width + 7) / 8;
204 dst += pitch;
205 }
206
207 surface->Unlock (surface);
208 }
209 }
210
211 #undef GET_PIXEL
212
213 return pixmap;
214 }
215
216 GdkPixmap *
_gdk_pixmap_create_from_data(GdkDrawable * drawable,const gchar * data,gint width,gint height,gint depth,const GdkColor * fg,const GdkColor * bg)217 _gdk_pixmap_create_from_data (GdkDrawable *drawable,
218 const gchar *data,
219 gint width,
220 gint height,
221 gint depth,
222 const GdkColor *fg,
223 const GdkColor *bg)
224 {
225 GdkPixmap *pixmap;
226
227 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
228 g_return_val_if_fail (data != NULL, NULL);
229 g_return_val_if_fail (drawable != NULL || depth > 0, NULL);
230 g_return_val_if_fail (width > 0 && height > 0, NULL);
231
232 GDK_NOTE (MISC, g_print ("gdk_pixmap_create_from_data: %dx%dx%d\n",
233 width, height, depth));
234
235 pixmap = gdk_pixmap_new (drawable, width, height, depth);
236
237 if (pixmap)
238 {
239 IDirectFBSurface *surface;
240 gchar *dst;
241 gint pitch;
242 gint src_pitch;
243
244 depth = gdk_drawable_get_depth (pixmap);
245 src_pitch = width * ((depth + 7) / 8);
246
247 surface = GDK_DRAWABLE_IMPL_DIRECTFB (GDK_PIXMAP_OBJECT (pixmap)->impl)->surface;
248
249 if (surface->Lock (surface,
250 DSLF_WRITE, (void**)(&dst), &pitch) == DFB_OK)
251 {
252 gint i;
253
254 for (i = 0; i < height; i++)
255 {
256 memcpy (dst, data, src_pitch);
257 dst += pitch;
258 data += src_pitch;
259 }
260
261 surface->Unlock (surface);
262 }
263 }
264
265 return pixmap;
266 }
267
268 GdkPixmap *
gdk_pixmap_foreign_new(GdkNativeWindow anid)269 gdk_pixmap_foreign_new (GdkNativeWindow anid)
270 {
271 g_warning (" gdk_pixmap_foreign_new unsuporrted \n");
272 return NULL;
273 }
274
275 GdkPixmap *
gdk_pixmap_foreign_new_for_display(GdkDisplay * display,GdkNativeWindow anid)276 gdk_pixmap_foreign_new_for_display (GdkDisplay *display, GdkNativeWindow anid)
277 {
278 return gdk_pixmap_foreign_new (anid);
279 }
280
281 GdkPixmap *
gdk_pixmap_foreign_new_for_screen(GdkScreen * screen,GdkNativeWindow anid,gint width,gint height,gint depth)282 gdk_pixmap_foreign_new_for_screen (GdkScreen *screen,
283 GdkNativeWindow anid,
284 gint width,
285 gint height,
286 gint depth)
287 {
288 /*Use the root drawable for now since only one screen */
289 return gdk_pixmap_new (NULL, width, height, depth);
290 }
291
292
293 GdkPixmap *
gdk_pixmap_lookup(GdkNativeWindow anid)294 gdk_pixmap_lookup (GdkNativeWindow anid)
295 {
296 g_warning (" gdk_pixmap_lookup unsuporrted \n");
297 return NULL;
298 }
299
300 GdkPixmap *
gdk_pixmap_lookup_for_display(GdkDisplay * display,GdkNativeWindow anid)301 gdk_pixmap_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
302 {
303 return gdk_pixmap_lookup (anid);
304 }
305
306 #define __GDK_PIXMAP_X11_C__
307 #include "gdkaliasdef.c"
308