comparison src/video/photon/SDL_photon_render.c @ 3459:feea0def118d

Support for RendererReadPixels and RendererWritePixels has been added to photon renderer.
author Mike Gorchak <lestat@i.com.ua>
date Thu, 19 Nov 2009 08:44:07 +0000
parents d15a4daa4a58
children 6265b67848e0
comparison
equal deleted inserted replaced
3458:0aed0755d1f1 3459:feea0def118d
80 int y2); 80 int y2);
81 static int photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect); 81 static int photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect);
82 static int photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture, 82 static int photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture,
83 const SDL_Rect * srcrect, 83 const SDL_Rect * srcrect,
84 const SDL_Rect * dstrect); 84 const SDL_Rect * dstrect);
85 static int photon_renderreadpixels(SDL_Renderer * renderer, const SDL_Rect * rect,
86 Uint32 format, void * pixels, int pitch);
87 static int photon_renderwritepixels(SDL_Renderer * renderer, const SDL_Rect * rect,
88 Uint32 format, const void * pixels, int pitch);
85 static void photon_renderpresent(SDL_Renderer * renderer); 89 static void photon_renderpresent(SDL_Renderer * renderer);
86 static void photon_destroytexture(SDL_Renderer * renderer, 90 static void photon_destroytexture(SDL_Renderer * renderer,
87 SDL_Texture * texture); 91 SDL_Texture * texture);
88 static void photon_destroyrenderer(SDL_Renderer * renderer); 92 static void photon_destroyrenderer(SDL_Renderer * renderer);
89 93
1569 } 1573 }
1570 break; 1574 break;
1571 } 1575 }
1572 } 1576 }
1573 1577
1578 static int
1579 photon_renderreadpixels(SDL_Renderer * renderer, const SDL_Rect * rect,
1580 Uint32 format, void * pixels, int pitch)
1581 {
1582 SDL_RenderData *rdata = (SDL_RenderData *)renderer->driverdata;
1583 Uint32 sformat=0;
1584 uint8_t* spixels=NULL;
1585 unsigned int spitch=0;
1586
1587 switch (rdata->surfaces_type)
1588 {
1589 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
1590 sformat=photon_image_to_sdl_pixelformat(rdata->osurfaces[rdata->surface_visible_idx]->format);
1591 spixels=(uint8_t*)PdGetOffscreenContextPtr(rdata->osurfaces[rdata->surface_visible_idx]);
1592 spitch=rdata->osurfaces[rdata->surface_visible_idx]->pitch;
1593 break;
1594 case SDL_PHOTON_SURFTYPE_PHIMAGE:
1595 sformat=photon_image_to_sdl_pixelformat(rdata->psurfaces[rdata->surface_visible_idx]->type);
1596 spixels=(uint8_t*)rdata->psurfaces[rdata->surface_visible_idx]->image;
1597 spitch=rdata->psurfaces[rdata->surface_visible_idx]->bpl;
1598 break;
1599 case SDL_PHOTON_SURFTYPE_UNKNOWN:
1600 default:
1601 SDL_SetError("Photon: surfaces are not initialized");
1602 return -1;
1603 }
1604
1605 /* Adjust surface pixels pointer to the rectangle coordinates */
1606 spixels+=rect->y*spitch + rect->x*SDL_BYTESPERPIXEL(sformat);
1607
1608 SDL_ConvertPixels(rect->w, rect->h,
1609 sformat, spixels, spitch,
1610 format, pixels, pitch);
1611
1612 return 0;
1613 }
1614
1615 static int
1616 photon_renderwritepixels(SDL_Renderer * renderer, const SDL_Rect * rect,
1617 Uint32 format, const void * pixels, int pitch)
1618 {
1619 SDL_RenderData *rdata = (SDL_RenderData *)renderer->driverdata;
1620 Uint32 sformat=0;
1621 uint8_t* spixels=NULL;
1622 unsigned int spitch=0;
1623
1624 switch (rdata->surfaces_type)
1625 {
1626 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
1627 sformat=photon_image_to_sdl_pixelformat(rdata->osurfaces[rdata->surface_visible_idx]->format);
1628 spixels=(uint8_t*)PdGetOffscreenContextPtr(rdata->osurfaces[rdata->surface_visible_idx]);
1629 spitch=rdata->osurfaces[rdata->surface_visible_idx]->pitch;
1630 break;
1631 case SDL_PHOTON_SURFTYPE_PHIMAGE:
1632 sformat=photon_image_to_sdl_pixelformat(rdata->psurfaces[rdata->surface_visible_idx]->type);
1633 spixels=(uint8_t*)rdata->psurfaces[rdata->surface_visible_idx]->image;
1634 spitch=rdata->psurfaces[rdata->surface_visible_idx]->bpl;
1635 break;
1636 case SDL_PHOTON_SURFTYPE_UNKNOWN:
1637 default:
1638 SDL_SetError("Photon: surfaces are not initialized");
1639 return -1;
1640 }
1641
1642 /* Adjust surface pixels pointer to the rectangle coordinates */
1643 spixels+=rect->y*spitch + rect->x*SDL_BYTESPERPIXEL(sformat);
1644
1645 SDL_ConvertPixels(rect->w, rect->h, format, pixels, pitch,
1646 sformat, spixels, spitch);
1647
1648 return 0;
1649 }
1650
1574 /* vi: set ts=4 sw=4 expandtab: */ 1651 /* vi: set ts=4 sw=4 expandtab: */