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 convergence GmbH
29
* Written by Denis Oliver Kropp <dok@convergence.de> and
30
* Sven Neumann <sven@convergence.de>
41
#include "gdkdirectfb.h"
42
#include "gdkprivate-directfb.h"
44
#include "gdkinternals.h"
52
IDirectFBPalette *palette;
53
} GdkColormapPrivateDirectFB;
56
static void gdk_colormap_init (GdkColormap *colormap);
57
static void gdk_colormap_class_init (GdkColormapClass *klass);
58
static void gdk_colormap_finalize (GObject *object);
60
static gint gdk_colormap_alloc_pseudocolors (GdkColormap *colormap,
66
static void gdk_directfb_allocate_color_key (GdkColormap *colormap);
69
static GObjectClass *parent_class = NULL;
73
gdk_colormap_get_type (void)
75
static GType object_type = 0;
78
static const GTypeInfo object_info =
80
sizeof (GdkColormapClass),
82
(GBaseFinalizeFunc) NULL,
83
(GClassInitFunc) gdk_colormap_class_init,
84
NULL, /* class_finalize */
85
NULL, /* class_data */
88
(GInstanceInitFunc) gdk_colormap_init,
91
object_type = g_type_register_static (G_TYPE_OBJECT,
100
gdk_colormap_init (GdkColormap *colormap)
103
colormap->colors = NULL;
104
colormap->windowing_data = NULL;
108
gdk_colormap_class_init (GdkColormapClass *klass)
110
GObjectClass *object_class = G_OBJECT_CLASS (klass);
112
parent_class = g_type_class_peek_parent (klass);
114
object_class->finalize = gdk_colormap_finalize;
118
gdk_colormap_finalize (GObject *object)
120
GdkColormap *colormap = GDK_COLORMAP (object);
121
GdkColormapPrivateDirectFB *private = colormap->windowing_data;
123
g_free (colormap->colors);
124
colormap->colors = NULL;
128
g_free (private->info);
130
if (private->palette)
131
private->palette->Release (private->palette);
134
colormap->windowing_data = NULL;
137
G_OBJECT_CLASS (parent_class)->finalize (object);
141
gdk_colormap_new (GdkVisual *visual,
142
gboolean private_cmap)
144
GdkColormap *colormap;
147
g_return_val_if_fail (visual != NULL, NULL);
149
colormap = g_object_new (gdk_colormap_get_type (), NULL);
150
colormap->visual = visual;
151
colormap->size = visual->colormap_size;
153
switch (visual->type)
155
case GDK_VISUAL_PSEUDO_COLOR:
157
GdkColormapPrivateDirectFB *private;
158
DFBPaletteDescription dsc;
160
colormap->colors = g_new0 (GdkColor, colormap->size);
162
private = g_new0 (GdkColormapPrivateDirectFB, 1);
163
private->info = g_new0 (GdkColorInfo, colormap->size);
165
if (visual == gdk_visual_get_system())
167
/* save the first (transparent) palette entry */
168
private->info[0].ref_count++;
171
dsc.flags = DPDESC_SIZE;
172
dsc.size = colormap->size;
173
_gdk_display->directfb->CreatePalette (
174
_gdk_display->directfb, &dsc, &private->palette);
176
colormap->windowing_data = private;
178
gdk_directfb_allocate_color_key (colormap);
182
case GDK_VISUAL_STATIC_COLOR:
183
colormap->colors = g_new0 (GdkColor, colormap->size);
184
for (i = 0; i < colormap->size; i++)
186
GdkColor *color = colormap->colors + i;
189
color->red = (i & 0xE0) << 8 | (i & 0xE0);
190
color->green = (i & 0x1C) << 11 | (i & 0x1C) << 3;
191
color->blue = (i & 0x03) << 14 | (i & 0x03) << 6;
203
gdk_colormap_get_screen (GdkColormap *cmap)
209
gdk_screen_get_system_colormap (GdkScreen *screen)
211
static GdkColormap *colormap = NULL;
215
GdkVisual *visual = gdk_visual_get_system();
217
/* special case PSEUDO_COLOR to use the system palette */
218
if (visual->type == GDK_VISUAL_PSEUDO_COLOR)
220
GdkColormapPrivateDirectFB *private;
221
IDirectFBSurface *surface;
223
colormap = g_object_new (gdk_colormap_get_type (), NULL);
225
colormap->visual = visual;
226
colormap->size = visual->colormap_size;
227
colormap->colors = g_new0 (GdkColor, colormap->size);
229
private = g_new0 (GdkColormapPrivateDirectFB, 1);
230
private->info = g_new0 (GdkColorInfo, colormap->size);
232
surface=GDK_WINDOW_IMPL_DIRECTFB (
233
GDK_WINDOW_OBJECT (_gdk_parent_root)->impl)->drawable.surface;
234
surface->GetPalette (surface, &private->palette);
236
colormap->windowing_data = private;
238
/* save the first (transparent) palette entry */
239
private->info[0].ref_count++;
241
gdk_directfb_allocate_color_key (colormap);
245
colormap = gdk_colormap_new (visual, FALSE);
253
gdk_colormap_get_system_size (void)
257
visual = gdk_visual_get_system ();
259
return visual->colormap_size;
263
gdk_colormap_change (GdkColormap *colormap,
266
g_message ("gdk_colormap_change() is deprecated and unimplemented");
270
gdk_colors_alloc (GdkColormap *colormap,
277
/* g_message ("gdk_colors_alloc() is deprecated and unimplemented"); */
279
return TRUE; /* return TRUE here to make GdkRGB happy */
283
gdk_colors_free (GdkColormap *colormap,
288
/* g_message ("gdk_colors_free() is deprecated and unimplemented"); */
292
gdk_colormap_free_colors (GdkColormap *colormap,
296
GdkColormapPrivateDirectFB *private;
299
g_return_if_fail (GDK_IS_COLORMAP (colormap));
300
g_return_if_fail (colors != NULL);
302
private = colormap->windowing_data;
306
for (i = 0; i < ncolors; i++)
308
gint index = colors[i].pixel;
310
if (index < 0 || index >= colormap->size)
313
if (private->info[index].ref_count)
314
private->info[index].ref_count--;
319
gdk_colormap_alloc_colors (GdkColormap *colormap,
329
g_return_val_if_fail (GDK_IS_COLORMAP (colormap), 0);
330
g_return_val_if_fail (colors != NULL, 0);
331
g_return_val_if_fail (success != NULL, 0);
333
switch (colormap->visual->type)
335
case GDK_VISUAL_TRUE_COLOR:
336
visual = colormap->visual;
338
for (i = 0; i < ncolors; i++)
342
>> (16 - visual->red_prec)) << visual->red_shift) +
344
>> (16 - visual->green_prec)) << visual->green_shift) +
346
>> (16 - visual->blue_prec)) << visual->blue_shift));
352
case GDK_VISUAL_PSEUDO_COLOR:
353
return gdk_colormap_alloc_pseudocolors (colormap,
355
writeable, best_match,
359
case GDK_VISUAL_STATIC_COLOR:
360
for (i = 0; i < ncolors; i++)
362
colors[i].pixel = (((colors[i].red & 0xE000) >> 8) |
363
((colors[i].green & 0xE000) >> 11) |
364
((colors[i].blue & 0xC000) >> 14));
370
for (i = 0; i < ncolors; i++)
379
gdk_color_change (GdkColormap *colormap,
382
GdkColormapPrivateDirectFB *private;
383
IDirectFBPalette *palette;
385
g_return_val_if_fail (GDK_IS_COLORMAP (colormap), FALSE);
386
g_return_val_if_fail (color != NULL, FALSE);
388
private = colormap->windowing_data;
392
palette = private->palette;
396
if (color->pixel < 0 || color->pixel >= colormap->size)
399
if (private->info[color->pixel].flags & GDK_COLOR_WRITEABLE)
401
DFBColor entry = { 0xFF,
406
if (palette->SetEntries (palette, &entry, 1, color->pixel) != DFB_OK)
409
colormap->colors[color->pixel] = *color;
417
gdk_colormap_query_color (GdkColormap *colormap,
423
g_return_if_fail (GDK_IS_COLORMAP (colormap));
425
visual = gdk_colormap_get_visual (colormap);
427
switch (visual->type)
429
case GDK_VISUAL_TRUE_COLOR:
430
result->red = 65535. *
431
(gdouble)((pixel & visual->red_mask) >> visual->red_shift) /
432
((1 << visual->red_prec) - 1);
434
result->green = 65535. *
435
(gdouble)((pixel & visual->green_mask) >> visual->green_shift) /
436
((1 << visual->green_prec) - 1);
438
result->blue = 65535. *
439
(gdouble)((pixel & visual->blue_mask) >> visual->blue_shift) /
440
((1 << visual->blue_prec) - 1);
443
case GDK_VISUAL_STATIC_COLOR:
444
case GDK_VISUAL_PSEUDO_COLOR:
445
if (pixel >= 0 && pixel < colormap->size)
447
result->red = colormap->colors[pixel].red;
448
result->green = colormap->colors[pixel].green;
449
result->blue = colormap->colors[pixel].blue;
452
g_warning ("gdk_colormap_query_color: pixel outside colormap");
455
case GDK_VISUAL_DIRECT_COLOR:
456
case GDK_VISUAL_GRAYSCALE:
457
case GDK_VISUAL_STATIC_GRAY:
459
g_assert_not_reached ();
465
gdk_directfb_colormap_get_palette (GdkColormap *colormap)
467
GdkColormapPrivateDirectFB *private;
469
g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL);
471
private = colormap->windowing_data;
473
if (private && private->palette)
474
return private->palette;
480
gdk_colormap_alloc_pseudocolors (GdkColormap *colormap,
487
GdkColormapPrivateDirectFB *private = colormap->windowing_data;
488
IDirectFBPalette *palette;
490
gint remaining = ncolors;
492
palette = private->palette;
494
for (i = 0; i < ncolors; i++)
497
DFBColor lookup = { 0xFF,
499
colors[i].green >> 8,
500
colors[i].blue >> 8 };
506
/* look for an empty slot and allocate a new color */
507
for (j = 0; j < colormap->size; j++)
508
if (private->info[j].ref_count == 0)
512
palette->SetEntries (palette, &lookup, 1, index);
514
private->info[index].flags = GDK_COLOR_WRITEABLE;
516
colors[i].pixel = index;
517
colormap->colors[index] = colors[i];
524
palette->FindBestMatch (palette,
525
lookup.r, lookup.g, lookup.b, lookup.a,
528
if (index < 0 || index > colormap->size)
531
/* check if we have an exact (non-writeable) match */
532
if (private->info[index].ref_count &&
533
!(private->info[index].flags & GDK_COLOR_WRITEABLE))
537
palette->GetEntries (palette, &entry, 1, index);
539
if (entry.a == 0xFF &&
540
entry.r == lookup.r && entry.g == lookup.g && entry.b == lookup.b)
542
colors[i].pixel = index;
548
/* look for an empty slot and allocate a new color */
549
for (j = 0; j < colormap->size; j++)
550
if (private->info[j].ref_count == 0)
554
palette->SetEntries (palette, &lookup, 1, index);
555
private->info[index].flags = 0;
557
colors[i].pixel = index;
558
colormap->colors[index] = colors[i];
563
/* if that failed, use the best match */
565
!(private->info[index].flags & GDK_COLOR_WRITEABLE))
568
g_print ("best match for (%d %d %d) ",
569
colormap->colors[index].red,
570
colormap->colors[index].green,
571
colormap->colors[index].blue);
574
colors[i].pixel = index;
580
/* if we got here, all attempts failed */
584
private->info[index].ref_count++;
587
g_print ("cmap %p: allocated (%d %d %d) %d [%d]\n", colormap,
588
colors[i].red, colors[i].green, colors[i].blue, colors[i].pixel,
589
private->info[index].ref_count);
599
/* dirty hack for color_keying */
601
gdk_directfb_allocate_color_key (GdkColormap *colormap)
603
GdkColormapPrivateDirectFB *private = colormap->windowing_data;
604
IDirectFBPalette *palette = private->palette;
606
if (!gdk_directfb_enable_color_keying)
609
palette->SetEntries (palette, &gdk_directfb_bg_color, 1, 255);
611
colormap->colors[255].pixel = 255;
612
colormap->colors[255].red = ((gdk_directfb_bg_color_key.r << 8)
613
| gdk_directfb_bg_color_key.r);
614
colormap->colors[255].green = ((gdk_directfb_bg_color_key.g << 8)
615
| gdk_directfb_bg_color_key.g);
616
colormap->colors[255].blue = ((gdk_directfb_bg_color_key.b << 8)
617
| gdk_directfb_bg_color_key.b);
619
private->info[255].ref_count++;
622
#define __GDK_COLOR_X11_C__
623
#include "gdkaliasdef.c"