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 android_native_buffer_t; |
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 | android_native_buffer_t, |
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_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE, |
michael@0 | 61 | USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER, |
michael@0 | 62 | USAGE_HW_2D = GRALLOC_USAGE_HW_2D, |
michael@0 | 63 | USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK |
michael@0 | 64 | }; |
michael@0 | 65 | |
michael@0 | 66 | GraphicBuffer(); |
michael@0 | 67 | |
michael@0 | 68 | // creates w * h buffer |
michael@0 | 69 | GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage); |
michael@0 | 70 | |
michael@0 | 71 | // create a buffer from an existing handle |
michael@0 | 72 | GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage, |
michael@0 | 73 | uint32_t stride, native_handle_t* handle, bool keepOwnership); |
michael@0 | 74 | |
michael@0 | 75 | // return status |
michael@0 | 76 | status_t initCheck() const; |
michael@0 | 77 | |
michael@0 | 78 | uint32_t getWidth() const { return width; } |
michael@0 | 79 | uint32_t getHeight() const { return height; } |
michael@0 | 80 | uint32_t getStride() const { return stride; } |
michael@0 | 81 | uint32_t getUsage() const { return usage; } |
michael@0 | 82 | PixelFormat getPixelFormat() const { return format; } |
michael@0 | 83 | Rect getBounds() const { return Rect(width, height); } |
michael@0 | 84 | |
michael@0 | 85 | status_t reallocate(uint32_t w, uint32_t h, PixelFormat f, uint32_t usage); |
michael@0 | 86 | |
michael@0 | 87 | status_t lock(uint32_t usage, void** vaddr); |
michael@0 | 88 | status_t lock(uint32_t usage, const Rect& rect, void** vaddr); |
michael@0 | 89 | status_t lock(GGLSurface* surface, uint32_t usage); |
michael@0 | 90 | status_t unlock(); |
michael@0 | 91 | |
michael@0 | 92 | android_native_buffer_t* getNativeBuffer() const; |
michael@0 | 93 | |
michael@0 | 94 | void setIndex(int index); |
michael@0 | 95 | int getIndex() const; |
michael@0 | 96 | void setVerticalStride(uint32_t vstride); |
michael@0 | 97 | uint32_t getVerticalStride() const; |
michael@0 | 98 | |
michael@0 | 99 | protected: |
michael@0 | 100 | virtual ~GraphicBuffer(); |
michael@0 | 101 | |
michael@0 | 102 | enum { |
michael@0 | 103 | ownNone = 0, |
michael@0 | 104 | ownHandle = 1, |
michael@0 | 105 | ownData = 2, |
michael@0 | 106 | }; |
michael@0 | 107 | |
michael@0 | 108 | inline const GraphicBufferMapper& getBufferMapper() const { return mBufferMapper; } |
michael@0 | 109 | inline GraphicBufferMapper& getBufferMapper() { return mBufferMapper; } |
michael@0 | 110 | uint8_t mOwner; |
michael@0 | 111 | |
michael@0 | 112 | private: |
michael@0 | 113 | friend class Surface; |
michael@0 | 114 | friend class BpSurface; |
michael@0 | 115 | friend class BnSurface; |
michael@0 | 116 | friend class LightRefBase<GraphicBuffer>; |
michael@0 | 117 | GraphicBuffer(const GraphicBuffer& rhs); |
michael@0 | 118 | GraphicBuffer& operator = (const GraphicBuffer& rhs); |
michael@0 | 119 | const GraphicBuffer& operator = (const GraphicBuffer& rhs) const; |
michael@0 | 120 | |
michael@0 | 121 | status_t initSize(uint32_t w, uint32_t h, PixelFormat format, |
michael@0 | 122 | uint32_t usage); |
michael@0 | 123 | |
michael@0 | 124 | void free_handle(); |
michael@0 | 125 | |
michael@0 | 126 | // Flattenable interface |
michael@0 | 127 | size_t getFlattenedSize() const; |
michael@0 | 128 | size_t getFdCount() const; |
michael@0 | 129 | status_t flatten(void* buffer, size_t size, |
michael@0 | 130 | int fds[], size_t count) const; |
michael@0 | 131 | status_t unflatten(void const* buffer, size_t size, |
michael@0 | 132 | int fds[], size_t count); |
michael@0 | 133 | |
michael@0 | 134 | |
michael@0 | 135 | GraphicBufferMapper& mBufferMapper; |
michael@0 | 136 | ssize_t mInitCheck; |
michael@0 | 137 | uint32_t mVStride; |
michael@0 | 138 | int mIndex; |
michael@0 | 139 | }; |
michael@0 | 140 | |
michael@0 | 141 | }; // namespace android |
michael@0 | 142 | |
michael@0 | 143 | #endif // ANDROID_GRAPHIC_BUFFER_H |