From 555facb9c737be20cd923abc15875af0281a8927 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Tue, 11 Feb 2003 22:38:29 +0000 Subject: [PATCH] free the surfaces' pixeldata after rendering it --- otk/surface.cc | 14 ++++++++++++-- otk/surface.hh | 16 ++++++++++++++++ otk/truerendercontrol.hh | 12 ------------ otk/widget.cc | 1 + src/frame.cc | 2 ++ 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/otk/surface.cc b/otk/surface.cc index 3f5624d7..9fff018c 100644 --- a/otk/surface.cc +++ b/otk/surface.cc @@ -26,14 +26,23 @@ Surface::Surface(int screen, const Size &size) Surface::~Surface() { destroyObjects(); - delete [] _pixel_data; + freePixelData(); +} + +void Surface::freePixelData() +{ + if (_pixel_data) { + delete [] _pixel_data; + _pixel_data = 0; + } } void Surface::setPixmap(const RenderColor &color) { + assert(_pixel_data); if (_pixmap == None) createObjects(); - + XFillRectangle(**display, _pixmap, color.gc(), 0, 0, _size.width(), _size.height()); @@ -49,6 +58,7 @@ void Surface::setPixmap(const RenderColor &color) void Surface::setPixmap(XImage *image) { + assert(_pixel_data); assert(image->width == _size.width()); assert(image->height == _size.height()); diff --git a/otk/surface.hh b/otk/surface.hh index 40dfbf84..a44b9049 100644 --- a/otk/surface.hh +++ b/otk/surface.hh @@ -34,6 +34,18 @@ typedef u_int32_t pixel32; typedef u_int16_t pixel16; #endif /* HAVE_STDINT_H */ +#ifdef WORDS_BIGENDIAN +const int default_red_shift=0; +const int default_green_shift=8; +const int default_blue_shift=16; +const int endian=MSBFirst; +#else +const int default_red_shift=16; +const int default_green_shift=8; +const int default_blue_shift=0; +const int endian=LSBFirst; +#endif /* WORDS_BIGENDIAN */ + class Surface { int _screen; Size _size; @@ -60,6 +72,10 @@ public: pixel32 *pixelData() { return _pixel_data; } + //! Frees the pixel data when it will no longer be needed. Only do this once + //! you have completed rendering onto the surface. + void freePixelData(); + // The RenderControl classes use the internal objects in this class to render // to it. Noone else needs them tho, so they are private. friend class RenderControl; diff --git a/otk/truerendercontrol.hh b/otk/truerendercontrol.hh index e0a0b31b..a1bc47dc 100644 --- a/otk/truerendercontrol.hh +++ b/otk/truerendercontrol.hh @@ -8,18 +8,6 @@ namespace otk { -#ifdef WORDS_BIGENDIAN -const int default_red_shift=0; -const int default_green_shift=8; -const int default_blue_shift=16; -const int endian=MSBFirst; -#else -const int default_red_shift=16; -const int default_green_shift=8; -const int default_blue_shift=0; -const int endian=LSBFirst; -#endif /* WORDS_BIGENDIAN */ - class TrueRenderControl : public RenderControl { private: // the number of bits to shift a color value (from 0-255) to the right, to diff --git a/otk/widget.cc b/otk/widget.cc index eccbb521..690224d8 100644 --- a/otk/widget.cc +++ b/otk/widget.cc @@ -508,6 +508,7 @@ void Widget::render() // delete the old surface *after* its pixmap isn't in use anymore if (_surface) delete _surface; + s->freePixelData(); // done rendering with this surface _surface = s; _dirty = false; diff --git a/src/frame.cc b/src/frame.cc index 5f63d17c..a4188b6e 100644 --- a/src/frame.cc +++ b/src/frame.cc @@ -227,6 +227,7 @@ static void render(int screen, const otk::Size &size, Window win, XSetWindowBackgroundPixmap(**otk::display, win, s->pixmap()); XClearWindow(**otk::display, win); if (*surface) delete *surface; + s->freePixelData(); *surface = s; } @@ -382,6 +383,7 @@ void Frame::renderLabel() XSetWindowBackgroundPixmap(**otk::display, _label, s->pixmap()); XClearWindow(**otk::display, _label); if (_label_sur) delete _label_sur; + s->freePixelData(); _label_sur = s; } -- 2.45.2