blob: 30b5785b6af6c8198aa7deb119c6f871b6235afd [file] [log] [blame]
chaviw0ef7caa2021-01-05 11:04:50 -08001/*
2 * Copyright 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (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.0
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 <gui/ScreenCaptureResults.h>
18
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010019#include <private/gui/ParcelUtils.h>
Patrick Williamsfdb57bb2022-08-09 22:48:18 +000020#include <ui/FenceResult.h>
Anton Ivanov8ed86592025-02-20 11:52:50 -080021#include <ui/GraphicBuffer.h>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010022
chaviw0ef7caa2021-01-05 11:04:50 -080023namespace android::gui {
24
25status_t ScreenCaptureResults::writeToParcel(android::Parcel* parcel) const {
26 if (buffer != nullptr) {
27 SAFE_PARCEL(parcel->writeBool, true);
28 SAFE_PARCEL(parcel->write, *buffer);
29 } else {
30 SAFE_PARCEL(parcel->writeBool, false);
31 }
Ady Abraham99599942021-01-27 20:27:23 -080032
Patrick Williamsfdb57bb2022-08-09 22:48:18 +000033 if (fenceResult.ok() && fenceResult.value() != Fence::NO_FENCE) {
Ady Abraham99599942021-01-27 20:27:23 -080034 SAFE_PARCEL(parcel->writeBool, true);
Patrick Williamsfdb57bb2022-08-09 22:48:18 +000035 SAFE_PARCEL(parcel->write, *fenceResult.value());
Ady Abraham99599942021-01-27 20:27:23 -080036 } else {
37 SAFE_PARCEL(parcel->writeBool, false);
Patrick Williamsfdb57bb2022-08-09 22:48:18 +000038 SAFE_PARCEL(parcel->writeInt32, fenceStatus(fenceResult));
Ady Abraham99599942021-01-27 20:27:23 -080039 }
40
chaviw0ef7caa2021-01-05 11:04:50 -080041 SAFE_PARCEL(parcel->writeBool, capturedSecureLayers);
Alec Mouri14d5b862022-04-27 21:20:04 +000042 SAFE_PARCEL(parcel->writeBool, capturedHdrLayers);
chaviw0ef7caa2021-01-05 11:04:50 -080043 SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(capturedDataspace));
Alec Mouri1b1853f2024-07-15 22:46:58 +000044 if (optionalGainMap != nullptr) {
45 SAFE_PARCEL(parcel->writeBool, true);
46 SAFE_PARCEL(parcel->write, *optionalGainMap);
47 } else {
48 SAFE_PARCEL(parcel->writeBool, false);
49 }
50 SAFE_PARCEL(parcel->writeFloat, hdrSdrRatio);
chaviw0ef7caa2021-01-05 11:04:50 -080051 return NO_ERROR;
52}
53
54status_t ScreenCaptureResults::readFromParcel(const android::Parcel* parcel) {
55 bool hasGraphicBuffer;
56 SAFE_PARCEL(parcel->readBool, &hasGraphicBuffer);
57 if (hasGraphicBuffer) {
Anton Ivanov8ed86592025-02-20 11:52:50 -080058 buffer = sp<GraphicBuffer>::make();
chaviw0ef7caa2021-01-05 11:04:50 -080059 SAFE_PARCEL(parcel->read, *buffer);
60 }
61
Ady Abraham99599942021-01-27 20:27:23 -080062 bool hasFence;
63 SAFE_PARCEL(parcel->readBool, &hasFence);
64 if (hasFence) {
Patrick Williamsfdb57bb2022-08-09 22:48:18 +000065 fenceResult = sp<Fence>::make();
66 SAFE_PARCEL(parcel->read, *fenceResult.value());
67 } else {
68 status_t status;
69 SAFE_PARCEL(parcel->readInt32, &status);
70 fenceResult = status == NO_ERROR ? FenceResult(Fence::NO_FENCE)
71 : FenceResult(base::unexpected(status));
Ady Abraham99599942021-01-27 20:27:23 -080072 }
73
chaviw0ef7caa2021-01-05 11:04:50 -080074 SAFE_PARCEL(parcel->readBool, &capturedSecureLayers);
Alec Mouri14d5b862022-04-27 21:20:04 +000075 SAFE_PARCEL(parcel->readBool, &capturedHdrLayers);
chaviw0ef7caa2021-01-05 11:04:50 -080076 uint32_t dataspace = 0;
77 SAFE_PARCEL(parcel->readUint32, &dataspace);
78 capturedDataspace = static_cast<ui::Dataspace>(dataspace);
Alec Mouri1b1853f2024-07-15 22:46:58 +000079
80 bool hasGainmap;
81 SAFE_PARCEL(parcel->readBool, &hasGainmap);
82 if (hasGainmap) {
Anton Ivanov8ed86592025-02-20 11:52:50 -080083 optionalGainMap = sp<GraphicBuffer>::make();
Alec Mouri1b1853f2024-07-15 22:46:58 +000084 SAFE_PARCEL(parcel->read, *optionalGainMap);
85 }
86 SAFE_PARCEL(parcel->readFloat, &hdrSdrRatio);
chaviw0ef7caa2021-01-05 11:04:50 -080087 return NO_ERROR;
88}
89
90} // namespace android::gui