From 9c79d52ca067eeff08034eea3c0d08d6be391e52 Mon Sep 17 00:00:00 2001 From: Alberto Valverde Date: Fri, 1 Oct 2010 11:22:39 +0000 Subject: [PATCH] Modified cairo_pattern in order to let cairo handle ownership of the image buffer. This solves the issue mentioned in [2254] properly as it wasn't solved properly before. The bug is uncovered in cairo 1.10.0 and caused that images added to pdf surfaces did not appear at all. My guess is that newest cairo reads the pattern surface lazily when "trasnfering" it to the target surface and by the time it does it the cairo_pattern which owns the buffer has already been destroyed. --- src/cairo_renderer.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index a81912401..fb7e2bf91 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -59,7 +59,9 @@ public: const unsigned int *in_end = in_ptr + pixels; unsigned int *out_ptr; - out_ptr = data_ = new unsigned int[pixels]; + surface_ = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, data.width(), data.height()); + + out_ptr = reinterpret_cast(surface_->get_data()); while (in_ptr < in_end) { @@ -75,14 +77,13 @@ public: *out_ptr++ = (a << 24) | (r << 16) | (g << 8) | b; } - - surface_ = Cairo::ImageSurface::create(reinterpret_cast(data_), Cairo::FORMAT_ARGB32, data.width(), data.height(), data.width() * 4); + // mark the surface as dirty as we've modified it behind cairo's back + surface_->mark_dirty(); pattern_ = Cairo::SurfacePattern::create(surface_); } ~cairo_pattern(void) { - delete [] data_; } void set_matrix(Cairo::Matrix const& matrix) @@ -118,7 +119,6 @@ public: } private: - unsigned int *data_; Cairo::RefPtr surface_; Cairo::RefPtr pattern_; }; @@ -344,7 +344,6 @@ public: context_->save(); context_->set_source(pattern.pattern()); context_->paint_with_alpha(opacity); - context_->get_target()->mark_dirty(); context_->restore(); }