native_drm.h revision e7424d72405a1cb1fb5ac625b340043aaa9f88be
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_KMS_H_
27#define _NATIVE_KMS_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
40struct kms_config;
41struct kms_crtc;
42struct kms_connector;
43struct kms_mode;
44struct kms_surface;
45
46struct kms_display {
47   struct native_display base;
48
49   struct native_event_handler *event_handler;
50
51   int fd;
52   struct kms_config *config;
53
54   /* for modesetting */
55   drmModeResPtr resources;
56   struct kms_connector *connectors;
57   int num_connectors;
58
59   struct kms_surface **shown_surfaces;
60   /* save the original settings of the CRTCs */
61   struct kms_crtc *saved_crtcs;
62};
63
64struct kms_config {
65   struct native_config base;
66};
67
68struct kms_crtc {
69   drmModeCrtcPtr crtc;
70   uint32_t connectors[32];
71   int num_connectors;
72};
73
74struct kms_framebuffer {
75   struct pipe_resource *texture;
76   boolean is_passive;
77
78   uint32_t buffer_id;
79};
80
81struct kms_surface {
82   struct native_surface base;
83   struct kms_display *kdpy;
84
85   struct resource_surface *rsurf;
86   enum pipe_format color_format;
87   int width, height;
88
89   unsigned int sequence_number;
90   struct kms_framebuffer front_fb, back_fb;
91
92   boolean is_shown;
93   struct kms_crtc current_crtc;
94};
95
96struct kms_connector {
97   struct native_connector base;
98
99   uint32_t connector_id;
100   drmModeConnectorPtr connector;
101   struct kms_mode *kms_modes;
102   int num_modes;
103};
104
105struct kms_mode {
106   struct native_mode base;
107   drmModeModeInfo mode;
108};
109
110static INLINE struct kms_display *
111kms_display(const struct native_display *ndpy)
112{
113   return (struct kms_display *) ndpy;
114}
115
116static INLINE struct kms_config *
117kms_config(const struct native_config *nconf)
118{
119   return (struct kms_config *) nconf;
120}
121
122static INLINE struct kms_surface *
123kms_surface(const struct native_surface *nsurf)
124{
125   return (struct kms_surface *) nsurf;
126}
127
128static INLINE struct kms_connector *
129kms_connector(const struct native_connector *nconn)
130{
131   return (struct kms_connector *) nconn;
132}
133
134static INLINE struct kms_mode *
135kms_mode(const struct native_mode *nmode)
136{
137   return (struct kms_mode *) nmode;
138}
139
140boolean
141kms_display_init_modeset(struct native_display *ndpy);
142
143void
144kms_display_fini_modeset(struct native_display *ndpy);
145
146#endif /* _NATIVE_KMS_H_ */
147