| 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 |  | 
|  | 23 | #include <cutils/native_handle.h> | 
|  | 24 |  | 
|  | 25 | #include <utils/Errors.h> | 
|  | 26 | #include <utils/KeyedVector.h> | 
|  | 27 | #include <utils/threads.h> | 
|  | 28 | #include <utils/Singleton.h> | 
|  | 29 |  | 
|  | 30 | #include <ui/PixelFormat.h> | 
|  | 31 |  | 
|  | 32 | #include <hardware/gralloc.h> | 
|  | 33 |  | 
|  | 34 |  | 
|  | 35 | namespace android { | 
|  | 36 | // --------------------------------------------------------------------------- | 
|  | 37 |  | 
|  | 38 | class String8; | 
|  | 39 |  | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 40 | class GraphicBufferAllocator : public Singleton<GraphicBufferAllocator> | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 41 | { | 
|  | 42 | public: | 
|  | 43 | enum { | 
|  | 44 | USAGE_SW_READ_NEVER     = GRALLOC_USAGE_SW_READ_NEVER, | 
|  | 45 | USAGE_SW_READ_RARELY    = GRALLOC_USAGE_SW_READ_RARELY, | 
|  | 46 | USAGE_SW_READ_OFTEN     = GRALLOC_USAGE_SW_READ_OFTEN, | 
|  | 47 | USAGE_SW_READ_MASK      = GRALLOC_USAGE_SW_READ_MASK, | 
| Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 48 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 49 | USAGE_SW_WRITE_NEVER    = GRALLOC_USAGE_SW_WRITE_NEVER, | 
|  | 50 | USAGE_SW_WRITE_RARELY   = GRALLOC_USAGE_SW_WRITE_RARELY, | 
|  | 51 | USAGE_SW_WRITE_OFTEN    = GRALLOC_USAGE_SW_WRITE_OFTEN, | 
|  | 52 | USAGE_SW_WRITE_MASK     = GRALLOC_USAGE_SW_WRITE_MASK, | 
| Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 53 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 54 | USAGE_SOFTWARE_MASK     = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK, | 
| Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 55 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 56 | USAGE_HW_TEXTURE        = GRALLOC_USAGE_HW_TEXTURE, | 
|  | 57 | USAGE_HW_RENDER         = GRALLOC_USAGE_HW_RENDER, | 
|  | 58 | USAGE_HW_2D             = GRALLOC_USAGE_HW_2D, | 
|  | 59 | USAGE_HW_MASK           = GRALLOC_USAGE_HW_MASK | 
|  | 60 | }; | 
|  | 61 |  | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 62 | static inline GraphicBufferAllocator& get() { return getInstance(); } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 63 |  | 
| Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 64 | status_t alloc(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage, | 
|  | 65 | buffer_handle_t* handle, uint32_t* stride); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 66 |  | 
|  | 67 | status_t free(buffer_handle_t handle); | 
|  | 68 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 69 | void dump(String8& res) const; | 
| Mathias Agopian | 678bdd6 | 2010-12-03 17:33:09 -0800 | [diff] [blame] | 70 | static void dumpToSystemLog(); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 71 |  | 
|  | 72 | private: | 
|  | 73 | struct alloc_rec_t { | 
| Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 74 | uint32_t width; | 
|  | 75 | uint32_t height; | 
|  | 76 | uint32_t stride; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 77 | PixelFormat format; | 
|  | 78 | uint32_t usage; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 79 | size_t size; | 
|  | 80 | }; | 
| Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 81 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 82 | static Mutex sLock; | 
|  | 83 | static KeyedVector<buffer_handle_t, alloc_rec_t> sAllocList; | 
| Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 84 |  | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 85 | friend class Singleton<GraphicBufferAllocator>; | 
|  | 86 | GraphicBufferAllocator(); | 
|  | 87 | ~GraphicBufferAllocator(); | 
| Dan Stoza | 303b9a5 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 88 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 89 | alloc_device_t  *mAllocDev; | 
|  | 90 | }; | 
|  | 91 |  | 
|  | 92 | // --------------------------------------------------------------------------- | 
|  | 93 | }; // namespace android | 
|  | 94 |  | 
|  | 95 | #endif // ANDROID_BUFFER_ALLOCATOR_H |