~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to gui/fb/fb_glue_agg.cpp

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2012-03-04 03:19:06 UTC
  • mfrom: (1.1.18) (3.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20120304031906-p6q5rnb0xhgpof7o
Tags: 0.8.10-3ubuntu1
* Merge from Debian testing (FFe: LP: #940876), remaining changes:
  - Use mozilla-flashplugin as the alternative for now
  - Change xulrunner-dev build dep to firefox-dev
* Drop the plugin API porting patch, this has been fixed upstream
  - drop debian/patches*
* Drop the following change as we want Adobe's player to take priority
  if it's installed
  - Set alternative priority to 50 so that it matches Adobe Flash's priority

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
 
//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
 
2
//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
3
3
//   Foundation, Inc
4
4
//
5
5
// This program is free software; you can redistribute it and/or modify
42
42
 
43
43
namespace gui {
44
44
 
45
 
// FBGlue::FBGlue()
46
 
// {
47
 
//     GNASH_REPORT_FUNCTION;
48
 
// }
49
 
 
50
 
// FBGlue::~FBGlue()
51
 
// {
52
 
//     GNASH_REPORT_FUNCTION;
53
 
// }
54
 
 
55
45
//---------------------------------------------
56
46
FBAggGlue::FBAggGlue()
57
47
    : _fd(-1)
58
48
{
59
 
    GNASH_REPORT_FUNCTION;
 
49
//    GNASH_REPORT_FUNCTION;
60
50
    memset(&_varinfo, 0, sizeof(fb_var_screeninfo));
61
51
    memset(&_fixinfo, 0, sizeof(fb_fix_screeninfo));
62
52
}
64
54
FBAggGlue::FBAggGlue(int fd)
65
55
    : _fd(fd)
66
56
{
67
 
    GNASH_REPORT_FUNCTION;    
 
57
//    GNASH_REPORT_FUNCTION;    
68
58
}
69
59
 
70
60
FBAggGlue::~FBAggGlue()
71
61
{
72
 
    GNASH_REPORT_FUNCTION;    
 
62
//    GNASH_REPORT_FUNCTION;    
73
63
 
74
64
    // Close the memory
75
65
    if (_fd) {
83
73
    // GNASH_REPORT_FUNCTION;
84
74
    
85
75
    if (!_renderer) {
86
 
        log_error("No renderer set!");
 
76
        log_error(_("No renderer set!"));
87
77
        return;
88
78
    }
89
79
}
91
81
void
92
82
FBAggGlue::setInvalidatedRegions(const InvalidatedRanges &ranges)
93
83
{
94
 
    // GNASH_REPORT_FUNCTION;
 
84
//    GNASH_REPORT_FUNCTION;
95
85
 
96
86
    if (!_renderer) {
97
 
        log_error("No renderer set!");
 
87
        log_error(_("No renderer set in %s!"), __FUNCTION__);
98
88
        return;
99
89
    }
100
 
 
 
90
    
101
91
    _renderer->set_invalidated_regions(ranges);
102
 
    
 
92
 
103
93
    _drawbounds.clear();
104
94
 
105
95
    for (size_t rno = 0; rno<ranges.size(); rno++) {
112
102
        
113
103
        _drawbounds.push_back(bounds);   
114
104
    }
115
 
 
116
105
}
117
106
 
118
107
bool
119
108
FBAggGlue::init (int argc, char ***argv)
120
109
{
121
 
    GNASH_REPORT_FUNCTION;    
 
110
//    GNASH_REPORT_FUNCTION;    
122
111
 
123
112
    // The device must be initialized before the renderer. AGG only supports
124
113
    // The Raw framebuffer, so we use that.
125
114
    _device.reset(new renderer::rawfb::RawFBDevice);
126
115
    _device->initDevice(argc, *argv);    
127
116
 
 
117
    renderer::rawfb::RawFBDevice *rawfb = reinterpret_cast
 
118
        <renderer::rawfb::RawFBDevice *>(_device.get());
 
119
 
 
120
    // You must pass in the file descriptor to the opened
 
121
    // framebuffer when creating a window.
 
122
    return _device->attachWindow(rawfb->getHandle());
 
123
 
128
124
    // Set the renderer for the AGG glue layer
129
125
    gnash::Renderer *rend = reinterpret_cast<gnash::Renderer *>
130
126
                                                (createRenderHandler());
131
127
    if (rend) {
132
128
        _renderer.reset(rend);
133
129
    } else {
134
 
        log_error("failed to create a render handler for AGG!");
 
130
        log_error(_("failed to create a render handler for AGG!"));
135
131
        return false;
136
132
    }
137
133
 
138
 
#ifdef PIXELFORMAT_LUT8
139
134
    // Set grayscale for 8 bit modes
140
 
    renderer::rawfb::RawFBDevice *rawfb = reinterpret_cast
141
 
        <renderer::rawfb::RawFBDevice *>(_device.get());    
142
135
    if (_varinfo.bits_per_pixel == 8) {
143
136
        if (!rawfb->setGrayscaleLUT8())
144
137
            return false;
145
138
    }
146
 
#endif
147
 
 
148
 
    _display.initDevice(0, 0);
149
 
 
150
 
    // You must pass in the file descriptor to the opened
151
 
    // framebuffer when creating a window. Under X11, this is
152
 
    // actually the XID of the created window.
153
 
    return _device->attachWindow(_display.getHandle());
154
 
    
 
139
 
155
140
    return true;
156
141
}
157
142
 
160
145
Renderer *
161
146
FBAggGlue::createRenderHandler()
162
147
{
163
 
    GNASH_REPORT_FUNCTION;
 
148
//    GNASH_REPORT_FUNCTION;
164
149
 
165
150
    if (!_device) {
166
 
        log_error("No Device layer initialized yet!");
 
151
        log_error(_("No Device layer initialized yet!"));
167
152
        return 0;
168
153
    }
169
154
    
170
155
    const int width     = _device->getWidth();
171
156
    const int height    = _device->getHeight();
172
 
    const int bpp       = _device->getDepth();
173
157
    
174
 
    // TODO: should recalculate!  
175
 
    boost::uint8_t       *mem;
176
 
    Renderer_agg_base   *agg_handler;
177
 
 
178
 
    agg_handler = NULL;
179
 
 
180
158
    _validbounds.setTo(0, 0, width - 1, height - 1);
181
159
    
182
 
#ifdef ENABLE_DOUBLE_BUFFERING
183
 
    log_debug(_("Double buffering enabled"));
184
 
    mem = _buffer;
185
 
#else
186
 
    log_debug(_("Double buffering disabled"));
187
 
    mem = _device->getFBMemory();
188
 
#endif
189
 
    
190
 
    agg_handler = NULL;
191
 
  
192
160
    // choose apropriate pixel format
193
161
 
194
162
    renderer::rawfb::RawFBDevice *rawfb = reinterpret_cast
195
163
        <renderer::rawfb::RawFBDevice *>(_device.get());
196
 
    log_debug(_("red channel: %d / %d"), rawfb->getRedOffset(), 
 
164
    log_debug("red channel: %d / %d", rawfb->getRedOffset(), 
197
165
              rawfb->getRedSize());
198
 
    log_debug(_("green channel: %d / %d"), rawfb->getGreenOffset(), 
 
166
    log_debug("green channel: %d / %d", rawfb->getGreenOffset(), 
199
167
              rawfb->getGreenSize());
200
 
    log_debug(_("blue channel: %d / %d"), rawfb->getBlueOffset(), 
 
168
    log_debug("blue channel: %d / %d", rawfb->getBlueOffset(), 
201
169
              rawfb->getBlueSize());
202
 
    log_debug(_("Total bits per pixel: %d"), bpp);
 
170
    log_debug("Total bits per pixel: %d",  rawfb->getDepth());
203
171
    
204
172
    const char* pixelformat = agg_detect_pixel_format(
205
173
        rawfb->getRedOffset(),   rawfb->getRedSize(),
206
174
        rawfb->getGreenOffset(), rawfb->getGreenSize(),
207
175
        rawfb->getBlueOffset(),  rawfb->getBlueSize(),
208
 
        bpp);
 
176
        rawfb->getDepth());
209
177
 
 
178
    Renderer_agg_base *agg_handler = 0;
210
179
    if (pixelformat) {
211
180
        agg_handler = create_Renderer_agg(pixelformat);
212
181
    } else {
213
 
        log_error("The pixel format of your framebuffer could not be detected.");
 
182
        log_error(_("The pixel format of your framebuffer could not be detected."));
214
183
        return false;
215
184
    }
216
185
    
217
186
    assert(agg_handler != NULL);
218
187
 
219
 
    // This attaches the memory from the framebuffer to the AGG
220
 
    // renderer.
221
 
    size_t rowsize = width*((bpp+7)/8);
222
 
    agg_handler->init_buffer((unsigned char *)mem, _device->getFBMemSize(),
223
 
                             width, height, rowsize);
 
188
    // Get the memory buffer to have AGG render into.
 
189
    boost::uint8_t *mem = 0;
 
190
    if (rawfb->isSingleBuffered()) {
 
191
        log_debug(_("Double buffering disabled"));
 
192
        mem = rawfb->getFBMemory();
 
193
    } else {
 
194
        log_debug(_("Double buffering enabled"));
 
195
        mem = rawfb->getOffscreenBuffer();
 
196
    }
 
197
 
 
198
    // This attaches the memory from the device to the AGG renderer
 
199
    agg_handler->init_buffer((unsigned char *)mem, rawfb->getFBMemSize(),
 
200
                             width, height, rawfb->getStride());
 
201
 
 
202
    _renderer.reset(agg_handler);
224
203
    
225
204
    return (Renderer *)agg_handler;
226
205
}    
228
207
void
229
208
FBAggGlue::prepDrawingArea(FbWidget */* drawing_area */)
230
209
{
231
 
    GNASH_REPORT_FUNCTION;
 
210
//    GNASH_REPORT_FUNCTION;
232
211
    // nothing to do here, the memory was attached when
233
212
    // creating the renderer.
234
213
}
235
214
 
236
 
#if 0
237
 
void
238
 
FBGlue::render(void * /* region */)
239
 
{
240
 
    GNASH_REPORT_FUNCTION;
241
 
}
242
 
#endif
243
 
 
244
215
void
245
216
FBAggGlue::render()
246
217
{
247
 
    GNASH_REPORT_FUNCTION;
 
218
//    GNASH_REPORT_FUNCTION;
248
219
 
249
 
    if ( _drawbounds.size() == 0 ) {
 
220
    if (_drawbounds.size() == 0 ) {
 
221
        log_error(_("No Drawbounds set in %s!"), __FUNCTION__);
250
222
        return; // nothing to do..
251
223
    }
252
 
    
253
 
#ifdef ENABLE_DOUBLE_BUFFERING
254
 
    // Size of a pixel in bytes
255
 
    // NOTE: +7 to support 15 bpp
256
 
    const unsigned int pixel_size = (var_screeninfo.bits_per_pixel+7)/8;
257
 
    
258
 
    for (unsigned int bno=0; bno < _drawbounds.size(); bno++) {
259
 
        geometry::Range2d<int>& bounds = _drawbounds[bno];
260
 
        
261
 
        assert ( ! bounds.isWorld() );
262
 
        
263
 
        // Size, in bytes, of a row that has to be copied
264
 
        const unsigned int row_size = (bounds.width()+1) * pixel_size;
265
 
        
266
 
        // copy each row
267
 
        const int minx = bounds.getMinX();
268
 
        const int maxy = bounds.getMaxY();
269
 
        
270
 
        for (int y=bounds.getMinY(); y<=maxy; ++y) {    
271
 
            const unsigned int pixel_index = y * _rowsize + minx*pixel_size;
272
 
            memcpy(&(_fbmem[pixel_index]), &buffer[pixel_index], row_size);
273
 
            
274
 
        }
275
 
    }  
276
 
    
277
 
#endif
 
224
 
 
225
    _device->swapBuffers();
278
226
    
279
227
#ifdef DEBUG_SHOW_FPS
280
228
    profile();
284
232
int
285
233
FBAggGlue::width()
286
234
{
287
 
    GNASH_REPORT_FUNCTION;
 
235
//    GNASH_REPORT_FUNCTION;
288
236
 
289
237
    if (_device) {
290
238
        return _device->getWidth();
295
243
int
296
244
FBAggGlue::height()
297
245
{
298
 
    GNASH_REPORT_FUNCTION;
 
246
//    GNASH_REPORT_FUNCTION;
299
247
 
300
248
    if (_device) {
301
249
        return _device->getHeight();