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/GLConsumer.h"
33 #endif
34 
35 class RsdFrameBufferObj;
36 struct ANativeWindow;
37 struct ANativeWindowBuffer;
38 struct ANativeWindow_Buffer;
39 
40 struct 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     GLenum glTarget;
55     GLenum glType;
56     GLenum glFormat;
57 
58     ANativeWindowBuffer *wndBuffer;
59     android::GLConsumer *surfaceTexture;
60 #else
61     int glTarget;
62     int glType;
63     int glFormat;
64 
65     ANativeWindow_Buffer *wndBuffer;
66 #endif
67 
68     bool useUserProvidedPtr;
69     bool uploadDeferred;
70 
71     RsdFrameBufferObj * readBackFBO;
72     ANativeWindow *wnd;
73     ANativeWindow *wndSurface;
74 };
75 
76 #ifndef RS_COMPATIBILITY_LIB
77 GLenum rsdTypeToGLType(RsDataType t);
78 GLenum rsdKindToGLFormat(RsDataKind k);
79 #endif
80 
81 
82 uint32_t rsdAllocationGrallocBits(const android::renderscript::Context *rsc,
83                                   android::renderscript::Allocation *alloc);
84 bool rsdAllocationInit(const android::renderscript::Context *rsc,
85                        android::renderscript::Allocation *alloc,
86                        bool forceZero);
87 bool rsdAllocationAdapterInit(const android::renderscript::Context *rsc,
88                               android::renderscript::Allocation *alloc);
89 void rsdAllocationDestroy(const android::renderscript::Context *rsc,
90                           android::renderscript::Allocation *alloc);
91 
92 void rsdAllocationResize(const android::renderscript::Context *rsc,
93                          const android::renderscript::Allocation *alloc,
94                          const android::renderscript::Type *newType, bool zeroNew);
95 void rsdAllocationSyncAll(const android::renderscript::Context *rsc,
96                           const android::renderscript::Allocation *alloc,
97                           RsAllocationUsageType src);
98 void rsdAllocationMarkDirty(const android::renderscript::Context *rsc,
99                             const android::renderscript::Allocation *alloc);
100 void rsdAllocationSetSurface(const android::renderscript::Context *rsc,
101                             android::renderscript::Allocation *alloc, ANativeWindow *nw);
102 void rsdAllocationIoSend(const android::renderscript::Context *rsc,
103                          android::renderscript::Allocation *alloc);
104 void rsdAllocationIoReceive(const android::renderscript::Context *rsc,
105                             android::renderscript::Allocation *alloc);
106 
107 void rsdAllocationData1D(const android::renderscript::Context *rsc,
108                          const android::renderscript::Allocation *alloc,
109                          uint32_t xoff, uint32_t lod, size_t count,
110                          const void *data, size_t sizeBytes);
111 void rsdAllocationData2D(const android::renderscript::Context *rsc,
112                          const android::renderscript::Allocation *alloc,
113                          uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
114                          uint32_t w, uint32_t h,
115                          const void *data, size_t sizeBytes, size_t stride);
116 void rsdAllocationData3D(const android::renderscript::Context *rsc,
117                          const android::renderscript::Allocation *alloc,
118                          uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
119                          uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes,
120                          size_t stride);
121 
122 void rsdAllocationRead1D(const android::renderscript::Context *rsc,
123                          const android::renderscript::Allocation *alloc,
124                          uint32_t xoff, uint32_t lod, size_t count,
125                          void *data, size_t sizeBytes);
126 void rsdAllocationRead2D(const android::renderscript::Context *rsc,
127                          const android::renderscript::Allocation *alloc,
128                          uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
129                          uint32_t w, uint32_t h,
130                          void *data, size_t sizeBytes, size_t stride);
131 void rsdAllocationRead3D(const android::renderscript::Context *rsc,
132                          const android::renderscript::Allocation *alloc,
133                          uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
134                          uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes,
135                          size_t stride);
136 
137 void * rsdAllocationLock1D(const android::renderscript::Context *rsc,
138                           const android::renderscript::Allocation *alloc);
139 void rsdAllocationUnlock1D(const android::renderscript::Context *rsc,
140                           const android::renderscript::Allocation *alloc);
141 
142 
143 void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc,
144                                const android::renderscript::Allocation *dstAlloc,
145                                uint32_t dstXoff, uint32_t dstLod, size_t count,
146                                const android::renderscript::Allocation *srcAlloc,
147                                uint32_t srcXoff, uint32_t srcLod);
148 void rsdAllocationData2D_alloc(const android::renderscript::Context *rsc,
149                                const android::renderscript::Allocation *dstAlloc,
150                                uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
151                                RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
152                                const android::renderscript::Allocation *srcAlloc,
153                                uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
154                                RsAllocationCubemapFace srcFace);
155 void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc,
156                                const android::renderscript::Allocation *dstAlloc,
157                                uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
158                                uint32_t dstLod,
159                                uint32_t w, uint32_t h, uint32_t d,
160                                const android::renderscript::Allocation *srcAlloc,
161                                uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
162                                uint32_t srcLod);
163 
164 void rsdAllocationElementData(const android::renderscript::Context *rsc,
165                               const android::renderscript::Allocation *alloc,
166                               uint32_t x, uint32_t y, uint32_t z,
167                               const void *data, uint32_t elementOff, size_t sizeBytes);
168 
169 void rsdAllocationElementRead(const android::renderscript::Context *rsc,
170                               const android::renderscript::Allocation *alloc,
171                               uint32_t x, uint32_t y, uint32_t z,
172                               void *data, uint32_t elementOff, size_t sizeBytes);
173 
174 void rsdAllocationGenerateMipmaps(const android::renderscript::Context *rsc,
175                                   const android::renderscript::Allocation *alloc);
176 
177 void rsdAllocationUpdateCachedObject(const android::renderscript::Context *rsc,
178                                      const android::renderscript::Allocation *alloc,
179                                      android::renderscript::rs_allocation *obj);
180 
181 void rsdAllocationAdapterOffset(const android::renderscript::Context *rsc,
182                                 const android::renderscript::Allocation *alloc);
183 
184 
185 #endif
186