Bug 1382128 part 7 - Organize types in webrender_bindings. r?kats draft
authorRyan Hunt <rhunt@eqrion.net>
Wed, 19 Jul 2017 02:54:10 -0400
changeset 611123 d792e18cec28f2cc4ca5bce77053889753e3ea24
parent 611122 6ea83ad784ccc449b6a88b3ef16fdab131f2563e
child 611124 a34db9b8655d29004783f90d914c775113cbcd93
push id69133
push userbmo:rhunt@eqrion.net
push dateWed, 19 Jul 2017 08:14:37 +0000
reviewerskats
bugs1382128
milestone56.0a1
Bug 1382128 part 7 - Organize types in webrender_bindings. r?kats This commit organizes the structs in bindings.rs to be sorted by similarity. MozReview-Commit-ID: KIskAwDiJIc
gfx/webrender_bindings/src/bindings.rs
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -43,53 +43,16 @@ type WrIdNamespace = IdNamespace;
 type WrPipelineId = PipelineId;
 /// cbindgen:field-names=[mNamespace, mHandle]
 type WrImageKey = ImageKey;
 /// cbindgen:field-names=[mNamespace, mHandle]
 type WrFontKey = FontKey;
 /// cbindgen:field-names=[mNamespace, mHandle]
 type WrYuvColorSpace = YuvColorSpace;
 
-/// cbindgen:field-names=[mHandle]
-#[repr(C)]
-#[derive(Copy, Clone)]
-pub struct WrExternalImageId(pub u64);
-
-#[repr(u32)]
-#[derive(Copy, Clone)]
-pub enum WrFilterOpType {
-  Blur = 0,
-  Brightness = 1,
-  Contrast = 2,
-  Grayscale = 3,
-  HueRotate = 4,
-  Invert = 5,
-  Opacity = 6,
-  Saturate = 7,
-  Sepia = 8,
-}
-
-#[repr(C)]
-#[derive(Copy, Clone)]
-pub struct WrFilterOp {
-    filter_type: WrFilterOpType,
-    argument: c_float,
-}
-
-impl Into<ExternalImageId> for WrExternalImageId {
-    fn into(self) -> ExternalImageId {
-        ExternalImageId(self.0)
-    }
-}
-impl Into<WrExternalImageId> for ExternalImageId {
-    fn into(self) -> WrExternalImageId {
-        WrExternalImageId(self.0)
-    }
-}
-
 fn make_slice<'a, T>(ptr: *const T, len: usize) -> &'a [T] {
     if ptr.is_null() {
         &[]
     } else {
         unsafe { slice::from_raw_parts(ptr, len) }
     }
 }
 
@@ -97,16 +60,43 @@ fn make_slice_mut<'a, T>(ptr: *mut T, le
     if ptr.is_null() {
         &mut []
     } else {
         unsafe { slice::from_raw_parts_mut(ptr, len) }
     }
 }
 
 #[repr(C)]
