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->writeBool, capturedHdrLayers);
40 SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(capturedDataspace));
41 SAFE_PARCEL(parcel->writeInt32, result);
42 return NO_ERROR;
43 }
44
readFromParcel(const android::Parcel * parcel)45 status_t ScreenCaptureResults::readFromParcel(const android::Parcel* parcel) {
46 bool hasGraphicBuffer;
47 SAFE_PARCEL(parcel->readBool, &hasGraphicBuffer);
48 if (hasGraphicBuffer) {
49 buffer = new GraphicBuffer();
50 SAFE_PARCEL(parcel->read, *buffer);
51 }
52
53 bool hasFence;
54 SAFE_PARCEL(parcel->readBool, &hasFence);
55 if (hasFence) {
56 fence = new Fence();
57 SAFE_PARCEL(parcel->read, *fence);
58 }
59
60 SAFE_PARCEL(parcel->readBool, &capturedSecureLayers);
61 SAFE_PARCEL(parcel->readBool, &capturedHdrLayers);
62 uint32_t dataspace = 0;
63 SAFE_PARCEL(parcel->readUint32, &dataspace);
64 capturedDataspace = static_cast<ui::Dataspace>(dataspace);
65 SAFE_PARCEL(parcel->readInt32, &result);
66 return NO_ERROR;
67 }
68
69 } // namespace android::gui
70