This repository has been archived by the owner on Jan 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
westeros-compositor.cpp
10170 lines (8704 loc) · 298 KB
/
westeros-compositor.cpp
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
/*
* If not stated otherwise in this file or this component's Licenses.txt file the
* following copyright and licenses apply:
*
* Copyright 2016 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "westeros-compositor.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <memory.h>
#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <dirent.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <unistd.h>
#include <map>
#include <vector>
#include <xkbcommon/xkbcommon.h>
#if defined (WESTEROS_HAVE_WAYLAND_EGL)
#include <EGL/egl.h>
#include <EGL/eglext.h>
#if defined (USE_MESA)
#include <EGL/eglmesaext.h>
#endif
#if defined (WESTEROS_PLATFORM_RPI)
#include <bcm_host.h>
#endif
#include "wayland-egl.h"
#endif
#include "wayland-server.h"
#include "westeros-nested.h"
#ifdef ENABLE_SBPROTOCOL
#include "westeros-simplebuffer.h"
#endif
#ifdef ENABLE_LDBPROTOCOL
#include "linux-dmabuf/westeros-linux-dmabuf.h"
#endif
#include "westeros-simpleshell.h"
#include "xdg-shell-server-protocol.h"
#include "vpc-client-protocol.h"
#include "vpc-server-protocol.h"
#include "westeros-version.h"
#if defined ( USE_XDG_STABLE )
// It's neither defined nor used for 'stable' version
// but minimizes the number of if/defs.
#define XDG_SURFACE_STATE_FULLSCREEN 2
#endif
#define WST_MAX_ERROR_DETAIL (512)
#define MAX_NESTED_NAME_LEN (32)
#define DEFAULT_FRAME_RATE (60)
#define DEFAULT_OUTPUT_WIDTH (1280)
#define DEFAULT_OUTPUT_HEIGHT (720)
#define DEFAULT_NESTED_WIDTH (1280)
#define DEFAULT_NESTED_HEIGHT (720)
#define DEFAULT_KEY_REPEAT_DELAY (1000)
#define DEFAULT_KEY_REPEAT_RATE (5)
#if !defined (XKB_KEYMAP_COMPILE_NO_FLAGS)
#define XKB_KEYMAP_COMPILE_NO_FLAGS XKB_MAP_COMPILE_NO_FLAGS
#endif
#define WESTEROS_UNUSED(x) ((void)(x))
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#define INT_FATAL(FORMAT, ...) wstLog(0, "Westeros Fatal: " FORMAT "\n", __VA_ARGS__)
#define INT_ERROR(FORMAT, ...) wstLog(0, "Westeros Error: " FORMAT "\n", __VA_ARGS__)
#define INT_WARNING(FORMAT, ...) wstLog(1, "Westeros Warning: " FORMAT "\n", __VA_ARGS__)
#define INT_INFO(FORMAT, ...) wstLog(2, "Westeros Info: " FORMAT "\n", __VA_ARGS__)
#define INT_DEBUG(FORMAT, ...) wstLog(3, "Westeros Debug: " FORMAT "\n", __VA_ARGS__)
#define INT_TRACE1(FORMAT, ...) wstLog(4, "Westeros Trace: " FORMAT "\n", __VA_ARGS__)
#define INT_TRACE2(FORMAT, ...) wstLog(5, "Westeros Trace: " FORMAT "\n", __VA_ARGS__)
#define INT_TRACE3(FORMAT, ...) wstLog(6, "Westeros Trace: " FORMAT "\n", __VA_ARGS__)
#define FATAL(...) INT_FATAL(__VA_ARGS__, "")
#define ERROR(...) INT_ERROR(__VA_ARGS__, "")
#define WARNING(...) INT_WARNING(__VA_ARGS__, "")
#define INFO(...) INT_INFO(__VA_ARGS__, "")
#define DEBUG(...) INT_DEBUG(__VA_ARGS__, "")
#define TRACE1(...) INT_TRACE1(__VA_ARGS__, "")
#define TRACE2(...) INT_TRACE2(__VA_ARGS__, "")
#define TRACE3(...) INT_TRACE3(__VA_ARGS__, "")
#define WST_EVENT_QUEUE_SIZE (64)
#define VPCBRIDGE_SIGNAL (INT_MIN)
typedef void* (*PFNGETDEVICEBUFFERFROMRESOURCE)( struct wl_resource *resource );
typedef bool (*PFNREMOTEBEGIN)( struct wl_display *dspsrc, struct wl_display *dspdst );
typedef void (*PFNREMOTEEND)( struct wl_display *dspsrc, struct wl_display *dspdst );
typedef struct wl_buffer* (*PFNREMOTECLONEBUFFERFROMRESOURCE)( struct wl_display *dspsrc,
struct wl_resource *resource,
struct wl_display *dspdst,
int *width,
int *height );
typedef enum _WstEventType
{
WstEventType_key,
WstEventType_keyCode,
WstEventType_keyModifiers,
WstEventType_pointerEnter,
WstEventType_pointerLeave,
WstEventType_pointerMove,
WstEventType_pointerButton,
WstEventType_touchDown,
WstEventType_touchUp,
WstEventType_touchMotion,
WstEventType_touchFrame,
WstEventType_resolutionChangeBegin,
WstEventType_resolutionChangeEnd
} WstEventType;
typedef enum
{
WstPipeDescriptor_ParentRead = 0,
WstPipeDescriptor_ChildWrite = 1
} WstPipeDescriptor;
typedef struct _WstEvent
{
WstEventType type;
void *p1;
unsigned int v1;
unsigned int v2;
unsigned int v3;
unsigned int v4;
} WstEvent;
typedef struct _WstContext WstContext;
typedef struct _WstSurface WstSurface;
typedef struct _WstSeat WstSeat;
typedef struct _WstShellSurface
{
struct wl_resource *resource;
WstSurface *surface;
const char* title;
const char* className;
} WstShellSurface;
typedef struct _WstVpcSurface
{
struct wl_resource *resource;
WstSurface *surface;
WstCompositor *compositor;
struct wl_vpc_surface *vpcSurfaceNested;
bool videoPathSet;
bool useHWPath;
bool useHWPathNext;
bool pathTransitionPending;
bool sizeOverride;
int xTrans;
int yTrans;
int xScaleNum;
int xScaleDenom;
int yScaleNum;
int yScaleDenom;
int outputWidth;
int outputHeight;
int hwX;
int hwY;
int hwWidth;
int hwHeight;
bool useHWPathVpcBridge;
int xTransVpcBridge;
int yTransVpcBridge;
int xScaleNumVpcBridge;
int xScaleDenomVpcBridge;
int yScaleNumVpcBridge;
int yScaleDenomVpcBridge;
int outputWidthVpcBridge;
int outputHeightVpcBridge;
} WstVpcSurface;
typedef struct _WstKeyboard
{
WstSeat *seat;
WstCompositor *compositor;
struct wl_list resourceList;
struct wl_list focusResourceList;
struct wl_array keys;
WstSurface *focus;
uint32_t currentModifiers;
struct xkb_state *state;
xkb_mod_index_t modShift;
xkb_mod_index_t modAlt;
xkb_mod_index_t modCtrl;
xkb_mod_index_t modCaps;
xkb_mod_index_t modMeta;
} WstKeyboard;
typedef struct _WstPointer
{
WstSeat *seat;
WstCompositor *compositor;
struct wl_list resourceList;
struct wl_list focusResourceList;
bool entered;
WstSurface *focus;
WstSurface *pointerSurface;
int32_t hotSpotX;
int32_t hotSpotY;
int32_t pointerX;
int32_t pointerY;
} WstPointer;
typedef struct _WstTouch
{
WstSeat *seat;
WstCompositor *compositor;
struct wl_list resourceList;
struct wl_list focusResourceList;
WstSurface *focus;
} WstTouch;
typedef struct _WstSeat
{
WstContext *ctx;
struct wl_list resourceList;
const char *seatName;
int keyRepeatDelay;
int keyRepeatRate;
} WstSeat;
typedef struct _WstShm WstShm;
typedef struct _WstShmPool WstShmPool;
typedef struct _WstShmBuffer
{
WstShmPool *pool;
struct wl_resource *bufferResource;
struct wl_buffer *bufferNested;
int32_t width;
int32_t height;
int32_t stride;
uint32_t format;
} WstShmBuffer;
typedef struct _WstShmPool
{
WstShm *shm;
int32_t refCount;
struct wl_resource *poolResource;
struct wl_shm_pool *poolNested;
} WstShmPool;
typedef struct _WstShm
{
WstContext *ctx;
struct wl_list resourceList;
} WstShm;
typedef struct _WstRegion
{
struct wl_resource *resource;
WstCompositor *compositor;
} WstRegion;
typedef struct _WstSurfaceFrameCallback
{
struct wl_resource *resource;
struct wl_list link;
} WstSurfaceFrameCallback;
typedef struct _WstSurface
{
struct wl_resource *resource;
WstCompositor *compositor;
int surfaceId;
WstRenderer *renderer;
WstRenderSurface *surface;
std::vector<WstShellSurface*> shellSurface;
WstVpcSurface *vpcSurface;
struct wl_surface *surfaceNested;
const char *roleName;
bool visible;
int x;
int y;
int width;
int height;
float opacity;
float zorder;
bool tempVisible;
const char *name;
int refCount;
pthread_mutex_t renderMutex;
bool needsRender;
struct wl_resource *attachedBufferResource;
struct wl_resource *detachedBufferResource;
int attachedX;
int attachedY;
bool vpcBridgeSignal;
int commitCount;
struct wl_list frameCallbackList;
struct wl_listener attachedBufferDestroyListener;
struct wl_listener detachedBufferDestroyListener;
} WstSurface;
typedef struct _WstSurfaceInfo
{
WstSurface *surface;
} WstSurfaceInfo;
typedef struct _WstClientInfo
{
struct wl_resource *sbResource;
WstSurface *surface;
WstCompositor *wctx;
bool usesXdgShell;
} WstClientInfo;
typedef struct _WstOutput
{
WstContext *ctx;
struct wl_list resourceList;
int x;
int y;
int refreshRate;
int mmWidth;
int mmHeight;
int subPixel;
const char *make;
const char *model;
int transform;
int currentScale;
} WstOutput;
typedef bool (*WstModuleInit)( WstCompositor *wctx, struct wl_display* );
typedef void (*WstModuleTerm)( WstCompositor *wctx );
typedef struct _WstModule
{
const char *moduleName;
void *module;
WstModuleInit initEntryPoint;
WstModuleTerm termEntryPoint;
bool isInitialized;
} WstModule;
typedef struct _WstContext
{
const char *displayName;
unsigned int frameRate;
int framePeriodMillis;
const char *rendererModule;
bool isNested;
bool isRepeater;
bool isEmbedded;
bool mustInitRendererModule;
bool hasVpcBridge;
const char *nestedDisplayName;
unsigned int nestedWidth;
unsigned int nestedHeight;
bool allowModifyCursor;
void *nativeWindow;
std::vector<WstModule*> modules;
void *terminatedUserData;
WstTerminatedCallback terminatedCB;
bool running;
bool compositorReady;
bool compositorAborted;
bool compositorThreadStarted;
pthread_t compositorThreadId;
struct xkb_rule_names xkbNames;
struct xkb_context *xkbCtx;
struct xkb_keymap *xkbKeymap;
uint32_t xkbKeymapFormat;
int xkbKeymapSize;
int xkbKeymapFd;
char *xkbKeymapArea;
pthread_mutex_t mutex;
WstOutput *output;
WstSeat *seat;
WstRenderer *renderer;
WstShm *shm;
WstNestedConnection *nc;
struct wl_display *ncDisplay;
pthread_mutex_t ncStartedMutex;
pthread_cond_t ncStartedCond;
void *nestedListenerUserData;
WstNestedConnectionListener nestedListener;
bool hasEmbeddedMaster;
void *outputNestedListenerUserData;
WstOutputNestedListener *outputNestedListener;
void *keyboardNestedListenerUserData;
WstKeyboardNestedListener *keyboardNestedListener;
void *pointerNestedListenerUserData;
WstPointerNestedListener *pointerNestedListener;
void *touchNestedListenerUserData;
WstTouchNestedListener *touchNestedListener;
void *unboundClientUserData;
WstVirtEmbUnBoundClient unboundClientCB;
struct wl_display *display;
#ifdef ENABLE_SBPROTOCOL
struct wl_sb *sb;
#endif
#ifdef ENABLE_LDBPROTOCOL
struct wl_ldb *ldb;
#endif
struct wl_simple_shell *simpleShell;
struct wl_event_source *displayTimer;
#if defined (WESTEROS_HAVE_WAYLAND_EGL)
EGLDisplay eglDisplay;
PFNEGLBINDWAYLANDDISPLAYWL eglBindWaylandDisplayWL;
PFNEGLUNBINDWAYLANDDISPLAYWL eglUnbindWaylandDisplayWL;
PFNEGLQUERYWAYLANDBUFFERWL eglQueryWaylandBufferWL;
PFNGETDEVICEBUFFERFROMRESOURCE getDeviceBufferFromResource;
bool haveRepeaterSupport;
bool canRemoteClone;
PFNREMOTEBEGIN remoteBegin;
PFNREMOTEEND remoteEnd;
PFNREMOTECLONEBUFFERFROMRESOURCE remoteCloneBufferFromResource;
#endif
int nextSurfaceId;
std::vector<WstSurface*> surfaces;
std::vector<WstVpcSurface*> vpcSurfaces;
std::map<int32_t, WstSurface*> surfaceMap;
std::map<struct wl_client*, WstClientInfo*> clientInfoMap;
std::map<struct wl_resource*, WstSurfaceInfo*> surfaceInfoMap;
bool needRepaint;
bool allowImmediateRepaint;
bool outputSizeChanged;
struct wl_display *dcDisplay;
struct wl_registry *dcRegistry;
struct wl_shm *dcShm;
struct wl_compositor *dcCompositor;
struct wl_seat *dcSeat;
struct wl_pointer *dcPointer;
struct wl_shm_pool *dcPool;
struct wl_surface *dcCursorSurface;
struct wl_client *dcClient;
void *dcPoolData;
int dcPoolSize;
int dcPoolFd;
int dcPid;
bool dcDefaultCursor;
WstCompositor *wctx;
std::vector<WstCompositor*> virt;
} WstContext;
typedef struct _WstCompositor
{
bool isVirtual;
WstContext *ctx;
int clientPid;
bool clientCommit;
int clientCommitPid;
bool clientFirstFrame;
char lastErrorDetail[WST_MAX_ERROR_DETAIL];
void *dispatchUserData;
WstDispatchCallback dispatchCB;
void *invalidateUserData;
WstInvalidateSceneCallback invalidateCB;
void *hidePointerUserData;
WstHidePointerCallback hidePointerCB;
void *clientStatusUserData;
WstClientStatus clientStatusCB;
bool outputSizeChanged;
int outputWidth;
int outputHeight;
WstKeyboard *keyboard;
WstPointer *pointer;
WstTouch *touch;
bool destroyed;
int eventIndex;
WstEvent eventQueue[WST_EVENT_QUEUE_SIZE];
} WstCompositor;
static void wstLog( int level, const char *fmt, ... );
static const char* wstGetNextNestedDisplayName(void);
static bool wstCompositorCreateRenderer( WstContext *ctx );
static void wstCompositorReleaseResources( WstContext *ctx );
static void* wstCompositorThread( void *arg );
static long long wstGetCurrentTimeMillis(void);
static bool wstCompositorCheckForRepeaterSupport( WstContext *ctx );
static void wstCompositorDestroyVirtual( WstCompositor *wctx );
static void wstCompositorProcessEvents( WstCompositor *wctx );
static void wstContextProcessEvents( WstContext *ctx );
static void wstCompositorComposeFrame( WstContext *ctx, uint32_t frameTime );
static void wstContextInvokeDispatchCB( WstContext *ctx );
static void wstContextInvokeInvalidateCB( WstContext *ctx );
static void wstContextInvokeHidePointerCB( WstContext *ctx, bool hidePointer );
static int wstCompositorDisplayTimeOut( void *data );
static void wstCompositorScheduleRepaint( WstContext *ctx );
static void wstCompositorReleaseDetachedBuffers( WstContext *ctx );
static void wstShmBind( struct wl_client *client, void *data, uint32_t version, uint32_t id);
static bool wstShmInit( WstContext *ctx );
static void wstShmTerm( WstContext *ctx );
static void wstIShmBufferDestroy(struct wl_client *client, struct wl_resource *resource);
static void wstIShmPoolCreateBuffer( struct wl_client *client, struct wl_resource *resource,
uint32_t id, int32_t offset,
int32_t width, int32_t height,
int32_t stride, uint32_t format);
static void wstShmBufferDestroy( struct wl_resource *resource );
static void wstIShmPoolDestroy( struct wl_client *client, struct wl_resource *resource );
static void wstIShmPoolResize( struct wl_client *client, struct wl_resource *resource, int32_t size );
static void wstIShmCreatePool( struct wl_client *client, struct wl_resource *resource,
uint32_t id, int fd, int32_t size );
static void wstShmDestroyPool( struct wl_resource *resource );
static void wstShmPoolUnRef( WstShmPool *pool );
static WstCompositor *wstGetCompositorFromPid( WstContext *ctx, struct wl_client *client, int pid );
static WstCompositor* wstGetCompositorFromClient( WstContext *ctx, struct wl_client *client );
static void wstCompositorBind( struct wl_client *client, void *data, uint32_t version, uint32_t id);
static void wstDestroyCompositorCallback(struct wl_resource *resource);
static void wstICompositorCreateSurface( struct wl_client *client, struct wl_resource *resource, uint32_t id);
static void wstICompositorCreateRegion( struct wl_client *client, struct wl_resource *resource, uint32_t id);
static void wstDestroySurfaceCallback(struct wl_resource *resource);
static WstSurface* wstSurfaceCreate( WstCompositor *wctx);
static void wstSurfaceDestroy( WstSurface *surface );
static bool wstSurfaceSetRole( WstSurface *surface, const char *roleName,
struct wl_resource *errorResource, uint32_t errorCode );
static void wstSurfaceInsertSurface( WstContext *ctx, WstSurface *surface );
static WstSurface* wstGetSurfaceFromSurfaceId( WstContext *ctx, int32_t surfaceId );
static WstSurface* wstGetSurfaceFromPoint( WstCompositor *wctx, int x, int y );
static WstSurfaceInfo* wstGetSurfaceInfo( WstContext *ctx, struct wl_resource *resource );
static void wstUpdateClientInfo( WstContext *ctx, struct wl_client *client, struct wl_resource *resource );
static void wstISurfaceDestroy(struct wl_client *client, struct wl_resource *resource);
static void wstISurfaceAttach(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *bufferResource, int32_t sx, int32_t sy);
static void wstISurfaceDamage(struct wl_client *client,
struct wl_resource *resource,
int32_t x, int32_t y, int32_t width, int32_t height);
static void wstISurfaceFrame(struct wl_client *client,
struct wl_resource *resource, uint32_t callback);
static void wstISurfaceSetOpaqueRegion(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *regionResource);
static void wstISurfaceSetInputRegion(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *regionResource);
static void wstISurfaceCommit(struct wl_client *client, struct wl_resource *resource);
static void wstISurfaceSetBufferTransform(struct wl_client *client,
struct wl_resource *resource, int transform);
static void wstISurfaceSetBufferScale(struct wl_client *client,
struct wl_resource *resource,
int32_t scale);
static WstRegion *wstRegionCreate( WstCompositor *wctx );
static void wstRegionDestroy( WstRegion *region );
static void wstDestroyRegionCallback(struct wl_resource *resource);
static void wstIRegionDestroy( struct wl_client *client, struct wl_resource *resource );
static void wstIRegionAdd( struct wl_client *client,
struct wl_resource *resource,
int32_t x, int32_t y, int32_t width, int32_t height );
static void wstIRegionSubtract( struct wl_client *client,
struct wl_resource *resource,
int32_t x, int32_t y, int32_t width, int32_t height );
static bool wstOutputInit( WstContext *ctx );
static void wstOutputTerm( WstContext *ctx );
static void wstOutputBind( struct wl_client *client, void *data, uint32_t version, uint32_t id);
static void wstOutputChangeSize( WstCompositor *wctx );
static void wstShellBind( struct wl_client *client, void *data, uint32_t version, uint32_t id);
static void wstIShellGetShellSurface(struct wl_client *client,
struct wl_resource *resource,
uint32_t id,
struct wl_resource *surfaceResource );
static void wstDestroyShellSurfaceCallback(struct wl_resource *resource);
static void wstShellSurfaceDestroy( WstShellSurface *shellSurface );
static void wstIShellSurfacePong(struct wl_client *client,
struct wl_resource *resource,
uint32_t serial );
static void wstIShellSurfaceMove(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *seatResource,
uint32_t serial );
static void wstIShellSurfaceResize(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *seatResource,
uint32_t serial,
uint32_t edges );
static void wstIShellSurfaceSetTopLevel(struct wl_client *client,
struct wl_resource *resource);
static void wstIShellSurfaceSetTransient(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *parentResource,
int x, int y, uint32_t flags );
static void wstIShellSurfaceSetFullscreen(struct wl_client *client,
struct wl_resource *resource,
uint32_t method,
uint32_t framerate,
struct wl_resource *outputResource );
static void wstIShellSurfaceSetPopup(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *seatResource,
uint32_t serial,
struct wl_resource *parentResource,
int x, int y, uint32_t flags );
static void wstIShellSurfaceSetMaximized(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *outputResource );
static void wstIShellSurfaceSetTitle(struct wl_client *client,
struct wl_resource *resource,
const char *title );
static void wstIShellSurfaceSetClass(struct wl_client *client,
struct wl_resource *resource,
const char *className );
static void wstXdgShellBind( struct wl_client *client, void *data, uint32_t version, uint32_t id);
static void wstIXdgDestroy( struct wl_client *client, struct wl_resource *resource );
static void wstIXdgUseUnstableVersion( struct wl_client *client, struct wl_resource *resource, int32_t version );
static void wstIXdgGetXdgSurface( struct wl_client *client,
struct wl_resource *resource,
uint32_t id,
struct wl_resource *surfaceResource );
static void wstIXdgGetXdgPopup( struct wl_client *client,
struct wl_resource *resource,
uint32_t id,
struct wl_resource *surfaceResource,
struct wl_resource *parentResource,
struct wl_resource *seatResource,
uint32_t serial,
int32_t x,
int32_t y
#if defined ( USE_XDG_VERSION4 )
,
uint32_t flags
#endif
);
static void wstIXdgPong( struct wl_client *client,
struct wl_resource *resource,
uint32_t serial );
static void wstIXdgShellSurfaceDestroy( struct wl_client *client,
struct wl_resource *resource );
static void wstIXdgCreatePositioner( struct wl_client *client,
struct wl_resource *resource,
uint32_t id);
static void wstIXdgShellGetTopLevel( struct wl_client *client,
struct wl_resource *resource,
uint32_t id);
static void wstIXdgShellGetPopup( struct wl_client *client,
struct wl_resource *resource,
uint32_t id,
struct wl_resource *parent,
struct wl_resource *positioner);
static void wstIXdgShellAckConfigure( struct wl_client *client,
struct wl_resource *resource,
uint32_t serial);
static void wstIXdgShellSurfaceSetParent( struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *parentResource );
static void wstIXdgShellSurfaceSetTitle( struct wl_client *client,
struct wl_resource *resource,
const char *title );
static void wstIXdgShellSurfaceSetAppId( struct wl_client *client,
struct wl_resource *resource,
const char *app_id );
static void wstIXdgShellSurfaceShowWindowMenu( struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *seatResource,
uint32_t serial,
int32_t x,
int32_t y );
static void wstIXdgShellSurfaceMove( struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *seatResource,
uint32_t serial );
static void wstIXdgShellSurfaceResize( struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *seatResource,
uint32_t serial,
uint32_t edges );
static void wstIXdgShellSurfaceAckConfigure( struct wl_client *client,
struct wl_resource *resource,
uint32_t serial );
static void wstIXdgShellSurfaceSetWindowGeometry( struct wl_client *client,
struct wl_resource *resource,
int32_t x,
int32_t y,
int32_t width,
int32_t height );
static void wstIXdgShellSurfaceSetMaximized( struct wl_client *client,
struct wl_resource *resource );
static void wstIXdgShellSurfaceUnSetMaximized( struct wl_client *client,
struct wl_resource *resource );
static void wstIXdgShellSurfaceSetFullscreen( struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *outputResource );
static void wstIXdgShellSurfaceUnSetFullscreen( struct wl_client *client,
struct wl_resource *resource );
static void wstIXdgShellSurfaceSetMinimized( struct wl_client *client,
struct wl_resource *resource );
static void wstXdgSurfaceSendConfigure( WstCompositor *wctx, WstSurface *surface, uint32_t state );
static void wstDefaultNestedConnectionStarted( void *userData );
static void wstDefaultNestedConnectionEnded( void *userData );
static void wstDefaultNestedOutputHandleGeometry( void *userData, int32_t x, int32_t y, int32_t mmWidth,
int32_t mmHeight, int32_t subPixel, const char *make,
const char *model, int32_t transform );
static void wstDefaultNestedOutputHandleMode( void* userData, uint32_t flags, int32_t width,
int32_t height, int32_t refreshRate );
static void wstDefaultNestedOutputHandleDone( void *userData );
static void wstDefaultNestedOutputHandleScale( void *userData, int32_t scale );
static void wstDefaultNestedKeyboardHandleKeyMap( void *userData, uint32_t format, int fd, uint32_t size );
static void wstDefaultNestedKeyboardHandleEnter( void *userData, struct wl_array *keys );
static void wstDefaultNestedKeyboardHandleLeave( void *userData );
static void wstDefaultNestedKeyboardHandleKey( void *userData, uint32_t time, uint32_t key, uint32_t state );
static void wstDefaultNestedKeyboardHandleModifiers( void *userData, uint32_t mods_depressed, uint32_t mods_latched,
uint32_t mods_locked, uint32_t group );
static void wstDefaultNestedKeyboardHandleRepeatInfo( void *userData, int32_t rate, int32_t delay );
static void wstDefaultNestedPointerHandleEnter( void *userData, struct wl_surface *surfaceNested, wl_fixed_t sx, wl_fixed_t sy );
static void wstDefaultNestedPointerHandleLeave( void *userData, struct wl_surface *surfaceNested );
static void wstDefaultNestedPointerHandleMotion( void *userData, uint32_t time, wl_fixed_t sx, wl_fixed_t sy );
static void wstDefaultNestedPointerHandleButton( void *userData, uint32_t time, uint32_t button, uint32_t state );
static void wstDefaultNestedPointerHandleAxis( void *userData, uint32_t time, uint32_t axis, wl_fixed_t value );
static void wstDefaultNestedTouchHandleDown( void *userData, struct wl_surface *surfaceNested, uint32_t time, int32_t id, wl_fixed_t sx, wl_fixed_t sy );
static void wstDefaultNestedTouchHandleUp( void *userData, uint32_t time, int32_t id );
static void wstDefaultNestedTouchHandleMotion( void *userData, uint32_t time, int32_t id, wl_fixed_t sx, wl_fixed_t sy );
static void wstDefaultNestedTouchHandleFrame( void *userData );
static void wstDefaultNestedShmFormat( void *userData, uint32_t format );
static void wstDefaultNestedVpcVideoPathChange( void *userData, struct wl_surface *surfaceNested, uint32_t newVideoPath );
static void wstDefaultNestedVpcVideoXformChange( void *userData,
struct wl_surface *surfaceNested,
int32_t x_translation,
int32_t y_translation,
uint32_t x_scale_num,
uint32_t x_scale_denom,
uint32_t y_scale_num,
uint32_t y_scale_denom,
uint32_t output_width,
uint32_t output_height );
static void wstDefaultNestedSurfaceStatus( void *userData, struct wl_surface *surface,
const char *name,
uint32_t visible,
int32_t x,
int32_t y,
int32_t width,
int32_t height,
wl_fixed_t opacity,
wl_fixed_t zorder);
static void wstSetDefaultNestedListener( WstContext *ctx );
static bool wstSeatInit( WstContext *ctx );
static void wstSeatItemTerm( WstCompositor *wctx );
static void wstSeatTerm( WstContext *ctx );
static void wstSeatCreateDevices( WstCompositor *wctx );
static void wstResourceUnBindCallback( struct wl_resource *resource );
static void wstSeatBind( struct wl_client *client, void *data, uint32_t version, uint32_t id);
static void wstISeatGetPointer( struct wl_client *client, struct wl_resource *resource, uint32_t id );
static void wstISeatGetKeyboard( struct wl_client *client, struct wl_resource *resource, uint32_t id );
static void wstISeatGetTouch( struct wl_client *client, struct wl_resource *resource, uint32_t id );
static void wstIKeyboardRelease( struct wl_client *client, struct wl_resource *resource );
static void wstIPointerSetCursor( struct wl_client *client,
struct wl_resource *resource,
uint32_t serial,
struct wl_resource *surfaceResource,
int32_t hotspot_x,
int32_t hotspot_y );
static void wstIPointerRelease( struct wl_client *client, struct wl_resource *resource );
static void wstITouchRelease( struct wl_client *client, struct wl_resource *resource );
static void wstVpcBind( struct wl_client *client, void *data, uint32_t version, uint32_t id);
static void wstIVpcGetVpcSurface( struct wl_client *client, struct wl_resource *resource,
uint32_t id, struct wl_resource *surfaceResource);
static void wstDestroyVpcSurfaceCallback(struct wl_resource *resource);
static void wstVpcSurfaceDestroy( WstVpcSurface *vpcSurface );
static void wstIVpcSurfaceSetGeometry( struct wl_client *client, struct wl_resource *resource,
int32_t x, int32_t y, int32_t width, int32_t height );
static void wstIVpcSurfaceSetGeometryWithCrop( struct wl_client *client, struct wl_resource *resource,
int32_t x, int32_t y, int32_t width, int32_t height,
int32_t cropX, int32_t cropY, int32_t cropW, int32_t cropH );
static void wstUpdateVPCSurfaces( WstCompositor *wctx, std::vector<WstRect> &rects );
static bool wstInitializeKeymap( WstCompositor *wctx );
static void wstTerminateKeymap( WstCompositor *wctx );
static void wstProcessKeyEvent( WstKeyboard *keyboard, uint32_t keyCode, uint32_t keyState, uint32_t modifiers );
static void wstKeyboardSendModifiers( WstKeyboard *keyboard, struct wl_resource *resource );
static void wstKeyboardCheckFocus( WstKeyboard *keyboard, WstSurface *surface );
static void wstKeyboardSetFocus( WstKeyboard *keyboard, WstSurface *surface );
static void wstKeyboardMoveFocusToClient( WstKeyboard *keyboard, struct wl_client *client );
static void wstProcessPointerEnter( WstPointer *pointer, int x, int y, struct wl_surface *surfaceNested );
static void wstProcessPointerLeave( WstPointer *pointer, struct wl_surface *surfaceNested );
static void wstProcessPointerMoveEvent( WstPointer *pointer, int32_t x, int32_t y );
static void wstProcessPointerButtonEvent( WstPointer *pointer, uint32_t button, uint32_t buttonState, uint32_t time );
static void wstPointerCheckFocus( WstPointer *pointer, int32_t x, int32_t y );
static void wstPointerSetPointer( WstPointer *pointer, WstSurface *surface );
static void wstPointerUpdatePosition( WstPointer *pointer );
static void wstPointerSetFocus( WstPointer *pointer, WstSurface *surface, wl_fixed_t x, wl_fixed_t y );
static void wstPointerMoveFocusToClient( WstPointer *pointer, struct wl_client *client );
static void wstProcessTouchDownEvent( WstTouch *touch, uint32_t time, int id, int x, int y, struct wl_surface *surfaceNested );
static void wstProcessTouchUpEvent( WstTouch *touch, uint32_t time, int id );
static void wstProcessTouchMotionEvent( WstTouch *touch, uint32_t time, int id, int x, int y );
static void wstProcessTouchFrameEvent( WstTouch *touch );
static void wstTouchCheckFocus( WstTouch *pointer, int32_t x, int32_t y );
static void wstTouchMoveFocusToClient( WstTouch *touch, struct wl_client *client );
static void wstRemoveTempFile( int fd );
static void wstPruneOrphanFiles( WstContext *ctx );
static bool wstInitializeDefaultCursor( WstCompositor *compositor,
unsigned char *imgData, int width, int height,
int hotspotX, int hotspotY );
static void wstTerminateDefaultCursor( WstCompositor *compositor );
static void wstForwardChildProcessStdout( int descriptors[2] );
static void wstMonitorChildProcessStdout( int descriptors[2] );
extern char **environ;
static pthread_mutex_t g_mutex= PTHREAD_MUTEX_INITIALIZER;
static int g_pid= 0;
static int g_nextNestedId= 0;
static pthread_mutex_t g_mutexMasterEmbedded= PTHREAD_MUTEX_INITIALIZER;
static WstCompositor *g_masterEmbedded= 0;
static int g_activeLevel= 3;
static void wstLog( int level, const char *fmt, ... )
{
if ( level <= g_activeLevel )
{
va_list argptr;
va_start( argptr, fmt );
vfprintf( stderr, fmt, argptr );
va_end( argptr );
}
}
WstCompositor* WstCompositorCreate()
{
WstCompositor *wctx= 0;
const char *env= getenv( "WESTEROS_DEBUG" );
if ( env )
{
int level= atoi( env );
g_activeLevel= level;
}
INFO("westeros (core) version " WESTEROS_VERSION_FMT, WESTEROS_VERSION );
wctx= (WstCompositor*)calloc( 1, sizeof(WstCompositor) );
if ( wctx )
{
WstContext *ctx= 0;
wctx->outputWidth= DEFAULT_OUTPUT_WIDTH;
wctx->outputHeight= DEFAULT_OUTPUT_HEIGHT;
ctx= (WstContext*)calloc( 1, sizeof(WstContext) );
if ( ctx )
{
pthread_mutex_init( &ctx->mutex, 0 );
ctx->frameRate= DEFAULT_FRAME_RATE;
ctx->framePeriodMillis= (1000/ctx->frameRate);
ctx->nestedWidth= DEFAULT_NESTED_WIDTH;
ctx->nestedHeight= DEFAULT_NESTED_HEIGHT;
#if defined (WESTEROS_HAVE_WAYLAND_EGL)
ctx->eglDisplay= EGL_NO_DISPLAY;
#endif
ctx->nextSurfaceId= 1;
ctx->surfaceMap= std::map<int32_t, WstSurface*>();
ctx->clientInfoMap= std::map<struct wl_client*, WstClientInfo*>();
ctx->surfaceInfoMap= std::map<struct wl_resource*, WstSurfaceInfo*>();
ctx->vpcSurfaces= std::vector<WstVpcSurface*>();
ctx->modules= std::vector<WstModule*>();
ctx->xkbNames.rules= strdup("evdev");
ctx->xkbNames.model= strdup("pc105");
ctx->xkbNames.layout= strdup("us");
ctx->xkbKeymapFd= -1;
ctx->dcPoolFd= -1;
wstSetDefaultNestedListener( ctx );
ctx->wctx= wctx;
wctx->ctx= ctx;
}
else
{
free( wctx );
wctx= 0;
}
}
return wctx;
}
void WstCompositorDestroy( WstCompositor *wctx )
{
if ( wctx && wctx->ctx )
{
WstContext *ctx= wctx->ctx;
if ( wctx->isVirtual )
{
pthread_mutex_lock( &ctx->mutex );
wctx->destroyed= true;
pthread_mutex_unlock( &ctx->mutex );
return;
}
pthread_mutex_lock( &g_mutexMasterEmbedded );
if ( g_masterEmbedded == wctx )
{
g_masterEmbedded= 0;
}
pthread_mutex_unlock( &g_mutexMasterEmbedded );
pthread_mutex_lock( &ctx->mutex );
for ( std::vector<WstCompositor*>::iterator it= ctx->virt.begin();
it != ctx->virt.end();
++it )
{
WstCompositor *wctx= (*it);
wctx->destroyed= true;
}
pthread_mutex_unlock( &ctx->mutex );
if ( ctx->running || ctx->compositorThreadStarted )
{
WstCompositorStop( wctx );
}
if ( ctx->displayName )
{
free( (void*)ctx->displayName );
ctx->displayName= 0;
}
if ( ctx->rendererModule )
{
free( (void*)ctx->rendererModule );
ctx->rendererModule= 0;
}
if ( ctx->nestedDisplayName )
{
free( (void*)ctx->nestedDisplayName );
ctx->nestedDisplayName= 0;
}
if ( ctx->xkbNames.rules )
{
free( (void*)ctx->xkbNames.rules );
ctx->xkbNames.rules= 0;
}