1 /* Cairo - a vector graphics library with display and print output
3 * Copyright © 2009 Chris Wilson
5 * This library is free software; you can redistribute it and/or
6 * modify it either under the terms of the GNU Lesser General Public
7 * License version 2.1 as published by the Free Software Foundation
8 * (the "LGPL") or, at your option, under the terms of the Mozilla
9 * Public License Version 1.1 (the "MPL"). If you do not alter this
10 * notice, a recipient may use your version of this file under either
11 * the MPL or the LGPL.
13 * You should have received a copy of the LGPL along with this library
14 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
16 * You should have received a copy of the MPL along with this library
17 * in the file COPYING-MPL-1.1
19 * The contents of this file are subject to the Mozilla Public License
20 * Version 1.1 (the "License"); you may not use this file except in
21 * compliance with the License. You may obtain a copy of the License at
22 * http://www.mozilla.org/MPL/
24 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
25 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
26 * the specific language governing rights and limitations.
28 * The Original Code is the cairo graphics library.
30 * The Initial Developer of the Original Code is Chris Wilson.
33 * Chris Wilson <chris@chris-wilson.co.uk>
36 #ifndef CAIRO_DRM_PRIVATE_H
37 #define CAIRO_DRM_PRIVATE_H
39 #include "cairo-drm.h"
41 #include "cairo-device-private.h"
42 #include "cairo-reference-count-private.h"
43 #include "cairo-surface-private.h"
45 #include <sys/types.h> /* dev_t */
47 typedef struct _cairo_drm_device cairo_drm_device_t;
49 typedef cairo_drm_device_t *
50 (*cairo_drm_device_create_func_t) (int fd,
55 typedef cairo_int_status_t
56 (*cairo_drm_device_flush_func_t) (cairo_drm_device_t *device);
58 typedef cairo_int_status_t
59 (*cairo_drm_device_throttle_func_t) (cairo_drm_device_t *device);
62 (*cairo_drm_device_destroy_func_t) (void *data);
64 typedef cairo_surface_t *
65 (*cairo_drm_surface_create_func_t) (cairo_drm_device_t *device,
66 cairo_format_t format,
67 int width, int height);
69 typedef cairo_surface_t *
70 (*cairo_drm_surface_create_for_name_func_t) (cairo_drm_device_t *device,
72 cairo_format_t format,
73 int width, int height, int stride);
75 typedef cairo_surface_t *
76 (*cairo_drm_surface_create_from_cacheable_image_func_t)
77 (cairo_drm_device_t *device, cairo_surface_t *image);
79 typedef cairo_int_status_t
80 (*cairo_drm_surface_flink_func_t) (void *surface);
82 typedef cairo_status_t
83 (*cairo_drm_surface_enable_scan_out_func_t) (void *surface);
85 typedef cairo_surface_t *
86 (*cairo_drm_surface_map_to_image_func_t) (void *surface);
88 typedef struct _cairo_drm_bo_backend {
89 void (*release) (void *device, void *bo);
90 } cairo_drm_bo_backend_t;
92 typedef struct _cairo_drm_device_backend {
93 cairo_drm_device_flush_func_t flush;
94 cairo_drm_device_throttle_func_t throttle;
95 cairo_drm_device_destroy_func_t destroy;
96 } cairo_drm_device_backend_t;
98 typedef struct _cairo_drm_surface_backend {
99 cairo_drm_surface_create_func_t create;
100 cairo_drm_surface_create_for_name_func_t create_for_name;
101 cairo_drm_surface_create_from_cacheable_image_func_t create_from_cacheable_image;
102 cairo_drm_surface_flink_func_t flink;
103 cairo_drm_surface_enable_scan_out_func_t enable_scan_out;
104 cairo_drm_surface_map_to_image_func_t map_to_image;
105 } cairo_drm_surface_backend_t;
107 typedef struct _cairo_drm_bo {
108 cairo_reference_count_t ref_count;
114 struct _cairo_drm_device {
122 int max_surface_size;
124 cairo_drm_bo_backend_t bo;
125 cairo_drm_surface_backend_t surface;
126 cairo_drm_device_backend_t device;
128 cairo_drm_device_t *next, *prev;
131 typedef struct _cairo_drm_surface {
132 cairo_surface_t base;
136 cairo_format_t format;
137 int width, height, stride;
139 cairo_surface_t *fallback;
141 } cairo_drm_surface_t;
143 static inline cairo_drm_bo_t *
144 cairo_drm_bo_reference (cairo_drm_bo_t *bo)
146 _cairo_reference_count_inc (&bo->ref_count);
150 static cairo_always_inline void
151 cairo_drm_bo_destroy (cairo_device_t *abstract_device,
154 if (_cairo_reference_count_dec_and_test (&bo->ref_count)) {
155 cairo_drm_device_t *device = (cairo_drm_device_t *) abstract_device;
156 device->bo.release (device, bo);
160 cairo_private cairo_status_t
161 _cairo_drm_bo_open_for_name (const cairo_drm_device_t *dev,
165 cairo_private cairo_status_t
166 _cairo_drm_bo_flink (const cairo_drm_device_t *dev,
170 _cairo_drm_bo_close (const cairo_drm_device_t *dev,
174 _cairo_drm_surface_init (cairo_drm_surface_t *surface,
175 cairo_format_t format,
176 int width, int height);
178 cairo_private cairo_status_t
179 _cairo_drm_surface_finish (cairo_drm_surface_t *surface);
182 _cairo_drm_surface_get_font_options (void *abstract_surface,
183 cairo_font_options_t *options);
185 cairo_private cairo_bool_t
186 _cairo_drm_surface_get_extents (void *abstract_surface,
187 cairo_rectangle_int_t *rectangle);
189 cairo_private cairo_int_status_t
190 _cairo_drm_surface_flink (void *abstract_surface);
192 static inline cairo_drm_device_t *
193 _cairo_drm_device_create_in_error (cairo_status_t status)
195 return (cairo_drm_device_t *) _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY);
198 cairo_private cairo_drm_device_t *
199 _cairo_drm_device_init (cairo_drm_device_t *device,
204 int max_surface_size);
207 _cairo_drm_device_fini (cairo_drm_device_t *device);
209 /* h/w specific backends */
211 cairo_private cairo_drm_device_t *
212 _cairo_drm_intel_device_create (int fd, dev_t dev, int vendor_id, int chip_id);
214 cairo_private cairo_drm_device_t *
215 _cairo_drm_i915_device_create (int fd, dev_t dev, int vendor_id, int chip_id);
217 cairo_private cairo_drm_device_t *
218 _cairo_drm_i965_device_create (int fd, dev_t dev, int vendor_id, int chip_id);
220 cairo_private cairo_drm_device_t *
221 _cairo_drm_radeon_device_create (int fd, dev_t dev, int vendor_id, int chip_id);
223 #if CAIRO_HAS_GALLIUM_SURFACE
224 cairo_private cairo_drm_device_t *
225 _cairo_drm_gallium_device_create (int fd, dev_t dev, int vendor_id, int chip_id);
228 slim_hidden_proto (cairo_drm_device_default);
229 slim_hidden_proto (cairo_drm_device_get);
230 slim_hidden_proto (cairo_drm_device_get_for_fd);
232 slim_hidden_proto (cairo_drm_surface_create_for_name);
234 cairo_private cairo_bool_t
235 _cairo_drm_size_is_valid (cairo_device_t *abstract_device,
236 int width, int height);
238 #endif /* CAIRO_DRM_PRIVATE_H */