1 /**************************************************************************
2  *
3  * Copyright 2009 VMware, Inc.
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 VMWARE 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 #ifndef GLHD_OBJECTS_H
29 #define GLHD_OBJECTS_H
30 
31 
32 #include "pipe/p_compiler.h"
33 #include "pipe/p_state.h"
34 
35 #include "glhd_screen.h"
36 
37 struct galahad_context;
38 
39 
40 struct galahad_resource
41 {
42    struct pipe_resource base;
43 
44    struct pipe_resource *resource;
45 
46    int map_count;
47 };
48 
49 
50 struct galahad_sampler_view
51 {
52    struct pipe_sampler_view base;
53 
54    struct pipe_sampler_view *sampler_view;
55 };
56 
57 
58 struct galahad_surface
59 {
60    struct pipe_surface base;
61 
62    struct pipe_surface *surface;
63 };
64 
65 
66 struct galahad_transfer
67 {
68    struct pipe_transfer base;
69 
70    struct pipe_transfer *transfer;
71 };
72 
73 
74 static INLINE struct galahad_resource *
galahad_resource(struct pipe_resource * _resource)75 galahad_resource(struct pipe_resource *_resource)
76 {
77    if(!_resource)
78       return NULL;
79    (void)galahad_screen(_resource->screen);
80    return (struct galahad_resource *)_resource;
81 }
82 
83 static INLINE struct galahad_sampler_view *
galahad_sampler_view(struct pipe_sampler_view * _sampler_view)84 galahad_sampler_view(struct pipe_sampler_view *_sampler_view)
85 {
86    if (!_sampler_view) {
87       return NULL;
88    }
89    return (struct galahad_sampler_view *)_sampler_view;
90 }
91 
92 static INLINE struct galahad_surface *
galahad_surface(struct pipe_surface * _surface)93 galahad_surface(struct pipe_surface *_surface)
94 {
95    if(!_surface)
96       return NULL;
97    (void)galahad_resource(_surface->texture);
98    return (struct galahad_surface *)_surface;
99 }
100 
101 static INLINE struct galahad_transfer *
galahad_transfer(struct pipe_transfer * _transfer)102 galahad_transfer(struct pipe_transfer *_transfer)
103 {
104    if(!_transfer)
105       return NULL;
106    (void)galahad_resource(_transfer->resource);
107    return (struct galahad_transfer *)_transfer;
108 }
109 
110 static INLINE struct pipe_resource *
galahad_resource_unwrap(struct pipe_resource * _resource)111 galahad_resource_unwrap(struct pipe_resource *_resource)
112 {
113    if(!_resource)
114       return NULL;
115    return galahad_resource(_resource)->resource;
116 }
117 
118 static INLINE struct pipe_sampler_view *
galahad_sampler_view_unwrap(struct pipe_sampler_view * _sampler_view)119 galahad_sampler_view_unwrap(struct pipe_sampler_view *_sampler_view)
120 {
121    if (!_sampler_view) {
122       return NULL;
123    }
124    return galahad_sampler_view(_sampler_view)->sampler_view;
125 }
126 
127 static INLINE struct pipe_surface *
galahad_surface_unwrap(struct pipe_surface * _surface)128 galahad_surface_unwrap(struct pipe_surface *_surface)
129 {
130    if(!_surface)
131       return NULL;
132    return galahad_surface(_surface)->surface;
133 }
134 
135 static INLINE struct pipe_transfer *
galahad_transfer_unwrap(struct pipe_transfer * _transfer)136 galahad_transfer_unwrap(struct pipe_transfer *_transfer)
137 {
138    if(!_transfer)
139       return NULL;
140    return galahad_transfer(_transfer)->transfer;
141 }
142 
143 
144 struct pipe_resource *
145 galahad_resource_create(struct galahad_screen *glhd_screen,
146                          struct pipe_resource *resource);
147 
148 void
149 galahad_resource_destroy(struct galahad_resource *glhd_resource);
150 
151 struct pipe_surface *
152 galahad_surface_create(struct galahad_context *glhd_context,
153                        struct galahad_resource *glhd_resource,
154                         struct pipe_surface *surface);
155 
156 void
157 galahad_surface_destroy(struct galahad_context *glhd_context,
158                          struct galahad_surface *glhd_surface);
159 
160 struct pipe_sampler_view *
161 galahad_sampler_view_create(struct galahad_context *glhd_context,
162                              struct galahad_resource *glhd_resource,
163                              struct pipe_sampler_view *view);
164 
165 void
166 galahad_sampler_view_destroy(struct galahad_context *glhd_context,
167                               struct galahad_sampler_view *glhd_sampler_view);
168 
169 struct pipe_transfer *
170 galahad_transfer_create(struct galahad_context *glhd_context,
171                          struct galahad_resource *glhd_resource,
172                          struct pipe_transfer *transfer);
173 
174 void
175 galahad_transfer_destroy(struct galahad_context *glhd_context,
176                           struct galahad_transfer *glhd_transfer);
177 
178 
179 #endif /* GLHD_OBJECTS_H */
180