blob: 7baba08fd622285249f061619beee22ae259728e [file] [log] [blame]
Jason Sams87fe59a2011-04-20 15:09:01 -07001/*
2 * Copyright (C) 2009 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#include "rsContext.h"
18#include "rsScriptC.h"
19
Stephen Hinesb0934b62013-07-03 17:27:38 -070020#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
Jason Sams87fe59a2011-04-20 15:09:01 -070021#include "utils/Timers.h"
Tim Murray0b575de2013-03-15 15:56:43 -070022#endif
Jason Sams87fe59a2011-04-20 15:09:01 -070023
24#include <time.h>
25
26namespace android {
27namespace renderscript {
28
29
30//////////////////////////////////////////////////////////////////////////////
31// Context
32//////////////////////////////////////////////////////////////////////////////
33
Jason Sams93eacc72012-12-18 14:26:57 -080034void rsrAllocationSyncAll(Context *, Script *, Allocation *);
35
36#ifndef RS_COMPATIBILITY_LIB
Jason Sams709a0972012-11-15 18:18:04 -080037void rsrBindTexture(Context *, ProgramFragment *, uint32_t slot, Allocation *);
38void rsrBindConstant(Context *, ProgramFragment *, uint32_t slot, Allocation *);
39void rsrBindConstant(Context *, ProgramVertex*, uint32_t slot, Allocation *);
40void rsrBindSampler(Context *, ProgramFragment *, uint32_t slot, Sampler *);
41void rsrBindProgramStore(Context *, ProgramStore *);
42void rsrBindProgramFragment(Context *, ProgramFragment *);
43void rsrBindProgramVertex(Context *, ProgramVertex *);
44void rsrBindProgramRaster(Context *, ProgramRaster *);
45void rsrBindFrameBufferObjectColorTarget(Context *, Allocation *, uint32_t slot);
46void rsrBindFrameBufferObjectDepthTarget(Context *, Allocation *);
47void rsrClearFrameBufferObjectColorTarget(Context *, uint32_t slot);
48void rsrClearFrameBufferObjectDepthTarget(Context *);
49void rsrClearFrameBufferObjectTargets(Context *);
Jason Sams87fe59a2011-04-20 15:09:01 -070050
51//////////////////////////////////////////////////////////////////////////////
52// VP
53//////////////////////////////////////////////////////////////////////////////
54
Jason Sams709a0972012-11-15 18:18:04 -080055void rsrVpLoadProjectionMatrix(Context *, const rsc_Matrix *m);
56void rsrVpLoadModelMatrix(Context *, const rsc_Matrix *m);
57void rsrVpLoadTextureMatrix(Context *, const rsc_Matrix *m);
58void rsrPfConstantColor(Context *, ProgramFragment *, float r, float g, float b, float a);
59void rsrVpGetProjectionMatrix(Context *, rsc_Matrix *m);
Jason Sams87fe59a2011-04-20 15:09:01 -070060
61//////////////////////////////////////////////////////////////////////////////
62// Drawing
63//////////////////////////////////////////////////////////////////////////////
64
Jason Sams709a0972012-11-15 18:18:04 -080065void rsrDrawPath(Context *, Path *);
66void rsrDrawMesh(Context *, Mesh *);
67void rsrDrawMeshPrimitive(Context *, Mesh *, uint32_t primIndex);
68void rsrDrawMeshPrimitiveRange(Context *, Mesh *,
Jason Sams87fe59a2011-04-20 15:09:01 -070069 uint32_t primIndex, uint32_t start, uint32_t len);
Jason Sams709a0972012-11-15 18:18:04 -080070void rsrMeshComputeBoundingBox(Context *, Mesh *,
Jason Sams87fe59a2011-04-20 15:09:01 -070071 float *minX, float *minY, float *minZ,
72 float *maxX, float *maxY, float *maxZ);
73
74
75//////////////////////////////////////////////////////////////////////////////
76//
77//////////////////////////////////////////////////////////////////////////////
78
79
Jason Sams709a0972012-11-15 18:18:04 -080080void rsrColor(Context *, float r, float g, float b, float a);
Jason Sams93eacc72012-12-18 14:26:57 -080081#endif
Alex Sakhartchouk74a82792011-06-14 11:13:19 -070082
83void rsrAllocationCopy1DRange(Context *, Allocation *dstAlloc,
84 uint32_t dstOff,
85 uint32_t dstMip,
86 uint32_t count,
87 Allocation *srcAlloc,
88 uint32_t srcOff, uint32_t srcMip);
89void rsrAllocationCopy2DRange(Context *, Allocation *dstAlloc,
90 uint32_t dstXoff, uint32_t dstYoff,
91 uint32_t dstMip, uint32_t dstFace,
92 uint32_t width, uint32_t height,
93 Allocation *srcAlloc,
94 uint32_t srcXoff, uint32_t srcYoff,
95 uint32_t srcMip, uint32_t srcFace);
96
Jason Sams93eacc72012-12-18 14:26:57 -080097#ifndef RS_COMPATIBILITY_LIB
Jason Sams709a0972012-11-15 18:18:04 -080098void rsrPrepareClear(Context *);
99uint32_t rsrGetWidth(Context *);
100uint32_t rsrGetHeight(Context *);
101void rsrDrawTextAlloc(Context *, Allocation *, int x, int y);
102void rsrDrawText(Context *, const char *text, int x, int y);
103void rsrSetMetrics(Context *, Font::Rect *metrics,
Jason Sams87fe59a2011-04-20 15:09:01 -0700104 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
Jason Sams709a0972012-11-15 18:18:04 -0800105void rsrMeasureTextAlloc(Context *, Allocation *,
Jason Sams87fe59a2011-04-20 15:09:01 -0700106 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
Jason Sams709a0972012-11-15 18:18:04 -0800107void rsrMeasureText(Context *, const char *text,
Jason Sams87fe59a2011-04-20 15:09:01 -0700108 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
Jason Sams709a0972012-11-15 18:18:04 -0800109void rsrBindFont(Context *, Font *);
110void rsrFontColor(Context *, float r, float g, float b, float a);
Jason Samsddceab92013-08-07 13:02:32 -0700111
Stephen Hines7a011262013-11-27 14:21:57 -0800112#endif
113
Jason Samsddceab92013-08-07 13:02:32 -0700114void rsrAllocationIoSend(Context *, Allocation *);
115void rsrAllocationIoReceive(Context *, Allocation *);
116
Jason Sams87fe59a2011-04-20 15:09:01 -0700117//////////////////////////////////////////////////////////////////////////////
118// Time routines
119//////////////////////////////////////////////////////////////////////////////
120
Jason Sams709a0972012-11-15 18:18:04 -0800121float rsrGetDt(Context *, const Script *sc);
122time_t rsrTime(Context *, time_t *timer);
123tm* rsrLocalTime(Context *, tm *local, time_t *timer);
124int64_t rsrUptimeMillis(Context *);
125int64_t rsrUptimeNanos(Context *);
Jason Sams87fe59a2011-04-20 15:09:01 -0700126
127//////////////////////////////////////////////////////////////////////////////
128// Message routines
129//////////////////////////////////////////////////////////////////////////////
130
Stephen Hines70537f52013-12-03 16:44:44 -0800131// Keep existing routines to not break current GPU drivers.
132uint32_t __attribute((used)) rsrToClient(Context *, int cmdID, void *data, int len);
133uint32_t __attribute((used)) rsrToClientBlocking(Context *, int cmdID, void *data, int len);
134
Stephen Hines276000a2013-12-03 09:33:32 -0800135uint32_t rsrToClient(Context *, int cmdID, const void *data, int len);
136uint32_t rsrToClientBlocking(Context *, int cmdID, const void *data, int len);
Jason Sams87fe59a2011-04-20 15:09:01 -0700137
138//////////////////////////////////////////////////////////////////////////////
139//
140//////////////////////////////////////////////////////////////////////////////
141
Jason Sams05ef73f2014-08-05 14:59:22 -0700142void rsrSetObject(const Context *, rs_object_base *dst, const ObjectBase *src);
143void rsrClearObject(const Context *, rs_object_base *dst);
Tim Murray6a45ddb2014-08-06 11:49:02 -0700144
Jason Sams05ef73f2014-08-05 14:59:22 -0700145bool rsrIsObject(const Context *, rs_object_base src);
Tim Murray6a45ddb2014-08-06 11:49:02 -0700146bool rsrIsObject(const Context *, ObjectBase* src);
Jason Sams87fe59a2011-04-20 15:09:01 -0700147
Jason Samseb4fe182011-05-26 16:33:01 -0700148void rsrAllocationIncRefs(const Context *, const Allocation *, void *ptr,
149 size_t elementCount, size_t startOffset);
150void rsrAllocationDecRefs(const Context *, const Allocation *, void *ptr,
151 size_t elementCount, size_t startOffset);
152
153
Jason Sams709a0972012-11-15 18:18:04 -0800154void rsrAllocationSyncAll(Context *, Allocation *a, RsAllocationUsageType source);
Jason Sams87fe59a2011-04-20 15:09:01 -0700155
156
Jason Sams709a0972012-11-15 18:18:04 -0800157void rsrForEach(Context *, Script *target,
Yang Ni12398d82015-09-18 14:57:07 -0700158 uint32_t slot,
Yang Nidda5cb52015-10-27 15:23:17 -0700159 uint32_t numInputs,
160 Allocation **in,
Jason Sams87fe59a2011-04-20 15:09:01 -0700161 Allocation *out,
162 const void *usr,
Chris Wailesf3712132014-07-16 15:18:30 -0700163 uint32_t usrBytes,
Pirama Arumuga Nainar9479e5b2015-04-28 14:40:45 -0700164 const RsScriptCall *call);
Jason Sams87fe59a2011-04-20 15:09:01 -0700165
Pirama Arumuga Nainar6b387c12015-10-12 14:06:57 -0700166RsElement rsrElementCreate(Context *rsc, RsDataType dt, RsDataKind dk,
167 bool norm, uint32_t vecSize);
168
169RsType rsrTypeCreate(Context *, const RsElement element, uint32_t dimX,
170 uint32_t dimY, uint32_t dimZ, bool mipmaps, bool faces,
171 uint32_t yuv);
172
173RsAllocation rsrAllocationCreateTyped(Context *, const RsType type,
174 RsAllocationMipmapControl mipmaps,
175 uint32_t usages, uintptr_t ptr);
Jason Sams87fe59a2011-04-20 15:09:01 -0700176
177//////////////////////////////////////////////////////////////////////////////
178// Heavy math functions
179//////////////////////////////////////////////////////////////////////////////
180
181
182void rsrMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v);
183float rsrMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col);
184void rsrMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v);
185float rsrMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col);
186void rsrMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v);
187float rsrMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col);
188void rsrMatrixLoadIdentity_4x4(rs_matrix4x4 *m);
189void rsrMatrixLoadIdentity_3x3(rs_matrix3x3 *m);
190void rsrMatrixLoadIdentity_2x2(rs_matrix2x2 *m);
191void rsrMatrixLoad_4x4_f(rs_matrix4x4 *m, const float *v);
192void rsrMatrixLoad_3x3_f(rs_matrix3x3 *m, const float *v);
193void rsrMatrixLoad_2x2_f(rs_matrix2x2 *m, const float *v);
194void rsrMatrixLoad_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *v);
195void rsrMatrixLoad_4x4_3x3(rs_matrix4x4 *m, const rs_matrix3x3 *v);
196void rsrMatrixLoad_4x4_2x2(rs_matrix4x4 *m, const rs_matrix2x2 *v);
197void rsrMatrixLoad_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *v);
198void rsrMatrixLoad_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *v);
199void rsrMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
200void rsrMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z);
201void rsrMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z);
202void rsrMatrixLoadMultiply_4x4_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *lhs,
203 const rs_matrix4x4 *rhs);
204void rsrMatrixMultiply_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *rhs);
205void rsrMatrixLoadMultiply_3x3_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *lhs,
206 const rs_matrix3x3 *rhs);
207void rsrMatrixMultiply_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *rhs);
208void rsrMatrixLoadMultiply_2x2_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *lhs,
209 const rs_matrix2x2 *rhs);
210void rsrMatrixMultiply_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *rhs);
211void rsrMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
212void rsrMatrixScale(rs_matrix4x4 *m, float x, float y, float z);
213void rsrMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z);
214void rsrMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right,
215 float bottom, float top, float near, float far);
216void rsrMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right,
217 float bottom, float top, float near, float far);
218void rsrMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
219
220// Returns true if the matrix was successfully inversed
221bool rsrMatrixInverse_4x4(rs_matrix4x4 *m);
222// Returns true if the matrix was successfully inversed
223bool rsrMatrixInverseTranspose_4x4(rs_matrix4x4 *m);
224
225void rsrMatrixTranspose_4x4(rs_matrix4x4 *m);
226void rsrMatrixTranspose_3x3(rs_matrix3x3 *m);
227void rsrMatrixTranspose_2x2(rs_matrix2x2 *m);
228
229}
230}