1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.1
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "SurfaceFlingerConfigs.h"
18
19 #include <android/hardware/configstore/1.1/types.h>
20 #include <log/log.h>
21
22 namespace android {
23 namespace hardware {
24 namespace configstore {
25 namespace V1_1 {
26 namespace implementation {
27
28 // Methods from ::android::hardware::configstore::V1_0::ISurfaceFlingerConfigs
29 // follow.
vsyncEventPhaseOffsetNs(vsyncEventPhaseOffsetNs_cb _hidl_cb)30 Return<void> SurfaceFlingerConfigs::vsyncEventPhaseOffsetNs(vsyncEventPhaseOffsetNs_cb _hidl_cb) {
31 #ifdef VSYNC_EVENT_PHASE_OFFSET_NS
32 _hidl_cb({true, VSYNC_EVENT_PHASE_OFFSET_NS});
33 #else
34 _hidl_cb({false, 0});
35 #endif
36 return Void();
37 }
38
vsyncSfEventPhaseOffsetNs(vsyncEventPhaseOffsetNs_cb _hidl_cb)39 Return<void> SurfaceFlingerConfigs::vsyncSfEventPhaseOffsetNs(vsyncEventPhaseOffsetNs_cb _hidl_cb) {
40 #ifdef SF_VSYNC_EVENT_PHASE_OFFSET_NS
41 _hidl_cb({true, SF_VSYNC_EVENT_PHASE_OFFSET_NS});
42 #else
43 _hidl_cb({false, 0});
44 #endif
45 return Void();
46 }
47
useContextPriority(useContextPriority_cb _hidl_cb)48 Return<void> SurfaceFlingerConfigs::useContextPriority(useContextPriority_cb _hidl_cb) {
49 #ifdef USE_CONTEXT_PRIORITY
50 _hidl_cb({true, USE_CONTEXT_PRIORITY});
51 #else
52 _hidl_cb({false, false});
53 #endif
54 return Void();
55 }
56
maxFrameBufferAcquiredBuffers(maxFrameBufferAcquiredBuffers_cb _hidl_cb)57 Return<void> SurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers(
58 maxFrameBufferAcquiredBuffers_cb _hidl_cb) {
59 #ifdef NUM_FRAMEBUFFER_SURFACE_BUFFERS
60 _hidl_cb({true, NUM_FRAMEBUFFER_SURFACE_BUFFERS});
61 #else
62 _hidl_cb({false, 0});
63 #endif
64 return Void();
65 }
66
hasWideColorDisplay(hasWideColorDisplay_cb _hidl_cb)67 Return<void> SurfaceFlingerConfigs::hasWideColorDisplay(hasWideColorDisplay_cb _hidl_cb) {
68 bool value = false;
69 #ifdef HAS_WIDE_COLOR_DISPLAY
70 value = true;
71 #endif
72 _hidl_cb({true, value});
73 return Void();
74 }
75
hasSyncFramework(hasSyncFramework_cb _hidl_cb)76 Return<void> SurfaceFlingerConfigs::hasSyncFramework(hasSyncFramework_cb _hidl_cb) {
77 bool value = true;
78 #ifdef RUNNING_WITHOUT_SYNC_FRAMEWORK
79 value = false;
80 #endif
81 _hidl_cb({true, value});
82 return Void();
83 }
84
hasHDRDisplay(hasHDRDisplay_cb _hidl_cb)85 Return<void> SurfaceFlingerConfigs::hasHDRDisplay(hasHDRDisplay_cb _hidl_cb) {
86 bool value = false;
87 #ifdef HAS_HDR_DISPLAY
88 value = true;
89 #endif
90 _hidl_cb({true, value});
91 return Void();
92 }
93
presentTimeOffsetFromVSyncNs(presentTimeOffsetFromVSyncNs_cb _hidl_cb)94 Return<void> SurfaceFlingerConfigs::presentTimeOffsetFromVSyncNs(
95 presentTimeOffsetFromVSyncNs_cb _hidl_cb) {
96 #ifdef PRESENT_TIME_OFFSET_FROM_VSYNC_NS
97 _hidl_cb({true, PRESENT_TIME_OFFSET_FROM_VSYNC_NS});
98 #else
99 _hidl_cb({false, 0});
100 #endif
101 return Void();
102 }
103
useHwcForRGBtoYUV(useHwcForRGBtoYUV_cb _hidl_cb)104 Return<void> SurfaceFlingerConfigs::useHwcForRGBtoYUV(useHwcForRGBtoYUV_cb _hidl_cb) {
105 bool value = false;
106 #ifdef FORCE_HWC_COPY_FOR_VIRTUAL_DISPLAYS
107 value = true;
108 #endif
109 _hidl_cb({true, value});
110 return Void();
111 }
112
maxVirtualDisplaySize(maxVirtualDisplaySize_cb _hidl_cb)113 Return<void> SurfaceFlingerConfigs::maxVirtualDisplaySize(maxVirtualDisplaySize_cb _hidl_cb) {
114 uint64_t maxSize = 0;
115 #ifdef MAX_VIRTUAL_DISPLAY_DIMENSION
116 maxSize = MAX_VIRTUAL_DISPLAY_DIMENSION;
117 _hidl_cb({true, maxSize});
118 #else
119 _hidl_cb({false, maxSize});
120 #endif
121 return Void();
122 }
123
useVrFlinger(useVrFlinger_cb _hidl_cb)124 Return<void> SurfaceFlingerConfigs::useVrFlinger(useVrFlinger_cb _hidl_cb) {
125 bool value = false;
126 bool specified = false;
127 #ifdef USE_VR_FLINGER
128 value = true;
129 specified = true;
130 #endif
131 _hidl_cb({specified, value});
132 return Void();
133 }
134
startGraphicsAllocatorService(startGraphicsAllocatorService_cb _hidl_cb)135 Return<void> SurfaceFlingerConfigs::startGraphicsAllocatorService(
136 startGraphicsAllocatorService_cb _hidl_cb) {
137 bool value = false;
138 #ifdef START_GRAPHICS_ALLOCATOR_SERVICE
139 value = true;
140 #endif
141 _hidl_cb({true, value});
142 return Void();
143 }
144
145 // Methods from ::android::hardware::configstore::V1_1::ISurfaceFlingerConfigs
146 // follow.
147
148 #ifdef PRIMARY_DISPLAY_ORIENTATION
149 static_assert(PRIMARY_DISPLAY_ORIENTATION == 0 || PRIMARY_DISPLAY_ORIENTATION == 90 ||
150 PRIMARY_DISPLAY_ORIENTATION == 180 || PRIMARY_DISPLAY_ORIENTATION == 270,
151 "Primary display orientation must be 0/90/180/270");
152 #endif
153
primaryDisplayOrientation(primaryDisplayOrientation_cb _hidl_cb)154 Return<void> SurfaceFlingerConfigs::primaryDisplayOrientation(
155 primaryDisplayOrientation_cb _hidl_cb) {
156 using ::android::hardware::configstore::V1_1::DisplayOrientation;
157
158 bool specified = false;
159 DisplayOrientation value = DisplayOrientation::ORIENTATION_0;
160
161 int orientation = 0;
162 #ifdef PRIMARY_DISPLAY_ORIENTATION
163 specified = true;
164 orientation = PRIMARY_DISPLAY_ORIENTATION;
165 #endif
166
167 switch (orientation) {
168 case 0: {
169 value = DisplayOrientation::ORIENTATION_0;
170 break;
171 }
172 case 90: {
173 value = DisplayOrientation::ORIENTATION_90;
174 break;
175 }
176 case 180: {
177 value = DisplayOrientation::ORIENTATION_180;
178 break;
179 }
180 case 270: {
181 value = DisplayOrientation::ORIENTATION_270;
182 break;
183 }
184 default: {
185 // statically checked above -> memory corruption
186 LOG_ALWAYS_FATAL("Invalid orientation %d", orientation);
187 }
188 }
189
190 _hidl_cb({specified, value});
191 return Void();
192 }
193
194 // Methods from ::android::hidl::base::V1_0::IBase follow.
195
196 } // namespace implementation
197 } // namespace V1_1
198 } // namespace configstore
199 } // namespace hardware
200 } // namespace android
201