// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_canvas.c
// Function: lv_canvas_draw_line
void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, const lv_style_t * style)
{
    LV_ASSERT_OBJ(canvas, LV_OBJX_NAME);
    LV_ASSERT_NULL(style);

    lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);

    /* Create a dummy display to fool the lv_draw function.
     * It will think it draws to real screen. */
    lv_area_t mask;
    mask.x1 = 0;
    mask.x2 = dsc->header.w - 1;
    mask.y1 = 0;
    mask.y2 = dsc->header.h - 1;

    lv_disp_t disp;
    memset(&disp, 0, sizeof(lv_disp_t));

    lv_disp_buf_t disp_buf;
    lv_disp_buf_init(&disp_buf, (void *)dsc->data, NULL, dsc->header.w * dsc->header.h);
    lv_area_copy(&disp_buf.area, &mask);

    lv_disp_drv_init(&disp.driver);

    disp.driver.buffer  = &disp_buf;
    disp.driver.hor_res = dsc->header.w;
    disp.driver.ver_res = dsc->header.h;

#if LV_ANTIALIAS
    /*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/
    lv_color_t ctransp = LV_COLOR_TRANSP;
    if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED &&
        style->body.main_color.full == ctransp.full &&
        style->body.grad_color.full == ctransp.full)
    {
        disp.driver.antialiasing = 0;
    }
#endif

    lv_disp_t * refr_ori = lv_refr_get_disp_refreshing();
    lv_refr_set_disp_refreshing(&disp);

    lv_style_t circle_style_tmp; /*If rounded...*/
    if(style->line.rounded) {
        lv_style_copy(&circle_style_tmp, style);
        circle_style_tmp.body.radius     = LV_RADIUS_CIRCLE;
        circle_style_tmp.body.main_color = style->line.color;
        circle_style_tmp.body.grad_color = style->line.color;
        circle_style_tmp.body.opa        = style->line.opa;
    }
    lv_area_t circle_area;
    uint32_t i;
    for(i = 0; i < point_cnt - 1; i++) {
        lv_draw_line(&points[i], &points[i + 1], &mask, style, LV_OPA_COVER);
        
        /*Draw circle on the joints if enabled*/
        if(style->line.rounded) {
            circle_area.x1 = points[i].x - ((style->line.width - 1) >> 1) - ((style->line.width - 1) & 0x1);
            circle_area.y1 = points[i].y - ((style->line.width - 1) >> 1) - ((style->line.width - 1) & 0x1);
            circle_area.x2 = points[i].x + ((style->line.width - 1) >> 1);
            circle_area.y2 = points[i].y + ((style->line.width - 1) >> 1);
            lv_draw_rect(&circle_area, &mask, &circle_style_tmp, LV_OPA_COVER);
        }
    }
    /*Draw circle on the last point too if enabled*/
    if(style->line.rounded) {
        circle_area.x1 = points[i].x - ((style->line.width - 1) >> 1) - ((style->line.width - 1) & 0x1);
        circle_area.y1 = points[i].y - ((style->line.width - 1) >> 1) - ((style->line.width - 1) & 0x1);
        circle_area.x2 = points[i].x + ((style->line.width - 1) >> 1);
        circle_area.y2 = points[i].y + ((style->line.width - 1) >> 1);
        lv_draw_rect(&circle_area, &mask, &circle_style_tmp, LV_OPA_COVER);
    }
    
    lv_refr_set_disp_refreshing(refr_ori);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %rcx, %r15
