ref: abd6e8f9cdd4 gio/op/clip/clip.go -rw-r--r-- 7.5 KiB
op/clip,gpu: move approximation of complex strokes to op/clip.Op.Add

Before this change, the two renderers both had special case code for
approximating strokes they don't support natively. This change moves
that conversion to clip.Op.Add, for several reasons:

- The compute renderer no longer need fallback logic and caches for
  strokes it doesn't support.
- The approximation logic is slow. Moving it to clip.Op.Add will not
  speed it up, but will make the cost easier to spot in profiles. Until all
  strokes are supported natively, users can use macros to cache
  expensive strokes.
- Reduced garbage: Op.Add takes an op.Ops anyway, and can use that for
  storing the approximated stroke outline.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
internal/stroke,op/clip: don't import op/clip from internal/stroke

To avoid an import cycle in a future change, internal/stroke can no
longer import op/clip. Move required op/clip functionality to
internal/stroke and duplicate the remaining types.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
op/clip: separate function for approximating arcs with quadratic curves

Both Path.Arc and the internal stroke package needs to support arcs;
this change isolates the approximation computation into a function we
can move to internal/stroke in a follow-up.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
gpu,op/clip: [compute] get rid of stroke vs fill flags

The fill mode is now controlled by a SetFillMode command, not by flags
on each path segment and fill command.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
op/clip: add Circle and Path.CubeTo

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
gpu,gpu/shaders: revert attempt to fix path gaps

This is effectively a revert of [0], reintroducing the path gaps
described in [1]. A follow-up change will implement another attempt.

[0] https://gioui.org/commit/2feec23561cd84d6b8ddbab84a202df66b123208
[1] https://github.com/linebender/piet-gpu/issues/62

Signed-off-by: Elias Naur <mail@eliasnaur.com>
op/clip,gpu,internal/scene: encode cubic bézier curves natively

The compute renderer supports cubic curves, so encode them as such.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
gpu,op/clip: encode lines as compute line commands, not quads

The new renderer supports lines natively; encode them as such and
convert them to a quadratic beziér.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
gpu: [compute] skip encoding roundtrip for path data

Since clip.Path now encodes paths in the format expected by
elements.comp, use that data directly instead of a roundtrip through

Signed-off-by: Elias Naur <mail@eliasnaur.com>
gpu,internal/ops: decode scene commands directly, not through quads

We're about to let clip.Path use more of the compute renderer features
(lines, cubic béziers). This change prepares the gpu package for reading
one of several commands types, not just the quadratic béziers of before.

The old Quad type is still the basis for the stroking algorithms, but
this change moves it into package gpu which is the only user.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
internal/ops: switch quad encoding to compute format

Signed-off-by: Elias Naur <mail@eliasnaur.com>
op/clip,gpu,internal/opconst: remove quad count from Path op

The check for path segments in gpu is redundant; clip.Op.Add doesn't add
the Path op if there were no segments.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
op/clip: don't accept open Paths for Outline

Outline represents a clipping operations that clips all drawing outside
a closed path. Before this change, paths not closed we're patched up by
adding an implicit line from the endpoint to the beginning.

These fixups are inefficient for a rare case, but acceptable because the
old renderer post-processes all paths anyway. However, the new compute
renderer don't need post-processing in most cases, making fixups too

Given that clipping to an open path is fundamentally undefined and that
implicit fixup with a closing line segment is merely a way to force the
clip to be well-defined, this change adds a panic to Outline for Paths
that are not closed.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
op/clip: move Rect to shapes.go

It's a specialized shape like the others.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
gpu,op/clip: implement dashed stroked paths

Signed-off-by: Sebastien Binet <s@sbinet.org>
all: introduce Outline and Stroke builders

This CL introduces 2 new path builders:
- Outline which takes a PathSpec to be outlined
- Stroke which takes a PathSpec and a stroke style, to stroke a path.

typically, code like this:

  var p clip.Path

should be replaced with:

  var p clip.Path
  clip.Outline{Path: p.End()}.Op().Add(o)

similarly, stroking should be modified from:

  var p clip.Path
  p.Stroke(width, clip.StrokeStyle{...}).Add(o)


  var p clip.Path
  clip.Stroke{Path: p.End(), Style: clip.StrokeStyle{Width:...}}.Op().Add(o)

here are tentative 'rf' scripts (see rsc.io/rf for more details):

  ex {
  	import "gioui.org/op";
  	import "gioui.org/op/clip";

  	var p clip.Path;
  	var o *op.Ops;

  	p.Outline().Add(o) -> clip.Outline{Path:p.End()}.Op().Add(o);

  ex {
  	import "gioui.org/op";
  	import "gioui.org/op/clip";

  	var o *op.Ops;
  	var p clip.Path;
  	var sty clip.StrokeStyle;
  	var width float32;

  	p.Stroke(width, sty).Add(o) ->   \
	    clip.Stroke{                 \
		Path:p.End(),            \
		Style: clip.StrokeStyle{ \
		    Width: width,        \

Signed-off-by: Sebastien Binet <s@sbinet.org>
op/clip: fix incirrent mention of even-odd fill rule

It's the non-zero winding rule.

Noticed by Richard Wilkes.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
op/clip: handle zero Cube

Currently this comes up with RRect/Border that has zero corners. It
improves them from ~250ns to ~170ns. While it's possible to check this
in RRect implementation, however it'll slow down calls with non-zero

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
op/clip: expose LineTo and QuadTo

Using delta position with Line and Quad can drift over successive calls.
Also, in some cases it's much more convenient to use absolute
coordinates rather than relative.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
gpu,op/clip: implement stroked paths with miter joins

Signed-off-by: Sebastien Binet <s@sbinet.org>
gpu,op/clip: implement stroked paths with round joins

Signed-off-by: Sebastien Binet <s@sbinet.org>