blob: 35999d3809231a80f09fee96f6ded49a8acbef36 [file] [log] [blame]
Jason Samseb4fe182011-05-26 16:33:01 -07001/*
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>
Jason Sams807fdc42012-07-25 17:55:39 -070022#include <rsAllocation.h>
Jason Samseb4fe182011-05-26 16:33:01 -070023
Jason Sams709a0972012-11-15 18:18:04 -080024#include "../cpu_ref/rsd_cpu.h"
Tim Murray0b575de2013-03-15 15:56:43 -070025
26#ifndef RS_SERVER
Jason Samseb4fe182011-05-26 16:33:01 -070027#include <GLES/gl.h>
28#include <GLES2/gl2.h>
Tim Murray0b575de2013-03-15 15:56:43 -070029#endif
Jason Samseb4fe182011-05-26 16:33:01 -070030
Stephen Hinesb0934b62013-07-03 17:27:38 -070031#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
32#include "gui/CpuConsumer.h"
33#include "gui/GLConsumer.h"
34#endif
35
Alex Sakhartchouka9495242011-06-16 11:05:13 -070036class RsdFrameBufferObj;
Tim Murray3a25fdd2013-02-22 17:56:56 -080037struct ANativeWindow;
Jason Sams7ac2a4d2012-02-15 12:04:24 -080038struct ANativeWindowBuffer;
Alex Sakhartchouka9495242011-06-16 11:05:13 -070039
Jason Samseb4fe182011-05-26 16:33:01 -070040struct 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
Jason Sams93eacc72012-12-18 14:26:57 -080053#ifndef RS_COMPATIBILITY_LIB
Jason Sams4961cce2013-04-11 16:11:46 -070054 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
Jason Samseb4fe182011-05-26 16:33:01 -070064 GLenum glTarget;
Jason Samsa614ae12011-05-26 17:05:51 -070065 GLenum glType;
66 GLenum glFormat;
Tim Murray3a25fdd2013-02-22 17:56:56 -080067
68 ANativeWindow *wndSurface;
69 android::GLConsumer *surfaceTexture;
Jason Sams93eacc72012-12-18 14:26:57 -080070#else
71 int glTarget;
72 int glType;
73 int glFormat;
74#endif
Jason Samsa614ae12011-05-26 17:05:51 -070075
Tim Murrayc2cfe6a2013-02-14 16:21:33 -080076 bool useUserProvidedPtr;
Jason Samseb4fe182011-05-26 16:33:01 -070077 bool uploadDeferred;
Alex Sakhartchouka9495242011-06-16 11:05:13 -070078
79 RsdFrameBufferObj * readBackFBO;
Jason Samsb3220332012-04-02 14:41:54 -070080 ANativeWindow *wnd;
Jason Sams7ac2a4d2012-02-15 12:04:24 -080081 ANativeWindowBuffer *wndBuffer;
Jason Sams733396b2013-02-22 12:46:18 -080082
Stephen Hinesb0934b62013-07-03 17:27:38 -070083#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
Jason Sams733396b2013-02-22 12:46:18 -080084 android::sp< android::CpuConsumer > cpuConsumer;
85 android::CpuConsumer::LockedBuffer lb;
Tim Murray0b575de2013-03-15 15:56:43 -070086#endif
Jason Samseb4fe182011-05-26 16:33:01 -070087};
88
Jason Sams93eacc72012-12-18 14:26:57 -080089#ifndef RS_COMPATIBILITY_LIB
Jason Samsa614ae12011-05-26 17:05:51 -070090GLenum rsdTypeToGLType(RsDataType t);
91GLenum rsdKindToGLFormat(RsDataKind k);
Jason Sams93eacc72012-12-18 14:26:57 -080092#endif
Jason Samsa614ae12011-05-26 17:05:51 -070093
94
Jason Samseb4fe182011-05-26 16:33:01 -070095bool 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);
Jason Sams733396b2013-02-22 12:46:18 -0800109void* 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);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800113void rsdAllocationIoSend(const android::renderscript::Context *rsc,
114 android::renderscript::Allocation *alloc);
115void rsdAllocationIoReceive(const android::renderscript::Context *rsc,
116 android::renderscript::Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700117
118void rsdAllocationData1D(const android::renderscript::Context *rsc,
119 const android::renderscript::Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700120 uint32_t xoff, uint32_t lod, size_t count,
121 const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700122void 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,
Tim Murray099bc262013-03-20 16:54:03 -0700126 const void *data, size_t sizeBytes, size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700127void rsdAllocationData3D(const android::renderscript::Context *rsc,
128 const android::renderscript::Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700129 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);
Jason Samseb4fe182011-05-26 16:33:01 -0700132
Jason Sams807fdc42012-07-25 17:55:39 -0700133void rsdAllocationRead1D(const android::renderscript::Context *rsc,
134 const android::renderscript::Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700135 uint32_t xoff, uint32_t lod, size_t count,
136 void *data, size_t sizeBytes);
Jason Sams807fdc42012-07-25 17:55:39 -0700137void 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,
Tim Murray099bc262013-03-20 16:54:03 -0700141 void *data, size_t sizeBytes, size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700142void rsdAllocationRead3D(const android::renderscript::Context *rsc,
143 const android::renderscript::Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700144 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);
Jason Sams807fdc42012-07-25 17:55:39 -0700147
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
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700154void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc,
155 const android::renderscript::Allocation *dstAlloc,
Tim Murray099bc262013-03-20 16:54:03 -0700156 uint32_t dstXoff, uint32_t dstLod, size_t count,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700157 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,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700169 uint32_t dstLod,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700170 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,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700173 uint32_t srcLod);
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700174
Jason Samseb4fe182011-05-26 16:33:01 -0700175void rsdAllocationElementData1D(const android::renderscript::Context *rsc,
176 const android::renderscript::Allocation *alloc,
177 uint32_t x,
Tim Murray099bc262013-03-20 16:54:03 -0700178 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700179void rsdAllocationElementData2D(const android::renderscript::Context *rsc,
180 const android::renderscript::Allocation *alloc,
181 uint32_t x, uint32_t y,
Tim Murray099bc262013-03-20 16:54:03 -0700182 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700183
Jason Samsa6dd8232012-07-25 19:33:43 -0700184void rsdAllocationGenerateMipmaps(const android::renderscript::Context *rsc,
185 const android::renderscript::Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700186
187
188
189#endif