Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- } else if ((usage & GRALLOC_USAGE_HW_RENDER) == 0) {
- flags |= private_handle_t::PRIV_FLAGS_USES_OGL;
- private_module_t* m = reinterpret_cast<private_module_t*>(
- dev->common.module);
- err = init_pmem_area(m);
- init_texture_access();
- if (err == 0) {
- LOGE("About to call ogl_alloc at 0x%p gpu1_base 0x%p", ogl_alloc, gpu1_base);
- int tsize;
- base = gpu1_base;
- offset = (int)ogl_alloc(w,h,format,text,stride,&tsize,gpu1_base);
- fd = open("/dev/pmem", O_RDWR, 0);
- err = fd < 0 ? fd : 0;
- int off = offset;
- if(off%4096)
- {
- off -= off % 4096;
- tsize += off % 4096;
- }
- if(tsize % 4096)
- tsize += 4096 - (tsize%4096);
- size = tsize;
- struct pmem_region sub = { off, tsize }; //offset, size };
- // and connect to it
- // if (err == 0)
- err = ioctl(fd, PMEM_CONNECT, gpu1_fd);
- // and make it available to the client process
- //if (err == 0)
- err = ioctl(fd, PMEM_MAP, &sub);
- LOGE("Memsetting");
- memset((char*)base + offset, 0, size);
- LOGE("Done");
- //LOGD_IF(!err, "allocating pmem size=%d, offset=%d", size, offset);
- }
- } else {
- static int gralloc_map(gralloc_module_t const* module,
- buffer_handle_t handle,
- void** vaddr)
- {
- private_handle_t* hnd = (private_handle_t*)handle;
- if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
- size_t size = hnd->size;
- #if PMEM_HACK
- size += hnd->offset;
- #endif
- if(size%4096)
- size += 4096 - (size%4096);
- void* mappedAddress = mmap(0, size,
- PROT_READ|PROT_WRITE, MAP_SHARED, hnd->fd, 0);
- if (mappedAddress == MAP_FAILED) {
- char fdPath[512];
- char filename[512];
- for(int i=0; i < 512; i++)
- filename[i] = 0;
- sprintf(fdPath,"/proc/self/fd/%d",hnd->fd);
- readlink(fdPath,filename,512);
- LOGE("Could not mmap handle %p, fd=%d (%s) size (0x%8.8X) source: %s",
- handle, hnd->fd, strerror(errno), size, filename);
- hnd->base = 0;
- return -errno;
- }
- hnd->base = intptr_t(mappedAddress) + hnd->offset;
- //TODO: this is just a hack to make sure our surface is not clobbering anything important
- hnd->base = (int)malloc(size);
- //LOGD("gralloc_map() succeeded fd=%d, off=%d, size=%d, vaddr=%p",
- // hnd->fd, hnd->offset, hnd->size, mappedAddress);
- }
- *vaddr = (void*)hnd->base;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement