void rendering_buffer::attach(byte* buf, unsigned int width, unsigned int height, int stride)
{
    if (m_impl)
        get_system_device()->destroy_rendering_buffer(m_impl);

    m_impl = get_system_device()->create_rendering_buffer(buf, width, height, stride);
}
trans_affine& trans_affine::operator=(const trans_affine& o)
{
    if (this == &o)
        return *this;

    get_system_device()->destroy_trans_affine(m_impl);
    m_impl = get_system_device()->create_trans_affine(o.sx(), o.shy(), o.shx(), o.sy(), o.tx(), o.ty());

    return *this;
}
//static methods
bool raster_adapter::fill_contents_point(const vertex_source& vs, scalar x, scalar y, filling_rule rule)
{
    bool ret = false;
    abstract_raster_adapter* rs = get_system_device()->create_raster_adapter();
    trans_affine mtx;
    if (rs) {
        rs->set_raster_method(raster_fill);
        rs->set_fill_attr(FIA_FILL_RULE, rule);
        rs->set_transform(mtx.impl());
        rs->add_shape(vs, 0);
        rs->commit();
        ret = rs->contains(x, y);
    }
    get_system_device()->destroy_raster_adapter(rs);
    return ret; 
}
trans_affine::~trans_affine()
{
    get_system_device()->destroy_trans_affine(m_impl);
}
trans_affine::trans_affine(const trans_affine& o)
{
    m_impl = get_system_device()->create_trans_affine(o.sx(), o.shy(), o.shx(), o.sy(), o.tx(), o.ty());
}
trans_affine::trans_affine(scalar sx, scalar shy, scalar shx, scalar sy, scalar tx, scalar ty)
{
    //Custom matrix
    m_impl = get_system_device()->create_trans_affine(sx, shy, shx, sy, tx, ty);
}
trans_affine::trans_affine()
{
    //Identity matrix
    m_impl = get_system_device()->create_trans_affine(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
}
raster_adapter::~raster_adapter()
{
    get_system_device()->destroy_raster_adapter(m_impl);
}
raster_adapter::raster_adapter()
{
    m_impl = get_system_device()->create_raster_adapter();
}
rendering_buffer::~rendering_buffer()
{
    if (m_impl)
        get_system_device()->destroy_rendering_buffer(m_impl);
}