Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Software Driver POC #4811

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft

Conversation

chabad360
Copy link
Contributor

Description:

This POC adds a new Driver that allows one to include their own event source and framebuffer (through an image.Image). It's based almost entirely on a combination of the testDriver and some choice bits from the mobileDriver (mainly the basic event loop and touch handling).

This is an incredibly rough draft, I'm putting it up so that it can be discussed. Moreover, the actual API surface and basic design hasn't really been discussed yet, so this couldn't be merged either way. But most importantly, it does work, which is a good start.

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

Where applicable:

  • Public APIs match existing style and have Since: line.
  • Any breaking changes have a deprecation path or have been discussed.

"fyne.io/fyne/v2"
software2 "fyne.io/fyne/v2/driver/software"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably switch the naming here as the first of the two is the one called "software" in the public API


// NewWithSoftwareDriver returns a new app instance using the Software (custom) driver.
// The ID string should be globally unique to this app.
func NewWithSoftwareDriver(id string, painter func(image.Image), events chan any) fyne.App {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't the painter always be the one we have in the software package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I didn't really look at the logic for how that worked, but I needed a way to add some extra params and wasn't sure a good way to do that with the existing interfaces.

Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some good work here - but I would hesitate from pulling so much internal API code into a public driver package.
The initial entry point should be all that is needed to change I would have thought - provide an event source and wire in the internal software painter by default?

@chabad360
Copy link
Contributor Author

chabad360 commented May 2, 2024

but I would hesitate from pulling so much internal API code into a public driver package.

Yea, you're right about that. It can pretty easily moved into an internal package, I just didn't put it there. I'll move things around once the code is in a more complete state.

Also, this is pretty much the exact code from the test driver (for the most part) so I'll probably have it replace the test painter once it's all said and done.

pad := painter.VectorPad(circle)
scaledWidth := scale.ToScreenCoordinate(c, circle.Size().Width+pad*2)
scaledHeight := scale.ToScreenCoordinate(c, circle.Size().Height+pad*2)
scaledX, scaledY := scale.ToScreenCoordinate(c, pos.X-pad), scale.ToScreenCoordinate(c, pos.Y-pad)
bounds := clip.Intersect(image.Rect(scaledX, scaledY, scaledX+scaledWidth, scaledY+scaledHeight))

raw := painter.DrawCircle(circle, pad, func(in float32) float32 {
return float32(math.Round(float64(in) * float64(c.Scale())))
raw, err := p.getTexture(circle, func(object fyne.CanvasObject) Texture {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a problem for tests (wrong type for TextureType), and I'm not quite sure what's a good way around it...

Maybe we could make the painter functions internal and add a wrapper file (i.e. draw_extern_software.go, draw_extern.go) that handles storing in the cache (or does nothing)? being that it's only a few lines, it should be eligible for inlining, so the wrapper should be functionally free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants