diff --git a/frameworks/surface/include/buffer_client_producer.h b/frameworks/surface/include/buffer_client_producer.h index 9bfa233ddb..5996d21211 100644 --- a/frameworks/surface/include/buffer_client_producer.h +++ b/frameworks/surface/include/buffer_client_producer.h @@ -82,6 +82,9 @@ public: GSError GetTransform(GraphicTransformType &transform) override; GSError AttachBufferToQueue(sptr& buffer) override; GSError DetachBufferFromQueue(sptr& buffer) override; + + GSError GetTransformHint(GraphicTransformType &transformHint) override; + GSError SetTransformHint(GraphicTransformType transformHint) override; private: static inline BrokerDelegator delegator_; std::string name_ = "not init"; diff --git a/frameworks/surface/include/buffer_handle.h b/frameworks/surface/include/buffer_handle.h index 030f163160..ba9a27f603 100644 --- a/frameworks/surface/include/buffer_handle.h +++ b/frameworks/surface/include/buffer_handle.h @@ -31,7 +31,6 @@ typedef struct { int32_t format; /**< the format of memory */ uint64_t usage; /**< the usage of memory */ void *virAddr; /**< Virtual address of memory */ - int32_t key; /**< Shared memory key */ uint64_t phyAddr; /**< Physical address */ uint32_t reserveFds; /**< the number of reserved fd value */ uint32_t reserveInts; /**< the number of reserved integer value */ diff --git a/frameworks/surface/include/buffer_queue.h b/frameworks/surface/include/buffer_queue.h index b2e7607e44..bfc959ad1d 100644 --- a/frameworks/surface/include/buffer_queue.h +++ b/frameworks/surface/include/buffer_queue.h @@ -154,6 +154,9 @@ public: GSError AttachBufferToQueue(sptr &buffer, InvokerType invokerType); GSError DetachBufferFromQueue(sptr &buffer, InvokerType invokerType); + GSError SetTransformHint(GraphicTransformType transformHint); + GraphicTransformType GetTransformHint() const; + private: GSError AllocBuffer(sptr& buffer, const BufferRequestConfig &config); void DeleteBufferInCache(uint32_t sequence); @@ -213,6 +216,7 @@ private: sptr lastFlusedFence_; wptr wpCSurfaceDelegator_; bool isCpuAccessable_ = false; + GraphicTransformType transformHint_ = GraphicTransformType::GRAPHIC_ROTATE_NONE; }; }; // namespace OHOS diff --git a/frameworks/surface/include/buffer_queue_producer.h b/frameworks/surface/include/buffer_queue_producer.h index b7ff31d196..43f0527287 100644 --- a/frameworks/surface/include/buffer_queue_producer.h +++ b/frameworks/surface/include/buffer_queue_producer.h @@ -95,6 +95,9 @@ public: GSError AttachBufferToQueue(sptr& buffer) override; GSError DetachBufferFromQueue(sptr& buffer) override; + GSError SetTransformHint(GraphicTransformType transformHint) override; + GSError GetTransformHint(GraphicTransformType &transformHint) override; + private: GSError CheckConnectLocked(); GSError SetTunnelHandle(const sptr &handle); @@ -130,6 +133,8 @@ private: int32_t GetTransformRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t AttachBufferToQueueRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); int32_t DetachBufferFromQueueRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); + int32_t SetTransformHintRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); + int32_t GetTransformHintRemote(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); using BufferQueueProducerFunc = int32_t (BufferQueueProducer::*)(MessageParcel &arguments, MessageParcel &reply, MessageOption &option); diff --git a/frameworks/surface/include/consumer_surface.h b/frameworks/surface/include/consumer_surface.h index dcaa232e3f..7af456bf07 100644 --- a/frameworks/surface/include/consumer_surface.h +++ b/frameworks/surface/include/consumer_surface.h @@ -129,6 +129,8 @@ public: void ConsumerRequestCpuAccess(bool on) override; GSError AttachBufferToQueue(sptr& buffer) override; GSError DetachBufferFromQueue(sptr& buffer) override; + GraphicTransformType GetTransformHint() const override; + GSError SetTransformHint(GraphicTransformType transformHint) override; private: std::map userData_; diff --git a/frameworks/surface/include/producer_surface.h b/frameworks/surface/include/producer_surface.h index 5c35c1f4cb..fbb26f6928 100644 --- a/frameworks/surface/include/producer_surface.h +++ b/frameworks/surface/include/producer_surface.h @@ -131,6 +131,8 @@ public: GSError ClearUserDataChangeListener() override; GSError AttachBufferToQueue(sptr& buffer) override; GSError DetachBufferFromQueue(sptr& buffer) override; + GraphicTransformType GetTransformHint() const override; + GSError SetTransformHint(GraphicTransformType transformHint) override; private: bool IsRemote(); void CleanAllLocked(); diff --git a/frameworks/surface/src/buffer_client_producer.cpp b/frameworks/surface/src/buffer_client_producer.cpp index 826c0fe3a4..92e6e92a59 100644 --- a/frameworks/surface/src/buffer_client_producer.cpp +++ b/frameworks/surface/src/buffer_client_producer.cpp @@ -587,4 +587,34 @@ GSError BufferClientProducer::GetTransform(GraphicTransformType &transform) transform = static_cast(reply.ReadUint32()); return GSERROR_OK; } + +GSError BufferClientProducer::GetTransformHint(GraphicTransformType &transformHint) +{ + DEFINE_MESSAGE_VARIABLES(arguments, reply, option, BLOGE); + SEND_REQUEST(BUFFER_PRODUCER_GET_TRANSFORMHINT, arguments, reply, option); + + auto ret = static_cast(reply.ReadInt32()); + if (ret != GSERROR_OK) { + BLOGN_FAILURE("Remote return %{public}d", static_cast(ret)); + return ret; + } + transformHint = static_cast(reply.ReadUint32()); + return GSERROR_OK; +} + +GSError BufferClientProducer::SetTransformHint(GraphicTransformType transformHint) +{ + DEFINE_MESSAGE_VARIABLES(arguments, reply, option, BLOGE); + + arguments.WriteUint32(static_cast(transformHint)); + + SEND_REQUEST(BUFFER_PRODUCER_SET_TRANSFORMHINT, arguments, reply, option); + int32_t ret = reply.ReadInt32(); + if (ret != GSERROR_OK) { + BLOGN_FAILURE("Remote return %{public}d", ret); + return (GSError)ret; + } + + return GSERROR_OK; +} }; // namespace OHOS diff --git a/frameworks/surface/src/buffer_queue.cpp b/frameworks/surface/src/buffer_queue.cpp index d1cbaacb25..ab36e98e13 100644 --- a/frameworks/surface/src/buffer_queue.cpp +++ b/frameworks/surface/src/buffer_queue.cpp @@ -1237,6 +1237,17 @@ GraphicTransformType BufferQueue::GetTransform() const return transform_; } +GSError BufferQueue::SetTransformHint(GraphicTransformType transformHint) +{ + transformHint_ = transformHint; + return GSERROR_OK; +} + +GraphicTransformType BufferQueue::GetTransformHint() const +{ + return transformHint_; +} + GSError BufferQueue::IsSupportedAlloc(const std::vector &infos, std::vector &supporteds) const { diff --git a/frameworks/surface/src/buffer_queue_producer.cpp b/frameworks/surface/src/buffer_queue_producer.cpp index d2308b5534..fd3f815ad5 100644 --- a/frameworks/surface/src/buffer_queue_producer.cpp +++ b/frameworks/surface/src/buffer_queue_producer.cpp @@ -70,6 +70,8 @@ BufferQueueProducer::BufferQueueProducer(sptr bufferQueue) memberFuncMap_[BUFFER_PRODUCER_ATTACH_BUFFER_TO_QUEUE] = &BufferQueueProducer::AttachBufferToQueueRemote; memberFuncMap_[BUFFER_PRODUCER_DETACH_BUFFER_FROM_QUEUE] = &BufferQueueProducer::DetachBufferFromQueueRemote; memberFuncMap_[BUFFER_PRODUCER_SET_DEFAULT_USAGE] = &BufferQueueProducer::SetDefaultUsageRemote; + memberFuncMap_[BUFFER_PRODUCER_GET_TRANSFORMHINT] = &BufferQueueProducer::GetTransformHintRemote; + memberFuncMap_[BUFFER_PRODUCER_SET_TRANSFORMHINT] = &BufferQueueProducer::SetTransformHintRemote; } BufferQueueProducer::~BufferQueueProducer() @@ -507,6 +509,31 @@ int32_t BufferQueueProducer::GetTransformRemote( return 0; } +int32_t BufferQueueProducer::SetTransformHintRemote(MessageParcel &arguments, + MessageParcel &reply, MessageOption &option) +{ + GraphicTransformType transformHint = static_cast(arguments.ReadUint32()); + GSError sret = SetTransformHint(transformHint); + reply.WriteInt32(sret); + return 0; +} + +int32_t BufferQueueProducer::GetTransformHintRemote( + MessageParcel &arguments, MessageParcel &reply, MessageOption &option) +{ + GraphicTransformType transformHint = GraphicTransformType::GRAPHIC_ROTATE_BUTT; + auto ret = GetTransformHint(transformHint); + if (ret != GSERROR_OK) { + reply.WriteInt32(static_cast(ret)); + return -1; + } + + reply.WriteInt32(GSERROR_OK); + reply.WriteUint32(static_cast(transformHint)); + + return 0; +} + GSError BufferQueueProducer::RequestBuffer(const BufferRequestConfig &config, sptr &bedata, RequestBufferReturnValue &retval) { @@ -724,6 +751,25 @@ GSError BufferQueueProducer::GetTransform(GraphicTransformType &transform) return GSERROR_OK; } +GSError BufferQueueProducer::SetTransformHint(GraphicTransformType transformHint) +{ + if (bufferQueue_ == nullptr) { + return GSERROR_INVALID_ARGUMENTS; + } + return bufferQueue_->SetTransformHint(transformHint); +} + +GSError BufferQueueProducer::GetTransformHint(GraphicTransformType &transformHint) +{ + std::lock_guard lock(mutex_); + if (bufferQueue_ == nullptr) { + transformHint = GraphicTransformType::GRAPHIC_ROTATE_BUTT; + return GSERROR_INVALID_ARGUMENTS; + } + transformHint = bufferQueue_->GetTransformHint(); + return GSERROR_OK; +} + GSError BufferQueueProducer::IsSupportedAlloc(const std::vector &infos, std::vector &supporteds) { diff --git a/frameworks/surface/src/consumer_surface.cpp b/frameworks/surface/src/consumer_surface.cpp index dbeea1c683..dbdbd333bc 100644 --- a/frameworks/surface/src/consumer_surface.cpp +++ b/frameworks/surface/src/consumer_surface.cpp @@ -532,4 +532,19 @@ void ConsumerSurface::ConsumerRequestCpuAccess(bool on) { consumer_->ConsumerRequestCpuAccess(on); } + +GraphicTransformType ConsumerSurface::GetTransformHint() const +{ + GraphicTransformType transformHint = GraphicTransformType::GRAPHIC_ROTATE_BUTT; + if (producer_->GetTransformHint(transformHint) != GSERROR_OK) { + BLOGNE("Warning ProducerSurface GetTransformHint failed."); + return GraphicTransformType::GRAPHIC_ROTATE_BUTT; + } + return transformHint; +} + +GSError ConsumerSurface::SetTransformHint(GraphicTransformType transformHint) +{ + return producer_->SetTransformHint(transformHint); +} } // namespace OHOS diff --git a/frameworks/surface/src/native_window.cpp b/frameworks/surface/src/native_window.cpp index 18b6cf7c4c..6b62c5e883 100644 --- a/frameworks/surface/src/native_window.cpp +++ b/frameworks/surface/src/native_window.cpp @@ -523,6 +523,36 @@ int32_t CreateNativeWindowFromSurfaceId(uint64_t surfaceId, OHNativeWindow **win return OHOS::GSERROR_OK; } +int32_t NativeWindowGetTransformHint(OHNativeWindow *window, GraphicTransformType *transform) +{ + if (window == nullptr || window->surface == nullptr || transform == nullptr) { + BLOGE("parameter error, please check input parameter"); + return OHOS::GSERROR_INVALID_ARGUMENTS; + } + *transform = window->surface->GetTransformHint(); + return OHOS::GSERROR_OK; +} + +int32_t NativeWindowSetTransformHint(OHNativeWindow *window, GraphicTransformType transform) +{ + if (window == nullptr || window->surface == nullptr) { + BLOGE("parameter error, please check input parameter"); + return OHOS::GSERROR_INVALID_ARGUMENTS; + } + return window->surface->SetTransformHint(transform); +} + +int32_t NativeWindowGetDefaultWidthAndHeight(OHNativeWindow *window, int32_t *width, int32_t *height) +{ + if (window == nullptr || window->surface == nullptr || width == nullptr || height == nullptr) { + BLOGE("parameter error, please check input parameter"); + return OHOS::GSERROR_INVALID_ARGUMENTS; + } + *width = window->surface->GetDefaultWidth(); + *height = window->surface->GetDefaultHeight(); + return OHOS::GSERROR_OK; +} + NativeWindow::NativeWindow() : NativeWindowMagic(NATIVE_OBJECT_MAGIC_WINDOW), surface(nullptr) { } diff --git a/frameworks/surface/src/producer_surface.cpp b/frameworks/surface/src/producer_surface.cpp index 55231f31ff..5894e19477 100644 --- a/frameworks/surface/src/producer_surface.cpp +++ b/frameworks/surface/src/producer_surface.cpp @@ -22,6 +22,7 @@ #include "buffer_producer_listener.h" #include "sync_fence.h" #include "native_window.h" +#include "surface_utils.h" namespace OHOS { namespace { @@ -360,6 +361,21 @@ int32_t ProducerSurface::GetDefaultHeight() return producer_->GetDefaultHeight(); } +GraphicTransformType ProducerSurface::GetTransformHint() const +{ + GraphicTransformType transformHint = GraphicTransformType::GRAPHIC_ROTATE_BUTT; + if (producer_->GetTransformHint(transformHint) != GSERROR_OK) { + BLOGNE("Warning ProducerSurface GetTransformHint failed."); + return GraphicTransformType::GRAPHIC_ROTATE_BUTT; + } + return transformHint; +} + +GSError ProducerSurface::SetTransformHint(GraphicTransformType transformHint) +{ + return producer_->SetTransformHint(transformHint); +} + GSError ProducerSurface::SetDefaultUsage(uint64_t usage) { return producer_->SetDefaultUsage(usage); diff --git a/frameworks/surface/src/surface_utils.cpp b/frameworks/surface/src/surface_utils.cpp index c008010ce3..36a9e35bc0 100644 --- a/frameworks/surface/src/surface_utils.cpp +++ b/frameworks/surface/src/surface_utils.cpp @@ -71,7 +71,7 @@ SurfaceError SurfaceUtils::Remove(uint64_t uniqueId) { std::lock_guard lockGuard(mutex_); if (surfaceCache_.count(uniqueId) == 0) { - BLOGW("Delete failed without surface by uniqueId %" PRIu64, uniqueId); + BLOGD("Delete failed without surface by uniqueId %" PRIu64, uniqueId); return GSERROR_INVALID_OPERATING; } surfaceCache_.erase(uniqueId); diff --git a/frameworks/surface/test/unittest/native_window_test.cpp b/frameworks/surface/test/unittest/native_window_test.cpp index 3594b86c82..a8a67c6b67 100644 --- a/frameworks/surface/test/unittest/native_window_test.cpp +++ b/frameworks/surface/test/unittest/native_window_test.cpp @@ -1311,4 +1311,42 @@ HWTEST_F(NativeWindowTest, SetTunnelHandle004, Function | MediumTest | Level1) ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_NO_ENTRY); FreeOHExtDataHandle(handle); } + +/* +* Function: NativeWindowGetTransformHint +* Type: Function +* Rank: Important(1) +* EnvConditions: N/A +* CaseDescription: 1. call NativeWindowGetTransformHint with normal parameters and check ret +* @tc.require: issueI5GMZN issueI5IWHW + */ +HWTEST_F(NativeWindowTest, NativeWindowGetTransformHint001, Function | MediumTest | Level1) +{ + GraphicTransformType transform = GraphicTransformType::GRAPHIC_ROTATE_180; + ASSERT_EQ(NativeWindowGetTransformHint(nullptr, &transform), OHOS::GSERROR_INVALID_ARGUMENTS); + ASSERT_EQ(NativeWindowSetTransformHint(nullptr, transform), OHOS::GSERROR_INVALID_ARGUMENTS); + ASSERT_EQ(NativeWindowSetTransformHint(nativeWindow, transform), OHOS::GSERROR_OK); + transform = GraphicTransformType::GRAPHIC_ROTATE_NONE; + ASSERT_EQ(NativeWindowGetTransformHint(nativeWindow, &transform), OHOS::GSERROR_OK); + ASSERT_EQ(transform, GraphicTransformType::GRAPHIC_ROTATE_180); +} + +/* +* Function: NativeWindowGetDefaultWidthAndHeight +* Type: Function +* Rank: Important(1) +* EnvConditions: N/A +* CaseDescription: 1. call NativeWindowGetDefaultWidthAndHeight with normal parameters and check ret +* @tc.require: issueI5GMZN issueI5IWHW + */ +HWTEST_F(NativeWindowTest, NativeWindowGetDefaultWidthAndHeight001, Function | MediumTest | Level1) +{ + ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nullptr, nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS); + cSurface->SetDefaultWidthAndHeight(300, 400); + int32_t width; + int32_t height; + ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nativeWindow, &width, &height), OHOS::GSERROR_OK); + ASSERT_EQ(width, 300); + ASSERT_EQ(height, 400); +} } diff --git a/interfaces/inner_api/surface/ibuffer_producer.h b/interfaces/inner_api/surface/ibuffer_producer.h index e5afca570d..b187d4debd 100644 --- a/interfaces/inner_api/surface/ibuffer_producer.h +++ b/interfaces/inner_api/surface/ibuffer_producer.h @@ -97,6 +97,8 @@ public: virtual GSError AttachBufferToQueue(sptr& buffer) = 0; virtual GSError DetachBufferFromQueue(sptr& buffer) = 0; + virtual GSError GetTransformHint(GraphicTransformType &transformHint) = 0; + virtual GSError SetTransformHint(GraphicTransformType transformHint) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"surf.IBufferProducer"); protected: @@ -132,6 +134,8 @@ protected: BUFFER_PRODUCER_ATTACH_BUFFER_TO_QUEUE = 28, BUFFER_PRODUCER_DETACH_BUFFER_FROM_QUEUE = 29, BUFFER_PRODUCER_SET_DEFAULT_USAGE = 30, + BUFFER_PRODUCER_GET_TRANSFORMHINT = 31, + BUFFER_PRODUCER_SET_TRANSFORMHINT = 32, }; }; } // namespace OHOS diff --git a/interfaces/inner_api/surface/surface.h b/interfaces/inner_api/surface/surface.h index bed819cdd5..14b90cde2d 100644 --- a/interfaces/inner_api/surface/surface.h +++ b/interfaces/inner_api/surface/surface.h @@ -132,6 +132,9 @@ public: virtual GSError AttachBufferToQueue(sptr& buffer) = 0; virtual GSError DetachBufferFromQueue(sptr& buffer) = 0; + virtual GraphicTransformType GetTransformHint() const = 0; + virtual GSError SetTransformHint(GraphicTransformType transformHint) = 0; + protected: Surface() = default; }; diff --git a/interfaces/inner_api/surface/window.h b/interfaces/inner_api/surface/window.h index e6fabbbac1..7c79914002 100644 --- a/interfaces/inner_api/surface/window.h +++ b/interfaces/inner_api/surface/window.h @@ -17,6 +17,7 @@ #define NDK_INCLUDE_NATIVE_WINDOW_H_ #include "external_window.h" +#include "surface_type.h" #ifdef __cplusplus extern "C" { @@ -66,6 +67,9 @@ int32_t GetSurfaceId(OHNativeWindow *window, uint64_t *surfaceId); int32_t CreateNativeWindowFromSurfaceId(uint64_t surfaceId, OHNativeWindow **window); int32_t NativeWindowAttachBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer); int32_t NativeWindowDetachBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer); +int32_t NativeWindowGetTransformHint(OHNativeWindow *window, OHOS::GraphicTransformType *transform); +int32_t NativeWindowSetTransformHint(OHNativeWindow *window, OHOS::GraphicTransformType transform); +int32_t NativeWindowGetDefaultWidthAndHeight(OHNativeWindow *window, int32_t *width, int32_t *height); #ifdef __cplusplus }