draw_utils.cpp 72.5 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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.
 */

#include "draw/draw_utils.h"
#include "draw/draw_triangle.h"
N
niulihua 已提交
18
#include "engines/gfx/gfx_engine_manager.h"
M
mamingshuai 已提交
19 20
#include "font/ui_font.h"
#include "font/ui_font_header.h"
Z
zhangguyuan 已提交
21 22 23
#include "gfx_utils/color.h"
#include "gfx_utils/graphic_log.h"
#include "gfx_utils/graphic_math.h"
M
mamingshuai 已提交
24 25 26 27 28 29 30 31
#include "graphic_performance.h"
#include "securec.h"

#ifdef ARM_NEON_OPT
#include "graphic_neon_pipeline.h"
#include "graphic_neon_utils.h"
#endif

G
guyuanzhang 已提交
32
#if ENABLE_ARM_MATH
M
mamingshuai 已提交
33 34 35 36 37
#include "arm_math.h"
#endif

namespace OHOS {
// Preprocess operation for draw
N
niulihua 已提交
38
#define DRAW_UTILS_PREPROCESS(gfxBufferInfo, opa)                                                   \
M
mamingshuai 已提交
39 40 41
    if ((opa) == OPA_TRANSPARENT) {                                                  \
        return;                                                                      \
    }                                                                                \
N
niulihua 已提交
42
    uint8_t* screenBuffer = static_cast<uint8_t*>(gfxBufferInfo.virAddr);           \
M
mamingshuai 已提交
43 44 45
    if (screenBuffer == nullptr) {                                                   \
        return;                                                                      \
    }                                                                                \
N
niulihua 已提交
46
    ColorMode bufferMode = gfxBufferInfo.mode;                                      \
M
mamingshuai 已提交
47
    uint8_t bufferPxSize = GetByteSizeByColorMode(bufferMode);                       \
N
niulihua 已提交
48
    uint16_t screenBufferWidth = gfxBufferInfo.width;
M
mamingshuai 已提交
49 50 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

/* cover mode, src alpha is 255 */
#define COLOR_FILL_COVER(d, dm, r2, g2, b2, sm)               \
    if ((dm) == ARGB8888) {                                   \
        reinterpret_cast<Color32*>(d)->alpha = OPA_OPAQUE;    \
        if (sm == RGB565) {                                   \
            reinterpret_cast<Color32*>(d)->red = (r2) << 3;   \
            reinterpret_cast<Color32*>(d)->green = (g2) << 2; \
            reinterpret_cast<Color32*>(d)->blue = (b2) << 3;  \
        } else {                                              \
            reinterpret_cast<Color32*>(d)->red = (r2);        \
            reinterpret_cast<Color32*>(d)->green = (g2);      \
            reinterpret_cast<Color32*>(d)->blue = (b2);       \
        }                                                     \
    } else if ((dm) == RGB888) {                              \
        if (sm == RGB565) {                                   \
            reinterpret_cast<Color24*>(d)->red = (r2) << 3;   \
            reinterpret_cast<Color24*>(d)->green = (g2) << 2; \
            reinterpret_cast<Color24*>(d)->blue = (b2) << 3;  \
        } else {                                              \
            reinterpret_cast<Color24*>(d)->red = (r2);        \
            reinterpret_cast<Color24*>(d)->green = (g2);      \
            reinterpret_cast<Color24*>(d)->blue = (b2);       \
        }                                                     \
    } else if ((dm) == RGB565) {                              \
        if ((sm) == ARGB8888 || (sm) == RGB888) {             \
            reinterpret_cast<Color16*>(d)->red = (r2) >> 3;   \
            reinterpret_cast<Color16*>(d)->green = (g2) >> 2; \
            reinterpret_cast<Color16*>(d)->blue = (b2) >> 3;  \
        } else {                                              \
            reinterpret_cast<Color16*>(d)->red = (r2);        \
            reinterpret_cast<Color16*>(d)->green = (g2);      \
            reinterpret_cast<Color16*>(d)->blue = (b2);       \
        }                                                     \
    } else {                                                  \
        ASSERT(0);                                            \
    }

#define COLOR_BLEND_RGBA(r1, g1, b1, a1, r2, g2, b2, a2)  \
    const float A1 = static_cast<float>(a1) / OPA_OPAQUE; \
    const float A2 = static_cast<float>(a2) / OPA_OPAQUE; \
    const float a = 1 - (1 - A1) * (1 - A2);              \
    (r1) = (A2 * (r2) + (1 - A2) * A1 * (r1)) / a;        \
    (g1) = (A2 * (g2) + (1 - A2) * A1 * (g1)) / a;        \
    (b1) = (A2 * (b2) + (1 - A2) * A1 * (b1)) / a;        \
    (a1) = a * OPA_OPAQUE;

#define COLOR_BLEND_RGB(r1, g1, b1, r2, g2, b2, a2)                                    \
    (r1) = (((r2) * (a2)) / OPA_OPAQUE) + (((r1) * (OPA_OPAQUE - (a2))) / OPA_OPAQUE); \
    (g1) = (((g2) * (a2)) / OPA_OPAQUE) + (((g1) * (OPA_OPAQUE - (a2))) / OPA_OPAQUE); \
    (b1) = (((b2) * (a2)) / OPA_OPAQUE) + (((b1) * (OPA_OPAQUE - (a2))) / OPA_OPAQUE);

// 565
#define COLOR_FILL_BLEND(d, dm, s, sm, a)                                                                           \
    if ((dm) == ARGB8888) {                                                                                         \
        Color32* p = reinterpret_cast<Color32*>(d);                                                                 \
        if ((sm) == ARGB8888) {                                                                                     \
            Color32* sTmp = reinterpret_cast<Color32*>(s);                                                          \
            uint8_t alpha = (sTmp->alpha * (a)) / OPA_OPAQUE;                                                       \
            COLOR_BLEND_RGBA(p->red, p->green, p->blue, p->alpha, sTmp->red, sTmp->green, sTmp->blue, alpha);       \
        } else if ((sm) == RGB888) {                                                                                \
            Color24* sTmp = reinterpret_cast<Color24*>(s);                                                          \
            COLOR_BLEND_RGBA(p->red, p->green, p->blue, p->alpha, sTmp->red, sTmp->green, sTmp->blue, a);           \
        } else if ((sm) == RGB565) {                                                                                \
            Color16* sTmp = reinterpret_cast<Color16*>(s);                                                          \
            COLOR_BLEND_RGBA(p->red, p->green, p->blue, p->alpha, (sTmp->red) << 3, (sTmp->green) << 2,             \
                             (sTmp->blue) << 3, a);                                                                 \
        }                                                                                                           \
    } else if ((dm) == RGB888) {                                                                                    \
        Color24* p = reinterpret_cast<Color24*>(d);                                                                 \
        if ((sm) == ARGB8888) {                                                                                     \
            Color32* sTmp = reinterpret_cast<Color32*>(s);                                                          \
            uint8_t alpha = (sTmp->alpha * (a)) / OPA_OPAQUE;                                                       \
            COLOR_BLEND_RGB(p->red, p->green, p->blue, sTmp->red, sTmp->green, sTmp->blue, alpha);                  \
        } else if ((sm) == RGB888) {                                                                                \
            Color24* sTmp = reinterpret_cast<Color24*>(s);                                                          \
            COLOR_BLEND_RGB(p->red, p->green, p->blue, sTmp->red, sTmp->green, sTmp->blue, a);                      \
        } else if ((sm) == RGB565) {                                                                                \
            Color16* sTmp = reinterpret_cast<Color16*>(s);                                                          \
            COLOR_BLEND_RGB(p->red, p->green, p->blue, (sTmp->red) << 3, (sTmp->green) << 2, (sTmp->blue) << 3, a); \
        }                                                                                                           \
    } else if ((dm) == RGB565) {                                                                                    \
        Color16* p = reinterpret_cast<Color16*>(d);                                                                 \
        if ((sm) == ARGB8888) {                                                                                     \
            Color32* sTmp = reinterpret_cast<Color32*>(s);                                                          \
            uint8_t alpha = (sTmp->alpha * (a)) / OPA_OPAQUE;                                                       \
            COLOR_BLEND_RGB(p->red, p->green, p->blue, (sTmp->red) >> 3, (sTmp->green) >> 2, (sTmp->blue) >> 3,     \
                            alpha);                                                                                 \
        } else if ((sm) == RGB888) {                                                                                \
            Color24* sTmp = reinterpret_cast<Color24*>(s);                                                          \
            COLOR_BLEND_RGB(p->red, p->green, p->blue, (sTmp->red) >> 3, (sTmp->green) >> 2, (sTmp->blue) >> 3, a); \
        } else if ((sm) == RGB565) {                                                                                \
            Color16* sTmp = reinterpret_cast<Color16*>(s);                                                          \
            COLOR_BLEND_RGB(p->red, p->green, p->blue, sTmp->red, sTmp->green, sTmp->blue, a);                      \
        }                                                                                                           \
    } else {                                                                                                        \
        ASSERT(0);                                                                                                  \
    }

#ifdef VERSION_STANDARD
const int16_t HARDWARE_ACC_SIZE_LIMIT = 50 * 50;
#endif

namespace {
static constexpr uint8_t OPACITY_STEP_A1 = 255;
static constexpr uint8_t OPACITY_STEP_A2 = 85;
static constexpr uint8_t OPACITY_STEP_A4 = 17;
} // namespace

TriangleEdge::TriangleEdge(int16_t x1, int16_t y1, int16_t x2, int16_t y2)
{
L
liqiang 已提交
160 161 162 163
    curX = FO_TRANS_INTEGER_TO_FIXED(x1);
    curY = FO_TRANS_INTEGER_TO_FIXED(y1);
    du = FO_TRANS_INTEGER_TO_FIXED(x2 - x1);
    dv = FO_TRANS_INTEGER_TO_FIXED(y2 - y1);
M
mamingshuai 已提交
164 165 166 167
}

TriangleEdge::~TriangleEdge() {}

Z
zhdengc 已提交
168 169 170 171 172 173
DrawUtils* DrawUtils::GetInstance()
{
    static DrawUtils instance;
    return &instance;
}

N
niulihua 已提交
174 175
void DrawUtils::DrawColorAreaBySides(BufferInfo& gfxDstBuffer,
                                     const Rect& mask,
M
mamingshuai 已提交
176 177 178 179 180
                                     const ColorType& color,
                                     OpacityType opa,
                                     const EdgeSides& sides) const
{
    Rect area(sides.left, sides.top, sides.right, sides.bottom);
N
niulihua 已提交
181
    DrawUtils::GetInstance()->DrawColorArea(gfxDstBuffer, area, mask, color, opa);
M
mamingshuai 已提交
182 183
}

N
niulihua 已提交
184 185 186 187 188
void DrawUtils::DrawColorArea(BufferInfo& gfxDstBuffer,
                              const Rect& area,
                              const Rect& mask,
                              const ColorType& color,
                              OpacityType opa) const
M
mamingshuai 已提交
189
{
N
niulihua 已提交
190
    DRAW_UTILS_PREPROCESS(gfxDstBuffer, opa);
M
mamingshuai 已提交
191 192 193 194
    Rect maskedArea;
    if (!maskedArea.Intersect(area, mask)) {
        return;
    }
N
niulihua 已提交
195 196

    BaseGfxEngine::GetInstance()->Fill(gfxDstBuffer, maskedArea, color, opa);
M
mamingshuai 已提交
197 198 199 200 201
}

uint8_t DrawUtils::GetPxSizeByColorMode(uint8_t colorMode)
{
    switch (colorMode) {
W
wanngtiantian 已提交
202
        case TSC:
M
mamingshuai 已提交
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
        case ARGB8888:
            return 32; // 32: 32 bit
        case RGB888:
            return 24; // 24: 24 bit
        case RGB565:
        case ARGB1555:
        case ARGB4444:
            return 16; // 16: 16 bit
        case L1:
        case A1:
            return 1; // 1: 1 bit
        case L2:
        case A2:
            return 2; // 2: 2 bit
        case L4:
        case A4:
            return 4; // 4: 4 bit
        case L8:
        case A8:
            return 8; // 8: 8 bit
        default:
            return 0;
    }
}

uint8_t DrawUtils::GetByteSizeByColorMode(uint8_t colorMode)
{
    switch (colorMode) {
        case ARGB8888:
            return 4; // 4: 4 Byte
        case RGB888:
            return 3; // 3: 3 Byte
        case RGB565:
        case ARGB1555:
        case ARGB4444:
            return 2; // 2: 2 Byte
        default:
            return 0;
    }
}

W
wanngtiantian 已提交
244
LutColorMode DrawUtils::GetLutColorModeBySize(uint8_t size)
M
mamingshuai 已提交
245
{
W
wanngtiantian 已提交
246 247 248 249 250 251 252 253 254
    switch (size) {
        case 2: // 2: 2 Byte
            return LUT_RGB565;
        case 3: // 3: 3 Byte
            return LUT_RGB888;
        case 4: // 4: 4 Byte
            return LUT_ARGB8888;
        default:
            return LUT_UNKNOW;
M
mamingshuai 已提交
255 256 257
    }
}

N
niulihua 已提交
258 259 260 261 262 263
void DrawUtils::DrawPixel(BufferInfo& gfxDstBuffer,
                          int16_t x,
                          int16_t y,
                          const Rect& mask,
                          const ColorType& color,
                          OpacityType opa) const
M
mamingshuai 已提交
264 265 266 267 268
{
    if ((x < mask.GetLeft()) || (x > mask.GetRight()) || (y < mask.GetTop()) || (y > mask.GetBottom())) {
        return;
    }

N
niulihua 已提交
269
    DRAW_UTILS_PREPROCESS(gfxDstBuffer, opa);
M
mamingshuai 已提交
270 271 272 273 274 275 276 277

    Color32 fillColor;
    fillColor.full = Color::ColorTo32(color);

    screenBuffer += (y * screenBufferWidth + x) * bufferPxSize;
    COLOR_FILL_BLEND(screenBuffer, bufferMode, &fillColor, ARGB8888, opa);
}

N
niulihua 已提交
278
void DrawUtils::DrawLetter(BufferInfo& gfxDstBuffer, const LabelLetterInfo& letterInfo) const
M
mamingshuai 已提交
279 280 281 282 283
{
    OpacityType opa = letterInfo.opa;
    Color32 fillColor;
    fillColor.full = Color::ColorTo32(letterInfo.color);

N
niulihua 已提交
284
    DRAW_UTILS_PREPROCESS(gfxDstBuffer, opa);
M
mamingshuai 已提交
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
    UIFont* fontEngine = UIFont::GetInstance();
    FontHeader head;
    GlyphNode node;
    if (fontEngine->GetCurrentFontHeader(head) != 0) {
        return;
    }

    const uint8_t* fontMap = fontEngine->GetBitmap(letterInfo.letter, node, letterInfo.shapingId);
    if (fontMap == nullptr) {
        return;
    }
    uint16_t letterW = node.cols;
    uint16_t letterH = node.rows;
    uint8_t opacityMask;
    int16_t posX;
    int16_t posY = letterInfo.pos.y + letterInfo.fontSize - node.top - letterInfo.offsetY;
    uint8_t fontWeight = fontEngine->GetFontWeight(letterInfo.fontId);
    uint8_t colorMode = 0;
    uint8_t opacityStep = 1;
    switch (fontWeight) {
        case FONT_WEIGHT_1:
            opacityStep = OPACITY_STEP_A1;
            opacityMask = 0x01;
            colorMode = A1;
            break;
        case FONT_WEIGHT_2:
            opacityStep = OPACITY_STEP_A2;
            opacityMask = 0x03;
            colorMode = A2;
            break;
        case FONT_WEIGHT_4:
            opacityStep = OPACITY_STEP_A4;
            opacityMask = 0x0F;
            colorMode = A4;
            break;
        case FONT_WEIGHT_8:
            opacityMask = 0xFF;
            colorMode = A8;
            break;
        default:
            return;
    }

    if (letterInfo.direct == TEXT_DIRECT_RTL) {
        /* RTL */
        posX = letterInfo.pos.x - node.advance + node.left + letterInfo.offsetX;
    } else {
        /* LTR */
        posX = letterInfo.pos.x + node.left + letterInfo.offsetX;
    }

    if ((posX + letterW < letterInfo.mask.GetLeft()) || (posX > letterInfo.mask.GetRight()) ||
        (posY + letterH < letterInfo.mask.GetTop()) || (posY > letterInfo.mask.GetBottom())) {
        return;
    }

    uint16_t rowStart = (posY >= letterInfo.mask.GetTop()) ? 0 : (letterInfo.mask.GetTop() - posY);
    uint16_t rowEnd =
        (posY + letterH <= letterInfo.mask.GetBottom()) ? letterH : (letterInfo.mask.GetBottom() - posY + 1);
    uint16_t colStart = (posX >= letterInfo.mask.GetLeft()) ? 0 : (letterInfo.mask.GetLeft() - posX);
    uint16_t colEnd =
        (posX + letterW <= letterInfo.mask.GetRight()) ? letterW : (letterInfo.mask.GetRight() - posX + 1);

    uint8_t letterWidthInByte = (letterW * fontWeight) >> SHIFT_3;
W
wanngtiantian 已提交
349
    if ((letterW * fontWeight) & 0x7) { // 0x7 : less than 1 byte is counted as 1 byte
M
mamingshuai 已提交
350 351 352 353 354 355 356 357
        letterWidthInByte++;
    }

    int16_t dstPosX = posX + colStart;
    int16_t dstPosY = posY + rowStart;

#if ENABLE_HARDWARE_ACCELERATION && ENABLE_HARDWARE_ACCELERATION_FOR_TEXT
    Rect srcRect(colStart, rowStart, colEnd - 1, rowEnd - 1);
N
niulihua 已提交
358 359 360 361 362 363 364 365 366 367 368 369 370 371
    BufferInfo src;
    src.rect = srcRect;
    src.virAddr = static_cast<void*>(const_cast<uint8_t*>(fontMap));
    src.stride = letterWidthInByte;
    src.mode = static_cast<ColorMode>(colorMode);
    src.color = Color::ColorTo32(letterInfo.color);

    Point dstPos = {dstPosX, dstPosY};
    BlendOption blendOption;
    blendOption.opacity = opa;

    Rect subRect(dstPosX, dstPosY, letterW, letterH);
    BaseGfxEngine::GetInstance()->Blit(*gfxDstBuffer, dstPos, src, subRect, blendOption);
    return;
M
mamingshuai 已提交
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
#endif

    screenBuffer += ((dstPosY * screenBufferWidth) + dstPosX) * bufferPxSize;
    fontMap += (rowStart * letterWidthInByte) + ((colStart * fontWeight) >> SHIFT_3);

    uint8_t offsetInFont = (colStart * fontWeight) % FONT_WEIGHT_8;
    int16_t temp = (colEnd - colStart) * fontWeight - FONT_WEIGHT_8 + offsetInFont;
    if (temp < 0) {
        temp = 0;
    }
    int16_t validWidthInByte = temp / FONT_WEIGHT_8 + 1;
    if (temp % FONT_WEIGHT_8 != 0) {
        validWidthInByte++;
    }
    for (int16_t i = rowStart; i < rowEnd; i++) {
        int16_t col = colStart;
        uint8_t tempOffset = offsetInFont;
        uint8_t tempFontByte = (*fontMap++) >> offsetInFont;
        while (col < colEnd) {
            while ((tempOffset < FONT_WEIGHT_8) && (col < colEnd)) {
                uint8_t validOpacity = tempFontByte & opacityMask;
                if (validOpacity != 0) {
                    validOpacity *= opacityStep;
                    if (opa != OPA_OPAQUE) {
                        validOpacity =
                            static_cast<OpacityType>((static_cast<uint16_t>(validOpacity) * opa) >> FONT_WEIGHT_8);
                    }
                    COLOR_FILL_BLEND(screenBuffer, bufferMode, &fillColor, ARGB8888, validOpacity);
                }
                screenBuffer += bufferPxSize;
                tempFontByte = tempFontByte >> fontWeight;
                tempOffset += fontWeight;
                col++;
            }
            tempOffset = 0;
            tempFontByte = *(fontMap++);
        }
        fontMap += (letterWidthInByte)-validWidthInByte - 1;
        screenBuffer += (screenBufferWidth - (colEnd - colStart)) * bufferPxSize;
    }
}

N
niulihua 已提交
414 415
void DrawUtils::DrawImage(BufferInfo& gfxDstBuffer,
                          const Rect& area,
M
mamingshuai 已提交
416 417 418
                          const Rect& mask,
                          const uint8_t* image,
                          OpacityType opa,
W
wanngtiantian 已提交
419 420 421
                          uint8_t pxBitSize,
                          ColorMode colorMode,
                          LutColorMode LutColorMode) const
M
mamingshuai 已提交
422 423 424 425
{
    if (image == nullptr) {
        return;
    }
N
niulihua 已提交
426
    DRAW_UTILS_PREPROCESS(gfxDstBuffer, opa);
M
mamingshuai 已提交
427
    Rect maskedArea;
J
jsjzju 已提交
428
    if (!maskedArea.Intersect(area, mask)) {
M
mamingshuai 已提交
429 430 431
        return;
    }
    int16_t mapWidth = area.GetWidth();
J
jsjzju 已提交
432 433
    int16_t imageX = maskedArea.GetLeft() - area.GetLeft();
    int16_t imageY = maskedArea.GetTop() - area.GetTop();
W
wanngtiantian 已提交
434 435 436
    uint32_t imageWidthInByte = (static_cast<uint32_t>(mapWidth) * pxBitSize) >> SHIFT_3;
    if ((mapWidth * pxBitSize) & 0x7) { // 0x7 : less than 1 byte is counted as 1 byte
        imageWidthInByte++;
M
mamingshuai 已提交
437 438
    }

N
niulihua 已提交
439 440 441 442 443 444 445
    BufferInfo src;
    src.rect = {
        imageX,
        imageY,
        static_cast<int16_t>(imageX + maskedArea.GetWidth() - 1),
        static_cast<int16_t>(imageY + maskedArea.GetHeight() - 1)
    };
M
mamingshuai 已提交
446

N
niulihua 已提交
447 448 449 450 451 452 453 454 455
    src.virAddr = static_cast<void*>(const_cast<uint8_t*>(image));
    src.stride = imageWidthInByte;
    src.mode = colorMode;
    src.color = 0;

    Point dstPos = {maskedArea.GetLeft(), maskedArea.GetTop()};
    BlendOption blendOption;
    blendOption.opacity = opa;
    BaseGfxEngine::GetInstance()->Blit(gfxDstBuffer, dstPos, src, maskedArea, blendOption);
M
mamingshuai 已提交
456 457
}

N
niulihua 已提交
458 459
void DrawUtils::FillAreaWithSoftWare(BufferInfo& gfxDstBuffer,
                                     const Rect& fillArea,
M
mamingshuai 已提交
460 461 462
                                     const ColorType& color,
                                     const OpacityType& opa) const
{
N
niulihua 已提交
463
    ColorMode mode = gfxDstBuffer.mode;
N
niulihua 已提交
464
    uint8_t destByteSize = GetByteSizeByColorMode(mode);
N
niulihua 已提交
465
    int16_t destWidth = gfxDstBuffer.width;
M
mamingshuai 已提交
466 467 468
    int32_t halBufferDeltaByteLen = static_cast<int32_t>(destWidth) * destByteSize;
    int16_t width = fillArea.GetWidth();
    int16_t height = fillArea.GetHeight();
N
niulihua 已提交
469
    uint8_t* dest = static_cast<uint8_t*>(gfxDstBuffer.virAddr);
M
mamingshuai 已提交
470 471
    int32_t offset = static_cast<int32_t>(fillArea.GetTop()) * destWidth + fillArea.GetLeft();
    dest += offset * destByteSize;
N
niulihua 已提交
472 473

    int32_t dstMaxSize = (gfxDstBuffer.width * gfxDstBuffer.height - offset) * destByteSize;
M
mamingshuai 已提交
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
    Color32 fillColor;
    fillColor.full = Color::ColorTo32(color);
    uint8_t* dstTmp = nullptr;

    if ((fillColor.alpha == OPA_TRANSPARENT) || (opa == OPA_TRANSPARENT)) {
        return;
    }
    /* cover mode */
    if ((opa == OPA_OPAQUE) && (fillColor.alpha == OPA_OPAQUE)) {
        for (int16_t col = 0; col < width; ++col) {
            dstTmp = dest + (col * destByteSize);
            COLOR_FILL_COVER(dstTmp, mode, fillColor.red, fillColor.green, fillColor.blue, ARGB8888);
        }
        uint8_t* memStart = dest;
        int32_t memSize = static_cast<int32_t>(width) * destByteSize;
N
niulihua 已提交
489
        dest += halBufferDeltaByteLen;
M
mamingshuai 已提交
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
        dstMaxSize -= halBufferDeltaByteLen;
        for (int16_t row = 1; row < height; ++row) {
#ifdef ARM_NEON_OPT
            {
                DEBUG_PERFORMANCE_TRACE("memcpy_neon");
                NeonMemcpy(dest, dstMaxSize, memStart, memSize);
            }
#else
            {
                DEBUG_PERFORMANCE_TRACE("memcpy");
                if (memcpy_s(dest, dstMaxSize, memStart, memSize) != EOK) {
                    GRAPHIC_LOGE("DrawUtils::FillAreaWithSoftWare memcpy failed!\n");
                    return;
                }
            }
#endif
N
niulihua 已提交
506
            dest += halBufferDeltaByteLen;
M
mamingshuai 已提交
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
            dstMaxSize -= halBufferDeltaByteLen;
        }
    } else {
#ifdef ARM_NEON_OPT
        {
            DEBUG_PERFORMANCE_TRACE("FillAreaWithSoftWare_neon");
            NeonBlendPipeLine pipeLine;
            pipeLine.Construct(mode, ARGB8888, &fillColor, opa);
            int16_t step = NEON_STEP_8 * GetByteSizeByColorMode(mode);
            for (int16_t row = 0; row < height; ++row) {
                uint8_t* buf = dest;
                int16_t tmpWidth = width;
                while (tmpWidth >= NEON_STEP_8) {
                    pipeLine.Invoke(buf);
                    buf += step;
                    tmpWidth -= NEON_STEP_8;
                }
                for (int16_t i = 0; i < tmpWidth; ++i) {
                    COLOR_FILL_BLEND(buf, mode, &fillColor, ARGB8888, opa);
                    buf += destByteSize;
                }
                dest += halBufferDeltaByteLen;
            }
        }
#else
        {
            DEBUG_PERFORMANCE_TRACE("FillAreaWithSoftWare");
            for (int16_t row = 0; row < height; row++) {
                for (int16_t col = 0; col < width; col++) {
                    dstTmp = dest + (col * destByteSize);
                    COLOR_FILL_BLEND(dstTmp, mode, &fillColor, ARGB8888, opa);
                }
                dest += destWidth * destByteSize;
            }
        }
#endif
    }
}

N
niulihua 已提交
546 547
void DrawUtils::BlendWithSoftWare(const uint8_t* src1,
                                  const Rect& srcRect,
M
mamingshuai 已提交
548
                                  uint32_t srcStride,
N
niulihua 已提交
549
                                  uint32_t srcLineNumber,
M
mamingshuai 已提交
550
                                  ColorMode srcMode,
N
niulihua 已提交
551 552 553
                                  uint32_t color,
                                  OpacityType opa,
                                  uint8_t* dst,
M
mamingshuai 已提交
554 555
                                  uint32_t destStride,
                                  ColorMode destMode,
N
niulihua 已提交
556 557
                                  uint32_t x,
                                  uint32_t y) const
M
mamingshuai 已提交
558 559 560
{
    uint8_t destByteSize = GetByteSizeByColorMode(destMode);
    uint8_t srcByteSize = GetByteSizeByColorMode(srcMode);
N
niulihua 已提交
561 562 563 564 565 566 567 568

    uint8_t* dest = dst + destStride * y;
    dest += destByteSize * x;

    uint8_t pxByteSize = GetPxSizeByColorMode(srcMode) >> 3;
    uint8_t* src = const_cast<uint8_t*>(src1) + srcStride * srcRect.GetY() + pxByteSize * srcRect.GetX();
    uint32_t width = srcRect.GetWidth();
    uint32_t height = srcRect.GetHeight();
M
mamingshuai 已提交
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
#ifdef ARM_NEON_OPT
    {
        DEBUG_PERFORMANCE_TRACE("BlendWithSoftWare_neon");
        NeonBlendPipeLine pipeLine;
        pipeLine.Construct(destMode, srcMode);
        int16_t dstStep = NEON_STEP_8 * GetByteSizeByColorMode(destMode);
        int16_t srcStep = NEON_STEP_8 * GetByteSizeByColorMode(srcMode);
        for (uint32_t row = 0; row < height; ++row) {
            uint8_t* dstBuf = dest;
            uint8_t* srcBuf = const_cast<uint8_t*>(src);
            int16_t tmpWidth = width;
            while (tmpWidth >= NEON_STEP_8) {
                pipeLine.Invoke(dstBuf, srcBuf, opa);
                dstBuf += dstStep;
                srcBuf += srcStep;
                tmpWidth -= NEON_STEP_8;
            }
            for (int16_t i = 0; i < tmpWidth; ++i) {
                COLOR_FILL_BLEND(dstBuf, destMode, srcBuf, srcMode, opa);
                dstBuf += destByteSize;
                srcBuf += srcByteSize;
            }
            dest += destStride;
            src += srcStride;
        }
    }
#else
    {
        DEBUG_PERFORMANCE_TRACE("BlendWithSoftWare");
        for (uint32_t row = 0; row < height; ++row) {
            uint8_t* destTmp = dest;
            uint8_t* srcTmp = const_cast<uint8_t*>(src);
            for (uint32_t col = 0; col < width; ++col) {
                COLOR_FILL_BLEND(destTmp, destMode, srcTmp, srcMode, opa);
                destTmp += destByteSize;
                srcTmp += srcByteSize;
            }
            dest += destStride;
            src += srcStride;
        }
    }
#endif
}

void DrawUtils::GetXAxisErrForJunctionLine(bool ignoreJunctionPoint,
                                           bool isRightPart,
L
liqiang 已提交
615 616
                                           int16_t& xMinErr,
                                           int16_t& xMaxErr)
M
mamingshuai 已提交
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
{
    xMinErr = 0;
    xMaxErr = 0;
    if (ignoreJunctionPoint) {
        if (isRightPart) {
            xMinErr = 1;
        } else {
            xMaxErr = -1;
        }
    }
}

void DrawUtils::GetTransformInitState(const TransformMap& transMap,
                                      const Point& position,
                                      const Rect& trans,
                                      TransformInitState& init)
{
    int16_t x = trans.GetLeft();
    int16_t y = trans.GetTop();

L
liqiang 已提交
637 638 639 640
    init.duHorizon = FO_TRANS_FLOAT_TO_FIXED(transMap.invMatrix_.GetData()[0]);
    init.dvHorizon = FO_TRANS_FLOAT_TO_FIXED(transMap.invMatrix_.GetData()[1]);
    init.duVertical = FO_TRANS_FLOAT_TO_FIXED(transMap.invMatrix_.GetData()[3]); // 3:RSxy
    init.dvVertical = FO_TRANS_FLOAT_TO_FIXED(transMap.invMatrix_.GetData()[4]); // 4:RSyy
M
mamingshuai 已提交
641 642

    init.verticalU = (x - position.x) * init.duHorizon + (y - position.y) * init.duVertical +
L
liqiang 已提交
643
                     FO_TRANS_FLOAT_TO_FIXED(transMap.invMatrix_.GetData()[6]); // 6:TRSx
M
mamingshuai 已提交
644
    init.verticalV = (x - position.x) * init.dvHorizon + (y - position.y) * init.dvVertical +
L
liqiang 已提交
645
                     FO_TRANS_FLOAT_TO_FIXED(transMap.invMatrix_.GetData()[7]); // 7:TRSy
M
mamingshuai 已提交
646 647 648 649
}

inline void DrawUtils::StepToNextLine(TriangleEdge& edge1, TriangleEdge& edge2)
{
L
liqiang 已提交
650 651 652 653
    edge1.curY += FIXED_NUM_1;
    edge2.curY += FIXED_NUM_1;
    edge1.curX += FO_DIV(edge1.du, edge1.dv);
    edge2.curX += FO_DIV(edge2.du, edge2.dv);
M
mamingshuai 已提交
654 655
}

N
niulihua 已提交
656
void DrawUtils::DrawTriangleAlphaBilinear(const TriangleScanInfo& in, const ColorMode bufferMode)
M
mamingshuai 已提交
657
{
L
liqiang 已提交
658 659
    int16_t maskLeft = in.mask.GetLeft();
    int16_t maskRight = in.mask.GetRight();
M
mamingshuai 已提交
660
    for (int16_t y = in.yMin; y <= in.yMax; y++) {
L
liqiang 已提交
661 662 663 664 665
        int16_t tempV = FO_TO_INTEGER(in.edge1.curX);
        int16_t xMin = MATH_MAX(tempV, maskLeft);
        tempV = FO_TO_INTEGER(in.edge2.curX);
        int16_t xMax = MATH_MIN(tempV, maskRight);
        int16_t diffX = xMin - FO_TO_INTEGER(in.edge1.curX);
M
mamingshuai 已提交
666 667 668
        in.init.verticalU += in.init.duHorizon * diffX;
        in.init.verticalV += in.init.dvHorizon * diffX;
        uint8_t* screenBuffer = in.screenBuffer + (y * in.screenBufferWidth + xMin) * in.bufferPxSize;
L
liqiang 已提交
669 670 671 672
        // parameters below are Q15 fixed-point number
        int32_t u = in.init.verticalU;
        int32_t v = in.init.verticalV;
        // parameters above are Q15 fixed-point number
M
mamingshuai 已提交
673
        for (int16_t x = xMin; x <= xMax; x++) {
L
liqiang 已提交
674 675 676 677 678
            int16_t intU = FO_TO_INTEGER(u);
            int16_t intV = FO_TO_INTEGER(v);
            if ((u >= 0) && (intU < (in.info.header.width - 1)) && (v >= 0) && (intV < (in.info.header.height - 1))) {
                int16_t intUPlus1 = intU + 1;
                int16_t intVPlus1 = intV + 1;
M
mamingshuai 已提交
679 680 681 682
                OpacityType p1 = GetPxAlphaForAlphaImg(in.info, {intU, intV});
                OpacityType p2 = GetPxAlphaForAlphaImg(in.info, {intUPlus1, intV});
                OpacityType p3 = GetPxAlphaForAlphaImg(in.info, {intU, intVPlus1});
                OpacityType p4 = GetPxAlphaForAlphaImg(in.info, {intUPlus1, intVPlus1});
L
liqiang 已提交
683 684 685 686 687 688 689 690 691 692
                // parameters below are Q15 fixed-point number
                int32_t decU = FO_DECIMAL(u);
                int32_t decV = FO_DECIMAL(v);
                int32_t decUMinus1 = FIXED_NUM_1 - decU;
                int32_t decVMinus1 = FIXED_NUM_1 - decV;
                int32_t w1 = FO_MUL(decUMinus1, decVMinus1);
                int32_t w2 = FO_MUL(decU, decVMinus1);
                int32_t w3 = FO_MUL(decUMinus1, decV);
                int32_t w4 = FO_MUL(decU, decV);
                // parameters above are Q15 fixed-point number
G
guyuanzhang 已提交
693
#if ENABLE_ARM_MATH
M
mamingshuai 已提交
694
                const int32_t outA = __SMUAD(p1, w1) + __SMUAD(p2, w2) + __SMUAD(p3, w3) + __SMUAD(p4, w4);
G
guyuanzhang 已提交
695 696
#else
                const int32_t outA = p1 * w1 + p2 * w2 + p3 * w3 + p4 * w4;
M
mamingshuai 已提交
697 698 699
#endif
                Color32 result;
                result.full = Color::ColorTo32(in.color);
L
liqiang 已提交
700
                result.alpha = FO_TO_INTEGER(outA);
M
mamingshuai 已提交
701 702 703 704 705 706 707 708 709
                COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, ARGB8888, in.opaScale);
            }
            u += in.init.duHorizon;
            v += in.init.dvHorizon;
            screenBuffer += in.bufferPxSize;
        }
        StepToNextLine(in.edge1, in.edge2);
        in.init.verticalU += in.init.duVertical;
        in.init.verticalV += in.init.dvVertical;
L
liqiang 已提交
710
        int16_t deltaX = FO_TO_INTEGER(in.edge1.curX) - xMin;
M
mamingshuai 已提交
711 712 713 714 715
        in.init.verticalU += in.init.duHorizon * deltaX;
        in.init.verticalV += in.init.dvHorizon * deltaX;
    }
}

