michael@0: /* michael@0: * Copyright (C) 2007 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef ANDROID_GRAPHIC_BUFFER_H michael@0: #define ANDROID_GRAPHIC_BUFFER_H michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: struct android_native_buffer_t; michael@0: michael@0: namespace android { michael@0: michael@0: class GraphicBufferMapper; michael@0: michael@0: // =========================================================================== michael@0: // GraphicBuffer michael@0: // =========================================================================== michael@0: michael@0: class GraphicBuffer michael@0: : public EGLNativeBase< michael@0: android_native_buffer_t, michael@0: GraphicBuffer, michael@0: LightRefBase >, public Flattenable michael@0: { michael@0: public: michael@0: michael@0: enum { michael@0: USAGE_SW_READ_NEVER = GRALLOC_USAGE_SW_READ_NEVER, michael@0: USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY, michael@0: USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN, michael@0: USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK, michael@0: michael@0: USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER, michael@0: USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY, michael@0: USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN, michael@0: USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK, michael@0: michael@0: USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK, michael@0: michael@0: USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE, michael@0: USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER, michael@0: USAGE_HW_2D = GRALLOC_USAGE_HW_2D, michael@0: USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK michael@0: }; michael@0: michael@0: GraphicBuffer(); michael@0: michael@0: // creates w * h buffer michael@0: GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage); michael@0: michael@0: // create a buffer from an existing handle michael@0: GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage, michael@0: uint32_t stride, native_handle_t* handle, bool keepOwnership); michael@0: michael@0: // return status michael@0: status_t initCheck() const; michael@0: michael@0: uint32_t getWidth() const { return width; } michael@0: uint32_t getHeight() const { return height; } michael@0: uint32_t getStride() const { return stride; } michael@0: uint32_t getUsage() const { return usage; } michael@0: PixelFormat getPixelFormat() const { return format; } michael@0: Rect getBounds() const { return Rect(width, height); } michael@0: michael@0: status_t reallocate(uint32_t w, uint32_t h, PixelFormat f, uint32_t usage); michael@0: michael@0: status_t lock(uint32_t usage, void** vaddr); michael@0: status_t lock(uint32_t usage, const Rect& rect, void** vaddr); michael@0: status_t lock(GGLSurface* surface, uint32_t usage); michael@0: status_t unlock(); michael@0: michael@0: android_native_buffer_t* getNativeBuffer() const; michael@0: michael@0: void setIndex(int index); michael@0: int getIndex() const; michael@0: void setVerticalStride(uint32_t vstride); michael@0: uint32_t getVerticalStride() const; michael@0: michael@0: protected: michael@0: virtual ~GraphicBuffer(); michael@0: michael@0: enum { michael@0: ownNone = 0, michael@0: ownHandle = 1, michael@0: ownData = 2, michael@0: }; michael@0: michael@0: inline const GraphicBufferMapper& getBufferMapper() const { return mBufferMapper; } michael@0: inline GraphicBufferMapper& getBufferMapper() { return mBufferMapper; } michael@0: uint8_t mOwner; michael@0: michael@0: private: michael@0: friend class Surface; michael@0: friend class BpSurface; michael@0: friend class BnSurface; michael@0: friend class LightRefBase; michael@0: GraphicBuffer(const GraphicBuffer& rhs); michael@0: GraphicBuffer& operator = (const GraphicBuffer& rhs); michael@0: const GraphicBuffer& operator = (const GraphicBuffer& rhs) const; michael@0: michael@0: status_t initSize(uint32_t w, uint32_t h, PixelFormat format, michael@0: uint32_t usage); michael@0: michael@0: void free_handle(); michael@0: michael@0: // Flattenable interface michael@0: size_t getFlattenedSize() const; michael@0: size_t getFdCount() const; michael@0: status_t flatten(void* buffer, size_t size, michael@0: int fds[], size_t count) const; michael@0: status_t unflatten(void const* buffer, size_t size, michael@0: int fds[], size_t count); michael@0: michael@0: michael@0: GraphicBufferMapper& mBufferMapper; michael@0: ssize_t mInitCheck; michael@0: uint32_t mVStride; michael@0: int mIndex; michael@0: }; michael@0: michael@0: }; // namespace android michael@0: michael@0: #endif // ANDROID_GRAPHIC_BUFFER_H