2
// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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.
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.
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
21
/// \page gtk_shm_support GTK shared memory extension support
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.
35
#include "Renderer_agg.h"
36
#include "gtk_glue_agg.h"
41
GtkAggGlue::GtkAggGlue()
42
: _offscreenbuf(NULL),
47
GtkAggGlue::~GtkAggGlue()
50
gdk_image_destroy(_offscreenbuf);
55
GtkAggGlue::init(int /*argc*/, char ** /*argv*/[])
61
GtkAggGlue::prepDrawingArea(GtkWidget *drawing_area)
63
_drawing_area = drawing_area;
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);
71
GtkAggGlue::createRenderHandler()
73
GdkVisual* wvisual = gdk_drawable_get_visual(_drawing_area->window);
75
GdkImage* tmpimage = gdk_image_new (GDK_IMAGE_FASTEST, wvisual, 1, 1);
77
const GdkVisual* visual = tmpimage->visual;
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,
87
gdk_image_destroy(tmpimage);
89
_agg_renderer = create_Renderer_agg(pixelformat);
94
GtkAggGlue::setRenderHandlerSize(int width, int height)
98
assert(_agg_renderer != NULL);
100
if (_offscreenbuf && _offscreenbuf->width == width &&
101
_offscreenbuf->height == height) {
106
gdk_image_destroy(_offscreenbuf);
109
GdkVisual* visual = gdk_drawable_get_visual(_drawing_area->window);
111
_offscreenbuf = gdk_image_new (GDK_IMAGE_FASTEST, visual, width,
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,
123
GtkAggGlue::beforeRendering()
125
if (_offscreenbuf && _offscreenbuf->type == GDK_IMAGE_SHARED) {
133
render(0, 0, _offscreenbuf->width, _offscreenbuf->height);
138
GtkAggGlue::render(int minx, int miny, int maxx, int maxy)
140
if (!_offscreenbuf) {
146
size_t width = std::min(_offscreenbuf->width, maxx - minx);
147
size_t height = std::min(_offscreenbuf->height, maxy - miny);
149
GdkGC* gc = gdk_gc_new(_drawing_area->window);
151
gdk_draw_image(_drawing_area->window, gc, _offscreenbuf, x, y, x, y, width,
157
GtkAggGlue::configure(GtkWidget *const /*widget*/, GdkEventConfigure *const event)
160
setRenderHandlerSize(event->width, event->height);