-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
vc_vchi_dispmanx.c
executable file
·1321 lines (1174 loc) · 48.2 KB
/
vc_vchi_dispmanx.c
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
/*
Copyright (c) 2012-2014, Broadcom Europe Ltd
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <stdlib.h>
#include "vchost_platform_config.h"
#include "vchost.h"
#include "interface/vcos/vcos.h"
#include "vc_dispservice_x_defs.h"
#include "vc_dispmanx.h"
#include "interface/vchi/vchi.h"
#include "vcinclude/common.h"
#include "interface/vchi/common/endian.h"
#include "interface/vchi/message_drivers/message.h"
#include "vc_vchi_dispmanx.h"
/******************************************************************************
Local types and defines.
******************************************************************************/
//DispmanX service
typedef struct {
VCHI_SERVICE_HANDLE_T client_handle[VCHI_MAX_NUM_CONNECTIONS]; //To connect to server on VC
VCHI_SERVICE_HANDLE_T notify_handle[VCHI_MAX_NUM_CONNECTIONS]; //For incoming notification
uint32_t msg_flag[VCHI_MAX_NUM_CONNECTIONS];
char command_buffer[DISPMANX_MSGFIFO_SIZE];
char response_buffer[DISPMANX_MSGFIFO_SIZE];
uint32_t response_length;
uint32_t notify_buffer[DISPMANX_MSGFIFO_SIZE/sizeof(uint32_t)];
uint32_t notify_length;
uint32_t num_connections;
VCOS_MUTEX_T lock;
char dispmanx_devices[DISPMANX_MAX_HOST_DEVICES][DISPMANX_MAX_DEVICE_NAME_LEN];
uint32_t num_devices;
uint32_t num_modes[DISPMANX_MAX_HOST_DEVICES];
//Callback for update
DISPMANX_CALLBACK_FUNC_T update_callback;
void *update_callback_param;
DISPMANX_UPDATE_HANDLE_T pending_update_handle;
//Callback for vsync
DISPMANX_CALLBACK_FUNC_T vsync_callback;
void *vsync_callback_param;
int vsync_enabled;
int initialised;
} DISPMANX_SERVICE_T;
/******************************************************************************
Static data.
******************************************************************************/
static DISPMANX_SERVICE_T dispmanx_client;
static VCOS_EVENT_T dispmanx_message_available_event;
static VCOS_EVENT_T dispmanx_notify_available_event;
static VCOS_THREAD_T dispmanx_notify_task;
/******************************************************************************
Static functions.
******************************************************************************/
//Lock the host state
static __inline void lock_obtain (void) {
VCOS_STATUS_T status;
uint32_t i;
vcos_assert(dispmanx_client.initialised);
status = vcos_mutex_lock( &dispmanx_client.lock );
if(dispmanx_client.initialised)
{
for (i=0; i<dispmanx_client.num_connections; i++) {
vchi_service_use(dispmanx_client.client_handle[i]);
}
}
vcos_assert(status == VCOS_SUCCESS);
}
//Unlock the host state
static __inline void lock_release (void) {
uint32_t i;
vcos_assert(dispmanx_client.initialised);
if(dispmanx_client.initialised)
{
for (i=0; i<dispmanx_client.num_connections; i++) {
vchi_service_release(dispmanx_client.client_handle[i]);
}
}
vcos_mutex_unlock( &dispmanx_client.lock );
}
//Forward declarations
static void dispmanx_client_callback( void *callback_param,
VCHI_CALLBACK_REASON_T reason,
void *msg_handle );
static void dispmanx_notify_callback( void *callback_param,
VCHI_CALLBACK_REASON_T reason,
void *msg_handle );
static int32_t dispmanx_wait_for_reply(void *response, uint32_t max_length);
static int32_t dispmanx_send_command( uint32_t command, void *buffer, uint32_t length);
static int32_t dispmanx_send_command_reply( uint32_t command, void *buffer, uint32_t length,
void *response, uint32_t max_length);
static uint32_t dispmanx_get_handle( uint32_t command, void *buffer, uint32_t length);
static void *dispmanx_notify_func( void *arg );
/******************************************************************************
NAME
vc_vchi_gencmd_init
SYNOPSIS
void vc_vchi_gencmd_init(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections )
FUNCTION
Initialise the general command service for use. A negative return value
indicates failure (which may mean it has not been started on VideoCore).
RETURNS
int
******************************************************************************/
void vc_vchi_dispmanx_init (VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections ) {
VCOS_STATUS_T status;
int32_t success;
uint32_t i;
if (dispmanx_client.initialised)
return;
// record the number of connections
memset( &dispmanx_client, 0, sizeof(DISPMANX_SERVICE_T) );
dispmanx_client.num_connections = num_connections;
status = vcos_mutex_create(&dispmanx_client.lock, "HDispmanx");
vcos_assert(status == VCOS_SUCCESS);
status = vcos_event_create(&dispmanx_message_available_event, "HDispmanx");
vcos_assert(status == VCOS_SUCCESS);
status = vcos_event_create(&dispmanx_notify_available_event, "HDispmanx");
vcos_assert(status == VCOS_SUCCESS);
dispmanx_client.initialised = 1;
for (i=0; i<dispmanx_client.num_connections; i++) {
VCOS_THREAD_ATTR_T attrs;
// Create a 'Client' service on the each of the connections
SERVICE_CREATION_T dispmanx_parameters = { VCHI_VERSION(VC_DISPMANX_VERSION),
DISPMANX_CLIENT_NAME, // 4cc service code
connections[i], // passed in fn ptrs
0, // tx fifo size (unused)
0, // tx fifo size (unused)
&dispmanx_client_callback, // service callback
&dispmanx_message_available_event, // callback parameter
VC_FALSE, // want_unaligned_bulk_rx
VC_FALSE, // want_unaligned_bulk_tx
VC_FALSE, // want_crc
};
SERVICE_CREATION_T dispmanx_parameters2 = { VCHI_VERSION(VC_DISPMANX_VERSION),
DISPMANX_NOTIFY_NAME, // 4cc service code
connections[i], // passed in fn ptrs
0, // tx fifo size (unused)
0, // tx fifo size (unused)
&dispmanx_notify_callback, // service callback
&dispmanx_notify_available_event, // callback parameter
VC_FALSE, // want_unaligned_bulk_rx
VC_FALSE, // want_unaligned_bulk_tx
VC_FALSE, // want_crc
};
success = vchi_service_open( initialise_instance, &dispmanx_parameters, &dispmanx_client.client_handle[i] );
vcos_assert( success == 0 );
// Create the async service of dispman to handle update callback
success = vchi_service_open( initialise_instance, &dispmanx_parameters2, &dispmanx_client.notify_handle[i] );
vcos_assert( success == 0 );
//Create the notifier task
vcos_thread_attr_init(&attrs);
vcos_thread_attr_setstacksize(&attrs, 2048);
vcos_thread_attr_settimeslice(&attrs, 1);
status = vcos_thread_create(&dispmanx_notify_task, "HDispmanx Notify", &attrs, dispmanx_notify_func, NULL);
vcos_assert(status == VCOS_SUCCESS);
// release services until they're actually used
vchi_service_release(dispmanx_client.client_handle[i]);
vchi_service_release(dispmanx_client.notify_handle[i]);
}
}
/***********************************************************
* Name: vc_dispmanx_stop
*
* Arguments:
* -
*
* Description: Stops the Host side part of dispmanx
*
* Returns: -
*
***********************************************************/
VCHPRE_ void VCHPOST_ vc_dispmanx_stop( void ) {
// Wait for the current lock-holder to finish before zapping dispmanx.
//TODO: kill the notifier task
void *dummy;
uint32_t i;
if (!dispmanx_client.initialised)
return;
lock_obtain();
for (i=0; i<dispmanx_client.num_connections; i++) {
int32_t result;
result = vchi_service_close(dispmanx_client.client_handle[i]);
vcos_assert( result == 0 );
result = vchi_service_close(dispmanx_client.notify_handle[i]);
vcos_assert( result == 0 );
}
lock_release();
dispmanx_client.initialised = 0;
vcos_event_signal(&dispmanx_notify_available_event);
vcos_thread_join(&dispmanx_notify_task, &dummy);
vcos_mutex_delete(&dispmanx_client.lock);
vcos_event_delete(&dispmanx_message_available_event);
vcos_event_delete(&dispmanx_notify_available_event);
}
/***********************************************************
* Name: vc_dispmanx_rect_set
*
* Arguments:
* VC_RECT_T *rect
* uint32_t x_offset
* uint32_t y_offset
* uint32_t width
* uint32_t height
*
* Description: Fills in the fields of the supplied VC_RECT_T structure
*
* Returns: 0 or failure
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_rect_set( VC_RECT_T *rect, uint32_t x_offset, uint32_t y_offset, uint32_t width, uint32_t height ) {
rect->x = (int32_t) x_offset;
rect->y = (int32_t) y_offset;
rect->width = (int32_t) width;
rect->height = (int32_t) height;
return 0;
}
/******************************************************************************
NAME
vc_dispmanx_query_image_formats
PARAMS
uint32_t *support_formats - the returned supported image formats
FUNCTION
Returns the support image formats from the VMCS host
RETURNS
Success: 0
Otherwise non-zero
******************************************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_query_image_formats( uint32_t *supported_formats ) {
*supported_formats = dispmanx_get_handle(EDispmanQueryImageFormats, NULL, 0);
return (*supported_formats)? 0 : -1;
}
/***********************************************************
* Name: vc_dispmanx_resource_create
*
* Arguments:
* VC_IMAGE_TYPE_T type
* uint32_t width
* uint32_t height
*
* Description: Create a new resource (in Videocore memory)
*
* Returns: resource handle
*
***********************************************************/
VCHPRE_ DISPMANX_RESOURCE_HANDLE_T VCHPOST_ vc_dispmanx_resource_create( VC_IMAGE_TYPE_T type, uint32_t width, uint32_t height, uint32_t *native_image_handle ) {
uint32_t resourceCreateParams[] = { (uint32_t)VC_HTOV32(type), VC_HTOV32(width), VC_HTOV32(height) };
uint32_t resource = 0;
resource = dispmanx_get_handle(EDispmanResourceCreate, resourceCreateParams, sizeof(resourceCreateParams));
//We don't get an image handle back, so explicitly set this to zero to let the caller know
*native_image_handle = 0;
//The caller should call vc_dispmanx_resource_get_image_handle below to get the VC_IMAGE_T *
//This will be deprecated soon, however
return (DISPMANX_RESOURCE_HANDLE_T) resource;
}
/***********************************************************
* Name: vc_dispmanx_resource_get_image_handle
*
* Arguments: resource handle
*
* Description: xxx only for hacking purpose, will be obsolete soon
*
* Returns: vc_image pointer
*
***********************************************************/
VCHPRE_ uint32_t VCHPOST_ vc_dispmanx_resource_get_image_handle( DISPMANX_RESOURCE_HANDLE_T res) {
return dispmanx_get_handle(EDispmanResourceGetImage, &res, sizeof(res));
}
/***********************************************************
* Name: vc_dispmanx_resource_delete
*
* Arguments:
* DISPMANX_RESOURCE_HANDLE_T res
*
* Description:
*
* Returns: 0 or failure
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_resource_delete( DISPMANX_RESOURCE_HANDLE_T res ) {
int status;
res = VC_HTOV32(res);
//We block to make sure the memory is freed after the call
status = (int) dispmanx_send_command(EDispmanResourceDelete, &res, sizeof(res));
return status;
}
/***********************************************************
* Name: vc_dispmanx_resource_write_data
*
* Arguments:
* DISPMANX_RESOURCE_HANDLE_T res
* int src_pitch
* void * src_address
* const VC_RECT_T * rect
*
* Description: Copy the bitmap data to VideoCore memory
*
* Returns: 0 or failure
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_resource_write_data( DISPMANX_RESOURCE_HANDLE_T handle, VC_IMAGE_TYPE_T src_type /* not used */,
int src_pitch, void * src_address, const VC_RECT_T * rect ) {
(void)src_type;
//Note that x coordinate of the rect is NOT used
//Address of data in host
uint8_t *host_start = (uint8_t *)src_address + src_pitch * rect->y;
int32_t bulk_len = src_pitch * rect->height, success = 0;
//Now send the bulk transfer across
//command parameters: resource handle, destination y, bulk length
uint32_t param[] = {VC_HTOV32(handle), VC_HTOV32(rect->y), VC_HTOV32(bulk_len), VC_HTOV32(src_type) };
success = dispmanx_send_command( EDispmanBulkWrite | DISPMANX_NO_REPLY_MASK, param, sizeof(param));
if(success == 0)
{
lock_obtain();
success = vchi_bulk_queue_transmit( dispmanx_client.client_handle[0],
host_start,
bulk_len,
VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
NULL );
lock_release();
}
return (int) success;
}
/***********************************************************
* Name: vc_dispmanx_resource_read_data
*
* Arguments:
* DISPMANX_RESOURCE_HANDLE_T res
* int src_pitch
* void * src_address
* const VC_RECT_T * rect
*
* Description: Copy the bitmap data from VideoCore memory
*
* Returns: 0 or failure
*
***********************************************************/
VCHPRE_ int VCHPOST_
vc_dispmanx_resource_read_data(
DISPMANX_RESOURCE_HANDLE_T handle,
const VC_RECT_T* p_rect,
void * dst_address,
uint32_t dst_pitch )
{
uint8_t* host_start;
int32_t bulk_len;
int32_t success = 0;
if ( p_rect == 0 || dst_address == 0 || dst_pitch == 0 )
{
return -1;
}
host_start = (uint8_t *)dst_address + (dst_pitch * p_rect->y);
bulk_len = (int32_t)dst_pitch * p_rect->height;
// Now send the bulk transfer across
// command parameters: resource handle, destination y, bulk length
uint32_t param[] = { VC_HTOV32(handle), VC_HTOV32(p_rect->y), VC_HTOV32(bulk_len) };
success = dispmanx_send_command( EDispmanBulkRead | DISPMANX_NO_REPLY_MASK, param, sizeof(param));
if (success == 0)
{
lock_obtain();
success = vchi_bulk_queue_receive( dispmanx_client.client_handle[0],
host_start,
bulk_len,
VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE,
0 );
lock_release();
}
return (int) success;
}
/***********************************************************
* Name: vc_dispmanx_resource_write_data_handle
*
* Arguments:
* DISPMANX_RESOURCE_HANDLE_T res
* int src_pitch
* MEM_HANDLE_T handle
* uint32_t offset
* const VC_RECT_T * rect
*
* Description: Copy the bitmap data to VideoCore memory
*
* Returns: 0 or failure
*
***********************************************************/
#ifdef SELF_HOSTED
VCHPRE_ int VCHPOST_ vc_dispmanx_resource_write_data_handle( DISPMANX_RESOURCE_HANDLE_T handle, VC_IMAGE_TYPE_T src_type /* not used */,
int src_pitch, VCHI_MEM_HANDLE_T mem_handle, uint32_t offset,
const VC_RECT_T * rect ) {
int32_t bulk_len;
uint32_t param[3];
uint32_t success = 0;
//Note that x coordinate of the rect is NOT used
//Address of data in host
offset += src_pitch * rect->y;
bulk_len = src_pitch * rect->height;
//Now send the bulk transfer across
//command parameters: resource handle, destination y, bulk length
param[0] = VC_HTOV32(handle);
param[1] = VC_HTOV32(rect->y);
param[2] = VC_HTOV32(bulk_len);
success = dispmanx_send_command( EDispmanBulkWrite | DISPMANX_NO_REPLY_MASK, param, sizeof(param));
if(success == 0)
{
lock_obtain();
success = vchi_bulk_queue_transmit_reloc( dispmanx_client.client_handle[0],
mem_handle, offset,
bulk_len,
VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
NULL );
lock_release();
}
return (int) success;
}
#endif
/***********************************************************
* Name: vc_dispmanx_display_open
*
* Arguments:
* uint32_t device
*
* Description:
*
* Returns:
*
***********************************************************/
VCHPRE_ DISPMANX_DISPLAY_HANDLE_T VCHPOST_ vc_dispmanx_display_open( uint32_t device ) {
uint32_t display_handle;
char *env = getenv("VC_DISPLAY");
if (device == 0 && env)
{
device = atoi(env);
}
device = VC_HTOV32(device);
display_handle = dispmanx_get_handle(EDispmanDisplayOpen,
&device, sizeof(device));
return (DISPMANX_DISPLAY_HANDLE_T) display_handle;
}
/***********************************************************
* Name: vc_dispmanx_display_open_mode
*
* Arguments:
* uint32_t device
* uint32_t mode
*
* Description:
*
* Returns:
*
***********************************************************/
VCHPRE_ DISPMANX_DISPLAY_HANDLE_T VCHPOST_ vc_dispmanx_display_open_mode( uint32_t device, uint32_t mode ) {
uint32_t display_open_param[] = {VC_HTOV32(device), VC_HTOV32(mode)};
uint32_t display_handle = dispmanx_get_handle(EDispmanDisplayOpenMode,
&display_open_param, sizeof(display_open_param));
return (DISPMANX_DISPLAY_HANDLE_T) display_handle;
}
/***********************************************************
* Name: vc_dispmanx_display_open_offscreen
*
* Arguments:
* DISPMANX_RESOURCE_HANDLE_T dest
* DISPMANX_TRANSFORM_T orientation
*
* Description:
*
* Returns:
*
***********************************************************/
VCHPRE_ DISPMANX_DISPLAY_HANDLE_T VCHPOST_ vc_dispmanx_display_open_offscreen( DISPMANX_RESOURCE_HANDLE_T dest, DISPMANX_TRANSFORM_T orientation ) {
uint32_t display_open_param[] = {(uint32_t)VC_HTOV32(dest), (uint32_t)VC_HTOV32(orientation)};
uint32_t display_handle = dispmanx_get_handle(EDispmanDisplayOpenOffscreen,
&display_open_param, sizeof(display_open_param));
return (DISPMANX_DISPLAY_HANDLE_T) display_handle;
}
/***********************************************************
* Name: vc_dispmanx_display_reconfigure
*
* Arguments:
* DISPMANX_DISPLAY_HANDLE_T display
* uint32_t mode
*
* Description:
*
* Returns:
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_display_reconfigure( DISPMANX_DISPLAY_HANDLE_T device, uint32_t mode ) {
uint32_t display_param[] = {(uint32_t)VC_HTOV32(device), VC_HTOV32(mode)};
int32_t success = dispmanx_send_command( EDispmanDisplayReconfigure | DISPMANX_NO_REPLY_MASK,
display_param, sizeof(display_param));
return (int) success;
}
/***********************************************************
* Name: vc_dispmanx_display_set_destination
*
* Arguments:
* DISPMANX_DISPLAY_HANDLE_T display
* DISPMANX_RESOURCE_HANDLE_T dest
*
* Description:
*
* Returns:
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_display_set_destination( DISPMANX_DISPLAY_HANDLE_T display, DISPMANX_RESOURCE_HANDLE_T dest ) {
uint32_t display_param[] = {(uint32_t)VC_HTOV32(display), (uint32_t)VC_HTOV32(dest)};
int32_t success = dispmanx_send_command( EDispmanDisplaySetDestination | DISPMANX_NO_REPLY_MASK,
display_param, sizeof(display_param));
return (int) success;
}
/***********************************************************
* Name: vc_dispmanx_display_set_background
*
* Arguments:
* DISPMANX_UPDATE_HANDLE_T update
* DISPMANX_DISPLAY_HANDLE_T display
* uint8_t red
* uint8_t green
* uint8_t blue
*
* Description:
*
* Returns:
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_display_set_background( DISPMANX_UPDATE_HANDLE_T update, DISPMANX_DISPLAY_HANDLE_T display,
uint8_t red, uint8_t green, uint8_t blue ) {
uint32_t display_param[] = {(uint32_t)VC_HTOV32(update), (uint32_t) VC_HTOV32(display), VC_HTOV32(red), VC_HTOV32(green), VC_HTOV32(blue)};
int success = (int) dispmanx_send_command( EDispmanDisplaySetBackground | DISPMANX_NO_REPLY_MASK,
display_param, sizeof(display_param));
return success;
}
/***********************************************************
* Name: vc_dispmanx_display_get_info
*
* Arguments:
* DISPMANX_DISPLAY_HANDLE_T display
* DISPMANX_MODEINFO_T * pinfo
*
* Description:
*
* Returns: VCHI error
*
***********************************************************/
VCHPRE_ int VCHPOST_
vc_dispmanx_display_get_info (DISPMANX_DISPLAY_HANDLE_T display,
DISPMANX_MODEINFO_T *pinfo)
{
GET_INFO_DATA_T info;
int32_t success;
display = VC_HTOV32(display);
success = dispmanx_send_command_reply (EDispmanDisplayGetInfo,
&display, sizeof(display),
&info, sizeof(info));
if(success == 0) {
pinfo->width = VC_VTOH32(info.width);
pinfo->height = VC_VTOH32(info.height);
pinfo->transform = (DISPMANX_TRANSFORM_T)VC_VTOH32(info.transform);
pinfo->input_format = (DISPLAY_INPUT_FORMAT_T)VC_VTOH32(info.input_format);
}
return (int) success;
}
/***********************************************************
* Name: vc_dispmanx_display_close
*
* Arguments:
* DISPMANX_DISPLAY_HANDLE_T display
*
* Description:
*
* Returns:
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_display_close( DISPMANX_DISPLAY_HANDLE_T display ) {
int success;
display = VC_HTOV32(display);
success = (int) dispmanx_send_command( EDispmanDisplayClose | DISPMANX_NO_REPLY_MASK,
&display, sizeof(display));
return success;
}
/***********************************************************
* Name: vc_dispmanx_update_start
*
* Arguments:
* int32_t priority
*
* Description:
*
* Returns:
*
***********************************************************/
VCHPRE_ DISPMANX_UPDATE_HANDLE_T VCHPOST_ vc_dispmanx_update_start( int32_t priority ) {
uint32_t handle;
priority = VC_HTOV32(priority);
handle = dispmanx_get_handle(EDispmanUpdateStart,
&priority, sizeof(priority));
return (DISPMANX_UPDATE_HANDLE_T) handle;
}
/***********************************************************
* Name: vc_dispmanx_update_submit
*
* Arguments:
* DISPMANX_UPDATE_HANDLE_T update
* DISPMANX_CALLBACK_FUNC_T cb_func
* void *cb_arg
*
* Description:
*
* Returns:
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_update_submit( DISPMANX_UPDATE_HANDLE_T update, DISPMANX_CALLBACK_FUNC_T cb_func, void *cb_arg ) {
uint32_t update_param[] = {(uint32_t) VC_HTOV32(update), (uint32_t) ((cb_func)? VC_HTOV32(1) : 0)};
int success;
vcos_assert(update); // handles must be non-zero
if (update)
{
//Set the callback
dispmanx_client.update_callback = cb_func;
dispmanx_client.update_callback_param = cb_arg;
dispmanx_client.pending_update_handle = update;
vchi_service_use(dispmanx_client.notify_handle[0]); // corresponding release is in dispmanx_notify_func
success = (int) dispmanx_send_command( EDispmanUpdateSubmit | DISPMANX_NO_REPLY_MASK,
update_param, sizeof(update_param));
}
else
{
success = -1;
}
return success;
}
/***********************************************************
* Name: vc_dispmanx_update_submit_sync
*
* Arguments:
* DISPMANX_UPDATE_HANDLE_T update
*
* Description:
*
* Returns: VCHI error code
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_update_submit_sync( DISPMANX_UPDATE_HANDLE_T update ) {
int success;
update = VC_HTOV32(update);
success = (int) dispmanx_send_command( EDispmanUpdateSubmitSync,
&update, sizeof(update));
return success;
}
/***********************************************************
* Name: vc_dispmanx_element_add
*
* Arguments:
* DISPMANX_UPDATE_HANDLE_T update
* DISPMANX_DISPLAY_HANDLE_T display
* int32_t layer
* const VC_RECT_T *dest_rect
* DISPMANX_RESOURCE_HANDLE_T src
* const VC_RECT_T *src_rect
* DISPMANX_FLAGS_T flags
* uint8_t opacity
* DISPMANX_RESOURCE_HANDLE_T mask
* DISPMANX_TRANSFORM_T transform
*
* Description:
*
* Returns: VCHI error code
*
***********************************************************/
VCHPRE_ DISPMANX_ELEMENT_HANDLE_T VCHPOST_ vc_dispmanx_element_add ( DISPMANX_UPDATE_HANDLE_T update,
DISPMANX_DISPLAY_HANDLE_T display,
int32_t layer,
const VC_RECT_T *dest_rect,
DISPMANX_RESOURCE_HANDLE_T src,
const VC_RECT_T *src_rect,
DISPMANX_PROTECTION_T protection,
VC_DISPMANX_ALPHA_T *alpha,
DISPMANX_CLAMP_T *clamp,
DISPMANX_TRANSFORM_T transform ) {
int32_t element_param[] = {
(int32_t) VC_HTOV32(update),
(int32_t) VC_HTOV32(display),
(int32_t) VC_HTOV32(layer),
(int32_t) VC_HTOV32(dest_rect->x),
(int32_t) VC_HTOV32(dest_rect->y),
(int32_t) VC_HTOV32(dest_rect->width),
(int32_t) VC_HTOV32(dest_rect->height),
(int32_t) VC_HTOV32(src),
(int32_t) VC_HTOV32(src_rect->x),
(int32_t) VC_HTOV32(src_rect->y),
(int32_t) VC_HTOV32(src_rect->width),
(int32_t) VC_HTOV32(src_rect->height),
(int32_t) VC_HTOV32(protection),
alpha ? (int32_t) VC_HTOV32(alpha->flags) : 0,
alpha ? (int32_t) VC_HTOV32(alpha->opacity) : 0,
alpha ? (int32_t) VC_HTOV32(alpha->mask) : 0,
clamp ? (int32_t) VC_HTOV32(clamp->mode) : 0,
clamp ? (int32_t) VC_HTOV32(clamp->key_mask) : 0,
clamp ? (int32_t) VC_HTOV32(clamp->key_value.yuv.yy_upper) : 0,
clamp ? (int32_t) VC_HTOV32(clamp->key_value.yuv.yy_lower) : 0,
clamp ? (int32_t) VC_HTOV32(clamp->key_value.yuv.cr_upper) : 0,
clamp ? (int32_t) VC_HTOV32(clamp->key_value.yuv.cr_lower) : 0,
clamp ? (int32_t) VC_HTOV32(clamp->key_value.yuv.cb_upper) : 0,
clamp ? (int32_t) VC_HTOV32(clamp->key_value.yuv.cb_lower) : 0,
clamp ? (int32_t) VC_HTOV32(clamp->replace_value) : 0,
(int32_t) VC_HTOV32(transform)
};
uint32_t handle = dispmanx_get_handle(EDispmanElementAdd,
element_param, sizeof(element_param));
return (DISPMANX_ELEMENT_HANDLE_T) handle;
}
/***********************************************************
* Name: vc_dispmanx_element_change_source
*
* Arguments:
* DISPMANX_UPDATE_HANDLE_T update
* DISPMANX_ELEMENT_HANDLE_T element
* DISPMANX_RESOURCE_HANDLE_T src
*
* Description:
*
* Returns: VCHI error code
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_element_change_source( DISPMANX_UPDATE_HANDLE_T update, DISPMANX_ELEMENT_HANDLE_T element,
DISPMANX_RESOURCE_HANDLE_T src ) {
uint32_t element_param[] = { (uint32_t) VC_HTOV32(update),
(uint32_t) VC_HTOV32(element),
(uint32_t) VC_HTOV32(src) };
int success = (int) dispmanx_send_command( EDispmanElementChangeSource | DISPMANX_NO_REPLY_MASK,
element_param, sizeof(element_param));
return success;
}
/***********************************************************
* Name: vc_dispmanx_element_change_layer
*
* Arguments:
* DISPMANX_UPDATE_HANDLE_T update
* DISPMANX_ELEMENT_HANDLE_T element
* int32_t layer
*
* Description:
*
* Returns: VCHI error code
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_element_change_layer (DISPMANX_UPDATE_HANDLE_T update,
DISPMANX_ELEMENT_HANDLE_T element,
int32_t layer)
{
uint32_t element_param[] = { (uint32_t) VC_HTOV32(update),
(uint32_t) VC_HTOV32(element),
(uint32_t) VC_HTOV32(layer) };
int success = (int) dispmanx_send_command( EDispmanElementChangeLayer | DISPMANX_NO_REPLY_MASK,
element_param, sizeof(element_param));
return success;
}
/***********************************************************
* Name: vc_dispmanx_element_modified
*
* Arguments:
* DISPMANX_UPDATE_HANDLE_T update
* DISPMANX_ELEMENT_HANDLE_T element
* const VC_RECT_T * rect
*
* Description:
*
* Returns: VCHI error code
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_element_modified( DISPMANX_UPDATE_HANDLE_T update, DISPMANX_ELEMENT_HANDLE_T element, const VC_RECT_T * rect ) {
uint32_t element_param[6] = { (uint32_t) VC_HTOV32(update),
(uint32_t) VC_HTOV32(element), 0, 0, 0, 0};
uint32_t param_length = 2*sizeof(uint32_t);
int success;
if(rect) {
element_param[2] = VC_HTOV32(rect->x);
element_param[3] = VC_HTOV32(rect->y);
element_param[4] = VC_HTOV32(rect->width);
element_param[5] = VC_HTOV32(rect->height);
param_length = 6*sizeof(uint32_t);
}
success = (int) dispmanx_send_command( EDispmanElementModified | DISPMANX_NO_REPLY_MASK,
element_param, param_length);
return success;
}
/***********************************************************
* Name: vc_dispmanx_element_remove
*
* Arguments:
* DISPMANX_UPDATE_HANDLE_T update
* DISPMANX_ELEMENT_HANDLE_T element
*
* Description:
*
* Returns:
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_element_remove( DISPMANX_UPDATE_HANDLE_T update, DISPMANX_ELEMENT_HANDLE_T element ) {
uint32_t element_param[] = {(uint32_t) VC_HTOV32(update), (uint32_t) VC_HTOV32(element)};
int success = (int) dispmanx_send_command( EDispmanElementRemove | DISPMANX_NO_REPLY_MASK,
element_param, sizeof(element_param));
return success;
}
/***********************************************************
* Name: vc_dispmanx_element_change_attributes
*
* Arguments:
* DISPMANX_UPDATE_HANDLE_T update
* DISPMANX_ELEMENT_HANDLE_T element
* uint32_t change flags (bit 0 layer, bit 1 opacity, bit 2 dest rect, bit 3 src rect, bit 4 mask, bit 5 transform
* uint32_t layer
* uint8_t opacity
* const VC_RECT_T *dest rect
* const VC_RECT_T *src rect
* DISPMANX_RESOURCE_HANDLE_T mask
* VC_DISPMAN_TRANSFORM_T transform
*
* Description:
*
* Returns:
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_element_change_attributes( DISPMANX_UPDATE_HANDLE_T update,
DISPMANX_ELEMENT_HANDLE_T element,
uint32_t change_flags,
int32_t layer,
uint8_t opacity,
const VC_RECT_T *dest_rect,
const VC_RECT_T *src_rect,
DISPMANX_RESOURCE_HANDLE_T mask,
DISPMANX_TRANSFORM_T transform ) {
uint32_t element_param[15] = { (uint32_t) VC_HTOV32(update),
(uint32_t) VC_HTOV32(element),
VC_HTOV32(change_flags),
VC_HTOV32(layer),
VC_HTOV32(opacity),
(uint32_t) VC_HTOV32(mask),
(uint32_t) VC_HTOV32(transform), 0, 0, 0, 0, 0, 0, 0, 0};
uint32_t param_length = 7*sizeof(uint32_t);
int success;
if(dest_rect) {
element_param[7] = VC_HTOV32(dest_rect->x);
element_param[8] = VC_HTOV32(dest_rect->y);
element_param[9] = VC_HTOV32(dest_rect->width);
element_param[10] = VC_HTOV32(dest_rect->height);
element_param[2] |= ELEMENT_CHANGE_DEST_RECT;
param_length += 4*sizeof(uint32_t);
}
if(src_rect) {
element_param[11] = VC_HTOV32(src_rect->x);
element_param[12] = VC_HTOV32(src_rect->y);
element_param[13] = VC_HTOV32(src_rect->width);
element_param[14] = VC_HTOV32(src_rect->height);
element_param[2] |= ELEMENT_CHANGE_SRC_RECT;
param_length += 4*sizeof(uint32_t);
}
success = (int) dispmanx_send_command( EDispmanElementChangeAttributes | DISPMANX_NO_REPLY_MASK,
element_param, param_length);
return success;
}
/***********************************************************
* Name: vc_dispmanx_snapshot
*
* Arguments:
* DISPMANX_DISPLAY_HANDLE_T display
* DISPMANX_RESOURCE_HANDLE_T snapshot_resource
* DISPMANX_TRANSFORM_T transform
*
* Description: Take a snapshot of a display in its current state
*
* Returns:
*
***********************************************************/
VCHPRE_ int VCHPOST_ vc_dispmanx_snapshot( DISPMANX_DISPLAY_HANDLE_T display,
DISPMANX_RESOURCE_HANDLE_T snapshot_resource,