// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_draw/lv_draw_basic.c
// Function: lv_draw_fill
void lv_draw_fill(const lv_area_t * cords_p, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa)
{
    if(opa < LV_OPA_MIN) return;
    if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;

    lv_area_t res_a;
    bool union_ok;

    /*Get the union of cord and mask*/
    /* The mask is already truncated to the vdb size
     * in 'lv_refr_area_with_vdb' function */
    union_ok = lv_area_intersect(&res_a, cords_p, mask_p);

    /*If there are common part of the three area then draw to the vdb*/
    if(union_ok == false) {
        return;
    }

    lv_disp_t * disp    = lv_refr_get_disp_refreshing();
    lv_disp_buf_t * vdb = lv_disp_get_buf(disp);

    lv_area_t vdb_rel_a; /*Stores relative coordinates on vdb*/
    vdb_rel_a.x1 = res_a.x1 - vdb->area.x1;
    vdb_rel_a.y1 = res_a.y1 - vdb->area.y1;
    vdb_rel_a.x2 = res_a.x2 - vdb->area.x1;
    vdb_rel_a.y2 = res_a.y2 - vdb->area.y1;

    lv_color_t * vdb_buf_tmp = vdb->buf_act;
    uint32_t vdb_width       = lv_area_get_width(&vdb->area);
    /*Move the vdb_tmp to the first row*/
    vdb_buf_tmp += vdb_width * vdb_rel_a.y1;

#if LV_USE_GPU
    static LV_ATTRIBUTE_MEM_ALIGN lv_color_t color_array_tmp[LV_HOR_RES_MAX]; /*Used by 'lv_disp_mem_blend'*/
    static lv_coord_t last_width = -1;

    lv_coord_t w = lv_area_get_width(&vdb_rel_a);
    /*Don't use hw. acc. for every small fill (because of the init overhead)*/
    if(w < VFILL_HW_ACC_SIZE_LIMIT) {
        sw_color_fill(vdb->buf_act, vdb_width, &vdb_rel_a, color, opa);
    }
    /*Not opaque fill*/
    else if(opa == LV_OPA_COVER) {
        /*Use hw fill if present*/
        if(disp->driver.gpu_fill_cb) {
            disp->driver.gpu_fill_cb(&disp->driver, vdb->buf_act, vdb_width, &vdb_rel_a, color);
        }
        /*Use hw blend if present and the area is not too small*/
        else if(lv_area_get_height(&vdb_rel_a) > VFILL_HW_ACC_SIZE_LIMIT && disp->driver.gpu_blend_cb) {
            /*Fill a  one line sized buffer with a color and blend this later*/
            if(color_array_tmp[0].full != color.full || last_width != w) {
                uint16_t i;
                for(i = 0; i < w; i++) {
                    color_array_tmp[i].full = color.full;
                }
                last_width = w;
            }

            /*Blend the filled line to every line VDB line-by-line*/
            lv_coord_t row;
            for(row = vdb_rel_a.y1; row <= vdb_rel_a.y2; row++) {
                disp->driver.gpu_blend_cb(&disp->driver, &vdb_buf_tmp[vdb_rel_a.x1], color_array_tmp, w, opa);
                vdb_buf_tmp += vdb_width;
            }

        }
        /*Else use sw fill if no better option*/
        else {
            sw_color_fill(vdb->buf_act, vdb_width, &vdb_rel_a, color, opa);
        }

    }
    /*Fill with opacity*/
    else {
        /*Use hw blend if present*/
        if(disp->driver.gpu_blend_cb) {
            if(color_array_tmp[0].full != color.full || last_width != w) {
                uint16_t i;
                for(i = 0; i < w; i++) {
                    color_array_tmp[i].full = color.full;
                }

                last_width = w;
            }
            lv_coord_t row;
            for(row = vdb_rel_a.y1; row <= vdb_rel_a.y2; row++) {
                disp->driver.gpu_blend_cb(&disp->driver, &vdb_buf_tmp[vdb_rel_a.x1], color_array_tmp, w, opa);
                vdb_buf_tmp += vdb_width;
            }

        }
        /*Use sw fill with opa if no better option*/
        else {
            sw_color_fill(vdb->buf_act, vdb_width, &vdb_rel_a, color, opa);
        }
    }
#else
    sw_color_fill(vdb->buf_act, vdb_width, &vdb_rel_a, color, opa);
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %ebp
movl %edx, 0x1c(%rsp)
cmpb $0x10, %bpl
jb 0x3296d
movq %rsi, %rdx
movq %rdi, %rsi
leaq 0x34(%rsp), %rdi
callq 0x26880
testb %al, %al
je 0x3296d
cmpb $-0x4, %bpl
movzbl %bpl, %ecx
movl $0xff, %eax
movl %ecx, 0x18(%rsp)
cmovbl %ecx, %eax
movl %eax, 0x24(%rsp)
callq 0x6e0e
movq %rax, %rdi
callq 0x7e45
movzwl 0x34(%rsp), %edx
movl 0x1c(%rax), %ecx
subl %ecx, %edx
movl %edx, 0x14(%rsp)
movzwl 0x36(%rsp), %r15d
movzwl 0x1e(%rax), %esi
movl %r15d, %r13d
subl %esi, %r13d
movzwl 0x38(%rsp), %edx
subl %ecx, %edx
movq %rdx, 0x28(%rsp)
movzwl 0x3a(%rsp), %edx
movl %esi, 0x3c(%rsp)
subl %esi, %edx
movl %edx, 0x20(%rsp)
movzwl 0x20(%rax), %ebx
subl %ecx, %ebx
incl %ebx
movq 0x10(%rax), %r14
callq 0x6e0e
cmpq $0x0, 0x28(%rax)
je 0x3285f
movq %rax, %r12
movl %r13d, 0x18(%rsp)
movzbl 0x24(%rsp), %r13d
movswl %bx, %ebp
movl 0x14(%rsp), %eax
cmpw 0x28(%rsp), %ax
jg 0x3296d
movl %eax, 0x14(%rsp)
movswl %ax, %r15d
movl 0x18(%rsp), %ebx
cmpw 0x20(%rsp), %bx
jg 0x32857
movl %r13d, (%rsp)
movswl %bx, %r8d
movq %r12, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r15d, %ecx
movl 0x1c(%rsp), %r9d
callq *0x28(%r12)
incl %ebx
jmp 0x3282f
movl 0x14(%rsp), %eax
incl %eax
jmp 0x32818
movl 0x18(%rsp), %r8d
movl 0x3c(%rsp), %edi
movswq %r13w, %rax
movswq %bx, %rcx
movq %rcx, 0x40(%rsp)
imulq %rax, %rcx
leaq (%r14,%rcx,2), %r12
cmpb $-0x4, %bpl
jb 0x3289f
movl 0x14(%rsp), %ecx
movl 0x1c(%rsp), %esi
cmpw 0x28(%rsp), %cx
jg 0x32910
movswq %cx, %rdx
movw %si, (%r12,%rdx,2)
incl %ecx
jmp 0x3288b
xorl %r15d, %r15d
movl 0x1c(%rsp), %edi
xorl %esi, %esi
movl %r8d, %edx
callq 0x326eb
movzbl 0x24(%rsp), %ebp
movl %r13d, 0x18(%rsp)
cmpw 0x20(%rsp), %r13w
movl 0x14(%rsp), %r13d
jg 0x3296d
cmpw 0x28(%rsp), %r13w
jg 0x328fd
movswq %r13w, %rbx
movzwl (%r12,%rbx,2), %r14d
cmpw %r15w, %r14w
je 0x328f3
movl 0x1c(%rsp), %edi
movl %r14d, %esi
movl %ebp, %edx
callq 0x326eb
movl %r14d, %r15d
movw %ax, (%r12,%rbx,2)
incl %r13d
jmp 0x328cb
movq 0x40(%rsp), %rcx
leaq (%r12,%rcx,2), %r12
movl 0x18(%rsp), %r13d
incl %r13d
jmp 0x328b5
movl 0x14(%rsp), %edx
movswq %dx, %rcx
leaq (%r12,%rcx,2), %rbx
movq 0x28(%rsp), %rsi
subl %edx, %esi
leal 0x2(,%rsi,2), %edx
movswq %dx, %rbp
subl %edi, %r15d
incl %r15d
leaq 0x2(,%rax,2), %rax
movq 0x40(%rsp), %r12
imulq %r12, %rax
leaq (%rax,%rcx,2), %rax
addq %rax, %r14
addq %r12, %r12
cmpw 0x20(%rsp), %r15w
jg 0x3296d
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x20f0
incl %r15d
addq %r12, %r14
jmp 0x3294f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq