14ed2deddSopenharmony_ci/* 24ed2deddSopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 34ed2deddSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44ed2deddSopenharmony_ci * you may not use this file except in compliance with the License. 54ed2deddSopenharmony_ci * You may obtain a copy of the License at 64ed2deddSopenharmony_ci * 74ed2deddSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84ed2deddSopenharmony_ci * 94ed2deddSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104ed2deddSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114ed2deddSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124ed2deddSopenharmony_ci * See the License for the specific language governing permissions and 134ed2deddSopenharmony_ci * limitations under the License. 144ed2deddSopenharmony_ci */ 154ed2deddSopenharmony_ci 164ed2deddSopenharmony_ci#include "buffer_client_producer.h" 174ed2deddSopenharmony_ci#include "ipc_skeleton.h" 184ed2deddSopenharmony_ci 194ed2deddSopenharmony_ci#include "buffer_common.h" 204ed2deddSopenharmony_ci#include "buffer_manager.h" 214ed2deddSopenharmony_ci#include "buffer_queue.h" 224ed2deddSopenharmony_ci#include "surface_buffer_impl.h" 234ed2deddSopenharmony_ci 244ed2deddSopenharmony_cinamespace OHOS { 254ed2deddSopenharmony_ciconst int32_t DEFAULT_IPC_SIZE = 200; 264ed2deddSopenharmony_ciBufferClientProducer::BufferClientProducer(const SvcIdentity& sid) : sid_(sid) 274ed2deddSopenharmony_ci{ 284ed2deddSopenharmony_ci} 294ed2deddSopenharmony_ci 304ed2deddSopenharmony_ciBufferClientProducer::~BufferClientProducer() 314ed2deddSopenharmony_ci{ 324ed2deddSopenharmony_ci} 334ed2deddSopenharmony_ci 344ed2deddSopenharmony_ciSurfaceBufferImpl* BufferClientProducer::RequestBuffer(uint8_t wait) 354ed2deddSopenharmony_ci{ 364ed2deddSopenharmony_ci IpcIo requestIo; 374ed2deddSopenharmony_ci uint8_t requestIoData[DEFAULT_IPC_SIZE]; 384ed2deddSopenharmony_ci IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0); 394ed2deddSopenharmony_ci WriteUint8(&requestIo, wait); 404ed2deddSopenharmony_ci IpcIo reply; 414ed2deddSopenharmony_ci uintptr_t ptr; 424ed2deddSopenharmony_ci MessageOption option; 434ed2deddSopenharmony_ci MessageOptionInit(&option); 444ed2deddSopenharmony_ci int32_t ret = SendRequest(sid_, REQUEST_BUFFER, &requestIo, &reply, option, &ptr); 454ed2deddSopenharmony_ci if (ret != 0) { 464ed2deddSopenharmony_ci GRAPHIC_LOGW("RequestBuffer SendRequest failed"); 474ed2deddSopenharmony_ci return nullptr; 484ed2deddSopenharmony_ci } 494ed2deddSopenharmony_ci ReadInt32(&reply, &ret); 504ed2deddSopenharmony_ci if (ret != 0) { 514ed2deddSopenharmony_ci GRAPHIC_LOGW("RequestBuffer generic failed code=%d", ret); 524ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 534ed2deddSopenharmony_ci return nullptr; 544ed2deddSopenharmony_ci } 554ed2deddSopenharmony_ci 564ed2deddSopenharmony_ci SurfaceBufferImpl* buffer = new SurfaceBufferImpl(); 574ed2deddSopenharmony_ci if (buffer == nullptr) { 584ed2deddSopenharmony_ci GRAPHIC_LOGW("SurfaceBufferImpl buffer is null"); 594ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 604ed2deddSopenharmony_ci return nullptr; 614ed2deddSopenharmony_ci } 624ed2deddSopenharmony_ci buffer->ReadFromIpcIo(reply); 634ed2deddSopenharmony_ci BufferManager* manager = BufferManager::GetInstance(); 644ed2deddSopenharmony_ci if (manager == nullptr) { 654ed2deddSopenharmony_ci GRAPHIC_LOGW("BufferManager is null, usage(%d)", buffer->GetUsage()); 664ed2deddSopenharmony_ci delete buffer; 674ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 684ed2deddSopenharmony_ci return nullptr; 694ed2deddSopenharmony_ci } 704ed2deddSopenharmony_ci 714ed2deddSopenharmony_ci if (!manager->MapBuffer(*buffer)) { 724ed2deddSopenharmony_ci Cancel(buffer); 734ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 744ed2deddSopenharmony_ci return nullptr; 754ed2deddSopenharmony_ci } 764ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 774ed2deddSopenharmony_ci return buffer; 784ed2deddSopenharmony_ci} 794ed2deddSopenharmony_ci 804ed2deddSopenharmony_ciint32_t BufferClientProducer::FlushBuffer(SurfaceBufferImpl* buffer) 814ed2deddSopenharmony_ci{ 824ed2deddSopenharmony_ci RETURN_VAL_IF_FAIL(buffer, -1); 834ed2deddSopenharmony_ci BufferManager* manager = BufferManager::GetInstance(); 844ed2deddSopenharmony_ci RETURN_VAL_IF_FAIL(manager, -1); 854ed2deddSopenharmony_ci int32_t ret = SURFACE_ERROR_OK; 864ed2deddSopenharmony_ci if (buffer->GetUsage() == BUFFER_CONSUMER_USAGE_HARDWARE_PRODUCER_CACHE) { 874ed2deddSopenharmony_ci ret = manager->FlushCache(*buffer); 884ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 894ed2deddSopenharmony_ci GRAPHIC_LOGW("Flush buffer failed, ret=%d", ret); 904ed2deddSopenharmony_ci return ret; 914ed2deddSopenharmony_ci } 924ed2deddSopenharmony_ci } 934ed2deddSopenharmony_ci IpcIo requestIo; 944ed2deddSopenharmony_ci uint8_t requestIoData[DEFAULT_IPC_SIZE]; 954ed2deddSopenharmony_ci IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0); 964ed2deddSopenharmony_ci buffer->WriteToIpcIo(requestIo); 974ed2deddSopenharmony_ci IpcIo reply; 984ed2deddSopenharmony_ci uintptr_t ptr; 994ed2deddSopenharmony_ci MessageOption option; 1004ed2deddSopenharmony_ci MessageOptionInit(&option); 1014ed2deddSopenharmony_ci ret = SendRequest(sid_, FLUSH_BUFFER, &requestIo, &reply, option, &ptr); 1024ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 1034ed2deddSopenharmony_ci GRAPHIC_LOGW("FlushBuffer failed"); 1044ed2deddSopenharmony_ci return ret; 1054ed2deddSopenharmony_ci } 1064ed2deddSopenharmony_ci ReadInt32(&reply, &ret); 1074ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 1084ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 1094ed2deddSopenharmony_ci GRAPHIC_LOGW("FlushBuffer failed code=%d", ret); 1104ed2deddSopenharmony_ci return -1; 1114ed2deddSopenharmony_ci } 1124ed2deddSopenharmony_ci manager->UnmapBuffer(*buffer); 1134ed2deddSopenharmony_ci delete buffer; 1144ed2deddSopenharmony_ci return ret; 1154ed2deddSopenharmony_ci} 1164ed2deddSopenharmony_ci 1174ed2deddSopenharmony_civoid BufferClientProducer::Cancel(SurfaceBufferImpl* buffer) 1184ed2deddSopenharmony_ci{ 1194ed2deddSopenharmony_ci if (buffer == nullptr) { 1204ed2deddSopenharmony_ci return; 1214ed2deddSopenharmony_ci } 1224ed2deddSopenharmony_ci IpcIo requestIo; 1234ed2deddSopenharmony_ci uint8_t requestIoData[DEFAULT_IPC_SIZE]; 1244ed2deddSopenharmony_ci IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0); 1254ed2deddSopenharmony_ci buffer->WriteToIpcIo(requestIo); 1264ed2deddSopenharmony_ci IpcIo reply; 1274ed2deddSopenharmony_ci uintptr_t ptr; 1284ed2deddSopenharmony_ci MessageOption option; 1294ed2deddSopenharmony_ci MessageOptionInit(&option); 1304ed2deddSopenharmony_ci int32_t ret = SendRequest(sid_, CANCEL_BUFFER, &requestIo, &reply, option, &ptr); 1314ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 1324ed2deddSopenharmony_ci GRAPHIC_LOGW("Cancel buffer failed"); 1334ed2deddSopenharmony_ci } else { 1344ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 1354ed2deddSopenharmony_ci } 1364ed2deddSopenharmony_ci BufferManager* manager = BufferManager::GetInstance(); 1374ed2deddSopenharmony_ci RETURN_IF_FAIL(manager); 1384ed2deddSopenharmony_ci manager->UnmapBuffer(*buffer); 1394ed2deddSopenharmony_ci delete buffer; 1404ed2deddSopenharmony_ci} 1414ed2deddSopenharmony_ci 1424ed2deddSopenharmony_civoid BufferClientProducer::SetQueueSize(uint8_t queueSize) 1434ed2deddSopenharmony_ci{ 1444ed2deddSopenharmony_ci IpcIo requestIo; 1454ed2deddSopenharmony_ci uint8_t requestIoData[DEFAULT_IPC_SIZE]; 1464ed2deddSopenharmony_ci IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0); 1474ed2deddSopenharmony_ci WriteUint8(&requestIo, queueSize); 1484ed2deddSopenharmony_ci IpcIo reply; 1494ed2deddSopenharmony_ci uintptr_t ptr; 1504ed2deddSopenharmony_ci MessageOption option; 1514ed2deddSopenharmony_ci MessageOptionInit(&option); 1524ed2deddSopenharmony_ci int32_t ret = SendRequest(sid_, SET_QUEUE_SIZE, &requestIo, &reply, option, &ptr); 1534ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 1544ed2deddSopenharmony_ci GRAPHIC_LOGW("Set Attr(%d:%u) failed", SET_QUEUE_SIZE, queueSize); 1554ed2deddSopenharmony_ci } 1564ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 1574ed2deddSopenharmony_ci} 1584ed2deddSopenharmony_ci 1594ed2deddSopenharmony_ciuint8_t BufferClientProducer::GetQueueSize() 1604ed2deddSopenharmony_ci{ 1614ed2deddSopenharmony_ci IpcIo requestIo; 1624ed2deddSopenharmony_ci uint8_t requestIoData[DEFAULT_IPC_SIZE]; 1634ed2deddSopenharmony_ci IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0); 1644ed2deddSopenharmony_ci IpcIo reply; 1654ed2deddSopenharmony_ci uintptr_t ptr; 1664ed2deddSopenharmony_ci MessageOption option; 1674ed2deddSopenharmony_ci MessageOptionInit(&option); 1684ed2deddSopenharmony_ci int32_t ret = SendRequest(sid_, GET_QUEUE_SIZE, &requestIo, &reply, option, &ptr); 1694ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 1704ed2deddSopenharmony_ci GRAPHIC_LOGW("GetAttr SendRequest failed, errno=%d", ret); 1714ed2deddSopenharmony_ci return 0; 1724ed2deddSopenharmony_ci } 1734ed2deddSopenharmony_ci ReadInt32(&reply, &ret); 1744ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 1754ed2deddSopenharmony_ci GRAPHIC_LOGW("GetAttr failed code=%d", GET_QUEUE_SIZE); 1764ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 1774ed2deddSopenharmony_ci return 0; 1784ed2deddSopenharmony_ci } 1794ed2deddSopenharmony_ci uint8_t queueSize; 1804ed2deddSopenharmony_ci ReadUint8(&reply, &queueSize); 1814ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 1824ed2deddSopenharmony_ci return queueSize; 1834ed2deddSopenharmony_ci} 1844ed2deddSopenharmony_ci 1854ed2deddSopenharmony_civoid BufferClientProducer::SetWidthAndHeight(uint32_t width, uint32_t height) 1864ed2deddSopenharmony_ci{ 1874ed2deddSopenharmony_ci IpcIo requestIo; 1884ed2deddSopenharmony_ci uint8_t requestIoData[DEFAULT_IPC_SIZE]; 1894ed2deddSopenharmony_ci IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0); 1904ed2deddSopenharmony_ci WriteUint32(&requestIo, width); 1914ed2deddSopenharmony_ci WriteUint32(&requestIo, height); 1924ed2deddSopenharmony_ci IpcIo reply; 1934ed2deddSopenharmony_ci uintptr_t ptr; 1944ed2deddSopenharmony_ci MessageOption option; 1954ed2deddSopenharmony_ci MessageOptionInit(&option); 1964ed2deddSopenharmony_ci int32_t ret = SendRequest(sid_, SET_WIDTH_AND_HEIGHT, &requestIo, &reply, option, &ptr); 1974ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 1984ed2deddSopenharmony_ci GRAPHIC_LOGW("SetWidthAndHeight failed"); 1994ed2deddSopenharmony_ci } else { 2004ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 2014ed2deddSopenharmony_ci } 2024ed2deddSopenharmony_ci return; 2034ed2deddSopenharmony_ci} 2044ed2deddSopenharmony_ci 2054ed2deddSopenharmony_ciuint32_t BufferClientProducer::GetWidth() 2064ed2deddSopenharmony_ci{ 2074ed2deddSopenharmony_ci return GetAttr(GET_WIDTH); 2084ed2deddSopenharmony_ci} 2094ed2deddSopenharmony_ci 2104ed2deddSopenharmony_ciuint32_t BufferClientProducer::GetHeight() 2114ed2deddSopenharmony_ci{ 2124ed2deddSopenharmony_ci return GetAttr(GET_HEIGHT); 2134ed2deddSopenharmony_ci} 2144ed2deddSopenharmony_ci 2154ed2deddSopenharmony_civoid BufferClientProducer::SetFormat(uint32_t format) 2164ed2deddSopenharmony_ci{ 2174ed2deddSopenharmony_ci SetAttr(SET_FORMAT, format); 2184ed2deddSopenharmony_ci} 2194ed2deddSopenharmony_ci 2204ed2deddSopenharmony_ciuint32_t BufferClientProducer::GetFormat() 2214ed2deddSopenharmony_ci{ 2224ed2deddSopenharmony_ci return GetAttr(GET_FORMAT); 2234ed2deddSopenharmony_ci} 2244ed2deddSopenharmony_ci 2254ed2deddSopenharmony_civoid BufferClientProducer::SetStrideAlignment(uint32_t strideAlignment) 2264ed2deddSopenharmony_ci{ 2274ed2deddSopenharmony_ci SetAttr(SET_STRIDE_ALIGNMENT, strideAlignment); 2284ed2deddSopenharmony_ci} 2294ed2deddSopenharmony_ci 2304ed2deddSopenharmony_ciuint32_t BufferClientProducer::GetStrideAlignment() 2314ed2deddSopenharmony_ci{ 2324ed2deddSopenharmony_ci return GetAttr(GET_STRIDE_ALIGNMENT); 2334ed2deddSopenharmony_ci} 2344ed2deddSopenharmony_ci 2354ed2deddSopenharmony_ciuint32_t BufferClientProducer::GetStride() 2364ed2deddSopenharmony_ci{ 2374ed2deddSopenharmony_ci return GetAttr(GET_STRIDE); 2384ed2deddSopenharmony_ci} 2394ed2deddSopenharmony_ci 2404ed2deddSopenharmony_civoid BufferClientProducer::SetSize(uint32_t size) 2414ed2deddSopenharmony_ci{ 2424ed2deddSopenharmony_ci SetAttr(SET_SIZE, size); 2434ed2deddSopenharmony_ci} 2444ed2deddSopenharmony_ci 2454ed2deddSopenharmony_ciuint32_t BufferClientProducer::GetSize() 2464ed2deddSopenharmony_ci{ 2474ed2deddSopenharmony_ci return GetAttr(GET_SIZE); 2484ed2deddSopenharmony_ci} 2494ed2deddSopenharmony_ci 2504ed2deddSopenharmony_civoid BufferClientProducer::SetUsage(uint32_t usage) 2514ed2deddSopenharmony_ci{ 2524ed2deddSopenharmony_ci SetAttr(SET_USAGE, usage); 2534ed2deddSopenharmony_ci} 2544ed2deddSopenharmony_ci 2554ed2deddSopenharmony_ciuint32_t BufferClientProducer::GetUsage() 2564ed2deddSopenharmony_ci{ 2574ed2deddSopenharmony_ci uint32_t usage = GetAttr(GET_USAGE); 2584ed2deddSopenharmony_ci return usage; 2594ed2deddSopenharmony_ci} 2604ed2deddSopenharmony_ci 2614ed2deddSopenharmony_civoid BufferClientProducer::SetUserData(const std::string& key, const std::string& value) 2624ed2deddSopenharmony_ci{ 2634ed2deddSopenharmony_ci IpcIo requestIo; 2644ed2deddSopenharmony_ci uint8_t requestIoData[DEFAULT_IPC_SIZE]; 2654ed2deddSopenharmony_ci IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0); 2664ed2deddSopenharmony_ci WriteString(&requestIo, key.c_str()); 2674ed2deddSopenharmony_ci WriteString(&requestIo, value.c_str()); 2684ed2deddSopenharmony_ci IpcIo reply; 2694ed2deddSopenharmony_ci uintptr_t ptr; 2704ed2deddSopenharmony_ci MessageOption option; 2714ed2deddSopenharmony_ci MessageOptionInit(&option); 2724ed2deddSopenharmony_ci int32_t ret = SendRequest(sid_, SET_USER_DATA, &requestIo, &reply, option, &ptr); 2734ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 2744ed2deddSopenharmony_ci GRAPHIC_LOGW("Get user data(%s) failed", key.c_str()); 2754ed2deddSopenharmony_ci } else { 2764ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 2774ed2deddSopenharmony_ci } 2784ed2deddSopenharmony_ci} 2794ed2deddSopenharmony_ci 2804ed2deddSopenharmony_cistd::string BufferClientProducer::GetUserData(const std::string& key) 2814ed2deddSopenharmony_ci{ 2824ed2deddSopenharmony_ci std::string sValue = std::string(); 2834ed2deddSopenharmony_ci IpcIo requestIo; 2844ed2deddSopenharmony_ci uint8_t requestIoData[DEFAULT_IPC_SIZE]; 2854ed2deddSopenharmony_ci IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0); 2864ed2deddSopenharmony_ci WriteString(&requestIo, key.c_str()); 2874ed2deddSopenharmony_ci IpcIo reply; 2884ed2deddSopenharmony_ci uintptr_t ptr; 2894ed2deddSopenharmony_ci MessageOption option; 2904ed2deddSopenharmony_ci MessageOptionInit(&option); 2914ed2deddSopenharmony_ci int32_t ret = SendRequest(sid_, GET_USER_DATA, &requestIo, &reply, option, &ptr); 2924ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 2934ed2deddSopenharmony_ci return sValue; 2944ed2deddSopenharmony_ci } else { 2954ed2deddSopenharmony_ci size_t len = 0; 2964ed2deddSopenharmony_ci const char* value = reinterpret_cast<char *>(ReadString(&reply, &len)); 2974ed2deddSopenharmony_ci if (value == nullptr || len == 0) { 2984ed2deddSopenharmony_ci GRAPHIC_LOGW("Get user data failed"); 2994ed2deddSopenharmony_ci } else { 3004ed2deddSopenharmony_ci sValue = value; 3014ed2deddSopenharmony_ci } 3024ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 3034ed2deddSopenharmony_ci return sValue; 3044ed2deddSopenharmony_ci } 3054ed2deddSopenharmony_ci} 3064ed2deddSopenharmony_ci 3074ed2deddSopenharmony_civoid BufferClientProducer::SetAttr(uint32_t code, uint32_t value) 3084ed2deddSopenharmony_ci{ 3094ed2deddSopenharmony_ci IpcIo requestIo; 3104ed2deddSopenharmony_ci uint8_t requestIoData[DEFAULT_IPC_SIZE]; 3114ed2deddSopenharmony_ci IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0); 3124ed2deddSopenharmony_ci WriteUint32(&requestIo, value); 3134ed2deddSopenharmony_ci IpcIo reply; 3144ed2deddSopenharmony_ci uintptr_t ptr; 3154ed2deddSopenharmony_ci MessageOption option; 3164ed2deddSopenharmony_ci MessageOptionInit(&option); 3174ed2deddSopenharmony_ci int32_t ret = SendRequest(sid_, code, &requestIo, &reply, option, &ptr); 3184ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 3194ed2deddSopenharmony_ci GRAPHIC_LOGW("Set Attr(%u:%u) failed", code, value); 3204ed2deddSopenharmony_ci } else { 3214ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 3224ed2deddSopenharmony_ci } 3234ed2deddSopenharmony_ci} 3244ed2deddSopenharmony_ci 3254ed2deddSopenharmony_ciuint32_t BufferClientProducer::GetAttr(uint32_t code) 3264ed2deddSopenharmony_ci{ 3274ed2deddSopenharmony_ci IpcIo requestIo; 3284ed2deddSopenharmony_ci uint8_t requestIoData[DEFAULT_IPC_SIZE]; 3294ed2deddSopenharmony_ci IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0); 3304ed2deddSopenharmony_ci IpcIo reply; 3314ed2deddSopenharmony_ci uintptr_t ptr; 3324ed2deddSopenharmony_ci MessageOption option; 3334ed2deddSopenharmony_ci MessageOptionInit(&option); 3344ed2deddSopenharmony_ci int32_t ret = SendRequest(sid_, code, &requestIo, &reply, option, &ptr); 3354ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 3364ed2deddSopenharmony_ci GRAPHIC_LOGW("GetAttr SendRequest failed, errno=%d", ret); 3374ed2deddSopenharmony_ci return 0; 3384ed2deddSopenharmony_ci } 3394ed2deddSopenharmony_ci ReadInt32(&reply, &ret); 3404ed2deddSopenharmony_ci if (ret != SURFACE_ERROR_OK) { 3414ed2deddSopenharmony_ci GRAPHIC_LOGW("GetAttr failed code=%d", code); 3424ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 3434ed2deddSopenharmony_ci return 0; 3444ed2deddSopenharmony_ci } 3454ed2deddSopenharmony_ci uint32_t attr; 3464ed2deddSopenharmony_ci ReadUint32(&reply, &attr); 3474ed2deddSopenharmony_ci FreeBuffer(reinterpret_cast<void *>(ptr)); 3484ed2deddSopenharmony_ci return attr; 3494ed2deddSopenharmony_ci} 3504ed2deddSopenharmony_ci} // end namespace 351