Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / gallium / state_trackers / egl / drm / native_drm.h
1 /*
2  * Mesa 3-D graphics library
3  * Version:  7.8
4  *
5  * Copyright (C) 2010 Chia-I Wu <olv@0xlab.org>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  */
25
26 #ifndef _NATIVE_DRM_H_
27 #define _NATIVE_DRM_H_
28
29 #include <xf86drm.h>
30 #include <xf86drmMode.h>
31
32 #include "pipe/p_compiler.h"
33 #include "util/u_format.h"
34 #include "pipe/p_state.h"
35 #include "state_tracker/drm_driver.h"
36
37 #include "common/native.h"
38 #include "common/native_helper.h"
39
40 #ifdef HAVE_WAYLAND_BACKEND
41 #include "common/native_wayland_drm_bufmgr_helper.h"
42 #endif
43
44 struct drm_config;
45 struct drm_crtc;
46 struct drm_connector;
47 struct drm_mode;
48 struct drm_surface;
49
50 struct drm_display {
51    struct native_display base;
52
53    const struct native_event_handler *event_handler;
54
55    int fd;
56    char *device_name;
57    struct drm_config *config;
58
59    /* for modesetting */
60    drmModeResPtr resources;
61    struct drm_connector *connectors;
62    int num_connectors;
63
64    struct drm_surface **shown_surfaces;
65    /* save the original settings of the CRTCs */
66    struct drm_crtc *saved_crtcs;
67
68 #ifdef HAVE_WAYLAND_BACKEND
69    struct wl_drm *wl_server_drm; /* for EGL_WL_bind_wayland_display */
70 #endif
71 };
72
73 struct drm_config {
74    struct native_config base;
75 };
76
77 struct drm_crtc {
78    drmModeCrtcPtr crtc;
79    uint32_t connectors[32];
80    int num_connectors;
81 };
82
83 struct drm_framebuffer {
84    struct pipe_resource *texture;
85    boolean is_passive;
86
87    uint32_t buffer_id;
88 };
89
90 struct drm_surface {
91    struct native_surface base;
92    struct drm_display *drmdpy;
93
94    struct resource_surface *rsurf;
95    enum pipe_format color_format;
96    int width, height;
97
98    unsigned int sequence_number;
99    struct drm_framebuffer front_fb, back_fb;
100
101    boolean is_shown;
102    struct drm_crtc current_crtc;
103
104    boolean have_pageflip;
105 };
106
107 struct drm_connector {
108    struct native_connector base;
109
110    uint32_t connector_id;
111    drmModeConnectorPtr connector;
112    struct drm_mode *drm_modes;
113    int num_modes;
114 };
115
116 struct drm_mode {
117    struct native_mode base;
118    drmModeModeInfo mode;
119 };
120
121 static INLINE struct drm_display *
122 drm_display(const struct native_display *ndpy)
123 {
124    return (struct drm_display *) ndpy;
125 }
126
127 static INLINE struct drm_config *
128 drm_config(const struct native_config *nconf)
129 {
130    return (struct drm_config *) nconf;
131 }
132
133 static INLINE struct drm_surface *
134 drm_surface(const struct native_surface *nsurf)
135 {
136    return (struct drm_surface *) nsurf;
137 }
138
139 static INLINE struct drm_connector *
140 drm_connector(const struct native_connector *nconn)
141 {
142    return (struct drm_connector *) nconn;
143 }
144
145 static INLINE struct drm_mode *
146 drm_mode(const struct native_mode *nmode)
147 {
148    return (struct drm_mode *) nmode;
149 }
150
151 boolean
152 drm_display_init_modeset(struct native_display *ndpy);
153
154 void
155 drm_display_fini_modeset(struct native_display *ndpy);
156
157 struct native_surface *
158 drm_display_create_surface_from_resource(struct native_display *ndpy,
159                                          struct pipe_resource *resource);
160
161 #endif /* _NATIVE_DRM_H_ */