blob: 3a20cb0355908adb77e7dfa6381280199da11c88 [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 Sams709a0972012-11-15 18:18:04 -080032void rsrBindTexture(Context *, ProgramFragment *, uint32_t slot, Allocation *);
33void rsrBindConstant(Context *, ProgramFragment *, uint32_t slot, Allocation *);
34void rsrBindConstant(Context *, ProgramVertex*, uint32_t slot, Allocation *);
35void rsrBindSampler(Context *, ProgramFragment *, uint32_t slot, Sampler *);
36void rsrBindProgramStore(Context *, ProgramStore *);
37void rsrBindProgramFragment(Context *, ProgramFragment *);
38void rsrBindProgramVertex(Context *, ProgramVertex *);
39void rsrBindProgramRaster(Context *, ProgramRaster *);
40void rsrBindFrameBufferObjectColorTarget(Context *, Allocation *, uint32_t slot);
41void rsrBindFrameBufferObjectDepthTarget(Context *, Allocation *);
42void rsrClearFrameBufferObjectColorTarget(Context *, uint32_t slot);
43void rsrClearFrameBufferObjectDepthTarget(Context *);
44void rsrClearFrameBufferObjectTargets(Context *);
Jason Sams87fe59a2011-04-20 15:09:01 -070045
46//////////////////////////////////////////////////////////////////////////////
47// VP
48//////////////////////////////////////////////////////////////////////////////
49
Jason Sams709a0972012-11-15 18:18:04 -080050void rsrVpLoadProjectionMatrix(Context *, const rsc_Matrix *m);
51void rsrVpLoadModelMatrix(Context *, const rsc_Matrix *m);
52void rsrVpLoadTextureMatrix(Context *, const rsc_Matrix *m);
53void rsrPfConstantColor(Context *, ProgramFragment *, float r, float g, float b, float a);
54void rsrVpGetProjectionMatrix(Context *, rsc_Matrix *m);
Jason Sams87fe59a2011-04-20 15:09:01 -070055
56//////////////////////////////////////////////////////////////////////////////
57// Drawing
58//////////////////////////////////////////////////////////////////////////////
59
Jason Sams709a0972012-11-15 18:18:04 -080060void rsrDrawPath(Context *, Path *);
61void rsrDrawMesh(Context *, Mesh *);
62void rsrDrawMeshPrimitive(Context *, Mesh *, uint32_t primIndex);
63void rsrDrawMeshPrimitiveRange(Context *, Mesh *,
Jason Sams87fe59a2011-04-20 15:09:01 -070064 uint32_t primIndex, uint32_t start, uint32_t len);
Jason Sams709a0972012-11-15 18:18:04 -080065void rsrMeshComputeBoundingBox(Context *, Mesh *,
Jason Sams87fe59a2011-04-20 15:09:01 -070066 float *minX, float *minY, float *minZ,
67 float *maxX, float *maxY, float *maxZ);
68
69
70//////////////////////////////////////////////////////////////////////////////
71//
72//////////////////////////////////////////////////////////////////////////////
73
74
Jason Sams709a0972012-11-15 18:18:04 -080075void rsrColor(Context *, float r, float g, float b, float a);
Alex Sakhartchouk74a82792011-06-14 11:13:19 -070076
77void rsrAllocationCopy1DRange(Context *, Allocation *dstAlloc,
78 uint32_t dstOff,
79 uint32_t dstMip,
80 uint32_t count,
81 Allocation *srcAlloc,
82 uint32_t srcOff, uint32_t srcMip);
83void rsrAllocationCopy2DRange(Context *, Allocation *dstAlloc,
84 uint32_t dstXoff, uint32_t dstYoff,
85 uint32_t dstMip, uint32_t dstFace,
86 uint32_t width, uint32_t height,
87 Allocation *srcAlloc,
88 uint32_t srcXoff, uint32_t srcYoff,
89 uint32_t srcMip, uint32_t srcFace);
90
Jason Sams709a0972012-11-15 18:18:04 -080091void rsrPrepareClear(Context *);
92uint32_t rsrGetWidth(Context *);
93uint32_t rsrGetHeight(Context *);
94void rsrDrawTextAlloc(Context *, Allocation *, int x, int y);
95void rsrDrawText(Context *, const char *text, int x, int y);
96void rsrSetMetrics(Context *, Font::Rect *metrics,
Jason Sams87fe59a2011-04-20 15:09:01 -070097 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
Jason Sams709a0972012-11-15 18:18:04 -080098void rsrMeasureTextAlloc(Context *, Allocation *,
Jason Sams87fe59a2011-04-20 15:09:01 -070099 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
Jason Sams709a0972012-11-15 18:18:04 -0800100void rsrMeasureText(Context *, const char *text,
Jason Sams87fe59a2011-04-20 15:09:01 -0700101 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
Jason Sams709a0972012-11-15 18:18:04 -0800102void rsrBindFont(Context *, Font *);
103void rsrFontColor(Context *, float r, float g, float b, float a);
Jason Sams87fe59a2011-04-20 15:09:01 -0700104
105//////////////////////////////////////////////////////////////////////////////
106// Time routines
107//////////////////////////////////////////////////////////////////////////////
108
Jason Sams709a0972012-11-15 18:18:04 -0800109float rsrGetDt(Context *, const Script *sc);
110time_t rsrTime(Context *, time_t *timer);
111tm* rsrLocalTime(Context *, tm *local, time_t *timer);
112int64_t rsrUptimeMillis(Context *);
113int64_t rsrUptimeNanos(Context *);
Jason Sams87fe59a2011-04-20 15:09:01 -0700114
115//////////////////////////////////////////////////////////////////////////////
116// Message routines
117//////////////////////////////////////////////////////////////////////////////
118
Jason Sams709a0972012-11-15 18:18:04 -0800119uint32_t rsrToClient(Context *, int cmdID, void *data, int len);
120uint32_t rsrToClientBlocking(Context *, int cmdID, void *data, int len);
Jason Sams87fe59a2011-04-20 15:09:01 -0700121
122//////////////////////////////////////////////////////////////////////////////
123//
124//////////////////////////////////////////////////////////////////////////////
125
Jason Sams709a0972012-11-15 18:18:04 -0800126void rsrSetObject(const Context *, ObjectBase **dst, ObjectBase * src);
127void rsrClearObject(const Context *, ObjectBase **dst);
128bool rsrIsObject(const Context *, const ObjectBase *src);
Jason Sams87fe59a2011-04-20 15:09:01 -0700129
Jason Samseb4fe182011-05-26 16:33:01 -0700130void rsrAllocationIncRefs(const Context *, const Allocation *, void *ptr,
131 size_t elementCount, size_t startOffset);
132void rsrAllocationDecRefs(const Context *, const Allocation *, void *ptr,
133 size_t elementCount, size_t startOffset);
134
135
Jason Sams709a0972012-11-15 18:18:04 -0800136void rsrAllocationSyncAll(Context *, Allocation *a, RsAllocationUsageType source);
Jason Sams87fe59a2011-04-20 15:09:01 -0700137
138
Jason Sams709a0972012-11-15 18:18:04 -0800139void rsrForEach(Context *, Script *target,
Jason Sams87fe59a2011-04-20 15:09:01 -0700140 Allocation *in,
141 Allocation *out,
142 const void *usr,
143 uint32_t usrBytes,
144 const RsScriptCall *call);
145
146
147//////////////////////////////////////////////////////////////////////////////
148// Heavy math functions
149//////////////////////////////////////////////////////////////////////////////
150
151
152void rsrMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v);
153float rsrMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col);
154void rsrMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v);
155float rsrMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col);
156void rsrMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v);
157float rsrMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col);
158void rsrMatrixLoadIdentity_4x4(rs_matrix4x4 *m);
159void rsrMatrixLoadIdentity_3x3(rs_matrix3x3 *m);
160void rsrMatrixLoadIdentity_2x2(rs_matrix2x2 *m);
161void rsrMatrixLoad_4x4_f(rs_matrix4x4 *m, const float *v);
162void rsrMatrixLoad_3x3_f(rs_matrix3x3 *m, const float *v);
163void rsrMatrixLoad_2x2_f(rs_matrix2x2 *m, const float *v);
164void rsrMatrixLoad_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *v);
165void rsrMatrixLoad_4x4_3x3(rs_matrix4x4 *m, const rs_matrix3x3 *v);
166void rsrMatrixLoad_4x4_2x2(rs_matrix4x4 *m, const rs_matrix2x2 *v);
167void rsrMatrixLoad_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *v);
168void rsrMatrixLoad_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *v);
169void rsrMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
170void rsrMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z);
171void rsrMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z);
172void rsrMatrixLoadMultiply_4x4_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *lhs,
173 const rs_matrix4x4 *rhs);
174void rsrMatrixMultiply_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *rhs);
175void rsrMatrixLoadMultiply_3x3_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *lhs,
176 const rs_matrix3x3 *rhs);
177void rsrMatrixMultiply_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *rhs);
178void rsrMatrixLoadMultiply_2x2_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *lhs,
179 const rs_matrix2x2 *rhs);
180void rsrMatrixMultiply_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *rhs);
181void rsrMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
182void rsrMatrixScale(rs_matrix4x4 *m, float x, float y, float z);
183void rsrMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z);
184void rsrMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right,
185 float bottom, float top, float near, float far);
186void rsrMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right,
187 float bottom, float top, float near, float far);
188void rsrMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
189
190// Returns true if the matrix was successfully inversed
191bool rsrMatrixInverse_4x4(rs_matrix4x4 *m);
192// Returns true if the matrix was successfully inversed
193bool rsrMatrixInverseTranspose_4x4(rs_matrix4x4 *m);
194
195void rsrMatrixTranspose_4x4(rs_matrix4x4 *m);
196void rsrMatrixTranspose_3x3(rs_matrix3x3 *m);
197void rsrMatrixTranspose_2x2(rs_matrix2x2 *m);
198
199}
200}