Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream_ohos/main' into feature/ohos_jsi
Browse files Browse the repository at this point in the history
  • Loading branch information
zealotchen0 committed Dec 3, 2024
2 parents fdefbb9 + f338196 commit c77de4b
Show file tree
Hide file tree
Showing 352 changed files with 9,805 additions and 29,689 deletions.
9 changes: 9 additions & 0 deletions devtools/devtools-integration/native/src/v8/trace_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ void TraceControl::StartTracing() {
auto trace_config = v8::platform::tracing::TraceConfig::CreateDefaultTraceConfig();
trace_config->SetTraceRecordMode(v8::platform::tracing::TraceRecordMode::RECORD_CONTINUOUSLY);
trace_config->AddIncludedCategory(kTraceIncludedCategoryV8);
trace_config->EnableSystrace();
trace_config->AddIncludedCategory("devtools.timeline");
trace_config->AddIncludedCategory("v8.execute");
trace_config->AddIncludedCategory("disabled-by-default-devtools.timeline");
trace_config->AddIncludedCategory("disabled-by-default-devtools.timeline.frame");
trace_config->AddIncludedCategory("disabled-by-default-devtools.timeline.stack");
trace_config->AddIncludedCategory("disabled-by-default-v8.cpu_profiler");
trace_config->AddIncludedCategory("disabled-by-default-v8.cpu_profiler.hires");
trace_config->AddIncludedCategory("latencyInfo");
v8_trace_control_->StartTracing(trace_config);
tracing_has_start_ = true;
}
Expand Down
30 changes: 8 additions & 22 deletions docs/development/native-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,37 +284,21 @@ ENV['layout_engine'] = 'Yoga'

## Demo 体验

