st/nine: Access pipe_context via NineDevice9_GetPipe
[mesa.git] / src / gallium / state_trackers / nine / surface9.h
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #ifndef _NINE_SURFACE9_H_
24 #define _NINE_SURFACE9_H_
25
26 #include "resource9.h"
27
28 #include "pipe/p_state.h"
29 #include "util/list.h"
30 #include "util/u_rect.h"
31 #include "util/u_inlines.h"
32
33 struct NineSurface9
34 {
35 struct NineResource9 base;
36
37 /* G3D state */
38 struct pipe_transfer *transfer;
39 struct pipe_surface *surface[2]; /* created on-demand (linear, sRGB) */
40 int lock_count;
41 uint8_t texture; /* rtype of container BaseTex or 0 */
42
43 /* resource description */
44 unsigned level; /* refers to the pipe_resource (SetLOD !) */
45 unsigned level_actual; /* refers to the NineTexture */
46 unsigned layer;
47 D3DSURFACE_DESC desc;
48
49 uint8_t *data; /* system memory backing */
50 uint8_t *data_conversion; /* for conversions */
51 enum pipe_format format_conversion;
52 unsigned stride; /* for system memory backing */
53 unsigned stride_conversion;
54 };
55 static inline struct NineSurface9 *
56 NineSurface9( void *data )
57 {
58 return (struct NineSurface9 *)data;
59 }
60
61 HRESULT
62 NineSurface9_new( struct NineDevice9 *pDevice,
63 struct NineUnknown *pContainer,
64 struct pipe_resource *pResource,
65 void *user_buffer,
66 uint8_t TextureType, /* 0 if pContainer isn't BaseTexure9 */
67 unsigned Level,
68 unsigned Layer,
69 D3DSURFACE_DESC *pDesc,
70 struct NineSurface9 **ppOut );
71
72 HRESULT
73 NineSurface9_ctor( struct NineSurface9 *This,
74 struct NineUnknownParams *pParams,
75 struct NineUnknown *pContainer,
76 struct pipe_resource *pResource,
77 void *user_buffer,
78 uint8_t TextureType,
79 unsigned Level,
80 unsigned Layer,
81 D3DSURFACE_DESC *pDesc );
82
83 void
84 NineSurface9_dtor( struct NineSurface9 *This );
85
86 /*** Nine private ***/
87
88 void
89 NineSurface9_MarkContainerDirty( struct NineSurface9 *This );
90
91 struct pipe_surface *
92 NineSurface9_CreatePipeSurface( struct NineSurface9 *This, const int sRGB );
93
94 static inline struct pipe_surface *
95 NineSurface9_GetSurface( struct NineSurface9 *This, int sRGB )
96 {
97 if (This->surface[sRGB])
98 return This->surface[sRGB];
99 return NineSurface9_CreatePipeSurface(This, sRGB);
100 }
101
102 static inline struct pipe_resource *
103 NineSurface9_GetResource( struct NineSurface9 *This )
104 {
105 return This->base.resource;
106 }
107
108 static inline void
109 NineSurface9_SetResource( struct NineSurface9 *This,
110 struct pipe_resource *resource, unsigned level )
111 {
112 This->level = level;
113 pipe_resource_reference(&This->base.resource, resource);
114 pipe_surface_reference(&This->surface[0], NULL);
115 pipe_surface_reference(&This->surface[1], NULL);
116 }
117
118 static inline void
119 NineSurface9_SetMultiSampleType( struct NineSurface9 *This,
120 D3DMULTISAMPLE_TYPE mst )
121 {
122 This->desc.MultiSampleType = mst;
123 }
124
125 void
126 NineSurface9_SetResourceResize( struct NineSurface9 *This,
127 struct pipe_resource *resource );
128
129 void
130 NineSurface9_AddDirtyRect( struct NineSurface9 *This,
131 const struct pipe_box *box );
132
133 HRESULT
134 NineSurface9_UploadSelf( struct NineSurface9 *This,
135 const struct pipe_box *damaged );
136
137 void
138 NineSurface9_CopyMemToDefault( struct NineSurface9 *This,
139 struct NineSurface9 *From,
140 const POINT *pDestPoint,
141 const RECT *pSourceRect );
142
143 void
144 NineSurface9_CopyDefaultToMem( struct NineSurface9 *This,
145 struct NineSurface9 *From );
146
147 static inline boolean
148 NineSurface9_IsOffscreenPlain (struct NineSurface9 *This )
149 {
150 return This->base.usage == 0 && !This->texture;
151 }
152
153 #ifdef DEBUG
154 void
155 NineSurface9_Dump( struct NineSurface9 *This );
156 #else
157 static inline void
158 NineSurface9_Dump( struct NineSurface9 *This ) { }
159 #endif
160
161 /*** Direct3D public ***/
162
163 HRESULT NINE_WINAPI
164 NineSurface9_GetContainer( struct NineSurface9 *This,
165 REFIID riid,
166 void **ppContainer );
167
168 HRESULT NINE_WINAPI
169 NineSurface9_GetDesc( struct NineSurface9 *This,
170 D3DSURFACE_DESC *pDesc );
171
172 HRESULT NINE_WINAPI
173 NineSurface9_LockRect( struct NineSurface9 *This,
174 D3DLOCKED_RECT *pLockedRect,
175 const RECT *pRect,
176 DWORD Flags );
177
178 HRESULT NINE_WINAPI
179 NineSurface9_UnlockRect( struct NineSurface9 *This );
180
181 HRESULT NINE_WINAPI
182 NineSurface9_GetDC( struct NineSurface9 *This,
183 HDC *phdc );
184
185 HRESULT NINE_WINAPI
186 NineSurface9_ReleaseDC( struct NineSurface9 *This,
187 HDC hdc );
188
189 #endif /* _NINE_SURFACE9_H_ */