// Copyright 2019 The Servo Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. use crate::{Peek, Poke}; use euclid::{Point2D, Rect, Box2D, SideOffsets2D, Size2D, Transform3D, Vector2D}; unsafe impl Poke for Point2D { #[inline(always)] fn max_size() -> usize { 2 * T::max_size() } #[inline(always)] unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { let bytes = self.x.poke_into(bytes); let bytes = self.y.poke_into(bytes); bytes } } impl Peek for Point2D { #[inline(always)] unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { let bytes = T::peek_from(bytes, &mut (*output).x); let bytes = T::peek_from(bytes, &mut (*output).y); bytes } } unsafe impl Poke for Rect { #[inline(always)] fn max_size() -> usize { Point2D::::max_size() + Size2D::::max_size() } #[inline(always)] unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { let bytes = self.origin.poke_into(bytes); let bytes = self.size.poke_into(bytes); bytes } } impl Peek for Rect { #[inline(always)] unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { let bytes = Point2D::::peek_from(bytes, &mut (*output).origin); let bytes = Size2D::::peek_from(bytes, &mut (*output).size); bytes } } unsafe impl Poke for Box2D { #[inline(always)] fn max_size() -> usize { Point2D::::max_size() * 2 } #[inline(always)] unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { let bytes = self.min.poke_into(bytes); let bytes = self.max.poke_into(bytes); bytes } } impl Peek for Box2D { #[inline(always)] unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { let bytes = Point2D::::peek_from(bytes, &mut (*output).min); let bytes = Point2D::::peek_from(bytes, &mut (*output).max); bytes } } unsafe impl Poke for SideOffsets2D { #[inline(always)] fn max_size() -> usize { 4 * T::max_size() } #[inline(always)] unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { let bytes = self.top.poke_into(bytes); let bytes = self.right.poke_into(bytes); let bytes = self.bottom.poke_into(bytes); let bytes = self.left.poke_into(bytes); bytes } } impl Peek for SideOffsets2D { #[inline(always)] unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { let bytes = T::peek_from(bytes, &mut (*output).top); let bytes = T::peek_from(bytes, &mut (*output).right); let bytes = T::peek_from(bytes, &mut (*output).bottom); let bytes = T::peek_from(bytes, &mut (*output).left); bytes } } unsafe impl Poke for Size2D { #[inline(always)] fn max_size() -> usize { 2 * T::max_size() } #[inline(always)] unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { let bytes = self.width.poke_into(bytes); let bytes = self.height.poke_into(bytes); bytes } } impl Peek for Size2D { #[inline(always)] unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { let bytes = T::peek_from(bytes, &mut (*output).width); let bytes = T::peek_from(bytes, &mut (*output).height); bytes } } unsafe impl Poke for Transform3D { #[inline(always)] fn max_size() -> usize { 16 * T::max_size() } #[inline(always)] unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { let bytes = self.m11.poke_into(bytes); let bytes = self.m12.poke_into(bytes); let bytes = self.m13.poke_into(bytes); let bytes = self.m14.poke_into(bytes); let bytes = self.m21.poke_into(bytes); let bytes = self.m22.poke_into(bytes); let bytes = self.m23.poke_into(bytes); let bytes = self.m24.poke_into(bytes); let bytes = self.m31.poke_into(bytes); let bytes = self.m32.poke_into(bytes); let bytes = self.m33.poke_into(bytes); let bytes = self.m34.poke_into(bytes); let bytes = self.m41.poke_into(bytes); let bytes = self.m42.poke_into(bytes); let bytes = self.m43.poke_into(bytes); let bytes = self.m44.poke_into(bytes); bytes } } impl Peek for Transform3D { #[inline(always)] unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { let bytes = T::peek_from(bytes, &mut (*output).m11); let bytes = T::peek_from(bytes, &mut (*output).m12); let bytes = T::peek_from(bytes, &mut (*output).m13); let bytes = T::peek_from(bytes, &mut (*output).m14); let bytes = T::peek_from(bytes, &mut (*output).m21); let bytes = T::peek_from(bytes, &mut (*output).m22); let bytes = T::peek_from(bytes, &mut (*output).m23); let bytes = T::peek_from(bytes, &mut (*output).m24); let bytes = T::peek_from(bytes, &mut (*output).m31); let bytes = T::peek_from(bytes, &mut (*output).m32); let bytes = T::peek_from(bytes, &mut (*output).m33); let bytes = T::peek_from(bytes, &mut (*output).m34); let bytes = T::peek_from(bytes, &mut (*output).m41); let bytes = T::peek_from(bytes, &mut (*output).m42); let bytes = T::peek_from(bytes, &mut (*output).m43); let bytes = T::peek_from(bytes, &mut (*output).m44); bytes } } unsafe impl Poke for Vector2D { #[inline(always)] fn max_size() -> usize { 2 * T::max_size() } #[inline(always)] unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { let bytes = self.x.poke_into(bytes); let bytes = self.y.poke_into(bytes); bytes } } impl Peek for Vector2D { #[inline(always)] unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { let bytes = T::peek_from(bytes, &mut (*output).x); let bytes = T::peek_from(bytes, &mut (*output).y); bytes } }