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

« back to all changes in this revision

Viewing changes to gui/fb/fb.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,
3
 
//   2011 Free Software Foundation, Inc
 
2
//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
 
3
//   Foundation, Inc
4
4
//
5
5
// This program is free software; you can redistribute it and/or modify
6
6
// it under the terms of the GNU General Public License as published by
26
26
///
27
27
/// Since there can be multiple input devices in /dev/input/ you have to
28
28
/// specify which device to use using the 
29
 
///  POINTING_DEVICE environment variable for the mouse and
 
29
//  POINTING_DEVICE environment variable for the mouse and
30
30
///  KEYBOARD_DEVICE environment variable for the keyboard
31
31
 
32
32
/// \page fb_calibration FB GUI Touchscreen Calibration
155
155
      _own_vt(-1),
156
156
      _xpos(0),
157
157
      _ypos(0),  
158
 
      _timeout(0)
 
158
      _timeout(0),
 
159
      _fullscreen(true)
159
160
{
160
161
    // GNASH_REPORT_FUNCTION;
161
162
    
162
163
    // initializing to zero helps with debugging and prevents weird bugs
163
164
//    memset(mouse_buf, 0, 256);
164
 
    memset(&_var_screeninfo, 0, sizeof(fb_var_screeninfo));
165
 
    memset(&_fix_screeninfo, 0, sizeof(fb_fix_screeninfo));
166
 
 
167
165
    signal(SIGINT, terminate_signal);
168
166
    signal(SIGTERM, terminate_signal);
169
167
}
174
172
    
175
173
    if (_fd > 0) {
176
174
        enable_terminal();
177
 
        log_debug(_("Closing framebuffer device"));
 
175
        // log_debug("Closing framebuffer device");
178
176
        close(_fd);
179
177
    }
180
 
 
181
 
#ifdef ENABLE_DOUBLE_BUFFERING
182
 
    if (buffer) {
183
 
        log_debug(_("Freeing offscreen buffer"));
184
 
        free(buffer);
185
 
    }
186
 
#endif
187
178
}
188
179
 
189
180
bool
190
181
FBGui::init(int argc, char *** argv)
191
182
{
192
 
    GNASH_REPORT_FUNCTION;
 
183
//  GNASH_REPORT_FUNCTION;
193
184
 
194
185
    // the current renderer as set on the command line or gnashrc file
195
186
    std::string renderer = _runResources.getRenderBackend();
232
223
        _height = agg->height();
233
224
        log_debug("Width:%d, Height:%d", _width, _height);
234
225
        _renderer.reset(agg->createRenderHandler());
235
 
        // Renderer_agg_base *rend = reinterpret_cast<Renderer_agg_base *>(_renderer.get());
236
 
        // rend->init(_width, _height);
237
226
    }
238
227
#endif
239
228
    if ((renderer != "openvg") && (renderer != "agg")) {
240
 
        log_error("No renderer! %s not supported.", renderer);
 
229
        log_error(_("No renderer! %s not supported."), renderer);
241
230
    }
242
231
    
243
232
    disable_terminal();
244
 
    
 
233
 
 
234
    // Look for the User Mode Input (Uinput) device, which is used to
 
235
    // control the movement and coordinates of the mouse cursor.
 
236
    if (_uinput.scanForDevice()) {
 
237
        _uinput.init();
 
238
        _uinput.moveTo(0, 0);
 
239
    } else {
 
240
        log_error(_("Found no accessible User mode input event device"));
 
241
    }
 
242
        
245
243
    // Initialize all the input devices
246
244
 
247
245
    // Look for Mice that use the PS/2 mouse protocol
248
246
    std::vector<boost::shared_ptr<InputDevice> > possibles
249
247
        = InputDevice::scanForDevices();
250
248
    if (possibles.empty()) {
251
 
        log_error("Found no accessible input event devices");
 
249
        log_error(_("Found no accessible input event devices"));
252
250
    } else {
253
251
        log_debug("Found %d input event devices.", possibles.size());
254
252
    }
