1 /*
2 * Copyright 2011 Joakim Sindholt <[email protected]>
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef _NINE_SURFACE9_H_
7 #define _NINE_SURFACE9_H_
8
9 #include "nine_memory_helper.h"
10 #include "resource9.h"
11
12 #include "pipe/p_state.h"
13 #include "util/list.h"
14 #include "util/u_rect.h"
15 #include "util/u_inlines.h"
16
17 struct NineSurface9
18 {
19 struct NineResource9 base;
20
21 /* G3D state */
22 struct pipe_transfer *transfer;
23 struct pipe_surface *surface[2]; /* created on-demand (linear, sRGB) */
24 int lock_count;
25 uint8_t texture; /* rtype of container BaseTex or 0 */
26
27 /* resource description */
28 unsigned level; /* refers to the pipe_resource (SetLOD !) */
29 unsigned level_actual; /* refers to the NineTexture */
30 unsigned layer;
31 D3DSURFACE_DESC desc;
32
33 struct nine_allocation *data; /* system memory backing */
34 struct nine_allocation *data_internal; /* for conversions */
35 enum pipe_format format_internal;
36 unsigned stride; /* for system memory backing */
37 unsigned stride_internal;
38
39 unsigned pending_uploads_counter; /* pending uploads */
40 };
41 static inline struct NineSurface9 *
NineSurface9(void * data)42 NineSurface9( void *data )
43 {
44 return (struct NineSurface9 *)data;
45 }
46
47 HRESULT
48 NineSurface9_new( struct NineDevice9 *pDevice,
49 struct NineUnknown *pContainer,
50 struct pipe_resource *pResource,
51 struct nine_allocation *user_buffer,
52 uint8_t TextureType, /* 0 if pContainer isn't BaseTexure9 */
53 unsigned Level,
54 unsigned Layer,
55 D3DSURFACE_DESC *pDesc,
56 struct NineSurface9 **ppOut );
57
58 HRESULT
59 NineSurface9_ctor( struct NineSurface9 *This,
60 struct NineUnknownParams *pParams,
61 struct NineUnknown *pContainer,
62 struct pipe_resource *pResource,
63 struct nine_allocation *user_buffer,
64 uint8_t TextureType,
65 unsigned Level,
66 unsigned Layer,
67 D3DSURFACE_DESC *pDesc );
68
69 void
70 NineSurface9_dtor( struct NineSurface9 *This );
71
72 /*** Nine private ***/
73
74 void
75 NineSurface9_MarkContainerDirty( struct NineSurface9 *This );
76
77 static inline struct pipe_surface *
NineSurface9_GetSurface(struct NineSurface9 * This,int sRGB)78 NineSurface9_GetSurface( struct NineSurface9 *This, int sRGB )
79 {
80 assert(This->surface[sRGB]);
81 return This->surface[sRGB];
82 }
83
84 static inline struct pipe_resource *
NineSurface9_GetResource(struct NineSurface9 * This)85 NineSurface9_GetResource( struct NineSurface9 *This )
86 {
87 return This->base.resource;
88 }
89
90 void
91 NineSurface9_SetResource( struct NineSurface9 *This,
92 struct pipe_resource *resource, unsigned level );
93
94 void
95 NineSurface9_SetMultiSampleType( struct NineSurface9 *This,
96 D3DMULTISAMPLE_TYPE mst );
97
98 void
99 NineSurface9_SetResourceResize( struct NineSurface9 *This,
100 struct pipe_resource *resource );
101
102 void
103 NineSurface9_AddDirtyRect( struct NineSurface9 *This,
104 const struct pipe_box *box );
105
106 HRESULT
107 NineSurface9_UploadSelf( struct NineSurface9 *This,
108 const struct pipe_box *damaged );
109
110 void
111 NineSurface9_CopyMemToDefault( struct NineSurface9 *This,
112 struct NineSurface9 *From,
113 const POINT *pDestPoint,
114 const RECT *pSourceRect );
115
116 void
117 NineSurface9_CopyDefaultToMem( struct NineSurface9 *This,
118 struct NineSurface9 *From );
119
120 static inline bool
NineSurface9_IsOffscreenPlain(struct NineSurface9 * This)121 NineSurface9_IsOffscreenPlain (struct NineSurface9 *This )
122 {
123 return This->base.usage == 0 && !This->texture;
124 }
125
126 #if MESA_DEBUG || !defined(NDEBUG)
127 void
128 NineSurface9_Dump( struct NineSurface9 *This );
129 #else
130 static inline void
NineSurface9_Dump(struct NineSurface9 * This)131 NineSurface9_Dump( struct NineSurface9 *This ) { }
132 #endif
133
134 /*** Direct3D public ***/
135
136 HRESULT NINE_WINAPI
137 NineSurface9_GetContainer( struct NineSurface9 *This,
138 REFIID riid,
139 void **ppContainer );
140
141 HRESULT NINE_WINAPI
142 NineSurface9_GetDesc( struct NineSurface9 *This,
143 D3DSURFACE_DESC *pDesc );
144
145 HRESULT NINE_WINAPI
146 NineSurface9_LockRect( struct NineSurface9 *This,
147 D3DLOCKED_RECT *pLockedRect,
148 const RECT *pRect,
149 DWORD Flags );
150
151 HRESULT NINE_WINAPI
152 NineSurface9_UnlockRect( struct NineSurface9 *This );
153
154 HRESULT NINE_WINAPI
155 NineSurface9_GetDC( struct NineSurface9 *This,
156 HDC *phdc );
157
158 HRESULT NINE_WINAPI
159 NineSurface9_ReleaseDC( struct NineSurface9 *This,
160 HDC hdc );
161
162 #endif /* _NINE_SURFACE9_H_ */
163