+pub struct WrVecU8 {
+    data: *mut u8,
+    length: usize,
+    capacity: usize,
+}
+
+impl WrVecU8 {
+    fn to_vec(self) -> Vec<u8> {
+        unsafe { Vec::from_raw_parts(self.data, self.length, self.capacity) }
+    }
+    fn from_vec(mut v: Vec<u8>) -> WrVecU8 {
+        let w = WrVecU8 {
+            data: v.as_mut_ptr(),
+            length: v.len(),
+            capacity: v.capacity(),
+        };
+        mem::forget(v);
+        w
+    }
+}
+
+#[no_mangle]
+pub extern "C" fn wr_vec_u8_free(v: WrVecU8) {
+    v.to_vec();
+}
+
+#[repr(C)]
 pub struct ByteSlice {
     buffer: *const u8,
     len: usize,
 }
 
 impl ByteSlice {
     pub fn new(slice: &[u8]) -> ByteSlice {
         ByteSlice {
@@ -172,31 +162,58 @@ impl From<ImageMask> for WrImageMask {
             image: image_mask.image,
             rect: image_mask.rect.into(),
             repeat: image_mask.repeat,
         }
     }
 }
 
 #[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrComplexClipRegion {
-    rect: LayoutRect,
-    radii: BorderRadius,
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+pub struct WrImageDescriptor {
+    pub format: WrImageFormat,
+    pub width: u32,
+    pub height: u32,
+    pub stride: u32,
+    pub is_opaque: bool,
 }
 
-impl<'a> Into<ComplexClipRegion> for &'a WrComplexClipRegion {
-    fn into(self) -> ComplexClipRegion {
-        ComplexClipRegion {
-            rect: self.rect.into(),
-            radii: self.radii.into(),
+impl<'a> Into<ImageDescriptor> for &'a WrImageDescriptor {
+    fn into(self) -> ImageDescriptor {
+        ImageDescriptor {
+            width: self.width,
+            height: self.height,
+            stride: if self.stride != 0 {
+                Some(self.stride)
+            } else {
+                None
+            },
+            format: self.format,
+            is_opaque: self.is_opaque,
+            offset: 0,
         }
     }
 }
 
+/// cbindgen:field-names=[mHandle]
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct WrExternalImageId(pub u64);
+
+impl Into<ExternalImageId> for WrExternalImageId {
+    fn into(self) -> ExternalImageId {
+        ExternalImageId(self.0)
+    }
+}
+impl Into<WrExternalImageId> for ExternalImageId {
+    fn into(self) -> WrExternalImageId {
+        WrExternalImageId(self.0)
+    }
+}
+
 #[repr(u32)]
 #[allow(dead_code)]
 enum WrExternalImageType {
     NativeTexture,
     RawData,
 }
 
 #[repr(C)]
@@ -257,75 +274,51 @@ impl ExternalImageHandler for WrExternal
 
     fn unlock(&mut self,
               id: ExternalImageId,
               channel_index: u8) {
         (self.unlock_func)(self.external_image_obj, id.into(), channel_index);
     }
 }
 
-/// cbindgen:field-names=[mHandle]
-/// cbindgen:derive-lt=true
-/// cbindgen:derive-lte=true
 #[repr(C)]
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
-pub struct WrWindowId(u64);
-
-#[repr(C)]
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
-pub struct WrImageDescriptor {
-    pub format: WrImageFormat,
-    pub width: u32,
-    pub height: u32,
-    pub stride: u32,
-    pub is_opaque: bool,
+#[derive(Debug, Clone, Copy)]
+pub struct WrComplexClipRegion {
+    rect: LayoutRect,
+    radii: BorderRadius,
 }
 
-impl<'a> Into<ImageDescriptor> for &'a WrImageDescriptor {
-    fn into(self) -> ImageDescriptor {
-        ImageDescriptor {
-            width: self.width,
-            height: self.height,
-            stride: if self.stride != 0 {
-                Some(self.stride)
-            } else {
-                None
-            },
-            format: self.format,
-            is_opaque: self.is_opaque,
-            offset: 0,
+impl<'a> Into<ComplexClipRegion> for &'a WrComplexClipRegion {
+    fn into(self) -> ComplexClipRegion {
+        ComplexClipRegion {
+            rect: self.rect.into(),
+            radii: self.radii.into(),
         }
     }
 }
 
-#[repr(C)]
-pub struct WrVecU8 {
-    data: *mut u8,
-    length: usize,
-    capacity: usize,
+#[repr(u32)]
+#[derive(Copy, Clone)]
+pub enum WrFilterOpType {
+  Blur = 0,
+  Brightness = 1,
+  Contrast = 2,
+  Grayscale = 3,
+  HueRotate = 4,
+  Invert = 5,
+  Opacity = 6,
+  Saturate = 7,
+  Sepia = 8,
 }
 
-impl WrVecU8 {
-    fn to_vec(self) -> Vec<u8> {
-        unsafe { Vec::from_raw_parts(self.data, self.length, self.capacity) }
-    }
-    fn from_vec(mut v: Vec<u8>) -> WrVecU8 {
-        let w = WrVecU8 {
-            data: v.as_mut_ptr(),
-            length: v.len(),
-            capacity: v.capacity(),
-        };
-        mem::forget(v);
-        w
-    }
-}
-
-#[no_mangle]
-pub extern "C" fn wr_vec_u8_free(v: WrVecU8) {
-    v.to_vec();
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct WrFilterOp {
+    filter_type: WrFilterOpType,
+    argument: c_float,
 }
 
 /// cbindgen:derive-eq=false
 #[repr(C)]
 #[derive(Debug)]
 pub struct WrTransformProperty {
     pub id: u64,
     pub transform: LayoutTransform,
@@ -333,16 +326,23 @@ pub struct WrTransformProperty {
 
 #[repr(C)]
 #[derive(Copy, Clone, Debug)]
 pub struct WrOpacityProperty {
     pub id: u64,
     pub opacity: f32,
 }
 
+/// cbindgen:field-names=[mHandle]
+/// cbindgen:derive-lt=true
+/// cbindgen:derive-lte=true
+#[repr(C)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+pub struct WrWindowId(u64);
+
 fn get_proc_address(glcontext_ptr: *mut c_void,
                     name: &str)
                     -> *const c_void {
 
     extern "C" {
         fn get_proc_address_from_glcontext(glcontext_ptr: *mut c_void,
                                            procname: *const c_char)
                                            -> *const c_void;