remove the deps to previewer.

Signed-off-by: seaside_wu <wuhaibin5@huawei.com>
Change-Id: Ib94d84b4c07d48c5c25951cc1f6221c355a474f8
This commit is contained in:
seaside_wu 2023-11-21 09:42:30 +08:00
parent ce82536bdd
commit 2858a623a0
11 changed files with 194 additions and 48 deletions

View File

@ -42,6 +42,7 @@ ohos_source_set("preview_entrance_source") {
"ace_ability.cpp",
"ace_application_info.cpp",
"ace_container.cpp",
"ace_preview_helper.cpp",
"ace_resource_register.cpp",
"ace_view_preview.cpp",
"clipboard/clipboard_impl.cpp",
@ -65,7 +66,6 @@ ohos_source_set("preview_entrance_source") {
"$flutter_root/engine",
"//foundation/window/window_manager",
"//foundation/ability/ability_runtime",
"//ide/tools/previewer",
"//arkcompiler/ets_runtime",
"//arkcompiler/runtime_core",
]
@ -73,8 +73,6 @@ ohos_source_set("preview_entrance_source") {
if (defined(config.enable_rosen_backend) && config.enable_rosen_backend) {
external_deps += [
"graphic_2d:librender_service_client",
"previewer:ide_extension",
"previewer:ide_util",
"window_manager:previewer_window",
]
if (ace_use_rosen_drawing) {

View File

@ -31,11 +31,11 @@
#include "core/common/rosen/rosen_asset_manager.h"
#endif
#include "jsapp/rich/external/StageContext.h"
#include "native_engine/native_engine.h"
#include "previewer/include/window.h"
#include "adapter/preview/entrance/ace_application_info.h"
#include "adapter/preview/entrance/ace_preview_helper.h"
#include "adapter/preview/osal/stage_card_parser.h"
#include "base/log/ace_trace.h"
#include "base/log/event_report.h"
@ -261,18 +261,7 @@ void AceContainer::SetHspBufferTrackerCallback()
ContainerScope scope(instanceId);
auto jsEngine = AceType::DynamicCast<Framework::JsiDeclarativeEngine>(weak.Upgrade());
CHECK_NULL_VOID(jsEngine);
jsEngine->SetHspBufferTrackerCallback(
[](const std::string& inputPath, uint8_t** buff, size_t* buffSize) -> bool {
if (!buff || !buffSize || inputPath.empty()) {
LOGI("The pointer of buff or buffSize is null or inputPath is empty.");
return false;
}
auto data = OHOS::Ide::StageContext::GetInstance().GetModuleBuffer(inputPath);
CHECK_NULL_RETURN(data, false);
*buff = data->data();
*buffSize = data->size();
return true;
});
jsEngine->SetHspBufferTrackerCallback(AcePreviewHelper::GetInstance()->GetCallbackOfHspBufferTracker());
},
TaskExecutor::TaskType::JS);
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2023 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 "adapter/preview/entrance/ace_preview_helper.h"
#include <memory>
#include <mutex>
namespace OHOS::Ace::Platform {
namespace {
std::unique_ptr<AcePreviewHelper> instance_ = nullptr;
std::mutex mutex_;
} // namespace
AcePreviewHelper* AcePreviewHelper::GetInstance()
{
if (!instance_) {
std::lock_guard<std::mutex> lock(mutex_);
if (!instance_) {
instance_.reset(new AcePreviewHelper());
}
}
return instance_.get();
}
} // namespace OHOS::Ace::Platform

View File

@ -0,0 +1,96 @@
/*
* Copyright (c) 2023 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 FOUNDATION_ACE_ADAPTER_PREVIEW_ACE_PREVIEW_HELPER_H
#define FOUNDATION_ACE_ADAPTER_PREVIEW_ACE_PREVIEW_HELPER_H
#include <functional>
#include "base/utils/macros.h"
namespace OHOS::Ace::Platform {
using CallbackTypeIsCurrentRunnerThread = std::function<bool(void)>;
using CallbackTypePostTask = std::function<void(const std::function<void()>&, int64_t)>;
using CallbackTypeHspBufferTracker = std::function<bool(const std::string&, uint8_t**, size_t*)>;
using CallbackTypeSetClipboardData = std::function<void(const std::string&)>;
using CallbackTypeGetClipboardData = std::function<const std::string(void)>;
class ACE_FORCE_EXPORT AcePreviewHelper {
public:
static AcePreviewHelper* GetInstance();
~AcePreviewHelper() = default;
void SetCallbackOfPostTask(const CallbackTypePostTask&& postTask)
{
postTask_ = postTask;
}
CallbackTypePostTask GetCallbackOfPostTask()
{
return postTask_;
}
void SetCallbackOfIsCurrentRunnerThread(const CallbackTypeIsCurrentRunnerThread&& isCurrentRunnerThread)
{
isCurrentRunnerThread_ = isCurrentRunnerThread;
}
CallbackTypeIsCurrentRunnerThread GetCallbackOfIsCurrentRunnerThread()
{
return isCurrentRunnerThread_;
}
void SetCallbackOfHspBufferTracker(const CallbackTypeHspBufferTracker&& hspBufferTracker)
{
hspBufferTracker_ = hspBufferTracker;
}
CallbackTypeHspBufferTracker GetCallbackOfHspBufferTracker()
{
return hspBufferTracker_;
}
void SetCallbackOfSetClipboardData(const CallbackTypeSetClipboardData&& setClipboardData)
{
setClipboardData_ = std::move(setClipboardData);
}
CallbackTypeSetClipboardData GetCallbackOfSetClipboardData()
{
return setClipboardData_;
}
void SetCallbackOfGetClipboardData(const CallbackTypeGetClipboardData&& getClipboardData)
{
getClipboardData_ = std::move(getClipboardData);
}
CallbackTypeGetClipboardData GetCallbackOfGetClipboardData()
{
return getClipboardData_;
}
private:
AcePreviewHelper() = default;
AcePreviewHelper(const AcePreviewHelper&) = delete;
AcePreviewHelper& operator=(const AcePreviewHelper&) = delete;
CallbackTypePostTask postTask_ = nullptr;
CallbackTypeIsCurrentRunnerThread isCurrentRunnerThread_ = nullptr;
CallbackTypeHspBufferTracker hspBufferTracker_ = nullptr;
CallbackTypeSetClipboardData setClipboardData_ = nullptr;
CallbackTypeGetClipboardData getClipboardData_ = nullptr;
};
} // namespace OHOS::Ace::Platform
#endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ACE_PREVIEW_HELPER_H

View File

@ -15,8 +15,7 @@
#include "adapter/preview/entrance/clipboard/clipboard_impl.h"
#include "util/ClipboardHelper.h"
#include "adapter/preview/entrance/ace_preview_helper.h"
#include "frameworks/base/utils/utils.h"
namespace OHOS::Ace::Platform {
@ -38,7 +37,13 @@ RefPtr<PasteDataMix> ClipboardImpl::CreatePasteDataMix()
void ClipboardImpl::SetData(const std::string& data, CopyOptions copyOption, bool isDragData)
{
CHECK_NULL_VOID(taskExecutor_);
taskExecutor_->PostTask([data] { ClipboardHelper::SetClipboardData(data); },
taskExecutor_->PostTask(
[data] {
auto setClipboardData = AcePreviewHelper::GetInstance()->GetCallbackOfSetClipboardData();
if (setClipboardData) {
setClipboardData(data);
}
},
TaskExecutor::TaskType::UI);
}
@ -47,7 +52,13 @@ void ClipboardImpl::GetData(const std::function<void(const std::string&)>& callb
if (!taskExecutor_ || !callback) {
return;
}
taskExecutor_->PostTask([callback] { callback(ClipboardHelper::GetClipboardData()); },
taskExecutor_->PostTask(
[callback] {
auto getClipboardData = AcePreviewHelper::GetInstance()->GetCallbackOfGetClipboardData();
if (callback && getClipboardData) {
callback(getClipboardData());
}
},
TaskExecutor::TaskType::UI);
}
@ -56,7 +67,13 @@ void ClipboardImpl::HasData(const std::function<void(bool hasData)>& callback)
if (!taskExecutor_ || !callback) {
return;
}
taskExecutor_->PostTask([callback] { callback(!ClipboardHelper::GetClipboardData().empty()); },
taskExecutor_->PostTask(
[callback] {
auto getClipboardData = AcePreviewHelper::GetInstance()->GetCallbackOfGetClipboardData();
if (callback && getClipboardData) {
callback(!getClipboardData().empty());
}
},
TaskExecutor::TaskType::UI);
}

View File

@ -51,7 +51,6 @@ foreach(device, ace_devices) {
"$ace_root/frameworks",
"$flutter_root/glfw/include",
"//foundation/window/window_manager",
"//ide/tools/previewer",
]
deps += [ ":copy_preview_shared_library" ]
sources = [
@ -61,7 +60,6 @@ foreach(device, ace_devices) {
external_deps = [
"graphic_2d:librender_service_client",
"previewer:ide_extension",
"window_manager:previewer_window",
]

View File

@ -47,16 +47,10 @@ ohos_source_set("preview_external_source") {
# for rosen backend
if (defined(config.enable_rosen_backend) && config.enable_rosen_backend) {
# for event loop
include_dirs = [
"//third_party/flutter/engine",
"//ide/tools/previewer",
]
include_dirs = [ "//third_party/flutter/engine" ]
# for window
external_deps = [
"graphic_2d:librender_service_client",
"previewer:ide_extension",
]
external_deps = [ "graphic_2d:librender_service_client" ]
sources += [
# for event loop

View File

@ -16,30 +16,41 @@
#include "adapter/preview/external/flutter/platform_task_runner_adapter.h"
#include "flutter/fml/time/time_point.h"
#include "jsapp/rich/external/EventHandler.h"
#include "adapter/preview/entrance/ace_preview_helper.h"
namespace flutter {
PlatformTaskRunnerAdapter::PlatformTaskRunnerAdapter(bool useCurrentEventRunner) : fml::TaskRunner(nullptr) {}
void PlatformTaskRunnerAdapter::PostTask(fml::closure task, const std::string& caller)
{
OHOS::AppExecFwk::EventHandler::PostTask(std::move(task));
auto postTask = OHOS::Ace::Platform::AcePreviewHelper::GetInstance()->GetCallbackOfPostTask();
if (postTask) {
postTask(std::move(task), 0);
}
}
void PlatformTaskRunnerAdapter::PostTaskForTime(fml::closure task, fml::TimePoint target_time, const std::string& caller)
void PlatformTaskRunnerAdapter::PostTaskForTime(fml::closure task, fml::TimePoint targetTime, const std::string& caller)
{
OHOS::AppExecFwk::EventHandler::PostTask(std::move(task), target_time.ToEpochDelta().ToMilliseconds());
auto postTask = OHOS::Ace::Platform::AcePreviewHelper::GetInstance()->GetCallbackOfPostTask();
if (postTask) {
postTask(std::move(task), targetTime.ToEpochDelta().ToMilliseconds());
}
}
void PlatformTaskRunnerAdapter::PostDelayedTask(fml::closure task, fml::TimeDelta delay, const std::string& caller)
{
OHOS::AppExecFwk::EventHandler::PostTask(std::move(task), delay.ToMilliseconds());
auto postTask = OHOS::Ace::Platform::AcePreviewHelper::GetInstance()->GetCallbackOfPostTask();
if (postTask) {
postTask(std::move(task), delay.ToMilliseconds());
}
}
bool PlatformTaskRunnerAdapter::RunsTasksOnCurrentThread()
{
return OHOS::AppExecFwk::EventHandler::IsCurrentRunnerThread();
auto isCurrentRunnerThread =
OHOS::Ace::Platform::AcePreviewHelper::GetInstance()->GetCallbackOfIsCurrentRunnerThread();
return isCurrentRunnerThread && isCurrentRunnerThread();
}
fml::TaskQueueId PlatformTaskRunnerAdapter::GetTaskQueueId()

View File

@ -103,10 +103,7 @@ ohos_source_set("preview_osal_source") {
"//third_party/curl:curl_config",
]
include_dirs = [
"//commonlibrary/c_utils/base/include",
"//ide/tools/previewer",
]
include_dirs = [ "//commonlibrary/c_utils/base/include" ]
if (is_ohos_standard_system) {
sources += [

View File

@ -15,27 +15,38 @@
#include "adapter/preview/osal/task/task_runner_adapter_impl.h"
#include "jsapp/rich/external/EventHandler.h"
#include "adapter/preview/entrance/ace_preview_helper.h"
namespace OHOS::Ace {
void TaskRunnerAdapterImpl::PostTask(std::function<void()> task, const std::string& caller)
{
OHOS::AppExecFwk::EventHandler::PostTask(std::move(task));
auto postTask = OHOS::Ace::Platform::AcePreviewHelper::GetInstance()->GetCallbackOfPostTask();
if (postTask) {
postTask(std::move(task), 0);
}
}
void TaskRunnerAdapterImpl::PostTaskForTime(std::function<void()> task, uint32_t targetTime, const std::string& caller)
{
OHOS::AppExecFwk::EventHandler::PostTask(std::move(task), targetTime);
auto postTask = OHOS::Ace::Platform::AcePreviewHelper::GetInstance()->GetCallbackOfPostTask();
if (postTask) {
postTask(std::move(task), targetTime);
}
}
void TaskRunnerAdapterImpl::PostDelayedTask(std::function<void()> task, uint32_t delay, const std::string& caller)
{
OHOS::AppExecFwk::EventHandler::PostTask(std::move(task), delay);
auto postTask = OHOS::Ace::Platform::AcePreviewHelper::GetInstance()->GetCallbackOfPostTask();
if (postTask) {
postTask(std::move(task), delay);
}
}
bool TaskRunnerAdapterImpl::RunsTasksOnCurrentThread()
{
return OHOS::AppExecFwk::EventHandler::IsCurrentRunnerThread();
auto isCurrentRunnerThread =
OHOS::Ace::Platform::AcePreviewHelper::GetInstance()->GetCallbackOfIsCurrentRunnerThread();
return isCurrentRunnerThread && isCurrentRunnerThread();
}
void TaskRunnerAdapterImpl::Initialize(bool useCurrentEventRunner, const std::string& name) {}

View File

@ -71,7 +71,6 @@
"soc_perf",
"security_component_manager",
"camera_framework",
"previewer",
"media_library",
"app_file_service"
],
@ -181,4 +180,4 @@
]
}
}
}
}