rsRuntime.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. #include "rsContext.h"
  17. #include "rsScriptC.h"
  18. #include <time.h>
  19. namespace android {
  20. namespace renderscript {
  21. //////////////////////////////////////////////////////////////////////////////
  22. // Context
  23. //////////////////////////////////////////////////////////////////////////////
  24. void rsrAllocationSyncAll(Context *, Script *, Allocation *);
  25. #ifndef RS_COMPATIBILITY_LIB
  26. void rsrBindTexture(Context *, ProgramFragment *, uint32_t slot, Allocation *);
  27. void rsrBindConstant(Context *, ProgramFragment *, uint32_t slot, Allocation *);
  28. void rsrBindConstant(Context *, ProgramVertex*, uint32_t slot, Allocation *);
  29. void rsrBindSampler(Context *, ProgramFragment *, uint32_t slot, Sampler *);
  30. void rsrBindProgramStore(Context *, ProgramStore *);
  31. void rsrBindProgramFragment(Context *, ProgramFragment *);
  32. void rsrBindProgramVertex(Context *, ProgramVertex *);
  33. void rsrBindProgramRaster(Context *, ProgramRaster *);
  34. void rsrBindFrameBufferObjectColorTarget(Context *, Allocation *, uint32_t slot);
  35. void rsrBindFrameBufferObjectDepthTarget(Context *, Allocation *);
  36. void rsrClearFrameBufferObjectColorTarget(Context *, uint32_t slot);
  37. void rsrClearFrameBufferObjectDepthTarget(Context *);
  38. void rsrClearFrameBufferObjectTargets(Context *);
  39. //////////////////////////////////////////////////////////////////////////////
  40. // VP
  41. //////////////////////////////////////////////////////////////////////////////
  42. void rsrVpLoadProjectionMatrix(Context *, const rsc_Matrix *m);
  43. void rsrVpLoadModelMatrix(Context *, const rsc_Matrix *m);
  44. void rsrVpLoadTextureMatrix(Context *, const rsc_Matrix *m);
  45. void rsrPfConstantColor(Context *, ProgramFragment *, float r, float g, float b, float a);
  46. void rsrVpGetProjectionMatrix(Context *, rsc_Matrix *m);
  47. //////////////////////////////////////////////////////////////////////////////
  48. // Drawing
  49. //////////////////////////////////////////////////////////////////////////////
  50. void rsrDrawPath(Context *, Path *);
  51. void rsrDrawMesh(Context *, Mesh *);
  52. void rsrDrawMeshPrimitive(Context *, Mesh *, uint32_t primIndex);
  53. void rsrDrawMeshPrimitiveRange(Context *, Mesh *,
  54. uint32_t primIndex, uint32_t start, uint32_t len);
  55. void rsrMeshComputeBoundingBox(Context *, Mesh *,
  56. float *minX, float *minY, float *minZ,
  57. float *maxX, float *maxY, float *maxZ);
  58. //////////////////////////////////////////////////////////////////////////////
  59. //
  60. //////////////////////////////////////////////////////////////////////////////
  61. void rsrColor(Context *, float r, float g, float b, float a);
  62. #endif
  63. void rsrAllocationCopy1DRange(Context *, Allocation *dstAlloc,
  64. uint32_t dstOff,
  65. uint32_t dstMip,
  66. uint32_t count,
  67. Allocation *srcAlloc,
  68. uint32_t srcOff, uint32_t srcMip);
  69. void rsrAllocationCopy2DRange(Context *, Allocation *dstAlloc,
  70. uint32_t dstXoff, uint32_t dstYoff,
  71. uint32_t dstMip, uint32_t dstFace,
  72. uint32_t width, uint32_t height,
  73. Allocation *srcAlloc,
  74. uint32_t srcXoff, uint32_t srcYoff,
  75. uint32_t srcMip, uint32_t srcFace);
  76. #ifndef RS_COMPATIBILITY_LIB
  77. void rsrPrepareClear(Context *);
  78. uint32_t rsrGetWidth(Context *);
  79. uint32_t rsrGetHeight(Context *);
  80. void rsrDrawTextAlloc(Context *, Allocation *, int x, int y);
  81. void rsrDrawText(Context *, const char *text, int x, int y);
  82. void rsrSetMetrics(Context *, Font::Rect *metrics,
  83. int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
  84. void rsrMeasureTextAlloc(Context *, Allocation *,
  85. int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
  86. void rsrMeasureText(Context *, const char *text,
  87. int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
  88. void rsrBindFont(Context *, Font *);
  89. void rsrFontColor(Context *, float r, float g, float b, float a);
  90. #endif
  91. void rsrAllocationIoSend(Context *, Allocation *);
  92. void rsrAllocationIoReceive(Context *, Allocation *);
  93. //////////////////////////////////////////////////////////////////////////////
  94. // Time routines
  95. //////////////////////////////////////////////////////////////////////////////
  96. float rsrGetDt(Context *, const Script *sc);
  97. time_t rsrTime(Context *, time_t *timer);
  98. tm* rsrLocalTime(Context *, tm *local, time_t *timer);
  99. int64_t rsrUptimeMillis(Context *);
  100. int64_t rsrUptimeNanos(Context *);
  101. //////////////////////////////////////////////////////////////////////////////
  102. // Message routines
  103. //////////////////////////////////////////////////////////////////////////////
  104. // Keep existing routines to not break current GPU drivers.
  105. uint32_t __attribute((used)) rsrToClient(Context *, int cmdID, void *data, int len);
  106. uint32_t __attribute((used)) rsrToClientBlocking(Context *, int cmdID, void *data, int len);
  107. uint32_t rsrToClient(Context *, int cmdID, const void *data, int len);
  108. uint32_t rsrToClientBlocking(Context *, int cmdID, const void *data, int len);
  109. //////////////////////////////////////////////////////////////////////////////
  110. //
  111. //////////////////////////////////////////////////////////////////////////////
  112. void rsrSetObject(const Context *, rs_object_base *dst, const ObjectBase *src);
  113. void rsrClearObject(rs_object_base *dst);
  114. bool rsrIsObject(const Context *, rs_object_base src);
  115. bool rsrIsObject(const Context *, ObjectBase* src);
  116. void rsrAllocationIncRefs(const Context *, const Allocation *, void *ptr,
  117. size_t elementCount, size_t startOffset);
  118. void rsrAllocationDecRefs(const Context *, const Allocation *, void *ptr,
  119. size_t elementCount, size_t startOffset);
  120. void rsrAllocationSyncAll(Context *, Allocation *a, RsAllocationUsageType source);
  121. void rsrForEach(Context *, Script *target,
  122. uint32_t slot,
  123. uint32_t numInputs,
  124. Allocation **in,
  125. Allocation *out,
  126. const void *usr,
  127. uint32_t usrBytes,
  128. const RsScriptCall *call);
  129. RsElement rsrElementCreate(Context *rsc, RsDataType dt, RsDataKind dk,
  130. bool norm, uint32_t vecSize);
  131. RsType rsrTypeCreate(Context *, const RsElement element, uint32_t dimX,
  132. uint32_t dimY, uint32_t dimZ, bool mipmaps, bool faces,
  133. uint32_t yuv);
  134. RsAllocation rsrAllocationCreateTyped(Context *, const RsType type,
  135. RsAllocationMipmapControl mipmaps,
  136. uint32_t usages, uintptr_t ptr);
  137. //////////////////////////////////////////////////////////////////////////////
  138. // Heavy math functions
  139. //////////////////////////////////////////////////////////////////////////////
  140. void rsrMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v);
  141. float rsrMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col);
  142. void rsrMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v);
  143. float rsrMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col);
  144. void rsrMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v);
  145. float rsrMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col);
  146. void rsrMatrixLoadIdentity_4x4(rs_matrix4x4 *m);
  147. void rsrMatrixLoadIdentity_3x3(rs_matrix3x3 *m);
  148. void rsrMatrixLoadIdentity_2x2(rs_matrix2x2 *m);
  149. void rsrMatrixLoad_4x4_f(rs_matrix4x4 *m, const float *v);
  150. void rsrMatrixLoad_3x3_f(rs_matrix3x3 *m, const float *v);
  151. void rsrMatrixLoad_2x2_f(rs_matrix2x2 *m, const float *v);
  152. void rsrMatrixLoad_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *v);
  153. void rsrMatrixLoad_4x4_3x3(rs_matrix4x4 *m, const rs_matrix3x3 *v);
  154. void rsrMatrixLoad_4x4_2x2(rs_matrix4x4 *m, const rs_matrix2x2 *v);
  155. void rsrMatrixLoad_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *v);
  156. void rsrMatrixLoad_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *v);
  157. void rsrMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
  158. void rsrMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z);
  159. void rsrMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z);
  160. void rsrMatrixLoadMultiply_4x4_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *lhs,
  161. const rs_matrix4x4 *rhs);
  162. void rsrMatrixMultiply_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *rhs);
  163. void rsrMatrixLoadMultiply_3x3_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *lhs,
  164. const rs_matrix3x3 *rhs);
  165. void rsrMatrixMultiply_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *rhs);
  166. void rsrMatrixLoadMultiply_2x2_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *lhs,
  167. const rs_matrix2x2 *rhs);
  168. void rsrMatrixMultiply_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *rhs);
  169. void rsrMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
  170. void rsrMatrixScale(rs_matrix4x4 *m, float x, float y, float z);
  171. void rsrMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z);
  172. void rsrMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right,
  173. float bottom, float top, float near, float far);
  174. void rsrMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right,
  175. float bottom, float top, float near, float far);
  176. void rsrMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
  177. // Returns true if the matrix was successfully inversed
  178. bool rsrMatrixInverse_4x4(rs_matrix4x4 *m);
  179. // Returns true if the matrix was successfully inversed
  180. bool rsrMatrixInverseTranspose_4x4(rs_matrix4x4 *m);
  181. void rsrMatrixTranspose_4x4(rs_matrix4x4 *m);
  182. void rsrMatrixTranspose_3x3(rs_matrix3x3 *m);
  183. void rsrMatrixTranspose_2x2(rs_matrix2x2 *m);
  184. } // namespace renderscript
  185. } // namespace android