Merge branch 'gallium-0.1' into gallium-0.2
[mesa.git] / src / gallium / winsys / drm / intel / egl / intel_device.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "utils.h"
30
31 #include "state_tracker/st_public.h"
32 #include "i915simple/i915_screen.h"
33
34 #include "intel_context.h"
35 #include "intel_device.h"
36 #include "intel_batchbuffer.h"
37 #include "intel_egl.h"
38
39
40 extern const struct dri_extension card_extensions[];
41
42
43 int
44 intel_create_device(struct egl_drm_device *device)
45 {
46 struct intel_device *intel_device;
47
48 /* Allocate the private area */
49 intel_device = CALLOC_STRUCT(intel_device);
50 if (!intel_device)
51 return FALSE;
52
53 device->priv = (void *)intel_device;
54 intel_device->device = device;
55
56 intel_device->deviceID = device->deviceID;
57
58 intel_be_init_device(&intel_device->base, device->drmFD, intel_device->deviceID);
59
60 intel_device->pipe = i915_create_screen(&intel_device->base.base, intel_device->deviceID);
61
62 /* hack */
63 driInitExtensions(NULL, card_extensions, GL_FALSE);
64
65 return TRUE;
66 }
67
68 int
69 intel_destroy_device(struct egl_drm_device *device)
70 {
71 struct intel_device *intel_device = (struct intel_device *)device->priv;
72
73 intel_be_destroy_device(&intel_device->base);
74
75 free(intel_device);
76 device->priv = NULL;
77
78 return TRUE;
79 }
80
81 int
82 intel_create_drawable(struct egl_drm_drawable *drawable,
83 const __GLcontextModes * visual)
84 {
85 enum pipe_format colorFormat, depthFormat, stencilFormat;
86 struct intel_framebuffer *intelfb = CALLOC_STRUCT(intel_framebuffer);
87
88 if (!intelfb)
89 return GL_FALSE;
90
91 intelfb->device = drawable->device->priv;
92
93 if (visual->redBits == 5)
94 colorFormat = PIPE_FORMAT_R5G6B5_UNORM;
95 else
96 colorFormat = PIPE_FORMAT_A8R8G8B8_UNORM;
97
98 if (visual->depthBits == 16)
99 depthFormat = PIPE_FORMAT_Z16_UNORM;
100 else if (visual->depthBits == 24)
101 depthFormat = PIPE_FORMAT_S8Z24_UNORM;
102 else
103 depthFormat = PIPE_FORMAT_NONE;
104
105 if (visual->stencilBits == 8)
106 stencilFormat = PIPE_FORMAT_S8Z24_UNORM;
107 else
108 stencilFormat = PIPE_FORMAT_NONE;
109
110 intelfb->stfb = st_create_framebuffer(visual,
111 colorFormat,
112 depthFormat,
113 stencilFormat,
114 drawable->w,
115 drawable->h,
116 (void*) intelfb);
117
118 if (!intelfb->stfb) {
119 free(intelfb);
120 return GL_FALSE;
121 }
122
123 drawable->priv = (void *) intelfb;
124 return GL_TRUE;
125 }
126
127 int
128 intel_destroy_drawable(struct egl_drm_drawable *drawable)
129 {
130 struct intel_framebuffer *intelfb = (struct intel_framebuffer *)drawable->priv;
131 drawable->priv = NULL;
132
133 assert(intelfb->stfb);
134 st_unreference_framebuffer(&intelfb->stfb);
135 free(intelfb);
136 return TRUE;
137 }