// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/classes/graphics/backends/cairo/surfacecairo.cpp
// Function: smooth::GUI::SurfaceCairo::Gradient(smooth::GUI::Rect const&, smooth::GUI::Color const&, smooth::GUI::Color const&, int)
S::Int S::GUI::SurfaceCairo::Gradient(const Rect &iRect, const Color &color1, const Color &color2, Int style)
{
	if (window == NIL) return Success();

	Rect	 rect = rightToLeft.TranslateRect(iRect);

	/* Setup colors.
	 */
	Color	 c1   = (style == OR_HORZ && rightToLeft.GetRightToLeft()) ? color2 : color1;
	Color	 c2   = (style == OR_HORZ && rightToLeft.GetRightToLeft()) ? color1 : color2;

	/* Setup Cairo objects and draw gradient.
	 */
	cairo_pattern_t	*pattern = cairo_pattern_create_linear(0, 0, style == OR_HORZ ? rect.GetWidth()	 : 0,
								     style == OR_VERT ? rect.GetHeight() : 0);

	cairo_pattern_add_color_stop_rgb(pattern, 0, c1.GetRed() / 255.0, c1.GetGreen() / 255.0, c1.GetBlue() / 255.0);
	cairo_pattern_add_color_stop_rgb(pattern, 1, c2.GetRed() / 255.0, c2.GetGreen() / 255.0, c2.GetBlue() / 255.0);

	if (!painting)
	{
		CreateCairoContext();

		cairo_set_source(context, pattern);
		cairo_rectangle(context, rect.left, rect.top, rect.GetWidth(), rect.GetHeight());
		cairo_fill(context);

		DestroyCairoContext();
	}

	cairo_set_source(paintContextCairo, pattern);
	cairo_rectangle(paintContextCairo, rect.left, rect.top, rect.GetWidth(), rect.GetHeight());
	cairo_fill(paintContextCairo);

	cairo_pattern_destroy(pattern);

	return Success();
}

// Assembly:
cmpq $0x0, 0x50(%rdi)
je 0xbf92a
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %ebp
movq %rcx, %r12
movq %rdx, %r13
movq %rdi, 0x20(%rsp)
leaq 0x28(%rdi), %r15
movq %r15, %rdi
callq 0x63e10
movq %rdx, %rbx
cmpl $0x1, %ebp
jne 0xbf751
movq %r15, %rdi
movq %rax, %rbp
callq 0x63e62
testb %al, %al
movq %r13, %rax
cmovneq %r12, %rax
movq 0x8(%rax), %r14
movq %r15, %rdi
callq 0x63e62
testb %al, %al
cmovneq %r13, %r12
movq 0x8(%r12), %r15
movl %ebx, %eax
subl %ebp, %eax
cvtsi2sd %eax, %xmm2
xorpd %xmm3, %xmm3
movq %rbp, %r13
jmp 0xbf783
movq %rax, %rcx
movq 0x8(%r13), %r14
movq 0x8(%r12), %r15
xorpd %xmm2, %xmm2
cmpl $0x2, %ebp
jne 0xbf77c
movq %rbx, %rax
shrq $0x20, %rax
movq %rcx, %r13
shrq $0x20, %rcx
subl %ecx, %eax
cvtsi2sd %eax, %xmm3
jmp 0xbf783
xorpd %xmm3, %xmm3
movq %rcx, %r13
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
callq 0x59300
movq %rax, %r12
movl $0xff, %ebp
movl %r14d, %eax
andl %ebp, %eax
cvtsi2sd %eax, %xmm1
movsd 0x23ba9(%rip), %xmm0    # 0xe3350
divsd %xmm0, %xmm1
movl %r14d, %eax
shrl $0x8, %eax
andl %ebp, %eax
cvtsi2sd %eax, %xmm2
divsd %xmm0, %xmm2
shrl $0x10, %r14d
andl %ebp, %r14d
cvtsi2sd %r14d, %xmm3
divsd %xmm0, %xmm3
xorpd %xmm0, %xmm0
movq %r12, %rdi
callq 0x59190
movl %r15d, %eax
andl %ebp, %eax
cvtsi2sd %eax, %xmm1
movsd 0x23b68(%rip), %xmm0    # 0xe3350
divsd %xmm0, %xmm1
movl %r15d, %eax
shrl $0x8, %eax
andl %ebp, %eax
cvtsi2sd %eax, %xmm2
divsd %xmm0, %xmm2
shrl $0x10, %r15d
andl %ebp, %r15d
cvtsi2sd %r15d, %xmm3
divsd %xmm0, %xmm3
movsd 0x23b5c(%rip), %xmm0    # 0xe3370
movq %r12, %rdi
callq 0x59190
movq 0x20(%rsp), %r14
cmpw $0x0, 0xa(%r14)
je 0xbf865
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r13, %rax
shrq $0x20, %rax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
movl %ebx, %ecx
subl %r13d, %ecx
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x8(%rsp)
shrq $0x20, %rbx
subl %eax, %ebx
cvtsi2sd %ebx, %xmm0
movsd %xmm0, (%rsp)
jmp 0xbf8d6
movq %r14, %rdi
callq 0xbdda4
movq 0xc0(%r14), %rdi
movq %r12, %rsi
callq 0x59a10
movq 0xc0(%r14), %rdi
cvtsi2sd %r13d, %xmm0
movq %r13, %rax
shrq $0x20, %rax
cvtsi2sd %eax, %xmm1
movl %ebx, %ecx
subl %r13d, %ecx
cvtsi2sd %ecx, %xmm2
shrq $0x20, %rbx
subl %eax, %ebx
cvtsi2sd %ebx, %xmm3
movsd %xmm0, 0x18(%rsp)
movsd %xmm1, 0x10(%rsp)
movsd %xmm2, 0x8(%rsp)
movsd %xmm3, (%rsp)
callq 0x576b0
movq 0xc0(%r14), %rdi
callq 0x58fc0
movq %r14, %rdi
callq 0xbddf8
movq 0xd0(%r14), %rdi
movq %r12, %rsi
callq 0x59a10
movq 0xd0(%r14), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movsd (%rsp), %xmm3
callq 0x576b0
movq 0xd0(%r14), %rdi
callq 0x58fc0
movq %r12, %rdi
callq 0x59400
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
xorl %eax, %eax
retq
nop