aboutsummaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/exp/shiny/driver/mtldriver/screen.go
blob: 1828a4c038dbfa52d83e72c72abef383f7f49d89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build darwin

package mtldriver

import (
	"image"

	"github.com/go-gl/glfw/v3.3/glfw"
	"golang.org/x/exp/shiny/screen"
)

// screenImpl implements screen.Screen.
type screenImpl struct {
	newWindowCh chan newWindowReq
}

func (*screenImpl) NewBuffer(size image.Point) (screen.Buffer, error) {
	return &bufferImpl{
		rgba: image.NewRGBA(image.Rectangle{Max: size}),
	}, nil
}

func (*screenImpl) NewTexture(size image.Point) (screen.Texture, error) {
	return &textureImpl{
		rgba: image.NewRGBA(image.Rectangle{Max: size}),
	}, nil
}

func (s *screenImpl) NewWindow(opts *screen.NewWindowOptions) (screen.Window, error) {
	respCh := make(chan newWindowResp)
	s.newWindowCh <- newWindowReq{
		opts:   opts,
		respCh: respCh,
	}
	glfw.PostEmptyEvent() // Break main loop out of glfw.WaitEvents so it can receive on newWindowCh.
	resp := <-respCh
	return resp.w, resp.err
}