This patch adds a new window capability DWCAPS_COLOR. What it does is that
the window doesn't have a surface and is just filled with a constant
color. Working with tvtime inspired me to do this. No point in wasting
video ram for for a window that only acts as a container for a layer.
I had to change the window resize function slightly to get the window
properly drawn after a resizing it to a larger size. How did windows with
a surface handle this?
--
Ville Syrj�l�
[EMAIL PROTECTED]
http://www.sci.fi/~syrjala/
Index: include/directfb.h
===================================================================
RCS file: /cvs/directfb/DirectFB/include/directfb.h,v
retrieving revision 1.188
diff -u -r1.188 directfb.h
--- include/directfb.h 18 Aug 2003 17:27:30 -0000 1.188
+++ include/directfb.h 26 Sep 2003 22:54:33 -0000
@@ -697,7 +697,10 @@
DWCAPS_INPUTONLY = 0x00000004, /* The window has no surface.
You can not draw to it but it
receives events */
- DWCAPS_ALL = 0x00000007 /* All valid flags. */
+ DWCAPS_COLOR = 0x00000008, /* The window has no surface.
+ It is filled with a constant color
+ and it receives events */
+ DWCAPS_ALL = 0x0000000F /* All valid flags. */
} DFBWindowCapabilities;
@@ -3161,6 +3164,16 @@
DFBWindowOptions *options
);
+ /*
+ * Set the window color for a DWCAPS_COLOR window.
+ */
+ DFBResult (*SetColor) (
+ IDirectFBWindow *thiz,
+ __u8 r,
+ __u8 g,
+ __u8 b
+ );
+
/*
* Set the window color key.
*
Index: src/core/windows.c
===================================================================
RCS file: /cvs/directfb/DirectFB/src/core/windows.c,v
retrieving revision 1.173
diff -u -r1.173 windows.c
--- src/core/windows.c 27 Aug 2003 17:39:15 -0000 1.173
+++ src/core/windows.c 26 Sep 2003 22:54:35 -0000
@@ -389,7 +389,7 @@
w = (CoreWindow*) fusion_object_create( stack->pool );
/* Create the window's surface using the layer's palette. */
- if (! (caps & DWCAPS_INPUTONLY)) {
+ if (! (caps & (DWCAPS_INPUTONLY | DWCAPS_COLOR))) {
ret = dfb_surface_create( width, height, pixelformat, surface_policy,
surface_caps, layer_surface->palette,
&surface );
@@ -807,18 +807,18 @@
}
if (VISIBLE_WINDOW (window)) {
- if (ow > window->width) {
- DFBRegion region = { window->x + window->width, window->y,
- window->x + ow - 1,
+ if (ow != window->width) {
+ DFBRegion region = { window->x + MIN(window->width, ow), window->y,
+ window->x + MAX(window->width, ow) - 1,
window->y + MIN(window->height, oh) - 1};
repaint_stack_window_changed( stack, ®ion, 0,
get_window_index(window) );
}
- if (oh > window->height) {
- DFBRegion region = { window->x, window->y + window->height,
+ if (oh != window->height) {
+ DFBRegion region = { window->x, window->y + MIN(window->height, oh),
window->x + MAX(window->width, ow) - 1,
- window->y + oh - 1};
+ window->y + MAX(window->height, oh) - 1};
repaint_stack_window_changed( stack, ®ion, 0,
get_window_index(window) );
}
@@ -1305,56 +1305,91 @@
draw_window( CoreWindow *window, CardState *state,
DFBRegion *region, bool alpha_channel )
{
- DFBRectangle srect;
- DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
-
DFB_ASSERT( window != NULL );
DFB_ASSERT( state != NULL );
DFB_ASSERT( region != NULL );
- srect.x = region->x1 - window->x;
- srect.y = region->y1 - window->y;
- srect.w = region->x2 - region->x1 + 1;
- srect.h = region->y2 - region->y1 + 1;
+ if (window->caps & DWCAPS_COLOR) {
+ CoreSurface *dest = state->destination;
+ DFBColor *color = &window->color;
+ DFBRectangle rect;
+ DFBSurfaceDrawingFlags flags = DSDRAW_NOFX;
+
+ color->a = window->opacity;
+ if (window->opacity != 0xFF)
+ flags |= DSDRAW_BLEND;
+
+ state->color = *color;
+
+ if (DFB_PIXELFORMAT_IS_INDEXED( dest->format ))
+ state->color_index = dfb_palette_search( dest->palette,
+ color->r,
+ color->g,
+ color->b,
+ color->a );
+
+ state->modified |= SMF_COLOR;
+
+ if (state->drawingflags != flags) {
+ state->drawingflags = flags;
+ state->modified |= SMF_DRAWING_FLAGS;
+ }
- if (alpha_channel && (window->options & DWOP_ALPHACHANNEL))
- flags |= DSBLIT_BLEND_ALPHACHANNEL;
+ rect.x = region->x1;
+ rect.y = region->y1;
+ rect.w = region->x2 - region->x1 + 1;
+ rect.h = region->y2 - region->y1 + 1;
+
+ dfb_gfxcard_fillrectangle( &rect, state );
+ } else {
+ DFBRectangle srect;
+ DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
+
+ srect.x = region->x1 - window->x;
+ srect.y = region->y1 - window->y;
+ srect.w = region->x2 - region->x1 + 1;
+ srect.h = region->y2 - region->y1 + 1;
- if (window->opacity != 0xFF) {
- flags |= DSBLIT_BLEND_COLORALPHA;
+ if (alpha_channel && (window->options & DWOP_ALPHACHANNEL))
+ flags |= DSBLIT_BLEND_ALPHACHANNEL;
- if (state->color.a != window->opacity) {
- state->color.a = window->opacity;
- state->modified |= SMF_COLOR;
+ if (window->opacity != 0xFF) {
+ flags |= DSBLIT_BLEND_COLORALPHA;
+
+ if (state->color.a != window->opacity) {
+ state->color.a = window->opacity;
+ state->modified |= SMF_COLOR;
+ }
}
- }
- if (window->options & DWOP_COLORKEYING) {
- flags |= DSBLIT_SRC_COLORKEY;
+ if (window->options & DWOP_COLORKEYING) {
+ flags |= DSBLIT_SRC_COLORKEY;
- if (state->src_colorkey != window->color_key) {
- state->src_colorkey = window->color_key;
- state->modified |= SMF_SRC_COLORKEY;
+ if (state->src_colorkey != window->color_key) {
+ state->src_colorkey = window->color_key;
+ state->modified |= SMF_SRC_COLORKEY;
+ }
}
- }
- if (window->surface->caps & DSCAPS_INTERLACED)
- flags |= DSBLIT_DEINTERLACE;
+ if (window->surface->caps & DSCAPS_INTERLACED)
+ flags |= DSBLIT_DEINTERLACE;
- if (state->blittingflags != flags) {
- state->blittingflags = flags;
- state->modified |= SMF_BLITTING_FLAGS;
- }
-
- state->source = window->surface;
- state->modified |= SMF_SOURCE;
+ if (state->blittingflags != flags) {
+ state->blittingflags = flags;
+ state->modified |= SMF_BLITTING_FLAGS;
+ }
- dfb_gfxcard_blit( &srect, region->x1, region->y1, state );
+ state->source = window->surface;
+ state->modified |= SMF_SOURCE;
+
+ dfb_gfxcard_blit( &srect, region->x1, region->y1, state );
- state->source = NULL;
- state->modified |= SMF_SOURCE;
+ state->source = NULL;
+ state->modified |= SMF_SOURCE;
+ }
}
+
static void
draw_background( CoreWindowStack *stack, CardState *state, DFBRegion *region )
{
@@ -1380,6 +1415,11 @@
color->a );
state->modified |= SMF_COLOR;
+
+ if (state->drawingflags != DSDRAW_NOFX) {
+ state->drawingflags = DSDRAW_NOFX;
+ state->modified |= SMF_DRAWING_FLAGS;
+ }
dfb_gfxcard_fillrectangle( &rect, state );
break;
Index: src/core/windows.h
===================================================================
RCS file: /cvs/directfb/DirectFB/src/core/windows.h,v
retrieving revision 1.47
diff -u -r1.47 windows.h
--- src/core/windows.h 8 Aug 2003 21:52:49 -0000 1.47
+++ src/core/windows.h 26 Sep 2003 22:54:35 -0000
@@ -72,6 +72,8 @@
__u8 opacity; /* global alpha factor */
__u32 color_key; /* transparent pixel */
+ DFBColor color; /* DWCAPS_COLOR window color */
+
CoreSurface *surface; /* backing store surface */
CoreWindowStack *stack; /* window stack the window belongs */
Index: src/windows/idirectfbwindow.c
===================================================================
RCS file: /cvs/directfb/DirectFB/src/windows/idirectfbwindow.c,v
retrieving revision 1.66
diff -u -r1.66 idirectfbwindow.c
--- src/windows/idirectfbwindow.c 27 Aug 2003 17:39:15 -0000 1.66
+++ src/windows/idirectfbwindow.c 26 Sep 2003 22:54:35 -0000
@@ -62,6 +62,7 @@
#include <misc/mem.h>
#include <gfx/convert.h>
+#include <gfx/util.h>
#include <windows/idirectfbwindow.h>
@@ -380,6 +381,32 @@
}
static DFBResult
+IDirectFBWindow_SetColor( IDirectFBWindow *thiz,
+ __u8 r,
+ __u8 g,
+ __u8 b )
+{
+ DFBColor color = { a: 0xFF, r: r, g: g, b: b };
+
+ INTERFACE_GET_DATA(IDirectFBWindow)
+
+ if (data->destroyed)
+ return DFB_DESTROYED;
+
+ if (!(data->window->caps & DWCAPS_COLOR))
+ return DFB_UNSUPPORTED;
+
+ if (dfb_colors_equal( &data->window->color, &color ))
+ return DFB_OK;
+
+ data->window->color = color;
+
+ dfb_window_repaint( data->window, NULL, 0 );
+
+ return DFB_OK;
+}
+
+static DFBResult
IDirectFBWindow_SetColorKey( IDirectFBWindow *thiz,
__u8 r,
__u8 g,
@@ -880,6 +907,7 @@
thiz->GetSurface = IDirectFBWindow_GetSurface;
thiz->SetOptions = IDirectFBWindow_SetOptions;
thiz->GetOptions = IDirectFBWindow_GetOptions;
+ thiz->SetColor = IDirectFBWindow_SetColor;
thiz->SetColorKey = IDirectFBWindow_SetColorKey;
thiz->SetColorKeyIndex = IDirectFBWindow_SetColorKeyIndex;
thiz->SetOpaqueRegion = IDirectFBWindow_SetOpaqueRegion;