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 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 <native_drawing/drawing_rect.h> 29 #include <native_drawing/drawing_rect.h> 30 #include <native_drawing/drawing_filter.h> 31 #include <native_drawing/drawing_color_filter.h> 32 #include <native_drawing/drawing_matrix.h> 33 #include <cstdint> 34 #include <map> 35 #include <sys/mman.h> 36 #include <string> 37 #include "napi/native_api.h" 38 39 class SampleBitMap { 40 public: 41 SampleBitMap() = default; 42 ~SampleBitMap(); SampleBitMap(std::string & id)43 explicit SampleBitMap(std::string &id) : id_(id) {} 44 static napi_value NapiDrawPattern(napi_env env, napi_callback_info info); 45 static void Release(std::string &id); 46 void DrawPath(); 47 void SetWidth(uint64_t width); 48 void SetHeight(uint64_t height); 49 void SetNativeWindow(OHNativeWindow *nativeWindow); 50 void Prepare(); 51 void Create(); 52 void DisPlay(); 53 void ConstructPath(); 54 void SetPenAndBrush(); 55 static void Export(napi_env env, napi_value exports); 56 void RegisterCallback(OH_NativeXComponent *nativeXComponent); 57 void Destroy(); 58 static SampleBitMap *GetInstance(std::string &id); 59 std::string id_ = ""; 60 private: 61 OH_NativeXComponent_Callback renderCallback_; 62 63 uint64_t width_ = 0; 64 uint64_t height_ = 0; 65 66 OH_Drawing_Bitmap *cBitmap_ = nullptr; 67 OH_Drawing_Canvas *cCanvas_ = nullptr; 68 69 OH_Drawing_Path *cPath_ = nullptr; 70 OH_Drawing_Pen *cPen_ = nullptr; 71 OH_Drawing_ColorFilter *cColorFilter_ = nullptr; 72 73 OHNativeWindow *nativeWindow_ = nullptr; 74 uint32_t *mappedAddr_ = nullptr; 75 BufferHandle *bufferHandle_ = nullptr; 76 struct NativeWindowBuffer *buffer_ = nullptr; 77 int fenceFd_ = 0; 78 }; 79 80 #endif 81