// Avoid having to reallocate memory and render quad by quad void FontState::initVertexArrayBuffers() { // Now lets write index data ObjectBaseRef<const Element> indexElem = Element::createRef(mRSC, RS_TYPE_UNSIGNED_16, RS_KIND_USER, false, 1); uint32_t numIndicies = mMaxNumberOfQuads * 6; ObjectBaseRef<Type> indexType = Type::getTypeRef(mRSC, indexElem.get(), numIndicies, 0, 0, false, false, 0); Allocation *indexAlloc = Allocation::createAllocation(mRSC, indexType.get(), RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_VERTEX); uint16_t *indexPtr = (uint16_t*)mRSC->mHal.funcs.allocation.lock1D(mRSC, indexAlloc); // Four verts, two triangles , six indices per quad for (uint32_t i = 0; i < mMaxNumberOfQuads; i ++) { int32_t i6 = i * 6; int32_t i4 = i * 4; indexPtr[i6 + 0] = i4 + 0; indexPtr[i6 + 1] = i4 + 1; indexPtr[i6 + 2] = i4 + 2; indexPtr[i6 + 3] = i4 + 0; indexPtr[i6 + 4] = i4 + 2; indexPtr[i6 + 5] = i4 + 3; } indexAlloc->sendDirty(mRSC); ObjectBaseRef<const Element> posElem = Element::createRef(mRSC, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 3); ObjectBaseRef<const Element> texElem = Element::createRef(mRSC, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 2); const char *ebn1[] = { "position", "texture0" }; const Element *ebe1[] = {posElem.get(), texElem.get()}; ObjectBaseRef<const Element> vertexDataElem = Element::create(mRSC, 2, ebe1, ebn1); ObjectBaseRef<Type> vertexDataType = Type::getTypeRef(mRSC, vertexDataElem.get(), mMaxNumberOfQuads * 4, 0, 0, false, false, 0); Allocation *vertexAlloc = Allocation::createAllocation(mRSC, vertexDataType.get(), RS_ALLOCATION_USAGE_SCRIPT); mTextMeshPtr = (float*)mRSC->mHal.funcs.allocation.lock1D(mRSC, vertexAlloc); mMesh.set(new Mesh(mRSC, 1, 1)); mMesh->setVertexBuffer(vertexAlloc, 0); mMesh->setPrimitive(indexAlloc, RS_PRIMITIVE_TRIANGLE, 0); mMesh->init(); mRSC->mHal.funcs.allocation.unlock1D(mRSC, indexAlloc); mRSC->mHal.funcs.allocation.unlock1D(mRSC, vertexAlloc); }
RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype, RsAllocationMipmapControl mips, const void *data, size_t data_length, uint32_t usages) { Type *t = static_cast<Type *>(vtype); RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages); Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); if (texAlloc == NULL) { ALOGE("Memory allocation failure"); return NULL; } memcpy(texAlloc->getPtr(), data, t->getDimX() * t->getDimY() * t->getElementSizeBytes()); if (mips == RS_ALLOCATION_MIPMAP_FULL) { AllocationGenerateScriptMips(rsc, texAlloc); } texAlloc->sendDirty(rsc); return texAlloc; }
RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype, RsAllocationMipmapControl mipmaps, const void *data, size_t sizeBytes, uint32_t usages) { Type *t = static_cast<Type *>(vtype); RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mipmaps, usages, 0); Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); if (texAlloc == nullptr) { ALOGE("Memory allocation failure"); return nullptr; } texAlloc->data(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, t->getDimX(), t->getDimY(), data, sizeBytes, 0); if (mipmaps == RS_ALLOCATION_MIPMAP_FULL) { rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc); } texAlloc->sendDirty(rsc); return texAlloc; }
RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype, RsAllocationMipmapControl mips, const void *data, size_t data_length, uint32_t usages) { Type *t = static_cast<Type *>(vtype); // Cubemap allocation's faces should be Width by Width each. // Source data should have 6 * Width by Width pixels // Error checking is done in the java layer RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages); Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); if (texAlloc == NULL) { ALOGE("Memory allocation failure"); return NULL; } uint32_t faceSize = t->getDimX(); uint32_t strideBytes = faceSize * 6 * t->getElementSizeBytes(); uint32_t copySize = faceSize * t->getElementSizeBytes(); uint8_t *sourcePtr = (uint8_t*)data; for (uint32_t face = 0; face < 6; face ++) { Adapter2D faceAdapter(rsc, texAlloc); faceAdapter.setFace(face); for (uint32_t dI = 0; dI < faceSize; dI ++) { memcpy(faceAdapter.getElement(0, dI), sourcePtr + strideBytes * dI, copySize); } // Move the data pointer to the next cube face sourcePtr += copySize; } if (mips == RS_ALLOCATION_MIPMAP_FULL) { AllocationGenerateScriptMips(rsc, texAlloc); } texAlloc->sendDirty(rsc); return texAlloc; }
RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype, RsAllocationMipmapControl mipmaps, const void *data, size_t sizeBytes, uint32_t usages) { Type *t = static_cast<Type *>(vtype); // Cubemap allocation's faces should be Width by Width each. // Source data should have 6 * Width by Width pixels // Error checking is done in the java layer RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mipmaps, usages, 0); Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); if (texAlloc == nullptr) { ALOGE("Memory allocation failure"); return nullptr; } uint32_t faceSize = t->getDimX(); uint32_t strideBytes = faceSize * 6 * t->getElementSizeBytes(); uint32_t copySize = faceSize * t->getElementSizeBytes(); uint8_t *sourcePtr = (uint8_t*)data; for (uint32_t face = 0; face < 6; face ++) { for (uint32_t dI = 0; dI < faceSize; dI ++) { texAlloc->data(rsc, 0, dI, 0, (RsAllocationCubemapFace)face, t->getDimX(), 1, sourcePtr + strideBytes * dI, copySize, 0); } // Move the data pointer to the next cube face sourcePtr += copySize; } if (mipmaps == RS_ALLOCATION_MIPMAP_FULL) { rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc); } texAlloc->sendDirty(rsc); return texAlloc; }
void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType src) { Allocation *a = static_cast<Allocation *>(va); a->sendDirty(rsc); a->syncAll(rsc, src); }