blob: daa26564f461ca2bb18b92df1fd8f70e384f2caf [file] [log] [blame]
Yin-Chia Yehb97babb2015-03-12 13:42:44 -07001/*
2**
Shuzhen Wangc28189a2017-11-27 23:05:10 -08003** Copyright 2015-2018, The Android Open Source Project
Yin-Chia Yehb97babb2015-03-12 13:42:44 -07004**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "OutputConfiguration"
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080019//#define LOG_NDEBUG 0
20
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070021#include <utils/Log.h>
22
23#include <camera/camera2/OutputConfiguration.h>
Austin Borger71d8f672023-06-01 16:51:35 -070024#include <camera/StringUtils.h>
Shuzhen Wang38df0ca2024-10-09 11:33:44 -070025#include <com_android_internal_camera_flags.h>
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070026#include <binder/Parcel.h>
Mathias Agopian032845c2017-02-08 17:05:02 -080027#include <gui/view/Surface.h>
Emilian Peev2295df72021-11-12 18:14:10 -080028#include <system/camera_metadata.h>
Shuzhen Wang0709c282024-02-12 09:09:32 -080029#include <system/graphics.h>
Brian Andersonf6753562016-10-11 14:51:05 -070030#include <utils/String8.h>
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070031
Shuzhen Wang38df0ca2024-10-09 11:33:44 -070032namespace flags = com::android::internal::camera::flags;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070033
Austin Borger9e2b27c2022-07-15 11:27:24 -070034namespace android {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070035
36const int OutputConfiguration::INVALID_ROTATION = -1;
Zhijun He018107a2016-01-18 15:32:50 -080037const int OutputConfiguration::INVALID_SET_ID = -1;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070038
Shuzhen Wang0129d522016-10-30 22:43:41 -070039const std::vector<sp<IGraphicBufferProducer>>&
40 OutputConfiguration::getGraphicBufferProducers() const {
41 return mGbps;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070042}
43
44int OutputConfiguration::getRotation() const {
45 return mRotation;
46}
47
Zhijun He018107a2016-01-18 15:32:50 -080048int OutputConfiguration::getSurfaceSetID() const {
49 return mSurfaceSetID;
50}
51
Zhijun He5d677d12016-05-29 16:52:39 -070052int OutputConfiguration::getSurfaceType() const {
53 return mSurfaceType;
54}
55
56int OutputConfiguration::getWidth() const {
57 return mWidth;
58}
59
60int OutputConfiguration::getHeight() const {
61 return mHeight;
62}
63
Shuzhen Wang758c2152017-01-10 18:26:18 -080064bool OutputConfiguration::isDeferred() const {
65 return mIsDeferred;
66}
67
68bool OutputConfiguration::isShared() const {
69 return mIsShared;
70}
71
Austin Borger71d8f672023-06-01 16:51:35 -070072std::string OutputConfiguration::getPhysicalCameraId() const {
Shuzhen Wangc28189a2017-11-27 23:05:10 -080073 return mPhysicalCameraId;
74}
75
Shuzhen Wang83bff122020-11-20 15:51:39 -080076bool OutputConfiguration::isMultiResolution() const {
77 return mIsMultiResolution;
78}
79
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080080const std::vector<int32_t> &OutputConfiguration::getSensorPixelModesUsed() const {
81 return mSensorPixelModesUsed;
82}
83
Emilian Peevc81a7592022-02-14 17:38:18 -080084int64_t OutputConfiguration::getDynamicRangeProfile() const {
Emilian Peev2295df72021-11-12 18:14:10 -080085 return mDynamicRangeProfile;
86}
87
Austin Borger9e2b27c2022-07-15 11:27:24 -070088int32_t OutputConfiguration::getColorSpace() const {
89 return mColorSpace;
90}
91
Shuzhen Wang8ed1e872022-03-08 16:34:33 -080092int64_t OutputConfiguration::getStreamUseCase() const {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -080093 return mStreamUseCase;
94}
95
Shuzhen Wange4208922022-02-01 16:52:48 -080096int OutputConfiguration::getTimestampBase() const {
97 return mTimestampBase;
98}
99
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700100int OutputConfiguration::getMirrorMode(sp<IGraphicBufferProducer> surface) const {
101 if (!flags::mirror_mode_shared_surfaces()) {
102 return mMirrorMode;
103 }
104
Shuzhen Wangb91d0c22024-10-29 09:58:55 -0700105 if (mGbps.size() != mMirrorModeForProducers.size()) {
106 ALOGE("%s: mGbps size doesn't match mMirrorModeForProducers: %zu vs %zu",
107 __FUNCTION__, mGbps.size(), mMirrorModeForProducers.size());
108 return mMirrorMode;
109 }
110
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700111 // Use per-producer mirror mode if available.
112 for (size_t i = 0; i < mGbps.size(); i++) {
113 if (mGbps[i] == surface) {
114 return mMirrorModeForProducers[i];
115 }
116 }
117
118 // For surface that doesn't belong to this output configuration, use
119 // mMirrorMode as default.
120 ALOGW("%s: Surface doesn't belong to this OutputConfiguration!", __FUNCTION__);
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800121 return mMirrorMode;
122}
123
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000124bool OutputConfiguration::useReadoutTimestamp() const {
125 return mUseReadoutTimestamp;
126}
127
Shuzhen Wang0709c282024-02-12 09:09:32 -0800128int OutputConfiguration::getFormat() const {
129 return mFormat;
130}
131
132int OutputConfiguration::getDataspace() const {
133 return mDataspace;
134}
135
136int64_t OutputConfiguration::getUsage() const {
137 return mUsage;
138}
139
140bool OutputConfiguration::isComplete() const {
141 return !((mSurfaceType == SURFACE_TYPE_MEDIA_RECORDER ||
142 mSurfaceType == SURFACE_TYPE_MEDIA_CODEC ||
143 mSurfaceType == SURFACE_TYPE_IMAGE_READER) &&
144 mGbps.empty());
145}
146
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800147OutputConfiguration::OutputConfiguration() :
148 mRotation(INVALID_ROTATION),
Zhijun He5d677d12016-05-29 16:52:39 -0700149 mSurfaceSetID(INVALID_SET_ID),
150 mSurfaceType(SURFACE_TYPE_UNKNOWN),
151 mWidth(0),
Shuzhen Wang758c2152017-01-10 18:26:18 -0800152 mHeight(0),
153 mIsDeferred(false),
Shuzhen Wang83bff122020-11-20 15:51:39 -0800154 mIsShared(false),
Emilian Peev2295df72021-11-12 18:14:10 -0800155 mIsMultiResolution(false),
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800156 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
Austin Borger9e2b27c2022-07-15 11:27:24 -0700157 mColorSpace(ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED),
Shuzhen Wange4208922022-02-01 16:52:48 -0800158 mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800159 mTimestampBase(TIMESTAMP_BASE_DEFAULT),
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000160 mMirrorMode(MIRROR_MODE_AUTO),
Shuzhen Wang0709c282024-02-12 09:09:32 -0800161 mUseReadoutTimestamp(false),
162 mFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED),
163 mDataspace(0),
164 mUsage(0) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800165}
166
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800167OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800168 mRotation(INVALID_ROTATION),
169 mSurfaceSetID(INVALID_SET_ID) {
170 readFromParcel(&parcel);
171}
172
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800173status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800174 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700175 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800176
177 if (parcel == nullptr) return BAD_VALUE;
178
179 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700180 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800181 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700182 }
183
Zhijun He018107a2016-01-18 15:32:50 -0800184 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800185 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -0800186 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800187 return err;
Zhijun He018107a2016-01-18 15:32:50 -0800188 }
189
Zhijun He5d677d12016-05-29 16:52:39 -0700190 int surfaceType = SURFACE_TYPE_UNKNOWN;
191 if ((err = parcel->readInt32(&surfaceType)) != OK) {
192 ALOGE("%s: Failed to read surface type from parcel", __FUNCTION__);
193 return err;
194 }
195
196 int width = 0;
197 if ((err = parcel->readInt32(&width)) != OK) {
198 ALOGE("%s: Failed to read surface width from parcel", __FUNCTION__);
199 return err;
200 }
201
202 int height = 0;
203 if ((err = parcel->readInt32(&height)) != OK) {
204 ALOGE("%s: Failed to read surface height from parcel", __FUNCTION__);
205 return err;
206 }
207
Shuzhen Wang758c2152017-01-10 18:26:18 -0800208 int isDeferred = 0;
209 if ((err = parcel->readInt32(&isDeferred)) != OK) {
210 ALOGE("%s: Failed to read surface isDeferred flag from parcel", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700211 return err;
212 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800213
214 int isShared = 0;
215 if ((err = parcel->readInt32(&isShared)) != OK) {
216 ALOGE("%s: Failed to read surface isShared flag from parcel", __FUNCTION__);
217 return err;
218 }
219
220 if (isDeferred && surfaceType != SURFACE_TYPE_SURFACE_VIEW &&
221 surfaceType != SURFACE_TYPE_SURFACE_TEXTURE) {
222 ALOGE("%s: Invalid surface type for deferred configuration", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700223 return BAD_VALUE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800224 }
225
Shuzhen Wang758c2152017-01-10 18:26:18 -0800226 std::vector<view::Surface> surfaceShims;
227 if ((err = parcel->readParcelableVector(&surfaceShims)) != OK) {
228 ALOGE("%s: Failed to read surface(s) from parcel", __FUNCTION__);
229 return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700230 }
231
Austin Borger71d8f672023-06-01 16:51:35 -0700232 String16 physicalCameraId;
233 parcel->readString16(&physicalCameraId);
234 mPhysicalCameraId = toStdString(physicalCameraId);
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800235
Shuzhen Wang83bff122020-11-20 15:51:39 -0800236 int isMultiResolution = 0;
237 if ((err = parcel->readInt32(&isMultiResolution)) != OK) {
238 ALOGE("%s: Failed to read surface isMultiResolution flag from parcel", __FUNCTION__);
239 return err;
240 }
241
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800242 std::vector<int32_t> sensorPixelModesUsed;
Jayant Chowdhary84df28c2021-05-26 22:32:21 -0700243 if ((err = parcel->readInt32Vector(&sensorPixelModesUsed)) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800244 ALOGE("%s: Failed to read sensor pixel mode(s) from parcel", __FUNCTION__);
245 return err;
246 }
Emilian Peevc81a7592022-02-14 17:38:18 -0800247 int64_t dynamicProfile;
248 if ((err = parcel->readInt64(&dynamicProfile)) != OK) {
Emilian Peev2295df72021-11-12 18:14:10 -0800249 ALOGE("%s: Failed to read surface dynamic range profile flag from parcel", __FUNCTION__);
250 return err;
251 }
Austin Borger9e2b27c2022-07-15 11:27:24 -0700252 int32_t colorSpace;
253 if ((err = parcel->readInt32(&colorSpace)) != OK) {
254 ALOGE("%s: Failed to read surface color space flag from parcel", __FUNCTION__);
255 return err;
256 }
Emilian Peev2295df72021-11-12 18:14:10 -0800257
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800258 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
259 if ((err = parcel->readInt64(&streamUseCase)) != OK) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800260 ALOGE("%s: Failed to read stream use case from parcel", __FUNCTION__);
261 return err;
262 }
263
Shuzhen Wange4208922022-02-01 16:52:48 -0800264 int timestampBase = TIMESTAMP_BASE_DEFAULT;
265 if ((err = parcel->readInt32(&timestampBase)) != OK) {
266 ALOGE("%s: Failed to read timestamp base from parcel", __FUNCTION__);
267 return err;
268 }
269
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800270 int mirrorMode = MIRROR_MODE_AUTO;
271 if ((err = parcel->readInt32(&mirrorMode)) != OK) {
272 ALOGE("%s: Failed to read mirroring mode from parcel", __FUNCTION__);
273 return err;
274 }
275
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700276 std::vector<int> mirrorModeForProducers;
277 if ((err = parcel->readInt32Vector(&mirrorModeForProducers)) != OK) {
278 ALOGE("%s: Failed to read mirroring mode for surfaces from parcel", __FUNCTION__);
279 return err;
280 }
281
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000282 int useReadoutTimestamp = 0;
283 if ((err = parcel->readInt32(&useReadoutTimestamp)) != OK) {
284 ALOGE("%s: Failed to read useReadoutTimestamp flag from parcel", __FUNCTION__);
285 return err;
286 }
287
Shuzhen Wang0709c282024-02-12 09:09:32 -0800288 int format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
289 if ((err = parcel->readInt32(&format)) != OK) {
290 ALOGE("%s: Failed to read format from parcel", __FUNCTION__);
291 return err;
292 }
293
294 int dataspace = 0;
295 if ((err = parcel->readInt32(&dataspace)) != OK) {
296 ALOGE("%s: Failed to read dataspace from parcel", __FUNCTION__);
297 return err;
298 }
299
300 int64_t usage = 0;
301 if ((err = parcel->readInt64(&usage)) != OK) {
302 ALOGE("%s: Failed to read usage flag from parcel", __FUNCTION__);
303 return err;
304 }
305
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700306 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800307 mSurfaceSetID = setID;
Zhijun He5d677d12016-05-29 16:52:39 -0700308 mSurfaceType = surfaceType;
309 mWidth = width;
310 mHeight = height;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800311 mIsDeferred = isDeferred != 0;
312 mIsShared = isShared != 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800313 mIsMultiResolution = isMultiResolution != 0;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800314 mStreamUseCase = streamUseCase;
Shuzhen Wange4208922022-02-01 16:52:48 -0800315 mTimestampBase = timestampBase;
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800316 mMirrorMode = mirrorMode;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700317 mMirrorModeForProducers = std::move(mirrorModeForProducers);
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000318 mUseReadoutTimestamp = useReadoutTimestamp != 0;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800319 for (auto& surface : surfaceShims) {
320 ALOGV("%s: OutputConfiguration: %p, name %s", __FUNCTION__,
321 surface.graphicBufferProducer.get(),
Tomasz Wasilczyk12b04a52023-08-11 15:52:22 +0000322 toString8(surface.name).c_str());
Shuzhen Wang758c2152017-01-10 18:26:18 -0800323 mGbps.push_back(surface.graphicBufferProducer);
324 }
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700325
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800326 mSensorPixelModesUsed = std::move(sensorPixelModesUsed);
Emilian Peev2295df72021-11-12 18:14:10 -0800327 mDynamicRangeProfile = dynamicProfile;
Austin Borger9e2b27c2022-07-15 11:27:24 -0700328 mColorSpace = colorSpace;
Shuzhen Wang0709c282024-02-12 09:09:32 -0800329 mFormat = format;
330 mDataspace = dataspace;
331 mUsage = usage;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800332
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800333 ALOGV("%s: OutputConfiguration: rotation = %d, setId = %d, surfaceType = %d,"
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800334 " physicalCameraId = %s, isMultiResolution = %d, streamUseCase = %" PRId64
Shuzhen Wang0709c282024-02-12 09:09:32 -0800335 ", timestampBase = %d, mirrorMode = %d, useReadoutTimestamp = %d, format = %d, "
336 "dataspace = %d, usage = %" PRId64,
Shuzhen Wange4208922022-02-01 16:52:48 -0800337 __FUNCTION__, mRotation, mSurfaceSetID, mSurfaceType,
Austin Borger71d8f672023-06-01 16:51:35 -0700338 mPhysicalCameraId.c_str(), mIsMultiResolution, mStreamUseCase, timestampBase,
Shuzhen Wang0709c282024-02-12 09:09:32 -0800339 mMirrorMode, mUseReadoutTimestamp, mFormat, mDataspace, mUsage);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800340
341 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700342}
343
Zhijun He018107a2016-01-18 15:32:50 -0800344OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
Austin Borger71d8f672023-06-01 16:51:35 -0700345 const std::string& physicalId,
Emilian Peev40ead602017-09-26 15:46:36 +0100346 int surfaceSetID, bool isShared) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700347 mGbps.push_back(gbp);
Ruben Brunk3450ba72015-06-16 11:00:37 -0700348 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800349 mSurfaceSetID = surfaceSetID;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800350 mIsDeferred = false;
Emilian Peev40ead602017-09-26 15:46:36 +0100351 mIsShared = isShared;
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800352 mPhysicalCameraId = physicalId;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800353 mIsMultiResolution = false;
Emilian Peev2295df72021-11-12 18:14:10 -0800354 mDynamicRangeProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
Austin Borger9e2b27c2022-07-15 11:27:24 -0700355 mColorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800356 mStreamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
Shuzhen Wange4208922022-02-01 16:52:48 -0800357 mTimestampBase = TIMESTAMP_BASE_DEFAULT;
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800358 mMirrorMode = MIRROR_MODE_AUTO;
Shuzhen Wangb91d0c22024-10-29 09:58:55 -0700359 mMirrorModeForProducers.push_back(mMirrorMode);
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000360 mUseReadoutTimestamp = false;
Shuzhen Wang0709c282024-02-12 09:09:32 -0800361 mFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
362 mDataspace = 0;
363 mUsage = 0;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700364}
365
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700366OutputConfiguration::OutputConfiguration(
367 const std::vector<sp<IGraphicBufferProducer>>& gbps,
Austin Borger71d8f672023-06-01 16:51:35 -0700368 int rotation, const std::string& physicalCameraId, int surfaceSetID, int surfaceType,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800369 int width, int height, bool isShared)
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700370 : mGbps(gbps), mRotation(rotation), mSurfaceSetID(surfaceSetID), mSurfaceType(surfaceType),
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800371 mWidth(width), mHeight(height), mIsDeferred(false), mIsShared(isShared),
Emilian Peev2295df72021-11-12 18:14:10 -0800372 mPhysicalCameraId(physicalCameraId), mIsMultiResolution(false),
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800373 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
Austin Borger9e2b27c2022-07-15 11:27:24 -0700374 mColorSpace(ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED),
Shuzhen Wange4208922022-02-01 16:52:48 -0800375 mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800376 mTimestampBase(TIMESTAMP_BASE_DEFAULT),
Shuzhen Wangb91d0c22024-10-29 09:58:55 -0700377 mMirrorMode(MIRROR_MODE_AUTO), mMirrorModeForProducers(gbps.size(), mMirrorMode),
378 mUseReadoutTimestamp(false), mFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED),
379 mDataspace(0), mUsage(0) { }
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700380
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800381status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700382
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800383 if (parcel == nullptr) return BAD_VALUE;
384 status_t err = OK;
385
386 err = parcel->writeInt32(mRotation);
387 if (err != OK) return err;
388
389 err = parcel->writeInt32(mSurfaceSetID);
390 if (err != OK) return err;
391
Zhijun He5d677d12016-05-29 16:52:39 -0700392 err = parcel->writeInt32(mSurfaceType);
393 if (err != OK) return err;
394
395 err = parcel->writeInt32(mWidth);
396 if (err != OK) return err;
397
398 err = parcel->writeInt32(mHeight);
399 if (err != OK) return err;
400
Shuzhen Wang758c2152017-01-10 18:26:18 -0800401 err = parcel->writeInt32(mIsDeferred ? 1 : 0);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800402 if (err != OK) return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700403
Shuzhen Wang758c2152017-01-10 18:26:18 -0800404 err = parcel->writeInt32(mIsShared ? 1 : 0);
405 if (err != OK) return err;
406
407 std::vector<view::Surface> surfaceShims;
408 for (auto& gbp : mGbps) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700409 view::Surface surfaceShim;
410 surfaceShim.name = String16("unknown_name"); // name of surface
Shuzhen Wang758c2152017-01-10 18:26:18 -0800411 surfaceShim.graphicBufferProducer = gbp;
412 surfaceShims.push_back(surfaceShim);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700413 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800414 err = parcel->writeParcelableVector(surfaceShims);
415 if (err != OK) return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700416
Austin Borger71d8f672023-06-01 16:51:35 -0700417 String16 physicalCameraId = toString16(mPhysicalCameraId);
418 err = parcel->writeString16(physicalCameraId);
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800419 if (err != OK) return err;
420
Shuzhen Wang83bff122020-11-20 15:51:39 -0800421 err = parcel->writeInt32(mIsMultiResolution ? 1 : 0);
422 if (err != OK) return err;
423
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800424 err = parcel->writeParcelableVector(mSensorPixelModesUsed);
425 if (err != OK) return err;
426
Emilian Peevc81a7592022-02-14 17:38:18 -0800427 err = parcel->writeInt64(mDynamicRangeProfile);
Emilian Peev2295df72021-11-12 18:14:10 -0800428 if (err != OK) return err;
429
Austin Borger9e2b27c2022-07-15 11:27:24 -0700430 err = parcel->writeInt32(mColorSpace);
431 if (err != OK) return err;
432
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800433 err = parcel->writeInt64(mStreamUseCase);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800434 if (err != OK) return err;
435
Shuzhen Wange4208922022-02-01 16:52:48 -0800436 err = parcel->writeInt32(mTimestampBase);
437 if (err != OK) return err;
438
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800439 err = parcel->writeInt32(mMirrorMode);
440 if (err != OK) return err;
441
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700442 err = parcel->writeInt32Vector(mMirrorModeForProducers);
443 if (err != OK) return err;
444
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000445 err = parcel->writeInt32(mUseReadoutTimestamp ? 1 : 0);
446 if (err != OK) return err;
447
Shuzhen Wang0709c282024-02-12 09:09:32 -0800448 err = parcel->writeInt32(mFormat);
449 if (err != OK) return err;
450
451 err = parcel->writeInt32(mDataspace);
452 if (err != OK) return err;
453
454 err = parcel->writeInt64(mUsage);
455 if (err != OK) return err;
456
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700457 return OK;
458}
459
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800460template <typename T>
461static bool simpleVectorsEqual(T first, T second) {
462 if (first.size() != second.size()) {
463 return false;
464 }
465
466 for (size_t i = 0; i < first.size(); i++) {
467 if (first[i] != second[i]) {
468 return false;
469 }
470 }
471 return true;
472}
473
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700474template <typename T>
475static bool simpleVectorsLessThan(T first, T second) {
476 if (first.size() != second.size()) {
477 return first.size() < second.size();
478 }
479
480 for (size_t i = 0; i < first.size(); i++) {
481 if (first[i] != second[i]) {
482 return first[i] < second[i];
483 }
484 }
485 return false;
486}
487
Shuzhen Wang0129d522016-10-30 22:43:41 -0700488bool OutputConfiguration::gbpsEqual(const OutputConfiguration& other) const {
489 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
490 other.getGraphicBufferProducers();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800491 return simpleVectorsEqual(otherGbps, mGbps);
492}
Shuzhen Wang0129d522016-10-30 22:43:41 -0700493
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800494bool OutputConfiguration::sensorPixelModesUsedEqual(const OutputConfiguration& other) const {
495 const std::vector<int32_t>& othersensorPixelModesUsed = other.getSensorPixelModesUsed();
496 return simpleVectorsEqual(othersensorPixelModesUsed, mSensorPixelModesUsed);
497}
498
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700499bool OutputConfiguration::mirrorModesEqual(const OutputConfiguration& other) const {
500 const std::vector<int>& otherMirrorModes = other.getMirrorModes();
501 return simpleVectorsEqual(otherMirrorModes, mMirrorModeForProducers);
502
503}
504
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800505bool OutputConfiguration::sensorPixelModesUsedLessThan(const OutputConfiguration& other) const {
506 const std::vector<int32_t>& spms = other.getSensorPixelModesUsed();
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700507 return simpleVectorsLessThan(mSensorPixelModesUsed, spms);
508}
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800509
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700510bool OutputConfiguration::mirrorModesLessThan(const OutputConfiguration& other) const {
511 const std::vector<int>& otherMirrorModes = other.getMirrorModes();
512 return simpleVectorsLessThan(mMirrorModeForProducers, otherMirrorModes);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700513}
514
515bool OutputConfiguration::gbpsLessThan(const OutputConfiguration& other) const {
516 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
517 other.getGraphicBufferProducers();
518
519 if (mGbps.size() != otherGbps.size()) {
520 return mGbps.size() < otherGbps.size();
521 }
522
523 for (size_t i = 0; i < mGbps.size(); i++) {
524 if (mGbps[i] != otherGbps[i]) {
525 return mGbps[i] < otherGbps[i];
526 }
527 }
528
529 return false;
530}
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700531}; // namespace android