• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "core/components_ng/image_provider/image_utils.h"
16 #include "core/common/container.h"
17 
18 namespace OHOS::Ace::NG {
PostTask(std::function<void ()> && task,TaskExecutor::TaskType taskType,const char * taskTypeName)19 void ImageUtils::PostTask(
20     std::function<void()>&& task, TaskExecutor::TaskType taskType, const char* taskTypeName)
21 {
22     auto taskExecutor = Container::CurrentTaskExecutor();
23     if (!taskExecutor) {
24         LOGE("taskExecutor is null when try post task to %{public}s", taskTypeName);
25         return;
26     }
27     taskExecutor->PostTask(
28         [task, id = Container::CurrentId()] {
29             ContainerScope scope(id);
30             CHECK_NULL_VOID(task);
31             task();
32         },
33         taskType);
34 }
35 
PostToUI(std::function<void ()> && task)36 void ImageUtils::PostToUI(std::function<void()>&& task)
37 {
38     CHECK_NULL_VOID(task);
39     ImageUtils::PostTask(std::move(task), TaskExecutor::TaskType::UI, "UI");
40 }
41 
PostToBg(std::function<void ()> && task)42 void ImageUtils::PostToBg(std::function<void()>&& task)
43 {
44     CHECK_NULL_VOID(task);
45     ImageUtils::PostTask(std::move(task), TaskExecutor::TaskType::BACKGROUND, "BACKGROUND");
46 }
47 } // namespace OHOS::Ace::NG
48