N
niulihua 已提交
716
void DrawUtils::DrawTriangleTrueColorBilinear565(const TriangleScanInfo& in, const ColorMode bufferMode)
M
mamingshuai 已提交
717 718
{
    for (int16_t y = in.yMin; y <= in.yMax; y++) {
L
liqiang 已提交
719 720
        int16_t xMin = FO_TO_INTEGER(in.edge1.curX);
        int16_t xMax = FO_TO_INTEGER(in.edge2.curX);
M
mamingshuai 已提交
721
        uint8_t* screenBuffer = in.screenBuffer + (y * in.screenBufferWidth + xMin) * in.bufferPxSize;
L
liqiang 已提交
722 723 724 725
        // parameters below are Q15 fixed-point number
        int32_t u = in.init.verticalU;
        int32_t v = in.init.verticalV;
        // parameters above are Q15 fixed-point number
M
mamingshuai 已提交
726
        for (int16_t x = xMin; x <= xMax; x++) {
L
liqiang 已提交
727 728 729
            int16_t intU = FO_TO_INTEGER(u);
            int16_t intV = FO_TO_INTEGER(v);
            if ((u >= 0) && (intU < (in.info.header.width - 1)) && (v >= 0) && (intV < (in.info.header.height - 1))) {
G
guyuanzhang 已提交
730
#if ENABLE_ARM_MATH
M
mamingshuai 已提交
731 732 733
                uint32_t val1 = __SMUAD(intV, in.srcLineWidth);
                uint32_t val2 = __SMUAD(intU, in.pixelSize);
                uint32_t px1 = val1 + val2;
G
guyuanzhang 已提交
734 735
#else
                uint32_t px1 = intV * in.srcLineWidth + intU * in.pixelSize;
M
mamingshuai 已提交
736 737 738 739 740 741 742
#endif
                uint8_t* imgHead = const_cast<uint8_t*>(in.info.data);
                const Color16 p1 = *(reinterpret_cast<Color16*>(&imgHead[px1]));
                const Color16 p2 = *(reinterpret_cast<Color16*>(&imgHead[px1 + in.pixelSize]));
                const Color16 p3 = *(reinterpret_cast<Color16*>(&imgHead[px1 + in.srcLineWidth]));
                const Color16 p4 = *(reinterpret_cast<Color16*>(&imgHead[px1 + in.srcLineWidth + in.pixelSize]));

L
liqiang 已提交
743 744 745 746 747 748 749 750 751 752
                // parameters below are Q15 fixed-point number
                int32_t decU = FO_DECIMAL(u);
                int32_t decV = FO_DECIMAL(v);
                int32_t decUMinus1 = FIXED_NUM_1 - decU;
                int32_t decVMinus1 = FIXED_NUM_1 - decV;
                int32_t w1 = FO_MUL(decUMinus1, decVMinus1);
                int32_t w2 = FO_MUL(decU, decVMinus1);
                int32_t w3 = FO_MUL(decUMinus1, decV);
                int32_t w4 = FO_MUL(decU, decV);
                // parameters above are Q15 fixed-point number
G
guyuanzhang 已提交
753
#if ENABLE_ARM_MATH
M
mamingshuai 已提交
754 755 756 757 758 759
                const int32_t outR =
                    __SMUAD(p1.red, w1) + __SMUAD(p2.red, w2) + __SMUAD(p3.red, w3) + __SMUAD(p4.red, w4);
                const int32_t outG =
                    __SMUAD(p1.green, w1) + __SMUAD(p2.green, w2) + __SMUAD(p3.green, w3) + __SMUAD(p4.green, w4);
                const int32_t outB =
                    __SMUAD(p1.blue, w1) + __SMUAD(p2.blue, w2) + __SMUAD(p3.blue, w3) + __SMUAD(p4.blue, w4);
G
guyuanzhang 已提交
760 761 762 763
#else
                const int32_t outR = p1.red * w1 + p2.red * w2 + p3.red * w3 + p4.red * w4;
                const int32_t outG = p1.green * w1 + p2.green * w2 + p3.green * w3 + p4.green * w4;
                const int32_t outB = p1.blue * w1 + p2.blue * w2 + p3.blue * w3 + p4.blue * w4;
M
mamingshuai 已提交
764 765 766
#endif

                Color16 result;
L
liqiang 已提交
767 768 769
                result.red = static_cast<uint8_t>(outR >>15); // 15: shift 15 bit right to convert fixed to int
                result.green = static_cast<uint8_t>(outG >> 15); // 15: shift 15 bit right to convert fixed to int
                result.blue = static_cast<uint8_t>(outB >> 15);  // 15: shift 15 bit right to convert fixed to int
M
mamingshuai 已提交
770 771 772 773 774 775 776 777 778 779 780 781 782
                if (in.opaScale == OPA_OPAQUE) {
                    COLOR_FILL_COVER(screenBuffer, bufferMode, result.red, result.green, result.blue, RGB565);
                } else {
                    COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, RGB565, in.opaScale);
                }
            }
            u += in.init.duHorizon;
            v += in.init.dvHorizon;
            screenBuffer += in.bufferPxSize;
        }
        StepToNextLine(in.edge1, in.edge2);
        in.init.verticalU += in.init.duVertical;
        in.init.verticalV += in.init.dvVertical;
L
liqiang 已提交
783
        int16_t deltaX = FO_TO_INTEGER(in.edge1.curX) - xMin;
M
mamingshuai 已提交
784 785 786 787 788
        in.init.verticalU += in.init.duHorizon * deltaX;
        in.init.verticalV += in.init.dvHorizon * deltaX;
    }
}

