mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
gpu/headless: make Screenshot take an input image to tranfer into
When extracting headless.Window's content via screenshots, it can be useful to keep reusing the same image for output, as well as specify which area of the Window is to be extracted. The updated Screenshot method does this by using the supplied image. API change: users must pass an existing image to Window.Screenshot. Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
@@ -185,7 +185,8 @@ func newDriver(t *testing.T) driver.Device {
|
||||
}
|
||||
|
||||
func screenshot(t *testing.T, d driver.Device, fbo driver.Texture, size image.Point) *image.RGBA {
|
||||
img, err := driver.DownloadImage(d, fbo, image.Rectangle{Max: size})
|
||||
img := image.NewRGBA(image.Rectangle{Max: size})
|
||||
err := driver.DownloadImage(d, fbo, img)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
+10
-12
@@ -122,7 +122,12 @@ func (w *Window) Release() {
|
||||
}
|
||||
}
|
||||
|
||||
// Frame replace the window content and state with the
|
||||
// Size returns the window size.
|
||||
func (w *Window) Size() image.Point {
|
||||
return w.size
|
||||
}
|
||||
|
||||
// Frame replaces the window content and state with the
|
||||
// operation list.
|
||||
func (w *Window) Frame(frame *op.Ops) error {
|
||||
return contextDo(w.ctx, func() error {
|
||||
@@ -131,18 +136,11 @@ func (w *Window) Frame(frame *op.Ops) error {
|
||||
})
|
||||
}
|
||||
|
||||
// Screenshot returns an image with the content of the window.
|
||||
func (w *Window) Screenshot() (*image.RGBA, error) {
|
||||
var img *image.RGBA
|
||||
err := contextDo(w.ctx, func() error {
|
||||
var err error
|
||||
img, err = driver.DownloadImage(w.dev, w.fboTex, image.Rectangle{Max: w.size})
|
||||
return err
|
||||
// Screenshot transfers the Window content at origin img.Rect.Min to img.
|
||||
func (w *Window) Screenshot(img *image.RGBA) error {
|
||||
return contextDo(w.ctx, func() error {
|
||||
return driver.DownloadImage(w.dev, w.fboTex, img)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return img, nil
|
||||
}
|
||||
|
||||
func contextDo(ctx context, f func() error) error {
|
||||
|
||||
@@ -28,7 +28,8 @@ func TestHeadless(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
img, err := w.Screenshot()
|
||||
img := image.NewRGBA(image.Rectangle{Max: w.Size()})
|
||||
err := w.Screenshot(img)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -69,7 +70,8 @@ func TestClipping(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
img, err := w.Screenshot()
|
||||
img := image.NewRGBA(image.Rectangle{Max: w.Size()})
|
||||
err := w.Screenshot(img)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -108,7 +110,8 @@ func TestDepth(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
img, err := w.Screenshot()
|
||||
img := image.NewRGBA(image.Rectangle{Max: w.Size()})
|
||||
err := w.Screenshot(img)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user