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