Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2007 The Android Open Source Project |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #ifndef ANDROID_GRAPHIC_BUFFER_H |
michael@0 | 18 | #define ANDROID_GRAPHIC_BUFFER_H |
michael@0 | 19 | |
michael@0 | 20 | #include <stdint.h> |
michael@0 | 21 | #include <sys/types.h> |
michael@0 | 22 | |
michael@0 | 23 | #include <ui/android_native_buffer.h> |
michael@0 | 24 | #include <ui/PixelFormat.h> |
michael@0 | 25 | #include <ui/Rect.h> |
michael@0 | 26 | #include <utils/Flattenable.h> |
michael@0 | 27 | #include <pixelflinger/pixelflinger.h> |
michael@0 | 28 | |
michael@0 | 29 | struct ANativeWindowBuffer; |
michael@0 | 30 | |
michael@0 | 31 | namespace android { |
michael@0 | 32 | |
michael@0 | 33 | class GraphicBufferMapper; |
michael@0 | 34 | |
michael@0 | 35 | // =========================================================================== |
michael@0 | 36 | // GraphicBuffer |
michael@0 | 37 | // =========================================================================== |
michael@0 | 38 | |
michael@0 | 39 | class GraphicBuffer |
michael@0 | 40 | : public EGLNativeBase< |
michael@0 | 41 | ANativeWindowBuffer, |
michael@0 | 42 | GraphicBuffer, |
michael@0 | 43 | LightRefBase<GraphicBuffer> >, public Flattenable |
michael@0 | 44 | { |
michael@0 | 45 | public: |
michael@0 | 46 | |
michael@0 | 47 | enum { |
michael@0 | 48 | USAGE_SW_READ_NEVER = GRALLOC_USAGE_SW_READ_NEVER, |
michael@0 | 49 | USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY, |
michael@0 | 50 | USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN, |
michael@0 | 51 | USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK, |
michael@0 | 52 | |
michael@0 | 53 | USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER, |
michael@0 | 54 | USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY, |
michael@0 | 55 | USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN, |
michael@0 | 56 | USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK, |
michael@0 | 57 | |
michael@0 | 58 | USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK, |
michael@0 | 59 | |
michael@0 | 60 | USAGE_PROTECTED = GRALLOC_USAGE_PROTECTED, |
michael@0 | 61 | |
michael@0 | 62 | USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE, |
michael@0 | 63 | USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER, |
michael@0 | 64 | USAGE_HW_2D = GRALLOC_USAGE_HW_2D, |
michael@0 | 65 | USAGE_HW_COMPOSER = GRALLOC_USAGE_HW_COMPOSER, |
michael@0 | 66 | USAGE_HW_VIDEO_ENCODER = GRALLOC_USAGE_HW_VIDEO_ENCODER, |
michael@0 | 67 | USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | GraphicBuffer(); |
michael@0 | 71 | |
michael@0 | 72 | // creates w * h buffer |
michael@0 | 73 | GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage); |
michael@0 | 74 | |
michael@0 | 75 | // create a buffer from an existing handle |
michael@0 | 76 | GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage, |
michael@0 | 77 | uint32_t stride, native_handle_t* handle, bool keepOwnership); |
michael@0 | 78 | |
michael@0 | 79 | // create a buffer from an existing ANativeWindowBuffer |
michael@0 | 80 | GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership); |
michael@0 | 81 | |
michael@0 | 82 | // return status |
michael@0 | 83 | status_t initCheck() const; |
michael@0 | 84 | |
michael@0 | 85 | uint32_t getWidth() const { return width; } |
michael@0 | 86 | uint32_t getHeight() const { return height; } |
michael@0 | 87 | uint32_t getStride() const { return stride; } |
michael@0 | 88 | uint32_t getUsage() const { return usage; } |
michael@0 | 89 | PixelFormat getPixelFormat() const { return format; } |
michael@0 | 90 | Rect getBounds() const { return Rect(width, height); } |
michael@0 | 91 | |
michael@0 | 92 | status_t reallocate(uint32_t w, uint32_t h, PixelFormat f, uint32_t usage); |
michael@0 | 93 | |
michael@0 | 94 | status_t lock(uint32_t usage, void** vaddr); |
michael@0 | 95 | status_t lock(uint32_t usage, const Rect& rect, void** vaddr); |
michael@0 | 96 | status_t lock(GGLSurface* surface, uint32_t usage); |
michael@0 | 97 | status_t unlock(); |
michael@0 | 98 | |
michael@0 | 99 | ANativeWindowBuffer* getNativeBuffer() const; |
michael@0 | 100 | |
michael@0 | 101 | void setIndex(int index); |
michael@0 | 102 | int getIndex() const; |
michael@0 | 103 | |
michael@0 | 104 | // for debugging |
michael@0 | 105 | static void dumpAllocationsToSystemLog(); |
michael@0 | 106 | |
michael@0 | 107 | private: |
michael@0 | 108 | virtual ~GraphicBuffer(); |
michael@0 | 109 | |
michael@0 | 110 | enum { |
michael@0 | 111 | ownNone = 0, |
michael@0 | 112 | ownHandle = 1, |
michael@0 | 113 | ownData = 2, |
michael@0 | 114 | }; |
michael@0 | 115 | |
michael@0 | 116 | inline const GraphicBufferMapper& getBufferMapper() const { |
michael@0 | 117 | return mBufferMapper; |
michael@0 | 118 | } |
michael@0 | 119 | inline GraphicBufferMapper& getBufferMapper() { |
michael@0 | 120 | return mBufferMapper; |
michael@0 | 121 | } |
michael@0 | 122 | uint8_t mOwner; |
michael@0 | 123 | |
michael@0 | 124 | private: |
michael@0 | 125 | friend class Surface; |
michael@0 | 126 | friend class BpSurface; |
michael@0 | 127 | friend class BnSurface; |
michael@0 | 128 | friend class SurfaceTextureClient; |
michael@0 | 129 | friend class LightRefBase<GraphicBuffer>; |
michael@0 | 130 | GraphicBuffer(const GraphicBuffer& rhs); |
michael@0 | 131 | GraphicBuffer& operator = (const GraphicBuffer& rhs); |
michael@0 | 132 | const GraphicBuffer& operator = (const GraphicBuffer& rhs) const; |
michael@0 | 133 | |
michael@0 | 134 | status_t initSize(uint32_t w, uint32_t h, PixelFormat format, |
michael@0 | 135 | uint32_t usage); |
michael@0 | 136 | |
michael@0 | 137 | void free_handle(); |
michael@0 | 138 | |
michael@0 | 139 | // Flattenable interface |
michael@0 | 140 | size_t getFlattenedSize() const; |
michael@0 | 141 | size_t getFdCount() const; |
michael@0 | 142 | status_t flatten(void* buffer, size_t size, |
michael@0 | 143 | int fds[], size_t count) const; |
michael@0 | 144 | status_t unflatten(void const* buffer, size_t size, |
michael@0 | 145 | int fds[], size_t count); |
michael@0 | 146 | |
michael@0 | 147 | |
michael@0 | 148 | GraphicBufferMapper& mBufferMapper; |
michael@0 | 149 | ssize_t mInitCheck; |
michael@0 | 150 | int mIndex; |
michael@0 | 151 | |
michael@0 | 152 | // If we're wrapping another buffer then this reference will make sure it |
michael@0 | 153 | // doesn't get freed. |
michael@0 | 154 | sp<ANativeWindowBuffer> mWrappedBuffer; |
michael@0 | 155 | }; |
michael@0 | 156 | |
michael@0 | 157 | }; // namespace android |
michael@0 | 158 | |
michael@0 | 159 | #endif // ANDROID_GRAPHIC_BUFFER_H |