255
253
    
256
254
    std::vector<boost::shared_ptr<InputDevice> >::iterator it;
257
255
    for (it=possibles.begin(); it!=possibles.end(); ++it) {
258
 
        //(*it)->dump();
 
256
        // Set the screen size, which is used for calculating absolute
 
257
        // mouse locations from relative ones.
 
258
        (*it)->setScreenSize(_width, _height);
 
259
        // (*it)->dump();
 
260
#if defined(USE_MOUSE_PS2) || defined(USE_MOUSE_ETT)
259
261
        if ((*it)->getType() == InputDevice::MOUSE) {
260
 
            log_debug("WARNING: Mouse support disabled as it conflicts with the input event support.");
 
262
            log_debug(_("WARNING: Mouse support may conflict with the input event support."));
261
263
            // For now we only want keyboard input events, as the mouse
262
264
            // interface default of /dev/input/mice supports hotpluging devices,
263
265
            // unlike the regular events.
264
 
            // _inputs.push_back(*it);
 
266
            _inputs.push_back(*it);
265
267
        }
 
268
#endif
266
269
        if ((*it)->getType() == InputDevice::KEYBOARD) {
267
270
            _inputs.push_back(*it);
268
271
        }
270
273
        // use that instead of handling the events directly. The
271
274
        // Babbage is configured as a tablet when using input events.
272
275
        if ((*it)->getType() == InputDevice::TOUCHSCREEN) {
273
 
            log_debug("Enabling Touchscreen support.");
 
276
            log_debug(_("Enabling Touchscreen support."));
274
277
            _inputs.push_back(*it);
275
278
        }
276
279
        if ((*it)->getType() == InputDevice::TABLET) {
277
280
#if 1
278
 
            log_debug("WARNING: Babbage Tablet support disabled as it conflicts with TSlib");
 
281
            log_debug(_("WARNING: Babbage Tablet support disabled as it conflicts with TSlib"));
279
282
#else
280
 
            log_debug("Enabling Babbage Touchscreen support");
 
283
            log_debug(_("Enabling Babbage Touchscreen support"));
281
284
            _inputs.push_back(*it);
282
285
#endif
283
286
        }
284
287
        if ((*it)->getType() == InputDevice::POWERBUTTON) {
 
288
            log_debug(_("Enabling Power Button support"));
285
289
            _inputs.push_back(*it);
286
290
        }
287
291
    }
288
292
 
289
 
#if 0
290
293
    // Let -j -k override "window" size
291
294
    optind = 0; opterr = 0; char c;
292
295
    while ((c = getopt (argc, *argv, "j:k:X:Y:")) != -1) {
305
308
                break;
306
309
        }
307
310
    }
308
 
#endif
309
 
    
 
311
 
310
312
#if 0
311
313
    // FIXME: this allows to draw in a subsection of the screen. OpenVG
312
314
    // should be able to support this, but right now it just gets in
320
322
 
321
323
    log_debug("X:%d, Y:%d", _xpos, _ypos);
322
324
#endif
323
 
 
 
325
    
324
326
    _validbounds.setTo(0, 0, _width - 1, _height - 1);
325
327
    
326
328
    return true;
327
329
}
328
330
 
329
331
bool
 
332
FBGui::resize_view(int width, int height)
 
333
{
 
334
    GNASH_REPORT_FUNCTION;
 
335
 
 
336
//   _glue.prepDrawingArea(width, height, 0);
 
337
    Gui::resize_view(width, height);
 
338
 
 
339
    return true;
 
340
}
 
