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