@@ -31,15 +31,15 @@ use cocoa::base::{id, nil, BOOL, NO, YES};
3131use cocoa:: foundation:: {
3232 NSAutoreleasePool , NSInteger , NSPoint , NSRect , NSSize , NSString , NSUInteger ,
3333} ;
34+ use core_graphics:: context:: CGContextRef ;
35+ use foreign_types:: ForeignTypeRef ;
3436use lazy_static:: lazy_static;
37+ use log:: { error, info} ;
3538use objc:: declare:: ClassDecl ;
3639use objc:: rc:: WeakPtr ;
3740use objc:: runtime:: { Class , Object , Sel } ;
3841use objc:: { class, msg_send, sel, sel_impl} ;
3942
40- use cairo:: { Context , QuartzSurface } ;
41- use log:: { error, info} ;
42-
4343use crate :: kurbo:: { Point , Rect , Size , Vec2 } ;
4444use crate :: piet:: { Piet , RenderContext } ;
4545
@@ -574,23 +574,17 @@ extern "C" fn mods_changed(this: &mut Object, _: Sel, nsevent: id) {
574574extern "C" fn draw_rect ( this : & mut Object , _: Sel , dirtyRect : NSRect ) {
575575 unsafe {
576576 let context: id = msg_send ! [ class![ NSGraphicsContext ] , currentContext] ;
577- // TODO: probably should use a better type than void pointer, but it's not obvious what's best.
578- // cairo_sys::CGContextRef would be better documentation-wise, but it's a type alias.
579- let cgcontext: * mut c_void = msg_send ! [ context, CGContext ] ;
580- // TODO: use width and height from view size
581- let frame = NSView :: frame ( this as * mut _ ) ;
582- let width = frame. size . width as u32 ;
583- let height = frame. size . height as u32 ;
577+ //FIXME: when core_graphics is at 0.20, we should be able to use
578+ //core_graphics::sys::CGContextRef as our pointer type.
579+ let cgcontext_ptr: * mut <CGContextRef as ForeignTypeRef >:: CType =
580+ msg_send ! [ context, CGContext ] ;
581+ let cgcontext_ref = CGContextRef :: from_ptr_mut ( cgcontext_ptr) ;
582+
584583 let rect = Rect :: from_origin_size (
585584 ( dirtyRect. origin . x , dirtyRect. origin . y ) ,
586585 ( dirtyRect. size . width , dirtyRect. size . height ) ,
587586 ) ;
588- let cairo_surface =
589- QuartzSurface :: create_for_cg_context ( cgcontext, width, height) . expect ( "cairo surface" ) ;
590- let mut cairo_ctx = Context :: new ( & cairo_surface) ;
591- cairo_ctx. set_source_rgb ( 0.0 , 0.5 , 0.0 ) ;
592- cairo_ctx. paint ( ) ;
593- let mut piet_ctx = Piet :: new ( & mut cairo_ctx) ;
587+ let mut piet_ctx = Piet :: new_y_down ( cgcontext_ref) ;
594588 let view_state: * mut c_void = * this. get_ivar ( "viewState" ) ;
595589 let view_state = & mut * ( view_state as * mut ViewState ) ;
596590 let anim = ( * view_state) . handler . paint ( & mut piet_ctx, rect) ;
0 commit comments