radeon-gallium: DRI2 state tracker, part 3.
[mesa.git] / src / gallium / winsys / drm / radeon / core / radeon_drm.c
1 /*
2 * Copyright © 2009 Corbin Simpson
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
17 * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 */
26 /*
27 * Authors:
28 * Corbin Simpson <MostAwesomeDude@gmail.com>
29 */
30
31 #include "radeon_drm.h"
32
33 /* Create a pipe_screen. */
34 struct pipe_screen* radeon_create_screen(int drmFB, int pciID)
35 {
36 struct pipe_winsys* winsys = radeon_pipe_winsys();
37
38 if (getenv("RADEON_SOFTPIPE")) {
39 return softpipe_create_screen(winsys);
40 } else {
41 struct r300_winsys* r300 = radeon_create_r300_winsys(drmFB, winsys);
42 FREE(winsys);
43 return r300_create_screen(r300);
44 }
45 }
46
47 /* Create a pipe_context. */
48 struct pipe_context* radeon_create_context(struct pipe_screen* screen)
49 {
50 if (getenv("RADEON_SOFTPIPE")) {
51 return radeon_create_softpipe(screen->winsys);
52 } else {
53 return r300_create_context(screen, screen->winsys);
54 }
55 }
56
57 boolean radeon_buffer_from_texture(struct pipe_texture* texture,
58 struct pipe_buffer** buffer,
59 unsigned* stride)
60 {
61 return FALSE;
62 }
63
64 /* Create a buffer from a handle. */
65 /* XXX what's up with name? */
66 struct pipe_buffer* radeon_buffer_from_handle(struct pipe_screen* screen,
67 const char* name,
68 unsigned handle)
69 {
70 struct radeon_bo_manager* bom =
71 ((struct radeon_winsys*)screen->winsys)->bom;
72 struct radeon_pipe_buffer* radeon_buffer;
73 struct radeon_bo* bo = NULL;
74
75 bo = radeon_bo_open(bom, handle, 0, 0, 0, 0);
76 if (bo == NULL) {
77 return NULL;
78 }
79
80 radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer);
81 if (radeon_buffer == NULL) {
82 radeon_bo_unref(bo);
83 return NULL;
84 }
85
86 pipe_reference_init(&radeon_buffer->base.reference, 1);
87 radeon_buffer->base.screen = screen;
88 radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL;
89 radeon_buffer->bo = bo;
90 return &radeon_buffer->base;
91 }
92
93 boolean radeon_handle_from_buffer(struct pipe_screen* screen,
94 struct pipe_buffer* buffer,
95 unsigned* handle)
96 {
97 struct radeon_pipe_buffer* radeon_buffer =
98 (struct radeon_pipe_buffer*)buffer;
99 *handle = radeon_buffer->bo->handle;
100 return TRUE;
101 }
102
103 boolean radeon_global_handle_from_buffer(struct pipe_screen* screen,
104 struct pipe_buffer* buffer,
105 unsigned* handle)
106 {
107 /* XXX WTF is the difference here? global? */
108 struct radeon_pipe_buffer* radeon_buffer =
109 (struct radeon_pipe_buffer*)buffer;
110 *handle = radeon_buffer->bo->handle;
111 return TRUE;
112 }
113
114 struct drm_api drm_api_hooks = {
115 .create_screen = radeon_create_screen,
116 .create_context = radeon_create_context,
117 /* XXX fix this */
118 .buffer_from_texture = r300_get_texture_buffer,
119 .buffer_from_handle = radeon_buffer_from_handle,
120 .handle_from_buffer = radeon_handle_from_buffer,
121 .global_handle_from_buffer = radeon_global_handle_from_buffer,
122 };