func (s *screenImpl) NewTexture(size image.Point) (screen.Texture, error) { w, h := int64(size.X), int64(size.Y) if w < 0 || maxShmSide < w || h < 0 || maxShmSide < h || maxShmSize < 4*w*h { return nil, fmt.Errorf("x11driver: invalid texture size %v", size) } xm, err := xproto.NewPixmapId(s.xc) if err != nil { return nil, fmt.Errorf("x11driver: xproto.NewPixmapId failed: %v", err) } xp, err := render.NewPictureId(s.xc) if err != nil { return nil, fmt.Errorf("x11driver: xproto.NewPictureId failed: %v", err) } t := &textureImpl{ s: s, size: size, xm: xm, xp: xp, } xproto.CreatePixmap(s.xc, textureDepth, xm, xproto.Drawable(s.window32), uint16(w), uint16(h)) render.CreatePicture(s.xc, xp, xproto.Drawable(xm), s.pictformat32, 0, nil) render.SetPictureFilter(s.xc, xp, uint16(len("bilinear")), "bilinear", nil) return t, nil }
func icon2md5(xid xproto.Window) []byte { pixmap, _ := xproto.NewPixmapId(TrayXU.Conn()) defer xproto.FreePixmap(TrayXU.Conn(), pixmap) if err := composite.NameWindowPixmapChecked(TrayXU.Conn(), xid, pixmap).Check(); err != nil { logger.Warning("NameWindowPixmap failed:", err, xid) return nil } im, err := xgraphics.NewDrawable(TrayXU, xproto.Drawable(pixmap)) if err != nil { logger.Warning("Create xgraphics.Image failed:", err, pixmap) return nil } buf := bytes.NewBuffer(nil) im.WritePng(buf) hasher := md5.New() hasher.Write(buf.Bytes()) return hasher.Sum(nil) }
// CreatePixmap allocates an X resource identifier for a pixmap. (It does not // do any drawing.) You only need to call this if you're using XDraw/XExpPaint. // If you're using XSurfaceSet/XDraw/XPaint, then CreatePixmap is called for // you automatically. func (im *Image) CreatePixmap() error { // Generate the pixmap id. pid, err := xproto.NewPixmapId(im.X.Conn()) if err != nil { return err } // Now actually create the pixmap. err = xproto.CreatePixmapChecked(im.X.Conn(), im.X.Screen().RootDepth, pid, xproto.Drawable(im.X.RootWin()), uint16(im.Bounds().Dx()), uint16(im.Bounds().Dy())).Check() if err != nil { return err } // Now give it to the image. im.Pixmap = pid return nil }