From c83e49b6a12da5830e2a4365ce6d5de916de820f Mon Sep 17 00:00:00 2001 From: "@ran-zhao-yu" Date: Fri, 17 May 2024 21:06:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9ECAPI=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: @ran-zhao-yu --- global/resource_management/BUILD.gn | 21 +- .../include/{ => rawfile}/raw_dir.h | 0 .../include/{ => rawfile}/raw_file.h | 0 .../include/{ => rawfile}/raw_file_manager.h | 0 .../include/resourcemanager/ohresmgr.h | 185 ++++++++++++++++++ .../include/resourcemanager/resmgr_common.h | 99 ++++++++++ .../libnative_resmgr.ndk.json | 26 +++ 7 files changed, 328 insertions(+), 3 deletions(-) rename global/resource_management/include/{ => rawfile}/raw_dir.h (100%) rename global/resource_management/include/{ => rawfile}/raw_file.h (100%) rename global/resource_management/include/{ => rawfile}/raw_file_manager.h (100%) create mode 100644 global/resource_management/include/resourcemanager/ohresmgr.h create mode 100644 global/resource_management/include/resourcemanager/resmgr_common.h create mode 100644 global/resource_management/libnative_resmgr.ndk.json diff --git a/global/resource_management/BUILD.gn b/global/resource_management/BUILD.gn index d5c9057ab..da91ccf2c 100644 --- a/global/resource_management/BUILD.gn +++ b/global/resource_management/BUILD.gn @@ -22,8 +22,23 @@ ohos_ndk_library("librawfile_ndk") { ohos_ndk_headers("rawfile_header") { dest_dir = "$ndk_headers_out_dir/rawfile" sources = [ - "./include/raw_dir.h", - "./include/raw_file.h", - "./include/raw_file_manager.h", + "./include/rawfile/raw_dir.h", + "./include/rawfile/raw_file.h", + "./include/rawfile/raw_file_manager.h", + ] +} + +ohos_ndk_library("native_resmgr_ndk") { + ndk_description_file = "./libnative_resmgr.ndk.json" + min_compact_version = "1" + output_name = "ohresmgr" + output_extension = "so" +} + +ohos_ndk_headers("native_resmgr_header") { + dest_dir = "$ndk_headers_out_dir/resourcemanager" + sources = [ + "./include/resourcemanager/ohresmgr.h", + "./include/resourcemanager/resmgr_common.h", ] } diff --git a/global/resource_management/include/raw_dir.h b/global/resource_management/include/rawfile/raw_dir.h similarity index 100% rename from global/resource_management/include/raw_dir.h rename to global/resource_management/include/rawfile/raw_dir.h diff --git a/global/resource_management/include/raw_file.h b/global/resource_management/include/rawfile/raw_file.h similarity index 100% rename from global/resource_management/include/raw_file.h rename to global/resource_management/include/rawfile/raw_file.h diff --git a/global/resource_management/include/raw_file_manager.h b/global/resource_management/include/rawfile/raw_file_manager.h similarity index 100% rename from global/resource_management/include/raw_file_manager.h rename to global/resource_management/include/rawfile/raw_file_manager.h diff --git a/global/resource_management/include/resourcemanager/ohresmgr.h b/global/resource_management/include/resourcemanager/ohresmgr.h new file mode 100644 index 000000000..5b0716373 --- /dev/null +++ b/global/resource_management/include/resourcemanager/ohresmgr.h @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup resourcemanager + * @{ + * + * @brief Provides the c interface to obtain resources, and relies on librawfile.z.so when used. + * + * @since 12 + */ + +/** + * @file ohresmgr.h + * + * @brief Provides the implementation of the interface. + * @syscap SystemCapability.Global.ResourceManager + * @library libohresmgr.so + * @since 12 + */ +#ifndef GLOBAL_OH_RESMGR_H +#define GLOBAL_OH_RESMGR_H + +#include "resmgr_common.h" +#include "../rawfile/raw_file_manager.h" +#include "../arkui/drawable_descriptor.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Obtains the Base64 code of the image resource. + * + * Obtains the Base64 code of the image resource corresponding to the specified resource ID. + * + * @param mgr Indicates the pointer to {@link NativeResourceManager} + * {@link OH_ResourceManager_InitNativeResourceManager}. + * @param resId Indicates the resource ID. + * @param density The optional parameter ScreenDensity{@link ScreenDensity}, A value of 0 means + * to use the density of current system dpi. + * @param resultValue the result write to resultValue. + * @param resultLen the media length write to resultLen. + * @return {@link SUCCESS} 0 - Success. + * {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - If the input parameter invalid. Possible causes: + * 1.Incorrect parameter types; 2.Parameter verification failed. + {@link ERROR_CODE_RES_ID_NOT_FOUND} 9001001 - Invalid resource ID. + {@link ERROR_CODE_RES_NOT_FOUND_BY_ID} 9001002 - No matching resource is found based on the resource ID. + {@link ERROR_CODE_OUT_OF_MEMORY} 9001100 - Out of memory. + * @since 12 + */ +ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64(const NativeResourceManager *mgr, uint32_t resId, + char **resultValue, uint64_t *resultLen, uint32_t density = 0); + +/** + * @brief Obtains the Base64 code of the image resource. + * + * Obtains the Base64 code of the image resource corresponding to the specified resource name. + * + * @param mgr Indicates the pointer to {@link NativeResourceManager} + * {@link OH_ResourceManager_InitNativeResourceManager}. + * @param resName Indicates the resource name. + * @param density The optional parameter ScreenDensity{@link ScreenDensity}, A value of 0 means + * to use the density of current system dpi. + * @param resultValue the result write to resultValue. + * @param resultLen the media length write to resultLen. + * @return {@link SUCCESS} 0 - Success. + * {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - If the input parameter invalid. Possible causes: + * 1.Incorrect parameter types; 2.Parameter verification failed. + {@link ERROR_CODE_RES_NAME_NOT_FOUND} 9001003 - Invalid resource name. + {@link ERROR_CODE_RES_NOT_FOUND_BY_NAME} 9001004 - No matching resource is found based on the resource name. + {@link ERROR_CODE_OUT_OF_MEMORY} 9001100 - Out of memory. + * @since 12 + */ +ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64ByName(const NativeResourceManager *mgr, + const char *resName, char **resultValue, uint64_t *resultLen, uint32_t density = 0); + +/** + * @brief Obtains the content of the image resource. + * + * Obtains the content of the specified screen density media file corresponding to a specified resource ID. + * + * @param mgr Indicates the pointer to {@link NativeResourceManager} + * {@link OH_ResourceManager_InitNativeResourceManager}. + * @param resId Indicates the resource ID. + * @param density The optional parameter ScreenDensity{@link ScreenDensity}, A value of 0 means + * to use the density of current system dpi. + * @param resultValue the result write to resultValue. + * @param resultLen the media length write to resultLen. + * @return {@link SUCCESS} 0 - Success. + * {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - If the input parameter invalid. Possible causes: + * 1.Incorrect parameter types; 2.Parameter verification failed. + {@link ERROR_CODE_RES_ID_NOT_FOUND} 9001001 - Invalid resource ID. + {@link ERROR_CODE_RES_NOT_FOUND_BY_ID} 9001002 - No matching resource is found based on the resource ID. + {@link ERROR_CODE_OUT_OF_MEMORY} 9001100 - Out of memory. + * @since 12 + */ +ResourceManager_ErrorCode OH_ResourceManager_GetMedia(const NativeResourceManager *mgr, uint32_t resId, + uint8_t **resultValue, uint64_t *resultLen, uint32_t density = 0); + +/** + * @brief Obtains the content of the image resource. + * + * Obtains the content of the specified screen density media file corresponding to a specified resource name. + * + * @param mgr Indicates the pointer to {@link NativeResourceManager} + * {@link OH_ResourceManager_InitNativeResourceManager}. + * @param resName Indicates the resource name. + * @param density The optional parameter ScreenDensity{@link ScreenDensity}, A value of 0 means + * to use the density of current system dpi. + * @param resultValue the result write to resultValue. + * @param resultLen the media length write to resultLen. + * @return {@link SUCCESS} 0 - Success. + * {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - If the input parameter invalid. Possible causes: + * 1.Incorrect parameter types; 2.Parameter verification failed. + {@link ERROR_CODE_RES_NAME_NOT_FOUND} 9001003 - Invalid resource name. + {@link ERROR_CODE_RES_NOT_FOUND_BY_NAME} 9001004 - No matching resource is found based on the resource name. + {@link ERROR_CODE_OUT_OF_MEMORY} 9001100 - Out of memory. + * @since 12 + */ +ResourceManager_ErrorCode OH_ResourceManager_GetMediaByName(const NativeResourceManager *mgr, const char *resName, + uint8_t **resultValue, uint64_t *resultLen, uint32_t density = 0); + +/** + * @brief Obtains the DrawableDescriptor of the media file. + * + * Obtains the DrawableDescriptor of the media file corresponding to a specified resource ID. + * + * @param mgr Indicates the pointer to {@link NativeResourceManager} + * {@link OH_ResourceManager_InitNativeResourceManager}. + * @param resId Indicates the resource ID. + * @param density The optional parameter ScreenDensity{@link ScreenDensity}, A value of 0 means + * to use the density of current system dpi. + * @param type The optional parameter means the media type, 0 means the normal media, 1 means the the theme style media. + * @param drawableDescriptor the result write to drawableDescriptor. + * @return {@link SUCCESS} 0 - Success. + * {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - If the input parameter invalid. Possible causes: + * 1.Incorrect parameter types; 2.Parameter verification failed. + {@link ERROR_CODE_RES_ID_NOT_FOUND} 9001001 - Invalid resource ID. + {@link ERROR_CODE_RES_NOT_FOUND_BY_ID} 9001002 - No matching resource is found based on the resource ID. + * @since 12 + */ +ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptor(const NativeResourceManager *mgr, + uint32_t resId, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density = 0, uint32_t type = 0); + +/** + * @brief Obtains the DrawableDescriptor of the media file. + * + * Obtains the DrawableDescriptor of the media file corresponding to a specified resource name. + * @param mgr Indicates the pointer to {@link NativeResourceManager} + * {@link OH_ResourceManager_InitNativeResourceManager}. + * @param resName Indicates the resource name. + * @param density The optional parameter ScreenDensity{@link ScreenDensity}, A value of 0 means + * to use the density of current system dpi. + * @param type The optional parameter means the media type, 0 means the normal media, 1 means the the theme style media, + * 2 means the theme dynamic media. + * @param drawableDescriptor the result write to drawableDescriptor. + * @return {@link SUCCESS} 0 - Success. + * {@link ERROR_CODE_INVALID_INPUT_PARAMETER} 401 - If the input parameter invalid. Possible causes: + * 1.Incorrect parameter types; 2.Parameter verification failed. + {@link ERROR_CODE_RES_NAME_NOT_FOUND} 9001003 - Invalid resource name. + {@link ERROR_CODE_RES_NOT_FOUND_BY_NAME} 9001004 - No matching resource is found based on the resource name. + * @since 12 + */ +ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptorByName(const NativeResourceManager *mgr, + const char *resName, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density = 0, uint32_t type = 0); + +#ifdef __cplusplus +}; +#endif + +/** @} */ +#endif // GLOBAL_OH_RESMGR_H \ No newline at end of file diff --git a/global/resource_management/include/resourcemanager/resmgr_common.h b/global/resource_management/include/resourcemanager/resmgr_common.h new file mode 100644 index 000000000..d6ef85885 --- /dev/null +++ b/global/resource_management/include/resourcemanager/resmgr_common.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup resourcemanager + * @{ + * + * @brief Provides the c interface to obtain resources, and relies on librawfile.z.so when used. + * + * @since 12 + */ + +/** + * @file resmgr_common.h + * + * @brief Provides the structure required by the interface. + * @syscap SystemCapability.Global.ResourceManager + * @library libohresmgr.so + * @since 12 + */ +#ifndef GLOBAL_RESMGR_COMMON_H +#define GLOBAL_RESMGR_COMMON_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The error code of resource manager. + * + * @since 12 + */ +enum ResourceManager_ErrorCode { + /** Success */ + SUCCESS = 0, + /** Invalid input parameter */ + ERROR_CODE_INVALID_INPUT_PARAMETER = 401, + /** Invalid resource ID */ + ERROR_CODE_RES_ID_NOT_FOUND = 9001001, + /** Invalid resource name */ + ERROR_CODE_RES_NOT_FOUND_BY_ID = 9001002, + /** No matching resource is found based on the resource ID */ + ERROR_CODE_RES_NAME_NOT_FOUND = 9001003, + /** No matching resource is found based on the resource name */ + ERROR_CODE_RES_NOT_FOUND_BY_NAME = 9001004, + /** Invalid relative path */ + ERROR_CODE_RES_PATH_INVALID = 9001005, + /** The resource is referenced cyclically */ + ERROR_CODE_RES_REF_TOO_MUCH = 9001006, + /** Failed to format the resource obtained based on the resource ID */ + ERROR_CODE_RES_ID_FORMAT_ERROR = 9001007, + /** Failed to format the resource obtained based on the resource Name */ + ERROR_CODE_RES_NAME_FORMAT_ERROR = 9001008, + /** Failed to access the system resource */ + ERROR_CODE_SYSTEM_RES_MANAGER_GET_FAILED = 9001009, + /** Invalid overlay path */ + ERROR_CODE_OVERLAY_RES_PATH_INVALID = 9001010, + /** Out of memory */ + ERROR_CODE_OUT_OF_MEMORY = 9001100, +}; + +/** + * @brief Enumerates screen density types. + * + * @since 12 + */ +enum ScreenDensity { + /** Indicates small screen density. */ + SCREEN_SDPI = 120, + /** Indicates medium screen density. */ + SCREEN_MDPI = 160, + /** Indicates large screen density. */ + SCREEN_LDPI = 240, + /** Indicates extra-large screen density. */ + SCREEN_XLDPI = 320, + /** Indicates extra-extra-large screen density. */ + SCREEN_XXLDPI = 480, + /** Indicates extra-extra-extra-large screen density. */ + SCREEN_XXXLDPI = 640, +}; + +#ifdef __cplusplus +}; +#endif + +/** @} */ +#endif // GLOBAL_RESMGR_COMMON_H diff --git a/global/resource_management/libnative_resmgr.ndk.json b/global/resource_management/libnative_resmgr.ndk.json new file mode 100644 index 000000000..3fbb2cf92 --- /dev/null +++ b/global/resource_management/libnative_resmgr.ndk.json @@ -0,0 +1,26 @@ +[ + { + "first_introduced": "12", + "name": "OH_ResourceManager_GetMediaBase64" + }, + { + "first_introduced": "12", + "name": "OH_ResourceManager_GetMediaBase64ByName" + }, + { + "first_introduced": "12", + "name": "OH_ResourceManager_GetMedia" + }, + { + "first_introduced": "12", + "name": "OH_ResourceManager_GetMediaByName" + }, + { + "first_introduced": "12", + "name": "OH_ResourceManager_GetDrawableDescriptor" + }, + { + "first_introduced": "12", + "name": "OH_ResourceManager_GetDrawableDescriptorByName" + } +] \ No newline at end of file -- Gitee