• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 OHOS_ROSEN_ANI_CANVAS_H
17 #define OHOS_ROSEN_ANI_CANVAS_H
18 
19 #ifdef ROSEN_OHOS
20 #include "pixel_map.h"
21 #endif
22 #include "ani_drawing_utils.h"
23 #include "draw/canvas.h"
24 #include "sampling_options_ani/ani_sampling_options.h"
25 
26 namespace OHOS::Rosen {
27 namespace Drawing {
28 class AniCanvas final {
29 public:
30     AniCanvas() = default;
m_canvas(canvas)31     explicit AniCanvas(Canvas* canvas, bool owned = false) : m_canvas(canvas), owned_(owned) {};
32     ~AniCanvas();
33 
34     static ani_status AniInit(ani_env *env);
35     static void Constructor(ani_env* env, ani_object obj, ani_object pixelmapObj);
36     static void DrawRect(ani_env* env, ani_object obj,
37         ani_double left, ani_double top, ani_double right, ani_double bottom);
38     static void DrawRectWithRect(ani_env* env, ani_object obj, ani_object aniRect);
39     static void DrawImageRect(ani_env* env, ani_object obj,
40         ani_object pixelmapObj, ani_object rectObj, ani_object samplingOptionsObj);
41 
42     static void DrawPixelMapMesh(ani_env* env, ani_object obj,
43         ani_object pixelmapObj, ani_double aniMeshWidth, ani_double aniMeshHeight,
44         ani_object verticesObj, ani_double aniVertOffset, ani_object colorsObj, ani_double aniColorOffset);
45 
46     static void AttachBrush(ani_env* env, ani_object obj, ani_object brushObj);
47     static void AttachPen(ani_env* env, ani_object obj, ani_object penObj);
48     static void DetachBrush(ani_env* env, ani_object obj);
49     static void DetachPen(ani_env* env, ani_object obj);
50     static ani_double Save(ani_env* env, ani_object obj);
51     static ani_double SaveLayer(ani_env* env, ani_object obj, ani_object rectObj, ani_object brushObj);
52     static void Restore(ani_env* env, ani_object obj);
53     static ani_double GetSaveCount(ani_env* env, ani_object obj);
54     static void Rotate(ani_env* env, ani_object obj, ani_double degrees, ani_double sx, ani_double sy);
55 
56     Canvas* GetCanvas();
57     DRAWING_API void ResetCanvas();
58     DRAWING_API void ClipCanvas(float width, float height);
59     DRAWING_API void SaveCanvas();
60     DRAWING_API void RestoreCanvas();
61     DRAWING_API static ani_object CreateAniCanvas(ani_env* env, Canvas* canvas);
62 
63 private:
64     void NotifyDirty();
65 #ifdef ROSEN_OHOS
66     void DrawImageRectInner(std::shared_ptr<Media::PixelMap> pixelmap,
67         Drawing::Rect& rect, AniSamplingOptions* samplingOptions);
68 #endif
69     Canvas* m_canvas = nullptr;
70     bool owned_ = false;
71 #ifdef ROSEN_OHOS
72     std::shared_ptr<Media::PixelMap> mPixelMap_ = nullptr;
73 #endif
74 };
75 } // namespace Drawing
76 } // namespace OHOS::Rosen
77 #endif // OHOS_ROSEN_ANI_CANVAS_H