// File: /workspace/github_c_makefile_star2_O1/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 0x355f2
movq %rsi, %rax
movq %rdi, %rsi
movl %edx, 0x14(%rsp)
leaq 0x30(%rsp), %rdi
movq %rax, %rdx
callq 0x2865e
testb %al, %al
je 0x355f2
cmpb $-0x4, %bpl
movzbl %bpl, %eax
movl $0xff, %ecx
cmovbl %eax, %ecx
movl %ecx, 0x10(%rsp)
callq 0x72ad
movq %rax, %rdi
callq 0x8660
movzwl 0x30(%rsp), %r14d
movl 0x1c(%rax), %ecx
subl %ecx, %r14d
movzwl 0x32(%rsp), %ebx
movzwl 0x1e(%rax), %edx
subl %edx, %ebx
movzwl 0x34(%rsp), %r13d
subl %ecx, %r13d
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 0x72ad
movq %r15, %rdx
cmpq $0x0, 0x28(%rax)
movq %r13, 0x20(%rsp)
movq %r15, 0x28(%rsp)
je 0x35445
movq %rax, %r15
movl %ebx, 0x18(%rsp)
cmpw %r14w, %r13w
movl 0xc(%rsp), %eax
jl 0x355f2
movzbl 0x10(%rsp), %ebp
movswl %r12w, %edx
movl 0x14(%rsp), %ebx
movq 0x28(%rsp), %r12
movl %r14d, 0x1c(%rsp)
cmpw %ax, 0x18(%rsp)
jg 0x35430
movswl 0x1c(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x18(%rsp), %r13d
movl %ebp, (%rsp)
movswl %r13w, %r13d
movq %r15, %rdi
movq %r12, %rsi
movl %edx, %r14d
movl 0x10(%rsp), %ecx
movl %r13d, %r8d
movl %ebx, %r9d
callq *0x28(%r15)
movl %r14d, %edx
movl 0xc(%rsp), %eax
incl %r13d
cmpw %ax, %r13w
jle 0x35402
movl 0x1c(%rsp), %r14d
incl %r14d
cmpw 0x20(%rsp), %r14w
jle 0x353e8
jmp 0x355f2
movswq %bx, %rcx
movswq %r12w, %r12
movq %r12, %rax
imulq %rcx, %rax
leaq (%rdx,%rax,2), %rax
cmpb $-0x4, %bpl
jb 0x354f7
movq 0x20(%rsp), %r9
cmpw %r14w, %r9w
movl 0xc(%rsp), %edi
movl 0x14(%rsp), %r8d
jl 0x3548a
movl %r14d, %edx
movswq %dx, %rsi
movw %r8w, (%rax,%rsi,2)
incl %edx
cmpw %r9w, %dx
jle 0x35479
incl %ebx
cmpw %di, %bx
jg 0x355f2
movl %ebx, %ebp
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
callq 0x20f0
movl %ebp, %eax
incl %eax
addq %r12, %r14
movq %r14, 0x28(%rsp)
movl %eax, %ebp
cmpw 0xc(%rsp), %ax
jle 0x354ca
jmp 0x355f2
cmpw 0xc(%rsp), %bx
jg 0x355f2
movl %ebx, %r10d
movl 0x14(%rsp), %r8d
movzwl %r8w, %ecx
movl %ecx, %edx
shrl $0xb, %edx
movzbl 0x10(%rsp), %esi
imull %esi, %edx
shrl $0x5, %ecx
andl $0x3f, %ecx
imull %esi, %ecx
andl $0x1f, %r8d
imull %esi, %r8d
movl %edx, %edi
andl $0x1f00, %edi           # imm = 0x1F00
movl %r8d, %ebp
shrl $0x8, %r8d
leal (%r8,%rdi,8), %r8d
movl %ecx, %edi
shrl $0x3, %edi
andl $-0x20, %edi
orl %r8d, %edi
xorl $0xff, %esi
xorl %r8d, %r8d
movl %r14d, %r15d
movq 0x20(%rsp), %r13
cmpw %r14w, %r13w
jge 0x35566
movl %r10d, %ebx
jmp 0x355db
movl %r14d, %r9d
movl %r10d, %ebx
movl %ebp, %r14d
movswq %r9w, %r9
movzwl (%rax,%r9,2), %r10d
cmpw %r8w, %r10w
je 0x355cd
movzwl %r10w, %edi
movl %edi, %r8d
shrl $0xb, %r8d
imull %esi, %r8d
addl %edx, %r8d
andl $0x3f00, %r8d           # imm = 0x3F00
movl %edi, %r11d
shrl $0x5, %r11d
andl $0x3f, %r11d
imull %esi, %r11d
addl %ecx, %r11d
shrl $0x3, %r11d
andl $0x7e0, %r11d           # imm = 0x7E0
andl $0x1f, %edi
imull %esi, %edi
addl %r14d, %edi
shrl $0x8, %edi
andl $0x1f, %edi
leal (%rdi,%r8,8), %edi
orl %r11d, %edi
movl %r10d, %r8d
movw %di, (%rax,%r9,2)
incl %r9d
cmpw %r13w, %r9w
jle 0x3556f
leaq (%rax,%r12,2), %rax
incl %ebx
movl %ebx, %r10d
cmpw 0xc(%rsp), %bx
movl %r15d, %r14d
jle 0x3555b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq