Debian Codegraph @

shiny/driver/x11driver/screen.go

raw symbols SCIP
1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package x11driver
6
7 import (
8 "fmt"
9 "image"
10 "image/color"
11 "image/draw"
12 "log"
13 "sync"
14
15 "github.com/jezek/xgb"
16 "github.com/jezek/xgb/render"
17 "github.com/jezek/xgb/shm"
18 "github.com/jezek/xgb/xproto"
19
20 "golang.org/x/exp/shiny/driver/internal/x11key"
21 "golang.org/x/exp/shiny/screen"
22 "golang.org/x/image/math/f64"
23 "golang.org/x/mobile/event/key"
24 "golang.org/x/mobile/event/mouse"
25 )
26
27 // TODO: check that xgb is safe to use concurrently from multiple goroutines.
28 // For example, its Conn.WaitForEvent concept is a method, not a channel, so
29 // it's not obvious how to interrupt it to service a NewWindow request.
30
31 type screenImpl struct {
32 xc *xgb.Conn
33 xsi *xproto.ScreenInfo
34 keysyms x11key.KeysymTable
35
36 atomNETWMName xproto.Atom
37 atomUTF8String xproto.Atom
38 atomWMDeleteWindow xproto.Atom
39 atomWMProtocols xproto.Atom
40 atomWMTakeFocus xproto.Atom
41
42 pixelsPerPt float32
43 pictformat24 render.Pictformat
44 pictformat32 render.Pictformat
45
46 // window32 and its related X11 resources is an unmapped window so that we
47 // have a depth-32 window to create depth-32 pixmaps from, i.e. pixmaps
48 // with an alpha channel. The root window isn't guaranteed to be depth-32.
49 gcontext32 xproto.Gcontext
50 window32 xproto.Window
51
52 // opaqueP is a fully opaque, solid fill picture.
53 opaqueP render.Picture
54 useShm bool
55
56 uniformMu sync.Mutex
57 uniformC render.Color
58 uniformP render.Picture
59
60 mu sync.Mutex
61 buffers map[shm.Seg]*bufferImpl
62 uploads map[uint16]chan struct{}
63 windows map[xproto.Window]*windowImpl
64 nPendingUploads int
65 completionKeys []uint16
66 }
67
68 func newScreenImpl(xc *xgb.Conn, useShm bool) (*screenImpl, error) {
69 s := &screenImpl{
70 xc: xc,
71 xsi: xproto.Setup(xc).DefaultScreen(xc),
72 buffers: map[shm.Seg]*bufferImpl{},
73 uploads: map[uint16]chan struct{}{},
74 windows: map[xproto.Window]*windowImpl{},
75 useShm: useShm,
76 }
77 if err := s.initAtoms(); err != nil {
78 return nil, err
79 }
80 if err := s.initKeyboardMapping(); err != nil {
81 return nil, err
82 }
83 const (
84 mmPerInch = 25.4
85 ptPerInch = 72
86 )
87 pixelsPerMM := float32(s.xsi.WidthInPixels) / float32(s.xsi.WidthInMillimeters)
88 s.pixelsPerPt = pixelsPerMM * mmPerInch / ptPerInch
89 if err := s.initPictformats(); err != nil {
90 return nil, err
91 }
92 if err := s.initWindow32(); err != nil {
93 return nil, err
94 }
95
96 var err error
97 s.opaqueP, err = render.NewPictureId(xc)
98 if err != nil {
99 return nil, fmt.Errorf("x11driver: xproto.NewPictureId failed: %v", err)
100 }
101 s.uniformP, err = render.NewPictureId(xc)
102 if err != nil {
103 return nil, fmt.Errorf("x11driver: xproto.NewPictureId failed: %v", err)
104 }
105 render.CreateSolidFill(s.xc, s.opaqueP, render.Color{
106 Red: 0xffff,
107 Green: 0xffff,
108 Blue: 0xffff,
109 Alpha: 0xffff,
110 })
111 render.CreateSolidFill(s.xc, s.uniformP, render.Color{})
112
113 go s.run()
114 return s, nil
115 }
116
117 func (s *screenImpl) run() {
118 keyboardChanged := false
119 for {
120 ev, err := s.xc.WaitForEvent()
121 if err != nil {
122 log.Printf("x11driver: xproto.WaitForEvent: %v", err)
123 continue
124 }
125
126 noWindowFound := false
127 switch ev := ev.(type) {
128 case xproto.DestroyNotifyEvent:
129 s.mu.Lock()
130 delete(s.windows, ev.Window)
131 s.mu.Unlock()
132
133 case shm.CompletionEvent:
134 s.mu.Lock()
135 s.completionKeys = append(s.completionKeys, ev.Sequence)
136 s.handleCompletions()
137 s.mu.Unlock()
138
139 case xproto.ClientMessageEvent:
140 if ev.Type != s.atomWMProtocols || ev.Format != 32 {
141 break
142 }
143 switch xproto.Atom(ev.Data.Data32[0]) {
144 case s.atomWMDeleteWindow:
145 if w := s.findWindow(ev.Window); w != nil {
146 w.lifecycler.SetDead(true)
147 w.lifecycler.SendEvent(w, nil)
148 } else {
149 noWindowFound = true
150 }
151 case s.atomWMTakeFocus:
152 xproto.SetInputFocus(s.xc, xproto.InputFocusParent, ev.Window, xproto.Timestamp(ev.Data.Data32[1]))
153 }
154
155 case xproto.ConfigureNotifyEvent:
156 if w := s.findWindow(ev.Window); w != nil {
157 w.handleConfigureNotify(ev)
158 } else {
159 noWindowFound = true
160 }
161
162 case xproto.ExposeEvent:
163 if w := s.findWindow(ev.Window); w != nil {
164 // A non-zero Count means that there are more expose events
165 // coming. For example, a non-rectangular exposure (e.g. from a
166 // partially overlapped window) will result in multiple expose
167 // events whose dirty rectangles combine to define the dirty
168 // region. Go's paint events do not provide dirty regions, so
169 // we only pass on the final X11 expose event.
170 if ev.Count == 0 {
171 w.handleExpose()
172 }
173 } else {
174 noWindowFound = true
175 }
176
177 case xproto.FocusInEvent:
178 if w := s.findWindow(ev.Event); w != nil {
179 w.lifecycler.SetFocused(true)
180 w.lifecycler.SendEvent(w, nil)
181 } else {
182 noWindowFound = true
183 }
184
185 case xproto.FocusOutEvent:
186 if w := s.findWindow(ev.Event); w != nil {
187 w.lifecycler.SetFocused(false)
188 w.lifecycler.SendEvent(w, nil)
189 } else {
190 noWindowFound = true
191 }
192
193 case xproto.KeyPressEvent:
194 if keyboardChanged {
195 keyboardChanged = false
196 s.initKeyboardMapping()
197 }
198 if w := s.findWindow(ev.Event); w != nil {
199 w.handleKey(ev.Detail, ev.State, key.DirPress)
200 } else {
201 noWindowFound = true
202 }
203
204 case xproto.KeyReleaseEvent:
205 if keyboardChanged {
206 keyboardChanged = false
207 s.initKeyboardMapping()
208 }
209 if w := s.findWindow(ev.Event); w != nil {
210 w.handleKey(ev.Detail, ev.State, key.DirRelease)
211 } else {
212 noWindowFound = true
213 }
214
215 case xproto.ButtonPressEvent:
216 if w := s.findWindow(ev.Event); w != nil {
217 w.handleMouse(ev.EventX, ev.EventY, ev.Detail, ev.State, mouse.DirPress)
218 } else {
219 noWindowFound = true
220 }
221
222 case xproto.ButtonReleaseEvent:
223 if w := s.findWindow(ev.Event); w != nil {
224 w.handleMouse(ev.EventX, ev.EventY, ev.Detail, ev.State, mouse.DirRelease)
225 } else {
226 noWindowFound = true
227 }
228
229 case xproto.MotionNotifyEvent:
230 if w := s.findWindow(ev.Event); w != nil {
231 w.handleMouse(ev.EventX, ev.EventY, 0, ev.State, mouse.DirNone)
232 } else {
233 noWindowFound = true
234 }
235
236 case xproto.MappingNotifyEvent:
237 if ev.Request == xproto.MappingModifier || ev.Request == xproto.MappingKeyboard {
238 keyboardChanged = true
239 }
240 }
241
242 if noWindowFound {
243 log.Printf("x11driver: no window found for event %T", ev)
244 }
245 }
246 }
247
248 // TODO: is findBuffer and the s.buffers field unused? Delete?
249
250 func (s *screenImpl) findBuffer(key shm.Seg) *bufferImpl {
251 s.mu.Lock()
252 b := s.buffers[key]
253 s.mu.Unlock()
254 return b
255 }
256
257 func (s *screenImpl) findWindow(key xproto.Window) *windowImpl {
258 s.mu.Lock()
259 w := s.windows[key]
260 s.mu.Unlock()
261 return w
262 }
263
264 // handleCompletions must only be called while holding s.mu.
265 func (s *screenImpl) handleCompletions() {
266 if s.nPendingUploads != 0 {
267 return
268 }
269 for _, ck := range s.completionKeys {
270 completion, ok := s.uploads[ck]
271 if !ok {
272 log.Printf("x11driver: no matching upload for a SHM completion event")
273 continue
274 }
275 delete(s.uploads, ck)
276 close(completion)
277 }
278 s.completionKeys = s.completionKeys[:0]
279 }
280
281 const (
282 maxShmSide = 0x00007fff // 32,767 pixels.
283 maxShmSize = 0x10000000 // 268,435,456 bytes.
284 )
285
286 func (s *screenImpl) NewBuffer(size image.Point) (retBuf screen.Buffer, retErr error) {
287
288 w, h := int64(size.X), int64(size.Y)
289 if w < 0 || maxShmSide < w || h < 0 || maxShmSide < h || maxShmSize < 4*w*h {
290 return nil, fmt.Errorf("x11driver: invalid buffer size %v", size)
291 }
292
293 // If the X11 server or connection cannot support SHM pixmaps,
294 // fall back to regular pixmaps.
295 if !s.useShm {
296 b := &bufferFallbackImpl{
297 xc: s.xc,
298 size: size,
299 rgba: image.RGBA{
300 Stride: 4 * size.X,
301 Rect: image.Rectangle{Max: size},
302 Pix: make([]uint8, 4*size.X*size.Y),
303 },
304 }
305 b.buf = b.rgba.Pix
306 return b, nil
307 }
308
309 b := &bufferImpl{
310 s: s,
311 rgba: image.RGBA{
312 Stride: 4 * size.X,
313 Rect: image.Rectangle{Max: size},
314 },
315 size: size,
316 }
317
318 if size.X == 0 || size.Y == 0 {
319 // No-op, but we can't take the else path because the minimum shmget
320 // size is 1.
321 } else {
322 xs, err := shm.NewSegId(s.xc)
323 if err != nil {
324 return nil, fmt.Errorf("x11driver: shm.NewSegId: %v", err)
325 }
326
327 bufLen := 4 * size.X * size.Y
328 shmid, addr, err := shmOpen(bufLen)
329 if err != nil {
330 return nil, fmt.Errorf("x11driver: shmOpen: %v", err)
331 }
332 defer func() {
333 if retErr != nil {
334 shmClose(addr)
335 }
336 }()
337 a := (*[maxShmSize]byte)(addr)
338 b.buf = (*a)[:bufLen:bufLen]
339 b.rgba.Pix = b.buf
340 b.addr = addr
341
342 // readOnly is whether the shared memory is read-only from the X11 server's
343 // point of view. We need false to use SHM pixmaps.
344 const readOnly = false
345 shm.Attach(s.xc, xs, uint32(shmid), readOnly)
346 b.xs = xs
347 }
348
349 s.mu.Lock()
350 s.buffers[b.xs] = b
351 s.mu.Unlock()
352
353 return b, nil
354 }
355
356 func (s *screenImpl) NewTexture(size image.Point) (screen.Texture, error) {
357 w, h := int64(size.X), int64(size.Y)
358 if w < 0 || maxShmSide < w || h < 0 || maxShmSide < h || maxShmSize < 4*w*h {
359 return nil, fmt.Errorf("x11driver: invalid texture size %v", size)
360 }
361 if w == 0 || h == 0 {
362 return &textureImpl{
363 s: s,
364 size: size,
365 }, nil
366 }
367
368 xm, err := xproto.NewPixmapId(s.xc)
369 if err != nil {
370 return nil, fmt.Errorf("x11driver: xproto.NewPixmapId failed: %v", err)
371 }
372 xp, err := render.NewPictureId(s.xc)
373 if err != nil {
374 return nil, fmt.Errorf("x11driver: xproto.NewPictureId failed: %v", err)
375 }
376 xproto.CreatePixmap(s.xc, textureDepth, xm, xproto.Drawable(s.window32), uint16(w), uint16(h))
377 render.CreatePicture(s.xc, xp, xproto.Drawable(xm), s.pictformat32, render.CpRepeat, []uint32{render.RepeatPad})
378 render.SetPictureFilter(s.xc, xp, uint16(len("bilinear")), "bilinear", nil)
379 // The X11 server doesn't zero-initialize the pixmap. We do it ourselves.
380 render.FillRectangles(s.xc, render.PictOpSrc, xp, render.Color{}, []xproto.Rectangle{{
381 Width: uint16(w),
382 Height: uint16(h),
383 }})
384
385 return &textureImpl{
386 s: s,
387 size: size,
388 xm: xm,
389 xp: xp,
390 }, nil
391 }
392
393 func (s *screenImpl) NewWindow(opts *screen.NewWindowOptions) (screen.Window, error) {
394 width, height := 1024, 768
395 if opts != nil {
396 if opts.Width > 0 {
397 width = opts.Width
398 }
399 if opts.Height > 0 {
400 height = opts.Height
401 }
402 }
403
404 xw, err := xproto.NewWindowId(s.xc)
405 if err != nil {
406 return nil, fmt.Errorf("x11driver: xproto.NewWindowId failed: %v", err)
407 }
408 xg, err := xproto.NewGcontextId(s.xc)
409 if err != nil {
410 return nil, fmt.Errorf("x11driver: xproto.NewGcontextId failed: %v", err)
411 }
412 xp, err := render.NewPictureId(s.xc)
413 if err != nil {
414 return nil, fmt.Errorf("x11driver: render.NewPictureId failed: %v", err)
415 }
416 pictformat := render.Pictformat(0)
417 switch s.xsi.RootDepth {
418 default:
419 return nil, fmt.Errorf("x11driver: unsupported root depth %d", s.xsi.RootDepth)
420 case 24:
421 pictformat = s.pictformat24
422 case 32:
423 pictformat = s.pictformat32
424 }
425
426 w := &windowImpl{
427 s: s,
428 xw: xw,
429 xg: xg,
430 xp: xp,
431 xevents: make(chan xgb.Event),
432 }
433
434 s.mu.Lock()
435 s.windows[xw] = w
436 s.mu.Unlock()
437
438 w.lifecycler.SendEvent(w, nil)
439
440 xproto.CreateWindow(s.xc, s.xsi.RootDepth, xw, s.xsi.Root,
441 0, 0, uint16(width), uint16(height), 0,
442 xproto.WindowClassInputOutput, s.xsi.RootVisual,
443 xproto.CwEventMask,
444 []uint32{0 |
445 xproto.EventMaskKeyPress |
446 xproto.EventMaskKeyRelease |
447 xproto.EventMaskButtonPress |
448 xproto.EventMaskButtonRelease |
449 xproto.EventMaskPointerMotion |
450 xproto.EventMaskExposure |
451 xproto.EventMaskStructureNotify |
452 xproto.EventMaskFocusChange,
453 },
454 )
455 s.setProperty(xw, s.atomWMProtocols, s.atomWMDeleteWindow, s.atomWMTakeFocus)
456
457 title := []byte(opts.GetTitle())
458 xproto.ChangeProperty(s.xc, xproto.PropModeReplace, xw, s.atomNETWMName, s.atomUTF8String, 8, uint32(len(title)), title)
459
460 xproto.CreateGC(s.xc, xg, xproto.Drawable(xw), 0, nil)
461 render.CreatePicture(s.xc, xp, xproto.Drawable(xw), pictformat, 0, nil)
462 xproto.MapWindow(s.xc, xw)
463
464 return w, nil
465 }
466
467 func (s *screenImpl) initAtoms() (err error) {
468 s.atomNETWMName, err = s.internAtom("_NET_WM_NAME")
469 if err != nil {
470 return err
471 }
472 s.atomUTF8String, err = s.internAtom("UTF8_STRING")
473 if err != nil {
474 return err
475 }
476 s.atomWMDeleteWindow, err = s.internAtom("WM_DELETE_WINDOW")
477 if err != nil {
478 return err
479 }
480 s.atomWMProtocols, err = s.internAtom("WM_PROTOCOLS")
481 if err != nil {
482 return err
483 }
484 s.atomWMTakeFocus, err = s.internAtom("WM_TAKE_FOCUS")
485 if err != nil {
486 return err
487 }
488 return nil
489 }
490
491 func (s *screenImpl) internAtom(name string) (xproto.Atom, error) {
492 r, err := xproto.InternAtom(s.xc, false, uint16(len(name)), name).Reply()
493 if err != nil {
494 return 0, fmt.Errorf("x11driver: xproto.InternAtom failed: %v", err)
495 }
496 if r == nil {
497 return 0, fmt.Errorf("x11driver: xproto.InternAtom failed")
498 }
499 return r.Atom, nil
500 }
501
502 func (s *screenImpl) initKeyboardMapping() error {
503 const keyLo, keyHi = 8, 255
504 km, err := xproto.GetKeyboardMapping(s.xc, keyLo, keyHi-keyLo+1).Reply()
505 if err != nil {
506 return err
507 }
508 n := int(km.KeysymsPerKeycode)
509 if n < 2 {
510 return fmt.Errorf("x11driver: too few keysyms per keycode: %d", n)
511 }
512 for i := keyLo; i <= keyHi; i++ {
513 for j := 0; j < 6; j++ {
514 if j < n {
515 s.keysyms.Table[i][j] = uint32(km.Keysyms[(i-keyLo)*n+j])
516 } else {
517 s.keysyms.Table[i][j] = 0
518 }
519 }
520 }
521
522 // Figure out which modifier is the numlock modifier (see chapter 12.7 of the XLib Manual).
523 mm, err := xproto.GetModifierMapping(s.xc).Reply()
524 if err != nil {
525 return err
526 }
527 s.keysyms.NumLockMod, s.keysyms.ModeSwitchMod, s.keysyms.ISOLevel3ShiftMod = 0, 0, 0
528 numLockFound, modeSwitchFound, isoLevel3ShiftFound := false, false, false
529 modifierSearchLoop:
530 for modifier := 0; modifier < 8; modifier++ {
531 for i := 0; i < int(mm.KeycodesPerModifier); i++ {
532 const (
533 // XK_Num_Lock, XK_Mode_switch and XK_ISO_Level3_Shift from /usr/include/X11/keysymdef.h.
534 xkNumLock = 0xff7f
535 xkModeSwitch = 0xff7e
536 xkISOLevel3Shift = 0xfe03
537 )
538 switch s.keysyms.Table[mm.Keycodes[modifier*int(mm.KeycodesPerModifier)+i]][0] {
539 case xkNumLock:
540 s.keysyms.NumLockMod = 1 << uint(modifier)
541 numLockFound = true
542 case xkModeSwitch:
543 s.keysyms.ModeSwitchMod = 1 << uint(modifier)
544 modeSwitchFound = true
545 case xkISOLevel3Shift:
546 s.keysyms.ISOLevel3ShiftMod = 1 << uint(modifier)
547 isoLevel3ShiftFound = true
548 }
549 if numLockFound && modeSwitchFound && isoLevel3ShiftFound {
550 break modifierSearchLoop
551 }
552 }
553 }
554 return nil
555 }
556
557 func (s *screenImpl) initPictformats() error {
558 pformats, err := render.QueryPictFormats(s.xc).Reply()
559 if err != nil {
560 return fmt.Errorf("x11driver: render.QueryPictFormats failed: %v", err)
561 }
562 s.pictformat24, err = findPictformat(pformats.Formats, 24)
563 if err != nil {
564 return err
565 }
566 s.pictformat32, err = findPictformat(pformats.Formats, 32)
567 if err != nil {
568 return err
569 }
570 return nil
571 }
572
573 func findPictformat(fs []render.Pictforminfo, depth byte) (render.Pictformat, error) {
574 // This presumes little-endian BGRA.
575 want := render.Directformat{
576 RedShift: 16,
577 RedMask: 0xff,
578 GreenShift: 8,
579 GreenMask: 0xff,
580 BlueShift: 0,
581 BlueMask: 0xff,
582 AlphaShift: 24,
583 AlphaMask: 0xff,
584 }
585 if depth == 24 {
586 want.AlphaShift = 0
587 want.AlphaMask = 0x00
588 }
589 for _, f := range fs {
590 if f.Type == render.PictTypeDirect && f.Depth == depth && f.Direct == want {
591 return f.Id, nil
592 }
593 }
594 return 0, fmt.Errorf("x11driver: no matching Pictformat for depth %d", depth)
595 }
596
597 func (s *screenImpl) initWindow32() error {
598 visualid, err := findVisual(s.xsi, 32)
599 if err != nil {
600 return err
601 }
602 colormap, err := xproto.NewColormapId(s.xc)
603 if err != nil {
604 return fmt.Errorf("x11driver: xproto.NewColormapId failed: %v", err)
605 }
606 if err := xproto.CreateColormapChecked(
607 s.xc, xproto.ColormapAllocNone, colormap, s.xsi.Root, visualid).Check(); err != nil {
608 return fmt.Errorf("x11driver: xproto.CreateColormap failed: %v", err)
609 }
610 s.window32, err = xproto.NewWindowId(s.xc)
611 if err != nil {
612 return fmt.Errorf("x11driver: xproto.NewWindowId failed: %v", err)
613 }
614 s.gcontext32, err = xproto.NewGcontextId(s.xc)
615 if err != nil {
616 return fmt.Errorf("x11driver: xproto.NewGcontextId failed: %v", err)
617 }
618 const depth = 32
619 xproto.CreateWindow(s.xc, depth, s.window32, s.xsi.Root,
620 0, 0, 1, 1, 0,
621 xproto.WindowClassInputOutput, visualid,
622 // The CwBorderPixel attribute seems necessary for depth == 32. See
623 // http://stackoverflow.com/questions/3645632/how-to-create-a-window-with-a-bit-depth-of-32
624 xproto.CwBorderPixel|xproto.CwColormap,
625 []uint32{0, uint32(colormap)},
626 )
627 xproto.CreateGC(s.xc, s.gcontext32, xproto.Drawable(s.window32), 0, nil)
628 return nil
629 }
630
631 func findVisual(xsi *xproto.ScreenInfo, depth byte) (xproto.Visualid, error) {
632 for _, d := range xsi.AllowedDepths {
633 if d.Depth != depth {
634 continue
635 }
636 for _, v := range d.Visuals {
637 if v.RedMask == 0xff0000 && v.GreenMask == 0xff00 && v.BlueMask == 0xff {
638 return v.VisualId, nil
639 }
640 }
641 }
642 return 0, fmt.Errorf("x11driver: no matching Visualid")
643 }
644
645 func (s *screenImpl) setProperty(xw xproto.Window, prop xproto.Atom, values ...xproto.Atom) {
646 b := make([]byte, len(values)*4)
647 for i, v := range values {
648 b[4*i+0] = uint8(v >> 0)
649 b[4*i+1] = uint8(v >> 8)
650 b[4*i+2] = uint8(v >> 16)
651 b[4*i+3] = uint8(v >> 24)
652 }
653 xproto.ChangeProperty(s.xc, xproto.PropModeReplace, xw, prop, xproto.AtomAtom, 32, uint32(len(values)), b)
654 }
655
656 func (s *screenImpl) drawUniform(xp render.Picture, src2dst *f64.Aff3, src color.Color, sr image.Rectangle, op draw.Op, opts *screen.DrawOptions) {
657 if sr.Empty() {
658 return
659 }
660
661 if opts == nil && *src2dst == (f64.Aff3{1, 0, 0, 0, 1, 0}) {
662 fill(s.xc, xp, sr, src, op)
663 return
664 }
665
666 r, g, b, a := src.RGBA()
667 c := render.Color{
668 Red: uint16(r),
669 Green: uint16(g),
670 Blue: uint16(b),
671 Alpha: uint16(a),
672 }
673 points := trifanPoints(src2dst, sr)
674
675 s.uniformMu.Lock()
676 defer s.uniformMu.Unlock()
677
678 if s.uniformC != c {
679 s.uniformC = c
680 render.FreePicture(s.xc, s.uniformP)
681 render.CreateSolidFill(s.xc, s.uniformP, c)
682 }
683
684 if op == draw.Src {
685 // We implement draw.Src as render.PictOpOutReverse followed by
686 // render.PictOpOver, for the same reason as in textureImpl.draw.
687 render.TriFan(s.xc, render.PictOpOutReverse, s.opaqueP, xp, 0, 0, 0, points[:])
688 }
689 render.TriFan(s.xc, render.PictOpOver, s.uniformP, xp, 0, 0, 0, points[:])
690 }