若想快速体验,可以打开我们的 [Ohos Demo](https://github.com/sohotz/Hippy/tree/main/framework/examples/ohos-demo) 来体验
Ohos Har Demo:Har 包方式依赖 Hippy。 体验方法:DevEco 打开 hippy 项目根目录运行 entry_har。

2个 Demo 说明:

Ohos Demo:源码依赖 Hippy。体验方法:IDE 打开 hippy 项目根目录直接运行 entry。

Ohos Har Demo:Har 包方式依赖 Hippy。 体验方法:Hippy/framework/examples/ohos-har-demo/oh-package.json5 取消 dependencies 里注释的依赖内容,
Make Module 'hippy' 后把 hippy.har 放到lib目录,IDE 打开 hippy 项目根目录运行 entry_har。
Ohos Demo:源码依赖 Hippy。体验方法:DevEco 打开 hippy 项目根目录直接运行 entry。

## 接入方式一:Har包快速接入

1. Har 包构建
- 拉取 hippy 代码
> https://github.com/sohotz/Hippy.git,分支:main

- 构建 hippy.har:IDE 打开 hippy 工程根目录,IDE 菜单 - Build - Make Module 'hippy'
> Har 包生成目录:Hippy0129/framework/ohos/build/default/outputs/default/hippy.har

> 如果菜单不显示 “Make Module 'hippy'”,可先选择到 hippy 模块内,比如选择文件:Hippy/framework/ohos/src/main/cpp/CMakeLists.txt

2. 创建一个 Ohos 工程

3. Har 包集成
1. 创建一个 Ohos 工程

- 引入hippy.har(比如:libs目录下)
2. Har 包集成

- 配置 oh-package.json5

```json
"dependencies": {
"hippy": "file:./libs/hippy.har"
"hippy": "1.0.0"
}
```

Expand All @@ -328,6 +312,8 @@ Make Module 'hippy' 后把 hippy.har 放到lib目录,IDE 打开 hippy 项目
AppStorage.setOrCreate("abilityContext", this.context)
```

> 注:App 直接集成 Hippy,context 使用 UIAbility context;如果 App 在一个模块里集成 Hippy,js 等资源也集成在模块里,context 使用 getContext().createModuleContext("moduleName"),否则会找不到 js 等资源。

- 创建 HippyEngine、初始化 HippyEngine、加载业务 bundle

```TypeScript
Expand Down Expand Up @@ -356,7 +342,7 @@ Make Module 'hippy' 后把 hippy.har 放到lib目录,IDE 打开 hippy 项目

1. 创建一个 Ohos 工程

2. Har包集成
2. Hippy 代码集成

- 拉取 hippy 代码到项目里(比如:根目录下)
> https://github.com/sohotz/Hippy.git,分支:main
Expand Down
15 changes: 15 additions & 0 deletions dom/include/dom/root_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ class DomNodeStyleDiffer {
std::unordered_map<uint32_t, std::unordered_map<std::string, std::shared_ptr<HippyValue>>> node_ext_style_map_;
};

struct ListenerOp {
bool add;
std::weak_ptr<DomNode> dom_node;
std::string name;

ListenerOp(bool add, std::weak_ptr<DomNode> dom_node, const std::string& name) {
this->add = add;
this->dom_node = dom_node;
this->name = name;
}
};

class RootNode : public DomNode {
public:
using TaskRunner = footstone::runner::TaskRunner;
Expand All @@ -72,6 +84,8 @@ class RootNode : public DomNode {
virtual void AddEventListener(const std::string& name, uint64_t listener_id, bool use_capture,
const EventCallback& cb) override;
virtual void RemoveEventListener(const std::string& name, uint64_t listener_id) override;

std::map<uint32_t, std::vector<ListenerOp>> &EventListenerOps() { return event_listener_ops_; }

void ReleaseResources();
void CreateDomNodes(std::vector<std::shared_ptr<DomInfo>>&& nodes, bool needSortByIndex);
Expand Down Expand Up @@ -118,6 +132,7 @@ class RootNode : public DomNode {

std::vector<DomOperation> dom_operations_;
std::vector<EventOperation> event_operations_;
std::map<uint32_t, std::vector<ListenerOp>> event_listener_ops_;

void FlushDomOperations(const std::shared_ptr<RenderManager>& render_manager);
void FlushEventOperations(const std::shared_ptr<RenderManager>& render_manager);
Expand Down
10 changes: 7 additions & 3 deletions dom/src/dom/animation/animation_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,11 @@ void AnimationManager::UpdateCubicBezierAnimation(double current,
}
HippyValue prop_value(current);
dom_node->EmplaceStyleMapAndGetDiff(prop_it->second, prop_value, diff_value);
FOOTSTONE_DLOG(INFO) << "animation related_animation_id = " << related_animation_id
<< "node id = " << dom_node->GetId() << ", key = " << prop_it->second << ", value = " << prop_value;

if (footstone::gEnableUpdateAnimLog) {
FOOTSTONE_DLOG(INFO) << "animation related_animation_id = " << related_animation_id
<< "node id = " << dom_node->GetId() << ", key = " << prop_it->second << ", value = " << prop_value;
}

dom_node->SetDiffStyle(std::make_shared<
std::unordered_map<std::string, std::shared_ptr<HippyValue>>>(std::move(diff_value)));
update_node_map[dom_node_id] = dom_node;
Expand Down Expand Up @@ -393,6 +395,8 @@ void AnimationManager::UpdateAnimations() {
return;
}

footstone::AutoInUpdateAnimScope autoInUpdateAnimScope;

auto now = footstone::time::MonotonicallyIncreasingTime();
std::unordered_map<uint32_t, std::shared_ptr<DomNode>> update_node_map;
// xcode crash if we change for to loop
Expand Down
40 changes: 25 additions & 15 deletions dom/src/dom/animation/cubic_bezier_animation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,32 @@ CubicBezier CubicBezierAnimation::ParseCubicBezierStr(const std::string& str) {

double CubicBezierAnimation::CalculateColor(double start_color, double to_color, double scale) {
auto start_value = static_cast<uint32_t>(start_color);
auto start_red = static_cast<uint8_t>(((start_value >> 24) & 0xff));
auto start_green = static_cast<uint8_t>(((start_value >> 16) & 0xff));
auto start_blue = static_cast<uint8_t>(((start_value >> 8) & 0xff));
auto start_alpha = static_cast<uint8_t>((start_value & 0xff));

if (start_color < 0) {
auto start_int_value = static_cast<int32_t>(start_color);
start_value = static_cast<uint32_t>(start_int_value);
}

auto start_alpha = ((start_value >> 24) & 0xff);
auto start_red = ((start_value >> 16) & 0xff);
auto start_green = ((start_value >> 8) & 0xff);
auto start_blue = (start_value & 0xff);

auto to_value = static_cast<uint32_t>(to_color);
auto to_red = static_cast<uint8_t>(((to_value >> 24) & 0xff));
auto to_green = static_cast<uint8_t>(((to_value >> 16) & 0xff));
auto to_blue = static_cast<uint8_t>(((to_value >> 8) & 0xff));
auto to_alpha = static_cast<uint8_t>((to_value & 0xff));

auto red = static_cast<uint8_t>(start_red + (to_red - start_red) * scale);
auto green = static_cast<uint8_t>(start_green + (to_green - start_green) * scale);
auto blue = static_cast<uint8_t>(start_blue + (to_blue - start_blue) * scale);
auto alpha = static_cast<uint8_t>(start_alpha + (to_alpha - start_alpha) * scale);
auto ret = (static_cast<uint32_t>(red) << 24) + (static_cast<uint32_t>(green) << 16) + (static_cast<uint32_t>(blue) << 8) + alpha;
if (to_color < 0) {
auto to_int_value = static_cast<int32_t>(to_color);
to_value = static_cast<uint32_t>(to_int_value);
}

auto to_alpha = ((to_value >> 24) & 0xff);
auto to_red = ((to_value >> 16) & 0xff);
auto to_green = ((to_value >> 8) & 0xff);
auto to_blue = (to_value & 0xff);

auto red = static_cast<int32_t>(start_red + static_cast<int32_t>(to_red - start_red) * scale);
auto green = static_cast<int32_t>(start_green + static_cast<int32_t>(to_green - start_green) * scale);
auto blue = static_cast<int32_t>(start_blue + static_cast<int32_t>(to_blue - start_blue) * scale);
auto alpha = static_cast<int32_t>(start_alpha + static_cast<int32_t>(to_alpha - start_alpha) * scale);
auto ret = (static_cast<uint32_t>(alpha) << 24) + (static_cast<uint32_t>(red) << 16) + (static_cast<uint32_t>(green) << 8) + static_cast<uint32_t>(blue);
return static_cast<double>(ret);
}

Expand Down
4 changes: 3 additions & 1 deletion dom/src/dom/dom_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ void DomManager::EndBatch(const std::weak_ptr<RootNode>& weak_root_node) {
if (!root_node) {
return;
}
FOOTSTONE_DLOG(INFO) << "[Hippy Statistic] total node size = " << root_node->GetChildCount();
if (!footstone::gInUpdateAnimScope || footstone::gEnableUpdateAnimLog) {
FOOTSTONE_DLOG(INFO) << "[Hippy Statistic] total node size = " << root_node->GetChildCount();
}
root_node->SyncWithRenderManager(render_manager);
}

Expand Down
6 changes: 4 additions & 2 deletions dom/src/dom/layer_optimized_render_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ void LayerOptimizedRenderManager::UpdateRenderNode(std::weak_ptr<RootNode> root_
}
}
}
FOOTSTONE_DLOG(INFO) << "[Hippy Statistic] update node size before optimize = " << nodes.size()
<< ", update node size after optimize = " << nodes_to_update.size();
if (!footstone::gInUpdateAnimScope || footstone::gEnableUpdateAnimLog) {
FOOTSTONE_DLOG(INFO) << "[Hippy Statistic] update node size before optimize = " << nodes.size()
<< ", update node size after optimize = " << nodes_to_update.size();
}
if (!nodes_to_update.empty()) {
render_manager_->UpdateRenderNode(root_node, std::move(nodes_to_update));
}
Expand Down
8 changes: 7 additions & 1 deletion dom/src/dom/yoga_layout_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ static YGSize YGMeasureFunction(YGNodeRef node, float width, YGMeasureMode width
YGMeasureMode height_mode) {
auto yoga_node = reinterpret_cast<YogaLayoutNode*>(YGNodeGetContext(node));
int64_t key = yoga_node->GetKey();
std::lock_guard<std::mutex> lock(mutex);
auto iter = measure_function_map.find(key);
if (iter != measure_function_map.end()) {
auto size = iter->second(width, ToLayoutMeasureMode(width_mode), height, ToLayoutMeasureMode(height_mode), nullptr);
Expand All @@ -319,12 +320,17 @@ static YGSize YGMeasureFunction(YGNodeRef node, float width, YGMeasureMode width
}

void YogaLayoutNode::SetMeasureFunction(MeasureFunction measure_function) {
std::lock_guard<std::mutex> lock(mutex);
measure_function_map[key_] = measure_function;
YGNodeSetContext(yoga_node_, reinterpret_cast<void*>(this));
return YGNodeSetMeasureFunc(yoga_node_, YGMeasureFunction);
}

bool YogaLayoutNode::HasMeasureFunction() { return measure_function_map.find(key_) != measure_function_map.end(); }
bool YogaLayoutNode::HasMeasureFunction() {
std::lock_guard<std::mutex> lock(mutex);
return measure_function_map.find(key_) != measure_function_map.end();
}

float YogaLayoutNode::GetLeft() { return YGNodeLayoutGetLeft(yoga_node_); }

float YogaLayoutNode::GetTop() { return YGNodeLayoutGetTop(yoga_node_); }
Expand Down
18 changes: 14 additions & 4 deletions driver/js/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ set(CMAKE_CXX_STANDARD 17)
# 现在源码集成配置需在app的build-profile.json5里,不方便,所以先放在这里。
# 后续hippy产物的独立后,放到hippy模块的build-profile.json5里。
if (OHOS)
set(JS_ENGINE "V8")
# set(JS_ENGINE "V8")
set(V8_COMPONENT "10.6.194")
set(JS_ENGINE "JSH")
endif ()

# region library
Expand All @@ -52,9 +54,6 @@ endif()

# region vm
if ("${JS_ENGINE}" STREQUAL "V8")
if (OHOS)
add_subdirectory("${PROJECT_SOURCE_DIR}/v8_ohos" ./v8_ohos)
endif ()
if (NOT TARGET v8)
if (NOT V8_COMPONENT)
message(FATAL_ERROR "The V8_COMPONENT variable must be set")
Expand All @@ -71,6 +70,8 @@ if ("${JS_ENGINE}" STREQUAL "V8")
set(V8_REMOTE_FILENAME "windows-x64.zip")
endif()
endif()
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "OHOS")
set(V8_REMOTE_FILENAME "ohos-arm64.tgz")
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "arm")
set(V8_REMOTE_FILENAME "ios-arm64.tgz")
Expand Down Expand Up @@ -126,6 +127,8 @@ if ("${JS_ENGINE}" STREQUAL "V8")
endif ()
elseif ("${JS_ENGINE}" STREQUAL "JSC")
target_compile_definitions(${PROJECT_NAME} PUBLIC "JS_JSC")
elseif ("${JS_ENGINE}" STREQUAL "JSH")
target_compile_definitions(${PROJECT_NAME} PUBLIC "JS_JSH")
endif ()
# endregion

Expand Down Expand Up @@ -220,6 +223,13 @@ elseif ("${JS_ENGINE}" STREQUAL "JSC")
src/napi/jsc/jsc_try_catch.cc
src/vm/jsc/jsc_vm.cc
src/vm/jsc/native_source_code_ios.cc)
elseif ("${JS_ENGINE}" STREQUAL "JSH")
list(APPEND SOURCE_SET
src/napi/jsh/jsh_class_definition.cc
src/napi/jsh/jsh_ctx.cc
src/napi/jsh/jsh_try_catch.cc
src/vm/jsh/jsh_vm.cc
src/vm/jsh/native_source_code_ohos.cc)
endif ()
set(SOURCE_SET_STANDALONE
src/modules/console_module.cc
Expand Down
1 change: 1 addition & 0 deletions driver/js/include/driver/napi/js_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class Ctx {
virtual std::shared_ptr<ClassDefinition> GetClassDefinition(const string_view& name) = 0;
virtual void SetWeak(std::shared_ptr<CtxValue> value,
const std::unique_ptr<WeakCallbackWrapper>& wrapper) = 0;
virtual void InvalidWeakCallbackWrapper() {}
};

}
Expand Down
51 changes: 51 additions & 0 deletions driver/js/include/driver/napi/jsh/jsh_class_definition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
*
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* 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.
*
*/

#pragma once

#include "driver/napi/js_class_definition.h"
#include "footstone/logging.h"
#include <ark_runtime/jsvm.h>

namespace hippy {
inline namespace driver {
inline namespace napi {

class JSHClassDefinition: public ClassDefinition {
public:
JSHClassDefinition(JSVM_Env env, JSVM_Value value);
virtual ~JSHClassDefinition();

inline auto GetValue() {
JSVM_Value result = nullptr;
auto s = OH_JSVM_GetReferenceValue(env_, value_ref_, &result);
FOOTSTONE_CHECK(s == JSVM_OK);
return result;
}
private:
JSVM_Env env_ = nullptr;
JSVM_Ref value_ref_ = nullptr;
};

}
}
}
Loading

0 comments on commit c77de4b

Please sign in to comment.