use crate::{SkAlphaType, SkBlendMode, SkBlendModeCoeff, SkPathFillType, SkPathVerb, SkPath_Verb};
use std::ffi::CStr;
impl SkBlendMode {
pub fn as_coeff(self) -> Option<(SkBlendModeCoeff, SkBlendModeCoeff)> {
let mut src = SkBlendModeCoeff::Zero;
let mut dst = SkBlendModeCoeff::Zero;
if unsafe { crate::SkBlendMode_AsCoeff(self, &mut src, &mut dst) } {
Some((src, dst))
} else {
None
}
}
pub fn name(self) -> &'static str {
unsafe {
let name_ptr = crate::SkBlendMode_Name(self);
CStr::from_ptr(name_ptr).to_str().unwrap()
}
}
}
impl SkPathVerb {
pub const MAX_POINTS: usize = SkPath_Verb::MAX_POINTS;
pub fn points(self) -> usize {
SkPath_Verb::from(self).points()
}
}
impl SkPath_Verb {
pub const MAX_POINTS: usize = 4;
pub fn points(self) -> usize {
match self {
SkPath_Verb::Move => 1,
SkPath_Verb::Line => 2,
SkPath_Verb::Quad => 3,
SkPath_Verb::Conic => 3,
SkPath_Verb::Cubic => 4,
SkPath_Verb::Close => 0,
SkPath_Verb::Done => 0,
}
}
}
impl From<SkPathVerb> for SkPath_Verb {
fn from(v: SkPathVerb) -> Self {
match v {
SkPathVerb::Move => SkPath_Verb::Move,
SkPathVerb::Line => SkPath_Verb::Line,
SkPathVerb::Quad => SkPath_Verb::Quad,
SkPathVerb::Conic => SkPath_Verb::Conic,
SkPathVerb::Cubic => SkPath_Verb::Cubic,
SkPathVerb::Close => SkPath_Verb::Close,
}
}
}
impl SkPathFillType {
pub fn is_even_odd(self) -> bool {
(self as i32 & 1) != 0
}
pub fn is_inverse(self) -> bool {
(self as i32 & 2) != 0
}
#[must_use]
pub fn to_non_inverse(self) -> Self {
use SkPathFillType::*;
match self {
Winding => self,
EvenOdd => self,
InverseWinding => Winding,
InverseEvenOdd => EvenOdd,
}
}
}
impl SkAlphaType {
pub fn is_opaque(self) -> bool {
self == SkAlphaType::Opaque
}
}
#[cfg(feature = "gl")]
impl From<crate::GrGLenum> for crate::GrGLFormat {
fn from(e: crate::GrGLenum) -> Self {
unsafe { crate::C_GrGLFormatFromGLEnum(e) }
}
}
#[cfg(feature = "gl")]
impl From<crate::GrGLFormat> for crate::GrGLenum {
fn from(format: crate::GrGLFormat) -> Self {
unsafe { crate::C_GrGLFormatToEnum(format) }
}
}
#[cfg(feature = "d3d")]
mod d3d {
use std::marker::PhantomData;
impl<T> Default for crate::gr_cp<T> {
fn default() -> Self {
Self {
fObject: std::ptr::null_mut(),
_phantom_0: PhantomData,
}
}
}
impl Default for crate::GrD3DTextureResourceInfo {
fn default() -> Self {
let mut instance = std::mem::MaybeUninit::uninit();
unsafe {
crate::C_GrD3DTextureResourceInfo_Construct(instance.as_mut_ptr());
instance.assume_init()
}
}
}
}