Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 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> |
Mathias Agopian | 8b765b7 | 2009-04-10 20:34:46 -0700 | [diff] [blame] | 22 | |
Mathias Agopian | fe2f54f | 2017-02-15 19:48:58 -0800 | [diff] [blame] | 23 | #include <memory> |
| 24 | |
Chia-I Wu | dbbe33b | 2017-09-27 15:22:21 -0700 | [diff] [blame] | 25 | #include <ui/PixelFormat.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 26 | #include <utils/Singleton.h> |
| 27 | |
Mathias Agopian | fe2f54f | 2017-02-15 19:48:58 -0800 | [diff] [blame] | 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 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 34 | namespace android { |
| 35 | |
| 36 | // --------------------------------------------------------------------------- |
| 37 | |
Marissa Wall | d380e2c | 2018-12-29 14:17:29 -0800 | [diff] [blame] | 38 | class GrallocMapper; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 39 | class Rect; |
| 40 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 41 | class GraphicBufferMapper : public Singleton<GraphicBufferMapper> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 42 | { |
| 43 | public: |
Jesse Hall | 5dac781 | 2017-07-06 14:02:29 -0700 | [diff] [blame] | 44 | static void preloadHal(); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 45 | static inline GraphicBufferMapper& get() { return getInstance(); } |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 46 | |
Chia-I Wu | 5bac7f3 | 2017-04-06 12:34:32 -0700 | [diff] [blame] | 47 | // The imported outHandle must be freed with freeBuffer when no longer |
| 48 | // needed. rawHandle is owned by the caller. |
| 49 | status_t importBuffer(buffer_handle_t rawHandle, |
Chia-I Wu | dbbe33b | 2017-09-27 15:22:21 -0700 | [diff] [blame] | 50 | uint32_t width, uint32_t height, uint32_t layerCount, |
| 51 | PixelFormat format, uint64_t usage, uint32_t stride, |
Chia-I Wu | 5bac7f3 | 2017-04-06 12:34:32 -0700 | [diff] [blame] | 52 | buffer_handle_t* outHandle); |
Chia-I Wu | 7bd8adb | 2017-02-10 14:53:12 -0800 | [diff] [blame] | 53 | |
Chia-I Wu | 5bac7f3 | 2017-04-06 12:34:32 -0700 | [diff] [blame] | 54 | status_t freeBuffer(buffer_handle_t handle); |
Craig Donner | 58a1ef2 | 2017-02-02 12:40:05 -0800 | [diff] [blame] | 55 | |
Chia-I Wu | dbbe33b | 2017-09-27 15:22:21 -0700 | [diff] [blame] | 56 | void getTransportSize(buffer_handle_t handle, |
| 57 | uint32_t* outTransportNumFds, uint32_t* outTransportNumInts); |
| 58 | |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 59 | status_t lock(buffer_handle_t handle, |
Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 60 | uint32_t usage, const Rect& bounds, void** vaddr); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 61 | |
Eino-Ville Talvala | c43946b | 2013-05-04 18:07:43 -0700 | [diff] [blame] | 62 | status_t lockYCbCr(buffer_handle_t handle, |
Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 63 | uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr); |
Eino-Ville Talvala | c43946b | 2013-05-04 18:07:43 -0700 | [diff] [blame] | 64 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 65 | status_t unlock(buffer_handle_t handle); |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 66 | |
| 67 | status_t lockAsync(buffer_handle_t handle, |
Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 68 | uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd); |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 69 | |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 70 | status_t lockAsync(buffer_handle_t handle, |
| 71 | uint64_t producerUsage, uint64_t consumerUsage, const Rect& bounds, |
| 72 | void** vaddr, int fenceFd); |
| 73 | |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 74 | status_t lockAsyncYCbCr(buffer_handle_t handle, |
Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 75 | uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr, |
| 76 | int fenceFd); |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 77 | |
| 78 | status_t unlockAsync(buffer_handle_t handle, int *fenceFd); |
Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 79 | |
Marissa Wall | d380e2c | 2018-12-29 14:17:29 -0800 | [diff] [blame] | 80 | const GrallocMapper& getGrallocMapper() const { |
| 81 | return reinterpret_cast<const GrallocMapper&>(*mMapper); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 82 | } |
| 83 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 84 | private: |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 85 | friend class Singleton<GraphicBufferMapper>; |
Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 86 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 87 | GraphicBufferMapper(); |
Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 88 | |
Marissa Wall | 925bf7f | 2018-12-29 14:27:11 -0800 | [diff] [blame^] | 89 | std::unique_ptr<const GrallocMapper> mMapper; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | // --------------------------------------------------------------------------- |
| 93 | |
| 94 | }; // namespace android |
| 95 | |
| 96 | #endif // ANDROID_UI_BUFFER_MAPPER_H |
| 97 | |