rsdAllocation.h revision b0934b67b95cc27e2358c2aa4db5f7c1067c8f9b
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#ifndef RS_SERVER
27#include <GLES/gl.h>
28#include <GLES2/gl2.h>
29#endif
30
31#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
32#include "gui/CpuConsumer.h"
33#include "gui/GLConsumer.h"
34#endif
35
36class RsdFrameBufferObj;
37struct ANativeWindow;
38struct ANativeWindowBuffer;
39
40struct DrvAllocation {
41    // Is this a legal structure to be used as a texture source.
42    // Initially this will require 1D or 2D and color data
43    uint32_t textureID;
44
45    // Is this a legal structure to be used as a vertex source.
46    // Initially this will require 1D and x(yzw).  Additional per element data
47    // is allowed.
48    uint32_t bufferID;
49
50    // Is this a legal structure to be used as an FBO render target
51    uint32_t renderTargetID;
52
53#ifndef RS_COMPATIBILITY_LIB
54    class NewBufferListener : public android::ConsumerBase::FrameAvailableListener {
55    public:
56        const android::renderscript::Context *rsc;
57        const android::renderscript::Allocation *alloc;
58
59        virtual void onFrameAvailable();
60    };
61    android::sp<NewBufferListener> mBufferListener;
62
63
64    GLenum glTarget;
65    GLenum glType;
66    GLenum glFormat;
67
68    ANativeWindow *wndSurface;
69    android::GLConsumer *surfaceTexture;
70#else
71    int glTarget;
72    int glType;
73    int glFormat;
74#endif
75
76    bool useUserProvidedPtr;
77    bool uploadDeferred;
78
79    RsdFrameBufferObj * readBackFBO;
80    ANativeWindow *wnd;
81    ANativeWindowBuffer *wndBuffer;
82
83#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
84    android::sp< android::CpuConsumer > cpuConsumer;
85    android::CpuConsumer::LockedBuffer lb;
86#endif
87};
88
89#ifndef RS_COMPATIBILITY_LIB
90GLenum rsdTypeToGLType(RsDataType t);
91GLenum rsdKindToGLFormat(RsDataKind k);
92#endif
93
94
95bool rsdAllocationInit(const android::renderscript::Context *rsc,
96                       android::renderscript::Allocation *alloc,
97                       bool forceZero);
98void rsdAllocationDestroy(const android::renderscript::Context *rsc,
99                          android::renderscript::Allocation *alloc);
100
101void rsdAllocationResize(const android::renderscript::Context *rsc,
102                         const android::renderscript::Allocation *alloc,
103                         const android::renderscript::Type *newType, bool zeroNew);
104void rsdAllocationSyncAll(const android::renderscript::Context *rsc,
105                          const android::renderscript::Allocation *alloc,
106                          RsAllocationUsageType src);
107void rsdAllocationMarkDirty(const android::renderscript::Context *rsc,
108                            const android::renderscript::Allocation *alloc);
109void* rsdAllocationGetSurface(const android::renderscript::Context *rsc,
110                              const android::renderscript::Allocation *alloc);
111void rsdAllocationSetSurface(const android::renderscript::Context *rsc,
112                            android::renderscript::Allocation *alloc, ANativeWindow *nw);
113void rsdAllocationIoSend(const android::renderscript::Context *rsc,
114                         android::renderscript::Allocation *alloc);
115void rsdAllocationIoReceive(const android::renderscript::Context *rsc,
116                            android::renderscript::Allocation *alloc);
117
118void rsdAllocationData1D(const android::renderscript::Context *rsc,
119                         const android::renderscript::Allocation *alloc,
120                         uint32_t xoff, uint32_t lod, size_t count,
121                         const void *data, size_t sizeBytes);
122void rsdAllocationData2D(const android::renderscript::Context *rsc,
123                         const android::renderscript::Allocation *alloc,
124                         uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
125                         uint32_t w, uint32_t h,
126                         const void *data, size_t sizeBytes, size_t stride);
127void rsdAllocationData3D(const android::renderscript::Context *rsc,
128                         const android::renderscript::Allocation *alloc,
129                         uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
130                         uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes,
131                         size_t stride);
132
133void rsdAllocationRead1D(const android::renderscript::Context *rsc,
134                         const android::renderscript::Allocation *alloc,
135                         uint32_t xoff, uint32_t lod, size_t count,
136                         void *data, size_t sizeBytes);
137void rsdAllocationRead2D(const android::renderscript::Context *rsc,
138                         const android::renderscript::Allocation *alloc,
139                         uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
140                         uint32_t w, uint32_t h,
141                         void *data, size_t sizeBytes, size_t stride);
142void rsdAllocationRead3D(const android::renderscript::Context *rsc,
143                         const android::renderscript::Allocation *alloc,
144                         uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
145                         uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes,
146                         size_t stride);
147
148void * rsdAllocationLock1D(const android::renderscript::Context *rsc,
149                          const android::renderscript::Allocation *alloc);
150void rsdAllocationUnlock1D(const android::renderscript::Context *rsc,
151                          const android::renderscript::Allocation *alloc);
152
153
154void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc,
155                               const android::renderscript::Allocation *dstAlloc,
156                               uint32_t dstXoff, uint32_t dstLod, size_t count,
157                               const android::renderscript::Allocation *srcAlloc,
158                               uint32_t srcXoff, uint32_t srcLod);
159void rsdAllocationData2D_alloc(const android::renderscript::Context *rsc,
160                               const android::renderscript::Allocation *dstAlloc,
161                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
162                               RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
163                               const android::renderscript::Allocation *srcAlloc,
164                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
165                               RsAllocationCubemapFace srcFace);
166void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc,
167                               const android::renderscript::Allocation *dstAlloc,
168                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
169                               uint32_t dstLod,
170                               uint32_t w, uint32_t h, uint32_t d,
171                               const android::renderscript::Allocation *srcAlloc,
172                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
173                               uint32_t srcLod);
174
175void rsdAllocationElementData1D(const android::renderscript::Context *rsc,
176                                const android::renderscript::Allocation *alloc,
177                                uint32_t x,
178                                const void *data, uint32_t elementOff, size_t sizeBytes);
179void rsdAllocationElementData2D(const android::renderscript::Context *rsc,
180                                const android::renderscript::Allocation *alloc,
181                                uint32_t x, uint32_t y,
182                                const void *data, uint32_t elementOff, size_t sizeBytes);
183
184void rsdAllocationGenerateMipmaps(const android::renderscript::Context *rsc,
185                                  const android::renderscript::Allocation *alloc);
186
187
188
189#endif
190