N
niulihua 已提交
789
void DrawUtils::DrawTriangleTrueColorBilinear888(const TriangleScanInfo& in, const ColorMode bufferMode)
M
mamingshuai 已提交
790 791
{
    for (int16_t y = in.yMin; y <= in.yMax; y++) {
L
liqiang 已提交
792 793
        int16_t xMin = FO_TO_INTEGER(in.edge1.curX);
        int16_t xMax = FO_TO_INTEGER(in.edge2.curX);
M
mamingshuai 已提交
794
        uint8_t* screenBuffer = in.screenBuffer + (y * in.screenBufferWidth + xMin) * in.bufferPxSize;
L
liqiang 已提交
795 796 797 798
        // parameters below are Q15 fixed-point number
        int32_t u = in.init.verticalU;
        int32_t v = in.init.verticalV;
        // parameters above are Q15 fixed-point number
M
mamingshuai 已提交
799
        for (int16_t x = xMin; x <= xMax; x++) {
L
liqiang 已提交
800 801
            int16_t intU = FO_TO_INTEGER(u);
            int16_t intV = FO_TO_INTEGER(v);
M
mamingshuai 已提交
802
            if ((u >= 0) && (intU < in.info.header.width - 1) && (v >= 0) && (intV < in.info.header.height - 1)) {
G
guyuanzhang 已提交
803
#if ENABLE_ARM_MATH
M
mamingshuai 已提交
804 805 806
                uint32_t val1 = __SMUAD(intV, in.srcLineWidth);
                uint32_t val2 = __SMUAD(intU, in.pixelSize);
                uint32_t px1 = val1 + val2;
G
guyuanzhang 已提交
807 808
#else
                uint32_t px1 = intV * in.srcLineWidth + intU * in.pixelSize;
M
mamingshuai 已提交
809 810 811 812 813 814 815
#endif
                uint8_t* imgHead = const_cast<uint8_t*>(in.info.data);
                const Color24 p1 = *(reinterpret_cast<Color24*>(&imgHead[px1]));
                const Color24 p2 = *(reinterpret_cast<Color24*>(&imgHead[px1 + in.pixelSize]));
                const Color24 p3 = *(reinterpret_cast<Color24*>(&imgHead[px1 + in.srcLineWidth]));
                const Color24 p4 = *(reinterpret_cast<Color24*>(&imgHead[px1 + in.srcLineWidth + in.pixelSize]));

L
liqiang 已提交
816 817 818 819 820 821 822 823 824 825
                // parameters below are Q15 fixed-point number
                int32_t decU = FO_DECIMAL(u);
                int32_t decV = FO_DECIMAL(v);
                int32_t decUMinus1 = FIXED_NUM_1 - decU;
                int32_t decVMinus1 = FIXED_NUM_1 - decV;
                int32_t w1 = FO_MUL(decUMinus1, decVMinus1);
                int32_t w2 = FO_MUL(decU, decVMinus1);
                int32_t w3 = FO_MUL(decUMinus1, decV);
                int32_t w4 = FO_MUL(decU, decV);
                // parameters above are Q15 fixed-point number
G
guyuanzhang 已提交
826
#if ENABLE_ARM_MATH
M
mamingshuai 已提交
827 828 829 830 831 832
                const int32_t outR =
                    __SMUAD(p1.red, w1) + __SMUAD(p2.red, w2) + __SMUAD(p3.red, w3) + __SMUAD(p4.red, w4);
                const int32_t outG =
                    __SMUAD(p1.green, w1) + __SMUAD(p2.green, w2) + __SMUAD(p3.green, w3) + __SMUAD(p4.green, w4);
                const int32_t outB =
                    __SMUAD(p1.blue, w1) + __SMUAD(p2.blue, w2) + __SMUAD(p3.blue, w3) + __SMUAD(p4.blue, w4);
G
guyuanzhang 已提交
833 834 835 836
#else
                const int32_t outR = p1.red * w1 + p2.red * w2 + p3.red * w3 + p4.red * w4;
                const int32_t outG = p1.green * w1 + p2.green * w2 + p3.green * w3 + p4.green * w4;
                const int32_t outB = p1.blue * w1 + p2.blue * w2 + p3.blue * w3 + p4.blue * w4;
M
mamingshuai 已提交
837 838 839
#endif

                Color24 result;
L
liqiang 已提交
840 841 842
                result.red = static_cast<uint8_t>(outR >> 15); // 15: shift 15 bit right to convert fixed to int
                result.green = static_cast<uint8_t>(outG >> 15); // 15: shift 15 bit right to convert fixed to int
                result.blue = static_cast<uint8_t>(outB >> 15);  // 15: shift 15 bit right to convert fixed to int
M
mamingshuai 已提交
843 844 845 846 847 848 849 850 851 852 853 854 855
                if (in.opaScale == OPA_OPAQUE) {
                    COLOR_FILL_COVER(screenBuffer, bufferMode, result.red, result.green, result.blue, RGB888);
                } else {
                    COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, RGB888, in.opaScale);
                }
            }
            u += in.init.duHorizon;
            v += in.init.dvHorizon;
            screenBuffer += in.bufferPxSize;
        }
        StepToNextLine(in.edge1, in.edge2);
        in.init.verticalU += in.init.duVertical;
        in.init.verticalV += in.init.dvVertical;
L
liqiang 已提交
856
        int16_t deltaX = FO_TO_INTEGER(in.edge1.curX) - xMin;
M
mamingshuai 已提交
857 858 859 860 861 862 863
        in.init.verticalU += in.init.duHorizon * deltaX;
        in.init.verticalV += in.init.dvHorizon * deltaX;
    }
}

