[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r9516: C++ify gtk_glue_agg.
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r9516: C++ify gtk_glue_agg. |
Date: |
Tue, 22 Jul 2008 10:37:17 +0200 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9516
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Tue 2008-07-22 10:37:17 +0200
message:
C++ify gtk_glue_agg.
modified:
gui/gtk_glue_agg.cpp
gui/gtk_glue_agg.h
------------------------------------------------------------
revno: 9507.1.7
committer: Benjamin Wolsey <address@hidden>
branch nick: workingcopy
timestamp: Tue 2008-07-22 10:00:17 +0200
message:
Use a std::string instead of const char* for the pixel format. Use a
boost::scoped_array and operator new instead of C array and realloc,
for the offscreen buffer, which is simpler, standard-compliant and
exception-safe. Reallocate the buffer when it shrinks too (the number
of reallocations could be reduced by taking the chunk size into
account).
Make spacing and brackets consistent throughout gtk_glue_agg.cpp.
Catch std::bad_alloc, add TODO for what to do about it (the same problem
existed before, as the pointer value was checked after realloc).
modified:
gui/gtk_glue_agg.cpp
gui/gtk_glue_agg.h
=== modified file 'gui/gtk_glue_agg.cpp'
--- a/gui/gtk_glue_agg.cpp 2008-07-15 08:32:00 +0000
+++ b/gui/gtk_glue_agg.cpp 2008-07-22 08:00:17 +0000
@@ -42,10 +42,9 @@
// Also worth checking: http://en.wikipedia.org/wiki/X_video_extension
-
-#include <cstdio>
#include <cerrno>
-#include <cstring>
+#include <cstring> // std::memset
+#include <exception>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
@@ -68,28 +67,23 @@
{
GtkAggGlue::GtkAggGlue() :
- _offscreenbuf(NULL),
- _offscreenbuf_size(0),
- _agg_renderer(NULL),
- _width(0),
- _height(0),
- _bpp(0),
- _have_shm(false)
+ _offscreenbuf(NULL),
+ _offscreenbuf_size(0),
+ _agg_renderer(NULL),
+ _width(0),
+ _height(0),
+ _bpp(0),
+ _have_shm(false)
#ifdef ENABLE_MIT_SHM
,_shm_image(NULL)
,_shm_info(NULL)
-#endif
+#endif
{
}
GtkAggGlue::~GtkAggGlue()
{
- if (_offscreenbuf) {
- free(_offscreenbuf);
- _offscreenbuf=NULL;
- }
-
- destroy_shm_image();
+ destroy_shm_image();
}
bool
@@ -104,9 +98,11 @@
#endif
if (!detect_pixelformat()) {
- printf("FATAL: Could not detect the pixel format used by your X
server.\n");
- printf("Please report this problem to the Gnash developer team.\n");
- return false;
+ // Perhaps this should be logged independently of verbosity. In this
+ // case use std::cerr.
+ log_error("FATAL: Could not detect the pixel format used by your X
server.");
+ log_error("Please report this problem to the Gnash developer team.");
+ return false;
}
log_debug("Your X server expects %s pixmap data for standard mode.",
_pixelformat);
@@ -122,32 +118,29 @@
#endif
{
#ifdef ENABLE_MIT_SHM
- int major, minor, dummy;
- Bool pixmaps;
-
- log_debug("Checking support for MIT-SHM...");
-
- if (!XQueryExtension(display, "MIT-SHM", &dummy, &dummy, &dummy))
- {
- log_debug("WARNING: No MIT-SHM extension available, using standard XLib "
- "calls (slower)");
- return false;
- }
-
- if (XShmQueryVersion(display, &major, &minor, &pixmaps )!=True)
- {
- log_debug("WARNING: MIT-SHM not ready (network link?), using standard XLib
"
- "calls (slower)");
- return false;
- }
-
- log_debug("NOTICE: MIT-SHM available (version %d.%d)!", major, minor);
-
- return true;
-
-
+ int major, minor, dummy;
+ Bool pixmaps;
+
+ log_debug("Checking support for MIT-SHM...");
+
+ if (!XQueryExtension(display, "MIT-SHM", &dummy, &dummy, &dummy)) {
+ log_debug("WARNING: No MIT-SHM extension available, using standard
XLib "
+ "calls (slower)");
+ return false;
+ }
+
+ if (XShmQueryVersion(display, &major, &minor, &pixmaps )!=True) {
+ log_debug("WARNING: MIT-SHM not ready (network link?), using standard
XLib "
+ "calls (slower)");
+ return false;
+ }
+
+ log_debug("NOTICE: MIT-SHM available (version %d.%d)!", major, minor);
+
+ return true;
+
#else
- return false; // !ifdef ENABLE_MIT_SHM
+ return false; // !ifdef ENABLE_MIT_SHM
#endif
}
@@ -156,61 +149,61 @@
GtkAggGlue::create_shm_image(unsigned int width, unsigned int height)
{
- // destroy any already existing structures
- destroy_shm_image();
+ // destroy any already existing structures
+ destroy_shm_image();
#ifdef ENABLE_MIT_SHM
- GdkVisual* visual = gdk_drawable_get_visual(_drawing_area->window);
- Visual* xvisual = GDK_VISUAL_XVISUAL(visual);
-
- // prepare segment info (populated by XShmCreateImage)
- _shm_info = (XShmSegmentInfo*) malloc(sizeof(XShmSegmentInfo));
- assert(_shm_info != NULL);
-
- // create shared memory XImage
- _shm_image = XShmCreateImage(gdk_display, xvisual, visual->depth,
- ZPixmap, NULL, _shm_info, width, height);
+ GdkVisual* visual = gdk_drawable_get_visual(_drawing_area->window);
+ Visual* xvisual = GDK_VISUAL_XVISUAL(visual);
+
+ // prepare segment info (populated by XShmCreateImage)
+ _shm_info = (XShmSegmentInfo*) malloc(sizeof(XShmSegmentInfo));
+ assert(_shm_info != NULL);
+
+ // create shared memory XImage
+ _shm_image = XShmCreateImage(gdk_display, xvisual, visual->depth,
+ ZPixmap, NULL, _shm_info, width, height);
- if (!_shm_image) {
- log_debug("Failed creating the shared memory XImage!");
- destroy_shm_image();
- return;
- }
+ if (!_shm_image) {
+ log_debug("Failed creating the shared memory XImage!");
+ destroy_shm_image();
+ return;
+ }
- // create shared memory segment
- _shm_info->shmid = shmget(IPC_PRIVATE,
+ // create shared memory segment
+ _shm_info->shmid = shmget(IPC_PRIVATE,
_shm_image->bytes_per_line * _shm_image->height, IPC_CREAT|0777);
- if (_shm_info->shmid == -1) {
- log_debug("Failed requesting shared memory segment (%s). Perhaps the "
- "required memory size is bigger than the limit set by the kernel.",
- strerror(errno));
- destroy_shm_image();
- return;
- }
-
- // attach the shared memory segment to our process
- _shm_info->shmaddr = _shm_image->data = (char*) shmat(_shm_info->shmid, 0,
0);
-
- if (_shm_info->shmaddr == (char*) -1) {
- log_debug("Failed attaching to shared memory segment: %s",
strerror(errno));
- destroy_shm_image();
- return;
- }
-
- // Give the server full access to our memory segment. We just follow
- // the documentation which recommends this, but we could also give him
- // just read-only access since we don't need XShmGetImage...
- _shm_info->readOnly = False;
-
- // Finally, tell the server to attach to our shared memory segment
- if (!XShmAttach(gdk_display, _shm_info)) {
- log_debug("Server failed attaching to the shared memory segment");
- destroy_shm_image();
- return;
- }
-
- //log_debug("create_shm_image() OK"); // <-- remove this
+ if (_shm_info->shmid == -1) {
+ log_debug("Failed requesting shared memory segment (%s). Perhaps the "
+ "required memory size is bigger than the limit set by the kernel.",
+ std::strerror(errno));
+ destroy_shm_image();
+ return;
+ }
+
+ // attach the shared memory segment to our process
+ _shm_info->shmaddr = _shm_image->data = (char*) shmat(_shm_info->shmid, 0,
0);
+
+ if (_shm_info->shmaddr == (char*) -1) {
+ log_debug("Failed attaching to shared memory segment: %s",
strerror(errno));
+ destroy_shm_image();
+ return;
+ }
+
+ // Give the server full access to our memory segment. We just follow
+ // the documentation which recommends this, but we could also give him
+ // just read-only access since we don't need XShmGetImage...
+ _shm_info->readOnly = False;
+
+ // Finally, tell the server to attach to our shared memory segment
+ if (!XShmAttach(gdk_display, _shm_info)) {
+ log_debug("Server failed attaching to the shared memory segment");
+ destroy_shm_image();
+ return;
+ }
+
+ //log_debug("create_shm_image() OK"); // <-- remove this
#endif // ENABLE_MIT_SHM
}
@@ -219,16 +212,16 @@
GtkAggGlue::destroy_shm_image()
{
#ifdef ENABLE_MIT_SHM
- if (_shm_image) {
- XDestroyImage(_shm_image);
- _shm_image=NULL;
- }
-
- if (_shm_info) {
- free(_shm_info);
- _shm_info=NULL;
- }
-
+ if (_shm_image) {
+ XDestroyImage(_shm_image);
+ _shm_image=NULL;
+ }
+
+ if (_shm_info) {
+ free(_shm_info);
+ _shm_info=NULL;
+ }
+
#endif
}
@@ -252,9 +245,9 @@
#ifdef PIXELFORMAT_RGB24 // normal case
- _bpp = 24;
- strcpy(_pixelformat, "RGB24");
- return true;
+ _bpp = 24;
+ _pixelformat = "RGB24";
+ return true;
#else
@@ -263,17 +256,17 @@
#warning A pixel format of RGB565; you must have a (hacked) GTK which supports
\
this format (e.g., GTK on the OLPC).
- _bpp = 16;
- strcpy(_pixelformat, "RGB565");
- return true;
+ _bpp = 16;
+ _pixelformat = "RGB565";
+ return true;
#else
#warning GTK GUI requires --with-pixelformat=RGB24 for AGG renderer
- printf("Missing a supported pixel format for GTK GUI. You probably want to "
- "configure --with-pixelformat=RGB24\n");
- return false;
+ log_error("Missing a supported pixel format for GTK GUI. You probably want
to "
+ "configure --with-pixelformat=RGB24");
+ return false;
#endif //ifdef PIXELFORMAT_RGB565
@@ -286,184 +279,179 @@
GtkAggGlue::create_shm_handler()
{
#ifdef ENABLE_MIT_SHM
- GdkVisual *visual = gdk_drawable_get_visual(_drawing_area->window);
-
- // Create a dummy SHM image to detect it's pixel format (we can't use the
- // info from "visual").
- // Is there a better way??
-
- create_shm_image(256,256);
-
- if (!_shm_image) return NULL;
-
- unsigned int red_shift, red_prec;
- unsigned int green_shift, green_prec;
- unsigned int blue_shift, blue_prec;
-
- decode_mask(_shm_image->red_mask, &red_shift, &red_prec);
- decode_mask(_shm_image->green_mask, &green_shift, &green_prec);
- decode_mask(_shm_image->blue_mask, &blue_shift, &blue_prec);
-
-
- log_debug("X server pixel format is (R%d:%d, G%d:%d, B%d:%d, %d bpp)",
- red_shift, red_prec,
- green_shift, green_prec,
- blue_shift, blue_prec,
- _shm_image->bits_per_pixel);
-
-
- const char *pixelformat = agg_detect_pixel_format(
- red_shift, red_prec,
- green_shift, green_prec,
- blue_shift, blue_prec,
- _shm_image->bits_per_pixel);
-
- destroy_shm_image();
-
- if (!pixelformat) {
- log_debug("Pixel format of X server not recognized!");
-
- // disable use of shared memory pixmaps
- _have_shm = false;
-
- return NULL;
- }
-
- log_debug("X server is using %s pixel format", pixelformat);
-
- render_handler* res = create_render_handler_agg(pixelformat);
-
- if (!res) {
- log_debug("Failed creating a renderer instance for this pixel format. "
- "Most probably Gnash has not compiled in (configured) support "
- "for this pixel format - using standard pixmaps instead");
-
- // disable use of shared memory pixmaps
- _have_shm = false;
- }
-
-
- return res;
+ GdkVisual *visual = gdk_drawable_get_visual(_drawing_area->window);
+
+ // Create a dummy SHM image to detect it's pixel format (we can't use the
+ // info from "visual").
+ // Is there a better way??
+
+ create_shm_image(256,256);
+
+ if (!_shm_image) return NULL;
+
+ unsigned int red_shift, red_prec;
+ unsigned int green_shift, green_prec;
+ unsigned int blue_shift, blue_prec;
+
+ decode_mask(_shm_image->red_mask, &red_shift, &red_prec);
+ decode_mask(_shm_image->green_mask, &green_shift, &green_prec);
+ decode_mask(_shm_image->blue_mask, &blue_shift, &blue_prec);
+
+
+ log_debug("X server pixel format is (R%d:%d, G%d:%d, B%d:%d, %d bpp)",
+ red_shift, red_prec,
+ green_shift, green_prec,
+ blue_shift, blue_prec,
+ _shm_image->bits_per_pixel);
+
+
+ const char *pixelformat = agg_detect_pixel_format(
+ red_shift, red_prec,
+ green_shift, green_prec,
+ blue_shift, blue_prec,
+ _shm_image->bits_per_pixel);
+
+ destroy_shm_image();
+
+ if (!pixelformat) {
+ log_debug("Pixel format of X server not recognized!");
+
+ // disable use of shared memory pixmaps
+ _have_shm = false;
+
+ return NULL;
+ }
+
+ log_debug("X server is using %s pixel format", pixelformat);
+
+ render_handler* res = create_render_handler_agg(pixelformat);
+
+ if (!res) {
+ log_debug("Failed creating a renderer instance for this pixel format. "
+ "Most probably Gnash has not compiled in (configured) support "
+ "for this pixel format - using standard pixmaps instead");
+
+ // disable use of shared memory pixmaps
+ _have_shm = false;
+ }
+
+
+ return res;
#else
- return NULL;
+ return NULL;
#endif
}
render_handler*
GtkAggGlue::createRenderHandler()
{
-
- // try with MIT-SHM
- if (_have_shm) {
- _agg_renderer = create_shm_handler();
- if (_agg_renderer) return _agg_renderer;
- }
-
- _agg_renderer = create_render_handler_agg(_pixelformat);
- return _agg_renderer;
+ // try with MIT-SHM
+ if (_have_shm) {
+ _agg_renderer = create_shm_handler();
+ if (_agg_renderer) return _agg_renderer;
+ }
+
+ _agg_renderer = create_render_handler_agg(_pixelformat.c_str());
+ return _agg_renderer;
}
void
GtkAggGlue::setRenderHandlerSize(int width, int height)
{
- assert(width>0);
- assert(height>0);
- assert(_agg_renderer!=NULL);
-
- #define CHUNK_SIZE (100*100*(_bpp/8))
-
- if (width == _width && height == _height)
- return;
-
- _width = width;
- _height = height;
-
-
- // try shared image first
- if (_have_shm)
- create_shm_image(width, height);
-
-#ifdef ENABLE_MIT_SHM
- if (_shm_image) {
-
- // ==> use shared memory image (faster)
-
- log_debug("GTK-AGG: Using shared memory image");
-
- if (_offscreenbuf) {
- free(_offscreenbuf);
- _offscreenbuf = NULL;
- }
-
- static_cast<render_handler_agg_base *>(_agg_renderer)->init_buffer(
- (unsigned char*) _shm_info->shmaddr,
- _shm_image->bytes_per_line * _shm_image->height,
- _width,
- _height,
- _shm_image->bytes_per_line
- );
-
- } else {
-#endif
-
- // ==> use standard pixmaps (slower, but should work in any case)
-
- int new_bufsize = width*height*((_bpp+7)/8);
-
- // TODO: At the moment we only increase the buffer and never decrease
it. Should be
- // changed sometime.
- if (new_bufsize > _offscreenbuf_size) {
- new_bufsize = static_cast<int>(new_bufsize / CHUNK_SIZE + 1) *
CHUNK_SIZE;
- // TODO: C++ conform alternative to realloc?
- _offscreenbuf = static_cast<unsigned char *>(
realloc(_offscreenbuf, new_bufsize) );
-
- if (!_offscreenbuf) {
- log_debug("Could not allocate %i bytes for offscreen buffer:
%s\n",
- new_bufsize, strerror(errno)
- );
- return;
- }
-
- log_debug("GTK-AGG: %i bytes offscreen buffer allocated\n",
new_bufsize);
-
- _offscreenbuf_size = new_bufsize;
- memset(_offscreenbuf, 0, new_bufsize);
- }
-
- // Only the AGG renderer has the function init_buffer, which is *not*
part of
- // the renderer api. It allows us to change the renderers movie size
(and buffer
- // address) during run-time.
- static_cast<render_handler_agg_base *>(_agg_renderer)->init_buffer(
- _offscreenbuf,
- _offscreenbuf_size,
- _width,
- _height,
- _width*((_bpp+7)/8)
- );
-
-
-#ifdef ENABLE_MIT_SHM
- }
+ assert(width > 0);
+ assert(height > 0);
+ assert(_agg_renderer != NULL);
+
+ const size_t CHUNK_SIZE = 100 * 100 * (_bpp / 8);
+
+ if (width == _width && height == _height) return;
+
+ _width = width;
+ _height = height;
+
+ // try shared image first
+ if (_have_shm) {
+ create_shm_image(width, height);
+ }
+
+#ifdef ENABLE_MIT_SHM
+ if (_shm_image) {
+
+ // ==> use shared memory image (faster)
+ log_debug("GTK-AGG: Using shared memory image");
+
+ static_cast<render_handler_agg_base *>(_agg_renderer)->init_buffer(
+ (unsigned char*) _shm_info->shmaddr,
+ _shm_image->bytes_per_line * _shm_image->height,
+ _width,
+ _height,
+ _shm_image->bytes_per_line
+ );
+
+ }
+ else {
+#endif
+
+ // ==> use standard pixmaps (slower, but should work in any case)
+ size_t newBufferSize = width * height * ((_bpp + 7) / 8);
+
+ // Reallocate the buffer when it shrinks or grows.
+ if (newBufferSize != _offscreenbuf_size) {
+
+ newBufferSize = (newBufferSize / CHUNK_SIZE + 1) * CHUNK_SIZE;
+
+ try {
+ _offscreenbuf.reset(new unsigned char[newBufferSize]);
+ log_debug("GTK-AGG %i bytes offscreen buffer allocated",
newBufferSize);
+ }
+ catch (std::bad_alloc &e)
+ {
+ log_error("Could not allocate %i bytes for offscreen buffer:
%s",
+ newBufferSize, e.what());
+
+ // TODO: what to do here? An assertion in
render_handler_agg.cpp
+ // fails if we just return.
+ return;
+ }
+
+ _offscreenbuf_size = newBufferSize;
+ std::memset(_offscreenbuf.get(), 0, _offscreenbuf_size);
+ }
+
+ // Only the AGG renderer has the function init_buffer, which is *not*
part of
+ // the renderer api. It allows us to change the renderers movie size
(and buffer
+ // address) during run-time.
+ static_cast<render_handler_agg_base *>(_agg_renderer)->init_buffer(
+ _offscreenbuf.get(),
+ _offscreenbuf_size,
+ _width,
+ _height,
+ _width*((_bpp+7)/8)
+ );
+
+
+#ifdef ENABLE_MIT_SHM
+ }
#endif
-
+
}
void
GtkAggGlue::beforeRendering()
{
#ifdef ENABLE_MIT_SHM
- if (_shm_image) {
- // The shared memory buffer is copied in background(!) since the X
- // calls are executed asynchroneously. This is dangerous because it
- // may happen that the renderer updates the buffer while the X server
- // still copies the data to the VRAM (flicker can occurr).
- // Instead of using the XShmCompletionEvent for this we just call XSync
- // right before writing to the shared memory again. This will make sure
- // that the X server finishes to copy the data to VRAM before we
- // change it again.
- XSync(gdk_display, False);
- }
+ if (_shm_image) {
+ // The shared memory buffer is copied in background(!) since the X
+ // calls are executed asynchroneously. This is dangerous because it
+ // may happen that the renderer updates the buffer while the X server
+ // still copies the data to the VRAM (flicker can occurr).
+ // Instead of using the XShmCompletionEvent for this we just call XSync
+ // right before writing to the shared memory again. This will make sure
+ // that the X server finishes to copy the data to VRAM before we
+ // change it again.
+ XSync(gdk_display, False);
+ }
#endif
}
@@ -472,86 +460,88 @@
{
#ifdef ENABLE_MIT_SHM
- if (_shm_image) {
+ if (_shm_image) {
- XShmPutImage(
- gdk_display,
- GDK_WINDOW_XWINDOW(_drawing_area->window),
- GDK_GC_XGC(_drawing_area->style->fg_gc[GTK_STATE_NORMAL]), // ???
- _shm_image,
- 0, 0,
- 0, 0,
- _width, _height,
- False);
+ XShmPutImage(
+ gdk_display,
+ GDK_WINDOW_XWINDOW(_drawing_area->window),
+ GDK_GC_XGC(_drawing_area->style->fg_gc[GTK_STATE_NORMAL]), // ???
+ _shm_image,
+ 0, 0,
+ 0, 0,
+ _width, _height,
+ False);
// NOTE: Data will be copied in background, see beforeRendering()
- } else {
+ }
+ else {
#endif
- // Update the entire screen
- gdk_draw_rgb_image (
- _drawing_area->window,
- _drawing_area->style->fg_gc[GTK_STATE_NORMAL],
- 0,
- 0,
- _width,
- _height,
- GDK_RGB_DITHER_NONE,
- _offscreenbuf,
- _width*((_bpp+7)/8)
- );
+ // Update the entire screen
+ gdk_draw_rgb_image (
+ _drawing_area->window,
+ _drawing_area->style->fg_gc[GTK_STATE_NORMAL],
+ 0,
+ 0,
+ _width,
+ _height,
+ GDK_RGB_DITHER_NONE,
+ _offscreenbuf.get(),
+ _width*((_bpp+7)/8)
+ );
#ifdef ENABLE_MIT_SHM
- }
+ }
#endif
-
+
}
void
GtkAggGlue::render(int minx, int miny, int maxx, int maxy)
{
#ifdef ENABLE_MIT_SHM
- if (_shm_image) {
+ if (_shm_image) {
XShmPutImage(
- gdk_display,
- GDK_WINDOW_XWINDOW(_drawing_area->window),
- GDK_GC_XGC(_drawing_area->style->fg_gc[GTK_STATE_NORMAL]), // ???
- _shm_image,
- minx, miny,
- minx, miny,
- maxx-minx+1, maxy-miny+1,
- False);
+ gdk_display,
+ GDK_WINDOW_XWINDOW(_drawing_area->window),
+ GDK_GC_XGC(_drawing_area->style->fg_gc[GTK_STATE_NORMAL]), // ???
+ _shm_image,
+ minx, miny,
+ minx, miny,
+ maxx-minx+1, maxy-miny+1,
+ False);
// NOTE: Data will be copied in background, see beforeRendering()
-
- } else {
+
+ }
+ else {
#endif
- size_t copy_width = std::min(_width * (_bpp/8), maxx - minx);
- size_t copy_height = std::min(_height, maxy - miny);
- size_t stride = _width*((_bpp+7)/8);
+ size_t copy_width = std::min(_width * (_bpp/8), maxx - minx);
+ size_t copy_height = std::min(_height, maxy - miny);
+ size_t stride = _width*((_bpp+7)/8);
// log_debug("minx: %d, miny: %d, copy width: %d, copy height: %d, stride:
%d",
// minx, miny, copy_width, copy_height, stride);
// log_debug("offscreenbuf size: %d", _offscreenbuf_size);
// log_debug("From: %d", miny * stride + minx * (_bpp/8));
- // Update only the invalidated rectangle
- gdk_draw_rgb_image (
- _drawing_area->window,
- _drawing_area->style->fg_gc[GTK_STATE_NORMAL],
- minx,
- miny,
- copy_width,
- copy_height,
- GDK_RGB_DITHER_NORMAL,
- _offscreenbuf + miny * stride + minx * (_bpp/8),
- stride
- );
+ // Update only the invalidated rectangle
+ gdk_draw_rgb_image (
+ _drawing_area->window,
+ _drawing_area->style->fg_gc[GTK_STATE_NORMAL],
+ minx,
+ miny,
+ copy_width,
+ copy_height,
+ GDK_RGB_DITHER_NORMAL,
+ _offscreenbuf.get() + miny * stride + minx * (_bpp/8),
+ stride
+ );
#ifdef ENABLE_MIT_SHM
- }
+ }
#endif
}
@@ -567,20 +557,20 @@
void
GtkAggGlue::decode_mask(unsigned long mask, unsigned int *shift, unsigned int
*size)
{
- *shift = 0;
- *size = 0;
-
- if (mask==0) return; // invalid mask
-
- while (!(mask & 1)) {
- (*shift)++;
- mask = mask >> 1;
- }
-
- while (mask & 1) {
- (*size)++;
- mask = mask >> 1;
- }
+ *shift = 0;
+ *size = 0;
+
+ if (mask==0) return; // invalid mask
+
+ while (!(mask & 1)) {
+ (*shift)++;
+ mask = mask >> 1;
+ }
+
+ while (mask & 1) {
+ (*size)++;
+ mask = mask >> 1;
+ }
}
} // namespace gnash
=== modified file 'gui/gtk_glue_agg.h'
--- a/gui/gtk_glue_agg.h 2008-06-27 03:50:30 +0000
+++ b/gui/gtk_glue_agg.h 2008-07-22 08:00:17 +0000
@@ -24,6 +24,8 @@
#include <gtk/gtk.h>
#include <gdk/gdk.h>
+#include <memory>
+#include <boost/scoped_array.hpp>
#undef ENABLE_MIT_SHM
@@ -54,11 +56,19 @@
void configure(GtkWidget *const widget, GdkEventConfigure *const event);
private:
- unsigned char *_offscreenbuf;
- int _offscreenbuf_size;
+
+ // A buffer to hold the actual image data. A boost::scoped_array
+ // is destroyed on reset and when it goes out of scope (including on
+ // stack unwinding after an exception), so there is no need to delete
+ // it.
+ boost::scoped_array<unsigned char> _offscreenbuf;
+
+ // The size of the offscreen image buffer.
+ size_t _offscreenbuf_size;
+
render_handler *_agg_renderer;
int _width, _height, _bpp;
- char _pixelformat[16];
+ std::string _pixelformat;
bool _have_shm;
#ifdef ENABLE_MIT_SHM
XImage *_shm_image;
- [Gnash-commit] /srv/bzr/gnash/trunk r9516: C++ify gtk_glue_agg.,
Benjamin Wolsey <=