341
 
 
342
bool
330
343
FBGui::run()
331
344
{
332
 
    GNASH_REPORT_FUNCTION;
 
345
//  GNASH_REPORT_FUNCTION;
333
346
 
334
347
#ifdef USE_TSLIB
335
348
    int ts_loop_count;
336
349
#endif
337
350
 
338
351
    VirtualClock& timer = getClock();
 
352
    int delay = 0;
339
353
    
340
354
    // let the GUI recompute the x/y scale factors to best fit the whole screen
341
355
    resize_view(_validbounds.width(), _validbounds.height());
342
356
 
 
357
    float fps = getFPS();
 
358
    
 
359
    // FIXME: this value is arbitrary, and will make any movie with
 
360
    // less than 12 frames eat up more of the cpu. It should probably
 
361
    // be a much lower value, like 2.
 
362
    if (fps > 12) {
 
363
        delay = static_cast<int>(100000/fps);
 
364
    } else {
 
365
        // 10ms per heart beat
 
366
        delay = 10000;
 
367
    }
 
368
    log_debug(_("Movie Frame Rate is %d, adjusting delay to %dms"), fps,
 
369
              _interval * delay);
 
370
    
343
371
    // This loops endlessly at the frame rate
344
372
    while (!terminate_request) {  
345
 
        // wait the "heartbeat" inteval
346
 
        gnashSleep(_interval * 1000);    
 
373
        // wait the "heartbeat" inteval. _interval is in milliseconds,
 
374
        // but gnashSleep() wants nanoseconds, so adjust by 1000.
 
375
        gnashSleep(_interval * 1000);
347
376
        // TODO: Do we need to check the real time slept or is it OK when we woke
348
377
        // up early because of some Linux signal sent to our process (and thus
349
378
        // "advance" faster than the "heartbeat" interval)? - Udo
370
399
void
371
400
FBGui::renderBuffer()
372
401
{
373
 
    // GNASH_REPORT_FUNCTION;
374
 
 
375
 
//    if ( _drawbounds.size() == 0 ) return; // nothing to do..
376
 
 
377
 
#ifdef ENABLE_DOUBLE_BUFFERING
378
 
 
379
 
    // Size of a pixel in bytes
380
 
    // NOTE: +7 to support 15 bpp
381
 
    const unsigned int pixel_size = (var_screeninfo.bits_per_pixel+7)/8;
382
 
    
383
 
    for (unsigned int bno=0; bno < _drawbounds.size(); bno++) {  
384
 
        geometry::Range2d<int>& bounds = _drawbounds[bno];
385
 
        assert ( ! bounds.isWorld() );  
386
 
    
387
 
        // Size, in bytes, of a row that has to be copied
388
 
        const unsigned int row_size = (bounds.width()+1) * pixel_size;
389
 
      
390
 
        // copy each row
391
 
        const int minx = bounds.getMinX();
392
 
        const int maxy = bounds.getMaxY();
393
 
 
394
 
        const int minx1 = minx+_xpos;
395
 
        for (int y=bounds.getMinY(), y1=y+_ypos; y<=maxy; ++y, ++y1) {
396
 
            const unsigned int pix_idx_in = y*m_rowsize + minx*pixel_size;
397
 
            const unsigned int pix_idx_out = y1*m_rowsize + minx1*pixel_size;
398
 
            memcpy(&(fbmem[pix_idx_out]), &buffer[pix_idx_in], row_size);
399
 
        }
400
 
    }  
401
 
       
402
 
#endif
 
402
//    GNASH_REPORT_FUNCTION;    
403
403
 
404
404
    _glue->render();
405
405
}
408
408
FBGui::createWindow(const char* /*title*/, int /*width*/, int /*height*/,
409
409
                     int /*xPosition*/, int /*yPosition*/)
410
410
{
411
 
    GNASH_REPORT_FUNCTION;
 
411
//  GNASH_REPORT_FUNCTION;
412
412
 
413
413
    _runResources.setRenderer(_renderer);
414
 
    
415
 
#ifdef RENDERER_AGG
416
 
    if (_glue) {
417
 
        _glue->prepDrawingArea(0);
418
 
    } else {
419
 
        return false;
420
 
    }
421
 
#endif
422
 
    
 
414
 
423
415
    return true;
424
416
}
425
417
 
449
441
    _timeout = timeout;
450
442
}
451
443
 
452
 
// void
453
 
// FBGui::setFullscreen()
454
 
// {
455
 
//     // FB GUI always runs fullscreen; ignore...
456
 
// }
 
444
// The Framebuffer GUI usually always runs fullscreen, which is
 
445
// the default, but occasionally users want to run the SWF movie
 
446
// it's actual size, or in different locations.
 
447
void
 
448
FBGui::setFullscreen()
 
449
{
 
450
    _fullscreen = true;
 
451
}
457
452
 
458
 
// void
459
 
// FBGui::unsetFullscreen()
460
 
// {
461
 
//   // FB GUI always runs fullscreen; ignore...
462
 
// }
 
453
void
 
454
FBGui::unsetFullscreen()
 
455
{
 
456
    _fullscreen = false;
 
457
}
463
458
 
464
459
void
465
460
FBGui::showMenu(bool /*show*/)
477
472
}
478
473
 
479
474
void
480
 
FBGui::setInvalidatedRegion(const SWFRect& /* bounds */)
 
475
FBGui::setInvalidatedRegion(const SWFRect& bounds)
481
476
{
482
 
    // GNASH_REPORT_FUNCTION;
483
 
 
484
 
#if 0
485
 
     FBAggGlue *fbag = reinterpret_cast
486
 
        <FBAggGlue *>(_glue.get());
487
 
 
488
 
     fbag->setInvalidatedRegion(bounds);
489
 
#endif
 
477
//  GNASH_REPORT_FUNCTION;
 
478
 
 
479
   setInvalidatedRegion(bounds);
490
480
}
491
481
 
492
482
void
493
483
FBGui::setInvalidatedRegions(const InvalidatedRanges& ranges)
494
484
 {
495
 
     // GNASH_REPORT_FUNCTION;
 
485
//     GNASH_REPORT_FUNCTION;
496
486
 
497
 
#if 0
498
 
     FBAggGlue *fbag = reinterpret_cast<FBAggGlue *>(_glue.get());
499
 
     fbag->setInvalidatedRegions(ranges);
500
 
#endif
501
 
     _glue->setInvalidatedRegions(ranges);     
 
487
     _glue->setInvalidatedRegions(ranges);
502
488
}
503
489
 
504
490
char *
543
529
 
544
530
    _original_kd = -1;
545
531
    
546
 
    struct vt_stat vts;
547
 
    
548
532
    // Find the TTY device name
549
533
    
550
534
    char* tty = find_accessible_tty(0);
552
536
    int fd;
553
537
  
554
538
    if (!tty) {
555
 
        log_debug(_("WARNING: Could not detect controlling TTY"));
 
539
        log_error(_("Could not detect controlling TTY"));
556
540
        return false;
557
541
    }
558
542
    
559
 
    
560
543
    // Detect the currently active virtual terminal (so we can switch back to
561
544
    // it later)
562
545
    
563
546
    fd = open(tty, O_RDWR);
564
547
    if (fd < 0) {
565
 
        log_debug(_("WARNING: Could not open %s"), tty);
 
548
        log_error(_("Could not open %s"), tty);
566
549
        return false;
567
550
    }
568
551
    
 
552
    struct vt_stat vts;
569
553
    if (ioctl(fd, VT_GETSTATE, &vts) == -1) {
570
 
        log_debug(_("WARNING: Could not get current VT state"));
 
554
        log_error(_("Could not get current VT state"));
571
555
        close(_fd);
572
556
        return false;
573
557
    }
574
558
    
575
559
    _original_vt = vts.v_active;
576
 
    log_debug(_("Original TTY NO = %d"), _original_vt);
 
560
    // log_debug("Original TTY NO = %d", _original_vt);
577
561
  
578
562
#ifdef REQUEST_NEW_VT
579
563
    // Request a new VT number
