• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 <thread>
16 
17 #include "mock_image_loader.h"
18 
19 #include "core/components_ng/image_provider/image_utils.h"
20 
21 namespace {
22 constexpr unsigned int MAX_THREADS = 2;
23 } // namespace
24 
25 namespace OHOS::Ace {
26 std::vector<std::thread> g_threads;
27 
28 namespace NG {
PostToUI(std::function<void ()> && task,const std::string & name,const int32_t containerId,PriorityType priorityType)29 void ImageUtils::PostToUI(
30     std::function<void()>&& task, const std::string& name, const int32_t containerId, PriorityType priorityType)
31 {
32     if (task) {
33         task();
34     }
35 }
36 
PostToBg(std::function<void ()> && task,const std::string & name,const int32_t containerId,PriorityType priorityType)37 void ImageUtils::PostToBg(
38     std::function<void()>&& task, const std::string& name, const int32_t containerId, PriorityType priorityType)
39 {
40     // mock bg thread pool
41     if (g_threads.size() > MAX_THREADS) {
42         return;
43     }
44     g_threads.emplace_back(std::thread(task));
45 }
46 
PostDelayedTaskToUI(std::function<void ()> && task,uint32_t delayTime,const std::string & name,const int32_t containerId,PriorityType priorityType)47 void ImageUtils::PostDelayedTaskToUI(std::function<void()>&& task, uint32_t delayTime, const std::string& name,
48     const int32_t containerId, PriorityType priorityType)
49 {}
50 } // namespace NG
51 } // namespace OHOS::Ace
52