Advertisement
Guest User

Untitled

a guest
Dec 7th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. } else if ((usage & GRALLOC_USAGE_HW_RENDER) == 0) {
  2. flags |= private_handle_t::PRIV_FLAGS_USES_OGL;
  3. private_module_t* m = reinterpret_cast<private_module_t*>(
  4. dev->common.module);
  5. err = init_pmem_area(m);
  6. init_texture_access();
  7. if (err == 0) {
  8. LOGE("About to call ogl_alloc at 0x%p gpu1_base 0x%p", ogl_alloc, gpu1_base);
  9. int tsize;
  10. base = gpu1_base;
  11. offset = (int)ogl_alloc(w,h,format,text,stride,&tsize,gpu1_base);
  12. fd = open("/dev/pmem", O_RDWR, 0);
  13. err = fd < 0 ? fd : 0;
  14.  
  15. int off = offset;
  16. if(off%4096)
  17. {
  18. off -= off % 4096;
  19. tsize += off % 4096;
  20. }
  21.  
  22. if(tsize % 4096)
  23. tsize += 4096 - (tsize%4096);
  24. size = tsize;
  25.  
  26. struct pmem_region sub = { off, tsize }; //offset, size };
  27.  
  28. // and connect to it
  29. // if (err == 0)
  30. err = ioctl(fd, PMEM_CONNECT, gpu1_fd);
  31.  
  32. // and make it available to the client process
  33. //if (err == 0)
  34. err = ioctl(fd, PMEM_MAP, &sub);
  35.  
  36. LOGE("Memsetting");
  37. memset((char*)base + offset, 0, size);
  38. LOGE("Done");
  39. //LOGD_IF(!err, "allocating pmem size=%d, offset=%d", size, offset);
  40. }
  41. } else {
  42.  
  43.  
  44.  
  45.  
  46.  
  47. static int gralloc_map(gralloc_module_t const* module,
  48. buffer_handle_t handle,
  49. void** vaddr)
  50. {
  51. private_handle_t* hnd = (private_handle_t*)handle;
  52. if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
  53. size_t size = hnd->size;
  54. #if PMEM_HACK
  55. size += hnd->offset;
  56. #endif
  57. if(size%4096)
  58. size += 4096 - (size%4096);
  59.  
  60. void* mappedAddress = mmap(0, size,
  61. PROT_READ|PROT_WRITE, MAP_SHARED, hnd->fd, 0);
  62. if (mappedAddress == MAP_FAILED) {
  63. char fdPath[512];
  64. char filename[512];
  65. for(int i=0; i < 512; i++)
  66. filename[i] = 0;
  67. sprintf(fdPath,"/proc/self/fd/%d",hnd->fd);
  68. readlink(fdPath,filename,512);
  69.  
  70.  
  71. LOGE("Could not mmap handle %p, fd=%d (%s) size (0x%8.8X) source: %s",
  72. handle, hnd->fd, strerror(errno), size, filename);
  73. hnd->base = 0;
  74. return -errno;
  75. }
  76. hnd->base = intptr_t(mappedAddress) + hnd->offset;
  77. //TODO: this is just a hack to make sure our surface is not clobbering anything important
  78. hnd->base = (int)malloc(size);
  79. //LOGD("gralloc_map() succeeded fd=%d, off=%d, size=%d, vaddr=%p",
  80. // hnd->fd, hnd->offset, hnd->size, mappedAddress);
  81. }
  82. *vaddr = (void*)hnd->base;
  83. return 0;
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement