~ubuntu-branches/ubuntu/maverick/gnash/maverick

« back to all changes in this revision

Viewing changes to gui/gtk_glue_agg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Micah Gersten, Micah Gersten, Chris Coulson
  • Date: 2010-09-28 23:38:37 UTC
  • mfrom: (1.1.14 upstream) (3.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20100928233837-wcay0dodera1c7sz
Tags: 0.8.8-5ubuntu1
[ Micah Gersten <micahg@ubuntu.com> ]
* FFe - LP: #636667
* Merge from debian unstable.  Remaining changes:
  + Add Ubuntu flash alternatives in postinst and prerm
    - update debian/browser-plugin-gnash.postinst
    - update debian/browser-plugin-gnash.prerm

[ Chris Coulson <chris.coulson@canonical.com> ]
* Ensure the directories we are installing alternatives too exist
  already
  - add debian/browser-plugin-gnash.dirs

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
18
 
 
19
 
 
20
 
 
21
 
/// \page gtk_shm_support GTK shared memory extension support
22
 
/// 
23
 
/// We use GdkImage to manage the rendering buffer for us. It supports
24
 
/// automatic detection and usage of MIT-ShM, so we don't have to worry about
25
 
/// it beyond synchronising the screen before rendering.
26
 
 
27
 
#include <cerrno>
28
 
#include <exception>
29
 
#include <gtk/gtk.h>
30
 
#include <gdk/gdk.h>
31
 
 
32
 
#include "gnash.h"
33
 
#include "log.h"
34
 
#include "Renderer.h"
35
 
#include "Renderer_agg.h"
36
 
#include "gtk_glue_agg.h"
37
 
 
38
 
namespace gnash
39
 
{
40
 
 
41
 
GtkAggGlue::GtkAggGlue()
42
 
:   _offscreenbuf(NULL),
43
 
    _agg_renderer(NULL)
44
 
{
45
 
}
46
 
 
47
 
GtkAggGlue::~GtkAggGlue()
48
 
{
49
 
    if (_offscreenbuf) {
50
 
        gdk_image_destroy(_offscreenbuf);
51
 
    }
52
 
}
53
 
 
54
 
bool
55
 
GtkAggGlue::init(int /*argc*/, char ** /*argv*/[])
56
 
{
57
 
    return true;
58
 
}
59
 
 
60
 
void
61
 
GtkAggGlue::prepDrawingArea(GtkWidget *drawing_area)
62
 
{
63
 
    _drawing_area = drawing_area;
64
 
 
65
 
    // Disable double buffering, otherwise gtk tries to update widget
66
 
    // contents from its internal offscreen buffer at the end of expose event
67
 
    gtk_widget_set_double_buffered(_drawing_area, FALSE);
68
 
}
69
 
 
70
 
Renderer*
71
 
GtkAggGlue::createRenderHandler()
72
 
{
73
 
    GdkVisual* wvisual = gdk_drawable_get_visual(_drawing_area->window);
74
 
 
75
 
    GdkImage* tmpimage = gdk_image_new (GDK_IMAGE_FASTEST, wvisual, 1, 1);
76
 
 
77
 
    const GdkVisual* visual = tmpimage->visual;
78
 
 
79
 
    // FIXME: we use bpp instead of depth, because depth doesn't appear to
80
 
    // include the padding byte(s) the GdkImage actually has.
81
 
    const char *pixelformat = agg_detect_pixel_format(
82
 
        visual->red_shift, visual->red_prec,
83
 
        visual->green_shift, visual->green_prec,
84
 
        visual->blue_shift, visual->blue_prec,
85
 
        tmpimage->bpp * 8);
86
 
 
87
 
    gdk_image_destroy(tmpimage);
88
 
 
89
 
    _agg_renderer = create_Renderer_agg(pixelformat);
90
 
    return _agg_renderer;
91
 
}
92
 
 
93
 
void
94
 
GtkAggGlue::setRenderHandlerSize(int width, int height)
95
 
{
96
 
    assert(width > 0);
97
 
    assert(height > 0);
98
 
    assert(_agg_renderer != NULL);
99
 
    
100
 
    if (_offscreenbuf && _offscreenbuf->width == width &&
101
 
        _offscreenbuf->height == height) {
102
 
        return; 
103
 
    }
104
 
 
105
 
    if (_offscreenbuf) {
106
 
        gdk_image_destroy(_offscreenbuf);
107
 
    }
108
 
 
109
 
    GdkVisual* visual = gdk_drawable_get_visual(_drawing_area->window);
110
 
 
111
 
    _offscreenbuf = gdk_image_new (GDK_IMAGE_FASTEST, visual, width,
112
 
                                   height);
113
 
 
114
 
        static_cast<Renderer_agg_base *>(_agg_renderer)->init_buffer(
115
 
        (unsigned char*) _offscreenbuf->mem,
116
 
        _offscreenbuf->bpl * _offscreenbuf->height,
117
 
        _offscreenbuf->width,
118
 
        _offscreenbuf->height,
119
 
        _offscreenbuf->bpl); 
120
 
}
121
 
 
122
 
void 
123
 
GtkAggGlue::beforeRendering()
124
 
{
125
 
    if (_offscreenbuf && _offscreenbuf->type == GDK_IMAGE_SHARED) {
126
 
         gdk_flush();
127
 
    }
128
 
}
129
 
 
130
 
void
131
 
GtkAggGlue::render()
132
 
{
133
 
    render(0, 0, _offscreenbuf->width, _offscreenbuf->height);
134
 
}
135
 
 
136
 
 
137
 
void
138
 
GtkAggGlue::render(int minx, int miny, int maxx, int maxy)
139
 
{
140
 
     if (!_offscreenbuf) {
141
 
         return;
142
 
     }
143
 
 
144
 
     const int& x = minx;
145
 
     const int& y = miny;
146
 
     size_t width = std::min(_offscreenbuf->width, maxx - minx);
147
 
     size_t height = std::min(_offscreenbuf->height, maxy - miny);
148
 
 
149
 
     GdkGC* gc = gdk_gc_new(_drawing_area->window);
150
 
    
151
 
     gdk_draw_image(_drawing_area->window, gc, _offscreenbuf, x, y, x, y, width,
152
 
                    height);
153
 
     gdk_gc_unref(gc);
154
 
}
155
 
 
156
 
void
157
 
GtkAggGlue::configure(GtkWidget *const /*widget*/, GdkEventConfigure *const event)
158
 
{
159
 
    if (_agg_renderer) {
160
 
        setRenderHandlerSize(event->width, event->height);
161
 
    }
162
 
}
163
 
 
164
 
} // namespace gnash
165