gfx_engine_manager.h 4.7 KB
Newer Older
N
niulihua 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef GRAPHIC_LITE_GFX_ENGINE_MANAGER_H
#define GRAPHIC_LITE_GFX_ENGINE_MANAGER_H

N
niulihua 已提交
19 20
#include "gfx_utils/geometry2d.h"
#include "gfx_utils/graphic_buffer.h"
N
niulihua 已提交
21
#include "gfx_utils/graphic_math.h"
N
niulihua 已提交
22 23
#include "gfx_utils/graphic_types.h"
#include "gfx_utils/heap_base.h"
N
niulihua 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include "gfx_utils/style.h"
#include "gfx_utils/transform.h"

namespace OHOS {
class BaseGfxEngine;
enum BlendMode {
    BLEND_MODE,          /* no blending */
    BLEND_SRC,           /* S */
    BLEND_DST,           /* D */
    BLEND_SRC_OVER,      /* S + (1 - Sa) * D */
    BLEND_DST_OVER,      /* (1 - Da) * S + D */
    BLEND_SRC_IN,        /* Da * S */
    BLEND_DST_IN,        /* Sa * D */
    BLEND_SRC_OUT,       /* S * (1 - Da) */
    BLEND_DST_OUT,       /* D * (1 - Sa) */
    BLEND_SCREEN,        /* S + D - S * D */
    BLEND_MULTIPLY,      /* S * (1 - Da) + D * (1 - Sa) + S * D */
    BLEND_ADDITIVE,      /* S + D */
    BLEND_SUBTRACT,      /* D * (1 - S) */
};

N
niulihua 已提交
45 46
#ifndef TRANSFORMOPTION
#define TRANSFORMOPTION
N
niulihua 已提交
47 48 49
struct TransformOption {
    TransformAlgorithm algorithm;
};
N
niulihua 已提交
50
#endif
N
niulihua 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

struct BlendOption {
    TransformMap transMap;
    BlendMode mode;
    TransformOption option;
    OpacityType opacity;
};

class Image;
struct ArcInfo {
    Point center;
    Point imgPos;
    uint16_t radius;
    int16_t startAngle;
    int16_t endAngle;
    const Image* imgSrc;
};

struct TransformDataInfo {
    ImageHeader header;
    const uint8_t* data;
    uint8_t pxSize;
    BlurLevel blurLevel;
    TransformAlgorithm algorithm;
};

enum BufferInfoUsage {
    BUFFER_FB_SURFACE,
    BUFFER_MAP_SURFACE,
    BUFFER_SNAPSHOT_SURFACE
};

class BaseGfxEngine : public HeapBase {
public:
    virtual void DrawArc(BufferInfo& dst, ArcInfo& arcInfo, const Rect& mask,
                         const Style& style, OpacityType opacity, uint8_t cap);

    virtual void DrawLine(BufferInfo& dst, const Point& start, const Point& end,
                          const Rect& mask, int16_t width, ColorType color, OpacityType opacity);

    virtual void DrawCubicBezier(BufferInfo& dst, const Point& start, const Point& control1,
                                 const Point& control2, const Point& end, const Rect& mask,
                                 int16_t width, ColorType color, OpacityType opacity);

    virtual void DrawRect(BufferInfo& dst,
                          const Rect& rect,
                          const Rect& dirtyRect,
                          const Style& style,
                          OpacityType opacity);

    virtual void DrawTransform(BufferInfo& dst,
                               const Rect& mask,
                               const Point& position,
                               ColorType color,
                               OpacityType opacity,
                               const TransformMap& transMap,
                               const TransformDataInfo& dataInfo);

    virtual void Blit(BufferInfo& dst,
                      const Point& dstPos,
                      const BufferInfo& src,
                      const Rect& subRect,
                      const BlendOption& blendOption);

    virtual void Fill(BufferInfo& dst,
                      const Rect& fillArea,
                      const ColorType color,
                      const OpacityType opacity);

    virtual uint8_t* AllocBuffer(uint32_t size, uint32_t usage);

    virtual void FreeBuffer(uint8_t* buffer);

    virtual BufferInfo* GetBufferInfo()
    {
        return nullptr;
    }

    virtual void Flush() {}

    virtual uint16_t GetScreenWidth()
    {
        return width_;
    }

    virtual uint16_t GetScreenHeight()
    {
        return height_;
    }

    static BaseGfxEngine* GetInstance()
    {
        return baseEngine_;
    }

    static void InitGfxEngine(BaseGfxEngine* gfxEngine = nullptr)
    {
        if (gfxEngine == nullptr) {
            static BaseGfxEngine localGfxEngine;
            baseEngine_ = &localGfxEngine;
            return;
        }
        baseEngine_ = gfxEngine;
    }
protected:
    static BaseGfxEngine* baseEngine_;
    uint16_t width_ = HORIZONTAL_RESOLUTION;
    uint16_t height_ = VERTICAL_RESOLUTION;
};
}

#endif // GRAPHIC_LITE_GFX_ENGINE_MANAGER_H