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_BITMAP_H 17 #define SAMPLE_BITMAP_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 SampleBitMap { 35 public: 36 SampleBitMap() = default; 37 ~SampleBitMap(); SampleBitMap(std::string id)38 explicit SampleBitMap(std::string id) : id_(id) {} 39 static napi_value NapiDrawPattern(napi_env env, napi_callback_info info); 40 static napi_value NapiDrawText(napi_env env, napi_callback_info info); 41 static void Release(std::string &id); 42 void DrawPath(); 43 void DrawText(); 44 void SetWidth(uint64_t width); 45 void SetHeight(uint64_t height); 46 void SetNativeWindow(OHNativeWindow *nativeWindow); 47 void Prepare(); 48 void Create(); 49 void DisPlay(); 50 void ConstructPath(); 51 void SetPenAndBrush(); 52 void Export(napi_env env, napi_value exports); 53 void RegisterCallback(OH_NativeXComponent *nativeXComponent); 54 void Destroy(); 55 static SampleBitMap *GetInstance(std::string &id); 56 std::string id_; 57 private: 58 OH_NativeXComponent_Callback renderCallback_; 59 60 uint64_t width_ = 0; 61 uint64_t height_ = 0; 62 63 OH_Drawing_Bitmap *cBitmap_ = nullptr; 64 OH_Drawing_Canvas *cCanvas_ = nullptr; 65 66 OH_Drawing_Path *cPath_ = nullptr; 67 OH_Drawing_Brush *cBrush_ = nullptr; 68 OH_Drawing_Pen *cPen_ = nullptr; 69 OHNativeWindow *nativeWindow_ = nullptr; 70 uint32_t *mappedAddr_ = nullptr; 71 BufferHandle *bufferHandle_ = nullptr; 72 struct NativeWindowBuffer *buffer_ = nullptr; 73 int fenceFd_ = 0; 74 }; 75 76 77 #endif 78