sdf_accelerator.go
Functions
func CanAccelerate
func (a *SDFAccelerator) CanAccelerate(op AcceleratedOp) bool {
return op&(AccelCircleSDF|AccelRRectSDF) != 0
}
func Close
Close releases resources. No-op for CPU-based SDF.
func (a *SDFAccelerator) Close() {}
func FillPath
FillPath always falls back to CPU for general paths.
func (a *SDFAccelerator) FillPath(_ GPURenderTarget, _ *Path, _ *Paint) error {
return ErrFallbackToCPU
}
func FillShape
FillShape renders a filled shape using SDF.
Shapes smaller than sdfMinSize in either dimension fall back to CPU scanline,
unless forceSDF is enabled (RasterizerSDF mode).
func (a *SDFAccelerator) FillShape(target GPURenderTarget, shape DetectedShape, paint *Paint) error {
if !a.forceSDF && shapeTooSmallForSDF(shape) {
return ErrFallbackToCPU
}
switch shape.Kind {
case ShapeCircle:
return a.fillCircleSDF(target, shape, paint)
case ShapeEllipse:
return a.fillEllipseSDF(target, shape, paint)
case ShapeRect, ShapeRRect:
return a.fillRRectSDF(target, shape, paint)
default:
return ErrFallbackToCPU
}
}
func Flush
Flush is a no-op for the CPU SDF accelerator (renders immediately).
func (a *SDFAccelerator) Flush(_ GPURenderTarget) error { return nil }
func Init
Init initializes the accelerator. No resources are needed.
func (a *SDFAccelerator) Init() error { return nil }
func Name
Name returns the accelerator name.
func (a *SDFAccelerator) Name() string { return "sdf-cpu" }
func SetForceSDF
SetForceSDF enables or disables forced SDF mode.
When enabled, FillShape/StrokeShape skip the minimum size check,
allowing SDF rendering for shapes smaller than sdfMinSize.
func (a *SDFAccelerator) SetForceSDF(force bool) {
a.forceSDF = force
}
func StrokePath
StrokePath always falls back to CPU for general paths.
func (a *SDFAccelerator) StrokePath(_ GPURenderTarget, _ *Path, _ *Paint) error {
return ErrFallbackToCPU
}
func StrokeShape
StrokeShape renders a stroked shape using SDF.
Shapes smaller than sdfMinSize in either dimension fall back to CPU scanline,
unless forceSDF is enabled (RasterizerSDF mode).
func (a *SDFAccelerator) StrokeShape(target GPURenderTarget, shape DetectedShape, paint *Paint) error {
if !a.forceSDF && shapeTooSmallForSDF(shape) {
return ErrFallbackToCPU
}
switch shape.Kind {
case ShapeCircle:
return a.strokeCircleSDF(target, shape, paint)
case ShapeEllipse:
return a.strokeEllipseSDF(target, shape, paint)
case ShapeRect, ShapeRRect:
return a.strokeRRectSDF(target, shape, paint)
default:
return ErrFallbackToCPU
}
}
Structs
type SDFAccelerator struct
SDFAccelerator is a CPU-based SDF accelerator for simple geometric shapes.
It produces smoother circles and rounded rectangles than the default
area-based rasterizer by computing per-pixel signed distance fields.
This accelerator only handles circles and rounded rectangles via the
AccelCircleSDF and AccelRRectSDF operations. All other operations fall
back to the software renderer.
Shapes smaller than sdfMinSize pixels in either dimension are rejected
(ErrFallbackToCPU) so AnalyticFiller handles them with lower overhead.
Usage:
gg.RegisterAccelerator(&gg.SDFAccelerator{})
type SDFAccelerator struct {
forceSDF bool // bypass sdfMinSize check for RasterizerSDF mode
}
CanAccelerate reports whether the accelerator supports the given operation.
Only circle and rounded-rect SDF operations are supported.