1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_UI_BUFFER_MAPPER_H 18 #define ANDROID_UI_BUFFER_MAPPER_H 19 20 #include <stdint.h> 21 #include <sys/types.h> 22 23 #include <memory> 24 25 #include <ui/PixelFormat.h> 26 #include <utils/Singleton.h> 27 28 29 // Needed by code that still uses the GRALLOC_USAGE_* constants. 30 // when/if we get rid of gralloc, we should provide aliases or fix call sites. 31 #include <hardware/gralloc.h> 32 33 34 namespace android { 35 36 // --------------------------------------------------------------------------- 37 38 namespace Gralloc2 { 39 class Mapper; 40 } 41 42 class Rect; 43 44 class GraphicBufferMapper : public Singleton<GraphicBufferMapper> 45 { 46 public: 47 static void preloadHal(); get()48 static inline GraphicBufferMapper& get() { return getInstance(); } 49 50 // The imported outHandle must be freed with freeBuffer when no longer 51 // needed. rawHandle is owned by the caller. 52 status_t importBuffer(buffer_handle_t rawHandle, 53 uint32_t width, uint32_t height, uint32_t layerCount, 54 PixelFormat format, uint64_t usage, uint32_t stride, 55 buffer_handle_t* outHandle); 56 57 status_t freeBuffer(buffer_handle_t handle); 58 59 void getTransportSize(buffer_handle_t handle, 60 uint32_t* outTransportNumFds, uint32_t* outTransportNumInts); 61 62 status_t lock(buffer_handle_t handle, 63 uint32_t usage, const Rect& bounds, void** vaddr); 64 65 status_t lockYCbCr(buffer_handle_t handle, 66 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr); 67 68 status_t unlock(buffer_handle_t handle); 69 70 status_t lockAsync(buffer_handle_t handle, 71 uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd); 72 73 status_t lockAsync(buffer_handle_t handle, 74 uint64_t producerUsage, uint64_t consumerUsage, const Rect& bounds, 75 void** vaddr, int fenceFd); 76 77 status_t lockAsyncYCbCr(buffer_handle_t handle, 78 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr, 79 int fenceFd); 80 81 status_t unlockAsync(buffer_handle_t handle, int *fenceFd); 82 getGrallocMapper()83 const Gralloc2::Mapper& getGrallocMapper() const 84 { 85 return *mMapper; 86 } 87 88 private: 89 friend class Singleton<GraphicBufferMapper>; 90 91 GraphicBufferMapper(); 92 93 const std::unique_ptr<const Gralloc2::Mapper> mMapper; 94 }; 95 96 // --------------------------------------------------------------------------- 97 98 }; // namespace android 99 100 #endif // ANDROID_UI_BUFFER_MAPPER_H 101 102