Home | History | Annotate | Download | only in rs
      1 /*
      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 #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
     21 #include "utils/Timers.h"
     22 #endif
     23 
     24 #include <time.h>
     25 
     26 namespace android {
     27 namespace renderscript {
     28 
     29 
     30 //////////////////////////////////////////////////////////////////////////////
     31 // Context
     32 //////////////////////////////////////////////////////////////////////////////
     33 
     34 void rsrAllocationSyncAll(Context *, Script *, Allocation *);
     35 
     36 #ifndef RS_COMPATIBILITY_LIB
     37 void rsrBindTexture(Context *, ProgramFragment *, uint32_t slot, Allocation *);
     38 void rsrBindConstant(Context *, ProgramFragment *, uint32_t slot, Allocation *);
     39 void rsrBindConstant(Context *, ProgramVertex*, uint32_t slot, Allocation *);
     40 void rsrBindSampler(Context *, ProgramFragment *, uint32_t slot, Sampler *);
     41 void rsrBindProgramStore(Context *, ProgramStore *);
     42 void rsrBindProgramFragment(Context *, ProgramFragment *);
     43 void rsrBindProgramVertex(Context *, ProgramVertex *);
     44 void rsrBindProgramRaster(Context *, ProgramRaster *);
     45 void rsrBindFrameBufferObjectColorTarget(Context *, Allocation *, uint32_t slot);
     46 void rsrBindFrameBufferObjectDepthTarget(Context *, Allocation *);
     47 void rsrClearFrameBufferObjectColorTarget(Context *, uint32_t slot);
     48 void rsrClearFrameBufferObjectDepthTarget(Context *);
     49 void rsrClearFrameBufferObjectTargets(Context *);
     50 
     51 //////////////////////////////////////////////////////////////////////////////
     52 // VP
     53 //////////////////////////////////////////////////////////////////////////////
     54 
     55 void rsrVpLoadProjectionMatrix(Context *, const rsc_Matrix *m);
     56 void rsrVpLoadModelMatrix(Context *, const rsc_Matrix *m);
     57 void rsrVpLoadTextureMatrix(Context *, const rsc_Matrix *m);
     58 void rsrPfConstantColor(Context *, ProgramFragment *, float r, float g, float b, float a);
     59 void rsrVpGetProjectionMatrix(Context *, rsc_Matrix *m);
     60 
     61 //////////////////////////////////////////////////////////////////////////////
     62 // Drawing
     63 //////////////////////////////////////////////////////////////////////////////
     64 
     65 void rsrDrawPath(Context *, Path *);
     66 void rsrDrawMesh(Context *, Mesh *);
     67 void rsrDrawMeshPrimitive(Context *, Mesh *, uint32_t primIndex);
     68 void rsrDrawMeshPrimitiveRange(Context *, Mesh *,
     69                                uint32_t primIndex, uint32_t start, uint32_t len);
     70 void rsrMeshComputeBoundingBox(Context *, Mesh *,
     71                                float *minX, float *minY, float *minZ,
     72                                float *maxX, float *maxY, float *maxZ);
     73 
     74 
     75 //////////////////////////////////////////////////////////////////////////////
     76 //
     77 //////////////////////////////////////////////////////////////////////////////
     78 
     79 
     80 void rsrColor(Context *, float r, float g, float b, float a);
     81 #endif
     82 
     83 void 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);
     89 void 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 
     97 #ifndef RS_COMPATIBILITY_LIB
     98 void rsrPrepareClear(Context *);
     99 uint32_t rsrGetWidth(Context *);
    100 uint32_t rsrGetHeight(Context *);
    101 void rsrDrawTextAlloc(Context *, Allocation *, int x, int y);
    102 void rsrDrawText(Context *, const char *text, int x, int y);
    103 void rsrSetMetrics(Context *, Font::Rect *metrics,
    104                    int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
    105 void rsrMeasureTextAlloc(Context *, Allocation *,
    106                          int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
    107 void rsrMeasureText(Context *, const char *text,
    108                     int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
    109 void rsrBindFont(Context *, Font *);
    110 void rsrFontColor(Context *, float r, float g, float b, float a);
    111 #endif
    112 
    113 //////////////////////////////////////////////////////////////////////////////
    114 // Time routines
    115 //////////////////////////////////////////////////////////////////////////////
    116 
    117 float rsrGetDt(Context *, const Script *sc);
    118 time_t rsrTime(Context *, time_t *timer);
    119 tm* rsrLocalTime(Context *, tm *local, time_t *timer);
    120 int64_t rsrUptimeMillis(Context *);
    121 int64_t rsrUptimeNanos(Context *);
    122 
    123 //////////////////////////////////////////////////////////////////////////////
    124 // Message routines
    125 //////////////////////////////////////////////////////////////////////////////
    126 
    127 uint32_t rsrToClient(Context *, int cmdID, void *data, int len);
    128 uint32_t rsrToClientBlocking(Context *, int cmdID, void *data, int len);
    129 
    130 //////////////////////////////////////////////////////////////////////////////
    131 //
    132 //////////////////////////////////////////////////////////////////////////////
    133 
    134 void rsrSetObject(const Context *, ObjectBase **dst, ObjectBase * src);
    135 void rsrClearObject(const Context *, ObjectBase **dst);
    136 bool rsrIsObject(const Context *, const ObjectBase *src);
    137 
    138 void rsrAllocationIncRefs(const Context *, const Allocation *, void *ptr,
    139                           size_t elementCount, size_t startOffset);
    140 void rsrAllocationDecRefs(const Context *, const Allocation *, void *ptr,
    141                           size_t elementCount, size_t startOffset);
    142 
    143 
    144 void rsrAllocationSyncAll(Context *, Allocation *a, RsAllocationUsageType source);
    145 
    146 
    147 void rsrForEach(Context *, Script *target,
    148                 Allocation *in,
    149                 Allocation *out,
    150                 const void *usr,
    151                  uint32_t usrBytes,
    152                 const RsScriptCall *call);
    153 
    154 
    155 //////////////////////////////////////////////////////////////////////////////
    156 // Heavy math functions
    157 //////////////////////////////////////////////////////////////////////////////
    158 
    159 
    160 void rsrMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v);
    161 float rsrMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col);
    162 void rsrMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v);
    163 float rsrMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col);
    164 void rsrMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v);
    165 float rsrMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col);
    166 void rsrMatrixLoadIdentity_4x4(rs_matrix4x4 *m);
    167 void rsrMatrixLoadIdentity_3x3(rs_matrix3x3 *m);
    168 void rsrMatrixLoadIdentity_2x2(rs_matrix2x2 *m);
    169 void rsrMatrixLoad_4x4_f(rs_matrix4x4 *m, const float *v);
    170 void rsrMatrixLoad_3x3_f(rs_matrix3x3 *m, const float *v);
    171 void rsrMatrixLoad_2x2_f(rs_matrix2x2 *m, const float *v);
    172 void rsrMatrixLoad_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *v);
    173 void rsrMatrixLoad_4x4_3x3(rs_matrix4x4 *m, const rs_matrix3x3 *v);
    174 void rsrMatrixLoad_4x4_2x2(rs_matrix4x4 *m, const rs_matrix2x2 *v);
    175 void rsrMatrixLoad_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *v);
    176 void rsrMatrixLoad_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *v);
    177 void rsrMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
    178 void rsrMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z);
    179 void rsrMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z);
    180 void rsrMatrixLoadMultiply_4x4_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *lhs,
    181                                        const rs_matrix4x4 *rhs);
    182 void rsrMatrixMultiply_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *rhs);
    183 void rsrMatrixLoadMultiply_3x3_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *lhs,
    184                                        const rs_matrix3x3 *rhs);
    185 void rsrMatrixMultiply_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *rhs);
    186 void rsrMatrixLoadMultiply_2x2_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *lhs,
    187                                        const rs_matrix2x2 *rhs);
    188 void rsrMatrixMultiply_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *rhs);
    189 void rsrMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
    190 void rsrMatrixScale(rs_matrix4x4 *m, float x, float y, float z);
    191 void rsrMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z);
    192 void rsrMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right,
    193                         float bottom, float top, float near, float far);
    194 void rsrMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right,
    195                           float bottom, float top, float near, float far);
    196 void rsrMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
    197 
    198 // Returns true if the matrix was successfully inversed
    199 bool rsrMatrixInverse_4x4(rs_matrix4x4 *m);
    200 // Returns true if the matrix was successfully inversed
    201 bool rsrMatrixInverseTranspose_4x4(rs_matrix4x4 *m);
    202 
    203 void rsrMatrixTranspose_4x4(rs_matrix4x4 *m);
    204 void rsrMatrixTranspose_3x3(rs_matrix3x3 *m);
    205 void rsrMatrixTranspose_2x2(rs_matrix2x2 *m);
    206 
    207 }
    208 }
    209