static int PrepareDraw(SDL_Renderer * renderer) { DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; IDirectFBSurface *destsurf = data->target; Uint8 r, g, b, a; r = renderer->r; g = renderer->g; b = renderer->b; a = renderer->a; SetBlendMode(data, renderer->blendMode, NULL); SDL_DFB_CHECKERR(destsurf->SetDrawingFlags(destsurf, data->drawFlags)); switch (renderer->blendMode) { case SDL_BLENDMODE_NONE: /* case SDL_BLENDMODE_MASK: */ case SDL_BLENDMODE_BLEND: break; case SDL_BLENDMODE_ADD: case SDL_BLENDMODE_MOD: r = ((int) r * (int) a) / 255; g = ((int) g * (int) a) / 255; b = ((int) b * (int) a) / 255; a = 255; break; } SDL_DFB_CHECKERR(destsurf->SetColor(destsurf, r, g, b, a)); return 0; error: return -1; }
static mrb_value surface_set_drawing_flags(mrb_state *mrb, mrb_value self) { IDirectFBSurface* surface = mrb_directfb_surface(mrb, self); DFBResult ret = -1; if (surface != NULL) { mrb_int flags; mrb_get_args(mrb, "i", &flags); ret = surface->SetDrawingFlags(surface, flags); } return mrb_fixnum_value(ret); }
void DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window) { SDL_DFB_WINDOWDATA(window); IDirectFBSurface *s = windata->window_surface; DFB_Theme *t = &windata->theme; int i; int d = (t->caption_size - t->font_size) / 2; int x, y, w; if (!windata->is_managed || (window->flags & SDL_WINDOW_FULLSCREEN)) return; SDL_DFB_CHECK(s->SetSrcBlendFunction(s, DSBF_ONE)); SDL_DFB_CHECK(s->SetDstBlendFunction(s, DSBF_ZERO)); SDL_DFB_CHECK(s->SetDrawingFlags(s, DSDRAW_NOFX)); SDL_DFB_CHECK(s->SetBlittingFlags(s, DSBLIT_NOFX)); LoadFont(_this, window); /* s->SetDrawingFlags(s, DSDRAW_BLEND); */ s->SetColor(s, COLOR_EXPAND(t->frame_color)); /* top */ for (i = 0; i < t->top_size; i++) s->DrawLine(s, 0, i, windata->size.w, i); /* bottom */ for (i = windata->size.h - t->bottom_size; i < windata->size.h; i++) s->DrawLine(s, 0, i, windata->size.w, i); /* left */ for (i = 0; i < t->left_size; i++) s->DrawLine(s, i, 0, i, windata->size.h); /* right */ for (i = windata->size.w - t->right_size; i < windata->size.w; i++) s->DrawLine(s, i, 0, i, windata->size.h); /* Caption */ s->SetColor(s, COLOR_EXPAND(t->caption_color)); s->FillRectangle(s, t->left_size, t->top_size, windata->client.w, t->caption_size); /* Close Button */ w = t->caption_size; x = windata->size.w - t->right_size - w + d; y = t->top_size + d; s->SetColor(s, COLOR_EXPAND(t->close_color)); DrawTriangle(s, 1, x, y, w - 2 * d); /* Max Button */ s->SetColor(s, COLOR_EXPAND(t->max_color)); DrawTriangle(s, window->flags & SDL_WINDOW_MAXIMIZED ? 1 : 0, x - w, y, w - 2 * d); /* Caption */ if (*window->title) { s->SetColor(s, COLOR_EXPAND(t->font_color)); DrawCraption(_this, s, (x - w) / 2, t->top_size + d, window->title); } /* Icon */ if (windata->icon) { DFBRectangle dr; dr.x = t->left_size + d; dr.y = t->top_size + d; dr.w = w - 2 * d; dr.h = w - 2 * d; s->SetBlittingFlags(s, DSBLIT_BLEND_ALPHACHANNEL); s->StretchBlit(s, windata->icon, NULL, &dr); } windata->wm_needs_redraw = 0; }
int main( int argc, char *argv[] ) { int i; DFBResult ret; DFBSurfaceDescription desc; IDirectFB *dfb; IDirectFBImageProvider *provider = NULL; IDirectFBSurface *source = NULL; IDirectFBSurface *dest = NULL; const char *url = NULL; DFBSurfacePixelFormat source_format = DSPF_UNKNOWN; DFBSurfacePixelFormat dest_format = DSPF_UNKNOWN; bool dest_resize = false; /* Initialize DirectFB. */ ret = DirectFBInit( &argc, &argv ); if (ret) { D_DERROR( ret, "DFBTest/Blit: DirectFBInit() failed!\n" ); return ret; } /* Parse arguments. */ for (i=1; i<argc; i++) { const char *arg = argv[i]; if (strcmp( arg, "-h" ) == 0 || strcmp (arg, "--help") == 0) return print_usage( argv[0] ); else if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) { fprintf (stderr, "dfbtest_blit version %s\n", DIRECTFB_VERSION); return false; } else if (strcmp (arg, "-s") == 0 || strcmp (arg, "--source") == 0) { if (++i == argc) { print_usage (argv[0]); return false; } if (!parse_format( argv[i], &source_format )) return false; } else if (strcmp (arg, "-d") == 0 || strcmp (arg, "--dest") == 0) { if (++i == argc) { print_usage (argv[0]); return false; } if (!parse_format( argv[i], &dest_format )) return false; } else if (strcmp (arg, "-r") == 0 || strcmp (arg, "--resize") == 0) dest_resize = true; else if (!url) url = arg; else return print_usage( argv[0] ); } /* Check if we got an URL. */ if (!url) return print_usage( argv[0] ); /* Create super interface. */ ret = DirectFBCreate( &dfb ); if (ret) { D_DERROR( ret, "DFBTest/Blit: DirectFBCreate() failed!\n" ); return ret; } /* Create an image provider for the image to be loaded. */ ret = dfb->CreateImageProvider( dfb, url, &provider ); if (ret) { D_DERROR( ret, "DFBTest/Blit: IDirectFB::CreateImageProvider( '%s' ) failed!\n", url ); goto out; } /* Get the surface description. */ ret = provider->GetSurfaceDescription( provider, &desc ); if (ret) { D_DERROR( ret, "DFBTest/Blit: IDirectFBImageProvider::GetSurfaceDescription() failed!\n" ); goto out; } if (source_format != DSPF_UNKNOWN) desc.pixelformat = source_format; D_INFO( "DFBTest/Blit: Source is %dx%d using %s\n", desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) ); /* Create a surface for the image. */ ret = dfb->CreateSurface( dfb, &desc, &source ); if (ret) { D_DERROR( ret, "DFBTest/Blit: IDirectFB::CreateSurface() failed!\n" ); goto out; } ret = provider->RenderTo( provider, source, NULL ); if (ret) { D_DERROR( ret, "DFBTest/Blit: IDirectFBImageProvider::RenderTo() failed!\n" ); goto out; } /* Fill description for a primary surface. */ desc.flags = DSDESC_CAPS; desc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING; if (dest_format != DSPF_UNKNOWN) { desc.flags |= DSDESC_PIXELFORMAT; desc.pixelformat = dest_format; } if (dest_resize) desc.flags |= DSDESC_WIDTH | DSDESC_HEIGHT; dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN ); /* Create a primary surface. */ ret = dfb->CreateSurface( dfb, &desc, &dest ); if (ret) { D_DERROR( ret, "DFBTest/Blit: IDirectFB::CreateSurface() failed!\n" ); goto out; } dest->GetSize( dest, &desc.width, &desc.height ); dest->GetPixelFormat( dest, &desc.pixelformat ); D_INFO( "DFBTest/Blit: Destination is %dx%d using %s\n", desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) ); for (i=0; i<100000; i++) { int j,n = rand()%100; for (j=0; j<n; j++) { switch (rand()%3) { case 0: dest->SetDrawingFlags( dest, rand() & (DSDRAW_BLEND) ); dest->FillRectangle( dest, rand()%100, rand()%100, rand()%100, rand()%100 ); break; case 1: dest->SetBlittingFlags( dest, rand() & (DSBLIT_BLEND_ALPHACHANNEL | DSBLIT_BLEND_COLORALPHA | DSBLIT_COLORIZE | DSBLIT_ROTATE90) ); dest->Blit( dest, source, NULL, rand()%100, rand()%100 ); break; case 2: dest->SetBlittingFlags( dest, rand() & (DSBLIT_BLEND_ALPHACHANNEL | DSBLIT_BLEND_COLORALPHA | DSBLIT_COLORIZE | DSBLIT_ROTATE90) ); dest->StretchBlit( dest, source, NULL, NULL ); break; } } dfb->WaitIdle( dfb ); dest->Flip( dest, NULL, DSFLIP_NONE ); } out: if (dest) dest->Release( dest ); if (source) source->Release( source ); if (provider) provider->Release( provider ); /* Shutdown DirectFB. */ dfb->Release( dfb ); return ret; }