1 // Copyright 2018 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #pragma once 15 16 #include <hardware/fb.h> 17 #include <hardware/gralloc.h> 18 19 // Consolidates all framebuffer device, alloc device, 20 // and gralloc module operations into one convenient struct. 21 struct gralloc_implementation { 22 void* lib; 23 24 struct alloc_device_t* alloc_dev; 25 struct gralloc_module_t* alloc_module; 26 27 // Allocator device============================================================= 28 allocgralloc_implementation29 int alloc(int w, 30 int h, 31 int format, 32 int usage, 33 buffer_handle_t* handle, 34 int* stride) { 35 return alloc_dev->alloc(alloc_dev, w, h, format, usage, handle, stride); 36 } 37 freegralloc_implementation38 int free(buffer_handle_t handle) { 39 return alloc_dev->free(alloc_dev, handle); 40 } 41 dumpAllocgralloc_implementation42 void dumpAlloc(char* buffer, int buff_len) { 43 if (!alloc_dev->dump) return; 44 alloc_dev->dump(alloc_dev, buffer, buff_len); 45 } 46 47 // Gralloc module=============================================================== 48 registerBuffergralloc_implementation49 int registerBuffer(buffer_handle_t handle) { 50 return alloc_module->registerBuffer(alloc_module, handle); 51 } 52 unregisterBuffergralloc_implementation53 int unregisterBuffer(buffer_handle_t handle) { 54 return alloc_module->unregisterBuffer(alloc_module, handle); 55 } 56 lockgralloc_implementation57 int lock(buffer_handle_t handle, int usage, 58 int l, int t, int w, int h, 59 void** vaddr) { 60 return alloc_module->lock(alloc_module, handle, usage, l, t, w, h, 61 vaddr); 62 } 63 unlockgralloc_implementation64 int unlock(buffer_handle_t handle) { 65 return alloc_module->unlock(alloc_module, handle); 66 } 67 lock_ycbcrgralloc_implementation68 int lock_ycbcr(buffer_handle_t handle, 69 int usage, 70 int l, 71 int t, 72 int w, 73 int h, 74 struct android_ycbcr* ycbcr) { 75 return alloc_module->lock_ycbcr(alloc_module, handle, usage, l, t, w, h, 76 ycbcr); 77 } 78 lockAsyncgralloc_implementation79 int lockAsync(buffer_handle_t handle, 80 int usage, 81 int l, 82 int t, 83 int w, 84 int h, 85 void** vaddr, 86 int fenceFd) { 87 return alloc_module->lockAsync(alloc_module, handle, usage, l, t, w, h, 88 vaddr, fenceFd); 89 } 90 unlockAsyncgralloc_implementation91 int unlockAsync(buffer_handle_t handle, int* fenceFd) { 92 return alloc_module->unlockAsync(alloc_module, handle, fenceFd); 93 } 94 lockAsync_ycbcrgralloc_implementation95 int lockAsync_ycbcr(buffer_handle_t handle, 96 int usage, 97 int l, 98 int t, 99 int w, 100 int h, 101 struct android_ycbcr* ycbcr, 102 int fenceFd) { 103 return alloc_module->lockAsync_ycbcr(alloc_module, handle, usage, l, t, 104 w, h, ycbcr, fenceFd); 105 } 106 }; 107 108 extern "C" { 109 110 void load_gralloc_module( 111 const char* path, 112 struct gralloc_implementation* impl_out); 113 114 void unload_gralloc_module( 115 const struct gralloc_implementation* impl); 116 117 void set_global_gralloc_module(struct gralloc_implementation* impl); 118 119 struct gralloc_implementation* 120 get_global_gralloc_module(void); 121 122 } // extern "C" 123