Blame cairomm/device.cc

Packit 908522
/* Copyright (C) 2010s The cairomm Development Team
Packit 908522
 *
Packit 908522
 * This library is free software; you can redistribute it and/or
Packit 908522
 * modify it under the terms of the GNU Library General Public
Packit 908522
 * License as published by the Free Software Foundation; either
Packit 908522
 * version 2 of the License, or (at your option) any later version.
Packit 908522
 *
Packit 908522
 * This library is distributed in the hope that it will be useful,
Packit 908522
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 908522
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 908522
 * Library General Public License for more details.
Packit 908522
 *
Packit 908522
 * You should have received a copy of the GNU Library General Public
Packit 908522
 * License along with this library; if not, write to the Free Software
Packit 908522
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit 908522
 * 02110-1301, USA.
Packit 908522
 */
Packit 908522
Packit 908522
#include <cairomm/device.h>
Packit 908522
#include <cairomm/private.h>
Packit 908522
Packit 908522
namespace Cairo
Packit 908522
{
Packit 908522
Packit 908522
Device::Device(cairo_device_t* cobject, bool has_reference)
Packit 908522
: m_cobject(nullptr)
Packit 908522
{
Packit 908522
  if(has_reference)
Packit 908522
    m_cobject = cobject;
Packit 908522
  else
Packit 908522
    m_cobject = cairo_device_reference(cobject);
Packit 908522
}
Packit 908522
Packit 908522
Device::~Device()
Packit 908522
{
Packit 908522
  if(m_cobject)
Packit 908522
    cairo_device_destroy(m_cobject);
Packit 908522
}
Packit 908522
Packit 908522
void Device::reference() const
Packit 908522
{
Packit 908522
 cairo_device_reference(m_cobject);
Packit 908522
}
Packit 908522
Packit 908522
void Device::unreference() const
Packit 908522
{
Packit 908522
  cairo_device_destroy(m_cobject);
Packit 908522
}
Packit 908522
Packit 908522
DeviceType Device::get_type() const
Packit 908522
{
Packit 908522
  auto surface_type =
Packit 908522
    cairo_device_get_type(const_cast<cobject*>(cobj()));
Packit 908522
  check_object_status_and_throw_exception(*this);
Packit 908522
  return static_cast<DeviceType>(surface_type);
Packit 908522
}
Packit 908522
Packit 908522
void Device::flush()
Packit 908522
{
Packit 908522
  cairo_device_flush(m_cobject);
Packit 908522
  check_object_status_and_throw_exception(*this);
Packit 908522
}
Packit 908522
Packit 908522
void Device::finish()
Packit 908522
{
Packit 908522
  cairo_device_flush(m_cobject);
Packit 908522
  check_object_status_and_throw_exception(*this);
Packit 908522
}
Packit 908522
Packit 908522
void Device::acquire()
Packit 908522
{
Packit 908522
  auto status = cairo_device_acquire(m_cobject);
Packit 908522
  check_status_and_throw_exception(status);
Packit 908522
}
Packit 908522
Packit 908522
void Device::release()
Packit 908522
{
Packit 908522
  cairo_device_release(m_cobject);
Packit 908522
  check_object_status_and_throw_exception(*this);
Packit 908522
}
Packit 908522
Packit 908522
Device::Lock::Lock(const RefPtr<Device>& device) :
Packit 908522
  m_device(device)
Packit 908522
{
Packit 908522
  m_device->acquire();
Packit 908522
}
Packit 908522
Packit 908522
Device::Lock::Lock (const Lock& other) :
Packit 908522
  m_device(other.m_device)
Packit 908522
{
Packit 908522
  m_device->acquire();
Packit 908522
}
Packit 908522
Packit 908522
Device::Lock::~Lock()
Packit 908522
{
Packit 908522
  m_device->release();
Packit 908522
}
Packit 908522
Packit 908522
Packit 908522
} //namespace Cairo
Packit 908522
Packit 908522
// vim: ts=2 sw=2 et