1 /* 2 * Copyright (c) 2020-2021 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 GRAPHIC_LITE_GFX_ENGINE_MANAGER_H 17 #define GRAPHIC_LITE_GFX_ENGINE_MANAGER_H 18 19 #include "gfx_utils/color.h" 20 #include "gfx_utils/diagram/common/paint.h" 21 #include "gfx_utils/graphic_buffer.h" 22 #include "gfx_utils/graphic_types.h" 23 #include "gfx_utils/image_info.h" 24 #include "gfx_utils/style.h" 25 #include "gfx_utils/transform.h" 26 27 namespace OHOS { 28 class BaseGfxEngine; 29 enum BlendMode { 30 BLEND_MODE, /* no blending */ 31 BLEND_SRC, /* S */ 32 BLEND_DST, /* D */ 33 BLEND_SRC_OVER, /* S + (1 - Sa) * D */ 34 BLEND_DST_OVER, /* (1 - Da) * S + D */ 35 BLEND_SRC_IN, /* Da * S */ 36 BLEND_DST_IN, /* Sa * D */ 37 BLEND_SRC_OUT, /* S * (1 - Da) */ 38 BLEND_DST_OUT, /* D * (1 - Sa) */ 39 BLEND_SCREEN, /* S + D - S * D */ 40 BLEND_MULTIPLY, /* S * (1 - Da) + D * (1 - Sa) + S * D */ 41 BLEND_ADDITIVE, /* S + D */ 42 BLEND_SUBTRACT, /* D * (1 - S) */ 43 }; 44 45 #ifndef TRANSFORMOPTION 46 #define TRANSFORMOPTION 47 struct TransformOption { 48 TransformAlgorithm algorithm; 49 }; 50 #endif 51 52 struct BlendOption { 53 TransformMap transMap; 54 BlendMode mode; 55 TransformOption option; 56 OpacityType opacity; 57 }; 58 59 class Image; 60 struct ArcInfo { 61 Point center; 62 Point imgPos; 63 uint16_t radius; 64 int16_t startAngle; 65 int16_t endAngle; 66 const Image* imgSrc; 67 }; 68 69 struct TransformDataInfo { 70 ImageHeader header; 71 const uint8_t* data; 72 uint8_t pxSize; 73 BlurLevel blurLevel; 74 TransformAlgorithm algorithm; 75 }; 76 77 enum BufferInfoUsage { BUFFER_FB_SURFACE, BUFFER_MAP_SURFACE, BUFFER_SNAPSHOT_SURFACE }; 78 79 class BaseGfxEngine : public HeapBase { 80 public: 81 virtual void DrawArc(BufferInfo& dst, 82 ArcInfo& arcInfo, 83 const Rect& mask, 84 const Style& style, 85 OpacityType opacity, 86 uint8_t cap) = 0; 87 MemoryBarrier()88 virtual void MemoryBarrier() {} 89 90 virtual void DrawLine(BufferInfo& dst, 91 const Point& start, 92 const Point& end, 93 const Rect& mask, 94 int16_t width, 95 ColorType color, 96 OpacityType opacity) = 0; 97 98 virtual void DrawLetter(BufferInfo& gfxDstBuffer, 99 const uint8_t* fontMap, 100 const Rect& fontRect, 101 const Rect& subRect, 102 const uint8_t fontWeight, 103 const ColorType& color, 104 const OpacityType opa) = 0; 105 106 virtual void DrawCubicBezier(BufferInfo& dst, 107 const Point& start, 108 const Point& control1, 109 const Point& control2, 110 const Point& end, 111 const Rect& mask, 112 int16_t width, 113 ColorType color, 114 OpacityType opacity) = 0; 115 116 virtual void 117 DrawRect(BufferInfo& dst, const Rect& rect, const Rect& dirtyRect, const Style& style, OpacityType opacity) = 0; 118 119 virtual void DrawTransform(BufferInfo& dst, 120 const Rect& mask, 121 const Point& position, 122 ColorType color, 123 OpacityType opacity, 124 const TransformMap& transMap, 125 const TransformDataInfo& dataInfo) = 0; 126 127 // x/y: center of a circle 128 virtual void ClipCircle(const ImageInfo* info, float x, float y, float radius) = 0; 129 130 virtual void Blit(BufferInfo& dst, 131 const Point& dstPos, 132 const BufferInfo& src, 133 const Rect& subRect, 134 const BlendOption& blendOption) = 0; 135 136 virtual void Fill(BufferInfo& dst, const Rect& fillArea, const ColorType color, const OpacityType opacity) = 0; 137 138 virtual void DrawPath(BufferInfo& dst, 139 void* param, 140 const Paint& paint, 141 const Rect& rect, 142 const Rect& invalidatedArea, 143 const Style& style) = 0; 144 145 virtual void FillPath(BufferInfo& dst, 146 void* param, 147 const Paint& paint, 148 const Rect& rect, 149 const Rect& invalidatedArea, 150 const Style& style) = 0; 151 152 virtual uint8_t* AllocBuffer(uint32_t size, uint32_t usage) = 0; 153 154 virtual void FreeBuffer(uint8_t* buffer, uint32_t usage) = 0; 155 GetFBBufferInfo()156 virtual BufferInfo* GetFBBufferInfo() 157 { 158 return nullptr; 159 } 160 AdjustLineStride(BufferInfo & info)161 virtual void AdjustLineStride(BufferInfo& info) {} 162 Flush(const Rect & flushRect)163 virtual void Flush(const Rect& flushRect) {} 164 GetScreenWidth()165 virtual uint16_t GetScreenWidth() 166 { 167 return screenWidth_; 168 } 169 GetScreenHeight()170 virtual uint16_t GetScreenHeight() 171 { 172 return screenHeight_; 173 } 174 SetScreenShape(ScreenShape screenShape)175 virtual void SetScreenShape(ScreenShape screenShape) 176 { 177 screenShape_ = screenShape; 178 } 179 GetScreenShape()180 virtual ScreenShape GetScreenShape() 181 { 182 return screenShape_; 183 } 184 GetInstance()185 static BaseGfxEngine* GetInstance() 186 { 187 return baseEngine_; 188 } 189 InitGfxEngine(BaseGfxEngine * gfxEngine)190 static void InitGfxEngine(BaseGfxEngine* gfxEngine) 191 { 192 baseEngine_ = gfxEngine; 193 } 194 195 protected: 196 static BaseGfxEngine* baseEngine_; 197 uint16_t screenWidth_ = HORIZONTAL_RESOLUTION; 198 uint16_t screenHeight_ = VERTICAL_RESOLUTION; 199 ScreenShape screenShape_ = RECTANGLE; 200 }; 201 } // namespace OHOS 202 203 #endif // GRAPHIC_LITE_GFX_ENGINE_MANAGER_H 204