static void DrawTriangleTrueColorBilinear8888Inner(const TriangleScanInfo& in,
                                                   uint8_t* screenBuffer,
J
jsjzju 已提交
864
                                                   int16_t len,
N
niulihua 已提交
865
												   const ColorMode bufferMode,
J
jsjzju 已提交
866 867
                                                   int32_t u,
                                                   int32_t v)
M
mamingshuai 已提交
868 869
{
    for (int16_t x = 0; x < len; ++x) {
L
liqiang 已提交
870 871
        int16_t intU = FO_TO_INTEGER(u);
        int16_t intV = FO_TO_INTEGER(v);
M
mamingshuai 已提交
872
        if ((u >= 0) && (intU < in.info.header.width - 1) && (v >= 0) && (intV < in.info.header.height - 1)) {
G
guyuanzhang 已提交
873
#if ENABLE_ARM_MATH
M
mamingshuai 已提交
874 875 876
            uint32_t val1 = __SMUAD(intV, in.srcLineWidth);
            uint32_t val2 = __SMUAD(intU, in.pixelSize);
            uint32_t px1 = val1 + val2;
G
guyuanzhang 已提交
877 878
#else
            uint32_t px1 = intV * in.srcLineWidth + intU * in.pixelSize;
M
mamingshuai 已提交
879 880 881 882 883 884 885
#endif
            uint8_t* imgHead = const_cast<uint8_t*>(in.info.data);
            const ColorType p1 = *(reinterpret_cast<ColorType*>(&imgHead[px1]));
            const ColorType p2 = *(reinterpret_cast<ColorType*>(&imgHead[px1 + in.pixelSize]));
            const ColorType p3 = *(reinterpret_cast<ColorType*>(&imgHead[px1 + in.srcLineWidth]));
            const ColorType p4 = *(reinterpret_cast<ColorType*>(&imgHead[px1 + in.srcLineWidth + in.pixelSize]));

L
liqiang 已提交
886 887 888 889 890 891 892 893 894 895
            // parameters below are Q15 fixed-point number
            int32_t decU = FO_DECIMAL(u);
            int32_t decV = FO_DECIMAL(v);
            int32_t decUMinus1 = FIXED_NUM_1 - decU;
            int32_t decVMinus1 = FIXED_NUM_1 - decV;
            int32_t w1 = FO_MUL(decUMinus1, decVMinus1);
            int32_t w2 = FO_MUL(decU, decVMinus1);
            int32_t w3 = FO_MUL(decUMinus1, decV);
            int32_t w4 = FO_MUL(decU, decV);
            // parameters above are Q15 fixed-point number
M
mamingshuai 已提交
896

G
guyuanzhang 已提交
897
#if ENABLE_ARM_MATH
M
mamingshuai 已提交
898 899 900 901 902 903 904
            const int32_t outR = __SMUAD(p1.red, w1) + __SMUAD(p2.red, w2) + __SMUAD(p3.red, w3) + __SMUAD(p4.red, w4);
            const int32_t outG =
                __SMUAD(p1.green, w1) + __SMUAD(p2.green, w2) + __SMUAD(p3.green, w3) + __SMUAD(p4.green, w4);
            const int32_t outB =
                __SMUAD(p1.blue, w1) + __SMUAD(p2.blue, w2) + __SMUAD(p3.blue, w3) + __SMUAD(p4.blue, w4);
            const int32_t outA =
                __SMUAD(p1.alpha, w1) + __SMUAD(p2.alpha, w2) + __SMUAD(p3.alpha, w3) + __SMUAD(p4.alpha, w4);
G
guyuanzhang 已提交
905 906 907 908 909
#else
            const int32_t outR = p1.red * w1 + p2.red * w2 + p3.red * w3 + p4.red * w4;
            const int32_t outG = p1.green * w1 + p2.green * w2 + p3.green * w3 + p4.green * w4;
            const int32_t outB = p1.blue * w1 + p2.blue * w2 + p3.blue * w3 + p4.blue * w4;
            const int32_t outA = p1.alpha * w1 + p2.alpha * w2 + p3.alpha * w3 + p4.alpha * w4;
M
mamingshuai 已提交
910 911 912
#endif

            Color32 result;
L
liqiang 已提交
913 914 915 916
            result.red = static_cast<uint8_t>(outR >> 15);   // 15: shift 15 bit right to convert fixed to int
            result.green = static_cast<uint8_t>(outG >> 15); // 15: shift 15 bit right to convert fixed to int
            result.blue = static_cast<uint8_t>(outB >> 15);  // 15: shift 15 bit right to convert fixed to int
            result.alpha = static_cast<uint8_t>(outA >> 15); // 15: shift 15 bit right to convert fixed to int
M
mamingshuai 已提交
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
            if ((in.opaScale == OPA_OPAQUE) && (result.alpha == OPA_OPAQUE)) {
                COLOR_FILL_COVER(screenBuffer, bufferMode, result.red, result.green, result.blue, ARGB8888);
            } else {
                COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, ARGB8888, in.opaScale);
            }
        }
        u += in.init.duHorizon;
        v += in.init.dvHorizon;
        screenBuffer += in.bufferPxSize;
    }
}

