1 /*
2 * Copyright (c) 2024-2024 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
16 #include "core/components_ng/base/transparent_node_detector.h"
17
18 #include "core/pipeline_ng/pipeline_context.h"
19
20 namespace OHOS::Ace::NG {
21 namespace {
22 constexpr uint32_t DELAY_TIME = 1000;
23 } // namespace
24
GetInstance()25 TransparentNodeDetector& TransparentNodeDetector::GetInstance()
26 {
27 static TransparentNodeDetector instance;
28 return instance;
29 }
30
31
PostCheckNodeTransparentTask(const RefPtr<FrameNode> & node,uint8_t detectCount)32 void TransparentNodeDetector::PostCheckNodeTransparentTask(const RefPtr<FrameNode>& node, uint8_t detectCount)
33 {
34 if (detectCount > TransparentNodeDetector::MAX_DETECT_COUNT || detectCount == 0) {
35 return;
36 }
37 CHECK_NULL_VOID(node);
38 auto pipelineContext = PipelineContext::GetCurrentContext();
39 CHECK_NULL_VOID(pipelineContext);
40 auto executor = pipelineContext->GetTaskExecutor();
41 CHECK_NULL_VOID(executor);
42
43 detectCount--;
44 auto task = [weakNode = AceType::WeakClaim(AceType::RawPtr(node)), taskDetectCount = detectCount]() {
45 auto currentNode = weakNode.Upgrade();
46 CHECK_NULL_VOID(currentNode);
47 auto host = currentNode->GetHostNode();
48 CHECK_NULL_VOID(host);
49
50 if (host->IsContextTransparent()) {
51 if (taskDetectCount > 0) {
52 LOGW("TransparentNodeDetector try again");
53 TransparentNodeDetector::GetInstance().PostCheckNodeTransparentTask(currentNode, taskDetectCount);
54 return;
55 }
56 LOGW("TransparentNodeDetector transparent node detected");
57 }
58 };
59 executor->PostDelayedTask(std::move(task), TaskExecutor::TaskType::UI, DELAY_TIME,
60 "ArkUINodeCheckContextTransparent");
61 }
62 } // namespace OHOS::Ace::NG
63
64