• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 "bridge/declarative_frontend/jsview/models/canvas/canvas_model_impl.h"
17 
18 #include "bridge/declarative_frontend/view_stack_processor.h"
19 #include "core/components/custom_paint/custom_paint_component.h"
20 
21 namespace OHOS::Ace::Framework {
Create()22 RefPtr<AceType> CanvasModelImpl::Create()
23 {
24     auto paintChild = AceType::MakeRefPtr<OHOS::Ace::CustomPaintComponent>();
25     if (!paintChild) {
26         return nullptr;
27     }
28     ViewStackProcessor::GetInstance()->ClaimElementId(paintChild);
29     ViewStackProcessor::GetInstance()->Push(paintChild);
30     return AceType::DynamicCast<OHOS::Ace::CustomPaintComponent>(paintChild)->GetTaskPool();
31 }
32 
SetOnReady(std::function<void (uint32_t)> && readyEvent)33 void CanvasModelImpl::SetOnReady(std::function<void(uint32_t)>&& readyEvent)
34 {
35     auto container = Container::Current();
36     if (!container) {
37         LOGE("No container");
38         return;
39     }
40     auto context = AceType::DynamicCast<PipelineContext>(container->GetPipelineContext());
41     if (!context) {
42         LOGE("No PipelineContext");
43         return;
44     }
45     auto component = AceType::DynamicCast<CustomPaintComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
46     if (!component) {
47         LOGE("No CustomPaintComponent");
48         return;
49     }
50 
51     auto elmtId = component->GetElementId();
52     auto fun = readyEvent;
53     auto onReadEvent = [fun, elmtId]() { fun(elmtId); };
54 
55     auto onReadyEvent = EventMarker(std::move(onReadEvent));
56 
57     component->SetOnReadyEvent(onReadyEvent, context);
58 }
59 } // namespace OHOS::Ace::Framework
60