• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include/draw/canvas.h"
19 #include "foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_canvas.h"
20 
21 namespace OHOS::Ace::NG {
22 
ModelPaintMethod(const WeakPtr<ModelAdapterWrapper> & adapter)23 ModelPaintMethod::ModelPaintMethod(const WeakPtr<ModelAdapterWrapper>& adapter) : modelAdapter_(adapter)
24 {}
25 
GetContentDrawFunction(PaintWrapper * paintWrapper)26 CanvasDrawFunction ModelPaintMethod::GetContentDrawFunction(PaintWrapper* paintWrapper)
27 {
28     auto adapter = modelAdapter_.Upgrade();
29     CHECK_NULL_RETURN(adapter, nullptr);
30     return [weak = WeakClaim(this), paintWrapper](RSCanvas& canvas) {
31         auto model = weak.Upgrade();
32         if (model) {
33             model->PerformPaint(canvas, paintWrapper);
34             model->OnPaintFinish();
35         }
36     };
37 }
38 
OnPaintFinish()39 void ModelPaintMethod::OnPaintFinish()
40 {
41     auto adapter = modelAdapter_.Upgrade();
42     CHECK_NULL_VOID(adapter);
43     adapter->OnPaintFinish();
44 }
45 
PerformPaint(RSCanvas & canvas,PaintWrapper * paintWrapper)46 void ModelPaintMethod::PerformPaint(RSCanvas& canvas, PaintWrapper* paintWrapper)
47 {
48     LOGD("MODEL_NG PerformPaint()");
49     auto adapter = modelAdapter_.Upgrade();
50     CHECK_NULL_VOID(adapter);
51     if (!adapter->IsReady()) {
52         return;
53     }
54     auto paintProperty = DynamicCast<ModelPaintProperty>(paintWrapper->GetPaintProperty());
55     CHECK_NULL_VOID(paintProperty);
56     auto offset = paintWrapper->GetContentOffset();
57     adapter->OnPaint(paintProperty);
58     std::shared_ptr<Rosen::Drawing::CoreCanvasImpl> coreCanvas = canvas.GetCanvasData();
59     const Rosen::Drawing::SkiaCanvas* skiaCanvas = static_cast<const Rosen::Drawing::SkiaCanvas*>(coreCanvas.get());
60     CHECK_NULL_VOID(skiaCanvas);
61     SkCanvas* skCanvas = skiaCanvas->ExportSkCanvas();
62     CHECK_NULL_VOID(skCanvas);
63     adapter->GetTextureLayer(offset)->OnDraw(skCanvas);
64 }
65 } // namespace OHOS::Ace::NG
66