mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2025-02-17 02:20:59 +00:00
Separate and add color space convertor to color manager
Signed-off-by: shiyueeee <nieshiyue@huawei.com> Change-Id: I04dcbbd50fb3d589b39b62f3b8fa0e608f7e31ca
This commit is contained in:
parent
769a310f99
commit
8a2013d4f1
@ -13,10 +13,43 @@
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
config("color_space_object_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [
|
||||
"//foundation/graphic/graphic_2d/interfaces/kits/napi/graphic/color_manager/color_space_object_convertor",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager/export",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("color_space_object_convertor") {
|
||||
sources = [
|
||||
"color_space_object_convertor/color_space_object_convertor.cpp",
|
||||
"color_space_object_convertor/js_color_space.cpp",
|
||||
"color_space_object_convertor/js_color_space_utils.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":color_space_object_config" ]
|
||||
|
||||
deps = [ "//foundation/graphic/graphic_2d/utils:libgraphic_utils" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
cflags_cc = [ "-std=c++17" ]
|
||||
|
||||
part_name = "graphic_standard"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
|
||||
config("color_manager_napi_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [
|
||||
"//foundation/graphic/graphic_2d/interfaces/kits/napi/graphic/color_manager/color_space_object_convertor",
|
||||
"//foundation/graphic/graphic_2d/interfaces/kits/napi/graphic/color_manager/colorspacemanager_napi",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager/export",
|
||||
]
|
||||
@ -25,14 +58,15 @@ config("color_manager_napi_config") {
|
||||
ohos_shared_library("colorspacemanager_napi") {
|
||||
sources = [
|
||||
"colorspacemanager_napi/color_space_manager_module.cpp",
|
||||
"colorspacemanager_napi/js_color_space.cpp",
|
||||
"colorspacemanager_napi/js_color_space_manager.cpp",
|
||||
"colorspacemanager_napi/js_color_space_manager_utils.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":color_manager_napi_config" ]
|
||||
|
||||
deps = [ "//foundation/graphic/graphic_2d/utils:libgraphic_utils" ]
|
||||
deps = [
|
||||
"//foundation/graphic/graphic_2d/interfaces/kits/napi/graphic/color_manager:color_space_object_convertor",
|
||||
"//foundation/graphic/graphic_2d/utils/color_manager:color_manager",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:runtime",
|
||||
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
#include "color_space_object_convertor.h"
|
||||
|
||||
#include "js_color_space_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ColorManager {
|
||||
using namespace AbilityRuntime;
|
||||
|
||||
NativeValue* CreateJsColorSpaceObject(NativeEngine& engine, std::shared_ptr<ColorSpace>& colorSpace)
|
||||
{
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
std::unique_ptr<JsColorSpace> jsColorSpace = std::make_unique<JsColorSpace>(colorSpace);
|
||||
object->SetNativePointer(jsColorSpace.release(), JsColorSpace::Finalizer, nullptr);
|
||||
|
||||
BindFunctions(engine, object);
|
||||
|
||||
std::shared_ptr<NativeReference> jsColorSpaceRef;
|
||||
jsColorSpaceRef.reset(engine.CreateReference(objValue, 1));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
std::shared_ptr<ColorSpace> GetColorSpaceByJSObject(NativeObject* object)
|
||||
{
|
||||
{
|
||||
if (object == nullptr) {
|
||||
CMLOGE("[NAPI]GetColorSpaceByJSObject::jsObject is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
auto jsColorSpace = reinterpret_cast<JsColorSpace*>(object->GetNativePointer());
|
||||
if (jsColorSpace == nullptr) {
|
||||
CMLOGE("[NAPI]GetColorSpaceByJSObject::jsColorSpace is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return jsColorSpace->GetColorSpaceToken();
|
||||
}
|
||||
}
|
||||
} // namespace ColorManager
|
||||
} // namespace OHOS
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_COLOR_SPACE_OBJECT_CONVERTOR_H
|
||||
#define OHOS_COLOR_SPACE_OBJECT_CONVERTOR_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "color_space.h"
|
||||
#include "js_color_space.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "native_engine/native_value.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ColorManager {
|
||||
NativeValue* CreateJsColorSpaceObject(NativeEngine& engine, std::shared_ptr<ColorSpace>& colorSpace);
|
||||
std::shared_ptr<ColorSpace> GetColorSpaceByJSObject(NativeObject* object);
|
||||
} // namespace ColorManager
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_COLOR_SPACE_OBJECT_CONVERTOR_H
|
@ -17,41 +17,12 @@
|
||||
#include <array>
|
||||
|
||||
#include "color_space.h"
|
||||
#include "js_color_space_manager_utils.h"
|
||||
#include "js_color_space_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ColorManager {
|
||||
using namespace AbilityRuntime;
|
||||
|
||||
NativeValue* CreateJsColorSpaceObject(NativeEngine& engine, std::shared_ptr<ColorSpace>& colorSpace)
|
||||
{
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
std::unique_ptr<JsColorSpace> jsColorSpace = std::make_unique<JsColorSpace>(colorSpace);
|
||||
object->SetNativePointer(jsColorSpace.release(), JsColorSpace::Finalizer, nullptr);
|
||||
|
||||
BindFunctions(engine, object);
|
||||
|
||||
std::shared_ptr<NativeReference> jsColorSpaceRef;
|
||||
jsColorSpaceRef.reset(engine.CreateReference(objValue, 1));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
std::shared_ptr<ColorSpace> GetColorSpaceByJSObject(NativeObject* object)
|
||||
{
|
||||
if (object == nullptr) {
|
||||
CMLOGE("[NAPI]GetColorSpaceByJSObject::jsObject is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
auto jsColorSpace = reinterpret_cast<JsColorSpace*>(object->GetNativePointer());
|
||||
if (jsColorSpace == nullptr) {
|
||||
CMLOGE("[NAPI]GetColorSpaceByJSObject::jsColorSpace is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return jsColorSpace->GetColorSpaceToken();
|
||||
}
|
||||
|
||||
void JsColorSpace::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
auto jsColorSpace = std::unique_ptr<JsColorSpace>(static_cast<JsColorSpace*>(data));
|
@ -25,8 +25,6 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace ColorManager {
|
||||
NativeValue* CreateJsColorSpaceObject(NativeEngine& engine, std::shared_ptr<ColorSpace>& colorSpace);
|
||||
std::shared_ptr<ColorSpace> GetColorSpaceByJSObject(NativeObject* object);
|
||||
void BindFunctions(NativeEngine& engine, NativeObject* object);
|
||||
class JsColorSpace final {
|
||||
public:
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "js_color_space_manager_utils.h"
|
||||
#include "js_color_space_utils.h"
|
||||
|
||||
#include "js_runtime_utils.h"
|
||||
|
@ -29,7 +29,7 @@ namespace ColorManager {
|
||||
#define TITLE __func__
|
||||
#endif
|
||||
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, 0xD001400, "JsColorSpaceManager"};
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, 0xD001400, "JsColorSpace"};
|
||||
#define CMLOGE(fmt, args...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, "%{public}s: " fmt, TITLE, ##args)
|
||||
#define CMLOGI(fmt, args...) \
|
@ -17,8 +17,9 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "color_space_object_convertor.h"
|
||||
#include "js_color_space.h"
|
||||
#include "js_color_space_manager_utils.h"
|
||||
#include "js_color_space_utils.h"
|
||||
#include "js_runtime_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
|
@ -20,7 +20,10 @@ group("color_manager_unit_test") {
|
||||
}
|
||||
|
||||
group("color_manager") {
|
||||
public_deps = [ "color_manager:color_manager" ]
|
||||
public_deps = [
|
||||
"color_manager:color_manager",
|
||||
"//foundation/graphic/graphic_2d/interfaces/kits/napi/graphic/color_manager:color_space_object_convertor",
|
||||
]
|
||||
}
|
||||
|
||||
group("buffer_handle") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user