blob: 2de023e5b285f42fb44db7c8c8003b904d32a829 [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>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010021
chaviw0ef7caa2021-01-05 11:04:50 -080022namespace android::gui {
23
24status_t ScreenCaptureResults::writeToParcel(android::Parcel* parcel) const {
25 if (buffer != nullptr) {
26 SAFE_PARCEL(parcel->writeBool, true);
27 SAFE_PARCEL(parcel->write, *buffer);
28 } else {
29 SAFE_PARCEL(parcel->writeBool, false);
30 }
Ady Abraham99599942021-01-27 20:27:23 -080031
Patrick Williamsfdb57bb2022-08-09 22:48:18 +000032 if (fenceResult.ok() && fenceResult.value() != Fence::NO_FENCE) {
Ady Abraham99599942021-01-27 20:27:23 -080033 SAFE_PARCEL(parcel->writeBool, true);
Patrick Williamsfdb57bb2022-08-09 22:48:18 +000034 SAFE_PARCEL(parcel->write, *fenceResult.value());
Ady Abraham99599942021-01-27 20:27:23 -080035 } else {
36 SAFE_PARCEL(parcel->writeBool, false);
Patrick Williamsfdb57bb2022-08-09 22:48:18 +000037 SAFE_PARCEL(parcel->writeInt32, fenceStatus(fenceResult));
Ady Abraham99599942021-01-27 20:27:23 -080038 }
39
chaviw0ef7caa2021-01-05 11:04:50 -080040 SAFE_PARCEL(parcel->writeBool, capturedSecureLayers);
Alec Mouri14d5b862022-04-27 21:20:04 +000041 SAFE_PARCEL(parcel->writeBool, capturedHdrLayers);
chaviw0ef7caa2021-01-05 11:04:50 -080042 SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(capturedDataspace));
Alec Mouri1b1853f2024-07-15 22:46:58 +000043 if (optionalGainMap != nullptr) {
44 SAFE_PARCEL(parcel->writeBool, true);
45 SAFE_PARCEL(parcel->write, *optionalGainMap);
46 } else {
47 SAFE_PARCEL(parcel->writeBool, false);
48 }
49 SAFE_PARCEL(parcel->writeFloat, hdrSdrRatio);
chaviw0ef7caa2021-01-05 11:04:50 -080050 return NO_ERROR;
51}
52
53status_t ScreenCaptureResults::readFromParcel(const android::Parcel* parcel) {
54 bool hasGraphicBuffer;
55 SAFE_PARCEL(parcel->readBool, &hasGraphicBuffer);
56 if (hasGraphicBuffer) {
57 buffer = new GraphicBuffer();
58 SAFE_PARCEL(parcel->read, *buffer);
59 }
60
Ady Abraham99599942021-01-27 20:27:23 -080061 bool hasFence;
62 SAFE_PARCEL(parcel->readBool, &hasFence);
63 if (hasFence) {
Patrick Williamsfdb57bb2022-08-09 22:48:18 +000064 fenceResult = sp<Fence>::make();
65 SAFE_PARCEL(parcel->read, *fenceResult.value());
66 } else {
67 status_t status;
68 SAFE_PARCEL(parcel->readInt32, &status);
69 fenceResult = status == NO_ERROR ? FenceResult(Fence::NO_FENCE)
70 : FenceResult(base::unexpected(status));
Ady Abraham99599942021-01-27 20:27:23 -080071 }
72
chaviw0ef7caa2021-01-05 11:04:50 -080073 SAFE_PARCEL(parcel->readBool, &capturedSecureLayers);
Alec Mouri14d5b862022-04-27 21:20:04 +000074 SAFE_PARCEL(parcel->readBool, &capturedHdrLayers);
chaviw0ef7caa2021-01-05 11:04:50 -080075 uint32_t dataspace = 0;
76 SAFE_PARCEL(parcel->readUint32, &dataspace);
77 capturedDataspace = static_cast<ui::Dataspace>(dataspace);
Alec Mouri1b1853f2024-07-15 22:46:58 +000078
79 bool hasGainmap;
80 SAFE_PARCEL(parcel->readBool, &hasGainmap);
81 if (hasGainmap) {
82 optionalGainMap = new GraphicBuffer();
83 SAFE_PARCEL(parcel->read, *optionalGainMap);
84 }
85 SAFE_PARCEL(parcel->readFloat, &hdrSdrRatio);
chaviw0ef7caa2021-01-05 11:04:50 -080086 return NO_ERROR;
87}
88
89} // namespace android::gui