#ifdef ARM_NEON_OPT
static void DrawTriangleTrueColorBilinear8888InnerNeon(const TriangleScanInfo& in,
                                                       uint8_t* screenBuffer,
                                                       int16_t len,
                                                       float u,
                                                       float v,
N
niulihua 已提交
935 936
                                                       NeonBlendPipeLine& pipeLine,
                                                       const ColorMode bufferMode)
M
mamingshuai 已提交
937
{
L
liqiang 已提交
938 939 940 941
    ColorType arrayp1[NEON_STEP_8] = {};
    ColorType arrayp2[NEON_STEP_8] = {};
    ColorType arrayp3[NEON_STEP_8] = {};
    ColorType arrayp4[NEON_STEP_8] = {};
M
mamingshuai 已提交
942 943 944 945
    float arrayU[NEON_STEP_8] = {0};
    float arrayV[NEON_STEP_8] = {0};
    int32_t arrayPx1[NEON_STEP_8] = {0};
    int16_t step = in.bufferPxSize * NEON_STEP_8;
L
liqiang 已提交
946 947
    float duHorizon = static_cast<float>(in.init.duHorizon) / FIXED_NUM_1;
    float dvHorizon = static_cast<float>(in.init.dvHorizon) / FIXED_NUM_1;
M
mamingshuai 已提交
948 949 950 951
    while (len >= NEON_STEP_8) {
        for (uint32_t i = 0; i < NEON_STEP_8; ++i) {
            arrayU[i] = u;
            arrayV[i] = v;
L
liqiang 已提交
952 953
            u += duHorizon;
            v += dvHorizon;
M
mamingshuai 已提交
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
        }
        // Monotonically increasing or decreasing, so only judge the beginning and end.
        if ((arrayU[0] >= 0) && (arrayU[0] < in.info.header.width - 1) &&
            (arrayV[0] >= 0) && (arrayV[0] < in.info.header.height - 1) &&
            (arrayU[NEON_STEP_8 - 1] >= 0) && (arrayU[NEON_STEP_8 - 1] < in.info.header.width - 1) &&
            (arrayV[NEON_STEP_8 - 1] >= 0) && (arrayV[NEON_STEP_8 - 1] < in.info.header.height - 1)) {
            // Process the lower half of arrayU and arrayV
            float32x4_t vU = vld1q_f32(arrayU);
            float32x4_t vV = vld1q_f32(arrayV);
            int32x4_t vIntU = vcvtq_s32_f32(vU);
            int32x4_t vIntV = vcvtq_s32_f32(vV);
            int32x4_t vPx1 =
                vaddq_s32(vmulq_s32(vIntV, vdupq_n_s32(in.srcLineWidth)), vmulq_s32(vIntU, vdupq_n_s32(in.pixelSize)));
            vst1q_s32(arrayPx1, vPx1);
            float32x4_t vDecU = vsubq_f32(vU, vcvtq_f32_s32(vIntU));
            float32x4_t vDecV = vsubq_f32(vV, vcvtq_f32_s32(vIntV));
            float32x4_t vDecUMinus1 = vsubq_f32(vdupq_n_f32(1.0), vDecU);
            float32x4_t vDecVMinus1 = vsubq_f32(vdupq_n_f32(1.0), vDecV);
            // 256:shift 8 bit left
            uint32x4_t vLowW1 = vcvtq_u32_f32(vmulq_f32(vmulq_f32(vDecUMinus1, vDecVMinus1), vdupq_n_f32(256.0)));
            uint32x4_t vLowW2 = vcvtq_u32_f32(vmulq_f32(vmulq_f32(vDecU, vDecVMinus1), vdupq_n_f32(256.0)));
            uint32x4_t vLowW3 = vcvtq_u32_f32(vmulq_f32(vmulq_f32(vDecUMinus1, vDecV), vdupq_n_f32(256.0)));
            uint32x4_t vLowW4 = vcvtq_u32_f32(vmulq_f32(vmulq_f32(vDecU, vDecV), vdupq_n_f32(256.0)));
            // Process the higher half of arrayU and arrayV
            vU = vld1q_f32(arrayU + NEON_STEP_4);
            vV = vld1q_f32(arrayV + NEON_STEP_4);
            vIntU = vcvtq_s32_f32(vU);
            vIntV = vcvtq_s32_f32(vV);
            vPx1 =
                vaddq_s32(vmulq_s32(vIntV, vdupq_n_s32(in.srcLineWidth)), vmulq_s32(vIntU, vdupq_n_s32(in.pixelSize)));
            vst1q_s32(arrayPx1 + NEON_STEP_4, vPx1);
            vDecU = vsubq_f32(vU, vcvtq_f32_s32(vIntU));
            vDecV = vsubq_f32(vV, vcvtq_f32_s32(vIntV));
            vDecUMinus1 = vsubq_f32(vdupq_n_f32(1.0), vDecU);
            vDecVMinus1 = vsubq_f32(vdupq_n_f32(1.0), vDecV);
            // 256:shift 8 bit left
            uint32x4_t vHighW1 = vcvtq_u32_f32(vmulq_f32(vmulq_f32(vDecUMinus1, vDecVMinus1), vdupq_n_f32(256.0)));
            uint32x4_t vHighW2 = vcvtq_u32_f32(vmulq_f32(vmulq_f32(vDecU, vDecVMinus1), vdupq_n_f32(256.0)));
            uint32x4_t vHighW3 = vcvtq_u32_f32(vmulq_f32(vmulq_f32(vDecUMinus1, vDecV), vdupq_n_f32(256.0)));
            uint32x4_t vHighW4 = vcvtq_u32_f32(vmulq_f32(vmulq_f32(vDecU, vDecV), vdupq_n_f32(256.0)));

            // joins two uint32x4_t vectors into a uint16x8_t vector
            uint16x8_t vW1 = vcombine_u16(vmovn_u32(vLowW1), vmovn_u32(vHighW1));
            uint16x8_t vW2 = vcombine_u16(vmovn_u32(vLowW2), vmovn_u32(vHighW2));
            uint16x8_t vW3 = vcombine_u16(vmovn_u32(vLowW3), vmovn_u32(vHighW3));
            uint16x8_t vW4 = vcombine_u16(vmovn_u32(vLowW4), vmovn_u32(vHighW4));

            uint8_t* imgHead = const_cast<uint8_t*>(in.info.data);
            for (uint32_t i = 0; i < NEON_STEP_8; ++i) {
                int32_t px1 = arrayPx1[i];
                arrayp1[i] = *(reinterpret_cast<ColorType*>(&imgHead[px1]));
                arrayp2[i] = *(reinterpret_cast<ColorType*>(&imgHead[px1 + in.pixelSize]));
                arrayp3[i] = *(reinterpret_cast<ColorType*>(&imgHead[px1 + in.srcLineWidth]));
                arrayp4[i] = *(reinterpret_cast<ColorType*>(&imgHead[px1 + in.srcLineWidth + in.pixelSize]));
            }

            uint8x8x4_t v4p1 = vld4_u8(reinterpret_cast<uint8_t*>(arrayp1));
            uint8x8x4_t v4p2 = vld4_u8(reinterpret_cast<uint8_t*>(arrayp2));
            uint8x8x4_t v4p3 = vld4_u8(reinterpret_cast<uint8_t*>(arrayp3));
            uint8x8x4_t v4p4 = vld4_u8(reinterpret_cast<uint8_t*>(arrayp4));
            uint8x8_t vOutB =
                vshrn_n_u16(vmulq_u16(vmovl_u8(v4p1.val[NEON_B]), vW1) + vmulq_u16(vmovl_u8(v4p2.val[NEON_B]), vW2) +
                                vmulq_u16(vmovl_u8(v4p3.val[NEON_B]), vW3) + vmulq_u16(vmovl_u8(v4p4.val[NEON_B]), vW4),
                            8); // 8:shift 8 bit right
            uint8x8_t vOutG =
                vshrn_n_u16(vmulq_u16(vmovl_u8(v4p1.val[NEON_G]), vW1) + vmulq_u16(vmovl_u8(v4p2.val[NEON_G]), vW2) +
                                vmulq_u16(vmovl_u8(v4p3.val[NEON_G]), vW3) + vmulq_u16(vmovl_u8(v4p4.val[NEON_G]), vW4),
                            8); // 8:shift 8 bit right
            uint8x8_t vOutR =
                vshrn_n_u16(vmulq_u16(vmovl_u8(v4p1.val[NEON_R]), vW1) + vmulq_u16(vmovl_u8(v4p2.val[NEON_R]), vW2) +
                                vmulq_u16(vmovl_u8(v4p3.val[NEON_R]), vW3) + vmulq_u16(vmovl_u8(v4p4.val[NEON_R]), vW4),
                            8); // 8:shift 8 bit right
            uint8x8_t vOutA =
                vshrn_n_u16(vmulq_u16(vmovl_u8(v4p1.val[NEON_A]), vW1) + vmulq_u16(vmovl_u8(v4p2.val[NEON_A]), vW2) +
                                vmulq_u16(vmovl_u8(v4p3.val[NEON_A]), vW3) + vmulq_u16(vmovl_u8(v4p4.val[NEON_A]), vW4),
                            8); // 8:shift 8 bit right
            vOutA = NeonMulDiv255(vdup_n_u8(in.opaScale), vOutA);
            pipeLine.Invoke(screenBuffer, vOutR, vOutG, vOutB, vOutA);
        } else {
J
jsjzju 已提交
1033 1034
            int32_t fixedU = FO_TRANS_FLOAT_TO_FIXED(arrayU[0]);
            int32_t fixedV = FO_TRANS_FLOAT_TO_FIXED(arrayV[0]);
N
niulihua 已提交
1035
            DrawTriangleTrueColorBilinear8888Inner(in, screenBuffer, NEON_STEP_8, bufferMode, fixedU, fixedV);
M
mamingshuai 已提交
1036 1037 1038 1039 1040
        }
        screenBuffer += step;
        len -= NEON_STEP_8;
    }
    if (len > 0) {
J
jsjzju 已提交
1041 1042
        int32_t fixedU = FO_TRANS_FLOAT_TO_FIXED(u);
        int32_t fixedV = FO_TRANS_FLOAT_TO_FIXED(v);
N
niulihua 已提交
1043
        DrawTriangleTrueColorBilinear8888Inner(in, screenBuffer, len, bufferMode, fixedU, fixedV);
M
mamingshuai 已提交
1044 1045 1046 1047
    }
}
#endif