movl %edx, %r14d
movq %rsi, %r12
movq %rdi, %rbx
callq 0x7994
testb %al, %al
je 0x17415
movq %r15, %rdi
callq 0x7994
testb %al, %al
je 0x17426
movq %r12, 0x18(%rsp)
movq %r14, 0x10(%rsp)
movq %rbx, %rdi
callq 0x16510
andw $0x0, (%rsp)
movq %rax, %r14
movl (%rax), %r12d
movl %r12d, %r13d
shrl $0xa, %r13d
movl $0x7ff, %ebp            # imm = 0x7FF
andl %ebp, %r13d
leal -0x1(%r13), %eax
movw %ax, 0x4(%rsp)
andw $0x0, 0x2(%rsp)
shrl $0x15, %r12d
leal -0x1(%r12), %eax
movw %ax, 0x6(%rsp)
leaq 0x98(%rsp), %rbx
movl $0x1a0, %edx            # imm = 0x1A0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20a0
movq 0x8(%r14), %rsi
imull %r13d, %r12d
leaq 0x70(%rsp), %r13
movq %r13, %rdi
xorl %edx, %edx
movl %r12d, %ecx
callq 0x7b7f
movq (%rsp), %rax
movq %rax, 0x1c(%r13)
movq %rbx, %rdi
callq 0x7b5c
movq %r13, 0x8(%rbx)
movl (%r14), %eax
movl %eax, %ecx
shrl $0xa, %ecx
andl %ebp, %ecx
movw %cx, (%rbx)
movl %eax, %ecx
shrl $0x15, %ecx
movw %cx, 0x2(%rbx)
andl $0x1f, %eax
cmpl $0x6, %eax
jne 0x17337
cmpw $0x7e0, 0x2(%r15)       # imm = 0x7E0
jne 0x17337
cmpw $0x7e0, 0x4(%r15)       # imm = 0x7E0
jne 0x17337
andb $-0x2, 0xa8(%rsp)
callq 0x6e0e
movq %rax, 0x20(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x6e16
testb $0x1, 0x41(%r15)
movq 0x10(%rsp), %rbp
je 0x17384
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x74d4
movw $0x7c18, 0x6(%rbx)      # imm = 0x7C18
movzwl 0x3c(%r15), %eax
movw %ax, 0x2(%rbx)
movw %ax, 0x4(%rbx)
movb 0x40(%r15), %al
movb %al, 0x8(%rbx)
decl %ebp
movq %rsp, %r13
leaq 0x28(%rsp), %r12
movq 0x18(%rsp), %r14
movq %rbp, 0x10(%rsp)
subq $0x1, %rbp
jb 0x17437
leaq 0x4(%r14), %rbx
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
movl $0xff, %r8d
callq 0x37138
testb $0x1, 0x41(%r15)
je 0x17410
movzwl (%r14), %eax
movswl 0x3e(%r15), %ecx
decl %ecx
movl %ecx, %edx
shrl %edx
andl $0x1, %ecx
addl %edx, %ecx
movl %eax, %esi
subl %ecx, %esi
movw %si, 0x8(%rsp)
movzwl 0x2(%r14), %esi
addl %edx, %eax
addl %esi, %edx
subl %ecx, %esi
movw %si, 0xa(%rsp)
movw %ax, 0xc(%rsp)
movw %dx, 0xe(%rsp)
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movl $0xff, %ecx
callq 0x336d4
movq %rbx, %r14
jmp 0x17398
leaq 0x23d28(%rip), %rdi     # 0x3b144
movq %rbx, %rsi
callq 0x7b01
jmp 0x17424
leaq 0x23d17(%rip), %rdi     # 0x3b144
movq %r15, %rsi
callq 0x7b01
jmp 0x17435
testb $0x1, 0x41(%r15)
je 0x17493
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r9
movzwl (%r9,%r8,4), %eax
movswl 0x3e(%r15), %ecx
decl %ecx
movl %ecx, %edx
shrl %edx
andl $0x1, %ecx
addl %edx, %ecx
movl %eax, %esi
subl %ecx, %esi
leaq 0x8(%rsp), %rdi
movw %si, (%rdi)
movzwl 0x2(%r9,%r8,4), %esi
addl %edx, %eax
addl %esi, %edx
subl %ecx, %esi
movw %si, 0x2(%rdi)
movw %ax, 0x4(%rdi)
movw %dx, 0x6(%rdi)
movq %rsp, %rsi
leaq 0x28(%rsp), %rdx
movl $0xff, %ecx
callq 0x336d4
movq 0x20(%rsp), %rdi
callq 0x6e16
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq