[28e3a1]: src / clx / xrender.lisp Maximize Restore History

Download this file

xrender.lisp    903 lines (832 with data), 39.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
;;; -*- Mode: Lisp; Syntax: Common-Lisp; Package: XLIB; -*-
;;; ---------------------------------------------------------------------------
;;; Title: The X Render Extension
;;; Created: 2002-08-03
;;; Author: Gilbert Baumann <unk6@rz.uni-karlsruhe.de>
;;; $Id$
;;; ---------------------------------------------------------------------------
;;;
;;; (c) copyright 2002, 2003 by Gilbert Baumann
;;; (c) copyright 2002 by Christian Sunesson
;;;
;;; Permission is granted to any individual or institution to use,
;;; copy, modify, and distribute this software, provided that this
;;; complete copyright and permission notice is maintained, intact, in
;;; all copies and supporting documentation.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;;;
;;; NOTE: we need to watch maximum request sizes and somehow work
;;; around them. Sometimes e.g. in AddGlyphs this is not possible,
;;; which is a design failure.
;;; TODO
;; - some request are still to be implemented at all.
;; + Can they not wait? Xrender seems to be in flux as the specification
;; isn't even conforming to the acctual protocol. However backwards
;; wierd that sound. --noss
;; - we need to invent something for the color values of e.g.
;; fill-rectangles; I would prefer some generic functions, so that
;; we later can map CLIM design directly to colors.
;; - we want some conviencene function to turn graphics contexts into
;; render pictures. --GB 2002-08-21
;; - also: uniform-alpha-picture display alpha-value
;; uniform-color-picture display red green blue
;; --GB 2002-08-21
;; - maybe we should aim for a higher level interface to
;; color-trapzoids and color-triangles and offer a low level [raw]
;; interface also for high performance apps?
;; - Write tests.
(in-package :xlib)
;; Beginning to collect the external interface for documentation.
(export '(render-create-picture
render-free-picture
render-create-glyph-set
render-reference-glyph-set
render-free-glyph-set
render-add-glyph
render-add-glyph-from-picture
render-free-glyph
render-fill-rectangle
picture-format-display
picture-format-id
picture-format-type
picture-format-depth
picture-format-red-byte
picture-format-green-byte
picture-format-blue-byte
picture-format-alpha-byte
picture-format-colormap
;; picture object
picture-repeat
picture-alpha-map
picture-alpha-x-origin
picture-alpha-y-origin
picture-clip-x-origin
picture-clip-y-origin
picture-clip-mask
picture-graphics-exposures
picture-subwindow-mode
picture-poly-edge
picture-poly-mode
picture-dither
picture-component-alpha
picture-drawable
find-matching-picture-formats
find-window-picture-format
render-free-picture
render-free-glyph-set
render-query-version
;; render-query-picture-formats
render-fill-rectangle
render-composite
render-create-glyph-set
render-reference-glyph-set
render-composite-glyphs
render-add-glyph
render-add-glyph-from-picture
render-free-glyphs
render-combine
))
(pushnew :clx-ext-render *features*)
(define-extension "RENDER")
(progn
(defconstant +X-RenderQueryVersion+ 0) ;done
(defconstant +X-RenderQueryPictFormats+ 1)
(defconstant +X-RenderQueryPictIndexValues+ 2)
(defconstant +X-RenderQueryDithers+ 3)
(defconstant +X-RenderCreatePicture+ 4) ;done
(defconstant +X-RenderChangePicture+ 5) ;done
(defconstant +X-RenderSetPictureClipRectangles+ 6) ;done
(defconstant +X-RenderFreePicture+ 7) ;done
(defconstant +X-RenderComposite+ 8) ;we need better arglist
(defconstant +X-RenderScale+ 9)
(defconstant +X-RenderTrapezoids+ 10)
(defconstant +X-RenderTriangles+ 11)
(defconstant +X-RenderTriStrip+ 12)
(defconstant +X-RenderTriFan+ 13)
(defconstant +X-RenderColorTrapezoids+ 14)
(defconstant +X-RenderColorTriangles+ 15)
(defconstant +X-RenderTransform+ 16)
(defconstant +X-RenderCreateGlyphSet+ 17) ;done
(defconstant +X-RenderReferenceGlyphSet+ 18) ;done
(defconstant +X-RenderFreeGlyphSet+ 19) ;done
(defconstant +X-RenderAddGlyphs+ 20)
(defconstant +X-RenderAddGlyphsFromPicture+ 21)
(defconstant +X-RenderFreeGlyphs+ 22)
(defconstant +X-RenderCompositeGlyphs8+ 23) ;done
(defconstant +X-RenderCompositeGlyphs16+ 24)
(defconstant +X-RenderCompositeGlyphs32+ 25)
(defconstant +X-RenderFillRectangles+ 26))
;; Sanity measures:
;; We do away with the distinction between pict-format and
;; picture-format-info. That is we cache picture-format-infos.
(defstruct render-info
major-version
minor-version
picture-formats)
(defun display-render-info (display)
(getf (xlib:display-plist display) 'render-info))
(defun (setf display-render-info) (new-value display)
(setf (getf (xlib:display-plist display) 'render-info)
new-value))
(defun ensure-render-initialized (display)
"Ensures that the RENDER extension is initialized. Should be called
by every function, which attempts to generate RENDER requests."
;; xxx locking?
(unless (display-render-info display)
(let ((q (make-render-info)))
(multiple-value-bind (maj min) (render-query-version display)
(setf (render-info-major-version q) maj
(render-info-minor-version q) min)
(setf (render-info-picture-formats q)
(make-hash-table :test #'eql))
(dolist (pf (render-query-picture-formats display))
(setf (gethash (picture-format-id pf) (render-info-picture-formats q))
pf))
(setf (display-render-info display) q)))))
(defun find-matching-picture-formats
(display
&key depth-min depth-max depth
red-min red-max red
green-min green-max green
blue-min blue-max blue
alpha-min alpha-max alpha
type
colormap)
;;
(ensure-render-initialized display)
(let ((res nil))
(maphash (lambda (k f)
(declare (ignore k))
(when (and
(or (null type) (eql (picture-format-type f) type))
(or (null colormap) (eql (picture-format-colormap f) colormap))
;; min
(or (null depth-min) (>= (picture-format-depth f) depth-min))
(or (null red-min) (>= (byte-size (picture-format-red-byte f)) red-min))
(or (null green-min) (>= (byte-size (picture-format-green-byte f)) green-min))
(or (null blue-min) (>= (byte-size (picture-format-blue-byte f)) blue-min))
(or (null alpha-min) (>= (byte-size (picture-format-alpha-byte f)) alpha-min))
;; max
(or (null depth-max) (<= (picture-format-depth f) depth-max))
(or (null red-max) (<= (byte-size (picture-format-red-byte f)) red-max))
(or (null green-max) (<= (byte-size (picture-format-green-byte f)) green-max))
(or (null blue-max) (<= (byte-size (picture-format-blue-byte f)) blue-max))
(or (null alpha-max) (<= (byte-size (picture-format-alpha-byte f)) alpha-max))
;; match
(or (null depth) (= (picture-format-depth f) depth))
(or (null red) (= (byte-size (picture-format-red-byte f)) red))
(or (null green) (= (byte-size (picture-format-green-byte f)) green))
(or (null blue) (= (byte-size (picture-format-blue-byte f)) blue))
(or (null alpha) (= (byte-size (picture-format-alpha-byte f)) alpha)))
(pushnew f res)))
(render-info-picture-formats
(display-render-info display)))
res))
(defun find-window-picture-format (window)
"Find the picture format which matches the given window."
(let* ((cm (window-colormap window))
(vi (colormap-visual-info cm))
(display (window-display window)))
(ensure-render-initialized display)
(case (visual-info-class vi)
((:true-color)
(maphash (lambda (k f)
(declare (ignore k))
(when (and (eql (picture-format-type f) :direct)
(eql (dpb -1 (picture-format-red-byte f) 0)
(visual-info-red-mask vi))
(eql (dpb -1 (picture-format-green-byte f) 0)
(visual-info-green-mask vi))
(eql (dpb -1 (picture-format-blue-byte f) 0)
(visual-info-blue-mask vi))
(eql (byte-size (picture-format-alpha-byte f)) 0))
(return-from find-window-picture-format f)))
(render-info-picture-formats
(display-render-info display))))
(t
))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(define-accessor picture (32)
((index) index :blip)
((index thing) `(resource-id-put ,index (picture-id ,thing))))
(define-accessor glyph-set (32)
((index) index :blip)
((index thing) `(resource-id-put ,index (glyph-set-id ,thing)))))
;;; picture format
(defstruct picture-format
display
(id 0 :type (unsigned-byte 29))
type
depth
red-byte
green-byte
blue-byte
alpha-byte
colormap)
(defmethod print-object ((object picture-format) stream)
(let ((abbrev
(with-output-to-string (bag)
;; build an abbreviated representation of the format
(let ((bytes (sort (list (cons "r" (picture-format-red-byte object))
(cons "g" (picture-format-green-byte object))
(cons "b" (picture-format-blue-byte object))
(cons "a" (picture-format-alpha-byte object)))
#'>
:key #'(lambda (x) (byte-position (cdr x))))))
(dolist (k bytes)
(unless (zerop (byte-size (cdr k)))
(format bag " ~A~D" (car k) (byte-size (cdr k)))))))))
(print-unreadable-object (object stream :type t :identity nil)
(format stream "~D ~S~A"
(picture-format-id object)
(picture-format-type object) abbrev))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(define-accessor picture-format (32)
((index) `(gethash (read-card32 ,index)
(render-info-picture-formats (display-render-info .display.))))
((index thing) `(write-card32 ,index (picture-format-id ,thing))))
(define-accessor render-op (8)
((index) `(member8-get ,index
:clear :src :dst :over :over-reverse :in :in-reverse
:out :out-reverse :atop :atop-reverse :xor :add :saturate :maximum))
((index thing) `(member8-put ,index ,thing
:clear :src :dst :over :over-reverse :in :in-reverse
:out :out-reverse :atop :atop-reverse :xor :add :saturate :maximum))))
;; Now these pictures objects are like graphics contexts. I was about
;; to introduce a synchronous mode, realizing that the RENDER protocol
;; provides no provision to actually query a picture object's values.
;; *sigh*
(def-clx-class (picture (:copier nil)
)
(id 0 :type resource-id)
(display nil :type (or null display))
(plist nil :type list) ; Extension hook
format
%changed-p
%server-values
%values
%drawable)
(defun picture-drawable (picture)
(picture-%drawable picture))
;; xx make id, display, format readonly
(defun %render-change-picture-clip-rectangles (picture rectangles)
"Dont call me, use (SETF PICTURE-CLIP-MASK) instead."
(declare (optimize (speed 0)))
(let ((display (picture-display picture)))
(ensure-render-initialized display)
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderSetPictureClipRectangles+)
(picture picture)
(int16 (picture-clip-x-origin picture))
(int16 (picture-clip-y-origin picture))
((sequence :format int16) rectangles))))
(macrolet ((foo (&rest specs)
`(progn
,@(loop for (type slot default) in specs
for index from 0
collect
`(progn
(defun ,(xintern 'picture- slot) (picture)
(aref (picture-%values picture) ,index))
(defun (setf ,(xintern 'picture- slot)) (new-value picture)
(setf (picture-%changed-p picture) t)
(setf (aref (picture-%values picture) ,index) new-value))))
(defun synchronise-picture-state (picture)
(when (picture-%changed-p picture)
(let ((display (picture-display picture)))
(ensure-render-initialized display)
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderChangePicture+)
(picture picture)
(mask
,@(loop for (type slot default) in specs
for index from 0
collect
`(,type (and
,(cond ((eql slot 'clip-mask)
`(not (typep (aref (picture-%values picture) ,index)
'sequence)))
(t
't))
(not (eq (aref (picture-%values picture) ,index)
(aref (picture-%server-values picture) ,index)))
(setf (aref (picture-%server-values picture) ,index)
(aref (picture-%values picture) ,index))))))))
,(let ((index (position 'clip-mask specs :key #'second)))
`(unless (eql (aref (picture-%values picture) ,index)
(aref (picture-%server-values picture)
,index))
(%render-change-picture-clip-rectangles
picture (aref (picture-%values picture) ,index))
(setf (aref (picture-%values picture) ,index)
(aref (picture-%server-values picture)
,index))))
(setf (picture-%changed-p picture) nil)))
(defun render-create-picture
(drawable
&key format
(picture (make-picture :display (drawable-display drawable)))
,@(loop for (type slot default-value) in specs
collect (cond ((eql slot 'clip-mask)
`(clip-mask :none))
(t
slot)))
)
;; xxx also offer to give a colormap instead of a picture-format
;; values!
(let ((display (drawable-display drawable)))
(ensure-render-initialized display)
(unless format
;; xxx check for drawable being a window
(setf format (find-window-picture-format drawable)))
(let ((pid (allocate-resource-id display picture 'picture)))
(setf (picture-id picture) pid)
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderCreatePicture+)
(resource-id pid)
(drawable drawable)
(picture-format format)
(mask
,@(loop for (type slot default) in specs
collect
(cond ((eql slot 'clip-mask)
(list type `(and
(not (typep clip-mask 'sequence))
clip-mask)))
(t
(list type slot)))))))
(when (typep clip-mask 'sequence)
(%render-change-picture-clip-rectangles picture clip-mask))
(setf (picture-format picture) format)
(setf (picture-%server-values picture)
(vector ,@(loop for (type slot default) in specs
collect
`(or ,slot ,default))))
(setf (picture-%values picture) (copy-seq (picture-%server-values picture)))
(setf (picture-%drawable picture) drawable)
picture))
(defconstant +picture-state-length+
,(length specs)) )))
(foo ((member :off :on) repeat :off)
((or (member :none) picture) alpha-map :none)
(int16 alpha-x-origin 0)
(int16 alpha-y-origin 0)
(int16 clip-x-origin 0)
(int16 clip-y-origin 0)
;; ### Now that is not correct is it?:
((or (member :none) pixmap) clip-mask :none)
((member :off :on) graphics-exposures :on)
((member :clip-by-children :include-inferiors) subwindow-mode :clip-by-children)
((member :sharp :smooth) poly-edge :smooth)
((member :precise :imprecise) poly-mode :precise)
((or (member :none) #||xatom||#) dither :none)
((member :off :on) component-alpha :off)))
(defun render-free-picture (picture)
(let ((display (picture-display picture)))
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderFreePicture+)
(picture picture))))
(defun render-free-glyph-set (glyph-set)
(let ((display (glyph-set-display glyph-set)))
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderFreeGlyphSet+)
(glyph-set glyph-set))))
(defun render-query-version (display)
(with-buffer-request-and-reply (display (extension-opcode display "RENDER") nil)
((data +X-RenderQueryVersion+)
(card32 0)
(card32 1))
(values
(card16-get 8)
(card16-get 10)
)))
(defun render-query-picture-formats (display)
(with-buffer-request-and-reply (display (extension-opcode display "RENDER") nil)
((data +X-RenderQueryPictFormats+))
(let ((n-picture-formats (card32-get 8))
(n-screens (card32-get 12))
(off 32))
(declare (ignore n-screens off))
(loop for i below n-picture-formats
collect
(let ((off (+ (* 8 4)
(* i 28)))) ;size of picture-format-info
(make-picture-format
:display display
:id (card32-get (+ off 0))
:type (member8-get (+ off 4) :indexed :direct)
:depth (card8-get (+ off 5))
:red-byte (byte (integer-length (card16-get (+ off 10)))
(card16-get (+ off 8)))
:green-byte (byte (integer-length (card16-get (+ off 14)))
(card16-get (+ off 12)))
:blue-byte (byte (integer-length (card16-get (+ off 18)))
(card16-get (+ off 16)))
:alpha-byte (byte (integer-length (card16-get (+ off 22)))
(card16-get (+ off 20)))
:colormap (let ((cmid (card32-get (+ off 24))))
(unless (zerop cmid)
(lookup-colormap display cmid)))))))))
(defun render-fill-rectangle (picture op color x1 y1 w h)
(let ((display (picture-display picture)))
(ensure-render-initialized display)
(synchronise-picture-state picture)
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderFillRectangles+)
(render-op op) ;op
(card8 0) ;pad
(card16 0) ;pad
(resource-id (picture-id picture))
(card16 (elt color 0)) (card16 (elt color 1)) (card16 (elt color 2)) (card16 (elt color 3))
(int16 x1) (int16 y1) (card16 w) (card16 h))))
;; fill rectangles, colors.
(defun render-composite (op
source mask dest
src-x src-y mask-x mask-y dst-x dst-y
width height)
(let ((display (picture-display source)))
(synchronise-picture-state source)
(when mask (synchronise-picture-state mask))
(synchronise-picture-state dest)
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderComposite+)
(render-op op) ;op
(card8 0) ;pad
(card16 0) ;pad
(resource-id (picture-id source))
(resource-id (if mask (picture-id mask) 0))
(resource-id (picture-id dest))
(card16 src-x)
(card16 src-y)
(card16 mask-x)
(card16 mask-y)
(card16 dst-x)
(card16 dst-y)
(card16 width)
(card16 height))))
(def-clx-class (glyph-set (:copier nil)
)
(id 0 :type resource-id)
(display nil :type (or null display))
(plist nil :type list) ; Extension hook
format)
(defun render-create-glyph-set (format &key glyph-set)
(let ((display (picture-format-display format)))
(let* ((glyph-set (or glyph-set (make-glyph-set :display display)))
(gsid (setf (glyph-set-id glyph-set)
(allocate-resource-id display glyph-set 'glyph-set))))
(declare (ignore gsid))
(setf (glyph-set-format glyph-set) format)
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderCreateGlyphSet+)
(glyph-set glyph-set)
(picture-format format))
glyph-set)))
(defun render-reference-glyph-set (existing-glyph-set &key glyph-set)
(let ((display (glyph-set-display existing-glyph-set)))
(let* ((glyph-set (or glyph-set (make-glyph-set :display display)))
(gsid (setf (glyph-set-id glyph-set)
(allocate-resource-id display glyph-set 'glyph-set))))
(declare (ignore gsid))
(setf (glyph-set-format glyph-set)
(glyph-set-format existing-glyph-set))
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderReferenceGlyphSet+)
(glyph-set glyph-set)
(glyph-set existing-glyph-set))
glyph-set)))
(defun render-composite-glyphs-8 (dest glyph-set source dest-x dest-y sequence
&key (op :over)
(alu op) ;for the fun of it
(src-x 0)
(src-y 0)
(mask-format :none)
(start 0)
(end (length sequence)))
(let ((display (picture-display dest)))
(ensure-render-initialized display)
(synchronise-picture-state dest)
(synchronise-picture-state source)
(when (stringp sequence)
;; lazy me, but then you should not confuse glyphs with
;; characters anyway.
(setf sequence (map 'vector #'char-code sequence)))
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderCompositeGlyphs8+)
(render-op alu)
(card8 0) (card16 0) ;padding
(picture source)
(picture dest)
((or (member :none) picture-format) mask-format)
(glyph-set glyph-set)
(int16 src-x) (int16 src-y)
(card8 (- end start)) ;length of glyph elt
(card8 0) (card16 0) ;padding
(card16 dest-x) (card16 dest-y) ;dx, dy
((sequence :format card8) sequence))))
(defmacro %render-composite-glyphs
(opcode type transform
display dest glyph-set source dest-x dest-y sequence alu src-x src-y mask-format start end)
`(with-buffer-request (,display (extension-opcode ,display "RENDER"))
(data ,opcode)
(render-op ,alu)
(card8 0) (card16 0) ;padding
(picture ,source)
(picture ,dest)
((or (member :none) picture-format) ,mask-format)
(glyph-set ,glyph-set)
(int16 ,src-x) (int16 ,src-y)
(card8 (- ,end ,start)) ;length of glyph elt
(card8 0) (card16 0) ;padding? really?
(card16 ,dest-x) (card16 ,dest-y) ;dx, dy
((sequence :format ,type :start ,start :end ,end :transform ,transform) ,sequence)))
(defun render-composite-glyphs (dest glyph-set source dest-x dest-y sequence
&key (op :over)
(alu op) ;for the fun of it
(src-x 0)
(src-y 0)
(mask-format :none)
(start 0)
(end (length sequence)))
;; xxx do we want to go with some translate function as draw-glyphs?
(declare (type array-index start end))
(let ((display (picture-display dest)))
(ensure-render-initialized display)
(synchronise-picture-state dest)
(synchronise-picture-state source)
;; hmm find out the element size
(typecase sequence
((array (unsigned-byte 8) (*))
(%render-composite-glyphs +X-RenderCompositeGlyphs8+ card8 nil
display dest glyph-set source dest-x dest-y sequence alu src-x
src-y mask-format start end))
((array (unsigned-byte 16) (*))
(%render-composite-glyphs +X-RenderCompositeGlyphs16+ card16 nil
display dest glyph-set source dest-x dest-y sequence alu src-x
src-y mask-format start end))
((array (unsigned-byte 32) (*))
(%render-composite-glyphs +X-RenderCompositeGlyphs32+ card32 nil
display dest glyph-set source dest-x dest-y sequence alu src-x
src-y mask-format start end))
(string
(%render-composite-glyphs #.(cond ((<= char-code-limit (expt 2 8)) '+X-RenderCompositeGlyphs8+)
((<= char-code-limit (expt 2 16)) '+X-RenderCompositeGlyphs16+)
((<= char-code-limit (expt 2 32)) '+X-RenderCompositeGlyphs32+)
(t
(error "Wow!")))
#.(cond ((<= char-code-limit (expt 2 8)) 'card8)
((<= char-code-limit (expt 2 16)) 'card16)
((<= char-code-limit (expt 2 32)) 'card32)
(t
(error "Wow!")))
#'char-code
display dest glyph-set source dest-x dest-y sequence alu src-x
src-y mask-format start end))
(t
;; should we bother testing the array element type?
(%render-composite-glyphs +X-RenderCompositeGlyphs32+ card32
#'(lambda (elt)
(if (characterp elt)
(char-code elt)
elt))
display dest glyph-set source dest-x dest-y sequence alu src-x
src-y mask-format start end))) ))
;; --- idea: Allow data to be an image to avoid unecessary consing? - noss
(defun render-add-glyph (glyph-set id &key x-origin y-origin x-advance y-advance data)
(let ((display (glyph-set-display glyph-set)))
(ensure-render-initialized display)
(let* ((w (array-dimension data 1))
(h (array-dimension data 0))
(bitmap-format (display-bitmap-format display))
(unit (bitmap-format-unit bitmap-format))
(byte-lsb-first-p (display-image-lsb-first-p display))
(bit-lsb-first-p (bitmap-format-lsb-first-p bitmap-format)))
(let* ((byte-per-line (* 4 (ceiling
(* w (picture-format-depth (glyph-set-format glyph-set)))
32)))
(request-length (+ 28
(* h byte-per-line))))
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderAddGlyphs+)
(length (ceiling request-length 4))
(glyph-set glyph-set)
(card32 1) ;number glyphs
(card32 id) ;id
(card16 w)
(card16 h)
(int16 x-origin)
(int16 y-origin)
(int16 x-advance)
(int16 y-advance)
(progn
(setf (buffer-boffset display) (advance-buffer-offset 28))
(let ((im (create-image :width w :height h :depth 8 :data data)))
(write-image-z display im 0 0 w h
byte-per-line ;padded bytes per line
unit byte-lsb-first-p bit-lsb-first-p)) ))) )))
(defun render-add-glyph-from-picture (glyph-set picture
&key x-origin y-origin x-advance y-advance
x y width height)
;; untested, the duplication of x-origin seems bogus.
;; Still untested, but these modifications seem to be more likely, (x,y) would be the offset into the picture.
;; and orgin advance would be properties of the defined glyph.
(let ((display (glyph-set-display glyph-set)))
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderAddGlyphsFromPicture+)
(glyph-set glyph-set)
(picture picture)
(card16 width)
(card16 height)
(card16 x-origin)
(card16 y-origin)
(card16 x-advance)
(card16 y-advance)
(card16 x)
(card16 y))))
;; untested
(defun render-free-glyphs (glyph-set glyphs)
"This request removes glyphs from glyph-set. Each glyph must exist in glyph-set (else a Match error results)."
(let ((display (glyph-set-display glyph-set)))
(with-buffer-request (display (extension-opcode display "RENDER"))
(data +X-RenderFreeGlyphs+)
(glyph-set glyph-set)
((sequence :format card32) glyphs))))
#||
;;; --------------------------------------------------------------------------------
;; testing code:
(defun x (op)
(let ((dpy (open-display "")))
(render-query-version dpy)
(unwind-protect
(let* ((win (screen-root (first (display-roots dpy))))
(display dpy)
(pf (find-window-picture-format win))
(pm (xlib:create-pixmap
:depth (xlib:drawable-depth win)
:drawable win :width 1 :height 1))
(pm.p (render-create-picture pm
:format pf
:repeat :on))
(win.p (render-create-picture win :format pf))
(gs (render-create-glyph-set (first
(find-matching-picture-formats
dpy
:alpha 8
:red-max 0
:green-max 0
:blue-max 0)))))
(xlib:clear-area win)
(render-fill-rectangle pm.p :src (list #xFFFF 0 0 0) 0 0 100 100)
(render-add-glyph gs 18
:data (make-array (list 3 3)
:initial-contents '((255 000 000)
(000 255 000)
(000 000 255))
:element-type '(unsigned-byte 8))
:x-advance 4
:y-advance 0
:x-origin 0
:y-origin 0)
(let ((w 50)
(h 50))
(let ((data (make-array (list h w) :element-type '(unsigned-byte 8) :initial-element 0)))
(dotimes (i w)
(dotimes (j h)
(setf (aref data i j) (* 3 i))))
(render-add-glyph gs 17
:data data
:x-advance (+ w 2)
:y-advance 0
:x-origin 0
:y-origin 0)))
(render-composite-glyphs-8 win.p gs pm.p
200 330
(vector 17 18 18 17 17 17 17 17 17 17)
:alu op
)
;;
(display-finish-output dpy)
(close-display dpy)))))
(defun z (op)
(let ((dpy (open-display "")))
(unwind-protect
(let* ((win (screen-root (first (display-roots dpy))))
(pic (render-create-picture win))
(fmt (first (find-matching-picture-formats
dpy
:red-min 8
:green-min 8
:blue-min 8
:alpha-min 8)))
(px (xlib:create-pixmap :width 256 :height 256 :depth (picture-format-depth fmt)
:drawable win))
(px.pic (render-create-picture px :format fmt))
(px.gc (xlib:create-gcontext :drawable px)))
(xlib:clear-area win)
;;
(render-fill-rectangle px.pic :src
(list #x8000 #x0000 #x8000 #xFFFF)
0 0 256 256)
;; render-combine simply does not work
(render-combine :src pic pic px.pic
350 350 350 350 0 0 256 256)
;;
(render-fill-rectangle px.pic :over
(list #x8000 #x8000 #x8000 #x8000)
0 0 100 100)
(render-combine :src
px.pic px.pic pic
0 0 0 0 350 350
256 256)
(render-fill-rectangle pic op (list #x0 #x0 #x0 #x8000) 200 200 800 800)
(display-finish-output dpy))
(close-display dpy))))
;;; ----------------------------------------------------------------------------------------------------
(defun y (op)
(let ((dpy (open-display "")))
(render-query-version dpy)
(unwind-protect
(let* ((win (screen-root (first (display-roots dpy))))
(pic
(render-create-picture win))
(px (xlib:create-pixmap :drawable win
:width 256
:height 256
:depth 32))
(px.gc (xlib:create-gcontext :drawable px)))
(dotimes (x 256)
(dotimes (y 256)
(setf (xlib:gcontext-foreground px.gc)
(dpb x (byte 8 24)
(dpb y (byte 8 16)
(dpb y (byte 8 8)
y))))
(xlib:draw-point px px.gc x y)
))
(xlib:clear-area win)
(let ((q(render-create-picture px
:format
(first (find-matching-picture-formats
dpy
:depth 32
:alpha 8 :red 8 :green 8 :blue 8))
:component-alpha :on
:repeat :off
)))
(render-combine op
q
q
pic
0 0
0 0
100 100
400 400))
(let ()
;;(render-fill-rectangle pic op (list 255 255 255 255) 100 100 200 200)
(display-finish-output dpy)))
(close-display dpy))))
(defun zz ()
(let* ((dpy (xlib:open-display ""))
(win (screen-root (first (display-roots dpy))))
(pic (render-create-picture win)))
(xlib:clear-area win)
(setf (picture-clip-mask pic) (list 100 100 200 2000))
(render-fill-rectangle pic :over (list #xFFFF 0 0 #x400) 0 0 2000 2000)
(display-finish-output dpy)
(close-display dpy)))
||#
;; $Log$
;; Revision 1.14 2005-04-12 11:59:36 jjgarcia
;; The build system has been cleaned. The --with-system-* options now can automatically detect the existence of GMP and Boehm-Weiser libraries
;;
;; Revision 1.1 2004/06/10 07:59:31 jlr
;; Portable CLX library imported
;;
;; Revision 1.2 2003/06/14 15:16:07 csr21
;; Clean up compilation under sbcl: a couple of IGNOREs, a couple of
;; s/load/:load-toplevel/, one s/*foo*/+foo+/. Still many many compilation
;; notes, but since the render protocol is inherently slow anyway...
;;
;; Revision 1.1 2003/06/14 14:27:33 gilbert
;; imported as is.
;;
;; Revision 1.1 2003/05/25 13:37:07 gilbert
;; imported
;;
;; Revision 1.5 2003/05/25 14:37:26 gilbert
;; - adjusted copyright.
;; - added a few more exports
;; - CLX-EXT-RENDER is now on *FEATURES*
;;
;; Revision 1.4 2002/08/22 23:57:29 noss
;; render-free-glyphs - new function
;; In %render-composite-glyphs - Found a lingering pict-format
;; In render-add-glyph - changed origin and advance to be transmitted as int16 instead of card16
;;
;; Revision 1.3 2002/08/21 19:56:08 gilbert
;; %render-composite-glyphs - new macro
;; render-composite-glyphs - new function
;;