N
niulihua 已提交
1048
void DrawUtils::DrawTriangleTrueColorBilinear8888(const TriangleScanInfo& in, const ColorMode bufferMode)
M
mamingshuai 已提交
1049 1050 1051
{
    int16_t maskLeft = in.mask.GetLeft();
    int16_t maskRight = in.mask.GetRight();
L
liqiang 已提交
1052 1053
    int16_t xMinErr = 0;
    int16_t xMaxErr = 0;
M
mamingshuai 已提交
1054 1055 1056 1057 1058 1059
    GetXAxisErrForJunctionLine(in.ignoreJunctionPoint, in.isRightPart, xMinErr, xMaxErr);
#ifdef ARM_NEON_OPT
    NeonBlendPipeLine pipeLine;
    pipeLine.Construct(bufferMode, ARGB8888);
#endif
    for (int16_t y = in.yMin; y <= in.yMax; ++y) {
L
liqiang 已提交
1060 1061 1062 1063 1064
        int16_t tempV = FO_TO_INTEGER(in.edge1.curX) + xMinErr;
        int16_t xMin = MATH_MAX(tempV, maskLeft);
        tempV = FO_TO_INTEGER(in.edge2.curX) + xMaxErr;
        int16_t xMax = MATH_MIN(tempV, maskRight);
        int16_t diffX = xMin - FO_TO_INTEGER(in.edge1.curX);
M
mamingshuai 已提交
1065 1066 1067 1068 1069
        in.init.verticalU += in.init.duHorizon * diffX;
        in.init.verticalV += in.init.dvHorizon * diffX;
        uint8_t* screenBuffer = in.screenBuffer + (y * in.screenBufferWidth + xMin) * in.bufferPxSize;
#ifdef ARM_NEON_OPT
        {
L
liqiang 已提交
1070 1071
            float u = static_cast<float>(in.init.verticalU) / FIXED_NUM_1;
            float v = static_cast<float>(in.init.verticalV) / FIXED_NUM_1;
M
mamingshuai 已提交
1072
            DEBUG_PERFORMANCE_TRACE("DrawTriangleTrueColorBilinear8888_neon");
N
niulihua 已提交
1073
            DrawTriangleTrueColorBilinear8888InnerNeon(in, screenBuffer, xMax - xMin + 1, u, v, pipeLine, bufferMode);
M
mamingshuai 已提交
1074 1075 1076
        }
#else
        {
J
jsjzju 已提交
1077 1078
            int32_t u = in.init.verticalU;
            int32_t v = in.init.verticalV;
M
mamingshuai 已提交
1079
            DEBUG_PERFORMANCE_TRACE("DrawTriangleTrueColorBilinear8888");
N
niulihua 已提交
1080
            DrawTriangleTrueColorBilinear8888Inner(in, screenBuffer, xMax - xMin + 1, bufferMode, u, v);
M
mamingshuai 已提交
1081 1082 1083 1084 1085
        }
#endif
        StepToNextLine(in.edge1, in.edge2);
        in.init.verticalU += in.init.duVertical;
        in.init.verticalV += in.init.dvVertical;
L
liqiang 已提交
1086
        int16_t deltaX = FO_TO_INTEGER(in.edge1.curX) - xMin;
M
mamingshuai 已提交
1087 1088 1089 1090 1091
        in.init.verticalU += in.init.duHorizon * deltaX;
        in.init.verticalV += in.init.dvHorizon * deltaX;
    }
}

N
niulihua 已提交
1092
void DrawUtils::DrawTriangleTrueColorNearest(const TriangleScanInfo& in, const ColorMode bufferMode)
M
mamingshuai 已提交
1093 1094 1095
{
    int16_t maskLeft = in.mask.GetLeft();
    int16_t maskRight = in.mask.GetRight();
L
liqiang 已提交
1096 1097
    int16_t xMinErr = 0;
    int16_t xMaxErr = 0;
M
mamingshuai 已提交
1098 1099
    GetXAxisErrForJunctionLine(in.ignoreJunctionPoint, in.isRightPart, xMinErr, xMaxErr);
    for (int16_t y = in.yMin; y <= in.yMax; y++) {
L
liqiang 已提交
1100 1101 1102 1103 1104
        int16_t tempV = FO_TO_INTEGER(in.edge1.curX) + xMinErr;
        int16_t xMin = MATH_MAX(tempV, maskLeft);
        tempV = FO_TO_INTEGER(in.edge2.curX) + xMaxErr;
        int16_t xMax = MATH_MIN(tempV, maskRight);
        int16_t diffX = xMin - FO_TO_INTEGER(in.edge1.curX);
M
mamingshuai 已提交
1105 1106 1107
        in.init.verticalU += in.init.duHorizon * diffX;
        in.init.verticalV += in.init.dvHorizon * diffX;
        uint8_t* screenBuffer = in.screenBuffer + (y * in.screenBufferWidth + xMin) * in.bufferPxSize;
L
liqiang 已提交
1108 1109 1110 1111
        // parameters below are Q15 fixed-point number
        int32_t u = in.init.verticalU;
        int32_t v = in.init.verticalV;
        // parameters above are Q15 fixed-point number
M
mamingshuai 已提交
1112
        for (int16_t x = xMin; x <= xMax; x++) {
L
liqiang 已提交
1113 1114 1115
            int16_t intU = FO_TO_INTEGER(u);
            int16_t intV = FO_TO_INTEGER(v);
            if ((u >= 0) && (intU < (in.info.header.width - 1)) && (v >= 0) && (intV < (in.info.header.height - 1))) {
G
guyuanzhang 已提交
1116
#if ENABLE_ARM_MATH
M
mamingshuai 已提交
1117 1118 1119
                uint32_t val1 = __SMUAD(intV, in.srcLineWidth);
                uint32_t val2 = __SMUAD(intU, in.pixelSize);
                uint32_t px1 = val1 + val2;
G
guyuanzhang 已提交
1120 1121
#else
                uint32_t px1 = intV * in.srcLineWidth + intU * in.pixelSize;
M
mamingshuai 已提交
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
#endif
                uint8_t* imgHead = const_cast<uint8_t*>(in.info.data);
                OpacityType opa = in.opaScale;

                switch (in.info.header.colorMode) {
                    case RGB888: {
                        Color24 p24 = *(reinterpret_cast<Color24*>(&imgHead[px1]));
                        if (opa == OPA_OPAQUE) {
                            COLOR_FILL_COVER(screenBuffer, bufferMode, p24.red, p24.green, p24.blue, RGB888);
                        } else {
                            COLOR_FILL_BLEND(screenBuffer, bufferMode, &p24, RGB888, opa);
                        }
                        break;
                    }
                    case RGB565: {
                        Color16 p16 = *(reinterpret_cast<Color16*>(&imgHead[px1]));
                        if (opa == OPA_OPAQUE) {
                            COLOR_FILL_COVER(screenBuffer, bufferMode, p16.red, p16.green, p16.blue, RGB565);
                        } else {
                            COLOR_FILL_BLEND(screenBuffer, bufferMode, &p16, RGB565, opa);
                        }
                        break;
                    }
                    case ARGB8888: {
                        Color32 p32 = *(reinterpret_cast<Color32*>(&imgHead[px1]));
                        if ((in.opaScale == OPA_OPAQUE) && (p32.alpha == OPA_OPAQUE)) {
                            COLOR_FILL_COVER(screenBuffer, bufferMode, p32.red, p32.green, p32.blue, ARGB8888);
                        } else {
                            COLOR_FILL_BLEND(screenBuffer, bufferMode, &p32, ARGB8888, in.opaScale);
                        }
                        break;
                    }
                    default:
                        return;
                }
            }
            u += in.init.duHorizon;
            v += in.init.dvHorizon;
            screenBuffer += in.bufferPxSize;
        }
        StepToNextLine(in.edge1, in.edge2);
        in.init.verticalU += in.init.duVertical;
        in.init.verticalV += in.init.dvVertical;
L
liqiang 已提交
1165
        int16_t deltaX = FO_TO_INTEGER(in.edge1.curX) - xMin;
M
mamingshuai 已提交
1166 1167 1168 1169 1170
        in.init.verticalU += in.init.duHorizon * deltaX;
        in.init.verticalV += in.init.dvHorizon * deltaX;
    }
}

