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
21 namespace android::gui {
22
writeToParcel(android::Parcel * parcel) const23 status_t ScreenCaptureResults::writeToParcel(android::Parcel* parcel) const {
24 if (buffer != nullptr) {
25 SAFE_PARCEL(parcel->writeBool, true);
26 SAFE_PARCEL(parcel->write, *buffer);
27 } else {
28 SAFE_PARCEL(parcel->writeBool, false);
29 }
30
31 if (fence != Fence::NO_FENCE) {
32 SAFE_PARCEL(parcel->writeBool, true);
33 SAFE_PARCEL(parcel->write, *fence);
34 } else {
35 SAFE_PARCEL(parcel->writeBool, false);
36 }
37
38 SAFE_PARCEL(parcel->writeBool, capturedSecureLayers);
39 SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(capturedDataspace));
40 SAFE_PARCEL(parcel->writeInt32, result);
41 return NO_ERROR;
42 }
43
readFromParcel(const android::Parcel * parcel)44 status_t ScreenCaptureResults::readFromParcel(const android::Parcel* parcel) {
45 bool hasGraphicBuffer;
46 SAFE_PARCEL(parcel->readBool, &hasGraphicBuffer);
47 if (hasGraphicBuffer) {
48 buffer = new GraphicBuffer();
49 SAFE_PARCEL(parcel->read, *buffer);
50 }
51
52 bool hasFence;
53 SAFE_PARCEL(parcel->readBool, &hasFence);
54 if (hasFence) {
55 fence = new Fence();
56 SAFE_PARCEL(parcel->read, *fence);
57 }
58
59 SAFE_PARCEL(parcel->readBool, &capturedSecureLayers);
60 uint32_t dataspace = 0;
61 SAFE_PARCEL(parcel->readUint32, &dataspace);
62 capturedDataspace = static_cast<ui::Dataspace>(dataspace);
63 SAFE_PARCEL(parcel->readInt32, &result);
64 return NO_ERROR;
65 }
66
67 } // namespace android::gui
68