• 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 
16 #ifndef FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_OFFSCREEN_CAVANS_H
17 #define FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_OFFSCREEN_CAVANS_H
18 
19 #include <cstdint>
20 
21 #include "ffi_remote_data.h"
22 
23 #include "base/memory/referenced.h"
24 #include "bridge/cj_frontend/cppview/offscreen_rendering_context.h"
25 #include "core/components/common/properties/decoration.h"
26 #include "core/components_ng/pattern/canvas/offscreen_canvas_pattern.h"
27 
28 namespace OHOS::Ace::Framework {
29 
30 class ACE_EXPORT NativeOffscreenCanvas : public OHOS::FFI::FFIData {
31 public:
32     NativeOffscreenCanvas(double height, double width, int32_t unit);
33     ~NativeOffscreenCanvas() override;
34 
35     int64_t GetContext(int32_t contextType, bool option, double width, double height);
36     int64_t TransferToImageBitmap();
37     void NativeSetHeihgt(double height);
38     void NativeSetWidth(double width);
39     double NativeGetHeihgt();
40     double NativeGetWidth();
41 
SetWidth(double width)42     void SetWidth(double width)
43     {
44         width_ = width;
45     }
46 
GetWidth()47     double GetWidth() const
48     {
49         return width_;
50     }
51 
SetHeight(double height)52     void SetHeight(double height)
53     {
54         height_ = height;
55     }
56 
GetHeight()57     double GetHeight() const
58     {
59         return height_;
60     }
61 
IsGetContext()62     bool IsGetContext() const
63     {
64         return isGetContext_;
65     }
66 
SetDetachStatus(bool isDetached)67     void SetDetachStatus(bool isDetached)
68     {
69         isDetached_ = isDetached;
70     }
71 
IsDetached()72     bool IsDetached() const
73     {
74         return isDetached_;
75     }
76 
SetUnit(CanvasUnit unit)77     void SetUnit(CanvasUnit unit)
78     {
79         unit_ = unit;
80     }
81 
SetOffscreenPattern(const RefPtr<NG::OffscreenCanvasPattern> & offscreenPattern)82     void SetOffscreenPattern(const RefPtr<NG::OffscreenCanvasPattern>& offscreenPattern)
83     {
84         offscreenCanvasPattern_ = offscreenPattern;
85     }
86 
GetUnit()87     CanvasUnit GetUnit()
88     {
89         return unit_;
90     }
91 
GetDensity()92     double GetDensity()
93     {
94         double density = PipelineBase::GetCurrentDensity();
95         return ((GetUnit() == CanvasUnit::DEFAULT) && !NearZero(density)) ? density : 1.0;
96     }
97 
98     enum class ContextType {
99         CONTEXT_2D = 0,
100     };
101 
SetOffscreenCanvasContext(const sptr<CJOffscreenRenderingContext> offscreenCanvasContext)102     void SetOffscreenCanvasContext(const sptr<CJOffscreenRenderingContext> offscreenCanvasContext)
103     {
104         offscreenCanvasContext_ = offscreenCanvasContext;
105     }
106 
107 private:
108     CanvasUnit unit_ = CanvasUnit::DEFAULT;
109     double width_ = 0.0f;
110     double height_ = 0.0f;
111     RefPtr<NG::OffscreenCanvasPattern> offscreenCanvasPattern_;
112     sptr<CJOffscreenRenderingContext> offscreenCanvasContext_;
113     bool isGetContext_ = false;
114     bool isDetached_ = false;
115     ContextType contextType_;
116 };
117 
118 } // namespace OHOS::Ace::Framework
119 #endif // FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_CAVANS_PATH_H
120