1 | /* $Id$ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * Blitter API
|
---|
5 | */
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.alldomusa.eu.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 | #ifndef ___cr_blitter_h__
|
---|
18 | #define ___cr_blitter_h__
|
---|
19 |
|
---|
20 | #include <iprt/cdefs.h>
|
---|
21 | #include <iprt/asm.h>
|
---|
22 | #include "cr_spu.h"
|
---|
23 | #include "cr_vreg.h"
|
---|
24 |
|
---|
25 | #ifndef IN_RING0
|
---|
26 | # define VBOXBLITTERDECL(_type) DECLEXPORT(_type)
|
---|
27 | #else
|
---|
28 | # define VBOXBLITTERDECL(_type) RTDECL(_type)
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | RT_C_DECLS_BEGIN
|
---|
32 | typedef struct CR_BLITTER_IMG
|
---|
33 | {
|
---|
34 | void *pvData;
|
---|
35 | GLuint cbData;
|
---|
36 | GLenum enmFormat;
|
---|
37 | GLuint width, height;
|
---|
38 | GLuint bpp;
|
---|
39 | GLuint pitch;
|
---|
40 | } CR_BLITTER_IMG, *PCR_BLITTER_IMG;
|
---|
41 |
|
---|
42 | VBOXBLITTERDECL(void) CrMClrFillImgRect(CR_BLITTER_IMG *pDst, const RTRECT *pCopyRect, uint32_t u32Color);
|
---|
43 | VBOXBLITTERDECL(void) CrMClrFillImg(CR_BLITTER_IMG *pImg, uint32_t cRects, const RTRECT *pRects, uint32_t u32Color);
|
---|
44 | VBOXBLITTERDECL(void) CrMBltImgRect(const CR_BLITTER_IMG *pSrc, const RTPOINT *pSrcDataPoint, bool fSrcInvert, const RTRECT *pCopyRect, CR_BLITTER_IMG *pDst);
|
---|
45 | VBOXBLITTERDECL(void) CrMBltImg(const CR_BLITTER_IMG *pSrc, const RTPOINT *pPos, uint32_t cRects, const RTRECT *pRects, CR_BLITTER_IMG *pDst);
|
---|
46 | VBOXBLITTERDECL(void) CrMBltImgRectScaled(const CR_BLITTER_IMG *pSrc, const RTPOINT *pPos, bool fSrcInvert, const RTRECT *pCopyRect, float strX, float strY, CR_BLITTER_IMG *pDst);
|
---|
47 | VBOXBLITTERDECL(void) CrMBltImgScaled(const CR_BLITTER_IMG *pSrc, const RTRECTSIZE *pSrcRectSize, const RTRECT *pDstRect, uint32_t cRects, const RTRECT *pRects, CR_BLITTER_IMG *pDst);
|
---|
48 |
|
---|
49 | /* GLSL Cache */
|
---|
50 | typedef struct CR_GLSL_CACHE
|
---|
51 | {
|
---|
52 | int iGlVersion;
|
---|
53 | GLuint uNoAlpha2DProg;
|
---|
54 | GLuint uNoAlpha2DRectProg;
|
---|
55 | SPUDispatchTable *pDispatch;
|
---|
56 | } CR_GLSL_CACHE;
|
---|
57 |
|
---|
58 | DECLINLINE(void) CrGlslInit(CR_GLSL_CACHE *pCache, SPUDispatchTable *pDispatch)
|
---|
59 | {
|
---|
60 | memset(pCache, 0, sizeof (*pCache));
|
---|
61 | pCache->pDispatch = pDispatch;
|
---|
62 | }
|
---|
63 |
|
---|
64 | DECLINLINE(bool) CrGlslIsInited(const CR_GLSL_CACHE *pCache)
|
---|
65 | {
|
---|
66 | return !!pCache->pDispatch;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /* clients should set proper context before calling these funcs */
|
---|
70 | VBOXBLITTERDECL(bool) CrGlslIsSupported(CR_GLSL_CACHE *pCache);
|
---|
71 | VBOXBLITTERDECL(int) CrGlslProgGenAllNoAlpha(CR_GLSL_CACHE *pCache);
|
---|
72 | VBOXBLITTERDECL(int) CrGlslProgGenNoAlpha(CR_GLSL_CACHE *pCache, GLenum enmTexTarget);
|
---|
73 | VBOXBLITTERDECL(int) CrGlslProgUseGenNoAlpha(CR_GLSL_CACHE *pCache, GLenum enmTexTarget);
|
---|
74 | VBOXBLITTERDECL(int) CrGlslProgUseNoAlpha(const CR_GLSL_CACHE *pCache, GLenum enmTexTarget);
|
---|
75 | VBOXBLITTERDECL(void) CrGlslProgClear(const CR_GLSL_CACHE *pCache);
|
---|
76 | VBOXBLITTERDECL(bool) CrGlslNeedsCleanup(const CR_GLSL_CACHE *pCache);
|
---|
77 | VBOXBLITTERDECL(void) CrGlslCleanup(CR_GLSL_CACHE *pCache);
|
---|
78 | VBOXBLITTERDECL(void) CrGlslTerm(CR_GLSL_CACHE *pCache);
|
---|
79 |
|
---|
80 | /* BLITTER */
|
---|
81 | typedef struct CR_BLITTER_BUFFER
|
---|
82 | {
|
---|
83 | GLuint cbBuffer;
|
---|
84 | GLvoid * pvBuffer;
|
---|
85 | } CR_BLITTER_BUFFER, *PCR_BLITTER_BUFFER;
|
---|
86 |
|
---|
87 | typedef union CR_BLITTER_FLAGS
|
---|
88 | {
|
---|
89 | struct
|
---|
90 | {
|
---|
91 | uint32_t Initialized : 1;
|
---|
92 | uint32_t CtxCreated : 1;
|
---|
93 | uint32_t SupportsFBO : 1;
|
---|
94 | uint32_t SupportsPBO : 1;
|
---|
95 | uint32_t CurrentMuralChanged : 1;
|
---|
96 | uint32_t LastWasFBODraw : 1;
|
---|
97 | uint32_t ForceDrawBlit : 1;
|
---|
98 | uint32_t ShadersGloal : 1;
|
---|
99 | uint32_t Reserved : 24;
|
---|
100 | };
|
---|
101 | uint32_t Value;
|
---|
102 | } CR_BLITTER_FLAGS, *PCR_BLITTER_FLAGS;
|
---|
103 |
|
---|
104 | struct CR_BLITTER;
|
---|
105 |
|
---|
106 | typedef DECLCALLBACK(int) FNCRBLT_BLITTER(struct CR_BLITTER *pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRect, const RTRECTSIZE *pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags);
|
---|
107 | typedef FNCRBLT_BLITTER *PFNCRBLT_BLITTER;
|
---|
108 |
|
---|
109 | typedef struct CR_BLITTER_SPUITEM
|
---|
110 | {
|
---|
111 | int id;
|
---|
112 | GLint visualBits;
|
---|
113 | } CR_BLITTER_SPUITEM, *PCR_BLITTER_SPUITEM;
|
---|
114 |
|
---|
115 | typedef struct CR_BLITTER_CONTEXT
|
---|
116 | {
|
---|
117 | CR_BLITTER_SPUITEM Base;
|
---|
118 | } CR_BLITTER_CONTEXT, *PCR_BLITTER_CONTEXT;
|
---|
119 |
|
---|
120 | typedef struct CR_BLITTER_WINDOW
|
---|
121 | {
|
---|
122 | CR_BLITTER_SPUITEM Base;
|
---|
123 | GLuint width, height;
|
---|
124 | } CR_BLITTER_WINDOW, *PCR_BLITTER_WINDOW;
|
---|
125 |
|
---|
126 | typedef struct CR_BLITTER
|
---|
127 | {
|
---|
128 | GLuint idFBO;
|
---|
129 | CR_BLITTER_FLAGS Flags;
|
---|
130 | uint32_t cEnters;
|
---|
131 | PFNCRBLT_BLITTER pfnBlt;
|
---|
132 | CR_BLITTER_BUFFER Verticies;
|
---|
133 | CR_BLITTER_BUFFER Indicies;
|
---|
134 | RTRECTSIZE CurrentSetSize;
|
---|
135 | CR_BLITTER_WINDOW CurrentMural;
|
---|
136 | CR_BLITTER_CONTEXT CtxInfo;
|
---|
137 | int32_t i32MakeCurrentUserData;
|
---|
138 | SPUDispatchTable *pDispatch;
|
---|
139 | const CR_GLSL_CACHE *pGlslCache;
|
---|
140 | CR_GLSL_CACHE LocalGlslCache;
|
---|
141 | } CR_BLITTER, *PCR_BLITTER;
|
---|
142 |
|
---|
143 | DECLINLINE(GLboolean) CrBltIsInitialized(PCR_BLITTER pBlitter)
|
---|
144 | {
|
---|
145 | return !!pBlitter->pDispatch;
|
---|
146 | }
|
---|
147 |
|
---|
148 | VBOXBLITTERDECL(int) CrBltInit(PCR_BLITTER pBlitter, const CR_BLITTER_CONTEXT *pCtxBase, bool fCreateNewCtx, bool fForceDrawBlt, const CR_GLSL_CACHE *pShaders, SPUDispatchTable *pDispatch);
|
---|
149 |
|
---|
150 | VBOXBLITTERDECL(void) CrBltTerm(PCR_BLITTER pBlitter);
|
---|
151 |
|
---|
152 | VBOXBLITTERDECL(int) CrBltCleanup(PCR_BLITTER pBlitter);
|
---|
153 |
|
---|
154 | DECLINLINE(GLboolean) CrBltSupportsTexTex(PCR_BLITTER pBlitter)
|
---|
155 | {
|
---|
156 | return pBlitter->Flags.SupportsFBO;
|
---|
157 | }
|
---|
158 |
|
---|
159 | DECLINLINE(GLboolean) CrBltIsEntered(PCR_BLITTER pBlitter)
|
---|
160 | {
|
---|
161 | return !!pBlitter->cEnters;
|
---|
162 | }
|
---|
163 |
|
---|
164 | DECLINLINE(GLint) CrBltGetVisBits(PCR_BLITTER pBlitter)
|
---|
165 | {
|
---|
166 | return pBlitter->CtxInfo.Base.visualBits;
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | DECLINLINE(GLboolean) CrBltIsEverEntered(PCR_BLITTER pBlitter)
|
---|
171 | {
|
---|
172 | return !!pBlitter->Flags.Initialized;
|
---|
173 | }
|
---|
174 |
|
---|
175 | DECLINLINE(void) CrBltSetMakeCurrentUserData(PCR_BLITTER pBlitter, int32_t i32MakeCurrentUserData)
|
---|
176 | {
|
---|
177 | pBlitter->i32MakeCurrentUserData = i32MakeCurrentUserData;
|
---|
178 | }
|
---|
179 |
|
---|
180 | VBOXBLITTERDECL(int) CrBltMuralSetCurrentInfo(PCR_BLITTER pBlitter, const CR_BLITTER_WINDOW *pMural);
|
---|
181 | DECLINLINE(const CR_BLITTER_WINDOW *) CrBltMuralGetCurrentInfo(PCR_BLITTER pBlitter)
|
---|
182 | {
|
---|
183 | return &pBlitter->CurrentMural;
|
---|
184 | }
|
---|
185 |
|
---|
186 | VBOXBLITTERDECL(void) CrBltCheckUpdateViewport(PCR_BLITTER pBlitter);
|
---|
187 |
|
---|
188 | VBOXBLITTERDECL(void) CrBltLeave(PCR_BLITTER pBlitter);
|
---|
189 | VBOXBLITTERDECL(int) CrBltEnter(PCR_BLITTER pBlitter);
|
---|
190 | VBOXBLITTERDECL(void) CrBltBlitTexMural(PCR_BLITTER pBlitter, bool fBb, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRects, const RTRECT *paDstRects, uint32_t cRects, uint32_t fFlags);
|
---|
191 | VBOXBLITTERDECL(void) CrBltBlitTexTex(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *pSrcRect, const VBOXVR_TEXTURE *pDst, const RTRECT *pDstRect, uint32_t cRects, uint32_t fFlags);
|
---|
192 | VBOXBLITTERDECL(int) CrBltImgGetTex(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, GLenum enmFormat, CR_BLITTER_IMG *pDst);
|
---|
193 |
|
---|
194 | VBOXBLITTERDECL(int) CrBltImgGetMural(PCR_BLITTER pBlitter, bool fBb, CR_BLITTER_IMG *pDst);
|
---|
195 | VBOXBLITTERDECL(void) CrBltImgFree(PCR_BLITTER pBlitter, CR_BLITTER_IMG *pDst);
|
---|
196 | VBOXBLITTERDECL(void) CrBltPresent(PCR_BLITTER pBlitter);
|
---|
197 | /* */
|
---|
198 | struct CR_TEXDATA;
|
---|
199 |
|
---|
200 | typedef DECLCALLBACK(void) FNCRTEXDATA_RELEASED(struct CR_TEXDATA *pTexture);
|
---|
201 | typedef FNCRTEXDATA_RELEASED *PFNCRTEXDATA_RELEASED;
|
---|
202 |
|
---|
203 | typedef union CR_TEXDATA_FLAGS
|
---|
204 | {
|
---|
205 | struct
|
---|
206 | {
|
---|
207 | uint32_t DataValid : 1;
|
---|
208 | uint32_t DataAcquired : 1;
|
---|
209 | uint32_t DataInverted : 1;
|
---|
210 | uint32_t Entered : 1;
|
---|
211 | uint32_t Reserved : 28;
|
---|
212 | };
|
---|
213 | uint32_t Value;
|
---|
214 | } CR_TEXDATA_FLAGS, *PCR_TEXDATA_FLAGS;
|
---|
215 |
|
---|
216 |
|
---|
217 | typedef struct CR_TEXDATA
|
---|
218 | {
|
---|
219 | VBOXVR_TEXTURE Tex;
|
---|
220 | volatile uint32_t cRefs;
|
---|
221 | /* fields specific to texture data download */
|
---|
222 | uint32_t idInvertTex;
|
---|
223 | uint32_t idPBO;
|
---|
224 | CR_TEXDATA_FLAGS Flags;
|
---|
225 | PCR_BLITTER pBlitter;
|
---|
226 | CR_BLITTER_IMG Img;
|
---|
227 | /*dtor*/
|
---|
228 | PFNCRTEXDATA_RELEASED pfnTextureReleased;
|
---|
229 | struct CR_TEXDATA *pScaledCache;
|
---|
230 | } CR_TEXDATA, *PCR_TEXDATA;
|
---|
231 |
|
---|
232 | DECLINLINE(void) CrTdInit(PCR_TEXDATA pTex, const VBOXVR_TEXTURE *pVrTex, PCR_BLITTER pBlitter, PFNCRTEXDATA_RELEASED pfnTextureReleased)
|
---|
233 | {
|
---|
234 | memset(pTex, 0, sizeof (*pTex));
|
---|
235 | pTex->Tex = *pVrTex;
|
---|
236 | pTex->cRefs = 1;
|
---|
237 | pTex->pBlitter = pBlitter;
|
---|
238 | pTex->pfnTextureReleased = pfnTextureReleased;
|
---|
239 | }
|
---|
240 |
|
---|
241 | DECLINLINE(const VBOXVR_TEXTURE*) CrTdTexGet(const CR_TEXDATA *pTex)
|
---|
242 | {
|
---|
243 | return &pTex->Tex;
|
---|
244 | }
|
---|
245 |
|
---|
246 | DECLINLINE(PCR_BLITTER) CrTdBlitterGet(CR_TEXDATA *pTex)
|
---|
247 | {
|
---|
248 | return pTex->pBlitter;
|
---|
249 | }
|
---|
250 |
|
---|
251 | DECLINLINE(int) CrTdBltEnter(PCR_TEXDATA pTex)
|
---|
252 | {
|
---|
253 | int rc;
|
---|
254 | if (pTex->Flags.Entered)
|
---|
255 | return VERR_INVALID_STATE;
|
---|
256 | rc = CrBltEnter(pTex->pBlitter);
|
---|
257 | if (!RT_SUCCESS(rc))
|
---|
258 | {
|
---|
259 | WARN(("CrBltEnter failed rc %d", rc));
|
---|
260 | return rc;
|
---|
261 | }
|
---|
262 | pTex->Flags.Entered = 1;
|
---|
263 | return VINF_SUCCESS;
|
---|
264 | }
|
---|
265 |
|
---|
266 | DECLINLINE(bool) CrTdBltIsEntered(PCR_TEXDATA pTex)
|
---|
267 | {
|
---|
268 | return pTex->Flags.Entered;
|
---|
269 | }
|
---|
270 |
|
---|
271 | DECLINLINE(void) CrTdBltLeave(PCR_TEXDATA pTex)
|
---|
272 | {
|
---|
273 | if (!pTex->Flags.Entered)
|
---|
274 | {
|
---|
275 | WARN(("invalid Blt Leave"));
|
---|
276 | return;
|
---|
277 | }
|
---|
278 |
|
---|
279 | CrBltLeave(pTex->pBlitter);
|
---|
280 |
|
---|
281 | pTex->Flags.Entered = 0;
|
---|
282 | }
|
---|
283 |
|
---|
284 | /* the CrTdBltXxx calls are done with the entered blitter */
|
---|
285 | /* acquire the texture data, returns the cached data in case it is cached.
|
---|
286 | * the data remains cached in the CR_TEXDATA object until it is discarded with CrTdBltDataFree or CrTdBltDataCleanup.
|
---|
287 | * */
|
---|
288 | VBOXBLITTERDECL(int) CrTdBltDataAcquire(PCR_TEXDATA pTex, GLenum enmFormat, bool fInverted, const CR_BLITTER_IMG**ppImg);
|
---|
289 |
|
---|
290 | VBOXBLITTERDECL(int) CrTdBltDataAcquireScaled(PCR_TEXDATA pTex, GLenum enmFormat, bool fInverted, uint32_t width, uint32_t height, const CR_BLITTER_IMG**ppImg);
|
---|
291 |
|
---|
292 | VBOXBLITTERDECL(int) CrTdBltDataReleaseScaled(PCR_TEXDATA pTex, const CR_BLITTER_IMG *pImg);
|
---|
293 |
|
---|
294 | VBOXBLITTERDECL(void) CrTdBltScaleCacheMoveTo(PCR_TEXDATA pTex, PCR_TEXDATA pDstTex);
|
---|
295 |
|
---|
296 | /* release the texture data, the data remains cached in the CR_TEXDATA object until it is discarded with CrTdBltDataFree or CrTdBltDataCleanup */
|
---|
297 | VBOXBLITTERDECL(int) CrTdBltDataRelease(PCR_TEXDATA pTex);
|
---|
298 | /* discard the texture data cached with previous CrTdBltDataAcquire.
|
---|
299 | * Must be called wit data released (CrTdBltDataRelease) */
|
---|
300 | VBOXBLITTERDECL(int) CrTdBltDataFree(PCR_TEXDATA pTex);
|
---|
301 | VBOXBLITTERDECL(int) CrTdBltDataFreeNe(PCR_TEXDATA pTex);
|
---|
302 | VBOXBLITTERDECL(void) CrTdBltDataInvalidateNe(PCR_TEXDATA pTex);
|
---|
303 | /* does same as CrTdBltDataFree, and in addition cleans up.
|
---|
304 | * this is kind of a texture destructor, which clients should call on texture object destruction, e.g. from the PFNCRTEXDATA_RELEASED callback */
|
---|
305 | VBOXBLITTERDECL(int) CrTdBltDataCleanup(PCR_TEXDATA pTex);
|
---|
306 |
|
---|
307 | VBOXBLITTERDECL(int) CrTdBltDataCleanupNe(PCR_TEXDATA pTex);
|
---|
308 |
|
---|
309 | DECLINLINE(uint32_t) CrTdAddRef(PCR_TEXDATA pTex)
|
---|
310 | {
|
---|
311 | return ASMAtomicIncU32(&pTex->cRefs);
|
---|
312 | }
|
---|
313 |
|
---|
314 | DECLINLINE(uint32_t) CrTdRelease(PCR_TEXDATA pTex)
|
---|
315 | {
|
---|
316 | uint32_t cRefs = ASMAtomicDecU32(&pTex->cRefs);
|
---|
317 | if (!cRefs)
|
---|
318 | {
|
---|
319 | if (pTex->pfnTextureReleased)
|
---|
320 | pTex->pfnTextureReleased(pTex);
|
---|
321 | else
|
---|
322 | CrTdBltDataCleanupNe(pTex);
|
---|
323 | }
|
---|
324 |
|
---|
325 | return cRefs;
|
---|
326 | }
|
---|
327 |
|
---|
328 | RT_C_DECLS_END
|
---|
329 |
|
---|
330 | #endif /* #ifndef ___cr_blitter_h__ */
|
---|