Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 1 | /* |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2 | ** |
| 3 | ** Copyright 2009, The Android Open Source Project |
| 4 | ** |
Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 8 | ** |
Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 10 | ** |
Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef ANDROID_BUFFER_ALLOCATOR_H |
| 19 | #define ANDROID_BUFFER_ALLOCATOR_H |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | |
Mathias Agopian | fe2f54f | 2017-02-15 19:48:58 -0800 | [diff] [blame] | 23 | #include <memory> |
| 24 | #include <string> |
| 25 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 26 | #include <cutils/native_handle.h> |
| 27 | |
Chia-I Wu | cb8405e | 2017-04-17 15:20:19 -0700 | [diff] [blame] | 28 | #include <system/window.h> |
| 29 | |
| 30 | #include <ui/PixelFormat.h> |
| 31 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 32 | #include <utils/Errors.h> |
| 33 | #include <utils/KeyedVector.h> |
Mathias Agopian | fe2f54f | 2017-02-15 19:48:58 -0800 | [diff] [blame] | 34 | #include <utils/Mutex.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 35 | #include <utils/Singleton.h> |
| 36 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 37 | namespace android { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 38 | |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 39 | namespace Gralloc2 { |
| 40 | class Allocator; |
| 41 | } |
| 42 | |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 43 | class GraphicBufferMapper; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 44 | class String8; |
| 45 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 46 | class GraphicBufferAllocator : public Singleton<GraphicBufferAllocator> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 47 | { |
| 48 | public: |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 49 | static inline GraphicBufferAllocator& get() { return getInstance(); } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 50 | |
Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 51 | status_t allocate(uint32_t w, uint32_t h, PixelFormat format, |
Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 52 | uint32_t layerCount, uint64_t usage, |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 53 | buffer_handle_t* handle, uint32_t* stride, uint64_t graphicBufferId, |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 54 | std::string requestorName); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 55 | |
| 56 | status_t free(buffer_handle_t handle); |
| 57 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 58 | void dump(String8& res) const; |
Mathias Agopian | 678bdd6 | 2010-12-03 17:33:09 -0800 | [diff] [blame] | 59 | static void dumpToSystemLog(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 60 | |
| 61 | private: |
| 62 | struct alloc_rec_t { |
Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 63 | uint32_t width; |
| 64 | uint32_t height; |
| 65 | uint32_t stride; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 66 | PixelFormat format; |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 67 | uint32_t layerCount; |
Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 68 | uint64_t usage; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 69 | size_t size; |
Dan Stoza | 024e931 | 2016-08-24 12:17:29 -0700 | [diff] [blame] | 70 | std::string requestorName; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 71 | }; |
Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 72 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 73 | static Mutex sLock; |
| 74 | static KeyedVector<buffer_handle_t, alloc_rec_t> sAllocList; |
Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 75 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 76 | friend class Singleton<GraphicBufferAllocator>; |
| 77 | GraphicBufferAllocator(); |
| 78 | ~GraphicBufferAllocator(); |
Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 79 | |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 80 | GraphicBufferMapper& mMapper; |
Chia-I Wu | 5bac7f3 | 2017-04-06 12:34:32 -0700 | [diff] [blame] | 81 | const std::unique_ptr<const Gralloc2::Allocator> mAllocator; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | // --------------------------------------------------------------------------- |
| 85 | }; // namespace android |
| 86 | |
| 87 | #endif // ANDROID_BUFFER_ALLOCATOR_H |