1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software 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
18
19 #ifdef HAVE_CONFIG_H
20 #include "gnashconfig.h"
21 #endif
22
23 #include <fltk/Item.h>
24 #include <fltk/ItemGroup.h>
25 #include <fltk/PopupMenu.h>
26 #include <fltk/Widget.h>
27 #include <fltk/ask.h>
28 #include <fltk/events.h>
29 #include <fltk/run.h>
30 #include <fltk/visual.h>
31 #include <fltk/Window.h>
32 #include <fltk/draw.h>
33 #include <fltk/x.h>
34 #include <fltk/damage.h>
35 #include <fltk/layout.h>
36 #include <fltk/Cursor.h>
37
38 #include "Renderer.h"
39 #include "Renderer_cairo.h"
40
41 #include "fltksup.h"
42 #include "fltk_glue_cairo.h"
43 #include "log.h"
44 #include "gui.h"
45
46 #include "RunResources.h"
47
48 using namespace std;
49 //using namespace fltk;
50
51 namespace gnash {
52
FltkCairoGlue()53 FltkCairoGlue::FltkCairoGlue()
54 : _offscreenbuf(NULL)
55 {
56 }
57
~FltkCairoGlue()58 FltkCairoGlue::~FltkCairoGlue()
59 {
60 cairo_surface_destroy(_cairo_surface);
61 delete [] _offscreenbuf;
62 }
63
64 Renderer*
createRenderHandler()65 FltkCairoGlue::createRenderHandler()
66 {
67 _renderer = renderer::cairo::create_handler();
68 return _renderer;
69 }
70
71 void
initBuffer(int width,int height)72 FltkCairoGlue::initBuffer(int width, int height)
73 {
74 static bool firstTime = true;
75
76 int _bpp = 32;
77 int depth_bytes = _bpp / 8;
78
79 assert(_bpp % 8 == 0);
80
81 _stride = width * depth_bytes;
82
83 #define CHUNK_SIZE (100 * 100 * depth_bytes)
84
85 //int bufsize = static_cast<int>(width * height * depth_bytes / CHUNK_SIZE + 1) * CHUNK_SIZE;
86
87 int bufsize = height * _stride;
88
89 _offscreenbuf = new unsigned char[bufsize];
90
91 // CAIRO_FORMAT_RGB24 actualy means a 32-bit RGB word with the upper 8 bits
92 // unused. Therefore we have allocated a 32-bit buffer.
93
94 if (_cairo_surface)
95 cairo_surface_destroy(_cairo_surface);
96 if (_cairo_handle)
97 cairo_destroy(_cairo_handle);
98
99 _cairo_surface =
100 cairo_image_surface_create_for_data (_offscreenbuf, CAIRO_FORMAT_RGB24,
101 width, height, _stride);
102
103 _cairo_handle = cairo_create(_cairo_surface);
104
105 cairo_set_source_surface(_cairo_handle, cairo_get_target(_cairo_handle), 0, 0);
106 renderer::cairo::set_context(_renderer, _cairo_handle);
107
108 //renderer::cairo::set_handle(_cairo_handle);
109
110 if (firstTime) {
111 //set_Renderer(_renderer);
112 _runResources.setRenderer(std::shared_ptr<Renderer>(_renderer));
113 firstTime = false;
114 }
115
116 _width = width;
117 _height = height;
118 }
119
120 void
draw()121 FltkCairoGlue::draw()
122 {
123 fltk::Rectangle area(0, 0, _width, _height);
124
125 // CAIRO_FORMAT_RGB24 == fltk::RGB32
126 fltk::drawimage(_offscreenbuf, fltk::RGB32, area);
127 }
128
129 void
invalidateRegion(const SWFRect & bounds)130 FltkCairoGlue::invalidateRegion(const SWFRect& bounds)
131 {
132 return;
133 }
134
135 void
resize(int width,int height)136 FltkCairoGlue::resize(int width, int height)
137 {
138 GNASH_REPORT_FUNCTION;
139 cairo_surface_destroy(_cairo_surface);
140 cairo_destroy (_cairo_handle);
141 delete [] _offscreenbuf;
142 initBuffer(width, height);
143 }
144
145 } // namespace gnash
146