• 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         default: {
49             ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50             break;
51         }
52     }
53 
54     return ret;
55 }
56 
ReadSurfaceCaptureConfig(RSSurfaceCaptureConfig & captureConfig,MessageParcel & data)57 bool RSSurfaceCaptureCallbackStub::ReadSurfaceCaptureConfig(RSSurfaceCaptureConfig& captureConfig, MessageParcel& data)
58 {
59     uint8_t captureType { 0 };
60     if (!data.ReadFloat(captureConfig.scaleX) || !data.ReadFloat(captureConfig.scaleY) ||
61         !data.ReadBool(captureConfig.useDma) || !data.ReadBool(captureConfig.useCurWindow) ||
62         !data.ReadUint8(captureType) || !data.ReadBool(captureConfig.isSync) ||
63         !data.ReadFloat(captureConfig.mainScreenRect.left_) ||
64         !data.ReadFloat(captureConfig.mainScreenRect.top_) ||
65         !data.ReadFloat(captureConfig.mainScreenRect.right_) ||
66         !data.ReadFloat(captureConfig.mainScreenRect.bottom_)) {
67         RS_LOGE("RSSurfaceCaptureCallbackStub::ReadSurfaceCaptureConfig read parcel failed!");
68         return false;
69     }
70     captureConfig.captureType = static_cast<SurfaceCaptureType>(captureType);
71     return true;
72 }
73 } // namespace Rosen
74 } // namespace OHOS
75