rsdAllocation.h revision 7ac2a4dda4d20ca1f1b714e129a3a08f63178c18
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef RSD_ALLOCATION_H
18#define RSD_ALLOCATION_H
19
20#include <rs_hal.h>
21#include <rsRuntime.h>
22
23#include <GLES/gl.h>
24#include <GLES2/gl2.h>
25
26class RsdFrameBufferObj;
27struct ANativeWindowBuffer;
28
29struct DrvAllocation {
30    // Is this a legal structure to be used as a texture source.
31    // Initially this will require 1D or 2D and color data
32    uint32_t textureID;
33
34    // Is this a legal structure to be used as a vertex source.
35    // Initially this will require 1D and x(yzw).  Additional per element data
36    // is allowed.
37    uint32_t bufferID;
38
39    // Is this a legal structure to be used as an FBO render target
40    uint32_t renderTargetID;
41
42    uint8_t * mallocPtr;
43
44    GLenum glTarget;
45    GLenum glType;
46    GLenum glFormat;
47
48    bool uploadDeferred;
49
50    RsdFrameBufferObj * readBackFBO;
51    ANativeWindowBuffer *wndBuffer;
52};
53
54GLenum rsdTypeToGLType(RsDataType t);
55GLenum rsdKindToGLFormat(RsDataKind k);
56
57
58bool rsdAllocationInit(const android::renderscript::Context *rsc,
59                       android::renderscript::Allocation *alloc,
60                       bool forceZero);
61void rsdAllocationDestroy(const android::renderscript::Context *rsc,
62                          android::renderscript::Allocation *alloc);
63
64void rsdAllocationResize(const android::renderscript::Context *rsc,
65                         const android::renderscript::Allocation *alloc,
66                         const android::renderscript::Type *newType, bool zeroNew);
67void rsdAllocationSyncAll(const android::renderscript::Context *rsc,
68                          const android::renderscript::Allocation *alloc,
69                          RsAllocationUsageType src);
70void rsdAllocationMarkDirty(const android::renderscript::Context *rsc,
71                            const android::renderscript::Allocation *alloc);
72int32_t rsdAllocationInitSurfaceTexture(const android::renderscript::Context *rsc,
73                                        const android::renderscript::Allocation *alloc);
74void rsdAllocationSetSurfaceTexture(const android::renderscript::Context *rsc,
75                                    android::renderscript::Allocation *alloc, ANativeWindow *nw);
76void rsdAllocationIoSend(const android::renderscript::Context *rsc,
77                         android::renderscript::Allocation *alloc);
78void rsdAllocationIoReceive(const android::renderscript::Context *rsc,
79                            android::renderscript::Allocation *alloc);
80
81void rsdAllocationData1D(const android::renderscript::Context *rsc,
82                         const android::renderscript::Allocation *alloc,
83                         uint32_t xoff, uint32_t lod, uint32_t count,
84                         const void *data, uint32_t sizeBytes);
85void rsdAllocationData2D(const android::renderscript::Context *rsc,
86                         const android::renderscript::Allocation *alloc,
87                         uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
88                         uint32_t w, uint32_t h,
89                         const void *data, uint32_t sizeBytes);
90void rsdAllocationData3D(const android::renderscript::Context *rsc,
91                         const android::renderscript::Allocation *alloc,
92                         uint32_t xoff, uint32_t yoff, uint32_t zoff,
93                         uint32_t lod, RsAllocationCubemapFace face,
94                         uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
95
96void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc,
97                               const android::renderscript::Allocation *dstAlloc,
98                               uint32_t dstXoff, uint32_t dstLod, uint32_t count,
99                               const android::renderscript::Allocation *srcAlloc,
100                               uint32_t srcXoff, uint32_t srcLod);
101void rsdAllocationData2D_alloc(const android::renderscript::Context *rsc,
102                               const android::renderscript::Allocation *dstAlloc,
103                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
104                               RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
105                               const android::renderscript::Allocation *srcAlloc,
106                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
107                               RsAllocationCubemapFace srcFace);
108void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc,
109                               const android::renderscript::Allocation *dstAlloc,
110                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
111                               uint32_t dstLod, RsAllocationCubemapFace dstFace,
112                               uint32_t w, uint32_t h, uint32_t d,
113                               const android::renderscript::Allocation *srcAlloc,
114                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
115                               uint32_t srcLod, RsAllocationCubemapFace srcFace);
116
117void rsdAllocationElementData1D(const android::renderscript::Context *rsc,
118                                const android::renderscript::Allocation *alloc,
119                                uint32_t x,
120                                const void *data, uint32_t elementOff, uint32_t sizeBytes);
121void rsdAllocationElementData2D(const android::renderscript::Context *rsc,
122                                const android::renderscript::Allocation *alloc,
123                                uint32_t x, uint32_t y,
124                                const void *data, uint32_t elementOff, uint32_t sizeBytes);
125
126
127
128
129#endif
130