N
niulihua 已提交
1171
void DrawUtils::DrawTriangleTransformPart(BufferInfo& gfxDstBuffer, const TrianglePartInfo& part)
M
mamingshuai 已提交
1172
{
L
liqiang 已提交
1173 1174 1175 1176 1177 1178
    // parameters below are Q15 fixed-point number
    int32_t yMin = FO_TRANS_INTEGER_TO_FIXED(part.yMin);
    part.edge1.curX += (static_cast<int64_t>(part.edge1.du) *  (yMin - part.edge1.curY) / part.edge1.dv);
    part.edge1.curY = yMin;
    part.edge2.curX += (static_cast<int64_t>(part.edge2.du) *  (yMin - part.edge2.curY) / part.edge2.dv);
    part.edge2.curY = yMin;
M
mamingshuai 已提交
1179
    Rect line;
L
liqiang 已提交
1180 1181 1182 1183 1184
    line.SetLeft(FO_TO_INTEGER(part.edge1.curX));
    line.SetRight(FO_TO_INTEGER(part.edge1.curX));
    line.SetTop(FO_TO_INTEGER(part.edge1.curY));
    line.SetBottom(FO_TO_INTEGER(part.edge1.curY));
    // parameters above are Q15 fixed-point number
M
mamingshuai 已提交
1185 1186 1187
    TransformInitState init;
    GetTransformInitState(part.transMap, part.position, line, init);

N
niulihua 已提交
1188
    DRAW_UTILS_PREPROCESS(gfxDstBuffer, OPA_OPAQUE);
M
mamingshuai 已提交
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
    uint8_t pixelSize;
    DrawTriangleTransformFuc fuc;
    bool isTrueColor = (part.info.header.colorMode == ARGB8888) || (part.info.header.colorMode == RGB888) ||
                       (part.info.header.colorMode == RGB565);
    if (isTrueColor) {
        pixelSize = part.info.pxSize >> SHIFT_3;
        if (part.info.algorithm == TransformAlgorithm::NEAREST_NEIGHBOR) {
            fuc = DrawTriangleTrueColorNearest;
        } else if (part.info.header.colorMode == ARGB8888) {
            fuc = DrawTriangleTrueColorBilinear8888;
        } else if (part.info.header.colorMode == RGB888) {
            fuc = DrawTriangleTrueColorBilinear888;
        } else {
            fuc = DrawTriangleTrueColorBilinear565;
        }
    } else {
        pixelSize = part.info.pxSize;
        fuc = DrawTriangleAlphaBilinear;
    }
    const int32_t srcLineWidth = part.info.header.width * pixelSize;
    TriangleScanInfo input{part.yMin,
                           part.yMax,
                           part.edge1,
                           part.edge2,
                           screenBuffer,
                           bufferPxSize,
                           part.color,
                           part.opaScale,
                           init,
N
niulihua 已提交
1218
                           gfxDstBuffer.width,
M
mamingshuai 已提交
1219 1220 1221 1222 1223 1224
                           pixelSize,
                           srcLineWidth,
                           part.info,
                           part.mask,
                           part.isRightPart,
                           part.ignoreJunctionPoint};
N
niulihua 已提交
1225
    fuc(input, gfxDstBuffer.mode);
M
mamingshuai 已提交
1226 1227
}

N
niulihua 已提交
1228 1229
void DrawUtils::DrawTriangleTransform(BufferInfo& gfxDstBuffer,
                                      const Rect& mask,
M
mamingshuai 已提交
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
                                      const Point& position,
                                      const ColorType& color,
                                      OpacityType opaScale,
                                      const TransformMap& transMap,
                                      const TriangleTransformDataInfo& triangleInfo)
{
    bool p3IsInRight = ((triangleInfo.p1.y - triangleInfo.p2.y) * triangleInfo.p3.x +
                        (triangleInfo.p2.x - triangleInfo.p1.x) * triangleInfo.p3.y +
                        triangleInfo.p1.x * triangleInfo.p2.y - triangleInfo.p2.x * triangleInfo.p1.y) < 0;
    TriangleEdge edge1;
    TriangleEdge edge2;
    TrianglePartInfo part{
        mask,
        transMap,
        position,
        edge1,
        edge2,
        0,
        0,
        triangleInfo.info,
        color,
        opaScale,
        triangleInfo.isRightPart,
        triangleInfo.ignoreJunctionPoint,
    };

    uint8_t yErr = 1;
    if (triangleInfo.p2.y == triangleInfo.p1.y) {
        yErr = 0;
        goto BottomHalf;
    }
    if (p3IsInRight) {
        edge1 = TriangleEdge(triangleInfo.p1.x, triangleInfo.p1.y, triangleInfo.p2.x, triangleInfo.p2.y);
        edge2 = TriangleEdge(triangleInfo.p1.x, triangleInfo.p1.y, triangleInfo.p3.x, triangleInfo.p3.y);
    } else {
        edge2 = TriangleEdge(triangleInfo.p1.x, triangleInfo.p1.y, triangleInfo.p2.x, triangleInfo.p2.y);
        edge1 = TriangleEdge(triangleInfo.p1.x, triangleInfo.p1.y, triangleInfo.p3.x, triangleInfo.p3.y);
    }

    part.yMin = MATH_MAX(mask.GetTop(), triangleInfo.p1.y);
    part.yMax = MATH_MIN(mask.GetBottom(), triangleInfo.p2.y);
    part.edge1 = edge1;
    part.edge2 = edge2;
N
niulihua 已提交
1273
    DrawTriangleTransformPart(gfxDstBuffer, part);
M
mamingshuai 已提交
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
BottomHalf:
    if (triangleInfo.p2.y == triangleInfo.p3.y) {
        return;
    }

    if (triangleInfo.p2.y == triangleInfo.p1.y) {
        if (triangleInfo.p1.x < triangleInfo.p2.x) {
            edge1 = TriangleEdge(triangleInfo.p1.x, triangleInfo.p1.y, triangleInfo.p3.x, triangleInfo.p3.y);
            edge2 = TriangleEdge(triangleInfo.p2.x, triangleInfo.p2.y, triangleInfo.p3.x, triangleInfo.p3.y);
        } else {
            edge2 = TriangleEdge(triangleInfo.p1.x, triangleInfo.p1.y, triangleInfo.p3.x, triangleInfo.p3.y);
            edge1 = TriangleEdge(triangleInfo.p2.x, triangleInfo.p2.y, triangleInfo.p3.x, triangleInfo.p3.y);
        }
    } else {
        if (p3IsInRight) {
            edge1 = TriangleEdge(triangleInfo.p2.x, triangleInfo.p2.y, triangleInfo.p3.x, triangleInfo.p3.y);
        } else {
            edge2 = TriangleEdge(triangleInfo.p2.x, triangleInfo.p2.y, triangleInfo.p3.x, triangleInfo.p3.y);
        }
    }

    part.yMin = MATH_MAX(mask.GetTop(), triangleInfo.p2.y + yErr);
    part.yMax = MATH_MIN(mask.GetBottom(), triangleInfo.p3.y);
    part.edge1 = edge1;
    part.edge2 = edge2;
N
niulihua 已提交
1299
    DrawTriangleTransformPart(gfxDstBuffer, part);
M
mamingshuai 已提交
1300 1301
}

N
niulihua 已提交
1302 1303
void DrawUtils::DrawTransform(BufferInfo& gfxDstBuffer,
                              const Rect& mask,
M
mamingshuai 已提交
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318
                              const Point& position,
                              const ColorType& color,
                              OpacityType opaScale,
                              const TransformMap& transMap,
                              const TransformDataInfo& dataInfo) const
{
    if (opaScale == OPA_TRANSPARENT) {
        return;
    }
    Rect trans = transMap.GetBoxRect();
    trans.SetX(trans.GetX() + position.x);
    trans.SetY(trans.GetY() + position.y);
    if (!trans.Intersect(trans, mask)) {
        return;
    }
N
niulihua 已提交
1319
#if ENABLE_HARDWARE_ACCELERATION    // to do for backends
N
niulihua 已提交
1320
    DRAW_UTILS_PREPROCESS(gfxDstBuffer, opaScale);
M
mamingshuai 已提交
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
    TransformOption option;
    option.algorithm = dataInfo.algorithm;
    if (ScreenDeviceProxy::GetInstance()->HardwareTransform(dataInfo.data,
        static_cast<ColorMode>(dataInfo.header.colorMode), transMap.GetTransMapRect(), transMap.GetTransformMatrix(),
        opaScale, Color::ColorTo32(color), mask, screenBuffer, screenBufferWidth * bufferPxSize, bufferMode, option)) {
        return;
    }
#endif

    TriangleTransformDataInfo triangleInfo{
        dataInfo,
    };
    Polygon polygon = transMap.GetPolygon();
    Point p1;
    p1.x = polygon[0].x_ + position.x; // 0:first point
    p1.y = polygon[0].y_ + position.y; // 0:first point
    Point p2;
    p2.x = polygon[1].x_ + position.x; // 1:second point
    p2.y = polygon[1].y_ + position.y; // 1:second point
    Point p3;
    p3.x = polygon[2].x_ + position.x; // 2:third point
    p3.y = polygon[2].y_ + position.y; // 2:third point
    triangleInfo.isRightPart = ((p1.y - p3.y) * p2.x + (p3.x - p1.x) * p2.y + p1.x * p3.y - p3.x * p1.y) < 0;
    triangleInfo.isRightPart = (p1.y < p3.y) ? triangleInfo.isRightPart : !triangleInfo.isRightPart;
    DrawTriangle::SortVertexs(p1, p2, p3);
    triangleInfo.ignoreJunctionPoint = false;
    triangleInfo.p1 = p1;
    triangleInfo.p2 = p2;
    triangleInfo.p3 = p3;
    if ((triangleInfo.p1.y <= mask.GetBottom()) && (triangleInfo.p3.y >= mask.GetTop())) {
N
niulihua 已提交
1351
        DrawTriangleTransform(gfxDstBuffer, mask, position, color, opaScale, transMap, triangleInfo);
M
mamingshuai 已提交
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367
    }

    triangleInfo.ignoreJunctionPoint = true;
    triangleInfo.isRightPart = !triangleInfo.isRightPart;
    p1.x = polygon[0].x_ + position.x; // 0:first point
    p1.y = polygon[0].y_ + position.y; // 0:first point
    p3.x = polygon[2].x_ + position.x; // 2:third point
    p3.y = polygon[2].y_ + position.y; // 2:third point
    Point p4;
    p4.x = polygon[3].x_ + position.x; // 3:fourth point
    p4.y = polygon[3].y_ + position.y; // 3:fourth point
    DrawTriangle::SortVertexs(p1, p3, p4);
    triangleInfo.p1 = p1;
    triangleInfo.p2 = p3;
    triangleInfo.p3 = p4;
    if ((triangleInfo.p1.y <= mask.GetBottom()) && (triangleInfo.p3.y >= mask.GetTop())) {
N
niulihua 已提交
1368
        DrawTriangleTransform(gfxDstBuffer, mask, position, color, opaScale, transMap, triangleInfo);
M
mamingshuai 已提交
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410
    }
}

