Permalink
Browse files

ImageBufferCairo: tie the FastMalloc-ed buffer lifetime to the Cairo …

…surface.
  • Loading branch information...
1 parent 12f2dd5 commit 8ca8ebcaa3096da6c80a664b0be05738a3da0b79 @zdobersek zdobersek committed Jan 11, 2017
@@ -227,10 +227,13 @@ ImageBuffer::ImageBuffer(const FloatSize& size, float resolutionScale, ColorSpac
ASSERT(m_data.m_renderingMode != Accelerated);
#endif
{
+ static cairo_user_data_key_t s_surfaceDataKey;
+
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, m_size.width());
- m_data.m_surfaceData = MallocPtr<unsigned char>::malloc(m_size.height() * stride);
- memset(m_data.m_surfaceData.get(), 0, m_size.height() * stride);
- m_data.m_surface = adoptRef(cairo_image_surface_create_for_data(m_data.m_surfaceData.get(), CAIRO_FORMAT_ARGB32, m_size.width(), m_size.height(), stride));
+ auto* surfaceData = fastZeroedMalloc(m_size.height() * stride);
+
+ m_data.m_surface = adoptRef(cairo_image_surface_create_for_data(static_cast<unsigned char*>(surfaceData), CAIRO_FORMAT_ARGB32, m_size.width(), m_size.height(), stride));
+ cairo_surface_set_user_data(m_data.m_surface.get(), &s_surfaceDataKey, surfaceData, [](void* data) { fastFree(data); });
}
if (cairo_surface_status(m_data.m_surface.get()) != CAIRO_STATUS_SUCCESS)
@@ -30,7 +30,6 @@
#include "PlatformContextCairo.h"
#include "RefPtrCairo.h"
-#include <wtf/MallocPtr.h>
#if ENABLE(ACCELERATED_2D_CANVAS)
#include "PlatformLayer.h"
@@ -52,7 +51,6 @@ class ImageBufferData
ImageBufferData(const IntSize&, RenderingMode);
virtual ~ImageBufferData();
- MallocPtr<unsigned char> m_surfaceData;
RefPtr<cairo_surface_t> m_surface;
PlatformContextCairo m_platformContext;
std::unique_ptr<GraphicsContext> m_context;

0 comments on commit 8ca8ebc

Please sign in to comment.