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 <utils/Singleton.h> 26 27 28 // Needed by code that still uses the GRALLOC_USAGE_* constants. 29 // when/if we get rid of gralloc, we should provide aliases or fix call sites. 30 #include <hardware/gralloc.h> 31 32 33 namespace android { 34 35 // --------------------------------------------------------------------------- 36 37 namespace Gralloc2 { 38 class Mapper; 39 } 40 41 class Rect; 42 43 class GraphicBufferMapper : public Singleton<GraphicBufferMapper> 44 { 45 public: 46 static void preloadHal(); get()47 static inline GraphicBufferMapper& get() { return getInstance(); } 48 49 // The imported outHandle must be freed with freeBuffer when no longer 50 // needed. rawHandle is owned by the caller. 51 status_t importBuffer(buffer_handle_t rawHandle, 52 buffer_handle_t* outHandle); 53 54 status_t freeBuffer(buffer_handle_t handle); 55 56 status_t lock(buffer_handle_t handle, 57 uint32_t usage, const Rect& bounds, void** vaddr); 58 59 status_t lockYCbCr(buffer_handle_t handle, 60 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr); 61 62 status_t unlock(buffer_handle_t handle); 63 64 status_t lockAsync(buffer_handle_t handle, 65 uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd); 66 67 status_t lockAsync(buffer_handle_t handle, 68 uint64_t producerUsage, uint64_t consumerUsage, const Rect& bounds, 69 void** vaddr, int fenceFd); 70 71 status_t lockAsyncYCbCr(buffer_handle_t handle, 72 uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr, 73 int fenceFd); 74 75 status_t unlockAsync(buffer_handle_t handle, int *fenceFd); 76 getGrallocMapper()77 const Gralloc2::Mapper& getGrallocMapper() const 78 { 79 return *mMapper; 80 } 81 82 private: 83 friend class Singleton<GraphicBufferMapper>; 84 85 GraphicBufferMapper(); 86 87 const std::unique_ptr<const Gralloc2::Mapper> mMapper; 88 }; 89 90 // --------------------------------------------------------------------------- 91 92 }; // namespace android 93 94 #endif // ANDROID_UI_BUFFER_MAPPER_H 95 96