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
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.
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.
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.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team.
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>
40 #include "gdkdirectfb.h"
41 #include "gdkprivate-directfb.h"
43 #include "gdkinternals.h"
45 #include "gdkpixmap.h"
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);
54 static gpointer parent_class = NULL;
58 gdk_pixmap_impl_directfb_get_type (void)
60 static GType object_type = 0;
64 static const GTypeInfo object_info =
66 sizeof (GdkPixmapImplDirectFBClass),
68 (GBaseFinalizeFunc) NULL,
69 (GClassInitFunc) gdk_pixmap_impl_directfb_class_init,
70 NULL, /* class_finalize */
71 NULL, /* class_data */
72 sizeof (GdkPixmapImplDirectFB),
74 (GInstanceInitFunc) gdk_pixmap_impl_directfb_init,
77 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_DIRECTFB,
78 "GdkPixmapImplDirectFB",
86 _gdk_pixmap_impl_get_type (void)
88 return gdk_pixmap_impl_directfb_get_type ();
92 gdk_pixmap_impl_directfb_init (GdkPixmapImplDirectFB *impl)
94 GdkDrawableImplDirectFB *draw_impl = GDK_DRAWABLE_IMPL_DIRECTFB (impl);
96 draw_impl->height = 1;
100 gdk_pixmap_impl_directfb_class_init (GdkPixmapImplDirectFBClass *klass)
102 GObjectClass *object_class = G_OBJECT_CLASS (klass);
104 parent_class = g_type_class_peek_parent (klass);
106 object_class->finalize = gdk_pixmap_impl_directfb_finalize;
110 gdk_pixmap_impl_directfb_finalize (GObject *object)
112 if (G_OBJECT_CLASS (parent_class)->finalize)
113 G_OBJECT_CLASS (parent_class)->finalize (object);
117 gdk_pixmap_new (GdkDrawable *drawable,
122 DFBSurfacePixelFormat format;
123 IDirectFBSurface *surface;
125 GdkDrawableImplDirectFB *draw_impl;
127 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
128 g_return_val_if_fail (drawable != NULL || depth != -1, NULL);
129 g_return_val_if_fail (width > 0 && height > 0, NULL);
132 drawable = _gdk_parent_root;
134 if (GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
137 GDK_NOTE (MISC, g_print ("gdk_pixmap_new: %dx%dx%d\n",
138 width, height, depth));
143 GDK_DRAWABLE_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (drawable)->impl);
145 g_return_val_if_fail (draw_impl != NULL, NULL);
147 draw_impl->surface->GetPixelFormat (draw_impl->surface, &format);
148 depth = DFB_BITS_PER_PIXEL (format);
161 format = DSPF_ARGB1555;
173 g_message ("unimplemented %s for depth %d", __FUNCTION__, depth);
179 gdk_display_dfb_create_surface(_gdk_display,format,width,height) )) {
180 g_assert( surface != NULL);
184 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
185 draw_impl = GDK_DRAWABLE_IMPL_DIRECTFB (GDK_PIXMAP_OBJECT (pixmap)->impl);
186 draw_impl->surface = surface;
187 surface->Clear (surface, 0x0, 0x0, 0x0, 0x0);
188 surface->GetSize (surface, &draw_impl->width, &draw_impl->height);
189 surface->GetPixelFormat (surface, &draw_impl->format);
191 draw_impl->abs_x = draw_impl->abs_y = 0;
193 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
199 gdk_bitmap_create_from_data (GdkDrawable *drawable,
206 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
207 g_return_val_if_fail (data != NULL, NULL);
208 g_return_val_if_fail (width > 0 && height > 0, NULL);
210 GDK_NOTE (MISC, g_print ("gdk_bitmap_create_from_data: %dx%d\n",
213 pixmap = gdk_pixmap_new (drawable, width, height, 1);
215 #define GET_PIXEL(data,pixel) \
216 ((data[(pixel / 8)] & (0x1 << ((pixel) % 8))) >> ((pixel) % 8))
223 IDirectFBSurface *surface;
225 surface = GDK_DRAWABLE_IMPL_DIRECTFB (GDK_PIXMAP_OBJECT (pixmap)->impl)->surface;
227 if (surface->Lock( surface, DSLF_WRITE, (void**)(&dst), &pitch ) == DFB_OK)
231 for (i = 0; i < height; i++)
233 for (j = 0; j < width; j++)
235 dst[j] = GET_PIXEL (data, j) * 255;
238 data += (width + 7) / 8;
242 surface->Unlock( surface );
252 gdk_pixmap_create_from_data (GdkDrawable *drawable,
262 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
263 g_return_val_if_fail (data != NULL, NULL);
264 g_return_val_if_fail (drawable != NULL || depth > 0, NULL);
265 g_return_val_if_fail (width > 0 && height > 0, NULL);
267 GDK_NOTE (MISC, g_print ("gdk_pixmap_create_from_data: %dx%dx%d\n",
268 width, height, depth));
270 pixmap = gdk_pixmap_new (drawable, width, height, depth);
274 IDirectFBSurface *surface;
279 depth = gdk_drawable_get_depth (pixmap);
280 src_pitch = width * ((depth + 7) / 8);
282 surface = GDK_DRAWABLE_IMPL_DIRECTFB (GDK_PIXMAP_OBJECT (pixmap)->impl)->surface;
284 if (surface->Lock( surface,
285 DSLF_WRITE, (void**)(&dst), &pitch ) == DFB_OK)
289 for (i = 0; i < height; i++)
291 memcpy (dst, data, src_pitch);
296 surface->Unlock( surface );
304 gdk_pixmap_foreign_new (GdkNativeWindow anid)
306 g_warning(" gdk_pixmap_foreign_new unsuporrted \n");
311 gdk_pixmap_foreign_new_for_display (GdkDisplay *display, GdkNativeWindow anid)
313 return gdk_pixmap_foreign_new(anid);
317 gdk_pixmap_foreign_new_for_screen (GdkScreen *screen,
318 GdkNativeWindow anid,
323 /*Use the root drawable for now since only one screen */
324 return gdk_pixmap_new(NULL,width,height,depth);
329 gdk_pixmap_lookup (GdkNativeWindow anid)
331 g_warning(" gdk_pixmap_lookup unsuporrted \n");
335 GdkPixmap* gdk_pixmap_lookup_for_display (GdkDisplay *display,GdkNativeWindow anid)
337 return gdk_pixmap_lookup (anid);
340 #define __GDK_PIXMAP_X11_C__
341 #include "gdkaliasdef.c"