Rectangle is not Drawing Like It should be

58 views
Skip to first unread message

Logan Welty

unread,
Jul 3, 2025, 6:11:02 PM7/3/25
to skia-discuss
Trying to swap out cairo with vulkan/skia instead and I have this code:

static const gboolean on_source_image_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data) {
// Want this color: #d2d2d4 rgba(219, 219, 219, 0.8)
TileGridUI *ui = (TileGridUI *)user_data;
render_data_t* state = render;
// GrVkImageInfo is used to construct GrBackendTexture and GrBackendRenderTarget objects that in turn are used to create SkSurface and SkImage objects that refer to VkImages created by the Skia client.
// Draw background
if (!draw.update_image_grid_container_drawing) {
// Get widget dimensions
dimensions.width = gtk_widget_get_allocated_width(widget);
dimensions.height = gtk_widget_get_allocated_height(widget);
std::unique_ptr<GtkAllocation> allocation = std::make_unique<GtkAllocation>();
gtk_widget_get_allocation(widget, allocation.get());
dimensions.x = allocation.get()->x; // Get x position
dimensions.y = allocation.get()->y; // Get y position
draw.update_image_grid_container_drawing = TRUE;
allocation.release();
}
strokePaint.setStyle(SkPaint::kStroke_Style); // Set the type of stroke
strokePaint.setStrokeWidth(3.0f); // Set the line width
fillPaint.setColor(SkColorSetARGB(219, 219, 219, 0.8f));
// Create an SkSurface backed by a Vulkan VkImage. Often clients will be getting VkImages from
// swapchains. In those cases they should use SkSurfaces::WrapBackendTexture or
// SkSurfaces::WrapBackendRenderTarget to wrap those premade VkImages in Skia.
SkImageInfo info = SkImageInfo::MakeN32Premul(dimensions.width, dimensions.height);
// Wrapper below self cleans
sk_sp<SkSurface> gpuSurface(
SkSurfaces::RenderTarget(context.get(), skgpu::Budgeted::kNo, info));
if (!gpuSurface) {
SkDebugf("SkSurfaces::RenderTarget returned null\n");
return FALSE;
}
SkCanvas* gpuCanvas = gpuSurface->getCanvas();
gpuCanvas->drawRect(draw.rect[0].MakeXYWH(dimensions.x, dimensions.y, dimensions.width, dimensions.height), fillPaint);
context->flush();
context->submit(); ....}
Going off of the skia user manual and I should be able to fill in the background white on my GTK widget, but I get this instead:
: (tileset_creator:18722): Gtk-WARNING **: 14:46:14.784: drawing failure for widget 'GtkDrawingArea': NULL pointer

(tileset_creator:18722): Gtk-WARNING **: 14:46:14.784: drawing failure for widget 'GtkFrame': NULL pointer

(tileset_creator:18722): Gtk-WARNING **: 14:46:14.784: drawing failure for widget 'GtkBox': NULL pointer

(tileset_creator:18722): Gtk-WARNING **: 14:46:14.784: drawing failure for widget 'GtkBox': NULL pointer

(tileset_creator:18722): Gtk-WARNING **: 14:46:14.785: drawing failure for widget 'GtkWindow': NULL pointer

I have other code that if uncommented it will work, because it is cairo and the warning will disappear. I am trying to figure out why it won't draw the rectangle white at the specified location

Logan Welty

unread,
Jul 5, 2025, 11:18:13 PM7/5/25
to skia-discuss
Nullptr is something else, and was fixed. The issue still resides to this day.
Reply all
Reply to author
Forward
0 new messages