src/video/directfb/SDL_DirectFB_render.c
branchgsoc2008_nds
changeset 2698 e1da92da346c
parent 2244 5234868559fa
equal deleted inserted replaced
2697:c9121b04cffa 2698:e1da92da346c
   313     data->format = texture->format;
   313     data->format = texture->format;
   314     data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
   314     data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
   315     data->vidlayer = NULL;
   315     data->vidlayer = NULL;
   316     if (renddata->isyuvdirect && (dispdata->vidID >= 0)
   316     if (renddata->isyuvdirect && (dispdata->vidID >= 0)
   317         && SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   317         && SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   318         SDL_DFB_CHECKERR(devdata->dfb->
   318         SDL_DFB_CHECKERR(devdata->
   319                          GetDisplayLayer(devdata->dfb, dispdata->vidID,
   319                          dfb->GetDisplayLayer(devdata->dfb, dispdata->vidID,
   320                                          &data->vidlayer));
   320                                               &data->vidlayer));
   321         layconf.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
   321         layconf.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
   322         layconf.width = texture->w;
   322         layconf.width = texture->w;
   323         layconf.height = texture->h;
   323         layconf.height = texture->h;
   324         layconf.pixelformat = SDLToDFBPixelFormat(data->format);
   324         layconf.pixelformat = SDLToDFBPixelFormat(data->format);
   325 
   325 
   326         SDL_DFB_CHECKERR(data->vidlayer->
   326         SDL_DFB_CHECKERR(data->vidlayer->SetCooperativeLevel(data->vidlayer,
   327                          SetCooperativeLevel(data->vidlayer,
   327                                                              DLSCL_EXCLUSIVE));
   328                                              DLSCL_EXCLUSIVE));
   328         SDL_DFB_CHECKERR(data->vidlayer->SetConfiguration(data->vidlayer,
   329         SDL_DFB_CHECKERR(data->vidlayer->
   329                                                           &layconf));
   330                          SetConfiguration(data->vidlayer, &layconf));
   330         SDL_DFB_CHECKERR(data->vidlayer->GetSurface(data->vidlayer,
   331         SDL_DFB_CHECKERR(data->vidlayer->
   331                                                     &data->surface));
   332                          GetSurface(data->vidlayer, &data->surface));
   332         SDL_DFB_CHECKERR(data->
   333         SDL_DFB_CHECKERR(data->vidlayer->
   333                          vidlayer->GetDescription(data->vidlayer, &laydsc));
   334                          GetDescription(data->vidlayer, &laydsc));
       
   335         SDL_DFB_DEBUG("Created HW YUV surface\n");
   334         SDL_DFB_DEBUG("Created HW YUV surface\n");
   336     }
   335     }
   337     if (!data->vidlayer) {
   336     if (!data->vidlayer) {
   338         /* fill surface description */
   337         /* fill surface description */
   339         dsc.flags =
   338         dsc.flags =
   354         }
   353         }
   355 
   354 
   356         data->pixels = NULL;
   355         data->pixels = NULL;
   357 
   356 
   358         /* Create the surface */
   357         /* Create the surface */
   359         SDL_DFB_CHECKERR(devdata->dfb->
   358         SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
   360                          CreateSurface(devdata->dfb, &dsc, &data->surface));
   359                                                      &data->surface));
   361         if (SDL_ISPIXELFORMAT_INDEXED(data->format)
   360         if (SDL_ISPIXELFORMAT_INDEXED(data->format)
   362             && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   361             && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   363             SDL_DFB_CHECKERR(data->surface->
   362             SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface,
   364                              GetPalette(data->surface, &data->palette));
   363                                                        &data->palette));
   365         }
   364         }
   366 
   365 
   367     }
   366     }
   368     return 0;
   367     return 0;
   369 
   368 
   406             entries[i].r = colors[i].r;
   405             entries[i].r = colors[i].r;
   407             entries[i].g = colors[i].g;
   406             entries[i].g = colors[i].g;
   408             entries[i].b = colors[i].b;
   407             entries[i].b = colors[i].b;
   409             entries[i].a = 0xFF;
   408             entries[i].a = 0xFF;
   410         }
   409         }
   411         SDL_DFB_CHECKERR(data->palette->
   410         SDL_DFB_CHECKERR(data->
   412                          SetEntries(data->palette, entries, ncolors,
   411                          palette->SetEntries(data->palette, entries, ncolors,
   413                                     firstcolor));
   412                                              firstcolor));
   414         return 0;
   413         return 0;
   415     } else {
   414     } else {
   416         SDL_SetError("YUV textures don't have a palette");
   415         SDL_SetError("YUV textures don't have a palette");
   417         return -1;
   416         return -1;
   418     }
   417     }
   430     if (SDL_ISPIXELFORMAT_INDEXED(data->format)
   429     if (SDL_ISPIXELFORMAT_INDEXED(data->format)
   431         && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   430         && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
   432         DFBColor entries[256];
   431         DFBColor entries[256];
   433         int i;
   432         int i;
   434 
   433 
   435         SDL_DFB_CHECKERR(data->palette->
   434         SDL_DFB_CHECKERR(data->
   436                          GetEntries(data->palette, entries, ncolors,
   435                          palette->GetEntries(data->palette, entries, ncolors,
   437                                     firstcolor));
   436                                              firstcolor));
   438 
   437 
   439         for (i = 0; i < ncolors; ++i) {
   438         for (i = 0; i < ncolors; ++i) {
   440             colors[i].r = entries[i].r;
   439             colors[i].r = entries[i].r;
   441             colors[i].g = entries[i].g;
   440             colors[i].g = entries[i].g;
   442             colors[i].b = entries[i].b;
   441             colors[i].b = entries[i].b;
   594 {
   593 {
   595     DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   594     DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
   596     DFBResult ret;
   595     DFBResult ret;
   597 
   596 
   598     SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, r, g, b, a));
   597     SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, r, g, b, a));
   599     SDL_DFB_CHECKERR(data->surface->
   598     SDL_DFB_CHECKERR(data->
   600                      FillRectangle(data->surface, rect->x, rect->y, rect->w,
   599                      surface->FillRectangle(data->surface, rect->x, rect->y,
   601                                    rect->h));
   600                                             rect->w, rect->h));
   602 
   601 
   603     return 0;
   602     return 0;
   604   error:
   603   error:
   605     return -1;
   604     return -1;
   606 }
   605 }
   620         SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   619         SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   621         SDL_DFB_DEVICEDATA(display->device);
   620         SDL_DFB_DEVICEDATA(display->device);
   622         DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
   621         DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
   623         SDL_DFB_WINDOWDATA(window);
   622         SDL_DFB_WINDOWDATA(window);
   624 
   623 
   625         SDL_DFB_CHECKERR(texturedata->vidlayer->
   624         SDL_DFB_CHECKERR(texturedata->
   626                          SetSourceRectangle(texturedata->vidlayer, srcrect->x,
   625                          vidlayer->SetSourceRectangle(texturedata->vidlayer,
   627                                             srcrect->y, srcrect->w,
   626                                                       srcrect->x, srcrect->y,
   628                                             srcrect->h));
   627                                                       srcrect->w,
       
   628                                                       srcrect->h));
   629         windata->window->GetPosition(windata->window, &px, &py);
   629         windata->window->GetPosition(windata->window, &px, &py);
   630         SDL_DFB_CHECKERR(texturedata->vidlayer->
   630         SDL_DFB_CHECKERR(texturedata->
   631                          SetScreenRectangle(texturedata->vidlayer,
   631                          vidlayer->SetScreenRectangle(texturedata->vidlayer,
   632                                             px + dstrect->x, py + dstrect->y,
   632                                                       px + dstrect->x,
   633                                             dstrect->w, dstrect->h));
   633                                                       py + dstrect->y,
       
   634                                                       dstrect->w,
       
   635                                                       dstrect->h));
   634     } else {
   636     } else {
   635         DFBRectangle sr, dr;
   637         DFBRectangle sr, dr;
   636         DFBSurfaceBlittingFlags flags = 0;
   638         DFBSurfaceBlittingFlags flags = 0;
   637 
   639 
   638         sr.x = srcrect->x;
   640         sr.x = srcrect->x;
   643         dr.x = dstrect->x;
   645         dr.x = dstrect->x;
   644         dr.y = dstrect->y;
   646         dr.y = dstrect->y;
   645         dr.w = dstrect->w;
   647         dr.w = dstrect->w;
   646         dr.h = dstrect->h;
   648         dr.h = dstrect->h;
   647 
   649 
   648         if (texture->
   650         if (texture->modMode &
   649             modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA))
   651             (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA)) {
   650         {
       
   651             u8 alpha = 0xFF;
   652             u8 alpha = 0xFF;
   652             if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA)
   653             if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA)
   653                 alpha = texture->a;
   654                 alpha = texture->a;
   654             if (texture->modMode & SDL_TEXTUREMODULATE_COLOR)
   655             if (texture->modMode & SDL_TEXTUREMODULATE_COLOR)
   655                 SDL_DFB_CHECKERR(data->surface->
   656                 SDL_DFB_CHECKERR(data->
   656                                  SetColor(data->surface, texture->r,
   657                                  surface->SetColor(data->surface, texture->r,
   657                                           texture->g, texture->b, alpha));
   658                                                    texture->g, texture->b,
       
   659                                                    alpha));
   658             else
   660             else
   659                 SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
   661                 SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
   660                                                          0xFF, 0xFF, alpha));
   662                                                          0xFF, 0xFF, alpha));
   661             // Only works together ....
   663             // Only works together ....
   662             flags |= DSBLIT_COLORIZE | DSBLIT_SRC_PREMULTCOLOR;
   664             flags |= DSBLIT_COLORIZE | DSBLIT_SRC_PREMULTCOLOR;
   663         }
   665         }
   664 
   666 
   665         if (texture->
   667         if (texture->blendMode & (SDL_TEXTUREBLENDMODE_MASK |
   666             blendMode & (SDL_TEXTUREBLENDMODE_MASK |
   668                                   SDL_TEXTUREBLENDMODE_BLEND)) {
   667                          SDL_TEXTUREBLENDMODE_BLEND)) {
       
   668             flags |= DSBLIT_BLEND_ALPHACHANNEL;
   669             flags |= DSBLIT_BLEND_ALPHACHANNEL;
   669         } else {
   670         } else {
   670             flags |= DSBLIT_NOFX;
   671             flags |= DSBLIT_NOFX;
   671         }
   672         }
   672         SDL_DFB_CHECKERR(data->surface->
   673         SDL_DFB_CHECKERR(data->
   673                          SetBlittingFlags(data->surface, flags));
   674                          surface->SetBlittingFlags(data->surface, flags));
   674         if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
   675         if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
   675             SDL_DFB_CHECKERR(data->surface->
   676             SDL_DFB_CHECKERR(data->surface->Blit(data->surface,
   676                              Blit(data->surface, texturedata->surface, &sr,
   677                                                  texturedata->surface, &sr,
   677                                   dr.x, dr.y));
   678                                                  dr.x, dr.y));
   678         } else {
   679         } else {
   679             SDL_DFB_CHECKERR(data->surface->
   680             SDL_DFB_CHECKERR(data->surface->StretchBlit(data->surface,
   680                              StretchBlit(data->surface, texturedata->surface,
   681                                                         texturedata->surface,
   681                                          &sr, &dr));
   682                                                         &sr, &dr));
   682         }
   683         }
   683     }
   684     }
   684     return 0;
   685     return 0;
   685   error:
   686   error:
   686     return -1;
   687     return -1;
   700     sr.y = 0;
   701     sr.y = 0;
   701     sr.w = window->w;
   702     sr.w = window->w;
   702     sr.h = window->h;
   703     sr.h = window->h;
   703 
   704 
   704     /* Send the data to the display */
   705     /* Send the data to the display */
   705     SDL_DFB_CHECKERR(data->surface->
   706     SDL_DFB_CHECKERR(data->
   706                      Flip(data->surface, NULL, data->flipflags));
   707                      surface->Flip(data->surface, NULL, data->flipflags));
   707 
   708 
   708     return;
   709     return;
   709   error:
   710   error:
   710     return;
   711     return;
   711 }
   712 }