forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNXGraphicsSubsystem.html
4248 lines (4002 loc) · 146 KB
/
NXGraphicsSubsystem.html
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
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<head>
<title>NX Graphics Subsystem</title>
<meta name="author" content="Gregory Nutt">
</head>
<body background="backgd.gif">
<hr><hr>
<table width ="100%">
<tr align="center" bgcolor="#e4e4e4">
<td>
<h1><big><font color="#3c34ec">
<i>NX Graphics Subsystem</i>
</font></big></h1>
<p>Last Updated: December 28, 2013</p>
</td>
</tr>
</table>
<hr><hr>
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<h1>Table of Contents</h1>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td align="left" valign="top">
<p>
<big><b>1.0</b> <a href="#Introduction">Introduction</a></big>
</p>
<ul>
<p>
<i><b>1.1</b> <a href="#Overview">Overview</a><br></i>
<i><b>1.2</b> <a href="#Objectives">Objectives</a></i><br>
<i><b>1.3</b> <a href="#Organization">Organization</a></i>
</p>
<p>
<ul>
<i>1.3.1 <a href="#nxgl1">NX Graphics Library (<code>NXGL</code>)</a></i><br>
<i>1.3.2 <a href="#nx1">NX (NXSU and NXMU)</a></i><br>
<i>1.3.3 <a href="#nxtk1">NX Tool Kit (<code>NXTK</code>)</a></i><br>
<i>1.3.4 <a href="#nxfonts1">NX Fonts Support (<code>NXFONTS</code>)</a></i><br>
<i>1.3.5 <a href="#nxwidgets1">NX Widgets (<code>NxWidgets</code>)</a></i><br>
<i>1.3.6 <a href="#nxconsole1">NX Console Driver (<code>NxConsole</code>)</a></i>
</ul>
</p>
</ul>
<p>
<big><b>2.0</b> <a href="#nxapis">NX User APIs</a></big>
</p>
<ul>
<p>
<i><b>2.1</b> <a href="#nxheaders">NX Header Files</a></i><br>
<i><b>2.2</b> <a href="#nxgl2">NX Graphics Library (<code>NXGL</code>)</a></i>
</p>
<p>
<ul>
<i>2.2.1 <a href="#nxgltypes">NXGL Types</a></i><br>
<i>2.2.1 <a href="#nxglrgb2yuv"><code>nxgl_rgb2yuv()</code></a></i><br>
<i>2.2.2 <a href="#nxglyuv2rgb"><code>nxgl_yuv2rgb()</code></a></i><br>
<i>2.2.3 <a href="#nxglrectcopy"><code>nxgl_rectcopy()</code></a></i><br>
<i>2.2.4 <a href="#nxglrectoffset"><code>nxgl_rectoffset()</code></a></i><br>
<i>2.2.5 <a href="#nxglvectoradd"><code>nxgl_vectoradd()</code></a></i><br>
<i>2.2.6 <a href="#nxglvectorsubtract"><code>nxgl_vectorsubtract()</code></a></i><br>
<i>2.2.7 <a href="#nxglrectintersect"><code>nxgl_rectintersect()</code></a></i><br>
<i>2.2.8 <a href="#nxglrectunion"><code>nxgl_rectunion()</code></a></i><br>
<i>2.2.9 <a href="#nxglnonintersecting"><code>nxgl_nonintersecting()</code></a></i><br>
<i>2.2.10 <a href="#nxglrectoverlap"><code>nxgl_rectoverlap()</code></a></i><br>
<i>2.2.11 <a href="#nxglrectinside"><code>nxgl_rectinside()</code></a></i><br>
<i>2.2.12 <a href="#nxglrectsize"><code>nxgl_rectsize()</code></a></i><br>
<i>2.2.13 <a href="#nxglnullrect"><code>nxgl_nullrect()</code></a></i><br>
<i>2.2.14 <a href="#nxglrunoffset"><code>nxgl_runoffset()</code></a></i><br>
<i>2.2.15 <a href="#nxglruncopy"><code>nxgl_runcopy()</code></a></i><br>
<i>2.2.16 <a href="#nxgltrapoffset"><code>nxgl_trapoffset()</code></a></i><br>
<i>2.2.17 <a href="#nxgltrapcopy"><code>nxgl_trapcopy()</code></a></i><br>
<i>2.2.18 <a href="#nxglcolorcopy"><code>nxgl_colorcopy</code></a></i><br>
<i>2.2.19 <a href="#nxglsplitline"><code>nxgl_splitline()</code></a></i><br>
<i>2.2.20 <a href="#nxglcirclepts"><code>nxgl_circlepts()</code></a></i><br>
<i>2.2.21 <a href="#nxglcircletraps"><code>nxgl_circletraps()</code></a></i>
</ul>
</p>
<p>
<i><b>2.3</b> <a href="#nx2">NX</a></i>
</p>
<p>
<ul>
<i>2.3.1 <a href="#nxppdefs">Pre-Processor Definitions</a></i><br>
<i>2.3.2 <a href="#nxtypes">NX Types</a></i><br>
<i>2.3.3 <a href="#nxtypes">NX Server Callbacks</a></i>
<p>
<ul>
<i>2.3.3.1 <a href="#nxcbredraw"><code>redraw()</code></a></i><br>
<i>2.3.3.2 <a href="#nxcbposition"><code>position()</code></a></i><br>
<i>2.3.3.3 <a href="#nxcbmousein"><code>mousein()</code></a></i><br>
<i>2.3.3.4 <a href="#nxcbkbdin"><code>kbdin()</code></a></i>
</ul>
<p>
<i>2.3.4 <a href="#nxruninstance"><code>nx_runinstance()</code> (and <code>nx_run()<code> macro)</a></i><br>
<i>2.3.5 <a href="#nxconnectinstance"><code>nx_connectinstance()</code> (and <code>nx_connect()</code> macro)</a></i><br>
<i>2.3.6 <a href="#nxopen"><code>nx_open()</code></a></i><br>
<i>2.3.7 <a href="#nxdisconnect"><code>nx_disconnect()</code></a></i><br>
<i>2.3.8 <a href="#nxclose"><code>nx_close()</code></a></i><br>
<i>2.3.9 <a href="#nxeventhandler"><code>nx_eventhandler()</code></a></i><br>
<i>2.3.10 <a href="#nxeventnotify"><code>nx_eventnotify()</code></a></i><br>
<i>2.3.11 <a href="#nxopenwindow"><code>nx_openwindow()</code></a></i><br>
<i>2.3.12 <a href="#nxclosewindow"><code>nx_closewindow()</code></a></i><br>
<i>2.3.13 <a href="#nxrequestbkgd"><code>nx_requestbkgd()</code></a></i><br>
<i>2.3.14 <a href="#nxreleasebkgd"><code>nx_releasebkgd()</code></a></i><br>
<i>2.3.15 <a href="#nxgetposition"><code>nx_getposition()</code></a></i><br>
<i>2.3.16 <a href="#nxsetposition"><code>nx_setposition()</code></a></i><br>
<i>2.3.17 <a href="#nxsetsize"><code>nx_setsize()</code></a></i><br>
<i>2.3.18 <a href="#nxraise"><code>nx_raise()</code></a></i><br>
<i>2.3.19 <a href="#nxlower"><code>nx_lower()</code></a></i><br>
<i>2.3.20 <a href="#nxfill"><code>nx_fill()</code></a></i><br>
<i>2.3.21 <a href="#nxgetrectangle"><code>nx_getrectangle()</code></a></i><br>
<i>2.3.22 <a href="#nxfilltrapezoid"><code>nx_filltrapezoid()</code></a></i><br>
<i>2.3.23 <a href="#nxdrawline"><code>nx_drawline()</code></a></i><br>
<i>2.3.24 <a href="#nxdrawcircle"><code>nx_drawcircle()</code></a></i><br>
<i>2.3.25 <a href="#nxfillcircle"><code>nx_fillcircle()</code></a></i><br>
<i>2.3.26 <a href="#nxglrgb2yuv"><code>nx_setbgcolor()</code></a></i><br>
<i>2.3.27 <a href="#nxmove"><code>nx_move()</code></a></i><br>
<i>2.3.28 <a href="#nxbitmap"><code>nx_bitmap()</code></a></i><br>
<i>2.3.29 <a href="#nxkbdin"><code>nx_kbdin()</code></a></i><br>
<i>2.3.30 <a href="#nxmousein"><code>nx_mousein()</code></a></i><br>
</ul>
</p>
</td>
<td align="left" valign="top">
<p>
<i><b>2.4</b> <a href="#nxtk2">NX Tool Kit (<code>NXTK</code>)</a></i>
</p>
<p>
<ul>
<i>2.4.1 <a href="#nxtktypes"><code>NXTK Types()</code></a></i><br>
<i>2.4.2 <a href="#nxtkopenwindow"><code>nxtk_openwindow()</code></a></i><br>
<i>2.4.3 <a href="#nxtkclosewindow"><code>nxtk_closewindow()</code></a></i><br>
<i>2.4.4 <a href="#nxtkgetposition"><code>nxtk_getposition()</code></a></i><br>
<i>2.4.5 <a href="#nxtksetposition"><code>nxtk_setposition()</code></a></i><br>
<i>2.4.6 <a href="#nxtksetsize"><code>nxtk_setsize()</code></a></i><br>
<i>2.4.7 <a href="#nxtkraise"><code>nxtk_raise()</code></a></i><br>
<i>2.4.8 <a href="#nxtklower"><code>nxtk_lower()</code></a></i><br>
<i>2.4.9 <a href="#nxtkfillwindow"><code>nxtk_fillwindow()</code></a></i><br>
<i>2.4.10 <a href="#nxtkgetwindow"><code>nxtk_getwindow()</code></a></i><br>
<i>2.4.11 <a href="#nxtkfilltrapwindow"><code>nxtk_filltrapwindow()</code></a></i><br>
<i>2.4.12 <a href="#nxtkdrawlinewindow"><code>nxtk_drawlinewindow()</code></a></i><br>
<i>2.4.13 <a href="#nxtkdrawcirclewindow"><code>nxtk_drawcirclewindow()</code></a></i><br>
<i>2.4.14 <a href="#nxtkfillcirclewindow"><code>nxtk_fillcirclewindow()</code></a></i><br>
<i>2.4.15 <a href="#nxtkmovewindow"><code>nxtk_movewindow()</code></a></i><br>
<i>2.4.16 <a href="#nxtkbitmapwindow"><code>nxtk_bitmapwindow()</code></a></i><br>
<i>2.4.17 <a href="#nxtkopentoolbar"><code>nxtk_opentoolbar()</code></a></i><br>
<i>2.4.18 <a href="#nxtkclosetoolbar"><code>nxtk_closetoolbar()</code></a></i><br>
<i>2.4.19 <a href="#nxtkfilltoolbar"><code>nxtk_filltoolbar()</code></a></i><br>
<i>2.4.20 <a href="#nxtkgettoolbar"><code>nxtk_gettoolbar()</code></a></i><br>
<i>2.4.21 <a href="#nxtkfilltraptoolbar"><code>nxtk_filltraptoolbar()</code></a></i><br>
<i>2.4.22 <a href="#nxtkdrawlinetoolbar"><code>nxtk_drawlinetoolbar()</code></a></i><br>
<i>2.4.23 <a href="#nxtkdrawcircletoolbar"><code>nxtk_drawcircletoolbar()</code></a></i><br>
<i>2.4.24 <a href="#nxtkfillcircletoolbar"><code>nxtk_fillcircletoolbar()</code></a></i><br>
<i>2.4.25 <a href="#nxtkmovetoolbar"><code>nxtk_movetoolbar()</code></a></i><br>
<i>2.4.26 <a href="#nxtkbitmaptoolbar"><code>nxtk_bitmaptoolbar()</code></a></i>
</ul>
</p>
<p>
<i><b>2.5</b> <a href="#nxfonts2">NX Fonts Support (<code>NXFONTS</code>)</a></i>
</p>
<p>
<ul>
<i>2.5.1 <a href="#nxfontstypes"><code>NXFONTS Types()</code></a></i><br>
<i>2.5.2 <a href="#nxfgetfonthandle"><code>nxf_getfonthandle()</code></a></i><br>
<i>2.5.3 <a href="#nxfgetfontset"><code>nxf_getfontset()</code></a></i><br>
<i>2.5.4 <a href="#nxfgetbitmap"><code>nxf_getbitmap()</code></a></i><br>
<i>2.5.5 <a href="#nxfconvertbpp"><code>nxf_convert_*bpp()</code></a></i>
</ul>
</p>
<p>
<i><b>2.6</b> <a href="#samplecode">Sample Code</a></i>
</p>
</ul>
<p>
<big><b>Appendix A</b> <a href="#grapicsdirs"><code>graphics/</code> Directory Structure</a></big><br>
<big><b>Appendix B</b> <a href="#nxconfigs">NX Configuration Options</a></big>
</p>
<p>
<ul>
<i><b>B.1</b> <a href="#nxgenconfig">General Configuration Settings</a></i><br>
<i><b>B.2</b> <a href="#nxglconfig">NXGL Configuration Settings</a></i><br>
<i><b>B.3</b> <a href="#nxconfig">NX Configuration Settings</a></i><br>
<i><b>B.4</b> <a href="#nxmuconfig">NX Multi-User (Only) Configuration Settings</a></i><br>
<i><b>B.5</b> <a href="#nxtkconfig">NXTK Configuration Settings</a></i><br>
<i><b>B.6</b> <a href="#nxfpmtsconfig">NXFONTS Configuration Settings</a></i><br>
<i><b>B.7</b> <a href="#nxconsoleconfig">NxConsole Configuration Settings</a></i>
</ul>
</p>
<p>
<big><b>Appendix C</b> <a href="#installnewfonts">Installing New Fonts</a></big>
</p>
<p>
<big><b>Appendix D</b> <a href="#testcoverage">NX Test Coverage</a></big>
</p>
<ul>
<i><b>Table D.1:</b> <a href="#nxglibcoverage">NXGLIB API Test Coverage</a></i><br>
<i><b>Table D.2:</b> <a href="#nxcbcoverage">NX Server Callbacks Test Coverage</a></i><br>
<i><b>Table D.3:</b> <a href="#nxcoverage">NX API Test Coverage</a></i><br>
<i><b>Table D.4:</b> <a href="#nxtkcoverage">NXTK API Test Coverage</a></i><br>
<i><b>Table D.5:</b> <a href="#nxfontscoverage">NXFONTS API Test Coverage</a></i><br>
</ul>
</td>
</tr>
</table>
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<h1>1.0 <a name="Introduction">Introduction</a></h1>
</td>
</tr>
</table>
<h2>1.1 <a name="Overview">Overview</a></h2>
<p>
This document describes the tiny graphics support included in NuttX.
It includes an overview description of that graphics support, detailed
descriptions of the NuttX graphics APIs, and discussion of code organization,
and OS configuration options.
</p>
<center><table width="480">
<tr>
<td><a name="screenshot"><img src="NuttXScreenShot.jpg"></a></td>
</tr>
<tr>
<td><small>Figure 1.
This scren shot shows the final frame for the NuttX example at <code>apps/examples/nx</code>
running on the simulated, Linux x86 platform with simulated framebuffer output to
an X window.
This picture shows to framed windows with (blank) toolbars.
Each window has displayed text as received from the NX keyboard interface
The second window has just been raised to the top of the display.
</small>
</tr>
</table></center>
<h2>1.2 <a name="Objectives">Objectives</a></h2>
<p>
The objective of this development was to provide a tiny windowing system in the
spirit of X, but greatly scaled down and appropriate for most resource-limited
embedded environments.
The current NX implementation supports the general following, high-level features:
</p>
<ul>
<li><b>Virtual Vertical Graphics Space</b>.
Windows that reside in a virtual, <i>vertical</i> space so that it makes
sense to talk about one window being on top of another and obscuring the
window below it.
</li>
<li><b>Client/Server Model</b>.
A standard client server/model was adopted. NX may be considered a server
and other logic that presents the windows are NX clients.
</li>
<li><b>Single- and Multi-User Support</b>.
NX includes <i>front-end</i> logic to either a simple single-thread/single-user
architecture or a separate NX server thread that can serve multiple NX client threads.
In the single-user case, the NX <i>server</i> is simply a set of library
calls; in the multi-user case, NX is a server thread/daemon the serializes
graphics operations from multiple clients.
Other some unique start-up/connection logic, the APIs supported by the single-user
and multi-user front-ends are identical.
Providing both front-ends is consistent with the NuttX commitment to scalability.
</li>
<li><b>Minimal Graphics Toolset</b>.
The actual implementation of the graphics operations is performed by common,
<i>back-end</i> logic. This back-end supports only a primitive set of graphic
and rendering operations.
</li>
<li><b>Device Interface</b>.
NX supports any graphics device either of two device interfaces:
<ul>
<li>
Any device with random accesss video memory using the NuttX framebuffer driver interface
(see <code>include/nuttx/video/fb.h</code>).
</li>
<li>
Any LCD-like device than can accept raster line <i>runs</i> through a parallel or serial interface
(see <code>include/nuttx/lcd/lcd.h</code>).
By default, NX is configured to use the frame buffer driver unless <code>CONFIG_NX_LCDDRIVER</code> is defined =y in your NuttX configuration file.
</li>
</ul>
</li>
<li><b>Transparent to NX Client</b>.
The window client on "sees" the sub-window that is operates in
and does not need to be concerned with the virtual, vertical space (other
that to respond to <i>redraw</i> requests from NX when needed).
</li>
<li><b>Framed Windows and Toolbars</b>.
NX also adds the capability to support windows with frames and toolbars on
top of the basic windowing support.
These are windows such as those shown in the
<a href="#screenshot">screenshot</a> above.
These framed windows sub-divide one one window into three relatively independent
subwindows: A frame, the contained window and an (optional) toolbar window.
</li>
<li><b>Mouse Support</b>.
NX provides support for a mouse or other X/Y pointing devices.
APIs are provided to allow external devices to give X/Y position information
and mouse button presses to NX.
NX will then provide the mouse input to the relevant window clients via callbacks.
Client windows only receive the mouse input callback if the mouse is positioned over a visible
portion of the client window; X/Y position is provided to the client in the relative
coordinate system of the client window.
</li>
<li><b>Keyboard input</b>.
NX also supports keyboard/keypad devices.
APIs are provided to allow external devices to give keypad information to NX.
NX will then provide the mouse input to the top window on the display (the window
that has the <i>focus</i>) via a callback function.
</li>
</ul>
<h2>1.3 <a name="Organization">Organization</a></h2>
<p>
NX is organized into 6 (and perhaps someday 7 or 8) logical modules.
These logical modules also correspond to the directory organization.
That NuttX directory organization is discussed in
<a href="#grapicsdirs">Appendix B</a> of this document.
The logic modules are discussed in the following sub-paragraphs.
</p>
<p>
<center><img src="NXOrganization.gif" width="60%"></center>
</p>
<h3>1.3.1 <a name="nxgl1">NX Graphics Library (<code>NXGL</code>)</a></h3>
<p>
NXGLIB is a standalone library that contains low-level graphics utilities and
direct framebuffer or LCD rendering logic. NX is built on top NXGLIB.
</p>
<h3>1.3.2 <a name="nx1">NX (<code>NXSU</code> and <code>NXMU</code>)</a></h3>
<p>
NX is the tiny NuttX windowing system for raw windows (i.e., simple regions of
graphics memory).
NX includes both a small-footprint, single user implementaton (NXSU) and a somewhat
larger multi-user implentation (NXMU as described below).
Both conform to the same APIs as defined in <code>include/nuttx/nx/nx.h</code> and, hence,
are interchangable<sup>1</sup>.
NX can be used without NxWidgets and without NXTOOLKIT for raw window displays.
</p>
<p>
<sup>1</sup><small>NXMU and NXSU are interchangeable other than (1) certain start-up
and initialization APIs (as described below), and (2) timing. With NXSU, NX APIs
execute immediately; with NXMU, NX APIs defer and serialize the operations and, hence,
introduce different timing and potential race conditions that you would not experience
with NXSU.</small>
</p>
<p><b>NXNULL?</b>
At one time, I also envisioned a <i>NULL</i> front-end that did not support windowing
at all but, rather, simply provided the entire framebuffer or LCD memory as one dumb window.
This has the advantage that the same NX APIs can be used on the one dumb window as
for the other NX windows.
This would be in the NuttX spirit of scalability.
</p>
<p>
However, the same end result can be obtained by using the
<a href="#nxrequestbkgd"><code>nx_requestbkgd()</code></a> API.
It still may be possible to reduce the footprint in this usage case by developing
and even thinner NXNULL front-end.
That is a possible future development.
</p>
<h3>1.3.3 <a name="nxtk1">NX Tool Kit (<code>NXTK</code>)</a></h3>
<p>
NXTK is a s set of C graphics tools that provide higher-level window drawing
operations.
This is the module where the framed windows and toolbar logic is implemented.
NXTK is built on top of NX and does not depend on NxWidgets.
</p>
<h3>1.3.4 <a name="nxfonts1">NX Fonts Support (<code>NXFONTS</code>)</a></h3>
<p>
A set of C graphics tools for present (bitmap) font images.
The font implementation is at a very low level or graphics operation,
comparable to the logic in NXGLIB.
NXFONTS does not depend on any NX module other than some utilities and types from NXGLIB.
</p>
<h3>1.3.5 <a name="nxwidgets1">NX Widgets (<code>NxWidgets</code>)</a></h3>
<p>
<a href="NxWidgets.html">NxWidgets</a> is a higher level, C++, object-oriented library for object-oriented access to graphical "widgets."
NxWidgets is provided as a separate package.
NxWidgets is built on top of the core NuttX graphics subsystem, but is not a part of the core graphics subystems.
</p>
<h3>1.3.6 <a name="nxconsole1">NX Console Driver (<code>NxConsole</code>)</a></h3>
<p>
NxConsole is a write-only character device (not shown) that is built on top of an NX window.
This character device can be used to provide <code>stdout</code> and <code>stderr</code> and, hence, can provide the output side of NuttX console.
NxConsole is only available when the multi-user NX implementation is selected (<code>CONFIG_NX_MULTIUSER</code>).
</p>
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<h1>2.0 <a name="nxapis">NX User APIs</a></h1>
</td>
</tr>
</table>
<h2>2.1 <a name="nxheaders">NX Header Files</a></h2>
<ul><dl>
<dt><code>include/nuttx/nx/nxglib.h</code>
<dd>Describes the NXGLIB C interfaces
<dt><code>include/nuttx/nx/nx.h</code>
<dd>Describes the NX C interfaces
<dt><code>include/nutt/nxtk.h</code>
<dd>Describe the NXTOOLKIT C interfaces
<dt><code>include/nutt/nxfont.h</code>
<dd>Describe sthe NXFONT C interfaces
</dl></ul>
<h2>2.2 <a name="nxgl2">NX Graphics Library (<code>NXGL</code>)</a></h2>
<p>
NXGL provides many APIs, some available for use internally by NX and
others for use by applications as well.
Only those APIs intended for application usage are documented here
See <code>include/nuttx/nx/nxglib.h</code> for the full set of APIs;
those APIs might be of interest if you are rendering directly into
framebuffer or LCD memory.
</p>
<h3>2.2.1 <a name="nxgltypes">NXGL Types</a></h3>
<p>
<code>nxgl_mxpixel_t</code>.
Holds one device pixel.
NXGLIB will select the smallest size for the <code>nxgl_mxpixel_t</code>
that just contains the pixel: <code>byte</code> if 16, 24, and 32 resolution
support is disabled, <code>uint16_t</code> if 24, and 32 resolution
support is disabled, or <code>uint32_t</code>.
</p>
<p>
<code>nxgl_coord_t</code>.
A given coordinate is limited to the screen height an width. If either
of those values exceed 32,767 pixels, then the following will have to need
to change:
</p>
<ul><pre>
typedef int16_t nxgl_coord_t;
</pre></ul>
<p>
<code>struct nxgl_point_s</code>. Describes a point on the display:
</p>
<ul><pre>
struct nxgl_point_s
{
nxgl_coord_t x; /* X position, range: 0 to screen width - 1 */
nxgl_coord_t y; /* Y position, range: 0 to screen height - 1 */
};
</pre></ul>
<p>
<code>struct nxgl_size_s</code>. Describes the size of a rectangular region.
</p>
<ul><pre>
struct nxgl_size_s
{
nxgl_coord_t w; /* Width in pixels */
nxgl_coord_t h; /* Height in rows */
};
</pre></ul>
<p>
<code>struct nxgl_rect_s</code>. Describes a positioned rectangle on the display.
</p>
<ul><pre>
struct nxgl_rect_s
{
struct nxgl_point_s pt1; /* Upper, left-hand corner */
struct nxgl_point_s pt2; /* Lower, right-hand corner */
};
</pre></ul>
<p>
<code>struct nxgl_run_s</code>.
Describes a run, i.e., a horizontal line. Note that the start/end positions
have fractional precision. This is necessary for good joining of trapezoids
when a more complex shape is decomposed into trapezoids
</p>
<ul><pre>
struct nxgl_run_s
{
b16_t x1; /* Left X position, range: 0 to x2 */
b16_t x2; /* Right X position, range: x1 to screen width - 1 */
nxgl_coord_t y; /* Top Y position, range: 0 to screen height - 1 */
};
</pre></ul>
<p>
<code>struct nxgl_trapezoid_s</code>.
Describes a horizontal trapezoid on the display in terms the run at the
top of the trapezoid and the run at the bottom
</p>
<ul><pre>
struct nxgl_trapezoid_s
{
struct nxgl_run_s top; /* Top run */
struct nxgl_run_s bot; /* bottom run */
};
</pre></ul>
<h3>2.2.1 <a name="nxglrgb2yuv"><code>nxgl_rgb2yuv()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_rgb2yuv(uint8_t r, uint8_t g, uint8_t b, uint8_t *y, uint8_t *u, uint8_t *v);
</pre></ul>
<p>
<b>Description:</b>
Convert 8-bit RGB triplet to 8-bit YUV triplet.
</p>
<h3>2.2.2 <a name="nxglyuv2rgb"><code>nxgl_yuv2rgb()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_yuv2rgb(uint8_t y, uint8_t u, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b);
</pre></ul>
<p>
<b>Description:</b>
Convert 8-bit RGB triplet to 8-bit YUV triplet.
</p>
<h3>2.2.3 <a name="nxglrectcopy"><code>nxgl_rectcopy()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_rectcopy(FAR struct nxgl_rect_s *dest,
FAR const struct nxgl_rect_s *src);
</pre></ul>
<p>
<b>Description:</b>
This is essentially <code>memcpy()</code>for rectangles. We don't do structure
assignments because some compilers are not good at that.
</p>
<h3>2.2.4 <a name="nxglrectoffset"><code>nxgl_rectoffset()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_rectoffset(FAR struct nxgl_rect_s *dest,
FAR const struct nxgl_rect_s *src,
nxgl_coord_t dx, nxgl_coord_t dy);
</pre></ul>
<p>
<b>Description:</b>
Offset the rectangle position by the specified dx, dy values.
</p>
<h3>2.2.5 <a name="nxglvectoradd"><code>nxgl_vectoradd()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_vectoradd(FAR struct nxgl_point_s *dest,
FAR const struct nxgl_point_s *v1,
FAR const struct nxgl_point_s *v2);
</pre></ul>
<p>
<b>Description:</b>
Add two 2x1 vectors and save the result to a third.
</p>
<h3>2.2.6 <a name="nxglvectorsubtract"><code>nxgl_vectorsubtract()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_vectsubtract(FAR struct nxgl_point_s *dest,
FAR const struct nxgl_point_s *v1,
FAR const struct nxgl_point_s *v2);
</pre></ul>
<p>
<b>Description:</b>
Add subtract vector <code>v2</code> from vector <code>v1</code> and return the result in vector dest.
</p>
<h3>2.2.7 <a name="nxglrectintersect"><code>nxgl_rectintersect()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_rectintersect(FAR struct nxgl_rect_s *dest,
FAR const struct nxgl_rect_s *src1,
FAR const struct nxgl_rect_s *src2);
</pre></ul>
<p>
<b>Description:</b>
Return the rectangle representing the intersection of the two rectangles.
</p>
<h3>2.2.8 <a name="nxglrectunion"><code>nxgl_rectunion()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_rectunion(FAR struct nxgl_rect_s *dest,
FAR const struct nxgl_rect_s *src1,
FAR const struct nxgl_rect_s *src2);
</pre></ul>
<p>
<b>Description:</b>
Given two rectanges, <code>src1</code> and <code>src2</code>, return the larger rectangle that
contains both, <code>dest</code>.
</p>
<h3>2.2.9 <a name="nxglnonintersecting"><code>nxgl_nonintersecting()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
nxgl_nonintersecting(FAR struct nxgl_rect_s result[4],
FAR const struct nxgl_rect_s *rect1,
FAR const struct nxgl_rect_s *rect2);
</pre></ul>
<p>
<b>Description:</b>
Return the regions of rectangle <code>rect1</code> that do not intersect with
<code>rect2</code>. This will four rectangles, some of which may be
degenerate (and can be picked off with <a href="#nxglnullrect"><code>nxgl_nullrect()</code></a>).
</p>
<h3>2.2.10 <a name="nxglrectoverlap"><code>nxgl_rectoverlap()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
bool nxgl_rectoverlap(FAR struct nxgl_rect_s *rect1,
FAR struct nxgl_rect_s *rect2);
</pre></ul>
<p>
<b>Description:</b>
Return true if the two rectangles overlap.
</p>
<h3>2.2.11 <a name="nxglrectinside"><code>nxgl_rectinside()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
bool nxgl_rectinside(FAR const struct nxgl_rect_s *rect,
FAR const struct nxgl_point_s *pt);
</pre></ul>
<p>
<b>Description:</b>
Return true if the point <code>pt</code> lies within <code>rect</code>.
</p>
<h3>2.2.12 <a name="nxglrectsize"><code>nxgl_rectsize()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_rectsize(FAR struct nxgl_size_s *size,
FAR const struct nxgl_rect_s *rect);
</pre></ul>
<p>
<b>Description:</b>
Return the size of the specified rectangle.
</p>
<h3>2.2.13 <a name="nxglnullrect"><code>nxgl_nullrect()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
bool nxgl_nullrect(FAR const struct nxgl_rect_s *rect);
</pre></ul>
<p>
<b>Description:</b>
Return true if the area of the retangle is <= 0.
</p>
<h3>2.2.14 <a name="nxglrunoffset"><code>nxgl_runoffset()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_runoffset(FAR struct nxgl_run_s *dest,
FAR const struct nxgl_run_s *src,
nxgl_coord_t dx, nxgl_coord_t dy);
</pre></ul>
<p>
<b>Description:</b>
Offset the run position by the specified <code>dx</code>, <code>dy</code> values.
</p>
<h3>2.2.15 <a name="nxglruncopy"><code>nxgl_runcopy()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_runcopy(FAR struct nxgl_run_s *dest,
FAR const struct nxgl_run_s *src);
</pre></ul>
<p>
<b>Description:</b>
This is essentially <code>memcpy()</code>for runs. We don't do structure assignments
because some compilers are not good at that.
</p>
<h3>2.2.16 <a name="nxgltrapoffset"><code>nxgl_trapoffset()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_trapoffset(FAR struct nxgl_trapezoid_s *dest,
FAR const struct nxgl_trapezoid_s *src,
nxgl_coord_t dx, nxgl_coord_t dy);
</pre></ul>
<p>
<b>Description:</b>
Offset the trapezoid position by the specified <code>dx</code>, <code>dy</code> values.
</p>
<h3>2.2.17 <a name="nxgltrapcopy"><code>nxgl_trapcopy()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_trapcopy(FAR struct nxgl_trapezoid_s *dest,
FAR const struct nxgl_trapezoid_s *src);
</pre></ul>
<p>
<b>Description:</b>
This is essentially <code>memcpy()</code>for trapezoids. We don't do structure
assignments because some compilers are not good at that.
</p>
<h3>2.2.18 <a name="nxglcolorcopy"><code>nxgl_colorcopy</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
nxgl_colorcopy(nxgl_mxpixel_t dest[CONFIG_NX_NPLANES],
const nxgl_mxpixel_t src[CONFIG_NX_NPLANES]);
</pre></ul>
<p>
<b>Description:</b>
This is essentially <code>memcpy()</code>for colors. This does very little for us
other than hide all of the conditional compilation for planar colors
in one place.
</p>
<h3>2.2.19 <a name="nxglsplitline"><code>nxgl_splitline</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include <nuttx/nx/nxglib.h>
int nxgl_splitline(FAR struct nxgl_vector_s *vector, FAR struct nxgl_trapezoid_s *traps,
FAR struct nxgl_rect_s *rect, nxgl_coord_t linewidth);
</pre></ul>
<p>
<b>Description:</b>
In the general case, a line with width can be represented as a parallelogram with a triangle at the top and bottom.
Triangles and parallelograms are both degenerate versions of a trapezoid.
This function breaks a wide line into triangles and trapezoids.
This function also detects other degenerate cases:
</p>
<ol>
<li>
If <code>y1 == y2</code> then the line is horizontal and is better represented as a rectangle.
</li>
<li>
If <code>x1 == x2</code> then the line is vertical and also better represented as a rectangle.
</li>
<li>
If the width of the line is 1, then there are no triangles at the top and bottom
(this may also be the case if the width is narrow and the line is near vertical).
</li>
<li>
If the line is oriented is certain angles, it may consist only of the upper and lower triangles with no trapezoid in between.
In this case, 3 trapezoids will be returned, but traps[1] will be degenerate.
</li>
</ol>
<p>
<b>Input parameters</b>:
<p>
<ul><dl>
<dt><code>vector</code>
<dd>A pointer to the vector described the line to be drawn.
<dt><code>traps</code>
<dd>A pointer to a array of trapezoids (size 3).
<dt><code>rect</code>
<dd> A pointer to a rectangle.
</dl></ul>
<p>
<b>Returned value</b>:
</p>
<ul>
<p>
<code>0</code>: Line successfully broken up into three trapezoids.
Values in <code>traps[0]</code>, <code>traps[1]</code>, and <code>traps[2]</code> are valid.
</p>
<p>
<code>1</code>: Line successfully represented by one trapezoid.
Value in <code>traps[1]</code> is valid.
</p>
<p>
<code>2</code>: Line successfully represented by one rectangle.
Value in <code>rect </code>is valid
</p>
<p>
<code><0</code>: On errors, a negated <code>errno</code> value is returned.
</p>
<p>
</ul>
<h3>2.2.20 <a name="nxglcirclepts"><code>nxgl_circlepts</code></a></h3>
<ul><pre>
#include <nuttx/nx/nxglib.h>
void nxgl_circlepts(FAR const struct nxgl_point_s *center, nxgl_coord_t radius,
FAR struct nxgl_point_s *circle);
</pre></ul>
<p>
<b>Description:</b>
Given a description of a circle, return a set of 16 points on the circumference of the circle.
These points may then be used by <a href="nxdrawcircle"><code>nx_drawcircle()</code></a> or related APIs to draw a circle outline.
</p>
<p>
<b>Input parameters</b>:
<p>
<ul><dl>
<dt><code>center</code>
<dd>A pointer to the point that is the center of the circle.
<dt><code>radius</code>
<dd>The radius of the circle in pixels.
<dt><code>circle</code>
<dd>A pointer the first entry in an array of 16 points where the circle points will be returned.
</dl></ul>
<p>
<b>Returned value</b>: None
</p>
<h3>2.2.21 <a name="nxglcircletraps"><code>nxgl_circletraps</code></a></h3>
<ul><pre>
#include <nuttx/nx/nxglib.h>
oid nxgl_circletraps(FAR const struct nxgl_point_s *center, nxgl_coord_t radius,
FAR struct nxgl_trapezoid_s *circle);
</pre></ul>
<p>
<b>Description:</b>
Given a description of a a circle, return 8 trapezoids that can be used to fill the circle by <a href="nxfillcircle"><code>nx_fillcircle()</code></a> and other interfaces.
</p>
<p>
<b>Input parameters</b>:
<p>
<ul><dl>
<dt><code>center</code>
<dd>A pointer to the point that is the center of the circle.
<dt><code>radius</code>
<dd>The radius of the circle in pixels.
<dt><code>circle</code>
<dd>A pointer the first entry in an array of 8 trapezoids where the circle description will be returned.
</dl></ul>
<p>
<b>Returned value</b>: None
</p>
<h2>2.3 <a name="nx2">NX</a></h2>
<h3>2.3.1 <a name="nxppdefs">Pre-Processor Definitions</a></h3>
<p>
The default server message queue name used by the
<a href="#nxruninstance"><code>nx_run()</code></a> macro:
</p>
<ul><pre>
#define NX_DEFAULT_SERVER_MQNAME "/dev/nxs"
</pre></ul>
<p>
Mouse button bits:
</p>
<ul><pre>
#define NX_MOUSE_NOBUTTONS 0x00
#define NX_MOUSE_LEFTBUTTON 0x01
#define NX_MOUSE_CENTERBUTTON 0x02
#define NX_MOUSE_RIGHTBUTTON 0x04
</pre></ul>
<h3>2.3.2 <a name="nxtypes">NX Types</a></h3>
<p>
The interface to the NX server is managed using a opaque handle:
</p>
<ul><pre>
typedef FAR void *NXHANDLE;
</pre></ul>
<p>
The interface to a specific window is managed using an opaque handle:
</p>
<ul><pre>
typedef FAR void *NXWINDOW;
</pre></ul>
<p>
These define callbacks that must be provided to
<a href="#nxopenwindow"><code>nx_openwindow()</code></a>.
In the multi-user model, these callbacks will be invoked as part of the
processing performed by
<a href="#nxeventhandler"><code>nx_eventhandler()</code></a>.
</p>
<ul><pre>
struct nx_callback_s
{
void (*redraw)(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
bool more, FAR void *arg);
void (*position)(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds,
FAR void *arg);
#ifdef CONFIG_NX_MOUSE
void (*mousein)(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
uint8_t buttons, FAR void *arg);
#endif
#ifdef CONFIG_NX_KBD
void (*kbdin)(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch, FAR void *arg);
#endif
};
</pre></ul>
<h3>2.3.3 <a name="nxtypes">NX Server Callbacks</a></h3>
<h4>2.3.3.1 <a name="nxcbredraw"><code>redraw()</code></a></h4>
<p><b>Callback Function Prototype:</b></p>
<ul><pre>
void redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
bool more, FAR void *arg);
</pre></ul>
<p>
<b>Description:</b>
NX requests that the client re-draw the portion of the window within
with rectangle.
</p>
<p>
<b>Input Parameters:</b>
<ul><dl>
<dt><code>hwnd</code>
<dd>The handle created by <a href="#nxopenwindow"><code>nx_openwindow()</code></a>
or <a href="#nxrequestbkgd"><code>nx_requestbkgd()</code></a>
<dt><code>rect</code>
<dd>The rectangle that needs to be re-drawn (in window relative coordinates)
<dt><code>more</code>
<dd>true: More re-draw requests will follow
<dt><code>arg</code>
<dd>User provided argument (see <a href="#nxopenwindow"><code>nx_openwindow()</code></a>)
</dl></ul>
</p>
<p>
<b>Returned Value:</b> None
</p>
<h4>2.3.3.2 <a name="nxcbposition"><code>position()</code></a></h4>
<p><b>Callback Function Prototype:</b></p>
<ul><pre>
void position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds,
FAR void *arg);
</pre></ul>
<p>
<b>Description:</b>
The size or position of the window has changed (or the window was
just created with zero size.
</p>
<p>
<b>Input Parameters:</b>
<ul><dl>
<dt><code>hwnd</code>
<dd>The handle created by <a href="#nxopenwindow"><code>nx_openwindow()</code></a>
or <a href="#nxrequestbkgd"><code>nx_requestbkgd()</code></a>
<dt><code>size</code>
<dd>The size of the window
<dt><code>pos</code>
<dd>The position of the upper left hand corner of the window on
the overall display
<dt><code>bounds</code>
<dd>The bounding rectangle that the describes the entire display
<dt><code>arg</code>
<dd>User provided argument (see <a href="#nxopenwindow"><code>nx_openwindow()</code></a>)
</dl></ul>
</p>
<p>
<b>Returned Value:</b> None
</p>