1 /*
2 * Copyright (c) 2022 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/pattern/model/model_paint_method.h"
17
18
19 namespace OHOS::Ace::NG {
20
ModelPaintMethod(const WeakPtr<ModelAdapterWrapper> & adapter)21 ModelPaintMethod::ModelPaintMethod(const WeakPtr<ModelAdapterWrapper>& adapter) : modelAdapter_(adapter)
22 {}
23
GetContentDrawFunction(PaintWrapper * paintWrapper)24 CanvasDrawFunction ModelPaintMethod::GetContentDrawFunction(PaintWrapper* paintWrapper)
25 {
26 auto adapter = modelAdapter_.Upgrade();
27 CHECK_NULL_RETURN(adapter, nullptr);
28 return [weak = WeakClaim(this), paintWrapper](RSCanvas& canvas) {
29 auto model = weak.Upgrade();
30 if (model) {
31 model->PerformPaint(canvas, paintWrapper);
32 model->OnPaintFinish();
33 }
34 };
35 }
36
OnPaintFinish()37 void ModelPaintMethod::OnPaintFinish()
38 {
39 auto adapter = modelAdapter_.Upgrade();
40 CHECK_NULL_VOID(adapter);
41 adapter->OnPaintFinish();
42 }
43
PerformPaint(RSCanvas & canvas,PaintWrapper * paintWrapper)44 void ModelPaintMethod::PerformPaint(RSCanvas& canvas, PaintWrapper* paintWrapper)
45 {
46 auto adapter = modelAdapter_.Upgrade();
47 CHECK_NULL_VOID(adapter);
48 auto paintProperty = DynamicCast<ModelPaintProperty>(paintWrapper->GetPaintProperty());
49 CHECK_NULL_VOID(paintProperty);
50 adapter->OnPaint3D(paintProperty);
51 }
52 } // namespace OHOS::Ace::NG
53