1 /* 2 * Copyright (c) 2023 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 SAMPLE_XCOMPONENT_H 17 #define SAMPLE_XCOMPONENT_H 18 #include <ace/xcomponent/native_interface_xcomponent.h> 19 #include <arpa/nameser.h> 20 #include <bits/alltypes.h> 21 #include <native_window/external_window.h> 22 #include <native_drawing/drawing_bitmap.h> 23 #include <native_drawing/drawing_color.h> 24 #include <native_drawing/drawing_canvas.h> 25 #include <native_drawing/drawing_pen.h> 26 #include <native_drawing/drawing_brush.h> 27 #include <native_drawing/drawing_path.h> 28 #include <cstdint> 29 #include <map> 30 #include <sys/mman.h> 31 #include <string> 32 #include "napi/native_api.h" 33 34 class SampleXComponent { 35 public: 36 SampleXComponent() = default; 37 ~SampleXComponent(); SampleXComponent(std::string id)38 explicit SampleXComponent(std::string id) : id_(id) {} 39 static napi_value NapiRegister(napi_env env, napi_callback_info info); 40 static napi_value NapiUnregister(napi_env env, napi_callback_info info); 41 static void Release(std::string &id); 42 void DrawPath(); 43 void SetWidth(uint64_t width); 44 void SetHeight(uint64_t height); 45 void SetNativeWindow(OHNativeWindow *nativeWindow); 46 OHNativeWindow* GetNativeWindow(); 47 48 void Prepare(); 49 void Create(); 50 void DisPlay(); 51 void ConstructPath(int x, int y, int offsetY); 52 void SetPenAndBrush(); 53 void Export(napi_env env, napi_value exports); 54 void RegisterCallback(OH_NativeXComponent *nativeXComponent); 55 void RegisterOnFrameCallback(OH_NativeXComponent *nativeXComponent); 56 void Destroy(); 57 static SampleXComponent *GetInstance(std::string &id); 58 std::string id_; 59 int defaultOffsetY = 300; 60 private: 61 OH_NativeXComponent_Callback renderCallback_; 62 63 uint64_t width_ = 0; 64 uint64_t height_ = 0; 65 66 float aX = 0.0; 67 float aY = 0.0; 68 float bX = 80.0; 69 float cY = 0.0; 70 bool desc = false; 71 72 OH_Drawing_Bitmap *cBitmap_ = nullptr; 73 OH_Drawing_Canvas *cCanvas_ = nullptr; 74 75 OH_Drawing_Path *cPath_ = nullptr; 76 OH_Drawing_Brush *cBrush_ = nullptr; 77 OH_Drawing_Pen *cPen_ = nullptr; 78 OHNativeWindow *nativeWindow_ = nullptr; 79 uint32_t *mappedAddr_ = nullptr; 80 BufferHandle *bufferHandle_ = nullptr; 81 struct NativeWindowBuffer *buffer_ = nullptr; 82 int fenceFd_ = 0; 83 }; 84 85 #endif 86