diff --git a/surface/include/producer_surface.h b/surface/include/producer_surface.h index f9532a55a480f7b6c3eaae36fd2e9c92afcf9204..98b300ead6d0a89c4d12b20365d49b4a4017a0ac 100644 --- a/surface/include/producer_surface.h +++ b/surface/include/producer_surface.h @@ -167,7 +167,7 @@ private: GSError AddCacheLocked(sptr &bedataimpl, IBufferProducer::RequestBufferReturnValue &retval, BufferRequestConfig &config); GSError CleanCacheLocked(bool cleanAll); - + GSError SetMetadataValve(sptr& buffer); mutable std::mutex mutex_; std::atomic_bool inited_ = false; std::map> bufferProducerCache_; diff --git a/surface/src/native_buffer.cpp b/surface/src/native_buffer.cpp index 7b8b0f24759bc78b020dc3bd91396f2e2f110740..0a4b86226e259202b7e6787d9b040bcd8ae4b03c 100644 --- a/surface/src/native_buffer.cpp +++ b/surface/src/native_buffer.cpp @@ -288,11 +288,13 @@ int32_t OH_NativeBuffer_GetColorSpace(OH_NativeBuffer *buffer, OH_NativeBuffer_C BLOGE("GetColorSpaceType failed!, retVal:%d", ret); return OHOS::SURFACE_ERROR_UNKOWN; } - for (auto type : NATIVE_COLORSPACE_TO_HDI_MAP) { - if (type.second == colorSpaceType) { - *colorSpace = type.first; - return OHOS::SURFACE_ERROR_OK; - } + auto it = std::find_if(NATIVE_COLORSPACE_TO_HDI_MAP.begin(), NATIVE_COLORSPACE_TO_HDI_MAP.end(), + [colorSpaceType](const std::pair& element) { + return element.second == colorSpaceType; + }); + if (it != NATIVE_COLORSPACE_TO_HDI_MAP.end()) { + *colorSpace = it->first; + return OHOS::SURFACE_ERROR_OK; } BLOGE("the colorSpace does not support it."); return OHOS::SURFACE_ERROR_UNKOWN; @@ -327,7 +329,7 @@ int32_t OH_NativeBuffer_SetMetadataValue(OH_NativeBuffer *buffer, OH_NativeBuffe return OHOS::SURFACE_ERROR_OK; } -GSError OH_NativeBuffer_GetMatedataValueType(sptr sbuffer, int32_t *size, uint8_t **metadata) +static GSError OH_NativeBuffer_GetMatedataValueType(sptr sbuffer, int32_t *size, uint8_t **metadata) { CM_HDR_Metadata_Type hdrMetadataType = CM_METADATA_NONE; GSError ret = MetadataHelper::GetHDRMetadataType(sbuffer, hdrMetadataType); @@ -337,19 +339,21 @@ GSError OH_NativeBuffer_GetMatedataValueType(sptr sbuffer, int32_ BLOGE("GetHDRMetadataType failed!, retVal:%d", ret); return OHOS::SURFACE_ERROR_UNKOWN; } - for (auto type : NATIVE_METADATATYPE_TO_HDI_MAP) { - if (type.second == hdrMetadataType) { - *size = sizeof(OH_NativeBuffer_MetadataType); - *metadata = new uint8_t[*size]; - errno_t err = memcpy_s(*metadata, *size, &(type.first), *size); - if (err != 0) { - delete[] *metadata; - *metadata = nullptr; - BLOGE("memcpy_s failed! , retVal:%d", err); - return OHOS::SURFACE_ERROR_UNKOWN; - } - return OHOS::SURFACE_ERROR_OK; + auto it = std::find_if(NATIVE_METADATATYPE_TO_HDI_MAP.begin(), NATIVE_METADATATYPE_TO_HDI_MAP.end(), + [hdrMetadataType](const std::pair& element) { + return element.second == hdrMetadataType; + }); + if (it != NATIVE_METADATATYPE_TO_HDI_MAP.end()) { + *size = sizeof(OH_NativeBuffer_MetadataType); + *metadata = new uint8_t[*size]; + errno_t err = memcpy_s(*metadata, *size, &(it->first), *size); + if (err != 0) { + delete[] *metadata; + *metadata = nullptr; + BLOGE("memcpy_s failed!, ret: %d", err); + return OHOS::SURFACE_ERROR_UNKOWN; } + return OHOS::SURFACE_ERROR_OK; } BLOGE("the hdrMetadataType does not support it."); return OHOS::SURFACE_ERROR_NOT_SUPPORT; diff --git a/surface/src/native_window.cpp b/surface/src/native_window.cpp index c320f8d78e53f52e68514bcd6575c681ac5d5a5d..92ba4076d671b02757bbbab8b603e5ca40e2b31b 100644 --- a/surface/src/native_window.cpp +++ b/surface/src/native_window.cpp @@ -778,16 +778,11 @@ int32_t OH_NativeWindow_SetColorSpace(OHNativeWindow *window, OH_NativeBuffer_Co if (window == nullptr || NATIVE_COLORSPACE_TO_HDI_MAP.find(colorSpace) == NATIVE_COLORSPACE_TO_HDI_MAP.end()) { return OHOS::SURFACE_ERROR_INVALID_PARAM; } - OHNativeWindowBuffer *lastFlushedBuffer; - int lastFlushFenceFd; - float matrix[16] = {0}; - int32_t status = GetLastFlushedBuffer(window, &lastFlushedBuffer, &lastFlushFenceFd, matrix); - if (status != OHOS::SURFACE_ERROR_OK) { - BLOGE("GetLastFlushedBuffer fail"); - return status; + std::string param = std::to_string(NATIVE_COLORSPACE_TO_HDI_MAP[colorSpace]); + GSError ret = GSERROR_OK; + if (window->surface != nullptr && param != window->surface->GetUserData("ATTRKEY_COLORSPACE_INFO")) { + ret = window->surface->SetUserData("ATTRKEY_COLORSPACE_INFO", param); } - GSError ret = MetadataHelper::SetColorSpaceType(lastFlushedBuffer->sfbuffer, - NATIVE_COLORSPACE_TO_HDI_MAP[colorSpace]); if (ret != OHOS::SURFACE_ERROR_OK) { BLOGE("SetColorSpaceType failed!, retVal:%d", ret); return OHOS::SURFACE_ERROR_UNKOWN; @@ -800,25 +795,20 @@ int32_t OH_NativeWindow_GetColorSpace(OHNativeWindow *window, OH_NativeBuffer_Co if (window == nullptr || colorSpace == nullptr) { return OHOS::SURFACE_ERROR_INVALID_PARAM; } - OHOS::HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType colorSpaceType; - OHNativeWindowBuffer *lastFlushedBuffer; - int lastFlushFenceFd; - float matrix[16] = {0}; - int32_t status = GetLastFlushedBuffer(window, &lastFlushedBuffer, &lastFlushFenceFd, matrix); - if (status != OHOS::SURFACE_ERROR_OK) { - BLOGE("GetLastFlushedBuffer fail"); - return status; - } - GSError ret = MetadataHelper::GetColorSpaceType(lastFlushedBuffer->sfbuffer, colorSpaceType); - if (GSErrorStr(ret) == "<500 api call failed>with low error ") { - return OHOS::SURFACE_ERROR_NOT_SUPPORT; - } else if (ret != OHOS::SURFACE_ERROR_OK) { - BLOGE("GetColorSpaceType failed!, retVal:%d", ret); - return OHOS::SURFACE_ERROR_UNKOWN; - } - for (auto type : NATIVE_COLORSPACE_TO_HDI_MAP) { - if (type.second == colorSpaceType) { - *colorSpace = type.first; + CM_ColorSpaceType colorSpaceType = CM_COLORSPACE_NONE; + if (window->surface != nullptr) { + std::string value = window->surface->GetUserData("ATTRKEY_COLORSPACE_INFO"); + if (value.empty()) { + BLOGE("no colorspace!"); + return OHOS::SURFACE_ERROR_UNKOWN; + } + colorSpaceType = static_cast(atoi(value.c_str())); + auto it = std::find_if(NATIVE_COLORSPACE_TO_HDI_MAP.begin(), NATIVE_COLORSPACE_TO_HDI_MAP.end(), + [colorSpaceType](const std::pair& element) { + return element.second == colorSpaceType; + }); + if (it != NATIVE_COLORSPACE_TO_HDI_MAP.end()) { + *colorSpace = it->first; return OHOS::SURFACE_ERROR_OK; } } @@ -829,27 +819,29 @@ int32_t OH_NativeWindow_GetColorSpace(OHNativeWindow *window, OH_NativeBuffer_Co int32_t OH_NativeWindow_SetMetadataValue(OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey, int32_t size, uint8_t *metadata) { - if (window == nullptr || metadata == nullptr || size <= 0 || size > META_DATA_MAX_SIZE) { + if (window == nullptr || metadata == nullptr || size <= 0 || size > META_DATA_MAX_SIZE || + window->surface == nullptr) { return OHOS::SURFACE_ERROR_INVALID_PARAM; } - OHNativeWindowBuffer *lastFlushedBuffer; - int lastFlushFenceFd; - float matrix[16] = {0}; - int32_t status = GetLastFlushedBuffer(window, &lastFlushedBuffer, &lastFlushFenceFd, matrix); - if (status != OHOS::SURFACE_ERROR_OK) { - BLOGE("GetLastFlushedBuffer fail"); - return status; - } GSError ret = GSERROR_OK; std::vector mD(metadata, metadata + size); + std::string param; if (metadataKey == OH_HDR_DYNAMIC_METADATA) { - ret = MetadataHelper::SetHDRDynamicMetadata(lastFlushedBuffer->sfbuffer, mD); + param.assign(mD.begin(), mD.end()); + if (param != window->surface->GetUserData("OH_HDR_DYNAMIC_METADATA")) { + ret = window->surface->SetUserData("OH_HDR_DYNAMIC_METADATA", param); + } } else if (metadataKey == OH_HDR_STATIC_METADATA) { - ret = MetadataHelper::SetHDRStaticMetadata(lastFlushedBuffer->sfbuffer, mD); + param.assign(mD.begin(), mD.end()); + if (param != window->surface->GetUserData("OH_HDR_STATIC_METADATA")) { + ret = window->surface->SetUserData("OH_HDR_STATIC_METADATA", param); + } } else if (metadataKey == OH_HDR_METADATA_TYPE) { OH_NativeBuffer_MetadataType hdrMetadataType = static_cast(*metadata); - ret = MetadataHelper::SetHDRMetadataType(lastFlushedBuffer->sfbuffer, - NATIVE_METADATATYPE_TO_HDI_MAP[hdrMetadataType]); + param = std::to_string(NATIVE_METADATATYPE_TO_HDI_MAP[hdrMetadataType]); + if (param != window->surface->GetUserData("OH_HDR_METADATA_TYPE")) { + ret = window->surface->SetUserData("OH_HDR_METADATA_TYPE", param); + } } else { BLOGE("the metadataKey does not support it."); return OHOS::SURFACE_ERROR_NOT_SUPPORT; @@ -863,28 +855,26 @@ int32_t OH_NativeWindow_SetMetadataValue(OHNativeWindow *window, OH_NativeBuffer return OHOS::SURFACE_ERROR_OK; } -GSError OH_NativeWindow_GetMatedataValueType(sptr sfbuffer, int32_t *size, uint8_t **metadata) +static GSError OH_NativeWindow_GetMatedataValueType(OHNativeWindow *window, int32_t *size, uint8_t **metadata) { + std::string value = window->surface->GetUserData("OH_HDR_METADATA_TYPE"); CM_HDR_Metadata_Type hdrMetadataType = CM_METADATA_NONE; - GSError ret = MetadataHelper::GetHDRMetadataType(sfbuffer, hdrMetadataType); - if (GSErrorStr(ret) == "<500 api call failed>with low error ") { - return OHOS::SURFACE_ERROR_NOT_SUPPORT; - } else if (ret != OHOS::SURFACE_ERROR_OK) { - BLOGE("GetHDRMetadataType failed!, retVal:%d", ret); - return OHOS::SURFACE_ERROR_UNKOWN; - } - for (auto type : NATIVE_METADATATYPE_TO_HDI_MAP) { - if (type.second == hdrMetadataType) { - *size = sizeof(OH_NativeBuffer_MetadataType); - *metadata = new uint8_t[*size]; - errno_t err = memcpy_s(*metadata, *size, &(type.first), *size); - if (err != 0) { - delete[] *metadata; - BLOGE("memcpy_s failed! , retVal:%d", err); - return OHOS::SURFACE_ERROR_UNKOWN; - } - return OHOS::SURFACE_ERROR_OK; + hdrMetadataType = static_cast(atoi(value.c_str())); + auto it = std::find_if(NATIVE_METADATATYPE_TO_HDI_MAP.begin(), NATIVE_METADATATYPE_TO_HDI_MAP.end(), + [hdrMetadataType](const std::pair& element) { + return element.second == hdrMetadataType; + }); + if (it != NATIVE_METADATATYPE_TO_HDI_MAP.end()) { + *size = sizeof(OH_NativeBuffer_MetadataType); + *metadata = new uint8_t[*size]; + errno_t err = memcpy_s(*metadata, *size, &(it->first), *size); + if (err != 0) { + delete[] *metadata; + *metadata = nullptr; + BLOGE("memcpy_s failed! , ret: %d", err); + return OHOS::SURFACE_ERROR_UNKOWN; } + return OHOS::SURFACE_ERROR_OK; } BLOGE("the hdrMetadataType does not support it."); return OHOS::SURFACE_ERROR_NOT_SUPPORT; @@ -893,25 +883,21 @@ GSError OH_NativeWindow_GetMatedataValueType(sptr sfbuffer, int32 int32_t OH_NativeWindow_GetMetadataValue(OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey, int32_t *size, uint8_t **metadata) { - if (window == nullptr || metadata == nullptr || size == nullptr) { + if (window == nullptr || metadata == nullptr || size == nullptr || window->surface == nullptr) { return OHOS::SURFACE_ERROR_INVALID_PARAM; } - OHNativeWindowBuffer *lastFlushedBuffer; - int lastFlushFenceFd; - float matrix[16] = {0}; - int32_t status = GetLastFlushedBuffer(window, &lastFlushedBuffer, &lastFlushFenceFd, matrix); - if (status != OHOS::SURFACE_ERROR_OK) { - BLOGE("GetLastFlushedBuffer fail"); - return status; - } GSError ret = GSERROR_OK; std::vector mD; if (metadataKey == OH_HDR_DYNAMIC_METADATA) { - ret = MetadataHelper::GetHDRDynamicMetadata(lastFlushedBuffer->sfbuffer, mD); + std::string value = window->surface->GetUserData("OH_HDR_DYNAMIC_METADATA"); + mD.resize(value.size()); + mD.assign(value.begin(), value.end()); } else if (metadataKey == OH_HDR_STATIC_METADATA) { - ret = MetadataHelper::GetHDRStaticMetadata(lastFlushedBuffer->sfbuffer, mD); + std::string value = window->surface->GetUserData("OH_HDR_STATIC_METADATA"); + mD.resize(value.size()); + mD.assign(value.begin(), value.end()); } else if (metadataKey == OH_HDR_METADATA_TYPE) { - ret = OH_NativeWindow_GetMatedataValueType(lastFlushedBuffer->sfbuffer, size, metadata); + ret = OH_NativeWindow_GetMatedataValueType(window, size, metadata); return ret; } else { BLOGE("the metadataKey does not support it."); @@ -929,11 +915,13 @@ int32_t OH_NativeWindow_GetMetadataValue(OHNativeWindow *window, OH_NativeBuffer errno_t err = memcpy_s(*metadata, mD.size(), &mD[0], mD.size()); if (err != 0) { delete[] *metadata; + *metadata = nullptr; BLOGE("memcpy_s failed! , retVal:%d", err); return OHOS::SURFACE_ERROR_UNKOWN; } } else { delete[] *metadata; + *metadata = nullptr; BLOGE("new metadata failed! "); return OHOS::SURFACE_ERROR_UNKOWN; } diff --git a/surface/src/producer_surface.cpp b/surface/src/producer_surface.cpp index 97ddb95dc331bb7ff5d7578b0c1599465ead42d8..f159904a3337943b48f5b271aecfabfd83e6a9db 100644 --- a/surface/src/producer_surface.cpp +++ b/surface/src/producer_surface.cpp @@ -23,7 +23,9 @@ #include "sync_fence.h" #include "native_window.h" #include "surface_utils.h" +#include "metadata_helper.h" +using namespace OHOS::HDI::Display::Graphic::Common::V1_0; namespace OHOS { sptr Surface::CreateSurfaceAsProducer(sptr& producer) @@ -119,7 +121,53 @@ GSError ProducerSurface::RequestBuffer(sptr& buffer, } buffer = retval.buffer; fence = retval.fence; - return GSERROR_OK; + ret = SetMetadataValve(buffer); + if (ret != GSERROR_OK) { + BLOGD("SetMetadataValve ret: %{public}d, uniqueId: %{public}" PRIu64 ".", ret, queueId_); + } + return ret; +} + +GSError ProducerSurface::SetMetadataValve(sptr& buffer) +{ + GSError ret = GSERROR_OK; + std::vector metaData; + std::string value = GetUserData("ATTRKEY_COLORSPACE_INFO"); + if (!value.empty()) { + ret = MetadataHelper::SetColorSpaceType(buffer, static_cast(atoi(value.c_str()))); + if (ret != GSERROR_OK) { + BLOGD("SetColorSpaceType ret: %{public}d, uniqueId: %{public}" PRIu64 ".", ret, queueId_); + return ret; + } + } + value = GetUserData("OH_HDR_DYNAMIC_METADATA"); + if (!value.empty()) { + metaData.resize(value.size()); + metaData.assign(value.begin(), value.end()); + ret = MetadataHelper::SetHDRStaticMetadata(buffer, metaData); + if (ret != GSERROR_OK) { + BLOGD("SetHDRStaticMetadata ret: %{public}d, uniqueId: %{public}" PRIu64 ".", ret, queueId_); + return ret; + } + } + value = GetUserData("OH_HDR_STATIC_METADATA"); + if (!value.empty()) { + metaData.resize(value.size()); + metaData.assign(value.begin(), value.end()); + ret = MetadataHelper::SetHDRStaticMetadata(buffer, metaData); + if (ret != GSERROR_OK) { + BLOGD("SetHDRStaticMetadata ret: %{public}d, uniqueId: %{public}" PRIu64 ".", ret, queueId_); + return ret; + } + } + value = GetUserData("OH_HDR_METADATA_TYPE"); + if (!value.empty()) { + ret = MetadataHelper::SetHDRMetadataType(buffer, static_cast(atoi(value.c_str()))); + if (ret != GSERROR_OK) { + BLOGD("SetHDRMetadataType ret: %{public}d, uniqueId: %{public}" PRIu64 ".", ret, queueId_); + } + } + return ret; } GSError ProducerSurface::AddCacheLocked(sptr& bedataimpl, @@ -620,7 +668,7 @@ GSError ProducerSurface::RegisterUserDataChangeListener(const std::string& funcN BLOGND("func already register"); return GSERROR_INVALID_ARGUMENTS; } - + onUserDataChange_[funcName] = func; return GSERROR_OK; } diff --git a/surface/test/unittest/native_window_test.cpp b/surface/test/unittest/native_window_test.cpp index 2dec302d4f2ae9e1cf19ba9d9abf7c1039f99653..c8693da25069d3bfd512502e1f9b1d97961dacc1 100644 --- a/surface/test/unittest/native_window_test.cpp +++ b/surface/test/unittest/native_window_test.cpp @@ -1149,7 +1149,8 @@ HWTEST_F(NativeWindowTest, OH_NativeWindow_SetColorSpace001, Function | MediumTe */ HWTEST_F(NativeWindowTest, OH_NativeWindow_SetColorSpace002, Function | MediumTest | Level2) { - auto ret = OH_NativeWindow_SetColorSpace(nativeWindow, OH_COLORSPACE_BT709_LIMIT); + OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_BT709_LIMIT; + auto ret = OH_NativeWindow_SetColorSpace(nativeWindow, colorSpace); if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace ASSERT_EQ(ret, GSERROR_OK); } @@ -1168,7 +1169,7 @@ HWTEST_F(NativeWindowTest, OH_NativeWindow_GetColorSpace001, Function | MediumTe OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_NONE; auto ret = OH_NativeWindow_GetColorSpace(nativeWindow, &colorSpace); if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace - ASSERT_EQ(ret, GSERROR_INTERNAL); + ASSERT_EQ(ret, GSERROR_OK); } } @@ -1183,14 +1184,15 @@ HWTEST_F(NativeWindowTest, OH_NativeWindow_GetColorSpace001, Function | MediumTe HWTEST_F(NativeWindowTest, OH_NativeWindow_GetColorSpace002, Function | MediumTest | Level2) { OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_NONE; - auto ret = OH_NativeWindow_SetColorSpace(nativeWindow, OH_COLORSPACE_BT709_LIMIT); + OH_NativeBuffer_ColorSpace colorSpaceSet = OH_COLORSPACE_BT709_FULL; + auto ret = OH_NativeWindow_SetColorSpace(nativeWindow, colorSpaceSet); if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace ASSERT_EQ(ret, GSERROR_OK); } ret = OH_NativeWindow_GetColorSpace(nativeWindow, &colorSpace); if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace ASSERT_EQ(ret, GSERROR_OK); - ASSERT_EQ(colorSpace, OH_COLORSPACE_BT709_LIMIT); + ASSERT_EQ(colorSpace, colorSpaceSet); } } @@ -1266,6 +1268,91 @@ HWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue003, Function | Mediu if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace ASSERT_EQ(ret, GSERROR_OK); } + OH_NativeBuffer_MetadataType type = OH_VIDEO_HDR_HLG; + ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type), + reinterpret_cast(&type)); + if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace + ASSERT_EQ(ret, GSERROR_OK); + } +} + +/* +* Function: OH_NativeWindow_SetMetadataValue +* Type: Function +* Rank: Important(2) +* EnvConditions: N/A +* CaseDescription: 1. call OH_NativeWindow_SetMetadataValue +* 2. check ret + */ +HWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue004, Function | MediumTest | Level2) +{ + int len = 60; + uint8_t buff[len]; + for (int i = 0; i < 60; ++i) { + buff[i] = static_cast(i); + } + auto ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff); + if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace + ASSERT_EQ(ret, GSERROR_OK); + } + ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff); + if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace + ASSERT_EQ(ret, GSERROR_OK); + } + ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff); + if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace + ASSERT_EQ(ret, GSERROR_OK); + } + ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff); + if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace + ASSERT_EQ(ret, GSERROR_OK); + } + OH_NativeBuffer_MetadataType type = OH_VIDEO_HDR_HLG; + ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type), + reinterpret_cast(&type)); + if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace + ASSERT_EQ(ret, GSERROR_OK); + } + ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type), + reinterpret_cast(&type)); + if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace + ASSERT_EQ(ret, GSERROR_OK); + } +} + +/* +* Function: OH_NativeWindow_SetMetadataValue +* Type: Function +* Rank: Important(2) +* EnvConditions: N/A +* CaseDescription: 1. call OH_NativeWindow_SetMetadataValue +* 2. check ret + */ +HWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue005, Function | MediumTest | Level2) +{ + int len = 60; + uint8_t buff[len]; + for (int i = 0; i < 60; ++i) { + buff[i] = static_cast(i); + } + NativeWindowBuffer *nativeWindowbuffer1 = nullptr; + int fenceFd = -1; + int32_t err = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowbuffer1, &fenceFd); + ASSERT_EQ(err, GSERROR_OK); + auto ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff); + if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace + ASSERT_EQ(ret, GSERROR_OK); + } + ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff); + if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace + ASSERT_EQ(ret, GSERROR_OK); + } + OH_NativeBuffer_MetadataType type = OH_VIDEO_HDR_HLG; + ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type), + reinterpret_cast(&type)); + if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace + ASSERT_EQ(ret, GSERROR_OK); + } } /* @@ -1316,7 +1403,7 @@ HWTEST_F(NativeWindowTest, OH_NativeWindow_GetMetadataValue003, Function | Mediu int len = 60; uint8_t buff[len]; for (int i = 0; i < 60; ++i) { - buff[i] = static_cast(i); + buff[i] = static_cast(60 - i); } int32_t buffSize; uint8_t *checkMetaData; @@ -1330,6 +1417,9 @@ HWTEST_F(NativeWindowTest, OH_NativeWindow_GetMetadataValue003, Function | Mediu delete[] checkMetaData; ASSERT_EQ(ret, GSERROR_OK); } + for (int i = 0; i < 60; i++) { + buff[i] = static_cast(70 - i); + } ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff); if (ret != GSERROR_NOT_SUPPORT) { // some device not support set metadataValue ASSERT_EQ(ret, GSERROR_OK); @@ -1340,6 +1430,19 @@ HWTEST_F(NativeWindowTest, OH_NativeWindow_GetMetadataValue003, Function | Mediu delete[] checkMetaData; ASSERT_EQ(ret, GSERROR_OK); } + OH_NativeBuffer_MetadataType type = OH_VIDEO_HDR_HDR10; + int32_t typeSize = sizeof(type); + uint8_t pa = static_cast(type); + ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type), &pa); + if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace + ASSERT_EQ(ret, GSERROR_OK); + } + ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, &typeSize, &checkMetaData); + if (ret != GSERROR_NOT_SUPPORT) { // some device not support set metadataValue + ASSERT_EQ(static_cast(type), checkMetaData[0]); + delete[] checkMetaData; + ASSERT_EQ(ret, GSERROR_OK); + } } /* * Function: OH_NativeWindow_NativeWindowAbortBuffer