blob: 390338bf7f447f40243cdef725695cc7c0a087a5 [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
20#include "utils/Timers.h"
21
22#include <time.h>
23
24namespace android {
25namespace renderscript {
26
27
28//////////////////////////////////////////////////////////////////////////////
29// Context
30//////////////////////////////////////////////////////////////////////////////
31
Jason Sams93eacc72012-12-18 14:26:57 -080032void rsrAllocationSyncAll(Context *, Script *, Allocation *);
33
34#ifndef RS_COMPATIBILITY_LIB
Jason Sams709a0972012-11-15 18:18:04 -080035void rsrBindTexture(Context *, ProgramFragment *, uint32_t slot, Allocation *);
36void rsrBindConstant(Context *, ProgramFragment *, uint32_t slot, Allocation *);
37void rsrBindConstant(Context *, ProgramVertex*, uint32_t slot, Allocation *);
38void rsrBindSampler(Context *, ProgramFragment *, uint32_t slot, Sampler *);
39void rsrBindProgramStore(Context *, ProgramStore *);
40void rsrBindProgramFragment(Context *, ProgramFragment *);
41void rsrBindProgramVertex(Context *, ProgramVertex *);
42void rsrBindProgramRaster(Context *, ProgramRaster *);
43void rsrBindFrameBufferObjectColorTarget(Context *, Allocation *, uint32_t slot);
44void rsrBindFrameBufferObjectDepthTarget(Context *, Allocation *);
45void rsrClearFrameBufferObjectColorTarget(Context *, uint32_t slot);
46void rsrClearFrameBufferObjectDepthTarget(Context *);
47void rsrClearFrameBufferObjectTargets(Context *);
Jason Sams87fe59a2011-04-20 15:09:01 -070048
49//////////////////////////////////////////////////////////////////////////////
50// VP
51//////////////////////////////////////////////////////////////////////////////
52
Jason Sams709a0972012-11-15 18:18:04 -080053void rsrVpLoadProjectionMatrix(Context *, const rsc_Matrix *m);
54void rsrVpLoadModelMatrix(Context *, const rsc_Matrix *m);
55void rsrVpLoadTextureMatrix(Context *, const rsc_Matrix *m);
56void rsrPfConstantColor(Context *, ProgramFragment *, float r, float g, float b, float a);
57void rsrVpGetProjectionMatrix(Context *, rsc_Matrix *m);
Jason Sams87fe59a2011-04-20 15:09:01 -070058
59//////////////////////////////////////////////////////////////////////////////
60// Drawing
61//////////////////////////////////////////////////////////////////////////////
62
Jason Sams709a0972012-11-15 18:18:04 -080063void rsrDrawPath(Context *, Path *);
64void rsrDrawMesh(Context *, Mesh *);
65void rsrDrawMeshPrimitive(Context *, Mesh *, uint32_t primIndex);
66void rsrDrawMeshPrimitiveRange(Context *, Mesh *,
Jason Sams87fe59a2011-04-20 15:09:01 -070067 uint32_t primIndex, uint32_t start, uint32_t len);
Jason Sams709a0972012-11-15 18:18:04 -080068void rsrMeshComputeBoundingBox(Context *, Mesh *,
Jason Sams87fe59a2011-04-20 15:09:01 -070069 float *minX, float *minY, float *minZ,
70 float *maxX, float *maxY, float *maxZ);
71
72
73//////////////////////////////////////////////////////////////////////////////
74//
75//////////////////////////////////////////////////////////////////////////////
76
77
Jason Sams709a0972012-11-15 18:18:04 -080078void rsrColor(Context *, float r, float g, float b, float a);
Jason Sams93eacc72012-12-18 14:26:57 -080079#endif
Alex Sakhartchouk74a82792011-06-14 11:13:19 -070080
81void rsrAllocationCopy1DRange(Context *, Allocation *dstAlloc,
82 uint32_t dstOff,
83 uint32_t dstMip,
84 uint32_t count,
85 Allocation *srcAlloc,
86 uint32_t srcOff, uint32_t srcMip);
87void rsrAllocationCopy2DRange(Context *, Allocation *dstAlloc,
88 uint32_t dstXoff, uint32_t dstYoff,
89 uint32_t dstMip, uint32_t dstFace,
90 uint32_t width, uint32_t height,
91 Allocation *srcAlloc,
92 uint32_t srcXoff, uint32_t srcYoff,
93 uint32_t srcMip, uint32_t srcFace);
94
Jason Sams93eacc72012-12-18 14:26:57 -080095#ifndef RS_COMPATIBILITY_LIB
Jason Sams709a0972012-11-15 18:18:04 -080096void rsrPrepareClear(Context *);
97uint32_t rsrGetWidth(Context *);
98uint32_t rsrGetHeight(Context *);
99void rsrDrawTextAlloc(Context *, Allocation *, int x, int y);
100void rsrDrawText(Context *, const char *text, int x, int y);
101void rsrSetMetrics(Context *, Font::Rect *metrics,
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 rsrMeasureTextAlloc(Context *, Allocation *,
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 rsrMeasureText(Context *, const char *text,
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 rsrBindFont(Context *, Font *);
108void rsrFontColor(Context *, float r, float g, float b, float a);
Jason Sams93eacc72012-12-18 14:26:57 -0800109#endif
Jason Sams87fe59a2011-04-20 15:09:01 -0700110
111//////////////////////////////////////////////////////////////////////////////
112// Time routines
113//////////////////////////////////////////////////////////////////////////////
114
Jason Sams709a0972012-11-15 18:18:04 -0800115float rsrGetDt(Context *, const Script *sc);
116time_t rsrTime(Context *, time_t *timer);
117tm* rsrLocalTime(Context *, tm *local, time_t *timer);
118int64_t rsrUptimeMillis(Context *);
119int64_t rsrUptimeNanos(Context *);
Jason Sams87fe59a2011-04-20 15:09:01 -0700120
121//////////////////////////////////////////////////////////////////////////////
122// Message routines
123//////////////////////////////////////////////////////////////////////////////
124
Jason Sams709a0972012-11-15 18:18:04 -0800125uint32_t rsrToClient(Context *, int cmdID, void *data, int len);
126uint32_t rsrToClientBlocking(Context *, int cmdID, void *data, int len);
Jason Sams87fe59a2011-04-20 15:09:01 -0700127
128//////////////////////////////////////////////////////////////////////////////
129//
130//////////////////////////////////////////////////////////////////////////////
131
Jason Sams709a0972012-11-15 18:18:04 -0800132void rsrSetObject(const Context *, ObjectBase **dst, ObjectBase * src);
133void rsrClearObject(const Context *, ObjectBase **dst);
134bool rsrIsObject(const Context *, const ObjectBase *src);
Jason Sams87fe59a2011-04-20 15:09:01 -0700135
Jason Samseb4fe182011-05-26 16:33:01 -0700136void rsrAllocationIncRefs(const Context *, const Allocation *, void *ptr,
137 size_t elementCount, size_t startOffset);
138void rsrAllocationDecRefs(const Context *, const Allocation *, void *ptr,
139 size_t elementCount, size_t startOffset);
140
141
Jason Sams709a0972012-11-15 18:18:04 -0800142void rsrAllocationSyncAll(Context *, Allocation *a, RsAllocationUsageType source);
Jason Sams87fe59a2011-04-20 15:09:01 -0700143
144
Jason Sams709a0972012-11-15 18:18:04 -0800145void rsrForEach(Context *, Script *target,
Jason Sams87fe59a2011-04-20 15:09:01 -0700146 Allocation *in,
147 Allocation *out,
148 const void *usr,
149 uint32_t usrBytes,
150 const RsScriptCall *call);
151
152
153//////////////////////////////////////////////////////////////////////////////
154// Heavy math functions
155//////////////////////////////////////////////////////////////////////////////
156
157
158void rsrMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v);
159float rsrMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col);
160void rsrMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v);
161float rsrMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col);
162void rsrMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v);
163float rsrMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col);
164void rsrMatrixLoadIdentity_4x4(rs_matrix4x4 *m);
165void rsrMatrixLoadIdentity_3x3(rs_matrix3x3 *m);
166void rsrMatrixLoadIdentity_2x2(rs_matrix2x2 *m);
167void rsrMatrixLoad_4x4_f(rs_matrix4x4 *m, const float *v);
168void rsrMatrixLoad_3x3_f(rs_matrix3x3 *m, const float *v);
169void rsrMatrixLoad_2x2_f(rs_matrix2x2 *m, const float *v);
170void rsrMatrixLoad_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *v);
171void rsrMatrixLoad_4x4_3x3(rs_matrix4x4 *m, const rs_matrix3x3 *v);
172void rsrMatrixLoad_4x4_2x2(rs_matrix4x4 *m, const rs_matrix2x2 *v);
173void rsrMatrixLoad_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *v);
174void rsrMatrixLoad_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *v);
175void rsrMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
176void rsrMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z);
177void rsrMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z);
178void rsrMatrixLoadMultiply_4x4_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *lhs,
179 const rs_matrix4x4 *rhs);
180void rsrMatrixMultiply_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *rhs);
181void rsrMatrixLoadMultiply_3x3_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *lhs,
182 const rs_matrix3x3 *rhs);
183void rsrMatrixMultiply_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *rhs);
184void rsrMatrixLoadMultiply_2x2_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *lhs,
185 const rs_matrix2x2 *rhs);
186void rsrMatrixMultiply_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *rhs);
187void rsrMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
188void rsrMatrixScale(rs_matrix4x4 *m, float x, float y, float z);
189void rsrMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z);
190void rsrMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right,
191 float bottom, float top, float near, float far);
192void rsrMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right,
193 float bottom, float top, float near, float far);
194void rsrMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
195
196// Returns true if the matrix was successfully inversed
197bool rsrMatrixInverse_4x4(rs_matrix4x4 *m);
198// Returns true if the matrix was successfully inversed
199bool rsrMatrixInverseTranspose_4x4(rs_matrix4x4 *m);
200
201void rsrMatrixTranspose_4x4(rs_matrix4x4 *m);
202void rsrMatrixTranspose_3x3(rs_matrix3x3 *m);
203void rsrMatrixTranspose_2x2(rs_matrix2x2 *m);
204
205}
206}