start
Begin recording drawing to the physical pixels in rect (enlarged to pixel boundaries).
Returns null in case of failure:
- backend does not support texture targets
- passed rect is empty
- out of memory
Only valid between Window.beginand Window.end.
Parameters
- rect:Rect.Physical
- Rect.Physical
Source
Implementation
pub fn start(rect: Rect.Physical) ?Picture {
if (rect.empty()) {
//log.err("Picture.start() was called with an empty rect", .{});
return null;
}
// insert queues to catch stuff like stroke after renders
const cw = dvui.currentWindow();
const prev_dr_cmds = cw.defer_render_cmds;
const prev_dr_cmds_after = cw.defer_render_cmds_after;
// allocate here to return null before we create a target texture
const render_cmds = cw.arena().create(std.ArrayList(dvui.RenderCommand)) catch return null;
const render_cmds_after = cw.arena().create(std.ArrayList(dvui.RenderCommand)) catch return null;
render_cmds.* = .empty;
render_cmds_after.* = .empty;
var r = rect;
// enlarge texture to pixels boundaries
const x_start = @floor(r.x);
const x_end = @ceil(r.x + r.w);
r.x = x_start;
r.w = @round(x_end - x_start);
const y_start = @floor(r.y);
const y_end = @ceil(r.y + r.h);
r.y = y_start;
r.h = @round(y_end - y_start);
const texture = dvui.textureCreateTarget(.{ .width = @trunc(r.w), .height = @trunc(r.h) }) catch return null;
const target = dvui.renderTarget(.{ .texture = texture, .offset = r.topLeft() });
// everything looks good, install our render queues
cw.defer_render_cmds = render_cmds;
cw.defer_render_cmds_after = render_cmds_after;
return .{
.r = r,
.texture = texture,
.prev_target = target,
.prev_dr_cmds = prev_dr_cmds,
.prev_dr_cmds_after = prev_dr_cmds_after,
.render_cmds = render_cmds,
.render_cmds_after = render_cmds_after,
};
}