mirror of
https://github.com/openharmony/graphic_surface.git
synced 2026-07-01 03:21:54 -04:00
Description: IPC switching interface
IssueNo: https://gitee.com/openharmony/communication_ipc/issues/I52D5F Feature or Bugfix: Bugfix Binary Source:No Signed-off-by: xing-tai-zhang <zhangxingtai@huawei.com>
This commit is contained in:
@@ -43,7 +43,7 @@ shared_library("surface") {
|
||||
public_deps = [ "//foundation/graphic/utils:lite_graphic_utils" ]
|
||||
deps = [
|
||||
"//drivers/peripheral/display/hal:hdi_display",
|
||||
"//foundation/communication/ipc_lite:liteipc_adapter",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
]
|
||||
ldflags = [
|
||||
|
||||
@@ -14,10 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "buffer_client_producer.h"
|
||||
|
||||
#include "liteipc_adapter.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "serializer.h"
|
||||
#include "ipc_skeleton.h"
|
||||
|
||||
#include "buffer_common.h"
|
||||
#include "buffer_manager.h"
|
||||
@@ -39,18 +36,20 @@ SurfaceBufferImpl* BufferClientProducer::RequestBuffer(uint8_t wait)
|
||||
IpcIo requestIo;
|
||||
uint8_t requestIoData[DEFAULT_IPC_SIZE];
|
||||
IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0);
|
||||
IpcIoPushUint8(&requestIo, wait);
|
||||
WriteUint8(&requestIo, wait);
|
||||
IpcIo reply;
|
||||
uintptr_t ptr;
|
||||
int32_t ret = Transact(nullptr, sid_, REQUEST_BUFFER, &requestIo, &reply, LITEIPC_FLAG_DEFAULT, &ptr);
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
int32_t ret = SendRequest(sid_, REQUEST_BUFFER, &requestIo, &reply, option, &ptr);
|
||||
if (ret != 0) {
|
||||
GRAPHIC_LOGW("RequestBuffer Transact failed");
|
||||
GRAPHIC_LOGW("RequestBuffer SendRequest failed");
|
||||
return nullptr;
|
||||
}
|
||||
ret = IpcIoPopInt32(&reply);
|
||||
ReadInt32(&reply, &ret);
|
||||
if (ret != 0) {
|
||||
GRAPHIC_LOGW("RequestBuffer generic failed code=%d", ret);
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -60,16 +59,16 @@ SurfaceBufferImpl* BufferClientProducer::RequestBuffer(uint8_t wait)
|
||||
if (manager == nullptr) {
|
||||
GRAPHIC_LOGW("BufferManager is null, usage(%d)", buffer->GetUsage());
|
||||
delete buffer;
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!manager->MapBuffer(*buffer)) {
|
||||
Cancel(buffer);
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
return nullptr;
|
||||
}
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@@ -92,13 +91,15 @@ int32_t BufferClientProducer::FlushBuffer(SurfaceBufferImpl* buffer)
|
||||
buffer->WriteToIpcIo(requestIo);
|
||||
IpcIo reply;
|
||||
uintptr_t ptr;
|
||||
ret = Transact(nullptr, sid_, FLUSH_BUFFER, &requestIo, &reply, LITEIPC_FLAG_DEFAULT, &ptr);
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
ret = SendRequest(sid_, FLUSH_BUFFER, &requestIo, &reply, option, &ptr);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
GRAPHIC_LOGW("FlushBuffer failed");
|
||||
return ret;
|
||||
}
|
||||
ret = IpcIoPopInt32(&reply);
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
ReadInt32(&reply, &ret);
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
GRAPHIC_LOGW("FlushBuffer failed code=%d", ret);
|
||||
return -1;
|
||||
@@ -119,11 +120,13 @@ void BufferClientProducer::Cancel(SurfaceBufferImpl* buffer)
|
||||
buffer->WriteToIpcIo(requestIo);
|
||||
IpcIo reply;
|
||||
uintptr_t ptr;
|
||||
int32_t ret = Transact(nullptr, sid_, CANCEL_BUFFER, &requestIo, &reply, LITEIPC_FLAG_DEFAULT, &ptr);
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
int32_t ret = SendRequest(sid_, CANCEL_BUFFER, &requestIo, &reply, option, &ptr);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
GRAPHIC_LOGW("Cancel buffer failed");
|
||||
} else {
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
}
|
||||
BufferManager* manager = BufferManager::GetInstance();
|
||||
RETURN_IF_FAIL(manager);
|
||||
@@ -136,14 +139,16 @@ void BufferClientProducer::SetQueueSize(uint8_t queueSize)
|
||||
IpcIo requestIo;
|
||||
uint8_t requestIoData[DEFAULT_IPC_SIZE];
|
||||
IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0);
|
||||
IpcIoPushUint8(&requestIo, queueSize);
|
||||
WriteUint8(&requestIo, queueSize);
|
||||
IpcIo reply;
|
||||
uintptr_t ptr;
|
||||
int32_t ret = Transact(nullptr, sid_, SET_QUEUE_SIZE, &requestIo, &reply, LITEIPC_FLAG_DEFAULT, &ptr);
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
int32_t ret = SendRequest(sid_, SET_QUEUE_SIZE, &requestIo, &reply, option, &ptr);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
GRAPHIC_LOGW("Set Attr(%d:%u) failed", SET_QUEUE_SIZE, queueSize);
|
||||
}
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
}
|
||||
|
||||
uint8_t BufferClientProducer::GetQueueSize()
|
||||
@@ -153,19 +158,22 @@ uint8_t BufferClientProducer::GetQueueSize()
|
||||
IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0);
|
||||
IpcIo reply;
|
||||
uintptr_t ptr;
|
||||
int32_t ret = Transact(nullptr, sid_, GET_QUEUE_SIZE, &requestIo, &reply, LITEIPC_FLAG_DEFAULT, &ptr);
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
int32_t ret = SendRequest(sid_, GET_QUEUE_SIZE, &requestIo, &reply, option, &ptr);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
GRAPHIC_LOGW("GetAttr Transact failed, errno=%d", ret);
|
||||
GRAPHIC_LOGW("GetAttr SendRequest failed, errno=%d", ret);
|
||||
return 0;
|
||||
}
|
||||
ret = IpcIoPopInt32(&reply);
|
||||
ReadInt32(&reply, &ret);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
GRAPHIC_LOGW("GetAttr failed code=%d", GET_QUEUE_SIZE);
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
return 0;
|
||||
}
|
||||
uint8_t queueSize = IpcIoPopUint8(&reply);
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
uint8_t queueSize;
|
||||
ReadUint8(&reply, &queueSize);
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
return queueSize;
|
||||
}
|
||||
|
||||
@@ -174,15 +182,17 @@ void BufferClientProducer::SetWidthAndHeight(uint32_t width, uint32_t height)
|
||||
IpcIo requestIo;
|
||||
uint8_t requestIoData[DEFAULT_IPC_SIZE];
|
||||
IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0);
|
||||
IpcIoPushUint32(&requestIo, width);
|
||||
IpcIoPushUint32(&requestIo, height);
|
||||
WriteUint32(&requestIo, width);
|
||||
WriteUint32(&requestIo, height);
|
||||
IpcIo reply;
|
||||
uintptr_t ptr;
|
||||
int32_t ret = Transact(nullptr, sid_, SET_WIDTH_AND_HEIGHT, &requestIo, &reply, LITEIPC_FLAG_DEFAULT, &ptr);
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
int32_t ret = SendRequest(sid_, SET_WIDTH_AND_HEIGHT, &requestIo, &reply, option, &ptr);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
GRAPHIC_LOGW("SetWidthAndHeight failed");
|
||||
} else {
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -248,15 +258,17 @@ void BufferClientProducer::SetUserData(const std::string& key, const std::string
|
||||
IpcIo requestIo;
|
||||
uint8_t requestIoData[DEFAULT_IPC_SIZE];
|
||||
IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0);
|
||||
IpcIoPushString(&requestIo, key.c_str());
|
||||
IpcIoPushString(&requestIo, value.c_str());
|
||||
WriteString(&requestIo, key.c_str());
|
||||
WriteString(&requestIo, value.c_str());
|
||||
IpcIo reply;
|
||||
uintptr_t ptr;
|
||||
int32_t ret = Transact(nullptr, sid_, SET_USER_DATA, &requestIo, &reply, LITEIPC_FLAG_DEFAULT, &ptr);
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
int32_t ret = SendRequest(sid_, SET_USER_DATA, &requestIo, &reply, option, &ptr);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
GRAPHIC_LOGW("Get user data(%s) failed", key.c_str());
|
||||
} else {
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,21 +278,23 @@ std::string BufferClientProducer::GetUserData(const std::string& key)
|
||||
IpcIo requestIo;
|
||||
uint8_t requestIoData[DEFAULT_IPC_SIZE];
|
||||
IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0);
|
||||
IpcIoPushString(&requestIo, key.c_str());
|
||||
WriteString(&requestIo, key.c_str());
|
||||
IpcIo reply;
|
||||
uintptr_t ptr;
|
||||
int32_t ret = Transact(nullptr, sid_, GET_USER_DATA, &requestIo, &reply, LITEIPC_FLAG_DEFAULT, &ptr);
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
int32_t ret = SendRequest(sid_, GET_USER_DATA, &requestIo, &reply, option, &ptr);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
return sValue;
|
||||
} else {
|
||||
size_t len = 0;
|
||||
const char* value = reinterpret_cast<char *>(IpcIoPopString(&reply, &len));
|
||||
const char* value = reinterpret_cast<char *>(ReadString(&reply, &len));
|
||||
if (value == nullptr || len == 0) {
|
||||
GRAPHIC_LOGW("Get user data failed");
|
||||
} else {
|
||||
sValue = value;
|
||||
}
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
return sValue;
|
||||
}
|
||||
}
|
||||
@@ -290,14 +304,16 @@ void BufferClientProducer::SetAttr(uint32_t code, uint32_t value)
|
||||
IpcIo requestIo;
|
||||
uint8_t requestIoData[DEFAULT_IPC_SIZE];
|
||||
IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0);
|
||||
IpcIoPushUint32(&requestIo, value);
|
||||
WriteUint32(&requestIo, value);
|
||||
IpcIo reply;
|
||||
uintptr_t ptr;
|
||||
int32_t ret = Transact(nullptr, sid_, code, &requestIo, &reply, LITEIPC_FLAG_DEFAULT, &ptr);
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
int32_t ret = SendRequest(sid_, code, &requestIo, &reply, option, &ptr);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
GRAPHIC_LOGW("Set Attr(%u:%u) failed", code, value);
|
||||
} else {
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,19 +324,22 @@ uint32_t BufferClientProducer::GetAttr(uint32_t code)
|
||||
IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0);
|
||||
IpcIo reply;
|
||||
uintptr_t ptr;
|
||||
int32_t ret = Transact(nullptr, sid_, code, &requestIo, &reply, LITEIPC_FLAG_DEFAULT, &ptr);
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
int32_t ret = SendRequest(sid_, code, &requestIo, &reply, option, &ptr);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
GRAPHIC_LOGW("GetAttr Transact failed, errno=%d", ret);
|
||||
GRAPHIC_LOGW("GetAttr SendRequest failed, errno=%d", ret);
|
||||
return 0;
|
||||
}
|
||||
ret = IpcIoPopInt32(&reply);
|
||||
ReadInt32(&reply, &ret);
|
||||
if (ret != SURFACE_ERROR_OK) {
|
||||
GRAPHIC_LOGW("GetAttr failed code=%d", code);
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
return 0;
|
||||
}
|
||||
uint32_t attr = IpcIoPopUint32(&reply);
|
||||
FreeBuffer(nullptr, reinterpret_cast<void *>(ptr));
|
||||
uint32_t attr;
|
||||
ReadUint32(&reply, &attr);
|
||||
FreeBuffer(reinterpret_cast<void *>(ptr));
|
||||
return attr;
|
||||
}
|
||||
} // end namespace
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
#ifndef GRAPHIC_LITE_BUFFER_CLIENT_PRODUCER_H
|
||||
#define GRAPHIC_LITE_BUFFER_CLIENT_PRODUCER_H
|
||||
|
||||
#include <pthread.h>
|
||||
#include "buffer_producer.h"
|
||||
#include "buffer_queue.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "serializer.h"
|
||||
#include "surface_buffer.h"
|
||||
namespace OHOS {
|
||||
@@ -178,6 +179,7 @@ private:
|
||||
uint32_t GetAttr(uint32_t code);
|
||||
void SetAttr(uint32_t code, uint32_t value);
|
||||
SvcIdentity sid_;
|
||||
IpcObjectStub objectStub_;
|
||||
};
|
||||
} // end namespace
|
||||
|
||||
|
||||
@@ -24,168 +24,156 @@ namespace OHOS {
|
||||
const int32_t DEFAULT_IPC_SIZE = 100;
|
||||
|
||||
extern "C" {
|
||||
typedef int32_t (*IpcMsgHandle)(BufferQueueProducer* product, void *ipcMsg, IpcIo *io);
|
||||
typedef int32_t (*IpcMsgHandle)(BufferQueueProducer* product, IpcIo *io, IpcIo *reply);
|
||||
};
|
||||
|
||||
static int32_t OnRequestBuffer(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnRequestBuffer(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
uint8_t isWaiting = IpcIoPopUint8(io);
|
||||
uint8_t isWaiting;
|
||||
ReadUint8(io, &isWaiting);
|
||||
SurfaceBufferImpl* buffer = product->RequestBuffer(isWaiting);
|
||||
IpcIo reply;
|
||||
uint8_t tmpData[DEFAULT_IPC_SIZE];
|
||||
IpcIoInit(&reply, tmpData, DEFAULT_IPC_SIZE, 1);
|
||||
uint32_t ret = -1;
|
||||
if (buffer == nullptr) {
|
||||
GRAPHIC_LOGW("get buffer failed");
|
||||
IpcIoPushInt32(&reply, -1);
|
||||
WriteInt32(reply, -1);
|
||||
ret = -1;
|
||||
} else {
|
||||
IpcIoPushInt32(&reply, 0);
|
||||
buffer->WriteToIpcIo(reply);
|
||||
WriteInt32(reply, 0);
|
||||
buffer->WriteToIpcIo(*reply);
|
||||
ret = 0;
|
||||
}
|
||||
SendReply(nullptr, ipcMsg, &reply);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t OnFlushBuffer(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnFlushBuffer(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
IpcIo reply;
|
||||
uint8_t tmpData[DEFAULT_IPC_SIZE];
|
||||
IpcIoInit(&reply, tmpData, DEFAULT_IPC_SIZE, 1);
|
||||
SurfaceBufferImpl buffer;
|
||||
buffer.ReadFromIpcIo(*io);
|
||||
IpcIoPushInt32(&reply, product->EnqueueBuffer(buffer));
|
||||
SendReply(nullptr, ipcMsg, &reply);
|
||||
WriteInt32(reply, product->EnqueueBuffer(buffer));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t OnCancelBuffer(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnCancelBuffer(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
SurfaceBufferImpl buffer;
|
||||
buffer.ReadFromIpcIo(*io);
|
||||
product->Cancel(&buffer);
|
||||
IpcIo reply;
|
||||
uint8_t tmpData[DEFAULT_IPC_SIZE];
|
||||
IpcIoInit(&reply, tmpData, DEFAULT_IPC_SIZE, 1);
|
||||
IpcIoPushInt32(&reply, 0);
|
||||
SendReply(nullptr, ipcMsg, &reply);
|
||||
WriteInt32(reply, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t OnGetAttr(uint32_t attr, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnGetAttr(uint32_t attr, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
IpcIo reply;
|
||||
uint8_t tmpData[DEFAULT_IPC_SIZE];
|
||||
IpcIoInit(&reply, tmpData, DEFAULT_IPC_SIZE, 1);
|
||||
IpcIoPushInt32(&reply, 0);
|
||||
IpcIoPushUint32(&reply, attr);
|
||||
SendReply(nullptr, ipcMsg, &reply);
|
||||
WriteInt32(reply, 0);
|
||||
WriteUint32(reply, attr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t OnSendReply(void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnSendReply(IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
IpcIo reply;
|
||||
uint8_t tmpData[DEFAULT_IPC_SIZE];
|
||||
IpcIoInit(&reply, tmpData, DEFAULT_IPC_SIZE, 1);
|
||||
IpcIoPushInt32(&reply, 0);
|
||||
SendReply(nullptr, ipcMsg, &reply);
|
||||
WriteInt32(reply, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t OnSetQueueSize(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnSetQueueSize(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
uint32_t queueSize = IpcIoPopUint32(io);
|
||||
uint32_t queueSize;
|
||||
ReadUint32(io, &queueSize);
|
||||
product->SetQueueSize(queueSize);
|
||||
return OnSendReply(ipcMsg, io);
|
||||
return OnSendReply(io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnGetQueueSize(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnGetQueueSize(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
return OnGetAttr(product->GetQueueSize(), ipcMsg, io);
|
||||
return OnGetAttr(product->GetQueueSize(), io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnSetWidthAndHeight(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnSetWidthAndHeight(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
uint32_t width = IpcIoPopUint32(io);
|
||||
uint32_t height = IpcIoPopUint32(io);
|
||||
uint32_t width;
|
||||
ReadUint32(io, &width);
|
||||
uint32_t height;
|
||||
ReadUint32(io, &height);
|
||||
product->SetWidthAndHeight(width, height);
|
||||
return OnSendReply(ipcMsg, io);
|
||||
return OnSendReply(io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnGetWidth(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnGetWidth(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
return OnGetAttr(product->GetWidth(), ipcMsg, io);
|
||||
return OnGetAttr(product->GetWidth(), io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnGetHeight(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnGetHeight(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
return OnGetAttr(product->GetHeight(), ipcMsg, io);
|
||||
return OnGetAttr(product->GetHeight(), io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnSetFormat(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnSetFormat(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
uint32_t format = IpcIoPopUint32(io);
|
||||
uint32_t format;
|
||||
ReadUint32(io, &format);
|
||||
product->SetFormat(format);
|
||||
return OnSendReply(ipcMsg, io);
|
||||
return OnSendReply(io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnGetFormat(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnGetFormat(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
return OnGetAttr(product->GetFormat(), ipcMsg, io);
|
||||
return OnGetAttr(product->GetFormat(), io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnSetStrideAlignment(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnSetStrideAlignment(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
uint32_t strideAlignment = IpcIoPopUint32(io);
|
||||
uint32_t strideAlignment;
|
||||
ReadUint32(io, &strideAlignment);
|
||||
product->SetStrideAlignment(strideAlignment);
|
||||
return OnSendReply(ipcMsg, io);
|
||||
return OnSendReply(io, reply);
|
||||
}
|
||||
|
||||
static int32_t GetStrideAlignment(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t GetStrideAlignment(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
return OnGetAttr(product->GetStrideAlignment(), ipcMsg, io);
|
||||
return OnGetAttr(product->GetStrideAlignment(), io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnGetStride(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnGetStride(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
return OnGetAttr(product->GetStride(), ipcMsg, io);
|
||||
return OnGetAttr(product->GetStride(), io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnSetSize(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnSetSize(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
uint32_t size = IpcIoPopUint32(io);
|
||||
uint32_t size;
|
||||
ReadUint32(io, &size);
|
||||
product->SetSize(size);
|
||||
return OnSendReply(ipcMsg, io);
|
||||
return OnSendReply(io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnGetSize(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnGetSize(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
return OnGetAttr(product->GetSize(), ipcMsg, io);
|
||||
return OnGetAttr(product->GetSize(), io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnSetUsage(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnSetUsage(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
uint32_t usage = IpcIoPopUint32(io);
|
||||
uint32_t usage;
|
||||
ReadUint32(io, &usage);
|
||||
product->SetUsage(usage);
|
||||
return OnSendReply(ipcMsg, io);
|
||||
return OnSendReply(io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnGetUsage(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnGetUsage(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
return OnGetAttr(product->GetUsage(), ipcMsg, io);
|
||||
return OnGetAttr(product->GetUsage(), io, reply);
|
||||
}
|
||||
|
||||
static int32_t OnSetUserData(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnSetUserData(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
size_t len = 0;
|
||||
const char* key = reinterpret_cast<char *>(IpcIoPopString(io, &len));
|
||||
const char* key = reinterpret_cast<char *>(ReadString(io, &len));
|
||||
if (key == nullptr || len == 0) {
|
||||
GRAPHIC_LOGW("Get user data key failed");
|
||||
return -1;
|
||||
}
|
||||
const char* value = reinterpret_cast<char *>(IpcIoPopString(io, &len));
|
||||
const char* value = reinterpret_cast<char *>(ReadString(io, &len));
|
||||
if (value == nullptr || len == 0) {
|
||||
GRAPHIC_LOGW("Get user data value failed");
|
||||
return -1;
|
||||
@@ -193,25 +181,21 @@ static int32_t OnSetUserData(BufferQueueProducer* product, void *ipcMsg, IpcIo *
|
||||
std::string sKey = key;
|
||||
std::string sValue = value;
|
||||
product->SetUserData(sKey, sValue);
|
||||
OnSendReply(ipcMsg, io);
|
||||
OnSendReply(io, reply);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t OnGetUserData(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
|
||||
static int32_t OnGetUserData(BufferQueueProducer* product, IpcIo *io, IpcIo *reply)
|
||||
{
|
||||
size_t len = 0;
|
||||
const char* key = reinterpret_cast<char *>(IpcIoPopString(io, &len));
|
||||
const char* key = reinterpret_cast<char *>(ReadString(io, &len));
|
||||
if (key == nullptr || len == 0) {
|
||||
GRAPHIC_LOGW("Get user data key failed");
|
||||
return -1;
|
||||
}
|
||||
std::string sKey = key;
|
||||
std::string value = product->GetUserData(sKey);
|
||||
IpcIo reply;
|
||||
uint8_t tmpData[DEFAULT_IPC_SIZE];
|
||||
IpcIoInit(&reply, tmpData, DEFAULT_IPC_SIZE, 0);
|
||||
IpcIoPushString(&reply, value.c_str());
|
||||
SendReply(nullptr, ipcMsg, &reply);
|
||||
WriteString(reply, value.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -386,20 +370,18 @@ void BufferQueueProducer::UnregisterConsumerListener()
|
||||
consumerListener_ = nullptr;
|
||||
}
|
||||
|
||||
int32_t BufferQueueProducer::OnIpcMsg(void *ipcMsg, IpcIo *io)
|
||||
int32_t BufferQueueProducer::OnIpcMsg(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option)
|
||||
{
|
||||
if (ipcMsg == nullptr || io == nullptr) {
|
||||
if (data == NULL) {
|
||||
GRAPHIC_LOGW("Invalid parameter, null pointer");
|
||||
return SURFACE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
uint32_t code;
|
||||
(void)GetCode(ipcMsg, &code);
|
||||
|
||||
if (code >= MAX_REQUEST_CODE) {
|
||||
GRAPHIC_LOGW("Resquest code(%u) does not support.", code);
|
||||
FreeBuffer(nullptr, ipcMsg);
|
||||
return SURFACE_ERROR_INVALID_REQUEST;
|
||||
}
|
||||
return g_ipcMsgHandleList[code](this, ipcMsg, io);
|
||||
return g_ipcMsgHandleList[code](this, data, reply);
|
||||
}
|
||||
|
||||
void BufferQueueProducer::SetUserData(const std::string& key, const std::string& value)
|
||||
|
||||
@@ -198,8 +198,7 @@ public:
|
||||
* @param [in] IpcIo pointer, ipc msg object, contains request attr...
|
||||
* @returns 0 is succeed; other is failed.
|
||||
*/
|
||||
int32_t OnIpcMsg(void *ipcMsg, IpcIo *io);
|
||||
|
||||
int32_t OnIpcMsg(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option);
|
||||
private:
|
||||
BufferQueue* bufferQueue_;
|
||||
IBufferConsumerListener* consumerListener_;
|
||||
|
||||
@@ -22,7 +22,7 @@ Surface* Surface::CreateSurface()
|
||||
SurfaceImpl* surface = new SurfaceImpl();
|
||||
if (surface != nullptr) {
|
||||
if (surface->Init()) {
|
||||
return surface;
|
||||
return reinterpret_cast<Surface *>(surface);
|
||||
} else {
|
||||
GRAPHIC_LOGE("surface init failed");
|
||||
delete surface;
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
*/
|
||||
|
||||
#include "surface_buffer_impl.h"
|
||||
|
||||
#include "securec.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -125,26 +124,31 @@ int32_t SurfaceBufferImpl::GetData(uint32_t key, uint8_t* type, void** data, uin
|
||||
|
||||
void SurfaceBufferImpl::ReadFromIpcIo(IpcIo& io)
|
||||
{
|
||||
bufferData_.handle.key = IpcIoPopInt32(&io);
|
||||
bufferData_.handle.phyAddr = IpcIoPopUint64(&io);
|
||||
bufferData_.handle.reserveFds = IpcIoPopUint32(&io);
|
||||
bufferData_.handle.reserveInts = IpcIoPopUint32(&io);
|
||||
bufferData_.size = IpcIoPopUint32(&io);
|
||||
bufferData_.usage = IpcIoPopUint32(&io);
|
||||
len_ = IpcIoPopUint32(&io);
|
||||
uint32_t extDataSize = IpcIoPopUint32(&io);
|
||||
ReadInt32(&io, &(bufferData_.handle.key));
|
||||
ReadUint64(&io, &(bufferData_.handle.phyAddr));
|
||||
ReadUint32(&io, &(bufferData_.handle.reserveFds));
|
||||
ReadUint32(&io, &(bufferData_.handle.reserveInts));
|
||||
ReadUint32(&io, &(bufferData_.size));
|
||||
ReadUint32(&io, &(bufferData_.usage));
|
||||
ReadUint32(&io, &len_);
|
||||
uint32_t extDataSize;
|
||||
ReadUint32(&io, &extDataSize);
|
||||
if (extDataSize > 0 && extDataSize < MAX_USER_DATA_COUNT) {
|
||||
for (uint32_t i = 0; i < extDataSize; i++) {
|
||||
uint32_t key = IpcIoPopUint32(&io);
|
||||
uint32_t type = IpcIoPopUint32(&io);
|
||||
uint32_t key;
|
||||
ReadUint32(&io, &key);
|
||||
uint32_t type;
|
||||
ReadUint32(&io, &type);
|
||||
switch (type) {
|
||||
case BUFFER_DATA_TYPE_INT_32: {
|
||||
int32_t value = IpcIoPopInt32(&io);
|
||||
int32_t value;
|
||||
ReadInt32(&io, &value);
|
||||
SetInt32(key, value);
|
||||
break;
|
||||
}
|
||||
case BUFFER_DATA_TYPE_INT_64: {
|
||||
int64_t value = IpcIoPopInt64(&io);
|
||||
int64_t value;
|
||||
ReadInt64(&io, &value);
|
||||
SetInt64(key, value);
|
||||
break;
|
||||
}
|
||||
@@ -156,27 +160,27 @@ void SurfaceBufferImpl::ReadFromIpcIo(IpcIo& io)
|
||||
}
|
||||
void SurfaceBufferImpl::WriteToIpcIo(IpcIo& io)
|
||||
{
|
||||
IpcIoPushInt32(&io, bufferData_.handle.key);
|
||||
IpcIoPushUint64(&io, bufferData_.handle.phyAddr);
|
||||
IpcIoPushUint32(&io, bufferData_.handle.reserveFds);
|
||||
IpcIoPushUint32(&io, bufferData_.handle.reserveInts);
|
||||
IpcIoPushUint32(&io, bufferData_.size);
|
||||
IpcIoPushUint32(&io, bufferData_.usage);
|
||||
IpcIoPushUint32(&io, len_);
|
||||
IpcIoPushUint32(&io, extDatas_.size());
|
||||
WriteInt32(&io, bufferData_.handle.key);
|
||||
WriteUint64(&io, bufferData_.handle.phyAddr);
|
||||
WriteUint32(&io, bufferData_.handle.reserveFds);
|
||||
WriteUint32(&io, bufferData_.handle.reserveInts);
|
||||
WriteUint32(&io, bufferData_.size);
|
||||
WriteUint32(&io, bufferData_.usage);
|
||||
WriteUint32(&io, len_);
|
||||
WriteUint32(&io, extDatas_.size());
|
||||
if (!extDatas_.empty()) {
|
||||
std::map<uint32_t, ExtraData>::iterator iter;
|
||||
for (iter = extDatas_.begin(); iter != extDatas_.end(); ++iter) {
|
||||
uint32_t key = iter->first;
|
||||
ExtraData value = iter->second;
|
||||
IpcIoPushUint32(&io, key);
|
||||
IpcIoPushUint32(&io, value.type);
|
||||
WriteUint32(&io, key);
|
||||
WriteUint32(&io, value.type);
|
||||
switch (value.type) {
|
||||
case BUFFER_DATA_TYPE_INT_32:
|
||||
IpcIoPushInt32(&io, *(reinterpret_cast<int32_t *>(value.value)));
|
||||
WriteInt32(&io, *(reinterpret_cast<int32_t *>(value.value)));
|
||||
break;
|
||||
case BUFFER_DATA_TYPE_INT_64:
|
||||
IpcIoPushInt64(&io, *(reinterpret_cast<int64_t *>(value.value)));
|
||||
WriteInt64(&io, *(reinterpret_cast<int64_t *>(value.value)));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
+19
-31
@@ -46,11 +46,9 @@ SurfaceImpl::~SurfaceImpl()
|
||||
delete producer_;
|
||||
producer_ = nullptr;
|
||||
}
|
||||
#ifdef __LINUX__
|
||||
if (sid_.handle != 0) {
|
||||
BinderRelease(sid_.ipcContext, sid_.handle);
|
||||
ReleaseSvc(sid_);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool SurfaceImpl::Init()
|
||||
@@ -85,17 +83,12 @@ bool SurfaceImpl::Init()
|
||||
producer_ = nullptr;
|
||||
return false;
|
||||
}
|
||||
SvcIdentity svc;
|
||||
int32_t ret = RegisterIpcCallback(IpcRequestHandler, 0, IPC_WAIT_FOREVER, &svc, producer_);
|
||||
if (ret != LITEIPC_OK) {
|
||||
GRAPHIC_LOGE("Surface RegisterIpcCallback failed.");
|
||||
delete consumer_;
|
||||
consumer_ = nullptr;
|
||||
delete producer_;
|
||||
producer_ = nullptr;
|
||||
return false;
|
||||
}
|
||||
sid_ = svc;
|
||||
objectStub_.func = IpcRequestHandler;
|
||||
objectStub_.args = reinterpret_cast<void*>(producer_);
|
||||
objectStub_.isRemote = false;
|
||||
sid_.handle = IPC_INVALID_HANDLE;
|
||||
sid_.token = SERVICE_TYPE_ANONYMOUS;
|
||||
sid_.cookie = reinterpret_cast<uintptr_t>(&objectStub_);
|
||||
} else {
|
||||
producer_ = new BufferClientProducer(sid_);
|
||||
if (producer_ == nullptr) {
|
||||
@@ -260,37 +253,32 @@ void SurfaceImpl::UnregisterConsumerListener()
|
||||
|
||||
void SurfaceImpl::WriteIoIpcIo(IpcIo& io)
|
||||
{
|
||||
IpcIoPushSvc(&io, &sid_);
|
||||
WriteRemoteObject(&io, &sid_);
|
||||
}
|
||||
|
||||
int32_t SurfaceImpl::IpcRequestHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg)
|
||||
int32_t SurfaceImpl::IpcRequestHandler(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option)
|
||||
{
|
||||
BufferQueueProducer* product = reinterpret_cast<BufferQueueProducer*>(arg);
|
||||
return product->OnIpcMsg(ipcMsg, io);
|
||||
BufferQueueProducer* product = reinterpret_cast<BufferQueueProducer*>(option.args);
|
||||
return product->OnIpcMsg(code, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t SurfaceImpl::DoIpcMsg(void* ipcMsg, IpcIo* io)
|
||||
int32_t SurfaceImpl::DoIpcMsg(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option)
|
||||
{
|
||||
RETURN_VAL_IF_FAIL(producer_, SURFACE_ERROR_INVALID_PARAM);
|
||||
RETURN_VAL_IF_FAIL(ipcMsg != nullptr, SURFACE_ERROR_INVALID_PARAM);
|
||||
RETURN_VAL_IF_FAIL(io != nullptr, SURFACE_ERROR_INVALID_PARAM);
|
||||
RETURN_VAL_IF_FAIL(data != nullptr, SURFACE_ERROR_INVALID_PARAM);
|
||||
BufferQueueProducer* bufferQueueProducer = reinterpret_cast<BufferQueueProducer*>(producer_);
|
||||
return bufferQueueProducer->OnIpcMsg(ipcMsg, io);
|
||||
return bufferQueueProducer->OnIpcMsg(code, data, reply, option);
|
||||
}
|
||||
|
||||
Surface* SurfaceImpl::GenericSurfaceByIpcIo(IpcIo& io)
|
||||
{
|
||||
SvcIdentity* sid = IpcIoPopSvc(&io);
|
||||
if (sid != nullptr) {
|
||||
SurfaceImpl* surface = new SurfaceImpl(*sid);
|
||||
#ifdef __LINUX__
|
||||
BinderAcquire(sid->ipcContext, sid->handle);
|
||||
free(sid);
|
||||
sid = nullptr;
|
||||
#endif
|
||||
SvcIdentity sid;
|
||||
bool ret = ReadRemoteObject(&io, &sid);
|
||||
if (ret) {
|
||||
SurfaceImpl* surface = new SurfaceImpl(sid);
|
||||
if (surface != nullptr) {
|
||||
if (surface->Init()) {
|
||||
return surface;
|
||||
return reinterpret_cast<Surface *>(surface);
|
||||
} else {
|
||||
GRAPHIC_LOGE("surface init failed");
|
||||
delete surface;
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
#define GRAPHIC_LITE_SURFACE_BUFFER_IMPL_H
|
||||
|
||||
#include <map>
|
||||
#include <pthread.h>
|
||||
#include "buffer_common.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "serializer.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "surface_buffer.h"
|
||||
|
||||
namespace OHOS {
|
||||
|
||||
@@ -216,7 +216,7 @@ public:
|
||||
* @param [in] IpcIo pointer, ipc msg object, constains request attr...
|
||||
* @returns 0 is succeed; other is failed.
|
||||
*/
|
||||
int32_t DoIpcMsg(void* ipcMsg, IpcIo* io);
|
||||
int32_t DoIpcMsg(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option);
|
||||
|
||||
/**
|
||||
* @brief Surface init succeed or not
|
||||
@@ -230,9 +230,10 @@ private:
|
||||
* @param [in] SvcIdentity. Consumer sid, ipc sending request param.
|
||||
* @returns Surface pointer.
|
||||
*/
|
||||
explicit SurfaceImpl(const SvcIdentity& sid);
|
||||
static int32_t IpcRequestHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg);
|
||||
SurfaceImpl(const SvcIdentity& sid);
|
||||
static int32_t IpcRequestHandler(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option);
|
||||
SvcIdentity sid_;
|
||||
IpcObjectStub objectStub_;
|
||||
BufferQueueConsumer* consumer_;
|
||||
BufferProducer* producer_;
|
||||
bool IsConsumer_;
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ if (ohos_build_type == "debug") {
|
||||
output_dir = "$root_out_dir/test/unittest/graphic"
|
||||
sources = [ "unittest/graphic_surface_test.cpp" ]
|
||||
deps = [
|
||||
"//foundation/communication/ipc_lite:liteipc_adapter",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single",
|
||||
"//foundation/graphic/surface:surface",
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user