rsdAllocation.h revision 358747a3118301c5faeee73c98dd5f839bbfb54a
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#include <rsAllocation.h>
23
24#include "../cpu_ref/rsd_cpu.h"
25
26#include <GLES/gl.h>
27#include <GLES2/gl2.h>
28
29class RsdFrameBufferObj;
30struct ANativeWindowBuffer;
31
32struct DrvAllocation {
33    // Is this a legal structure to be used as a texture source.
34    // Initially this will require 1D or 2D and color data
35    uint32_t textureID;
36
37    // Is this a legal structure to be used as a vertex source.
38    // Initially this will require 1D and x(yzw).  Additional per element data
39    // is allowed.
40    uint32_t bufferID;
41
42    // Is this a legal structure to be used as an FBO render target
43    uint32_t renderTargetID;
44
45    GLenum glTarget;
46    GLenum glType;
47    GLenum glFormat;
48
49    bool uploadDeferred;
50
51    RsdFrameBufferObj * readBackFBO;
52    ANativeWindow *wnd;
53    ANativeWindowBuffer *wndBuffer;
54};
55
56GLenum rsdTypeToGLType(RsDataType t);
57GLenum rsdKindToGLFormat(RsDataKind k);
58
59
60bool rsdAllocationInit(const android::renderscript::Context *rsc,
61                       android::renderscript::Allocation *alloc,
62                       bool forceZero);
63void rsdAllocationDestroy(const android::renderscript::Context *rsc,
64                          android::renderscript::Allocation *alloc);
65
66void rsdAllocationResize(const android::renderscript::Context *rsc,
67                         const android::renderscript::Allocation *alloc,
68                         const android::renderscript::Type *newType, bool zeroNew);
69void rsdAllocationSyncAll(const android::renderscript::Context *rsc,
70                          const android::renderscript::Allocation *alloc,
71                          RsAllocationUsageType src);
72void rsdAllocationMarkDirty(const android::renderscript::Context *rsc,
73                            const android::renderscript::Allocation *alloc);
74int32_t rsdAllocationInitSurfaceTexture(const android::renderscript::Context *rsc,
75                                        const android::renderscript::Allocation *alloc);
76void rsdAllocationSetSurfaceTexture(const android::renderscript::Context *rsc,
77                                    android::renderscript::Allocation *alloc, ANativeWindow *nw);
78void rsdAllocationIoSend(const android::renderscript::Context *rsc,
79                         android::renderscript::Allocation *alloc);
80void rsdAllocationIoReceive(const android::renderscript::Context *rsc,
81                            android::renderscript::Allocation *alloc);
82
83void rsdAllocationData1D(const android::renderscript::Context *rsc,
84                         const android::renderscript::Allocation *alloc,
85                         uint32_t xoff, uint32_t lod, uint32_t count,
86                         const void *data, uint32_t sizeBytes);
87void rsdAllocationData2D(const android::renderscript::Context *rsc,
88                         const android::renderscript::Allocation *alloc,
89                         uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
90                         uint32_t w, uint32_t h,
91                         const void *data, uint32_t sizeBytes, size_t stride);
92void rsdAllocationData3D(const android::renderscript::Context *rsc,
93                         const android::renderscript::Allocation *alloc,
94                         uint32_t xoff, uint32_t yoff, uint32_t zoff,
95                         uint32_t lod, RsAllocationCubemapFace face,
96                         uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
97
98void rsdAllocationRead1D(const android::renderscript::Context *rsc,
99                         const android::renderscript::Allocation *alloc,
100                         uint32_t xoff, uint32_t lod, uint32_t count,
101                         void *data, uint32_t sizeBytes);
102void rsdAllocationRead2D(const android::renderscript::Context *rsc,
103                         const android::renderscript::Allocation *alloc,
104                         uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
105                         uint32_t w, uint32_t h,
106                         void *data, uint32_t sizeBytes, size_t stride);
107void rsdAllocationRead3D(const android::renderscript::Context *rsc,
108                         const android::renderscript::Allocation *alloc,
109                         uint32_t xoff, uint32_t yoff, uint32_t zoff,
110                         uint32_t lod, RsAllocationCubemapFace face,
111                         uint32_t w, uint32_t h, uint32_t d, void *data, uint32_t sizeBytes);
112
113void * rsdAllocationLock1D(const android::renderscript::Context *rsc,
114                          const android::renderscript::Allocation *alloc);
115void rsdAllocationUnlock1D(const android::renderscript::Context *rsc,
116                          const android::renderscript::Allocation *alloc);
117
118
119void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc,
120                               const android::renderscript::Allocation *dstAlloc,
121                               uint32_t dstXoff, uint32_t dstLod, uint32_t count,
122                               const android::renderscript::Allocation *srcAlloc,
123                               uint32_t srcXoff, uint32_t srcLod);
124void rsdAllocationData2D_alloc(const android::renderscript::Context *rsc,
125                               const android::renderscript::Allocation *dstAlloc,
126                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
127                               RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
128                               const android::renderscript::Allocation *srcAlloc,
129                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
130                               RsAllocationCubemapFace srcFace);
131void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc,
132                               const android::renderscript::Allocation *dstAlloc,
133                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
134                               uint32_t dstLod, RsAllocationCubemapFace dstFace,
135                               uint32_t w, uint32_t h, uint32_t d,
136                               const android::renderscript::Allocation *srcAlloc,
137                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
138                               uint32_t srcLod, RsAllocationCubemapFace srcFace);
139
140void rsdAllocationElementData1D(const android::renderscript::Context *rsc,
141                                const android::renderscript::Allocation *alloc,
142                                uint32_t x,
143                                const void *data, uint32_t elementOff, uint32_t sizeBytes);
144void rsdAllocationElementData2D(const android::renderscript::Context *rsc,
145                                const android::renderscript::Allocation *alloc,
146                                uint32_t x, uint32_t y,
147                                const void *data, uint32_t elementOff, uint32_t sizeBytes);
148
149void rsdAllocationGenerateMipmaps(const android::renderscript::Context *rsc,
150                                  const android::renderscript::Allocation *alloc);
151
152
153
154#endif
155