File tree Expand file tree Collapse file tree 5 files changed +33
-42
lines changed Expand file tree Collapse file tree 5 files changed +33
-42
lines changed Original file line number Diff line number Diff line change @@ -17,9 +17,8 @@ import (
1717)
1818
1919type androidContext struct {
20- win * window
21- eglSurf egl.NativeWindowType
22- width , height int
20+ win * window
21+ eglSurf egl.NativeWindowType
2322 * egl.Context
2423}
2524
@@ -45,17 +44,16 @@ func (c *androidContext) Refresh() error {
4544 if err := c .win .setVisual (c .Context .VisualID ()); err != nil {
4645 return err
4746 }
48- win , width , height := c .win .nativeWindow ()
47+ win , _ , _ := c .win .nativeWindow ()
4948 c .eglSurf = egl .NativeWindowType (unsafe .Pointer (win ))
50- c .width , c .height = width , height
5149 return nil
5250}
5351
5452func (c * androidContext ) Lock () error {
5553 // The Android emulator creates a broken surface if it is not
5654 // created on the same thread as the context is made current.
5755 if c .eglSurf != nil {
58- if err := c .Context .CreateSurface (c .eglSurf , c . width , c . height ); err != nil {
56+ if err := c .Context .CreateSurface (c .eglSurf ); err != nil {
5957 return err
6058 }
6159 c .eglSurf = nil
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ func (c *wlContext) Refresh() error {
6969 }
7070 c .eglWin = eglWin
7171 eglSurf := egl .NativeWindowType (uintptr (unsafe .Pointer (eglWin )))
72- if err := c .Context .CreateSurface (eglSurf , width , height ); err != nil {
72+ if err := c .Context .CreateSurface (eglSurf ); err != nil {
7373 return err
7474 }
7575 if err := c .Context .MakeCurrent (); err != nil {
Original file line number Diff line number Diff line change 55package app
66
77import (
8- "golang.org/x/sys/windows"
9-
108 "gioui.org/internal/egl"
119)
1210
@@ -24,6 +22,18 @@ func init() {
2422 if err != nil {
2523 return nil , err
2624 }
25+ win , _ , _ := w .HWND ()
26+ eglSurf := egl .NativeWindowType (win )
27+ if err := ctx .CreateSurface (eglSurf ); err != nil {
28+ ctx .Release ()
29+ return nil , err
30+ }
31+ if err := ctx .MakeCurrent (); err != nil {
32+ ctx .Release ()
33+ return nil , err
34+ }
35+ defer ctx .ReleaseCurrent ()
36+ ctx .EnableVSync (true )
2737 return & glContext {win : w , Context : ctx }, nil
2838 },
2939 })
@@ -37,21 +47,6 @@ func (c *glContext) Release() {
3747}
3848
3949func (c * glContext ) Refresh () error {
40- c .Context .ReleaseSurface ()
41- var (
42- win windows.Handle
43- width , height int
44- )
45- win , width , height = c .win .HWND ()
46- eglSurf := egl .NativeWindowType (win )
47- if err := c .Context .CreateSurface (eglSurf , width , height ); err != nil {
48- return err
49- }
50- if err := c .Context .MakeCurrent (); err != nil {
51- return err
52- }
53- c .Context .EnableVSync (true )
54- c .Context .ReleaseCurrent ()
5550 return nil
5651}
5752
Original file line number Diff line number Diff line change @@ -25,6 +25,18 @@ func init() {
2525 if err != nil {
2626 return nil , err
2727 }
28+ win , _ , _ := w .window ()
29+ eglSurf := egl .NativeWindowType (uintptr (win ))
30+ if err := ctx .CreateSurface (eglSurf ); err != nil {
31+ ctx .Release ()
32+ return nil , err
33+ }
34+ if err := ctx .MakeCurrent (); err != nil {
35+ ctx .Release ()
36+ return nil , err
37+ }
38+ defer ctx .ReleaseCurrent ()
39+ ctx .EnableVSync (true )
2840 return & x11Context {win : w , Context : ctx }, nil
2941 }
3042}
@@ -37,17 +49,6 @@ func (c *x11Context) Release() {
3749}
3850
3951func (c * x11Context ) Refresh () error {
40- c .Context .ReleaseSurface ()
41- win , width , height := c .win .window ()
42- eglSurf := egl .NativeWindowType (uintptr (win ))
43- if err := c .Context .CreateSurface (eglSurf , width , height ); err != nil {
44- return err
45- }
46- if err := c .Context .MakeCurrent (); err != nil {
47- return err
48- }
49- defer c .Context .ReleaseCurrent ()
50- c .Context .EnableVSync (true )
5152 return nil
5253}
5354
Original file line number Diff line number Diff line change @@ -15,10 +15,9 @@ import (
1515)
1616
1717type Context struct {
18- disp _EGLDisplay
19- eglCtx * eglContext
20- eglSurf _EGLSurface
21- width , height int
18+ disp _EGLDisplay
19+ eglCtx * eglContext
20+ eglSurf _EGLSurface
2221}
2322
2423type eglContext struct {
@@ -121,11 +120,9 @@ func (c *Context) VisualID() int {
121120 return c .eglCtx .visualID
122121}
123122
124- func (c * Context ) CreateSurface (win NativeWindowType , width , height int ) error {
123+ func (c * Context ) CreateSurface (win NativeWindowType ) error {
125124 eglSurf , err := createSurface (c .disp , c .eglCtx , win )
126125 c .eglSurf = eglSurf
127- c .width = width
128- c .height = height
129126 return err
130127}
131128
You can’t perform that action at this time.
0 commit comments