1 // Copyright (C) 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <stdint.h>                                         // for uint32_t
16 #include <map>                                              // for map, __ma...
17 #include <utility>                                          // for pair
18 
19 #include "host-common/MultiDisplay.h"                 // for MultiDisp...
20 #include "host-common/multi_display_agent.h"  // for QAndroidM...
21 
22 static std::map<uint32_t, android::MultiDisplayInfo> mMultiDisplay;
23 static const QAndroidMultiDisplayAgent sMultiDisplayAgent = {
24         .setMultiDisplay = [](uint32_t id,
25                               int32_t x,
26                               int32_t y,
27                               uint32_t w,
28                               uint32_t h,
29                               uint32_t dpi,
30                               uint32_t flag,
__anonf83c99110102() 31                               bool add) -> int{
32             return 0;
33         },
34         .getMultiDisplay = [](uint32_t id,
35                              int32_t* x,
36                              int32_t* y,
37                              uint32_t* w,
38                              uint32_t* h,
39                              uint32_t* dpi,
40                              uint32_t* flag,
__anonf83c99110202() 41                              bool* enable) -> bool{
42             return true;
43         },
44         .getNextMultiDisplay = [](int32_t start_id,
45                                 uint32_t* id,
46                                 int32_t* x,
47                                 int32_t* y,
48                                 uint32_t* w,
49                                 uint32_t* h,
50                                 uint32_t* dpi,
51                                 uint32_t* flag,
__anonf83c99110302() 52                                 uint32_t* cb) -> bool {
53             uint32_t key;
54             std::map<uint32_t, android::MultiDisplayInfo>::iterator i;
55             if (start_id < 0) {
56                 key = 0;
57             } else {
58                 key = start_id + 1;
59             }
60             i = mMultiDisplay.lower_bound(key);
61             if (i == mMultiDisplay.end()) {
62                 return false;
63             } else {
64                 if (id) {
65                     *id = i->first;
66                 }
67                 if (x) {
68                     *x = i->second.pos_x;
69                 }
70                 if (y) {
71                     *y = i->second.pos_y;
72                 }
73                 if (w) {
74                     *w = i->second.width;
75                 }
76                 if (h) {
77                     *h = i->second.height;
78                 }
79                 if (dpi) {
80                     *dpi = i->second.dpi;
81                 }
82                 if (flag) {
83                     *flag = i->second.flag;
84                 }
85                 if (cb) {
86                     *cb = i->second.cb;
87                 }
88                 return true;
89             }
90         },
__anonf83c99110402() 91         .isMultiDisplayEnabled = [](void) -> bool {
92             return mMultiDisplay.size() > 1;
93         },
__anonf83c99110502() 94         .getCombinedDisplaySize = [](uint32_t* width, uint32_t* height) {
95         },
96         .multiDisplayParamValidate = [](uint32_t id,
97                                         uint32_t w,
98                                         uint32_t h,
99                                         uint32_t dpi,
__anonf83c99110602() 100                                         uint32_t flag) -> bool {
101             return true;
102         },
103         .translateCoordination = [](uint32_t* x,
104                                     uint32_t*y,
__anonf83c99110702() 105                                     uint32_t* displayId) -> bool {
106             return true;
107         },
__anonf83c99110802() 108         .setGpuMode = [](bool isGuestMode, uint32_t w, uint32_t h) { },
__anonf83c99110902() 109         .createDisplay = [](uint32_t* displayId) -> int {
110             mMultiDisplay.emplace(*displayId, android::MultiDisplayInfo());
111             return 0;
112         },
__anonf83c99110a02() 113         .destroyDisplay = [](uint32_t displayId) -> int {
114             mMultiDisplay.erase(displayId);
115             return 0;
116         },
117         .setDisplayPose = [](uint32_t displayId,
118                              int32_t x,
119                              int32_t y,
120                              uint32_t w,
121                              uint32_t h,
__anonf83c99110b02() 122                              uint32_t dpi) -> int {
123             mMultiDisplay[displayId].pos_x = x;
124             mMultiDisplay[displayId].pos_y = y;
125             mMultiDisplay[displayId].width = w;
126             mMultiDisplay[displayId].height = h;
127             mMultiDisplay[displayId].dpi = dpi;
128             return 0;
129         },
130         .getDisplayPose = [](uint32_t displayId,
131                             int32_t* x,
132                             int32_t* y,
133                             uint32_t* w,
__anonf83c99110c02() 134                             uint32_t* h) -> int {
135             *x = mMultiDisplay[displayId].pos_x;
136             *y = mMultiDisplay[displayId].pos_y;
137             *w = mMultiDisplay[displayId].width;
138             *h = mMultiDisplay[displayId].height;
139             return 0;
140         },
141         .getDisplayColorBuffer = [](uint32_t displayId,
__anonf83c99110d02() 142                                     uint32_t* colorBuffer) -> int {
143             *colorBuffer = mMultiDisplay[displayId].cb;
144             return 0;
145          },
146          .getColorBufferDisplay = [](uint32_t colorBuffer,
__anonf83c99110e02() 147                                      uint32_t* displayId) -> int {
148             for (const auto& iter : mMultiDisplay) {
149                 if (iter.second.cb == colorBuffer) {
150                     *displayId = iter.first;
151                     return 0;
152                 }
153             }
154             return -1;
155         },
156         .setDisplayColorBuffer = [](uint32_t displayId,
__anonf83c99110f02() 157                                     uint32_t colorBuffer) -> int {
158             mMultiDisplay[displayId].cb = colorBuffer;
159             return 0;
160         }
161 };
162 extern "C" const QAndroidMultiDisplayAgent* const
163         gMockQAndroidMultiDisplayAgent = &sMultiDisplayAgent;
164