• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_CAVANS_PATTERN_H
16 #define FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_CAVANS_PATTERN_H
17 
18 #include "ffi_remote_data.h"
19 
20 #include "bridge/cj_frontend/cppview/canvas_renderer.h"
21 #include "base/memory/referenced.h"
22 #include "core/components/common/properties/decoration.h"
23 #include "frameworks/core/components/common/properties/paint_state.h"
24 
25 
26 namespace OHOS::Ace::Framework {
27 
28 class ACE_EXPORT NativeCanvasPattern : public OHOS::FFI::FFIData, public Referenced {
29 public:
30     NativeCanvasPattern();
31     ~NativeCanvasPattern() override;
32 
33     void SetTransform(int64_t matrixId);
34 
SetCanvasRenderer(const sptr<NativeCanvasRenderer> & canvasRenderer)35     void SetCanvasRenderer(const sptr<NativeCanvasRenderer>& canvasRenderer)
36     {
37         canvasRenderWeak_ = canvasRenderer;
38     }
39 
SetUnit(CanvasUnit unit)40     void SetUnit(CanvasUnit unit)
41     {
42         unit_ = unit;
43     }
44 
GetUnit()45     CanvasUnit GetUnit()
46     {
47         return unit_;
48     }
49 
GetDensity()50     double GetDensity()
51     {
52         double density = PipelineBase::GetCurrentDensity();
53         return ((GetUnit() == CanvasUnit::DEFAULT) && !NearZero(density)) ? density : 1.0;
54     }
55 
SetId(int32_t id)56     void SetId(int32_t id)
57     {
58         id_ = id;
59     }
60 
GetId()61     int32_t GetId() const
62     {
63         return id_;
64     }
65 private:
66     TransformParam transform_;
67     sptr<NativeCanvasRenderer> canvasRenderWeak_;
68     CanvasUnit unit_ = CanvasUnit::DEFAULT;
69     int32_t id_ = 0;
70 };
71 
72 } // namespace OHOS::Ace::Framework
73 #endif // FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_CAVANS_PATTERN_H
74