Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / state_trackers / egl / kms / native_kms.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
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #ifndef _NATIVE_KMS_H_
26 #define _NATIVE_KMS_H_
27
28 #include <xf86drm.h>
29 #include <xf86drmMode.h>
30
31 #include "pipe/p_compiler.h"
32 #include "util/u_format.h"
33 #include "pipe/p_state.h"
34 #include "state_tracker/drm_api.h"
35
36 #include "common/native.h"
37
38 enum kms_surface_type {
39 KMS_SURFACE_TYPE_PBUFFER,
40 KMS_SURFACE_TYPE_SCANOUT
41 };
42
43 struct kms_config;
44 struct kms_connector;
45 struct kms_mode;
46
47 struct kms_crtc {
48 drmModeCrtcPtr crtc;
49 uint32_t connectors[32];
50 int num_connectors;
51 };
52
53 struct kms_display {
54 struct native_display base;
55
56 int fd;
57 struct drm_api *api;
58 drmModeResPtr resources;
59 struct kms_config *config;
60
61 struct kms_connector *connectors;
62 int num_connectors;
63
64 struct kms_surface **shown_surfaces;
65 /* save the original settings of the CRTCs */
66 struct kms_crtc *saved_crtcs;
67 };
68
69 struct kms_framebuffer {
70 struct pipe_texture *texture;
71 boolean is_passive;
72
73 uint32_t buffer_id;
74 };
75
76 struct kms_surface {
77 struct native_surface base;
78 enum kms_surface_type type;
79 enum pipe_format color_format;
80 struct kms_display *kdpy;
81 int width, height;
82
83 struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
84 unsigned int sequence_number;
85 struct kms_framebuffer front_fb, back_fb;
86
87 boolean is_shown;
88 struct kms_crtc current_crtc;
89 };
90
91 struct kms_config {
92 struct native_config base;
93 };
94
95 struct kms_connector {
96 struct native_connector base;
97
98 uint32_t connector_id;
99 drmModeConnectorPtr connector;
100 struct kms_mode *kms_modes;
101 int num_modes;
102 };
103
104 struct kms_mode {
105 struct native_mode base;
106 drmModeModeInfo mode;
107 };
108
109 static INLINE struct kms_display *
110 kms_display(const struct native_display *ndpy)
111 {
112 return (struct kms_display *) ndpy;
113 }
114
115 static INLINE struct kms_surface *
116 kms_surface(const struct native_surface *nsurf)
117 {
118 return (struct kms_surface *) nsurf;
119 }
120
121 static INLINE struct kms_config *
122 kms_config(const struct native_config *nconf)
123 {
124 return (struct kms_config *) nconf;
125 }
126
127 static INLINE struct kms_connector *
128 kms_connector(const struct native_connector *nconn)
129 {
130 return (struct kms_connector *) nconn;
131 }
132
133 static INLINE struct kms_mode *
134 kms_mode(const struct native_mode *nmode)
135 {
136 return (struct kms_mode *) nmode;
137 }
138
139 #endif /* _NATIVE_KMS_H_ */