Skip to content

Commit 0f8e804

Browse files
jpochylacmyr
authored andcommitted
mac: Create gradients with DeviceRGB colorspace
1 parent f19a261 commit 0f8e804

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

piet-coregraphics/src/gradient.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
//! core graphics gradient support
44
5-
use core_foundation::array::CFArray;
65
use core_graphics::{
76
base::CGFloat,
8-
color::CGColor,
9-
color_space::{kCGColorSpaceSRGB, CGColorSpace},
7+
color_space::CGColorSpace,
108
context::CGContextRef,
119
geometry::CGPoint,
1210
gradient::{CGGradient, CGGradientDrawingOptions},
@@ -63,21 +61,16 @@ impl Gradient {
6361
}
6462

6563
fn new_cg_gradient(stops: &[GradientStop]) -> CGGradient {
66-
unsafe {
67-
//FIXME: is this expensive enough we should be reusing it?
68-
let space = CGColorSpace::create_with_name(kCGColorSpaceSRGB).unwrap();
69-
let mut colors = Vec::<CGColor>::new();
70-
let mut locations = Vec::<CGFloat>::new();
71-
for GradientStop { pos, color } in stops {
72-
let (r, g, b, a) = Color::as_rgba(color);
73-
let color = CGColor::rgb(r, g, b, a);
74-
colors.push(color);
75-
locations.push(*pos as CGFloat);
76-
}
77-
78-
let colors = CFArray::from_CFTypes(&colors);
79-
CGGradient::create_with_colors(&space, &colors, &locations)
64+
//FIXME: is this expensive enough we should be reusing it?
65+
let space = CGColorSpace::create_device_rgb();
66+
let mut components = Vec::<CGFloat>::new();
67+
let mut locations = Vec::<CGFloat>::new();
68+
for GradientStop { pos, color } in stops {
69+
let (r, g, b, a) = Color::as_rgba(color);
70+
components.extend_from_slice(&[r, g, b, a]);
71+
locations.push(*pos as CGFloat);
8072
}
73+
CGGradient::create_with_color_components(&space, &components, &locations, locations.len())
8174
}
8275

8376
fn to_cgpoint(point: Point) -> CGPoint {

0 commit comments

Comments
 (0)