// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movl %ecx, %ebp
cmpb $0x10, %bpl
jb 0x35a62
movq %rsi, %rax
movq %rdi, %rsi
movl %edx, 0x14(%rsp)
leaq 0x30(%rsp), %rdi
movq %rax, %rdx
callq 0x28d24
testb %al, %al
je 0x35a62
cmpb $-0x4, %bpl
movzbl %bpl, %r13d
movl $0xff, %eax
cmovbl %r13d, %eax
movl %eax, 0x18(%rsp)
callq 0x7293
movq %rax, %rdi
callq 0x85d8
movzwl 0x30(%rsp), %r14d
movl 0x1c(%rax), %ecx
subl %ecx, %r14d
movzwl 0x32(%rsp), %esi
movzwl 0x1e(%rax), %edx
subl %edx, %esi
movl %esi, 0x10(%rsp)
movzwl 0x34(%rsp), %ebx
subl %ecx, %ebx
movzwl 0x36(%rsp), %esi
subl %edx, %esi
movl %esi, 0xc(%rsp)
movzwl 0x20(%rax), %r12d
subl %ecx, %r12d
incl %r12d
movq 0x10(%rax), %r15
callq 0x7293
movq %r15, %rdx
cmpq $0x0, 0x28(%rax)
movq %rbx, 0x20(%rsp)
movq %r15, 0x28(%rsp)
je 0x358cd
movq %rax, %r15
cmpw %r14w, %bx
movl 0x10(%rsp), %eax
movl 0xc(%rsp), %ecx
jl 0x35a62
movzbl 0x18(%rsp), %ebp
movswl %r12w, %edx
movl 0x14(%rsp), %ebx
movq 0x28(%rsp), %r12
movl %r14d, 0x1c(%rsp)
cmpw %cx, %ax
jg 0x358b4
movswl 0x1c(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x10(%rsp), %r13d
movl %ebp, (%rsp)
movswl %r13w, %r13d
movq %r15, %rdi
movq %r12, %rsi
movl 0x18(%rsp), %ecx
movl %edx, %r14d
movl %r13d, %r8d
movl %ebx, %r9d
callq *0x28(%r15)
movl %r14d, %edx
movl 0xc(%rsp), %ecx
incl %r13d
cmpw %cx, %r13w
jle 0x35886
movl 0x1c(%rsp), %r14d
incl %r14d
cmpw 0x20(%rsp), %r14w
movl 0x10(%rsp), %eax
jle 0x3586e
jmp 0x35a62
movl 0x10(%rsp), %r11d
movswq %r11w, %rcx
movswq %r12w, %r12
movq %r12, %rax
imulq %rcx, %rax
leaq (%rdx,%rax,2), %rax
cmpb $-0x4, %bpl
jb 0x35988
movq 0x20(%rsp), %r9
cmpw %r14w, %r9w
movl 0xc(%rsp), %edi
movl 0x14(%rsp), %r8d
jl 0x35917
movl %r14d, %edx
movswq %dx, %rsi
movw %r8w, (%rax,%rsi,2)
incl %edx
cmpw %r9w, %dx
jle 0x35906
incl %r11d
cmpw %di, %r11w
jg 0x35a62
movswq %r14w, %rdx
leaq (%rax,%rdx,2), %rbx
movq 0x20(%rsp), %rax
subl %r14d, %eax
leal 0x2(,%rax,2), %eax
movswq %ax, %r15
leaq 0x2(,%rcx,2), %rax
imulq %r12, %rax
leaq (%rax,%rdx,2), %rax
addq %rax, 0x28(%rsp)
addq %r12, %r12
movq 0x28(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl %r11d, %ebp
callq 0x20f0
movl %ebp, %r11d
incl %r11d
addq %r12, %r14
movq %r14, 0x28(%rsp)
cmpw 0xc(%rsp), %r11w
jle 0x35957
jmp 0x35a62
cmpw 0xc(%rsp), %r11w
jg 0x35a62
movl 0x14(%rsp), %edi
movzwl %di, %ecx
movl %ecx, %edx
shrl $0xb, %edx
imull %r13d, %edx
shrl $0x5, %ecx
andl $0x3f, %ecx
imull %r13d, %ecx
andl $0x1f, %edi
imull %r13d, %edi
movl %edx, %esi
andl $0x1f00, %esi           # imm = 0x1F00
movl %edi, %ebx
shrl $0x8, %edi
leal (%rdi,%rsi,8), %edi
movl %ecx, %esi
shrl $0x3, %esi
andl $-0x20, %esi
orl %edi, %esi
xorl $0xff, %r13d
xorl %edi, %edi
movq 0x20(%rsp), %r15
cmpw %r14w, %r15w
jl 0x35a4f
movl %r14d, %r8d
movl %ebx, %ebp
movswq %r8w, %r8
movzwl (%rax,%r8,2), %r9d
cmpw %di, %r9w
je 0x35a41
movzwl %r9w, %esi
movl %esi, %edi
shrl $0xb, %edi
imull %r13d, %edi
addl %edx, %edi
andl $0x3f00, %edi           # imm = 0x3F00
movl %esi, %r10d
shrl $0x5, %r10d
andl $0x3f, %r10d
imull %r13d, %r10d
addl %ecx, %r10d
shrl $0x3, %r10d
andl $0x7e0, %r10d           # imm = 0x7E0
andl $0x1f, %esi
imull %r13d, %esi
addl %ebp, %esi
shrl $0x8, %esi
andl $0x1f, %esi
leal (%rsi,%rdi,8), %esi
orl %r10d, %esi
movl %r9d, %edi
movw %si, (%rax,%r8,2)
incl %r8d
cmpw %r15w, %r8w
jle 0x359e8
leaq (%rax,%r12,2), %rax
incl %r11d
cmpw 0xc(%rsp), %r11w
jle 0x359dd
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq