all: clean up code, upgrade to modern Go

Signed-off-by: ddkwork
This commit is contained in:
Admin
2025-05-05 23:27:04 +08:00
committed by Elias Naur
parent 86668e8b45
commit f73287be87
58 changed files with 413 additions and 241 deletions
+7 -6
View File
@@ -15,6 +15,7 @@ import (
"image/color"
"math"
"reflect"
"slices"
"time"
"unsafe"
@@ -189,7 +190,7 @@ const (
// imageOpData is the shadow of paint.ImageOp.
type imageOpData struct {
src *image.RGBA
handle interface{}
handle any
filter byte
}
@@ -200,7 +201,7 @@ type linearGradientOpData struct {
color2 color.NRGBA
}
func decodeImageOp(data []byte, refs []interface{}) imageOpData {
func decodeImageOp(data []byte, refs []any) imageOpData {
handle := refs[1]
if handle == nil {
return imageOpData{}
@@ -547,7 +548,7 @@ func newBlitter(ctx driver.Device) *blitter {
b.texUniforms = new(blitTexUniforms)
b.linearGradientUniforms = new(blitLinearGradientUniforms)
pipelines, err := createColorPrograms(ctx, gio.Shader_blit_vert, gio.Shader_blit_frag,
[3]interface{}{b.colUniforms, b.linearGradientUniforms, b.texUniforms},
[3]any{b.colUniforms, b.linearGradientUniforms, b.texUniforms},
)
if err != nil {
panic(err)
@@ -565,7 +566,7 @@ func (b *blitter) release() {
}
}
func createColorPrograms(b driver.Device, vsSrc shader.Sources, fsSrc [3]shader.Sources, uniforms [3]interface{}) (pipelines [2][3]*pipeline, err error) {
func createColorPrograms(b driver.Device, vsSrc shader.Sources, fsSrc [3]shader.Sources, uniforms [3]any) (pipelines [2][3]*pipeline, err error) {
defer func() {
if err != nil {
for _, p := range pipelines {
@@ -822,7 +823,7 @@ func (r *renderer) packLayers(layers []opacityLayer) []opacityLayer {
layers[l.parent].clip = b.Union(l.clip)
}
if l.clip.Empty() {
layers = append(layers[:i], layers[i+1:]...)
layers = slices.Delete(layers, i, i+1)
}
}
// Pack layers.
@@ -1316,7 +1317,7 @@ func (b *blitter) blit(mat materialType, fbo bool, col f32color.RGBA, col1, col2
// newUniformBuffer creates a new GPU uniform buffer backed by the
// structure uniformBlock points to.
func newUniformBuffer(b driver.Device, uniformBlock interface{}) *uniformBuffer {
func newUniformBuffer(b driver.Device, uniformBlock any) *uniformBuffer {
ref := reflect.ValueOf(uniformBlock)
// Determine the size of the uniforms structure, *uniforms.
size := ref.Elem().Type().Size()