1 /* Copyright (C) 2005 The cairomm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Library General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
12 *
13 * You should have received a copy of the GNU Library General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301, USA.
17 */
18
19 #include <cairomm/xlib_surface.h>
20 #include <cairomm/private.h>
21
22
23 namespace Cairo
24 {
25
26 #ifdef CAIRO_HAS_XLIB_SURFACE
27
XlibSurface(cairo_surface_t * cobject,bool has_reference)28 XlibSurface::XlibSurface(cairo_surface_t* cobject, bool has_reference) :
29 Surface(cobject, has_reference)
30 {}
31
~XlibSurface()32 XlibSurface::~XlibSurface()
33 {
34 // surface is destroyed in base class
35 }
36
create(Display * dpy,Drawable drawable,Visual * visual,int width,int height)37 RefPtr<XlibSurface> XlibSurface::create(Display* dpy, Drawable drawable, Visual* visual, int width, int height)
38 {
39 auto cobject = cairo_xlib_surface_create(dpy, drawable, visual, width, height);
40 check_status_and_throw_exception(cairo_surface_status(cobject));
41 return RefPtr<XlibSurface>(new XlibSurface(cobject, true /* has reference */));
42 }
43
create(Display * dpy,Pixmap bitmap,Screen * screen,int width,int height)44 RefPtr<XlibSurface> XlibSurface::create(Display* dpy, Pixmap bitmap, Screen* screen, int width, int height)
45 {
46 auto cobject = cairo_xlib_surface_create_for_bitmap(dpy, bitmap, screen, width, height);
47 check_status_and_throw_exception(cairo_surface_status(cobject));
48 return RefPtr<XlibSurface>(new XlibSurface(cobject, true /* has reference */));
49 }
50
set_size(int width,int height)51 void XlibSurface::set_size(int width, int height)
52 {
53 cairo_xlib_surface_set_size(m_cobject, width, height);
54 check_object_status_and_throw_exception(*this);
55 }
56
set_drawable(Drawable drawable,int width,int height)57 void XlibSurface::set_drawable(Drawable drawable, int width, int height)
58 {
59 cairo_xlib_surface_set_drawable(m_cobject, drawable, width, height);
60 check_object_status_and_throw_exception(*this);
61 }
62
get_drawable() const63 Drawable XlibSurface::get_drawable() const
64 {
65 auto drawable = cairo_xlib_surface_get_drawable(m_cobject);
66 check_object_status_and_throw_exception(*this);
67 return drawable;
68 }
69
get_display() const70 const Display* XlibSurface::get_display() const
71 {
72 const auto dpy = cairo_xlib_surface_get_display(m_cobject);
73 check_object_status_and_throw_exception(*this);
74 return dpy;
75 }
76
get_display()77 Display* XlibSurface::get_display()
78 {
79 auto dpy = cairo_xlib_surface_get_display(m_cobject);
80 check_object_status_and_throw_exception(*this);
81 return dpy;
82 }
83
get_screen()84 Screen* XlibSurface::get_screen()
85 {
86 auto screen = cairo_xlib_surface_get_screen(m_cobject);
87 check_object_status_and_throw_exception(*this);
88 return screen;
89 }
90
get_screen() const91 const Screen* XlibSurface::get_screen() const
92 {
93 const auto screen = cairo_xlib_surface_get_screen(m_cobject);
94 check_object_status_and_throw_exception(*this);
95 return screen;
96 }
97
get_visual()98 Visual* XlibSurface::get_visual()
99 {
100 auto visual = cairo_xlib_surface_get_visual(m_cobject);
101 check_object_status_and_throw_exception(*this);
102 return visual;
103 }
104
get_visual() const105 const Visual* XlibSurface::get_visual() const
106 {
107 const auto visual = cairo_xlib_surface_get_visual(m_cobject);
108 check_object_status_and_throw_exception(*this);
109 return visual;
110 }
111
get_depth() const112 int XlibSurface::get_depth() const
113 {
114 auto depth = cairo_xlib_surface_get_depth(m_cobject);
115 check_object_status_and_throw_exception(*this);
116 return depth;
117 }
118
get_height() const119 int XlibSurface::get_height() const
120 {
121 auto h = cairo_xlib_surface_get_height(m_cobject);
122 check_object_status_and_throw_exception(*this);
123 return h;
124 }
125
get_width() const126 int XlibSurface::get_width() const
127 {
128 auto w = cairo_xlib_surface_get_width(m_cobject);
129 check_object_status_and_throw_exception(*this);
130 return w;
131 }
132
133 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
134 Cairo::RefPtr<Cairo::XlibSurface>
create_with_xrender_format(Display * dpy,Drawable drawable,Screen * screen,XRenderPictFormat * format,int width,int height)135 XlibSurface::create_with_xrender_format (Display *dpy,
136 Drawable drawable,
137 Screen *screen,
138 XRenderPictFormat *format,
139 int width,
140 int height)
141 {
142 auto cobject =
143 cairo_xlib_surface_create_with_xrender_format(dpy, drawable,
144 screen, format,
145 width, height);
146 check_status_and_throw_exception(cairo_surface_status(cobject));
147 return RefPtr<XlibSurface>(new XlibSurface(cobject, true /* has reference */));
148 }
149
150 XRenderPictFormat*
get_xrender_format() const151 XlibSurface::get_xrender_format() const
152 {
153 XRenderPictFormat*
154 format = cairo_xlib_surface_get_xrender_format(m_cobject);
155 check_object_status_and_throw_exception(*this);
156 return format;
157 }
158
159 #endif // CAIRO_HAS_XLIB_XRENDER_SURFACE
160
161 #endif // CAIRO_HAS_XLIB_SURFACE
162
163 } //namespace Cairo
164
165 // vim: ts=2 sw=2 et
166