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 #ifndef ANDROID_UI_BUFFER_MAPPER_H 17 #define ANDROID_UI_BUFFER_MAPPER_H 18 #include <stdint.h> 19 #include <sys/types.h> 20 #include <memory> 21 #include <ui/PixelFormat.h> 22 #include <utils/Singleton.h> 23 // Needed by code that still uses the GRALLOC_USAGE_* constants. 24 // when/if we get rid of gralloc, we should provide aliases or fix call sites. 25 #include <hardware/gralloc.h> 26 namespace android { 27 // --------------------------------------------------------------------------- 28 namespace Gralloc2 { 29 class Mapper; 30 } 31 class Rect; 32 class GraphicBufferMapper : public Singleton<GraphicBufferMapper> 33 { 34 public: 35 static void preloadHal(); get()36 static inline GraphicBufferMapper& get() { return getInstance(); } 37 // The imported outHandle must be freed with freeBuffer when no longer 38 // needed. rawHandle is owned by the caller. 39 status_t importBuffer(buffer_handle_t rawHandle, 40 uint32_t width, uint32_t height, uint32_t layerCount, 41 PixelFormat format, uint64_t usage, uint32_t stride, 42 buffer_handle_t* outHandle); 43 status_t freeBuffer(buffer_handle_t handle); 44 void getTransportSize(buffer_handle_t handle, 45 uint32_t* outTransportNumFds, uint32_t* outTransportNumInts); 46 status_t lock(buffer_handle_t handle, 47 uint32_t usage, const Rect& bounds, void** vaddr); 48 status_t lockYCbCr(buffer_handle_t handle, 49 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr); 50 status_t unlock(buffer_handle_t handle); 51 status_t lockAsync(buffer_handle_t handle, 52 uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd); 53 status_t lockAsync(buffer_handle_t handle, 54 uint64_t producerUsage, uint64_t consumerUsage, const Rect& bounds, 55 void** vaddr, int fenceFd); 56 status_t lockAsyncYCbCr(buffer_handle_t handle, 57 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr, 58 int fenceFd); 59 status_t unlockAsync(buffer_handle_t handle, int *fenceFd); getGrallocMapper()60 const Gralloc2::Mapper& getGrallocMapper() const 61 { 62 return *mMapper; 63 } 64 private: 65 friend class Singleton<GraphicBufferMapper>; 66 GraphicBufferMapper(); 67 const std::unique_ptr<const Gralloc2::Mapper> mMapper; 68 }; 69 // --------------------------------------------------------------------------- 70 }; // namespace android 71 #endif // ANDROID_UI_BUFFER_MAPPER_H 72