Add brackets around control flow constructs to make more readable
[gnash.git] / gui / sdl / sdl_cairo_glue.cpp
blobf7bd231705d357e6ad4481b9667df534d07427bd
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
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.
9 //
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.
14 //
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"
20 #include "log.h"
21 #include "Renderer_cairo.h"
23 using namespace std;
26 namespace gnash
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;
43 bool
44 SdlCairoGlue::init(int /*argc*/, char** /*argv*/[])
46 // GNASH_REPORT_FUNCTION;
47 return true;
51 Renderer*
52 SdlCairoGlue::createRenderHandler(int depth)
54 // GNASH_REPORT_FUNCTION;
55 _bpp = depth;
57 _renderer = renderer::cairo::create_handler();
59 return _renderer;
62 /// Not implemented, Fixme
63 void
64 SdlCairoGlue::setInvalidatedRegions(const InvalidatedRanges& /*ranges*/)
68 bool
69 SdlCairoGlue::prepDrawingArea(int width, int height, boost::uint32_t sdl_flags)
71 _screen = SDL_SetVideoMode(width, height, _bpp, sdl_flags | SDL_SWSURFACE);
73 if (!_screen) {
74 fprintf(stderr, "SDL_SetVideoMode() failed.\n");
75 exit(EXIT_FAILURE);
78 int stride=width * 4;
80 _render_image = new unsigned char[stride * height];
81 // XXX is there a need for zeroing out _render_image?
83 _cairo_surface =
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;
93 rmask = 0x00ff0000;
94 gmask = 0x0000ff00;
95 bmask = 0x000000ff;
96 amask = 0xff000000;
98 _sdl_surface = SDL_CreateRGBSurfaceFrom((void *) _render_image, width, height,
99 _bpp, stride, rmask, gmask, bmask, amask);
100 assert(_sdl_surface);
102 return true;
105 void
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);
121 } // namespace gnash