580
564
    if (ioctl(fd, VT_OPENQRY, &_own_vt) == -1) {
581
 
        log_debug(_("WARNING: Could not request a new VT"));
 
565
        log_error(_("Could not request a new VT"));
582
566
        close(fd);
583
567
        return false;
584
568
    }
585
569
  
586
 
    log_debug(_("Own TTY NO = %d"), _own_vt);
 
570
    // log_debug("Own TTY NO = %d", _own_vt);
587
571
 
588
572
    if (fd > 0) {
589
573
        close(fd);
592
576
    // Activate our new VT
593
577
    tty = find_accessible_tty(_own_vt);
594
578
    if (!tty) {
595
 
        log_debug(_("WARNING: Could not find device for VT number %d"), _own_vt);
 
579
        log_error(_("Could not find device for VT number %d"), _own_vt);
596
580
        return false;
597
581
    }
598
582
  
599
583
    _fd = open(tty, O_RDWR);
600
584
    if (fd < 0) {
601
 
        log_debug(_("WARNING: Could not open %s"), tty);
 
585
        log_error(_("Could not open %s"), tty);
602
586
        return false;
603
587
    }
604
588
  
605
589
    if (ioctl(fd, VT_ACTIVATE, _own_vt) == -1) {
606
 
        log_debug(_("WARNING: Could not activate VT number %d"), _own_vt);
 
590
        log_error(_("Could not activate VT number %d"), _own_vt);
607
591
        close(fd);
608
592
        return false;
609
593
    }
610
594
  
611
595
    if (ioctl(fd, VT_WAITACTIVE, _own_vt) == -1) {
612
 
        log_debug(_("WARNING: Error waiting for VT %d becoming active"),
 
596
        log_error(_("Error waiting for VT %d becoming active"),
613
597
                  _own_vt);
614
598
        //close(tty);
615
599
        //return false;   don't abort
626
610
    // Activate our new VT
627
611
    tty = find_accessible_tty(_own_vt);
628
612
    if (!tty) {
629
 
        log_debug(_("WARNING: Could not find device for VT number %d"),
630
 
                  _own_vt);
 
613
        log_error(_("Could not find device for VT number %d"), _own_vt);
631
614
        return false;
632
615
    }
633
616
  
634
617
    fd = open(tty, O_RDWR);
635
618
    if (fd < 0) {
636
 
        log_debug(_("WARNING: Could not open %s"), tty);
 
619
        log_error(_("Could not open %s"), tty);
637
620
        return false;
638
621
    }
639
622
  
641
624
    // Become session leader and attach to terminal
642
625
    setsid();
643
626
    if (ioctl(fd, TIOCSCTTY, 0) == -1) {
644
 
    log_debug(_("WARNING: Could not attach controlling terminal (%s)"), tty);
 
627
    log_error(_("Could not attach controlling terminal (%s)"), tty);
645
628
    }
646
629
#endif
647
630
#endif  // end of if REQUEST_NEW_VT
649
632
    // Disable keyboard cursor
650
633
  
651
634
    if (ioctl(fd, KDGETMODE, &_original_kd) == -1) {
652
 
        log_debug(_("WARNING: Could not query current keyboard mode on VT"));
 
635
        log_error(_("Could not query current keyboard mode on VT"));
653
636
    }
654
637
 
655
638
    if (ioctl(fd, KDSETMODE, KD_GRAPHICS) == -1) {
656
 
        log_debug(_("WARNING: Could not switch to graphics mode on new VT"));
 
639
        log_error(_("Could not switch to graphics mode on new VT"));
657
640
    }
658
641
 
659
642
    if (fd > 0) {
660
643
        close(fd);
661
644
    }
662
645
  
663
 
    log_debug(_("VT %d ready"), _own_vt);  
 
646
    // log_debug("VT %d ready", _own_vt);  
664
647
  
665
648
    // NOTE: We could also implement virtual console switching by using 
666
649
    // VT_GETMODE / VT_SETMODE ioctl calls and handling their signals, but
674
657
{
675
658
    // GNASH_REPORT_FUNCTION;
676
659
 
677
 
    log_debug(_("Restoring terminal..."));
 
660
    // log_debug("Restoring terminal...");
678
661
 
679
662
    char* tty = find_accessible_tty(_own_vt);
680
663
    if (!tty) {
681
 
        log_debug(_("WARNING: Could not find device for VT number %d"), _own_vt);
 
664
        log_error(_("Could not find device for VT number %d"), _own_vt);
682
665
        return false;
683
666
    }
684
667
 
685
668
    int fd = open(tty, O_RDWR);
686
669
    if (fd < 0) {
687
 
        log_debug(_("WARNING: Could not open %s"), tty);
 
670
        log_error(_("Could not open %s"), tty);
688
671
        return false;
689
672
    }
690
673
 
691
674
    if (ioctl(fd, VT_ACTIVATE, _original_vt)) {
692
 
        log_debug(_("WARNING: Could not activate VT number %d"), _original_vt);
 
675
        log_error(_("Could not activate VT number %d"), _original_vt);
693
676
        close(_fd);
694
677
        return false;
695
678
    }
696
679
 
697
680
    if (ioctl(fd, VT_WAITACTIVE, _original_vt)) {
698
 
        log_debug(_("WARNING: Error waiting for VT %d becoming active"),
 
681
        log_error(_("Error waiting for VT %d becoming active"),
699
682
                  _original_vt);
700
683
        //close(tty);
701
684
        //return false;   don't abort
704
687
    // Restore keyboard
705
688
  
706
689
    if (ioctl(fd, KDSETMODE, _original_kd)) {
707
 
        log_debug(_("WARNING: Could not restore keyboard mode"));
 
690
        log_error(_("Could not restore keyboard mode"));
708
691
    }  
709
692
 
710
693
    if (fd > 0) {
724
707
    for (it=_inputs.begin(); it!=_inputs.end(); ++it) {
725
708
        (*it)->check();
726
709
        boost::shared_ptr<InputDevice::input_data_t> ie = (*it)->popData();
727
 
        if (ie) {
728
 
#if 1
 
710
        if (ie) {            
 
711
            // notifyMouseMove(ie->x, ie->y);
 
712
#if 0
729
713
            std::cerr << "Got data: " << ((ie->pressed) ? "true" : "false");
730
714
            std::cerr << ", " << ie->key << ", " << ie->modifier;
731
715
            std::cerr << ", " << ie->x << ", " << ie->y << std::endl;
732
716
            // cerr << "X = " << coords[0] << endl;
733
717
            // cerr << "Y = " << coords[1] << endl;
734
718
#endif
735
 
#if 0
736
719
            // Range check and convert the position from relative to
737
720
            // absolute
738
721
            boost::shared_array<int> coords =
739
 
                MouseDevice::convertCoordinates(ie->x, ie->y,
740
 
                                                getStage()->getStageWidth(),
741
 
                                                getStage()->getStageHeight());
 
722
                InputDevice::convertAbsCoords(ie->x, ie->y,
 
723
                                              getStage()->getStageWidth(),
 
724
                                              getStage()->getStageHeight());
742
725
            // The mouse was moved
 
726
            _uinput.moveTo(coords[0], coords[1]);
743
727
            if (coords) {
744
728
                notifyMouseMove(coords[0], coords[1]);
745
729
            }
746
 
#endif
 
730
            
747
731
            // See if a mouse button was clicked
748
732
            if (ie->pressed) {
749
733
                notifyMouseClick(true);
750
 
#if 0
 
734
#if 1
751
735
                double x = 0.655 * ie->x;
752
736
                double y = 0.46875 * ie->y;
753
 
                log_debug("Mouse clicked at: %g:%g", x, y);
 
737
                // log_debug("Mouse clicked at: %g:%g", x, y);
754
738
                notifyMouseMove(int(x), int(y));
755
739
#else
756
740
                notifyMouseMove(ie->x, ie->y);