1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team.
26 * GTK+ DirectFB backend
27 * Copyright (C) 2001-2002 convergence integrated media GmbH
28 * Copyright (C) 2002-2004 convergence GmbH
29 * Written by Denis Oliver Kropp <dok@convergence.de> and
30 * Sven Neumann <sven@convergence.de>
37 #include "gdkdirectfb.h"
38 #include "gdkprivate-directfb.h"
40 #include "gdkinternals.h"
46 static GList *image_list = NULL;
47 static gpointer parent_class = NULL;
49 static void gdk_directfb_image_destroy (GdkImage *image);
50 static void gdk_image_init (GdkImage *image);
51 static void gdk_image_class_init (GdkImageClass *klass);
52 static void gdk_image_finalize (GObject *object);
55 gdk_image_get_type (void)
57 static GType object_type = 0;
61 static const GTypeInfo object_info =
63 sizeof (GdkImageClass),
65 (GBaseFinalizeFunc) NULL,
66 (GClassInitFunc) gdk_image_class_init,
67 NULL, /* class_finalize */
68 NULL, /* class_data */
71 (GInstanceInitFunc) gdk_image_init,
74 object_type = g_type_register_static (G_TYPE_OBJECT,
83 gdk_image_init (GdkImage *image)
85 image->windowing_data = g_new0 (GdkImageDirectFB, 1);
88 image_list = g_list_prepend (image_list, image);
92 gdk_image_class_init (GdkImageClass *klass)
94 GObjectClass *object_class = G_OBJECT_CLASS (klass);
96 parent_class = g_type_class_peek_parent (klass);
98 object_class->finalize = gdk_image_finalize;
102 gdk_image_finalize (GObject *object)
106 image = GDK_IMAGE (object);
108 image_list = g_list_remove (image_list, image);
110 if (image->depth == 1)
113 gdk_directfb_image_destroy (image);
115 if (G_OBJECT_CLASS (parent_class)->finalize)
116 G_OBJECT_CLASS (parent_class)->finalize (object);
120 /* this function is called from the atexit handler! */
122 _gdk_image_exit (void)
128 image = image_list->data;
130 gdk_image_finalize (image);
135 gdk_image_new_bitmap (GdkVisual *visual,
141 GdkImageDirectFB *private;
143 image = g_object_new (gdk_image_get_type (), NULL);
144 private = image->windowing_data;
146 image->type = GDK_IMAGE_SHARED;
147 image->visual = visual;
152 GDK_NOTE (MISC, g_print ("gdk_image_new_bitmap: %dx%d\n", w, h));
154 g_message ("not fully implemented %s", __FUNCTION__);
156 image->bpl = (w + 7) / 8;
157 image->mem = g_malloc (image->bpl * h);
158 #if G_BYTE_ORDER == G_BIG_ENDIAN
159 image->byte_order = GDK_MSB_FIRST;
161 image->byte_order = GDK_LSB_FIRST;
169 _gdk_windowing_image_init (void)
174 _gdk_image_new_for_depth (GdkScreen *screen,
182 GdkImageDirectFB *private;
185 DFBSurfacePixelFormat format;
186 IDirectFBSurface *surface;
188 if (type == GDK_IMAGE_FASTEST || type == GDK_IMAGE_NORMAL)
189 type = GDK_IMAGE_SHARED;
192 depth = visual->depth;
200 format = DSPF_ARGB1555;
212 g_message ("unimplemented %s for depth %d", __FUNCTION__, depth);
216 surface = gdk_display_dfb_create_surface(_gdk_display,format,width,height);
221 surface->GetPixelFormat( surface, &format );
223 image = g_object_new (gdk_image_get_type (), NULL);
224 private = image->windowing_data;
226 private->surface = surface;
228 ret = surface->Lock( surface, DSLF_WRITE, &image->mem, &pitch );
231 DirectFBError( "IDirectFBSurface::Lock() for writing failed!\n", ret );
232 gdk_image_unref( image );
237 image->visual = visual;
238 #if G_BYTE_ORDER == G_BIG_ENDIAN
239 image->byte_order = GDK_MSB_FIRST;
241 image->byte_order = GDK_LSB_FIRST;
243 image->width = width;
244 image->height = height;
245 image->depth = depth;
246 image->bpp = DFB_BYTES_PER_PIXEL (format);
248 image->bits_per_pixel = DFB_BITS_PER_PIXEL (format);
250 image_list = g_list_prepend (image_list, image);
257 _gdk_directfb_copy_to_image (GdkDrawable *drawable,
266 GdkDrawableImplDirectFB *impl;
267 GdkImageDirectFB *private;
269 DFBRectangle rect = { src_x, src_y, width, height };
270 IDirectFBDisplayLayer *layer = _gdk_display->layer;
272 g_return_val_if_fail (GDK_IS_DRAWABLE_IMPL_DIRECTFB (drawable), NULL);
273 g_return_val_if_fail (image != NULL || (dest_x == 0 && dest_y == 0), NULL);
275 impl = GDK_DRAWABLE_IMPL_DIRECTFB (drawable);
277 if (impl->wrapper == _gdk_parent_root)
281 ret = layer->SetCooperativeLevel (layer, DLSCL_EXCLUSIVE);
284 DirectFBError ("_gdk_directfb_copy_to_image - SetCooperativeLevel",
289 ret = layer->GetSurface (layer, &impl->surface);
292 layer->SetCooperativeLevel (layer, DLSCL_SHARED);
293 DirectFBError ("_gdk_directfb_copy_to_image - GetSurface", ret);
302 image = gdk_image_new (GDK_IMAGE_NORMAL,
303 gdk_visual_get_system (), width, height);
305 private = image->windowing_data;
307 private->surface->Unlock( private->surface );
309 private->surface->Blit( private->surface,
310 impl->surface, &rect, dest_x, dest_y );
312 private->surface->Lock( private->surface, DSLF_WRITE, &image->mem, &pitch );
315 if (impl->wrapper == _gdk_parent_root)
317 impl->surface->Release (impl->surface);
318 impl->surface = NULL;
319 layer->SetCooperativeLevel (layer, DLSCL_SHARED);
326 gdk_image_get_pixel (GdkImage *image,
332 g_return_val_if_fail (GDK_IS_IMAGE (image), 0);
334 if (!(x >= 0 && x < image->width && y >= 0 && y < image->height))
337 if (image->depth == 1)
338 pixel = (((guchar *) image->mem)[y * image->bpl + (x >> 3)] & (1 << (7 - (x & 0x7)))) != 0;
341 guchar *pixelp = (guchar *) image->mem + y * image->bpl + x * image->bpp;
350 pixel = pixelp[0] | (pixelp[1] << 8);
354 pixel = pixelp[0] | (pixelp[1] << 8) | (pixelp[2] << 16);
358 pixel = pixelp[0] | (pixelp[1] << 8) | (pixelp[2] << 16);
367 gdk_image_put_pixel (GdkImage *image,
372 g_return_if_fail (image != NULL);
374 if (!(x >= 0 && x < image->width && y >= 0 && y < image->height))
377 if (image->depth == 1)
379 ((guchar *) image->mem)[y * image->bpl + (x >> 3)] |= (1 << (7 - (x & 0x7)));
381 ((guchar *) image->mem)[y * image->bpl + (x >> 3)] &= ~(1 << (7 - (x & 0x7)));
384 guchar *pixelp = (guchar *) image->mem + y * image->bpl + x * image->bpp;
391 pixelp[2] = ((pixel >> 16) & 0xFF);
393 pixelp[1] = ((pixel >> 8) & 0xFF);
395 pixelp[0] = (pixel & 0xFF);
401 gdk_directfb_image_destroy (GdkImage *image)
403 GdkImageDirectFB *private;
405 g_return_if_fail (GDK_IS_IMAGE (image));
407 private = image->windowing_data;
412 GDK_NOTE (MISC, g_print ("gdk_directfb_image_destroy: %#lx\n",
413 (gulong) private->surface));
415 private->surface->Unlock( private->surface );
416 private->surface->Release( private->surface );
419 image->windowing_data = NULL;
423 _gdk_windowing_get_bits_for_depth (GdkDisplay *display,
442 #define __GDK_IMAGE_X11_C__
443 #include "gdkaliasdef.c"