This repository was archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathgpudevice.cpp
More file actions
1132 lines (1025 loc) · 38.5 KB
/
gpudevice.cpp
File metadata and controls
1132 lines (1025 loc) · 38.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
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) 2016 Intel Corporation
//
// 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 <gpudevice.h>
#include <intel/intel_gvt.h>
#include <sys/file.h>
#include "mosaicdisplay.h"
#include "hwctrace.h"
#include "hwcutils.h"
namespace hwcomposer {
GpuDevice::GpuDevice() : HWCThread(-8, "GpuDevice") {
}
GpuDevice::~GpuDevice() {
display_manager_.reset(nullptr);
HWCThread::Exit();
if (-1 != lock_fd_) {
close(lock_fd_);
lock_fd_ = -1;
}
}
void GpuDevice::ResetAllDisplayCommit(bool enable) {
if (enable == enable_all_display_)
return;
enable_all_display_ = enable;
size_t size = total_displays_.size();
for (size_t i = 0; i < size; i++)
total_displays_.at(i)->EnableDRMCommit(enable);
}
bool GpuDevice::Initialize() {
initialization_state_lock_.lock();
if (initialization_state_ & kInitialized) {
initialization_state_lock_.unlock();
return true;
}
initialization_state_ |= kInitialized;
initialization_state_lock_.unlock();
display_manager_.reset(DisplayManager::CreateDisplayManager());
bool success = display_manager_->Initialize();
if (!success) {
return false;
}
display_manager_->InitializeDisplayResources();
//display_manager_->StartHotPlugMonitor();
CheckGvtActive();
HandleHWCSettings();
if (reserve_plane_) {
display_manager_->RemoveUnreservedPlanes();
}
lock_fd_ = open(HWC_LOCK_FILE, O_RDONLY);
if (-1 != lock_fd_) {
if (!InitWorker()) {
ETRACE("Failed to initalize thread for GpuDevice. %s", PRINTERROR());
}
} else {
ETRACE("Failed to open %s", HWC_LOCK_FILE);
// HWC should become drm master and start to commit.
// if hwc.lock is not available
if (!display_manager_->IsDrmMasterByDefault())
display_manager_->setDrmMaster(true);
ResetAllDisplayCommit(true);
}
return true;
}
FrameBufferManager *GpuDevice::GetFrameBufferManager() {
return display_manager_->GetFrameBufferManager();
}
uint32_t GpuDevice::GetFD() const {
return display_manager_->GetFD();
}
bool GpuDevice::IsGvtActive() const {
return gvt_active_;
}
NativeDisplay *GpuDevice::GetDisplay(uint32_t display_id) {
if (total_displays_.size() > display_id)
return total_displays_.at(display_id);
return NULL;
}
NativeDisplay *GpuDevice::CreateVirtualDisplay(uint32_t display_index) {
return display_manager_->CreateVirtualDisplay(display_index);
}
void GpuDevice::DestroyVirtualDisplay(uint32_t display_index) {
display_manager_->DestroyVirtualDisplay(display_index);
}
void GpuDevice::GetConnectedPhysicalDisplays(
std::vector<NativeDisplay *> &displays) {
size_t size = total_displays_.size();
for (size_t i = 0; i < size; i++) {
if (total_displays_.at(i)->IsConnected()) {
displays.emplace_back(total_displays_.at(i));
}
}
}
bool GpuDevice::EnableDRMCommit(bool enable, uint32_t display_id) {
size_t size = total_displays_.size();
bool ret = false;
if (size > display_id)
ret = total_displays_.at(display_id)->EnableDRMCommit(enable);
return ret;
}
void GpuDevice::MarkDisplayForFirstCommit() {
size_t size = total_displays_.size();
for (size_t i = 0; i < size; i++) {
if (total_displays_.at(i)->IsConnected()) {
total_displays_.at(i)->MarkFirstCommit();
}
}
}
bool GpuDevice::ResetDrmMaster(bool drop_master) {
bool ret = true;
if (drop_master) {
ResetAllDisplayCommit(false);
display_manager_->DropDrmMaster();
ITRACE("locking %s and monitoring if %s is unlocked.", HWC_LOCK_FILE,
HWC_LOCK_FILE);
// Resume GpuDevice thread to check hwc.lock and re-apply drm master.
lock_fd_ = open(HWC_LOCK_FILE, O_RDONLY);
if (-1 != lock_fd_) {
// Only resume GpuDevice thread for dropping DRM Master and
// the lock file exist.
Resume();
return !display_manager_->IsDrmMaster();
}
}
// In case of setDrmMaster or the lock file is not exist.
// Re-set DRM Master true.
display_manager_->setDrmMaster(false);
MarkDisplayForFirstCommit();
ResetAllDisplayCommit(true);
DisableWatch();
if (drop_master)
ret = !display_manager_->IsDrmMaster();
else
ret = display_manager_->IsDrmMaster();
return ret;
}
bool GpuDevice::IsDrmMaster() {
return display_manager_->IsDrmMaster();
}
const std::vector<NativeDisplay *> &GpuDevice::GetAllDisplays() {
return total_displays_;
}
void GpuDevice::RegisterHotPlugEventCallback(
std::shared_ptr<DisplayHotPlugEventCallback> callback) {
display_manager_->RegisterHotPlugEventCallback(callback);
}
bool GpuDevice::IsReservedDrmPlane() {
return reserve_plane_;
}
std::vector<uint32_t> GpuDevice::GetDisplayReservedPlanes(uint32_t display_id) {
std::map<uint8_t, std::vector<uint32_t>>::const_iterator pos =
reserved_drm_display_planes_map_.find(display_id);
if (pos == reserved_drm_display_planes_map_.end())
return std::vector<uint32_t>();
else
return pos->second;
}
void GpuDevice::ParsePlaneReserveSettings(std::string &value) {
std::string display_line_str;
std::string reserved_plane_index_str;
std::istringstream i_value(value);
// Get each display setting
while (std::getline(i_value, display_line_str, ';')) {
if (display_line_str.empty() ||
display_line_str.find_first_not_of("0123456789:+") != std::string::npos)
continue;
std::string display_index_str =
display_line_str.substr(0, display_line_str.find(":"));
uint8_t display_index = atoi(display_index_str.c_str());
std::string tmp = display_line_str.substr(display_line_str.find(":") + 1);
std::vector<uint32_t> reserved_drm_planes_;
std::istringstream planes_index_value(
display_line_str.substr(display_line_str.find(":") + 1));
// Get reversed drm plane index
while (std::getline(planes_index_value, reserved_plane_index_str, '+')) {
if (reserved_plane_index_str.empty() ||
reserved_plane_index_str.find_first_not_of("0123456789") !=
std::string::npos)
continue;
uint32_t reserved_plane_index_num =
atoi(reserved_plane_index_str.c_str());
// Check if the plane index is duplicated
bool skip_duplicate_plane = false;
size_t reserved_plane_size = reserved_drm_planes_.size();
for (size_t i = 0; i < reserved_plane_size; i++) {
if (reserved_drm_planes_.at(i) == reserved_plane_index_num) {
skip_duplicate_plane = true;
break;
}
}
if (skip_duplicate_plane) {
continue;
}
IPLANERESERVEDTRACE(
"Parsing configure for reserving display[%d], plane[%d]",
display_index, reserved_plane_index_num);
reserved_drm_planes_.emplace_back(reserved_plane_index_num);
}
reserved_drm_display_planes_map_[display_index] = reserved_drm_planes_;
}
}
#ifdef ENABLE_PANORAMA
void GpuDevice::ParsePanoramaDisplayConfig(
std::string &value, std::vector<std::vector<uint32_t>> &panorama_displays) {
std::istringstream i_value(value);
std::string i_panorama_split_str;
std::vector<uint32_t> panorama_duplicate_check;
// Got panorama sub display num
std::vector<uint32_t> panorama_display;
while (std::getline(i_value, i_panorama_split_str, '+')) {
if (i_panorama_split_str.empty() ||
i_panorama_split_str.find_first_not_of("0123456789") !=
std::string::npos)
continue;
size_t i_panorama_split_num = atoi(i_panorama_split_str.c_str());
// Check and skip if the display already been used in other panorama
bool skip_duplicate_display = false;
size_t panorama_size = panorama_duplicate_check.size();
for (size_t i = 0; i < panorama_size; i++) {
if (panorama_duplicate_check.at(i) == i_panorama_split_num) {
skip_duplicate_display = true;
break;
}
}
if (!skip_duplicate_display) {
// save the sub display num for the panorama display (don't care if
// the physical/logical display is existing/connected here)
panorama_display.emplace_back(i_panorama_split_num);
panorama_duplicate_check.emplace_back(i_panorama_split_num);
}
}
panorama_displays.emplace_back(panorama_display);
}
void GpuDevice::ParsePanoramaSOSDisplayConfig(
std::string &value,
std::vector<std::vector<uint32_t>> &panorama_sos_displays) {
std::istringstream i_value(value);
std::string i_panorama_sos_split_str;
std::vector<uint32_t> panorama_sos_duplicate_check;
// Got panorama sub display num
std::vector<uint32_t> panorama_sos_display;
while (std::getline(i_value, i_panorama_sos_split_str, '+')) {
if (i_panorama_sos_split_str.empty() ||
i_panorama_sos_split_str.find_first_not_of("0123456789") !=
std::string::npos)
continue;
size_t i_panorama_sos_split_num = atoi(i_panorama_sos_split_str.c_str());
// Check and skip if the display already been used in other panorama
bool skip_duplicate_display = false;
size_t panorama_sos_size = panorama_sos_duplicate_check.size();
for (size_t i = 0; i < panorama_sos_size; i++) {
if (panorama_sos_duplicate_check.at(i) == i_panorama_sos_split_num) {
skip_duplicate_display = true;
break;
}
}
if (!skip_duplicate_display) {
// save the sub display num for the panorama display (don't care if
// the physical/logical display is existing/connected here)
panorama_sos_display.emplace_back(i_panorama_sos_split_num);
panorama_sos_duplicate_check.emplace_back(i_panorama_sos_split_num);
}
}
panorama_sos_displays.emplace_back(panorama_sos_display);
}
void GpuDevice::InitializePanorama(
std::vector<NativeDisplay *> &total_displays_,
std::vector<NativeDisplay *> &temp_displays,
std::vector<std::vector<uint32_t>> &panorama_displays,
std::vector<std::vector<uint32_t>> &panorama_sos_displays,
std::vector<bool> &available_displays) {
std::vector<NativeDisplay *> i_available_panorama_displays;
temp_displays.swap(total_displays_);
// Add the virtual panorama displays mapping the SOS virtual displays.
size_t sos_displays_size = panorama_sos_displays.size();
for (size_t sos_it = 0; sos_it < sos_displays_size; sos_it++) {
NativeDisplay *virtualdisp = display_manager_->CreateVirtualPanoramaDisplay(
panorama_sos_displays.at(0).at(sos_it));
virtualdisp->InitVirtualDisplay(1920, 1080);
i_available_panorama_displays.emplace_back(virtualdisp);
virtual_panorama_displays_.emplace_back(virtualdisp);
}
// Add the native displays
size_t displays_size = temp_displays.size();
for (size_t t = 0; t < displays_size; t++) {
// Skip the displays which already be marked in other panorama
if (!available_displays.at(t)) {
ETRACE("display: %u is not present in the vector of avaialble_displays");
continue;
}
bool skip_display = false;
size_t panorama_size = panorama_displays.size();
for (size_t m = 0; m < panorama_size; m++) {
size_t panorama_inner_size = panorama_displays.at(m).size();
for (size_t l = 0; l < panorama_inner_size; l++) {
// Check if the logical display is in panorama, keep the order of
// logical displays list
// Get the smallest logical num of the panorama for order keeping
if (t == panorama_displays.at(m).at(l)) {
if (panorama_displays.at(m).at(l) < displays_size) {
// Skip the disconnected display here
i_available_panorama_displays.emplace_back(
temp_displays.at(panorama_displays.at(m).at(l)));
physical_panorama_displays_.emplace_back(
temp_displays.at(panorama_displays.at(m).at(l)));
// Add tag for panorama-ed displays
available_displays.at(panorama_displays.at(m).at(l)) = false;
}
skip_display = true;
break;
}
}
if (skip_display)
break;
}
}
// Create panorama for those logical displays
if (i_available_panorama_displays.size() > 0) {
std::unique_ptr<MosaicDisplay> panorama(
new MosaicDisplay(i_available_panorama_displays));
panorama->SetPanoramaMode(true);
panorama->SetExtraDispInfo(&virtual_panorama_displays_,
&physical_panorama_displays_);
ptr_mosaicdisplay = (MosaicDisplay *)panorama.get();
panorama_displays_.emplace_back(std::move(panorama));
// Save the panorama to the final displays list
total_displays_.emplace_back(panorama_displays_.back().get());
}
}
bool GpuDevice::TriggerPanorama(uint32_t hotplug_simulation) {
bool ret = false;
if (ptr_mosaicdisplay) {
ret = ptr_mosaicdisplay->TriggerPanorama(hotplug_simulation);
}
return ret;
}
bool GpuDevice::ShutdownPanorama(uint32_t hotplug_simulation) {
bool ret = false;
if (ptr_mosaicdisplay) {
ret = ptr_mosaicdisplay->ShutdownPanorama(hotplug_simulation);
}
return ret;
}
#endif
void GpuDevice::ParseLogicalDisplaySetting(
std::string &value, std::vector<uint32_t> &logical_displays) {
std::istringstream i_value(value);
std::string physical_index_str;
std::getline(i_value, physical_index_str, ':');
if (physical_index_str.empty() ||
physical_index_str.find_first_not_of("0123456789") != std::string::npos)
return;
std::string logical_split_str;
// Got split num
std::getline(i_value, logical_split_str, ':');
if (logical_split_str.empty() ||
logical_split_str.find_first_not_of("0123456789") != std::string::npos)
return;
if (physical_index_str.length() > 1)
return;
uint32_t physical_index = atoi(physical_index_str.c_str());
uint32_t logical_split_num = atoi(logical_split_str.c_str());
if (logical_split_num <= 1)
return;
// Set logical num 1 for physical display which is not in config
while (physical_index > logical_displays.size()) {
logical_displays.emplace_back(1);
}
// Save logical split num for the physical display (don't care if the
// physical display is disconnected/connected here)
logical_displays.emplace_back(logical_split_num);
// Got mosaic config
}
void GpuDevice::ParseMosaicDisplaySetting(
std::string &value, std::vector<std::vector<uint32_t>> &mosaic_displays) {
std::istringstream i_value(value);
std::string i_mosaic_split_str;
std::vector<uint32_t> mosaic_duplicate_check;
// Got mosaic sub display num
std::vector<uint32_t> mosaic_display;
while (std::getline(i_value, i_mosaic_split_str, '+')) {
if (i_mosaic_split_str.empty() ||
i_mosaic_split_str.find_first_not_of("0123456789") != std::string::npos)
continue;
size_t i_mosaic_split_num = atoi(i_mosaic_split_str.c_str());
// Check and skip if the display already been used in other mosaic
bool skip_duplicate_display = false;
size_t mosaic_size = mosaic_duplicate_check.size();
for (size_t i = 0; i < mosaic_size; i++) {
if (mosaic_duplicate_check.at(i) == i_mosaic_split_num) {
skip_duplicate_display = true;
break;
}
}
if (!skip_duplicate_display) {
// save the sub display num for the mosaic display (don't care
// if
// the physical/logical display is existing/connected here)
mosaic_display.emplace_back(i_mosaic_split_num);
mosaic_duplicate_check.emplace_back(i_mosaic_split_num);
}
}
mosaic_displays.emplace_back(mosaic_display);
}
void GpuDevice::ParsePhysicalDisplaySetting(
std::string &value, std::vector<uint32_t> &physical_displays) {
std::istringstream i_value(value);
std::string physical_split_str;
std::vector<uint32_t> physical_duplicate_check;
// Got physical display num
while (std::getline(i_value, physical_split_str, ':')) {
if (physical_split_str.empty() ||
physical_split_str.find_first_not_of("0123456789") != std::string::npos)
continue;
size_t physical_split_num = atoi(physical_split_str.c_str());
// Check and skip if the display already been used in other mosaic
bool skip_duplicate_display = false;
size_t physical_size = physical_duplicate_check.size();
for (size_t i = 0; i < physical_size; i++) {
if (physical_duplicate_check.at(i) == physical_split_num) {
skip_duplicate_display = true;
break;
}
}
if (!skip_duplicate_display) {
physical_displays.emplace_back(physical_split_num);
physical_duplicate_check.emplace_back(physical_split_num);
}
}
}
void GpuDevice::ParseCloneDisplaySetting(
std::string &value, std::vector<std::vector<uint32_t>> &cloned_displays) {
std::istringstream i_value(value);
std::string i_clone_split_str;
std::vector<uint32_t> clone_duplicate_check;
// Got clone sub display num
std::vector<uint32_t> clone_display;
while (std::getline(i_value, i_clone_split_str, '+')) {
if (i_clone_split_str.empty() ||
i_clone_split_str.find_first_not_of("0123456789") != std::string::npos)
continue;
size_t i_clone_split_num = atoi(i_clone_split_str.c_str());
// Check and skip if the display already been used in other clone
bool skip_duplicate_display = false;
size_t clone_size = clone_duplicate_check.size();
for (size_t i = 0; i < clone_size; i++) {
if (clone_duplicate_check.at(i) == i_clone_split_num) {
skip_duplicate_display = true;
break;
}
}
if (!skip_duplicate_display) {
// save the sub display num for the mosaic display (don't care
// if
// the physical/logical display is existing/connected here)
clone_display.emplace_back(i_clone_split_num);
clone_duplicate_check.emplace_back(i_clone_split_num);
}
}
cloned_displays.emplace_back(clone_display);
}
void GpuDevice::ParsePhysicalDisplayRotation(
std::string &value, std::vector<uint32_t> &display_rotation,
std::vector<uint32_t> &rotation_display_index) {
std::istringstream i_value(value);
std::string physical_index_str;
std::getline(i_value, physical_index_str, ':');
if (physical_index_str.empty() ||
physical_index_str.find_first_not_of("0123456789") != std::string::npos)
return;
uint32_t physical_index = atoi(physical_index_str.c_str());
// Check and skip if the display is already in use.
bool skip_duplicate_display = false;
size_t rotation_size = rotation_display_index.size();
for (size_t i = 0; i < rotation_size; i++) {
if (rotation_display_index.at(i) == physical_index) {
skip_duplicate_display = true;
break;
}
}
if (skip_duplicate_display) {
return;
}
std::string rotation_str;
// Got split num
std::getline(i_value, rotation_str, ':');
if (rotation_str.empty() ||
rotation_str.find_first_not_of("0123") != std::string::npos)
return;
uint32_t rotation_num = atoi(rotation_str.c_str());
display_rotation.emplace_back(rotation_num);
rotation_display_index.emplace_back(physical_index);
}
void GpuDevice::ParseFloatDisplaySetting(
std::string &value, std::vector<HwcRect<int32_t>> &float_displays,
std::vector<uint32_t> &float_display_indices) {
std::istringstream i_value(value);
std::string index_str;
std::string float_rect_str;
std::vector<int32_t> float_rect;
// Got display index
std::getline(i_value, index_str, ':');
if (index_str.empty() ||
index_str.find_first_not_of("0123456789") != std::string::npos) {
return;
}
int32_t index = atoi(index_str.c_str());
// Got rectangle configuration
while (std::getline(i_value, float_rect_str, '+')) {
if (float_rect_str.empty() ||
float_rect_str.find_first_not_of("0123456789") != std::string::npos) {
continue;
}
size_t float_rect_val = atoi(float_rect_str.c_str());
// Save the rectangle - left, top, right & bottom
float_rect.emplace_back(float_rect_val);
}
// If entire rect is available, store the parameters
// TODO remove hard code
if (float_rect.size() == 4) {
float_display_indices.emplace_back(index);
HwcRect<int32_t> rect = HwcRect<int32_t>(
float_rect.at(0), float_rect.at(1), float_rect.at(2), float_rect.at(3));
float_displays.emplace_back(rect);
}
}
void GpuDevice::InitializeDisplayIndex(std::vector<uint32_t> &physical_displays,
std::vector<NativeDisplay *> &displays) {
std::vector<NativeDisplay *> unordered_displays =
display_manager_->GetAllDisplays();
size_t size = unordered_displays.size();
uint32_t dispmgr_display_size = (uint32_t)size;
if (physical_displays.empty()) {
displays.swap(unordered_displays);
} else {
size = physical_displays.size();
for (size_t i = 0; i < size; i++) {
uint32_t pdisp_index = physical_displays.at(i);
// Add the physical display only if it has been enumerated from DRM API.
// Skip the non-existence display defined in hwc_display.ini file.
if (pdisp_index < dispmgr_display_size) {
displays.emplace_back(unordered_displays.at(pdisp_index));
} else {
ETRACE(
"Physical display number: %u defined in hwc_display.ini "
"doesn't exist in enumerated DRM display list (total: %u).",
pdisp_index, dispmgr_display_size);
}
}
if (displays.size() != unordered_displays.size()) {
size = unordered_displays.size();
for (size_t i = 0; i < size; i++) {
NativeDisplay *display = unordered_displays.at(i);
uint32_t temp = displays.size();
for (size_t i = 0; i < temp; i++) {
if (displays.at(i) == display) {
display = NULL;
break;
}
}
if (display) {
displays.emplace_back(display);
}
}
}
}
// Re-order displays based on connection status.
std::vector<NativeDisplay *> connected_displays;
std::vector<NativeDisplay *> un_connected_displays;
size = displays.size();
for (size_t i = 0; i < size; i++) {
NativeDisplay *temp = displays.at(i);
if (temp->IsConnected()) {
connected_displays.emplace_back(temp);
} else {
un_connected_displays.emplace_back(temp);
}
}
displays.swap(connected_displays);
if (!un_connected_displays.empty()) {
size_t temp = un_connected_displays.size();
for (size_t i = 0; i < temp; i++) {
displays.emplace_back(un_connected_displays.at(i));
}
}
for (size_t i = 0; i < size; i++) {
displays.at(i)->SetDisplayOrder(i);
}
}
void GpuDevice::InitializeDisplayRotation(
std::vector<uint32_t> &display_rotation,
std::vector<uint32_t> &rotation_display_index,
std::vector<NativeDisplay *> &displays) {
size_t rotation_size = rotation_display_index.size();
for (size_t i = 0; i < rotation_size; i++) {
HWCRotation rotation = static_cast<HWCRotation>(display_rotation.at(i));
displays.at(rotation_display_index.at(i))->RotateDisplay(rotation);
}
}
void GpuDevice::InitializeLogicalDisplay(
std::vector<uint32_t> &logical_displays,
std::vector<NativeDisplay *> &displays,
std::vector<NativeDisplay *> &temp_displays, bool use_logical) {
size_t size = displays.size();
for (size_t i = 0; i < size; i++) {
hwcomposer::NativeDisplay *display = displays.at(i);
// Save logical displays to temp_displays, skip the physical display
if (use_logical && (logical_displays.size() >= i + 1) &&
logical_displays[i] > 1) {
std::unique_ptr<LogicalDisplayManager> manager(
new LogicalDisplayManager(display));
logical_display_manager_.emplace_back(std::move(manager));
// don't care if the displays is connected/disconnected here
logical_display_manager_.back()->InitializeLogicalDisplays(
logical_displays[i]);
std::vector<LogicalDisplay *> temp_logical_displays;
logical_display_manager_.back()->GetLogicalDisplays(
temp_logical_displays);
size_t logical_display_total_size = temp_logical_displays.size();
for (size_t j = 0; j < logical_display_total_size; j++) {
temp_displays.emplace_back(temp_logical_displays.at(j));
}
// Save no split physical displays to temp_displays
} else {
temp_displays.emplace_back(display);
}
}
}
void GpuDevice::InitializeMosaicDisplay(
std::vector<NativeDisplay *> &total_displays_,
std::vector<std::vector<uint32_t>> &mosaic_displays,
std::vector<NativeDisplay *> &temp_displays,
std::vector<bool> &available_displays) {
size_t displays_size = temp_displays.size();
for (size_t t = 0; t < displays_size; t++) {
// Skip the displays which already be marked in other mosaic
if (!available_displays.at(t))
continue;
bool skip_display = false;
size_t mosaic_size = mosaic_displays.size();
for (size_t m = 0; m < mosaic_size; m++) {
std::vector<NativeDisplay *> i_available_mosaic_displays;
size_t mosaic_inner_size = mosaic_displays.at(m).size();
for (size_t l = 0; l < mosaic_inner_size; l++) {
// Check if the logical display is in mosaic, keep the order of
// logical displays list
// Get the smallest logical num of the mosaic for order keeping
if (t == mosaic_displays.at(m).at(l)) {
// Loop to get logical displays of mosaic, keep the order of config
for (size_t i = 0; i < mosaic_inner_size; i++) {
// Verify the logical display num
if (mosaic_displays.at(m).at(i) < displays_size) {
// Skip the disconnected display here
i_available_mosaic_displays.emplace_back(
temp_displays.at(mosaic_displays.at(m).at(i)));
// Add tag for mosaic-ed displays
available_displays.at(mosaic_displays.at(m).at(i)) = false;
}
}
// Create mosaic for those logical displays
if (i_available_mosaic_displays.size() > 0) {
std::unique_ptr<MosaicDisplay> mosaic(
new MosaicDisplay(i_available_mosaic_displays));
mosaic_displays_.emplace_back(std::move(mosaic));
// Save the mosaic to the final displays list
total_displays_.emplace_back(mosaic_displays_.back().get());
}
skip_display = true;
break;
}
}
if (skip_display)
break;
}
if (!skip_display) {
total_displays_.emplace_back(temp_displays.at(t));
}
}
}
void GpuDevice::InitializeCloneDisplay(
std::vector<NativeDisplay *> &total_displays_,
std::vector<std::vector<uint32_t>> &cloned_displays) {
std::vector<NativeDisplay *> temp_displays;
size_t displays_size = total_displays_.size();
size_t cloned_displays_size = cloned_displays.size();
for (size_t c = 0; c < cloned_displays_size; c++) {
std::vector<uint32_t> &temp = cloned_displays.at(c);
if (!temp.empty() && temp.size() >= 2) {
size_t c_size = temp.size();
if (total_displays_.size() > temp.at(0)) {
NativeDisplay *physical_display = total_displays_.at(temp.at(0));
for (size_t clone = 1; clone < c_size; clone++) {
if (total_displays_.size() > temp.at(clone))
total_displays_.at(temp.at(clone))->CloneDisplay(physical_display);
}
}
}
}
for (size_t t = 0; t < displays_size; t++) {
bool found = false;
for (size_t c = 0; c < cloned_displays_size; c++) {
std::vector<uint32_t> &temp = cloned_displays.at(c);
size_t c_size = temp.size();
for (size_t clone = 1; clone < c_size; clone++) {
uint32_t temp_clone = temp.at(clone);
if (temp_clone == t) {
found = true;
break;
}
}
if (found) {
break;
}
}
// Don't advertise cloned display as another independent
// Physical Display.
if (found) {
continue;
}
temp_displays.emplace_back(total_displays_.at(t));
}
temp_displays.swap(total_displays_);
}
void GpuDevice::InitializeFloatDisplay(
std::vector<NativeDisplay *> &total_displays_,
std::vector<HwcRect<int32_t>> &float_displays,
std::vector<uint32_t> &float_display_indices) {
bool ret = false;
size_t size = float_display_indices.size();
size_t num_displays = total_displays_.size();
// Set custom resolution to desired display instance
for (size_t i = 0; i < size; i++) {
int index = float_display_indices.at(i);
// Ignore float index if out of range of connected displays
if ((size_t)index < num_displays) {
const HwcRect<int32_t> &rect = float_displays.at(i);
ret = total_displays_.at(index)->SetCustomResolution(rect);
}
}
}
void GpuDevice::CheckGvtActive() {
int fd = GetFD();
int gvt_active = 0;
int ret = drm_intel_get_gvt_active(fd, &gvt_active);
if (ret) {
ITRACE(
"Fail to get GVT active from kernel, set active as true by default.");
gvt_active_ = true;
} else {
if (gvt_active) {
gvt_active_ = true;
ITRACE("Running on vGPU (GVT-g) mode");
} else {
gvt_active_ = false;
ITRACE("Running on bare-metal mode");
}
}
}
void GpuDevice::HandleHWCSettings() {
// Handle config file reading
// check if running with GVT to decide load KVM/native config
std::string hwc_dp_cfg_path_str;
if (IsGvtActive())
hwc_dp_cfg_path_str = KVM_HWC_DISPLAY_INI_PATH;
else
hwc_dp_cfg_path_str = HWC_DISPLAY_INI_PATH;
const char *hwc_dp_cfg_path = hwc_dp_cfg_path_str.c_str();
ITRACE("Hwc display config file is %s", hwc_dp_cfg_path);
bool use_logical = false;
bool use_mosaic = false;
bool use_cloned = false;
bool rotate_display = false;
bool use_float = false;
std::vector<uint32_t> logical_displays;
std::vector<uint32_t> physical_displays;
std::vector<uint32_t> display_rotation;
std::vector<uint32_t> float_display_indices;
std::vector<uint32_t> rotation_display_index;
std::vector<HwcRect<int32_t>> float_displays;
std::vector<std::vector<uint32_t>> cloned_displays;
std::vector<std::vector<uint32_t>> mosaic_displays;
#ifdef ENABLE_PANORAMA
bool use_panorama = false;
std::vector<std::vector<uint32_t>> panorama_displays;
std::vector<std::vector<uint32_t>> panorama_sos_displays;
#endif
std::ifstream fin(hwc_dp_cfg_path);
std::string cfg_line;
std::string key_logical("LOGICAL");
std::string key_mosaic("MOSAIC");
std::string key_clone("CLONE");
std::string key_rotate("ROTATION");
std::string key_float("FLOAT");
std::string key_plane_reserved("PLANE_RESERVED");
std::string key_logical_display("LOGICAL_DISPLAY");
std::string key_mosaic_display("MOSAIC_DISPLAY");
std::string key_physical_display("PHYSICAL_DISPLAY");
std::string key_physical_display_rotation("PHYSICAL_DISPLAY_ROTATION");
std::string key_clone_display("CLONE_DISPLAY");
std::string key_float_display("FLOAT_DISPLAY");
#ifdef ENABLE_PANORAMA
std::string key_panorama("PANORAMA");
std::string key_panorama_display("PANORAMA_DISPLAY");
std::string key_panorama_sos_display("PANORAMA_SOS_DISPLAY");
#endif
std::string key_reserved_drm_plane("DRM_PLANE_RESERVED");
while (std::getline(fin, cfg_line)) {
std::istringstream i_line(cfg_line);
std::string key;
// Skip comments
if (cfg_line[0] != '#' && std::getline(i_line, key, '=')) {
std::string content;
std::string value;
std::getline(i_line, content, '=');
std::istringstream i_content(content);
while (std::getline(i_content, value, '"')) {
if (value.empty())
continue;
std::string enable_str("true");
// Got logical switch
if (!key.compare(key_logical)) {
if (!value.compare(enable_str)) {
use_logical = true;
}
// Got mosaic switch
} else if (!key.compare(key_mosaic)) {
if (!value.compare(enable_str)) {
use_mosaic = true;
}
#ifdef ENABLE_PANORAMA
// Got panorama switch
} else if (!key.compare(key_panorama)) {
if (!value.compare(enable_str)) {
use_panorama = true;
}
#endif
// Got clone switch
} else if (!key.compare(key_clone)) {
if (!value.compare(enable_str)) {
use_cloned = true;
}
// Got rotation switch.
} else if (!key.compare(key_rotate)) {
if (!value.compare(enable_str)) {
rotate_display = true;
}
// Got float switch
} else if (!key.compare(key_float)) {
if (!value.compare(enable_str)) {
use_float = true;
}
} else if (!key.compare(key_plane_reserved)) {
if (!value.compare(enable_str)) {
reserve_plane_ = true;
}
// Got logical display index
} else if (!key.compare(key_logical_display)) {
ParseLogicalDisplaySetting(value, logical_displays);
// Got mosaic config
} else if (!key.compare(key_mosaic_display)) {
ParseMosaicDisplaySetting(value, mosaic_displays);
#ifdef ENABLE_PANORAMA
// Got panorama config
} else if (!key.compare(key_panorama_display)) {
ParsePanoramaDisplayConfig(value, panorama_displays);
size_t panorama_displays_size = panorama_displays.size();
// Got panorama sos config
} else if (!key.compare(key_panorama_sos_display)) {
ParsePanoramaSOSDisplayConfig(value, panorama_sos_displays);
size_t panorama_sos_displays_size = panorama_sos_displays.size();
#endif
// Got physical display config
} else if (!key.compare(key_physical_display)) {
ParsePhysicalDisplaySetting(value, physical_displays);
// Got clone display config
} else if (!key.compare(key_clone_display)) {
ParseCloneDisplaySetting(value, cloned_displays);
// Got physical display rotation config
} else if (!key.compare(key_physical_display_rotation)) {
ParsePhysicalDisplayRotation(value, display_rotation,
rotation_display_index);
// Got float display config
} else if (!key.compare(key_float_display)) {
ParseFloatDisplaySetting(value, float_displays,
float_display_indices);
// Got plan reserve config
} else if (!key.compare(key_reserved_drm_plane)) {
ParsePlaneReserveSettings(value);
}
}
}
};
std::vector<NativeDisplay *> displays;
InitializeDisplayIndex(physical_displays, displays);
// We should have all displays ordered. Apply rotation settings.
if (rotate_display) {
InitializeDisplayRotation(display_rotation, rotation_display_index,
displays);
}