blob: 601a5f9b333c6b0ab616df2ba35bff331b5b9419 [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));
chaviw0ef7caa2021-01-05 11:04:50 -080043 return NO_ERROR;
44}
45
46status_t ScreenCaptureResults::readFromParcel(const android::Parcel* parcel) {
47 bool hasGraphicBuffer;
48 SAFE_PARCEL(parcel->readBool, &hasGraphicBuffer);
49 if (hasGraphicBuffer) {
50 buffer = new GraphicBuffer();
51 SAFE_PARCEL(parcel->read, *buffer);
52 }
53
Ady Abraham99599942021-01-27 20:27:23 -080054 bool hasFence;
55 SAFE_PARCEL(parcel->readBool, &hasFence);
56 if (hasFence) {
Patrick Williamsfdb57bb2022-08-09 22:48:18 +000057 fenceResult = sp<Fence>::make();
58 SAFE_PARCEL(parcel->read, *fenceResult.value());
59 } else {
60 status_t status;
61 SAFE_PARCEL(parcel->readInt32, &status);
62 fenceResult = status == NO_ERROR ? FenceResult(Fence::NO_FENCE)
63 : FenceResult(base::unexpected(status));
Ady Abraham99599942021-01-27 20:27:23 -080064 }
65
chaviw0ef7caa2021-01-05 11:04:50 -080066 SAFE_PARCEL(parcel->readBool, &capturedSecureLayers);
Alec Mouri14d5b862022-04-27 21:20:04 +000067 SAFE_PARCEL(parcel->readBool, &capturedHdrLayers);
chaviw0ef7caa2021-01-05 11:04:50 -080068 uint32_t dataspace = 0;
69 SAFE_PARCEL(parcel->readUint32, &dataspace);
70 capturedDataspace = static_cast<ui::Dataspace>(dataspace);
chaviw0ef7caa2021-01-05 11:04:50 -080071 return NO_ERROR;
72}
73
74} // namespace android::gui