github.com/jmigpin/editor@v1.6.0/driver/xdriver/wimage/wimage.go (about)

     1  package wimage
     2  
     3  import (
     4  	"fmt"
     5  	"image"
     6  	"image/draw"
     7  
     8  	"github.com/BurntSushi/xgb"
     9  	"github.com/BurntSushi/xgb/xproto"
    10  )
    11  
    12  // Window image for drawing.
    13  type WImage interface {
    14  	Image() draw.Image
    15  	PutImage(image.Rectangle) error
    16  	PutImageCompleted()
    17  	Resize(image.Rectangle) error
    18  	Close() error
    19  }
    20  
    21  func NewWImage(opt *Options) (WImage, error) {
    22  	// image using shared memory (better performance)
    23  	wimg, err := NewShmWImage(opt)
    24  	if err != nil {
    25  		// output error, try next method
    26  		fmt.Printf("warning: unable to use shmwimage: %v\n", err)
    27  	} else {
    28  		return wimg, nil
    29  	}
    30  
    31  	// default method via copy to pixmap
    32  	return NewPixmapWImage(opt)
    33  }
    34  
    35  type Options struct {
    36  	Conn       *xgb.Conn
    37  	Window     xproto.Window
    38  	ScreenInfo *xproto.ScreenInfo
    39  	GCtx       xproto.Gcontext
    40  }