Mathias Agopian | 6950e42 | 2009-10-05 17:07:12 -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_GRAPHIC_BUFFER_H |
| 18 | #define ANDROID_GRAPHIC_BUFFER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <ui/android_native_buffer.h> |
| 24 | #include <ui/PixelFormat.h> |
| 25 | #include <ui/Rect.h> |
| 26 | #include <pixelflinger/pixelflinger.h> |
| 27 | |
| 28 | struct android_native_buffer_t; |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | class GraphicBufferMapper; |
| 33 | class Parcel; |
| 34 | |
| 35 | // =========================================================================== |
| 36 | // GraphicBuffer |
| 37 | // =========================================================================== |
| 38 | |
| 39 | class GraphicBuffer |
| 40 | : public EGLNativeBase< |
| 41 | android_native_buffer_t, |
| 42 | GraphicBuffer, |
| 43 | LightRefBase<GraphicBuffer> > |
| 44 | { |
| 45 | public: |
| 46 | |
| 47 | enum { |
| 48 | USAGE_SW_READ_NEVER = GRALLOC_USAGE_SW_READ_NEVER, |
| 49 | USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY, |
| 50 | USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN, |
| 51 | USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK, |
| 52 | |
| 53 | USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER, |
| 54 | USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY, |
| 55 | USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 56 | USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK, |
| 57 | |
| 58 | USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK, |
| 59 | |
| 60 | USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE, |
| 61 | USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER, |
| 62 | USAGE_HW_2D = GRALLOC_USAGE_HW_2D, |
| 63 | USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK |
| 64 | }; |
| 65 | |
| 66 | GraphicBuffer(); |
| 67 | |
| 68 | // creates w * h buffer |
| 69 | GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t ssage); |
| 70 | |
| 71 | // return status |
| 72 | status_t initCheck() const; |
| 73 | |
| 74 | uint32_t getWidth() const { return width; } |
| 75 | uint32_t getHeight() const { return height; } |
| 76 | uint32_t getStride() const { return stride; } |
| 77 | uint32_t getUsage() const { return usage; } |
| 78 | PixelFormat getPixelFormat() const { return format; } |
| 79 | Rect getBounds() const { return Rect(width, height); } |
| 80 | |
| 81 | status_t reallocate(uint32_t w, uint32_t h, PixelFormat f, uint32_t usage); |
| 82 | |
| 83 | status_t lock(uint32_t usage, void** vaddr); |
| 84 | status_t lock(uint32_t usage, const Rect& rect, void** vaddr); |
| 85 | status_t lock(GGLSurface* surface, uint32_t usage); |
| 86 | status_t unlock(); |
| 87 | |
| 88 | android_native_buffer_t* getNativeBuffer() const; |
| 89 | |
| 90 | void setIndex(int index); |
| 91 | int getIndex() const; |
| 92 | |
| 93 | protected: |
| 94 | GraphicBuffer(const Parcel& reply); |
| 95 | virtual ~GraphicBuffer(); |
| 96 | |
| 97 | inline const GraphicBufferMapper& getBufferMapper() const { return mBufferMapper; } |
| 98 | inline GraphicBufferMapper& getBufferMapper() { return mBufferMapper; } |
| 99 | bool mOwner; |
| 100 | |
| 101 | private: |
| 102 | friend class Surface; |
| 103 | friend class BpSurface; |
| 104 | friend class BnSurface; |
| 105 | friend class LightRefBase<GraphicBuffer>; |
| 106 | GraphicBuffer(const GraphicBuffer& rhs); |
| 107 | GraphicBuffer& operator = (const GraphicBuffer& rhs); |
| 108 | const GraphicBuffer& operator = (const GraphicBuffer& rhs) const; |
| 109 | |
| 110 | status_t initSize(uint32_t w, uint32_t h, PixelFormat format, |
| 111 | uint32_t usage); |
| 112 | |
| 113 | static status_t writeToParcel(Parcel* reply, |
| 114 | android_native_buffer_t const* buffer); |
| 115 | |
| 116 | GraphicBufferMapper& mBufferMapper; |
| 117 | ssize_t mInitCheck; |
| 118 | uint32_t mVStride; |
| 119 | int mIndex; |
| 120 | }; |
| 121 | |
| 122 | }; // namespace android |
| 123 | |
| 124 | #endif // ANDROID_GRAPHIC_BUFFER_H |