|
2 | 2 |
|
3 | 3 | //! core graphics gradient support
|
4 | 4 |
|
5 |
| -use core_foundation::array::CFArray; |
6 | 5 | use core_graphics::{
|
7 | 6 | base::CGFloat,
|
8 |
| - color::CGColor, |
9 |
| - color_space::{kCGColorSpaceSRGB, CGColorSpace}, |
| 7 | + color_space::CGColorSpace, |
10 | 8 | context::CGContextRef,
|
11 | 9 | geometry::CGPoint,
|
12 | 10 | gradient::{CGGradient, CGGradientDrawingOptions},
|
@@ -63,21 +61,16 @@ impl Gradient {
|
63 | 61 | }
|
64 | 62 |
|
65 | 63 | 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); |
80 | 72 | }
|
| 73 | + CGGradient::create_with_color_components(&space, &components, &locations, locations.len()) |
81 | 74 | }
|
82 | 75 |
|
83 | 76 | fn to_cgpoint(point: Point) -> CGPoint {
|
|
0 commit comments