Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. pub struct Surface<'a> {
  2. //this: cairo::ImageSurface,
  3. data: std::marker::PhantomData<&'a mut [u8]>,
  4. pub dimensions: (i32, i32),
  5. pub scale: i32,
  6. }
  7.  
  8. impl<'a> Surface<'a> {
  9. // XXX: Should we really hardcode the cairo::Format?
  10. pub fn new(data: &mut [u8], dimensions: (i32, i32), scale: i32) -> Result<Surface, ()> {
  11. /*let this = unsafe {
  12. cairo::ImageSurface::create_for_data::<&mut [u8]>(
  13. core::mem::transmute(data),
  14. cairo::Format::ARgb32,
  15. scale * dimensions.0,
  16. scale * dimensions.1,
  17. scale * dimensions.0 * 4,
  18. )?
  19. };*/
  20.  
  21. Ok(Surface{
  22. //this: this,
  23. data: std::marker::PhantomData,
  24. dimensions: dimensions,
  25. scale: scale,
  26. })
  27. }
  28.  
  29. pub fn make_context(&self) -> Context {
  30. Context::new(self)
  31. }
  32. }
  33.  
  34. impl<'a> Drop for Surface<'a> {
  35. fn drop(&mut self) {
  36. /*let pointer = self.this.to_raw_none();
  37. unsafe {
  38. let count = cairo_sys::cairo_surface_get_reference_count(pointer);
  39.  
  40. assert_eq!(count, 1, "multiple C references to surface remaining");
  41. drop(cairo::Surface::from_raw_none(pointer));
  42. }*/
  43. println!("Do stuff");
  44. }
  45. }
  46.  
  47. pub struct Context<'a> {
  48. //pub this: cairo::Context,
  49. surface: std::marker::PhantomData<&'a Surface<'a>>,
  50. }
  51.  
  52. impl<'a> Context<'a> {
  53. fn new(surface: &'a Surface) -> Context<'a> {
  54. //let this = cairo::Context::new(&surface.this);
  55. //this.scale(surface.scale.into(), surface.scale.into());
  56.  
  57. Context {
  58. //this: this,
  59. surface: std::marker::PhantomData,
  60. }
  61. }
  62. }
  63.  
  64. impl<'a> Drop for Context<'a> {
  65. fn drop(&mut self) {
  66. println!("Dropping context");
  67. }
  68. }
  69.  
  70. fn main() {
  71. let mut buf = [0; 4];
  72. let context: Context;
  73. {
  74. let surface = Surface::new(&mut buf, (32, 32), 1).expect("failed to create Cairo surface");
  75. context = surface.make_context();
  76.  
  77. //context.this.set_source_rgba(0.16, 0.16, 0.16, 0.50);
  78. //context.this.rectangle(0.0, 0.0, 32.0, 32.0);
  79. //context.this.fill();
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement