| // Copyright 2015 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. |
| |
| package x11driver |
| |
| import ( |
| "image" |
| "image/draw" |
| "log" |
| "sync" |
| |
| "github.com/BurntSushi/xgb" |
| "github.com/BurntSushi/xgb/render" |
| "github.com/BurntSushi/xgb/xproto" |
| |
| "golang.org/x/exp/shiny/driver/internal/pump" |
| "golang.org/x/exp/shiny/screen" |
| "golang.org/x/image/math/f64" |
| "golang.org/x/mobile/event/paint" |
| ) |
| |
| type windowImpl struct { |
| s *screenImpl |
| |
| xw xproto.Window |
| xg xproto.Gcontext |
| xp render.Picture |
| |
| pump pump.Pump |
| xevents chan xgb.Event |
| |
| mu sync.Mutex |
| released bool |
| } |
| |
| func (w *windowImpl) run() { |
| for { |
| select { |
| // TODO: things other than X11 events. |
| |
| case ev, ok := <-w.xevents: |
| if !ok { |
| return |
| } |
| switch ev := ev.(type) { |
| default: |
| // TODO: implement. |
| log.Println(ev) |
| } |
| } |
| } |
| } |
| |
| func (w *windowImpl) Events() <-chan interface{} { return w.pump.Events() } |
| func (w *windowImpl) Send(event interface{}) { w.pump.Send(event) } |
| |
| func (w *windowImpl) Release() { |
| w.mu.Lock() |
| released := w.released |
| w.released = true |
| w.mu.Unlock() |
| |
| if released { |
| return |
| } |
| render.FreePicture(w.s.xc, w.xp) |
| xproto.FreeGC(w.s.xc, w.xg) |
| xproto.DestroyWindow(w.s.xc, w.xw) |
| w.pump.Release() |
| } |
| |
| func (w *windowImpl) Upload(dp image.Point, src screen.Buffer, sr image.Rectangle, sender screen.Sender) { |
| src.(*bufferImpl).upload(w, xproto.Drawable(w.xw), w.xg, w.s.xsi.RootDepth, dp, sr, sender) |
| } |
| |
| func (w *windowImpl) Draw(src2dst f64.Aff3, src screen.Texture, sr image.Rectangle, op draw.Op, opts *screen.DrawOptions) { |
| src.(*textureImpl).draw(w.xp, &src2dst, sr, op, opts) |
| } |
| |
| func (w *windowImpl) EndPaint(e paint.Event) { |
| // TODO. |
| } |