Skip to content

Commit

Permalink
move some stuff around, make the painter a little better
Browse files Browse the repository at this point in the history
  • Loading branch information
chabad360 committed May 9, 2024
1 parent b89ee98 commit a5f7931
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/app_software.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"image"

"fyne.io/fyne/v2"
software2 "fyne.io/fyne/v2/driver/software"
software2 "fyne.io/fyne/v2/internal/driver/software"
"fyne.io/fyne/v2/internal/painter/software"
"fyne.io/fyne/v2/test"
)
Expand Down
2 changes: 1 addition & 1 deletion canvas/rectangle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/driver/software"
"fyne.io/fyne/v2/internal/driver/software"
"fyne.io/fyne/v2/test"

"github.com/stretchr/testify/assert"
Expand Down
3 changes: 2 additions & 1 deletion driver/software/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/internal/app"
"fyne.io/fyne/v2/internal/driver/software"
)

// RenderCanvas takes a canvas and renders it to a regular Go image using the provided Theme.
Expand All @@ -22,7 +23,7 @@ func RenderCanvas(c fyne.Canvas, t fyne.Theme) image.Image {
func Render(obj fyne.CanvasObject, t fyne.Theme) image.Image {
fyne.CurrentApp().Settings().SetTheme(t)

c := NewCanvas()
c := software.NewCanvas()
c.SetPadded(false)
c.SetContent(obj)

Expand Down
3 changes: 2 additions & 1 deletion driver/software/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/internal/driver/software"
internalTest "fyne.io/fyne/v2/internal/test"
"fyne.io/fyne/v2/test"

Expand Down Expand Up @@ -44,7 +45,7 @@ func TestRenderCanvas(t *testing.T) {
widget.NewButton("Button", func() {}),
)))

c := NewCanvas()
c := software.NewCanvas()
c.SetContent(obj)

if fyne.CurrentDevice().IsMobile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *softwareCanvas) MinSize() fyne.Size {
// Canvas returns a reusable in-memory canvas used for testing
func Canvas() fyne.Canvas {
if dummyCanvas == nil {
dummyCanvas = NewCanvas()
dummyCanvas = NewTransparentCanvas()
}

return dummyCanvas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (d *softwareDriver) CanvasForObject(fyne.CanvasObject) fyne.Canvas {
}

func (d *softwareDriver) CreateWindow(string) fyne.Window {
canvas := NewCanvas().(*softwareCanvas)
canvas := NewTransparentCanvas().(*softwareCanvas)
if d.painter != nil {
canvas.SetPainter(d.painter)
} else {
Expand Down
File renamed without changes.
30 changes: 22 additions & 8 deletions internal/painter/software/painter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,31 @@ func (p *Painter) Capture(c fyne.Canvas) image.Image {
base := image.NewNRGBA(bounds)

paint := func(obj fyne.CanvasObject, pos, clipPos fyne.Position, clipSize fyne.Size) bool {
shouldTest := true
shouldPaint := false
shouldPaint = driver.WalkVisibleObjectTree(obj, func(obj fyne.CanvasObject, _, _ fyne.Position, _ fyne.Size) bool {
switch obj.(type) {
case *fyne.Container, fyne.Widget:
return false
}

switch obj.(type) {
case *fyne.Container, fyne.Widget:
shouldTest = true
default:
if _, ok := cache.GetTexture(obj); !ok {
return true
shouldTest = false
shouldPaint = true
}
return false
}, nil)
}

if shouldTest {
shouldPaint = driver.WalkVisibleObjectTree(obj, func(obj fyne.CanvasObject, _, _ fyne.Position, _ fyne.Size) bool {
switch obj.(type) {
case *fyne.Container, fyne.Widget:
return false
}
if _, ok := cache.GetTexture(obj); !ok {
return true
}
return false
}, nil)
}

if shouldPaint {
w := fyne.Min(clipPos.X+clipSize.Width, c.Size().Width)
Expand Down
5 changes: 0 additions & 5 deletions internal/painter/software/texture.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package software

import (
"fmt"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/internal/cache"
)
Expand All @@ -26,11 +24,8 @@ func (p *Painter) getTexture(object fyne.CanvasObject, creator func(canvasObject
texture, ok := cache.GetTexture(object)

if !ok {
fmt.Println("cache miss")
texture = cache.TextureType(creator(object))
cache.SetTexture(object, texture, p.canvas)
} else {
fmt.Println("cache hit")
}
// TODO: get this to work
// if !cache.IsValid(texture) {
Expand Down
2 changes: 1 addition & 1 deletion tools/playground/softwarecanvas.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package playground

import (
"fyne.io/fyne/v2/driver/software"
"fyne.io/fyne/v2/internal/driver/software"
"fyne.io/fyne/v2/test"
)

Expand Down

0 comments on commit a5f7931

Please sign in to comment.