+// ----------------------------------------------------------------------------
+
+int wxCairoBitmapData::InitBuffer(int width, int height, cairo_format_t format)
+{
+ wxUnusedVar(format); // Only really unused with Cairo < 1.6.
+
+ // Determine the stride: use cairo_format_stride_for_width() if available
+ // but fall back to 4*width for the earlier versions as this is what that
+ // function always returns, even in latest Cairo, anyhow.
+ int stride;
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 6, 0)
+ if ( cairo_version() >= CAIRO_VERSION_ENCODE(1, 6, 0) )
+ {
+ stride = cairo_format_stride_for_width(format, width);
+
+ // All our code would totally break if stride were not a multiple of 4
+ // so ensure this is the case.
+ if ( stride % 4 )
+ {
+ wxFAIL_MSG("Unexpected Cairo image surface stride.");
+
+ stride += 4 - stride % 4;
+ }
+ }
+ else
+#endif
+ stride = 4*width;
+
+ m_width = width;
+ m_height = height;
+ m_buffer = new unsigned char[height*stride];
+
+ return stride;
+}
+
+void wxCairoBitmapData::InitSurface(cairo_format_t format, int stride)
+{
+ m_surface = cairo_image_surface_create_for_data(
+ m_buffer, format, m_width, m_height, stride);
+ m_pattern = cairo_pattern_create_for_surface(m_surface);
+}