pub struct DeviceContext(_);
Expand description

The main context that takes drawing operations.

This type is a thin wrapper for ID2D1DeviceContext.

This struct is public only to use for system integration in piet_common and druid-shell. It is not intended that end-users directly use this struct.

Implementations§

source§

impl DeviceContext

source

pub unsafe fn new(ptr: ComPtr<ID2D1DeviceContext>) -> DeviceContext

Create a new device context from an existing COM object.

Marked as unsafe because the device must be in a good state. This might be overly conservative.

Safety

TODO

source

pub fn get_raw(&self) -> *mut ID2D1DeviceContext

Get the raw pointer

source

pub fn get_comptr(&self) -> &ComPtr<ID2D1DeviceContext>

Get the Com ptr TODO rename to inner, like for D3D11Device?

source

pub unsafe fn create_bitmap_from_dxgi(
    &self,
    dxgi: &ComPtr<IDXGISurface>,
    dpi_scale: f32
) -> Result<Bitmap, Error>

Create a bitmap from a DXGI surface.

Most often, this bitmap will be used to set the target of a DeviceContext.

Assumes RGBA8 format and premultiplied alpha.

The unsafe might be conservative, but we assume the dxgi argument is in good shape to be a target.

Safety

TODO

source

pub fn set_target(&mut self, target: &Bitmap)

Set the target for the device context.

Useful for rendering into bitmaps.

source

pub fn set_dpi_scale(&mut self, dpi_scale: f32)

Set the dpi scale.

Mostly useful when rendering into bitmaps.

source

pub fn get_dpi_scale(&self) -> (f32, f32)

source

pub fn begin_draw(&mut self)

Begin drawing.

This must be done before any piet drawing operations.

There may be safety concerns (not clear what happens if the sequence is not followed).

source

pub fn end_draw(&mut self) -> Result<(), Error>

End drawing.

Trait Implementations§

source§

impl Clone for DeviceContext

source§

fn clone(&self) -> DeviceContext

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> RoundFrom<T> for T

source§

fn round_from(x: T) -> T

Performs the conversion.
source§

impl<T, U> RoundInto<U> for Twhere
    U: RoundFrom<T>,

source§

fn round_into(self) -> U

Performs the conversion.
source§

impl<T> ToOwned for Twhere
    T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.