blob: 97e0d6a867b6d3da9617c66d4e72b8a5cb592c67 [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 Sams733396b2013-02-22 12:46:18 -080027#include "gui/CpuConsumer.h"
Tim Murray3a25fdd2013-02-22 17:56:56 -080028#include "gui/GLConsumer.h"
Jason Samseb4fe182011-05-26 16:33:01 -070029#include <GLES/gl.h>
30#include <GLES2/gl2.h>
Tim Murray0b575de2013-03-15 15:56:43 -070031#endif
Jason Samseb4fe182011-05-26 16:33:01 -070032
Alex Sakhartchouka9495242011-06-16 11:05:13 -070033class RsdFrameBufferObj;
Tim Murray3a25fdd2013-02-22 17:56:56 -080034struct ANativeWindow;
Jason Sams7ac2a4d2012-02-15 12:04:24 -080035struct ANativeWindowBuffer;
Alex Sakhartchouka9495242011-06-16 11:05:13 -070036
Jason Samseb4fe182011-05-26 16:33:01 -070037struct DrvAllocation {
38 // Is this a legal structure to be used as a texture source.
39 // Initially this will require 1D or 2D and color data
40 uint32_t textureID;
41
42 // Is this a legal structure to be used as a vertex source.
43 // Initially this will require 1D and x(yzw). Additional per element data
44 // is allowed.
45 uint32_t bufferID;
46
47 // Is this a legal structure to be used as an FBO render target
48 uint32_t renderTargetID;
49
Jason Sams93eacc72012-12-18 14:26:57 -080050#ifndef RS_COMPATIBILITY_LIB
Jason Sams4961cce2013-04-11 16:11:46 -070051 class NewBufferListener : public android::ConsumerBase::FrameAvailableListener {
52 public:
53 const android::renderscript::Context *rsc;
54 const android::renderscript::Allocation *alloc;
55
56 virtual void onFrameAvailable();
57 };
58 android::sp<NewBufferListener> mBufferListener;
59
60
Jason Samseb4fe182011-05-26 16:33:01 -070061 GLenum glTarget;
Jason Samsa614ae12011-05-26 17:05:51 -070062 GLenum glType;
63 GLenum glFormat;
Tim Murray3a25fdd2013-02-22 17:56:56 -080064
65 ANativeWindow *wndSurface;
66 android::GLConsumer *surfaceTexture;
Jason Sams93eacc72012-12-18 14:26:57 -080067#else
68 int glTarget;
69 int glType;
70 int glFormat;
71#endif
Jason Samsa614ae12011-05-26 17:05:51 -070072
Tim Murrayc2cfe6a2013-02-14 16:21:33 -080073 bool useUserProvidedPtr;
Jason Samseb4fe182011-05-26 16:33:01 -070074 bool uploadDeferred;
Alex Sakhartchouka9495242011-06-16 11:05:13 -070075
76 RsdFrameBufferObj * readBackFBO;
Jason Samsb3220332012-04-02 14:41:54 -070077 ANativeWindow *wnd;
Jason Sams7ac2a4d2012-02-15 12:04:24 -080078 ANativeWindowBuffer *wndBuffer;
Jason Sams733396b2013-02-22 12:46:18 -080079
Tim Murray0b575de2013-03-15 15:56:43 -070080#ifndef RS_SERVER
Jason Sams733396b2013-02-22 12:46:18 -080081 android::sp< android::CpuConsumer > cpuConsumer;
82 android::CpuConsumer::LockedBuffer lb;
Tim Murray0b575de2013-03-15 15:56:43 -070083#endif
Jason Samseb4fe182011-05-26 16:33:01 -070084};
85
Jason Sams93eacc72012-12-18 14:26:57 -080086#ifndef RS_COMPATIBILITY_LIB
Jason Samsa614ae12011-05-26 17:05:51 -070087GLenum rsdTypeToGLType(RsDataType t);
88GLenum rsdKindToGLFormat(RsDataKind k);
Jason Sams93eacc72012-12-18 14:26:57 -080089#endif
Jason Samsa614ae12011-05-26 17:05:51 -070090
91
Jason Samseb4fe182011-05-26 16:33:01 -070092bool rsdAllocationInit(const android::renderscript::Context *rsc,
93 android::renderscript::Allocation *alloc,
94 bool forceZero);
95void rsdAllocationDestroy(const android::renderscript::Context *rsc,
96 android::renderscript::Allocation *alloc);
97
98void rsdAllocationResize(const android::renderscript::Context *rsc,
99 const android::renderscript::Allocation *alloc,
100 const android::renderscript::Type *newType, bool zeroNew);
101void rsdAllocationSyncAll(const android::renderscript::Context *rsc,
102 const android::renderscript::Allocation *alloc,
103 RsAllocationUsageType src);
104void rsdAllocationMarkDirty(const android::renderscript::Context *rsc,
105 const android::renderscript::Allocation *alloc);
Jason Sams733396b2013-02-22 12:46:18 -0800106void* rsdAllocationGetSurface(const android::renderscript::Context *rsc,
107 const android::renderscript::Allocation *alloc);
108void rsdAllocationSetSurface(const android::renderscript::Context *rsc,
109 android::renderscript::Allocation *alloc, ANativeWindow *nw);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800110void rsdAllocationIoSend(const android::renderscript::Context *rsc,
111 android::renderscript::Allocation *alloc);
112void rsdAllocationIoReceive(const android::renderscript::Context *rsc,
113 android::renderscript::Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700114
115void rsdAllocationData1D(const android::renderscript::Context *rsc,
116 const android::renderscript::Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700117 uint32_t xoff, uint32_t lod, size_t count,
118 const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700119void rsdAllocationData2D(const android::renderscript::Context *rsc,
120 const android::renderscript::Allocation *alloc,
121 uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
122 uint32_t w, uint32_t h,
Tim Murray099bc262013-03-20 16:54:03 -0700123 const void *data, size_t sizeBytes, size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700124void rsdAllocationData3D(const android::renderscript::Context *rsc,
125 const android::renderscript::Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700126 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
127 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes,
128 size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700129
Jason Sams807fdc42012-07-25 17:55:39 -0700130void rsdAllocationRead1D(const android::renderscript::Context *rsc,
131 const android::renderscript::Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700132 uint32_t xoff, uint32_t lod, size_t count,
133 void *data, size_t sizeBytes);
Jason Sams807fdc42012-07-25 17:55:39 -0700134void rsdAllocationRead2D(const android::renderscript::Context *rsc,
135 const android::renderscript::Allocation *alloc,
136 uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
137 uint32_t w, uint32_t h,
Tim Murray099bc262013-03-20 16:54:03 -0700138 void *data, size_t sizeBytes, size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700139void rsdAllocationRead3D(const android::renderscript::Context *rsc,
140 const android::renderscript::Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700141 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
142 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes,
143 size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700144
145void * rsdAllocationLock1D(const android::renderscript::Context *rsc,
146 const android::renderscript::Allocation *alloc);
147void rsdAllocationUnlock1D(const android::renderscript::Context *rsc,
148 const android::renderscript::Allocation *alloc);
149
150
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700151void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc,
152 const android::renderscript::Allocation *dstAlloc,
Tim Murray099bc262013-03-20 16:54:03 -0700153 uint32_t dstXoff, uint32_t dstLod, size_t count,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700154 const android::renderscript::Allocation *srcAlloc,
155 uint32_t srcXoff, uint32_t srcLod);
156void rsdAllocationData2D_alloc(const android::renderscript::Context *rsc,
157 const android::renderscript::Allocation *dstAlloc,
158 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
159 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
160 const android::renderscript::Allocation *srcAlloc,
161 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
162 RsAllocationCubemapFace srcFace);
163void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc,
164 const android::renderscript::Allocation *dstAlloc,
165 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700166 uint32_t dstLod,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700167 uint32_t w, uint32_t h, uint32_t d,
168 const android::renderscript::Allocation *srcAlloc,
169 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700170 uint32_t srcLod);
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700171
Jason Samseb4fe182011-05-26 16:33:01 -0700172void rsdAllocationElementData1D(const android::renderscript::Context *rsc,
173 const android::renderscript::Allocation *alloc,
174 uint32_t x,
Tim Murray099bc262013-03-20 16:54:03 -0700175 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700176void rsdAllocationElementData2D(const android::renderscript::Context *rsc,
177 const android::renderscript::Allocation *alloc,
178 uint32_t x, uint32_t y,
Tim Murray099bc262013-03-20 16:54:03 -0700179 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700180
Jason Samsa6dd8232012-07-25 19:33:43 -0700181void rsdAllocationGenerateMipmaps(const android::renderscript::Context *rsc,
182 const android::renderscript::Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700183
184
185
186#endif