OpacityType DrawUtils::GetPxAlphaForAlphaImg(const TransformDataInfo& dataInfo, const Point& point)
{
    Point tmpPoint = point;
    const uint8_t* bufU8 = const_cast<uint8_t*>(dataInfo.data);
#if ENABLE_SPEC_FONT
    if (dataInfo.header.colorMode == A1) {
        uint8_t bit = tmpPoint.x & 0x7; // 0x7: 1 byte is 8 bit,
        tmpPoint.x = tmpPoint.x >> SHIFT_3;

        uint32_t px = (dataInfo.header.width >> SHIFT_3) * tmpPoint.y + tmpPoint.x;
        // 1: A1 means 1 bit, 7: maximum offset in bytes
        uint8_t pxOpa = (bufU8[px] & (1 << (7 - bit))) >> (7 - bit);
        return pxOpa ? OPA_TRANSPARENT : OPA_OPAQUE;
    } else if (dataInfo.header.colorMode == A2) {
        uint8_t bit = (tmpPoint.x & 0x3) * 2; // 0x3: 0b0011, 2: A2 color mode
        tmpPoint.x = tmpPoint.x >> SHIFT_2;

        uint32_t px = (dataInfo.header.width >> SHIFT_2) * tmpPoint.y + tmpPoint.x;
        // 3: the value of 0b0011
        uint8_t pxOpa = (bufU8[px] & (3 << (SHIFT_6 - bit))) >> (SHIFT_6 - bit);
        return pxOpa * OPACITY_STEP_A2;
    } else if (dataInfo.header.colorMode == A8) {
        uint32_t px = dataInfo.header.width * tmpPoint.y + tmpPoint.x;
        return bufU8[px];
    }
#else
    uint8_t letterWidthInByte = (dataInfo.header.width * dataInfo.pxSize) >> SHIFT_3;
    // 0x7: for rounding
    if ((dataInfo.header.width * dataInfo.pxSize) & 0x7) {
        letterWidthInByte++;
    }
    uint8_t bit = (tmpPoint.x & 0x1) << SHIFT_2;
    bufU8 += (tmpPoint.y * letterWidthInByte) + ((tmpPoint.x * dataInfo.pxSize) >> SHIFT_3);
    // 0xF: 0b1111, get the data of the A4 color mode
    uint8_t pxOpa = (*bufU8 & (0xF << bit)) >> (bit);
    return pxOpa * OPACITY_STEP_A4;
#endif // ENABLE_SPEC_FONT
}

N
niulihua 已提交
1411
void DrawUtils::DrawTranspantArea(BufferInfo& gfxDstBuffer, const Rect& rect, const Rect& mask)
M
mamingshuai 已提交
1412
{
N
niulihua 已提交
1413
    FillArea(gfxDstBuffer, rect, mask, true, nullptr);
M
mamingshuai 已提交
1414 1415
}

N
niulihua 已提交
1416 1417
void DrawUtils::DrawWithBuffer(BufferInfo& gfxDstBuffer, const Rect& rect,
                               const Rect& mask, const ColorType* colorBuf)
M
mamingshuai 已提交
1418
{
N
niulihua 已提交
1419
    FillArea(gfxDstBuffer, rect, mask, false, colorBuf);
M
mamingshuai 已提交
1420 1421
}

N
niulihua 已提交
1422 1423 1424 1425 1426
void DrawUtils::FillArea(BufferInfo& gfxDstBuffer,
                         const Rect& rect,
                         const Rect& mask,
                         bool isTransparent,
                         const ColorType* colorBuf)
M
mamingshuai 已提交
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437
{
    Rect maskedArea;
    if (!maskedArea.Intersect(rect, mask)) {
        return;
    }

    int16_t left = maskedArea.GetLeft();
    int16_t right = maskedArea.GetRight();
    int16_t top = maskedArea.GetTop();
    int16_t bottom = maskedArea.GetBottom();

N
niulihua 已提交
1438 1439
    DRAW_UTILS_PREPROCESS(gfxDstBuffer, OPA_OPAQUE);
    uint8_t* mem = screenBuffer;
M
mamingshuai 已提交
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469
    mem += top * screenBufferWidth * bufferPxSize;
    if (isTransparent) {
        uint16_t sz = (right - left + 1) * bufferPxSize;
        for (int16_t row = top; row <= bottom; row++) {
            if (memset_s(mem + (left * bufferPxSize), sz, 0, sz) != EOK) {
                return;
            }
            mem += screenBufferWidth * bufferPxSize;
        }
    } else {
        if (colorBuf == nullptr) {
            return;
        }
        for (int16_t row = top; row <= bottom; row++) {
            for (int16_t col = left; col <= right; col++) {
#if COLOR_DEPTH == 32
                COLOR_FILL_COVER(mem[col * bufferPxSize], bufferMode, colorBuf[row * screenBufferWidth + col].red,
                                 colorBuf[row * screenBufferWidth + col].green,
                                 colorBuf[row * screenBufferWidth + col].blue, ARGB8888);
#else
                COLOR_FILL_COVER(mem[col * bufferPxSize], bufferMode, colorBuf[row * screenBufferWidth + col].red,
                                 colorBuf[row * screenBufferWidth + col].green,
                                 colorBuf[row * screenBufferWidth + col].blue, RGB565);
#endif
            }
            mem += screenBufferWidth * bufferPxSize;
        }
    }
}

N
niulihua 已提交
1470 1471
void DrawUtils::DrawAdjPixelInLine(BufferInfo& gfxDstBuffer,
                                   int16_t x1,
M
mamingshuai 已提交
1472 1473 1474 1475 1476 1477 1478 1479
                                   int16_t y1,
                                   int16_t x2,
                                   int16_t y2,
                                   const Rect& mask,
                                   const ColorType& color,
                                   OpacityType opa,
                                   uint16_t weight) const
{
N
niulihua 已提交
1480
    DRAW_UTILS_PREPROCESS(gfxDstBuffer, opa);
M
mamingshuai 已提交
1481 1482 1483 1484 1485 1486 1487 1488
    Color32 result;
    result.full = Color::ColorTo32(color);
    if ((x1 >= mask.GetLeft()) && (x1 <= mask.GetRight()) && (y1 >= mask.GetTop()) && (y1 <= mask.GetBottom())) {
        screenBuffer += (y1 * screenBufferWidth + x1) * bufferPxSize;
        OpacityType fillOpa = (weight ^ OPA_OPAQUE) * opa / OPA_OPAQUE;
        COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, ARGB8888, fillOpa);
    }
    if ((x2 >= mask.GetLeft()) && (x2 <= mask.GetRight()) && (y2 >= mask.GetTop()) && (y2 <= mask.GetBottom())) {
N
niulihua 已提交
1489
        screenBuffer = static_cast<uint8_t*>(gfxDstBuffer.virAddr);
M
mamingshuai 已提交
1490 1491 1492 1493 1494 1495
        screenBuffer += (y2 * screenBufferWidth + x2) * bufferPxSize;
        OpacityType fillOpa = weight * opa / OPA_OPAQUE;
        COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, ARGB8888, fillOpa);
    }
}

N
niulihua 已提交
1496 1497
void DrawUtils::DrawPixelInLine(BufferInfo& gfxDstBuffer,
                                int16_t x,
M
mamingshuai 已提交
1498 1499 1500 1501 1502 1503
                                int16_t y,
                                const Rect& mask,
                                const ColorType& color,
                                OpacityType opa,
                                uint16_t weight) const
{
N
niulihua 已提交
1504
    DRAW_UTILS_PREPROCESS(gfxDstBuffer, opa);
M
mamingshuai 已提交
1505 1506 1507 1508 1509 1510 1511 1512 1513
    Color32 result;
    result.full = Color::ColorTo32(color);
    if ((x >= mask.GetLeft()) && (x <= mask.GetRight()) && (y >= mask.GetTop()) && (y <= mask.GetBottom())) {
        screenBuffer += (y * screenBufferWidth + x) * bufferPxSize;
        OpacityType fillOpa = weight * opa / OPA_OPAQUE;
        COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, ARGB8888, fillOpa);
    }
}

N
niulihua 已提交
1514 1515
void DrawUtils::DrawVerPixelInLine(BufferInfo& gfxDstBuffer,
                                   int16_t x,
M
mamingshuai 已提交
1516 1517 1518 1519 1520 1521 1522
                                   int16_t y,
                                   int8_t dir,
                                   const Rect& mask,
                                   const ColorType& color,
                                   OpacityType opa,
                                   uint16_t weight) const
{
N
niulihua 已提交
1523
    DRAW_UTILS_PREPROCESS(gfxDstBuffer, opa);
M
mamingshuai 已提交
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536
    if ((y < mask.GetTop()) || (y > mask.GetBottom())) {
        return;
    }
    Color32 result;
    result.full = Color::ColorTo32(color);
    int16_t x0 = x + dir;
    int16_t x1 = x - dir;
    if ((x0 >= mask.GetLeft()) && (x0 <= mask.GetRight())) {
        screenBuffer += (y * screenBufferWidth + x0) * bufferPxSize;
        OpacityType fillOpa = weight * opa / OPA_OPAQUE;
        COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, ARGB8888, fillOpa);
    }
    if ((x >= mask.GetLeft()) && (x <= mask.GetRight())) {
N
niulihua 已提交
1537
        screenBuffer = static_cast<uint8_t*>(gfxDstBuffer.virAddr);
M
mamingshuai 已提交
1538 1539 1540 1541 1542 1543 1544 1545
        screenBuffer += (y * screenBufferWidth + x) * bufferPxSize;
        if (opa == OPA_OPAQUE) {
            COLOR_FILL_COVER(screenBuffer, bufferMode, result.red, result.green, result.blue, ARGB8888);
        } else {
            COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, ARGB8888, opa);
        }
    }
    if ((x1 >= mask.GetLeft()) && (x1 <= mask.GetRight())) {
N
niulihua 已提交
1546
        screenBuffer = static_cast<uint8_t*>(gfxDstBuffer.virAddr);
M
mamingshuai 已提交
1547 1548 1549 1550 1551 1552
        screenBuffer += (y * screenBufferWidth + x1) * bufferPxSize;
        OpacityType fillOpa = (weight ^ OPA_OPAQUE) * opa / OPA_OPAQUE;
        COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, ARGB8888, fillOpa);
    }
}

N
niulihua 已提交
1553 1554
void DrawUtils::DrawHorPixelInLine(BufferInfo& gfxDstBuffer,
                                   int16_t x,
M
mamingshuai 已提交
1555 1556 1557 1558 1559 1560 1561
                                   int16_t y,
                                   int8_t dir,
                                   const Rect& mask,
                                   const ColorType& color,
                                   OpacityType opa,
                                   uint16_t weight) const
{
N
niulihua 已提交
1562
    DRAW_UTILS_PREPROCESS(gfxDstBuffer, opa);
M
mamingshuai 已提交
1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575
    if ((x < mask.GetLeft()) || (x > mask.GetRight())) {
        return;
    }
    Color32 result;
    result.full = Color::ColorTo32(color);
    int16_t y0 = y + dir;
    int16_t y1 = y - dir;
    if ((y0 >= mask.GetTop()) && (y0 <= mask.GetBottom())) {
        screenBuffer += (y0 * screenBufferWidth + x) * bufferPxSize;
        OpacityType fillOpa = weight * opa / OPA_OPAQUE;
        COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, ARGB8888, fillOpa);
    }
    if ((y >= mask.GetTop()) && (y <= mask.GetBottom())) {
N
niulihua 已提交
1576
        screenBuffer = static_cast<uint8_t*>(gfxDstBuffer.virAddr);
M
mamingshuai 已提交
1577 1578 1579 1580 1581 1582 1583 1584
        screenBuffer += (y * screenBufferWidth + x) * bufferPxSize;
        if (opa == OPA_OPAQUE) {
            COLOR_FILL_COVER(screenBuffer, bufferMode, result.red, result.green, result.blue, ARGB8888);
        } else {
            COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, ARGB8888, opa);
        }
    }
    if ((y1 >= mask.GetTop()) && (y1 <= mask.GetBottom())) {
N
niulihua 已提交
1585
        screenBuffer = static_cast<uint8_t*>(gfxDstBuffer.virAddr);
M
mamingshuai 已提交
1586 1587 1588 1589 1590
        screenBuffer += (y1 * screenBufferWidth + x) * bufferPxSize;
        OpacityType fillOpa = (weight ^ OPA_OPAQUE) * opa / OPA_OPAQUE;
        COLOR_FILL_BLEND(screenBuffer, bufferMode, &result, ARGB8888, fillOpa);
    }
}
N
niulihua 已提交
1591
} // namespace OHOS