blob: e1fbd51ea55a6587b082a5247eb533534d10392d [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
Jason Sams87fe59a2011-04-20 15:09:01 -070020#include <time.h>
21
22namespace android {
23namespace renderscript {
24
25
26//////////////////////////////////////////////////////////////////////////////
27// Context
28//////////////////////////////////////////////////////////////////////////////
29
Jason Sams93eacc72012-12-18 14:26:57 -080030void rsrAllocationSyncAll(Context *, Script *, Allocation *);
31
32#ifndef RS_COMPATIBILITY_LIB
Jason Sams709a0972012-11-15 18:18:04 -080033void rsrBindTexture(Context *, ProgramFragment *, uint32_t slot, Allocation *);
34void rsrBindConstant(Context *, ProgramFragment *, uint32_t slot, Allocation *);
35void rsrBindConstant(Context *, ProgramVertex*, uint32_t slot, Allocation *);
36void rsrBindSampler(Context *, ProgramFragment *, uint32_t slot, Sampler *);
37void rsrBindProgramStore(Context *, ProgramStore *);
38void rsrBindProgramFragment(Context *, ProgramFragment *);
39void rsrBindProgramVertex(Context *, ProgramVertex *);
40void rsrBindProgramRaster(Context *, ProgramRaster *);
41void rsrBindFrameBufferObjectColorTarget(Context *, Allocation *, uint32_t slot);
42void rsrBindFrameBufferObjectDepthTarget(Context *, Allocation *);
43void rsrClearFrameBufferObjectColorTarget(Context *, uint32_t slot);
44void rsrClearFrameBufferObjectDepthTarget(Context *);
45void rsrClearFrameBufferObjectTargets(Context *);
Jason Sams87fe59a2011-04-20 15:09:01 -070046
47//////////////////////////////////////////////////////////////////////////////
48// VP
49//////////////////////////////////////////////////////////////////////////////
50
Jason Sams709a0972012-11-15 18:18:04 -080051void rsrVpLoadProjectionMatrix(Context *, const rsc_Matrix *m);
52void rsrVpLoadModelMatrix(Context *, const rsc_Matrix *m);
53void rsrVpLoadTextureMatrix(Context *, const rsc_Matrix *m);
54void rsrPfConstantColor(Context *, ProgramFragment *, float r, float g, float b, float a);
55void rsrVpGetProjectionMatrix(Context *, rsc_Matrix *m);
Jason Sams87fe59a2011-04-20 15:09:01 -070056
57//////////////////////////////////////////////////////////////////////////////
58// Drawing
59//////////////////////////////////////////////////////////////////////////////
60
Jason Sams709a0972012-11-15 18:18:04 -080061void rsrDrawPath(Context *, Path *);
62void rsrDrawMesh(Context *, Mesh *);
63void rsrDrawMeshPrimitive(Context *, Mesh *, uint32_t primIndex);
64void rsrDrawMeshPrimitiveRange(Context *, Mesh *,
Jason Sams87fe59a2011-04-20 15:09:01 -070065 uint32_t primIndex, uint32_t start, uint32_t len);
Jason Sams709a0972012-11-15 18:18:04 -080066void rsrMeshComputeBoundingBox(Context *, Mesh *,
Jason Sams87fe59a2011-04-20 15:09:01 -070067 float *minX, float *minY, float *minZ,
68 float *maxX, float *maxY, float *maxZ);
69
70
71//////////////////////////////////////////////////////////////////////////////
72//
73//////////////////////////////////////////////////////////////////////////////
74
75
Jason Sams709a0972012-11-15 18:18:04 -080076void rsrColor(Context *, float r, float g, float b, float a);
Jason Sams93eacc72012-12-18 14:26:57 -080077#endif
Alex Sakhartchouk74a82792011-06-14 11:13:19 -070078
79void rsrAllocationCopy1DRange(Context *, Allocation *dstAlloc,
80 uint32_t dstOff,
81 uint32_t dstMip,
82 uint32_t count,
83 Allocation *srcAlloc,
84 uint32_t srcOff, uint32_t srcMip);
85void rsrAllocationCopy2DRange(Context *, Allocation *dstAlloc,
86 uint32_t dstXoff, uint32_t dstYoff,
87 uint32_t dstMip, uint32_t dstFace,
88 uint32_t width, uint32_t height,
89 Allocation *srcAlloc,
90 uint32_t srcXoff, uint32_t srcYoff,
91 uint32_t srcMip, uint32_t srcFace);
92
Jason Sams93eacc72012-12-18 14:26:57 -080093#ifndef RS_COMPATIBILITY_LIB
Jason Sams709a0972012-11-15 18:18:04 -080094void rsrPrepareClear(Context *);
95uint32_t rsrGetWidth(Context *);
96uint32_t rsrGetHeight(Context *);
97void rsrDrawTextAlloc(Context *, Allocation *, int x, int y);
98void rsrDrawText(Context *, const char *text, int x, int y);
99void rsrSetMetrics(Context *, Font::Rect *metrics,
Jason Sams87fe59a2011-04-20 15:09:01 -0700100 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
Jason Sams709a0972012-11-15 18:18:04 -0800101void rsrMeasureTextAlloc(Context *, Allocation *,
Jason Sams87fe59a2011-04-20 15:09:01 -0700102 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
Jason Sams709a0972012-11-15 18:18:04 -0800103void rsrMeasureText(Context *, const char *text,
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 rsrBindFont(Context *, Font *);
106void rsrFontColor(Context *, float r, float g, float b, float a);
Jason Samsddceab92013-08-07 13:02:32 -0700107
Stephen Hines7a011262013-11-27 14:21:57 -0800108#endif
109
Jason Samsddceab92013-08-07 13:02:32 -0700110void rsrAllocationIoSend(Context *, Allocation *);
111void rsrAllocationIoReceive(Context *, Allocation *);
112
Jason Sams87fe59a2011-04-20 15:09:01 -0700113//////////////////////////////////////////////////////////////////////////////
114// Time routines
115//////////////////////////////////////////////////////////////////////////////
116
Jason Sams709a0972012-11-15 18:18:04 -0800117float rsrGetDt(Context *, const Script *sc);
118time_t rsrTime(Context *, time_t *timer);
119tm* rsrLocalTime(Context *, tm *local, time_t *timer);
120int64_t rsrUptimeMillis(Context *);
121int64_t rsrUptimeNanos(Context *);
Jason Sams87fe59a2011-04-20 15:09:01 -0700122
123//////////////////////////////////////////////////////////////////////////////
124// Message routines
125//////////////////////////////////////////////////////////////////////////////
126
Stephen Hines70537f52013-12-03 16:44:44 -0800127// Keep existing routines to not break current GPU drivers.
128uint32_t __attribute((used)) rsrToClient(Context *, int cmdID, void *data, int len);
129uint32_t __attribute((used)) rsrToClientBlocking(Context *, int cmdID, void *data, int len);
130
Stephen Hines276000a2013-12-03 09:33:32 -0800131uint32_t rsrToClient(Context *, int cmdID, const void *data, int len);
132uint32_t rsrToClientBlocking(Context *, int cmdID, const void *data, int len);
Jason Sams87fe59a2011-04-20 15:09:01 -0700133
134//////////////////////////////////////////////////////////////////////////////
135//
136//////////////////////////////////////////////////////////////////////////////
137
Jason Sams05ef73f2014-08-05 14:59:22 -0700138void rsrSetObject(const Context *, rs_object_base *dst, const ObjectBase *src);
Yang Niade31372016-04-06 09:34:34 -0700139void rsrClearObject(rs_object_base *dst);
Tim Murray6a45ddb2014-08-06 11:49:02 -0700140
Jason Sams05ef73f2014-08-05 14:59:22 -0700141bool rsrIsObject(const Context *, rs_object_base src);
Tim Murray6a45ddb2014-08-06 11:49:02 -0700142bool rsrIsObject(const Context *, ObjectBase* src);
Jason Sams87fe59a2011-04-20 15:09:01 -0700143
Jason Samseb4fe182011-05-26 16:33:01 -0700144void rsrAllocationIncRefs(const Context *, const Allocation *, void *ptr,
145 size_t elementCount, size_t startOffset);
146void rsrAllocationDecRefs(const Context *, const Allocation *, void *ptr,
147 size_t elementCount, size_t startOffset);
148
149
Jason Sams709a0972012-11-15 18:18:04 -0800150void rsrAllocationSyncAll(Context *, Allocation *a, RsAllocationUsageType source);
Jason Sams87fe59a2011-04-20 15:09:01 -0700151
152
Jason Sams709a0972012-11-15 18:18:04 -0800153void rsrForEach(Context *, Script *target,
Yang Ni12398d82015-09-18 14:57:07 -0700154 uint32_t slot,
Yang Nidda5cb52015-10-27 15:23:17 -0700155 uint32_t numInputs,
156 Allocation **in,
Jason Sams87fe59a2011-04-20 15:09:01 -0700157 Allocation *out,
158 const void *usr,
Chris Wailesf3712132014-07-16 15:18:30 -0700159 uint32_t usrBytes,
Pirama Arumuga Nainar9479e5b2015-04-28 14:40:45 -0700160 const RsScriptCall *call);
Jason Sams87fe59a2011-04-20 15:09:01 -0700161
Pirama Arumuga Nainar6b387c12015-10-12 14:06:57 -0700162RsElement rsrElementCreate(Context *rsc, RsDataType dt, RsDataKind dk,
163 bool norm, uint32_t vecSize);
164
165RsType rsrTypeCreate(Context *, const RsElement element, uint32_t dimX,
166 uint32_t dimY, uint32_t dimZ, bool mipmaps, bool faces,
167 uint32_t yuv);
168
169RsAllocation rsrAllocationCreateTyped(Context *, const RsType type,
170 RsAllocationMipmapControl mipmaps,
171 uint32_t usages, uintptr_t ptr);
Jason Sams87fe59a2011-04-20 15:09:01 -0700172
173//////////////////////////////////////////////////////////////////////////////
174// Heavy math functions
175//////////////////////////////////////////////////////////////////////////////
176
177
178void rsrMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v);
179float rsrMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col);
180void rsrMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v);
181float rsrMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col);
182void rsrMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v);
183float rsrMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col);
184void rsrMatrixLoadIdentity_4x4(rs_matrix4x4 *m);
185void rsrMatrixLoadIdentity_3x3(rs_matrix3x3 *m);
186void rsrMatrixLoadIdentity_2x2(rs_matrix2x2 *m);
187void rsrMatrixLoad_4x4_f(rs_matrix4x4 *m, const float *v);
188void rsrMatrixLoad_3x3_f(rs_matrix3x3 *m, const float *v);
189void rsrMatrixLoad_2x2_f(rs_matrix2x2 *m, const float *v);
190void rsrMatrixLoad_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *v);
191void rsrMatrixLoad_4x4_3x3(rs_matrix4x4 *m, const rs_matrix3x3 *v);
192void rsrMatrixLoad_4x4_2x2(rs_matrix4x4 *m, const rs_matrix2x2 *v);
193void rsrMatrixLoad_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *v);
194void rsrMatrixLoad_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *v);
195void rsrMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
196void rsrMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z);
197void rsrMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z);
198void rsrMatrixLoadMultiply_4x4_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *lhs,
199 const rs_matrix4x4 *rhs);
200void rsrMatrixMultiply_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *rhs);
201void rsrMatrixLoadMultiply_3x3_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *lhs,
202 const rs_matrix3x3 *rhs);
203void rsrMatrixMultiply_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *rhs);
204void rsrMatrixLoadMultiply_2x2_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *lhs,
205 const rs_matrix2x2 *rhs);
206void rsrMatrixMultiply_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *rhs);
207void rsrMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
208void rsrMatrixScale(rs_matrix4x4 *m, float x, float y, float z);
209void rsrMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z);
210void rsrMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right,
211 float bottom, float top, float near, float far);
212void rsrMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right,
213 float bottom, float top, float near, float far);
214void rsrMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
215
216// Returns true if the matrix was successfully inversed
217bool rsrMatrixInverse_4x4(rs_matrix4x4 *m);
218// Returns true if the matrix was successfully inversed
219bool rsrMatrixInverseTranspose_4x4(rs_matrix4x4 *m);
220
221void rsrMatrixTranspose_4x4(rs_matrix4x4 *m);
222void rsrMatrixTranspose_3x3(rs_matrix3x3 *m);
223void rsrMatrixTranspose_2x2(rs_matrix2x2 *m);
224
Rahul Chaudhry7974fc02017-02-09 12:33:28 -0800225} // namespace renderscript
226} // namespace android