+wxBitmap wxBitmap::GetMaskBitmap() const
+{
+ wxBitmap bitmap;
+ wxBitmapRefData* bmpData = M_BMPDATA;
+#ifdef __WXGTK3__
+ cairo_surface_t* mask = NULL;
+ if (bmpData && bmpData->m_mask)
+ mask = bmpData->m_mask->GetBitmap();
+ if (mask)
+ {
+ const int w = cairo_image_surface_get_width(mask);
+ const int h = cairo_image_surface_get_height(mask);
+ GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, w, h);
+ const guchar* src = cairo_image_surface_get_data(mask);
+ guchar* dst = gdk_pixbuf_get_pixels(pixbuf);
+ const int stride_src = cairo_image_surface_get_stride(mask);
+ const int stride_dst = gdk_pixbuf_get_rowstride(pixbuf);
+ for (int j = 0; j < h; j++, src += stride_src, dst += stride_dst)
+ {
+ guchar* d = dst;
+ for (int i = 0; i < w; i++, d += 3)
+ {
+ d[0] = src[i];
+ d[1] = src[i];
+ d[2] = src[i];
+ }
+ }
+ bitmap = wxBitmap(pixbuf);
+ }
+#else
+ GdkPixmap* mask = NULL;
+ if (bmpData && bmpData->m_mask)
+ mask = bmpData->m_mask->GetBitmap();
+ if (mask)
+ {
+ int w, h;
+ gdk_drawable_get_size(mask, &w, &h);
+ GdkPixbuf* pixbuf = gdk_pixbuf_get_from_drawable(
+ NULL, mask, NULL, 0, 0, 0, 0, w, h);
+ bitmap = wxBitmap(pixbuf);
+ }
+#endif
+ return bitmap;
+}
+
+bool wxBitmap::CopyFromIcon(const wxIcon& icon)
+{
+ *this = icon;
+ return IsOk();
+}
+
+#ifdef __WXGTK3__
+static cairo_surface_t* GetSubSurface(cairo_surface_t* surface, const wxRect& rect)
+{
+ cairo_surface_flush(surface);
+ const cairo_format_t format = cairo_image_surface_get_format(surface);
+ int x = rect.x;
+ if (format != CAIRO_FORMAT_A8)
+ x *= 4;
+ cairo_surface_t* subSurface = cairo_image_surface_create(format, rect.width, rect.height);
+ const int srcStride = cairo_image_surface_get_stride(surface);
+ const int dstStride = cairo_image_surface_get_stride(subSurface);
+ const guchar* src = cairo_image_surface_get_data(surface) + rect.y * srcStride + x;
+ guchar* dst = cairo_image_surface_get_data(subSurface);
+ for (int j = 0; j < rect.height; j++, src += srcStride, dst += dstStride)
+ memcpy(dst, src, dstStride);
+ cairo_surface_mark_dirty(subSurface);
+ return subSurface;
+}
+#endif
+