• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <ui/GraphicBuffer.h>
22 
23 namespace android::gui {
24 
writeToParcel(android::Parcel * parcel) const25 status_t ScreenCaptureResults::writeToParcel(android::Parcel* parcel) const {
26     if (buffer != nullptr) {
27         SAFE_PARCEL(parcel->writeBool, true);
28         SAFE_PARCEL(parcel->write, *buffer);
29     } else {
30         SAFE_PARCEL(parcel->writeBool, false);
31     }
32 
33     if (fenceResult.ok() && fenceResult.value() != Fence::NO_FENCE) {
34         SAFE_PARCEL(parcel->writeBool, true);
35         SAFE_PARCEL(parcel->write, *fenceResult.value());
36     } else {
37         SAFE_PARCEL(parcel->writeBool, false);
38         SAFE_PARCEL(parcel->writeInt32, fenceStatus(fenceResult));
39     }
40 
41     SAFE_PARCEL(parcel->writeBool, capturedSecureLayers);
42     SAFE_PARCEL(parcel->writeBool, capturedHdrLayers);
43     SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(capturedDataspace));
44     if (optionalGainMap != nullptr) {
45         SAFE_PARCEL(parcel->writeBool, true);
46         SAFE_PARCEL(parcel->write, *optionalGainMap);
47     } else {
48         SAFE_PARCEL(parcel->writeBool, false);
49     }
50     SAFE_PARCEL(parcel->writeFloat, hdrSdrRatio);
51     return NO_ERROR;
52 }
53 
readFromParcel(const android::Parcel * parcel)54 status_t ScreenCaptureResults::readFromParcel(const android::Parcel* parcel) {
55     bool hasGraphicBuffer;
56     SAFE_PARCEL(parcel->readBool, &hasGraphicBuffer);
57     if (hasGraphicBuffer) {
58         buffer = sp<GraphicBuffer>::make();
59         SAFE_PARCEL(parcel->read, *buffer);
60     }
61 
62     bool hasFence;
63     SAFE_PARCEL(parcel->readBool, &hasFence);
64     if (hasFence) {
65         fenceResult = sp<Fence>::make();
66         SAFE_PARCEL(parcel->read, *fenceResult.value());
67     } else {
68         status_t status;
69         SAFE_PARCEL(parcel->readInt32, &status);
70         fenceResult = status == NO_ERROR ? FenceResult(Fence::NO_FENCE)
71                                          : FenceResult(base::unexpected(status));
72     }
73 
74     SAFE_PARCEL(parcel->readBool, &capturedSecureLayers);
75     SAFE_PARCEL(parcel->readBool, &capturedHdrLayers);
76     uint32_t dataspace = 0;
77     SAFE_PARCEL(parcel->readUint32, &dataspace);
78     capturedDataspace = static_cast<ui::Dataspace>(dataspace);
79 
80     bool hasGainmap;
81     SAFE_PARCEL(parcel->readBool, &hasGainmap);
82     if (hasGainmap) {
83         optionalGainMap = sp<GraphicBuffer>::make();
84         SAFE_PARCEL(parcel->read, *optionalGainMap);
85     }
86     SAFE_PARCEL(parcel->readFloat, &hdrSdrRatio);
87     return NO_ERROR;
88 }
89 
90 } // namespace android::gui
91