2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "sdl_cairo_glue.h"
21 #include "Renderer_cairo.h"
29 SdlCairoGlue::SdlCairoGlue()
31 // GNASH_REPORT_FUNCTION;
34 SdlCairoGlue::~SdlCairoGlue()
36 // GNASH_REPORT_FUNCTION;
37 if ( _cairo_surface
) cairo_surface_destroy(_cairo_surface
);
38 if ( _sdl_surface
) SDL_FreeSurface(_sdl_surface
);
39 if ( _screen
) SDL_FreeSurface(_screen
);
40 delete [] _render_image
;
44 SdlCairoGlue::init(int /*argc*/, char** /*argv*/[])
46 // GNASH_REPORT_FUNCTION;
52 SdlCairoGlue::createRenderHandler(int depth
)
54 // GNASH_REPORT_FUNCTION;
57 _renderer
= renderer::cairo::create_handler();
62 /// Not implemented, Fixme
64 SdlCairoGlue::setInvalidatedRegions(const InvalidatedRanges
& /*ranges*/)
69 SdlCairoGlue::prepDrawingArea(int width
, int height
, boost::uint32_t sdl_flags
)
71 _screen
= SDL_SetVideoMode(width
, height
, _bpp
, sdl_flags
| SDL_SWSURFACE
);
74 fprintf(stderr
, "SDL_SetVideoMode() failed.\n");
80 _render_image
= new unsigned char[stride
* height
];
81 // XXX is there a need for zeroing out _render_image?
84 cairo_image_surface_create_for_data (_render_image
, CAIRO_FORMAT_ARGB32
,
85 width
, height
, stride
);
87 _cairo_handle
= cairo_create(_cairo_surface
);
89 renderer::cairo::set_context(_renderer
, _cairo_handle
);
91 boost::uint32_t rmask
, gmask
, bmask
, amask
;
98 _sdl_surface
= SDL_CreateRGBSurfaceFrom((void *) _render_image
, width
, height
,
99 _bpp
, stride
, rmask
, gmask
, bmask
, amask
);
100 assert(_sdl_surface
);
106 SdlCairoGlue::render()
108 // GNASH_REPORT_FUNCTION;
110 /*Fill the background in purple so we can see the alpha blend */
111 //SDL_FillRect (_screen, NULL, SDL_MapRGB(_screen->format,255,0,255));
113 SDL_BlitSurface(_sdl_surface
, NULL
, _screen
, NULL
);
115 //cairo_surface_write_to_png (_cairo_surface, "/tmp/gnash.png");
117 SDL_UpdateRect (_screen
, 0, 0, 0, 0);