I just ran into a problem on DirectFB 1.0.1. I setup a layer surface, called
DrawString with no problem. I set the surface's Destination Color Key drawing
flag. I then called DrawString and observed that the resulting blits for
drawing the glyphs of the font utilized the surface's Dest Color Key flag. I
then disabled the flag by setting it to NOFX and called DrawString again. But
this time, the font continued to use Dest Color Key flag even though the
surface's flag had been cleared.
I followed the code down and it appears that when DrawString is called the
surface's CardState is intelligently copied into the font's CardState in the
function: setup_font_state:gfxcard.c. The offending code is:
if (state->drawingflags & DSDRAW_DST_COLORKEY) {
flags |= DSBLIT_DST_COLORKEY;
dfb_state_set_dst_colorkey( &font->state, state->dst_colorkey );
}
As can be seen, the flag is set conditionally, but never cleared. I admit to
being tempted to add the following:
else
{
flags &= ~DSBLIT_DST_COLOR_KEY;
}
but I am unaware if this is valid for other locations in the code. Can anyone
speak to this? Incidentally, this seems true for the other flags such as
DSDRAW_XOR and DSDRAW_BLEND.
For those that would like to see this in action, I have attached some sample
code that demonstrates this:
#include <stdio.h>
#include <unistd.h>
#include <directfb.h>
int main (int argc, char **argv)
{
IDirectFB *dfb = NULL;
DirectFBInit (&argc, &argv);
DirectFBCreate (&dfb);
IDirectFBDisplayLayer *pLayer;
dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &pLayer);
pLayer->SetCooperativeLevel(pLayer, DLSCL_EXCLUSIVE);
DFBFontDescription desc;
desc.height = 24;
desc.flags = DFDESC_HEIGHT;
IDirectFBFont *pFont;
dfb->CreateFont(dfb, "decker.ttf",&desc,&pFont);
IDirectFBSurface *pSurface;
pLayer->GetSurface(pLayer, &pSurface);
pSurface->SetFont(pSurface, pFont);
// Clear to Red
pSurface->Clear(pSurface, 0xFF, 0x00, 0x00, 0xFF);
// Draw Blue String
pSurface->SetColor(pSurface, 0x00, 0x00, 0xFF, 0xFF);
pSurface->DrawString(pSurface,
"Before Dest Color Key is set", -1,
100, 100, DSTF_LEFT);
// Set Destination Color Key Flag
pSurface->SetDrawingFlags(pSurface, DSDRAW_DST_COLORKEY);
// Set the Dest Color Key to Red
pSurface->SetDstColorKey(pSurface, 0xFF, 0x00, 0x00);
pSurface->DrawString(pSurface,
"DestColorKey:SET ColorKey:RED String:VISIBLE", -1,
100, 120, DSTF_LEFT);
// Set the Dest Color Key to something besides Red
pSurface->SetDstColorKey(pSurface, 0x00, 0xFF, 0x00);
pSurface->DrawString(pSurface,
"DestColorKey:SET ColorKey:GREEN String:NOT_VISIBLE",
-1,
100, 120, DSTF_LEFT);
// Clear Destination Color Key Flag
pSurface->SetDrawingFlags(pSurface, DSDRAW_NOFX);
pSurface->DrawString(pSurface,
"DestColorKey:CLEARED ColorKey:GREEN
String:SHOULD_BE_VISIBLE(But isn't)",
-1, 100, 140, DSTF_LEFT);
sleep(10);
pFont->Release(pFont);
pSurface->Release(pSurface);
pLayer->Release(pLayer);
dfb->Release( dfb );
return 0;
}
Thanks to anyone that can help me confirm if this is a bug or if I have just
done something wrong.
Bryce Poole
_______________________________________________
directfb-dev mailing list
[email protected]
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev