• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "surface_capture_callback_stub.h"
17 #include "platform/common/rs_log.h"
18 
19 namespace OHOS {
20 namespace Rosen {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)21 int RSSurfaceCaptureCallbackStub::OnRemoteRequest(
22     uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
23 {
24     auto token = data.ReadInterfaceToken();
25     if (token != RSISurfaceCaptureCallback::GetDescriptor()) {
26         ROSEN_LOGE("RSSurfaceCaptureCallbackStub: token ERR_INVALID_STATE");
27         return ERR_INVALID_STATE;
28     }
29     int ret = ERR_NONE;
30     switch (code) {
31         case static_cast<uint32_t>(RSISurfaceCaptureCallbackInterfaceCode::ON_SURFACE_CAPTURE): {
32             NodeId id{0};
33             if (!data.ReadUint64(id)) {
34                 RS_LOGE("RSSurfaceCaptureCallbackStub::ON_SURFACE_CAPTURE read nodeId failed!");
35                 ret = ERR_INVALID_DATA;
36                 break;
37             }
38             RSSurfaceCaptureConfig captureConfig;
39             if (!ReadSurfaceCaptureConfig(captureConfig, data)) {
40                 ret = ERR_INVALID_DATA;
41                 RS_LOGE("RSSurfaceCaptureCallbackStub: ReadSurfaceCaptureConfig failed");
42                 break;
43             }
44             auto pixelmap = data.ReadParcelable<OHOS::Media::PixelMap>();
45             OnSurfaceCapture(id, captureConfig, pixelmap);
46             break;
47         }
48         case static_cast<uint32_t>(RSISurfaceCaptureCallbackInterfaceCode::ON_SURFACE_CAPTURE_HDR): {
49             NodeId id{0};
50             if (!data.ReadUint64(id)) {
51                 RS_LOGE("RSSurfaceCaptureCallbackStub::ON_SURFACE_CAPTURE read nodeId failed!");
52                 ret = ERR_INVALID_DATA;
53                 break;
54             }
55             RSSurfaceCaptureConfig captureConfig;
56             if (!ReadSurfaceCaptureConfig(captureConfig, data)) {
57                 ret = ERR_INVALID_DATA;
58                 RS_LOGE("RSSurfaceCaptureCallbackStub: ReadSurfaceCaptureConfig failed");
59                 break;
60             }
61             auto pixelmap = data.ReadParcelable<OHOS::Media::PixelMap>();
62             auto pixelmapHDR = data.ReadParcelable<OHOS::Media::PixelMap>();
63             OnSurfaceCapture(id, captureConfig, pixelmap, pixelmapHDR);
64             break;
65         }
66         default: {
67             ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
68             break;
69         }
70     }
71 
72     return ret;
73 }
74 
ReadSurfaceCaptureConfig(RSSurfaceCaptureConfig & captureConfig,MessageParcel & data)75 bool RSSurfaceCaptureCallbackStub::ReadSurfaceCaptureConfig(RSSurfaceCaptureConfig& captureConfig, MessageParcel& data)
76 {
77     // read mainScreenRect only to reduce ipc data size
78     if (!data.ReadBool(captureConfig.isHdrCapture) ||
79         !data.ReadBool(captureConfig.needF16WindowCaptureForScRGB) ||
80         !data.ReadFloat(captureConfig.mainScreenRect.left_) ||
81         !data.ReadFloat(captureConfig.mainScreenRect.top_) ||
82         !data.ReadFloat(captureConfig.mainScreenRect.right_) ||
83         !data.ReadFloat(captureConfig.mainScreenRect.bottom_) ||
84         !data.ReadUint64(captureConfig.uiCaptureInRangeParam.endNodeId) ||
85         !data.ReadBool(captureConfig.uiCaptureInRangeParam.useBeginNodeSize) ||
86         !data.ReadFloat(captureConfig.specifiedAreaRect.left_) ||
87         !data.ReadFloat(captureConfig.specifiedAreaRect.top_) ||
88         !data.ReadFloat(captureConfig.specifiedAreaRect.right_) ||
89         !data.ReadFloat(captureConfig.specifiedAreaRect.bottom_)) {
90         RS_LOGE("RSSurfaceCaptureCallbackStub::ReadSurfaceCaptureConfig read parcel failed!");
91         return false;
92     }
93     return true;
94 }
95 } // namespace Rosen
96 } // namespace OHOS
97