void BufferManager::CreateSharedHandle(buffer_handle_t inbuffer, const BufferDescriptor &descriptor, buffer_handle_t *outbuffer) { // TODO(user): This path is not verified private_handle_t const *input = reinterpret_cast<private_handle_t const *>(inbuffer); // Get Buffer attributes or dimension unsigned int alignedw = 0, alignedh = 0; allocator_->GetAlignedWidthAndHeight(descriptor, &alignedw, &alignedh); // create new handle from input reference handle and given descriptor int flags = GetHandleFlags(descriptor.GetFormat(), descriptor.GetProducerUsage(), descriptor.GetConsumerUsage()); int buffer_type = GetBufferType(descriptor.GetFormat()); // Duplicate the fds // TODO(user): Not sure what to do for fb_id. Use duped fd and new dimensions? private_handle_t *out_hnd = new private_handle_t(dup(input->fd), dup(input->fd_metadata), flags, INT(alignedw), INT(alignedh), descriptor.GetWidth(), descriptor.GetHeight(), descriptor.GetFormat(), buffer_type, input->size, descriptor.GetProducerUsage(), descriptor.GetConsumerUsage()); out_hnd->id = ++next_id_; // TODO(user): Base address of shared handle and ion handles RegisterHandleLocked(out_hnd, -1, -1); *outbuffer = out_hnd; }
void *Do_Buffer_BufferAllocate(void *Object_p, int BufferSize) { void *Buffer_p = NULL; int BufferType = GetBufferType(BufferSize); if (BufferType < NUMBER_OF_BUFFER_TYPES) { if (Do_RFifo_IsEmpty(Object_p, FreeQueue_p[BufferType])) { return NULL; } Buffer_p = Do_RFifo_Dequeue(Object_p, FreeQueue_p[BufferType]); } return Buffer_p; }
ErrorCode_e Do_Buffer_BufferRelease(void *Object_p, void *Buffer_p, int BufferSize) { ErrorCode_e ReturnValue = E_INVALID_INPUT_PARAMETERS; int BufferType = 0; VERIFY(NULL != Buffer_p, E_INVALID_INPUT_PARAMETERS); VERIFY(BufferSize <= MAX_BUFFER_SIZE, E_INVALID_TYPE_OF_BUFFER); BufferType = GetBufferType(BufferSize); //new VERIFY(BufferType < NUMBER_OF_BUFFER_TYPES, E_INVALID_TYPE_OF_BUFFER); ReturnValue = Do_RFifo_Enqueue(Object_p, FreeQueue_p[BufferType], Buffer_p); ErrorExit: return ReturnValue; }
void CRenderer::Draw( IwGxPrimType type, const CIwSVec2 * vertex, const CIwSVec2 * uv, const uint16* indexStream, const CIwColour * colour, int32 vertexCount, CIwMaterial * mat ) { if ( mat == NULL ) { mat = mDefaultMaterial; } if (( GetVBSize() + vertexCount >= RENDER_MAX_BUFF_SIZE || (mat != mCurrMtl) || (GetBufferType() != type) || (uv == NULL && GetUVBSize() != 0) || (indexStream == NULL && GetIBSize() != 0) || (colour == NULL && GetCBSize() != 0) )) { DrawBatch(); } if ( (uint32)vertexCount >= RENDER_MAX_BUFF_SIZE ) { CIwSVec2 * _v = IW_GX_ALLOC(CIwSVec2, vertexCount); CIwSVec2 * _uv = IW_GX_ALLOC(CIwSVec2, vertexCount); CIwColour * _c = IW_GX_ALLOC(CIwColour, vertexCount); uint16 * _is = NULL; if (indexStream != NULL ) { _is = IW_GX_ALLOC(uint16, vertexCount); memcpy(_is, indexStream, vertexCount*sizeof(uint16)); } memcpy(&_v[0], &vertex[0], vertexCount*sizeof(CIwSVec2)); memcpy(&_uv[0], &uv[0], vertexCount*sizeof(CIwSVec2)); memcpy(&_c[0], &colour[0], vertexCount*sizeof(CIwColour)); CameraTransform( &_v[0], vertexCount); DrawDirect(type, _v, _uv, _is, _c, vertexCount, mat); } else { mCurrMtl = mat; SetBufferType(type); AddBuffer(type, vertex, uv, indexStream, colour, vertexCount); CameraTransform( &mVB[GetVBSize() - vertexCount], vertexCount); } }
BufferObject::BufferObject(Type type) : _type(GetBufferType(type)), _bo(0) { GL_CHECKED(glGenBuffers(1, &_bo)); }
int BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle, unsigned int bufferSize) { if (!handle) return -EINVAL; int format = descriptor.GetFormat(); gralloc1_producer_usage_t prod_usage = descriptor.GetProducerUsage(); gralloc1_consumer_usage_t cons_usage = descriptor.GetConsumerUsage(); uint32_t layer_count = descriptor.GetLayerCount(); // Get implementation defined format int gralloc_format = allocator_->GetImplDefinedFormat(prod_usage, cons_usage, format); unsigned int size; unsigned int alignedw, alignedh; int buffer_type = GetBufferType(gralloc_format); allocator_->GetBufferSizeAndDimensions(descriptor, &size, &alignedw, &alignedh); size = (bufferSize >= size) ? bufferSize : size; int err = 0; int flags = 0; auto page_size = UINT(getpagesize()); AllocData data; data.align = GetDataAlignment(format, prod_usage, cons_usage); size = ALIGN(size, data.align) * layer_count; data.size = size; data.handle = (uintptr_t) handle; data.uncached = allocator_->UseUncached(prod_usage, cons_usage); // Allocate buffer memory err = allocator_->AllocateMem(&data, prod_usage, cons_usage); if (err) { ALOGE("gralloc failed to allocate err=%s", strerror(-err)); return err; } // Allocate memory for MetaData AllocData e_data; e_data.size = ALIGN(UINT(sizeof(MetaData_t)), page_size); e_data.handle = data.handle; e_data.align = page_size; err = allocator_->AllocateMem(&e_data, GRALLOC1_PRODUCER_USAGE_NONE, GRALLOC1_CONSUMER_USAGE_NONE); if (err) { ALOGE("gralloc failed to allocate metadata error=%s", strerror(-err)); return err; } flags = GetHandleFlags(format, prod_usage, cons_usage); flags |= data.alloc_type; // Create handle private_handle_t *hnd = new private_handle_t(data.fd, e_data.fd, flags, INT(alignedw), INT(alignedh), descriptor.GetWidth(), descriptor.GetHeight(), format, buffer_type, size, prod_usage, cons_usage); hnd->id = ++next_id_; hnd->base = 0; hnd->base_metadata = 0; hnd->layer_count = layer_count; ColorSpace_t colorSpace = ITU_R_601; setMetaData(hnd, UPDATE_COLOR_SPACE, reinterpret_cast<void *>(&colorSpace)); *handle = hnd; RegisterHandleLocked(hnd, data.ion_handle, e_data.ion_handle); ALOGD_IF(DEBUG, "Allocated buffer handle: %p id: %" PRIu64, hnd, hnd->id); if (DEBUG) { private_handle_t::Dump(hnd); } return err; }