Skip to content

BS2 tracking PR #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion skia-safe/src/codec/_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ variant_name!(SelectionPolicy::PreferStillImage, selection_policy_naming);
pub use sb::SkCodec_ZeroInitialized as ZeroInitialized;
variant_name!(ZeroInitialized::Yes, zero_initialized_naming);

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct Options {
pub zero_initialized: ZeroInitialized,
pub subset: Option<IRect>,
Expand Down
2 changes: 1 addition & 1 deletion skia-safe/src/codec/encoded_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use skia_bindings::{self as sb, SkEncodedOrigin};

/// These values match the orientation www.exif.org/Exif2-2.PDF.
#[repr(i32)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
pub enum EncodedOrigin {
/// Default
TopLeft = SkEncodedOrigin::TopLeft as _,
Expand Down
34 changes: 19 additions & 15 deletions skia-safe/src/core/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::ops::{BitAnd, BitOr, Index, IndexMut, Mul};
// Note: SkColor _is_ a u32, and therefore its components are
// endian dependent, so we can't expose it as (transmuted) individual
// argb fields.
#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Default, Debug)]
#[repr(transparent)]
pub struct Color(SkColor);

Expand Down Expand Up @@ -69,8 +69,8 @@ impl Color {
Self(argb)
}

// note: we don't use the u8cpu type in the arguments here, because we trust the Rust
// compiler to optimize the storage type.
// We don't use the `u8cpu` Skia type in the arguments here, because we trust the Rust compiler
// to optimize the parameter layout.
pub const fn from_argb(a: u8, r: u8, g: u8, b: u8) -> Color {
Self(((a as u8cpu) << 24) | ((r as u8cpu) << 16) | ((g as u8cpu) << 8) | (b as u8cpu))
}
Expand All @@ -79,24 +79,24 @@ impl Color {
Self::from_argb(0xff, r, g, b)
}

pub fn a(self) -> u8 {
(self.into_native() >> 24) as _
pub const fn a(self) -> u8 {
(self.0 >> 24) as _
}

pub fn r(self) -> u8 {
(self.into_native() >> 16) as _
pub const fn r(self) -> u8 {
(self.0 >> 16) as _
}

pub fn g(self) -> u8 {
(self.into_native() >> 8) as _
pub const fn g(self) -> u8 {
(self.0 >> 8) as _
}

pub fn b(self) -> u8 {
self.into_native() as _
pub const fn b(self) -> u8 {
self.0 as _
}

#[must_use]
pub fn with_a(self, a: u8) -> Self {
pub const fn with_a(self, a: u8) -> Self {
Self::from_argb(a, self.r(), self.g(), self.b())
}

Expand All @@ -113,16 +113,20 @@ impl Color {
pub const CYAN: Self = Self(sb::SK_ColorCYAN);
pub const MAGENTA: Self = Self(sb::SK_ColorMAGENTA);

pub fn to_rgb(self) -> RGB {
(self.r(), self.g(), self.b()).into()
pub const fn to_rgb(self) -> RGB {
RGB {
r: self.r(),
g: self.g(),
b: self.b(),
}
}

pub fn to_hsv(self) -> HSV {
self.to_rgb().to_hsv()
}
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct RGB {
pub r: u8,
pub g: u8,
Expand Down
2 changes: 1 addition & 1 deletion skia-safe/src/core/color_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl ColorSpace {
// TODO: hash()?
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
pub struct XYZD50Hash(pub u32);

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions skia-safe/src/core/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Mul for Matrix {
}
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum Member {
ScaleX = 0,
SkewX = 1,
Expand All @@ -64,7 +64,7 @@ pub enum Member {
Persp2 = 8,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum AffineMember {
ScaleX = 0,
SkewY = 1,
Expand Down
22 changes: 21 additions & 1 deletion skia-safe/src/core/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssi
pub use IPoint as IVector;

#[repr(C)]
#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Default, Debug)]
pub struct IPoint {
pub x: i32,
pub y: i32,
Expand Down Expand Up @@ -92,6 +92,10 @@ impl IPoint {
pub fn equals(self, x: i32, y: i32) -> bool {
self == IPoint::new(x, y)
}

pub fn to_isize(self) -> ISize {
(self.x, self.y).into()
}
}

pub type Vector = Point;
Expand Down Expand Up @@ -306,6 +310,10 @@ impl Point {
pub fn dot(self, vec: Vector) -> scalar {
Self::dot_product(self, vec)
}

pub fn to_size(self) -> Size {
(self.x, self.y).into()
}
}

impl From<(i32, i32)> for IPoint {
Expand All @@ -314,12 +322,24 @@ impl From<(i32, i32)> for IPoint {
}
}

impl From<IPoint> for (i32, i32) {
fn from(p: IPoint) -> Self {
(p.x, p.y)
}
}

impl From<(scalar, scalar)> for Point {
fn from(source: (scalar, scalar)) -> Self {
Point::new(source.0, source.1)
}
}

impl From<Point> for (scalar, scalar) {
fn from(p: Point) -> Self {
(p.x, p.y)
}
}

impl From<IPoint> for Point {
fn from(source: IPoint) -> Self {
Self::new(source.x as _, source.y as _)
Expand Down
6 changes: 6 additions & 0 deletions skia-safe/src/core/point3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ impl From<(scalar, scalar, scalar)> for Point3 {
}
}

impl From<Point3> for (scalar, scalar, scalar) {
fn from(p: Point3) -> Self {
(p.x, p.y, p.z)
}
}

impl Neg for Point3 {
type Output = Self;
fn neg(self) -> Self::Output {
Expand Down
14 changes: 13 additions & 1 deletion skia-safe/src/core/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
};

#[repr(C)]
#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Default, Debug)]
pub struct IRect {
pub left: i32,
pub top: i32,
Expand Down Expand Up @@ -794,6 +794,12 @@ impl From<(IPoint, ISize)> for IRect {
}
}

impl From<IRect> for (IPoint, ISize) {
fn from(r: IRect) -> Self {
(IPoint::new(r.x(), r.y()), r.size())
}
}

impl From<(Point, Size)> for Rect {
fn from((point, size): (Point, Size)) -> Self {
Rect::new(
Expand All @@ -805,6 +811,12 @@ impl From<(Point, Size)> for Rect {
}
}

impl From<Rect> for (Point, Size) {
fn from(r: Rect) -> Self {
(Point::new(r.x(), r.y()), r.size())
}
}

impl From<ISize> for Rect {
fn from(isize: ISize) -> Self {
Self::from_isize(isize)
Expand Down
14 changes: 13 additions & 1 deletion skia-safe/src/core/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use skia_bindings::{self as sb, SkISize, SkSize};
use std::ops::{Div, DivAssign, Mul, MulAssign};

#[repr(C)]
#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Default, Debug)]
pub struct ISize {
pub width: i32,
pub height: i32,
Expand Down Expand Up @@ -120,12 +120,24 @@ impl From<(i32, i32)> for ISize {
}
}

impl From<ISize> for (i32, i32) {
fn from(size: ISize) -> Self {
(size.width, size.height)
}
}

impl From<(scalar, scalar)> for Size {
fn from(source: (scalar, scalar)) -> Self {
Self::new(source.0, source.1)
}
}

impl From<Size> for (scalar, scalar) {
fn from(size: Size) -> Self {
(size.width, size.height)
}
}

impl From<ISize> for Size {
fn from(size: ISize) -> Self {
Self::new(size.width as _, size.height as _)
Expand Down
2 changes: 1 addition & 1 deletion skia-safe/src/core/surface_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use skia_bindings::{self as sb, SkPixelGeometry, SkSurfaceProps};
use std::fmt;

// TODO: use the enum rewriter and strip underscores?
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[repr(i32)]
pub enum PixelGeometry {
Unknown = SkPixelGeometry::kUnknown_SkPixelGeometry as _,
Expand Down
2 changes: 1 addition & 1 deletion skia-safe/src/core/typeface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variant_name!(
serialize_behavior_naming
);

#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
pub struct LocalizedString {
pub string: String,
pub language: String,
Expand Down
4 changes: 2 additions & 2 deletions skia-safe/src/core/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) const SK_MIN_S32: i32 = -SK_MAX_S32;
// FourByteTag
//

#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Debug)]
#[repr(transparent)]
pub struct FourByteTag(SkFourByteTag);

Expand Down Expand Up @@ -82,7 +82,7 @@ pub type Unichar = skia_bindings::SkUnichar;
// pub(crate) const MSEC_MAX: u32 = std::i32::MAX as u32;

#[repr(C)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
pub struct Budgeted(bool);

native_transmutable!(SkBudgeted, Budgeted, budgeted_layout);
Expand Down
2 changes: 1 addition & 1 deletion skia-safe/src/effects/runtime_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl NativeRefCountedBase for SkRuntimeEffect {
}

#[repr(C)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct Options {
pub force_no_inline: bool,
enforce_es2_restrictions: bool,
Expand Down
6 changes: 3 additions & 3 deletions skia-safe/src/gpu/direct_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::{
};

#[repr(C)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct DirectContextId {
id: u32,
}
Expand Down Expand Up @@ -49,13 +49,13 @@ impl DerefMut for DirectContext {
}
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct ResourceCacheLimits {
pub max_resources: usize,
pub max_resource_bytes: usize,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct ResourceCacheUsage {
pub resource_count: usize,
pub resource_bytes: usize,
Expand Down
2 changes: 1 addition & 1 deletion skia-safe/src/gpu/gl/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl TextureInfo {
}
}

#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Default, Debug)]
#[repr(C)]
pub struct FramebufferInfo {
pub fboid: UInt,
Expand Down
2 changes: 1 addition & 1 deletion skia-safe/src/gpu/vk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl From<NullHandle> for u64 {
}

#[repr(transparent)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
pub struct Version(u32);

impl Version {
Expand Down
4 changes: 3 additions & 1 deletion skia-safe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ extern crate bitflags;
extern crate lazy_static;

// Prelude re-exports
pub use crate::prelude::{Borrows, ConditionallySend, Handle, RCHandle, RefHandle, Sendable};
pub use crate::prelude::{
Borrows, ConditionallySend, Handle, NativeRefCounted, RCHandle, RefHandle, Sendable,
};

/// All Sk* types are accessible via skia_safe::
pub use crate::core::*;
Expand Down
10 changes: 8 additions & 2 deletions skia-safe/src/modules/paragraph.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::interop::AsStr;
use std::ops::Index;
use std::{fmt, ops::Index};

mod dart_types;
mod font_arguments;
Expand Down Expand Up @@ -29,9 +29,15 @@ pub use typeface_font_provider::*;
/// Efficient reference type to a C++ vector of font family SkStrings.
///
/// Use indexer or .iter() to access the Rust str references.
#[derive(Debug)]
pub struct FontFamilies<'a>(&'a [skia_bindings::SkString]);

impl fmt::Debug for FontFamilies<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let families: Vec<_> = self.iter().collect();
f.debug_tuple("FontFamilies").field(&families).finish()
}
}

impl Index<usize> for FontFamilies<'_> {
type Output = str;
fn index(&self, index: usize) -> &Self::Output {
Expand Down
Loading