xref: /aosp_15_r20/frameworks/native/libs/gui/ScreenCaptureResults.cpp (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
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 
19 #include <private/gui/ParcelUtils.h>
20 #include <ui/FenceResult.h>
21 
22 namespace android::gui {
23 
writeToParcel(android::Parcel * parcel) const24 status_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     }
31 
32     if (fenceResult.ok() && fenceResult.value() != Fence::NO_FENCE) {
33         SAFE_PARCEL(parcel->writeBool, true);
34         SAFE_PARCEL(parcel->write, *fenceResult.value());
35     } else {
36         SAFE_PARCEL(parcel->writeBool, false);
37         SAFE_PARCEL(parcel->writeInt32, fenceStatus(fenceResult));
38     }
39 
40     SAFE_PARCEL(parcel->writeBool, capturedSecureLayers);
41     SAFE_PARCEL(parcel->writeBool, capturedHdrLayers);
42     SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(capturedDataspace));
43     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);
50     return NO_ERROR;
51 }
52 
readFromParcel(const android::Parcel * parcel)53 status_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 
61     bool hasFence;
62     SAFE_PARCEL(parcel->readBool, &hasFence);
63     if (hasFence) {
64         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));
71     }
72 
73     SAFE_PARCEL(parcel->readBool, &capturedSecureLayers);
74     SAFE_PARCEL(parcel->readBool, &capturedHdrLayers);
75     uint32_t dataspace = 0;
76     SAFE_PARCEL(parcel->readUint32, &dataspace);
77     capturedDataspace = static_cast<ui::Dataspace>(dataspace);
78 
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);
86     return NO_ERROR;
87 }
88 
89 } // namespace android::gui
90