1 /*
2 * Copyright (c) 2021 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 "snapshot_proxy.h"
17 #include "ipc_types.h"
18 #include "pixel_map.h"
19 #include "window_manager_hilog.h"
20 #include "wm_common.h"
21
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SnapshotProxy"};
26 }
27
GetSnapshot(const sptr<IRemoteObject> & token,AAFwk::Snapshot & snapshot)28 int32_t SnapshotProxy::GetSnapshot(const sptr<IRemoteObject> &token, AAFwk::Snapshot& snapshot)
29 {
30 MessageParcel data;
31 MessageParcel reply;
32 MessageOption option;
33
34 if (!data.WriteInterfaceToken(GetDescriptor())) {
35 WLOGFE("WriteInterfaceToken failed");
36 return static_cast<int32_t>(WMError::WM_ERROR_IPC_FAILED);
37 }
38
39 if (!data.WriteRemoteObject(token)) {
40 WLOGFE("Write ability token failed");
41 return static_cast<int32_t>(WMError::WM_ERROR_IPC_FAILED);
42 }
43
44 if (Remote()->SendRequest(TRANS_ID_GET_SNAPSHOT, data, reply, option) != ERR_NONE) {
45 return static_cast<int32_t>(WMError::WM_ERROR_IPC_FAILED);
46 }
47
48 std::shared_ptr<Media::PixelMap> pixelMap(reply.ReadParcelable<Media::PixelMap>());
49 snapshot.SetPixelMap(pixelMap);
50 return reply.ReadInt32();
51 }
52 }
53 }