1e0dac50fSopenharmony_ci/* 2e0dac50fSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License. 5e0dac50fSopenharmony_ci * You may obtain a copy of the License at 6e0dac50fSopenharmony_ci * 7e0dac50fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0dac50fSopenharmony_ci * 9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and 13e0dac50fSopenharmony_ci * limitations under the License. 14e0dac50fSopenharmony_ci */ 15e0dac50fSopenharmony_ci 16e0dac50fSopenharmony_ci#include "snapshot_proxy.h" 17e0dac50fSopenharmony_ci#include "ipc_types.h" 18e0dac50fSopenharmony_ci#include "pixel_map.h" 19e0dac50fSopenharmony_ci#include "window_manager_hilog.h" 20e0dac50fSopenharmony_ci#include "wm_common.h" 21e0dac50fSopenharmony_ci 22e0dac50fSopenharmony_cinamespace OHOS { 23e0dac50fSopenharmony_cinamespace Rosen { 24e0dac50fSopenharmony_cinamespace { 25e0dac50fSopenharmony_ciconstexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SnapshotProxy"}; 26e0dac50fSopenharmony_ci} 27e0dac50fSopenharmony_ci 28e0dac50fSopenharmony_ciint32_t SnapshotProxy::GetSnapshot(const sptr<IRemoteObject>& token, AAFwk::Snapshot& snapshot) 29e0dac50fSopenharmony_ci{ 30e0dac50fSopenharmony_ci MessageParcel data; 31e0dac50fSopenharmony_ci MessageParcel reply; 32e0dac50fSopenharmony_ci MessageOption option; 33e0dac50fSopenharmony_ci 34e0dac50fSopenharmony_ci if (!data.WriteInterfaceToken(GetDescriptor())) { 35e0dac50fSopenharmony_ci WLOGFE("WriteInterfaceToken failed"); 36e0dac50fSopenharmony_ci return static_cast<int32_t>(WMError::WM_ERROR_IPC_FAILED); 37e0dac50fSopenharmony_ci } 38e0dac50fSopenharmony_ci 39e0dac50fSopenharmony_ci if (!data.WriteRemoteObject(token)) { 40e0dac50fSopenharmony_ci WLOGFE("Write ability token failed"); 41e0dac50fSopenharmony_ci return static_cast<int32_t>(WMError::WM_ERROR_IPC_FAILED); 42e0dac50fSopenharmony_ci } 43e0dac50fSopenharmony_ci 44e0dac50fSopenharmony_ci sptr<IRemoteObject> remote = Remote(); 45e0dac50fSopenharmony_ci if (remote == nullptr) { 46e0dac50fSopenharmony_ci WLOGFE("remote is null"); 47e0dac50fSopenharmony_ci return static_cast<int32_t>(WMError::WM_ERROR_IPC_FAILED); 48e0dac50fSopenharmony_ci } 49e0dac50fSopenharmony_ci if (remote->SendRequest(TRANS_ID_GET_SNAPSHOT, data, reply, option) != ERR_NONE) { 50e0dac50fSopenharmony_ci return static_cast<int32_t>(WMError::WM_ERROR_IPC_FAILED); 51e0dac50fSopenharmony_ci } 52e0dac50fSopenharmony_ci 53e0dac50fSopenharmony_ci std::shared_ptr<Media::PixelMap> pixelMap(reply.ReadParcelable<Media::PixelMap>()); 54e0dac50fSopenharmony_ci snapshot.SetPixelMap(pixelMap); 55e0dac50fSopenharmony_ci return reply.ReadInt32(); 56e0dac50fSopenharmony_ci} 57e0dac50fSopenharmony_ci} 58e0dac50fSopenharmony_ci}