2009-10-06 00:07:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANDROID_GRAPHIC_BUFFER_H
|
|
|
|
#define ANDROID_GRAPHIC_BUFFER_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2012-02-25 02:25:41 +00:00
|
|
|
#include <ui/ANativeObjectBase.h>
|
2009-10-06 00:07:12 +00:00
|
|
|
#include <ui/PixelFormat.h>
|
|
|
|
#include <ui/Rect.h>
|
2010-02-12 01:30:52 +00:00
|
|
|
#include <utils/Flattenable.h>
|
2013-03-07 02:50:52 +00:00
|
|
|
#include <utils/RefBase.h>
|
2012-02-25 02:25:41 +00:00
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
|
2011-05-01 18:33:26 +00:00
|
|
|
struct ANativeWindowBuffer;
|
2009-10-06 00:07:12 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
class GraphicBufferMapper;
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// GraphicBuffer
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
class GraphicBuffer
|
2013-03-07 02:50:52 +00:00
|
|
|
: public ANativeObjectBase< ANativeWindowBuffer, GraphicBuffer, RefBase >,
|
2013-07-30 04:24:40 +00:00
|
|
|
public Flattenable<GraphicBuffer>
|
2009-10-06 00:07:12 +00:00
|
|
|
{
|
2013-07-30 04:24:40 +00:00
|
|
|
friend class Flattenable<GraphicBuffer>;
|
2009-10-06 00:07:12 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
enum {
|
|
|
|
USAGE_SW_READ_NEVER = GRALLOC_USAGE_SW_READ_NEVER,
|
|
|
|
USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY,
|
|
|
|
USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN,
|
|
|
|
USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK,
|
2014-11-17 20:03:59 +00:00
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER,
|
|
|
|
USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY,
|
|
|
|
USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN,
|
|
|
|
USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK,
|
2011-01-19 23:27:27 +00:00
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK,
|
2011-01-19 23:27:27 +00:00
|
|
|
|
|
|
|
USAGE_PROTECTED = GRALLOC_USAGE_PROTECTED,
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE,
|
|
|
|
USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER,
|
|
|
|
USAGE_HW_2D = GRALLOC_USAGE_HW_2D,
|
2011-08-10 18:48:07 +00:00
|
|
|
USAGE_HW_COMPOSER = GRALLOC_USAGE_HW_COMPOSER,
|
2011-11-22 00:51:47 +00:00
|
|
|
USAGE_HW_VIDEO_ENCODER = GRALLOC_USAGE_HW_VIDEO_ENCODER,
|
2014-07-01 21:22:59 +00:00
|
|
|
USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK,
|
|
|
|
|
|
|
|
USAGE_CURSOR = GRALLOC_USAGE_CURSOR,
|
2009-10-06 00:07:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GraphicBuffer();
|
|
|
|
|
|
|
|
// creates w * h buffer
|
2014-11-17 20:03:59 +00:00
|
|
|
GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
|
|
|
|
uint32_t inUsage);
|
2009-10-27 03:12:37 +00:00
|
|
|
|
|
|
|
// create a buffer from an existing handle
|
2014-11-17 20:03:59 +00:00
|
|
|
GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
|
|
|
|
uint32_t inUsage, uint32_t inStride, native_handle_t* inHandle,
|
|
|
|
bool keepOwnership);
|
2009-10-06 00:07:12 +00:00
|
|
|
|
2011-05-01 18:33:26 +00:00
|
|
|
// create a buffer from an existing ANativeWindowBuffer
|
|
|
|
GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership);
|
2010-10-07 20:46:55 +00:00
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
// return status
|
|
|
|
status_t initCheck() const;
|
|
|
|
|
2014-11-17 20:03:59 +00:00
|
|
|
uint32_t getWidth() const { return static_cast<uint32_t>(width); }
|
|
|
|
uint32_t getHeight() const { return static_cast<uint32_t>(height); }
|
|
|
|
uint32_t getStride() const { return static_cast<uint32_t>(stride); }
|
|
|
|
uint32_t getUsage() const { return static_cast<uint32_t>(usage); }
|
2009-10-06 00:07:12 +00:00
|
|
|
PixelFormat getPixelFormat() const { return format; }
|
|
|
|
Rect getBounds() const { return Rect(width, height); }
|
2014-03-28 22:10:52 +00:00
|
|
|
uint64_t getId() const { return mId; }
|
|
|
|
|
2014-11-17 20:03:59 +00:00
|
|
|
status_t reallocate(uint32_t inWidth, uint32_t inHeight,
|
|
|
|
PixelFormat inFormat, uint32_t inUsage);
|
2009-10-06 00:07:12 +00:00
|
|
|
|
2015-04-17 00:28:43 +00:00
|
|
|
bool needsReallocation(uint32_t inWidth, uint32_t inHeight,
|
|
|
|
PixelFormat inFormat, uint32_t inUsage);
|
|
|
|
|
2014-11-17 20:03:59 +00:00
|
|
|
status_t lock(uint32_t inUsage, void** vaddr);
|
|
|
|
status_t lock(uint32_t inUsage, const Rect& rect, void** vaddr);
|
2013-05-05 01:07:43 +00:00
|
|
|
// For HAL_PIXEL_FORMAT_YCbCr_420_888
|
2014-11-17 20:03:59 +00:00
|
|
|
status_t lockYCbCr(uint32_t inUsage, android_ycbcr *ycbcr);
|
|
|
|
status_t lockYCbCr(uint32_t inUsage, const Rect& rect,
|
|
|
|
android_ycbcr *ycbcr);
|
2009-10-06 00:07:12 +00:00
|
|
|
status_t unlock();
|
2014-11-17 20:03:59 +00:00
|
|
|
status_t lockAsync(uint32_t inUsage, void** vaddr, int fenceFd);
|
|
|
|
status_t lockAsync(uint32_t inUsage, const Rect& rect, void** vaddr,
|
|
|
|
int fenceFd);
|
|
|
|
status_t lockAsyncYCbCr(uint32_t inUsage, android_ycbcr *ycbcr,
|
|
|
|
int fenceFd);
|
|
|
|
status_t lockAsyncYCbCr(uint32_t inUsage, const Rect& rect,
|
|
|
|
android_ycbcr *ycbcr, int fenceFd);
|
2014-04-01 12:30:53 +00:00
|
|
|
status_t unlockAsync(int *fenceFd);
|
2010-12-04 01:33:09 +00:00
|
|
|
|
2011-05-01 18:33:26 +00:00
|
|
|
ANativeWindowBuffer* getNativeBuffer() const;
|
2009-10-06 00:07:12 +00:00
|
|
|
|
2010-12-04 01:33:09 +00:00
|
|
|
// for debugging
|
|
|
|
static void dumpAllocationsToSystemLog();
|
|
|
|
|
2013-08-01 02:18:22 +00:00
|
|
|
// Flattenable protocol
|
|
|
|
size_t getFlattenedSize() const;
|
|
|
|
size_t getFdCount() const;
|
|
|
|
status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
|
|
|
|
status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
|
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
private:
|
2013-07-30 04:24:40 +00:00
|
|
|
~GraphicBuffer();
|
2009-10-06 00:07:12 +00:00
|
|
|
|
2009-10-27 03:12:37 +00:00
|
|
|
enum {
|
|
|
|
ownNone = 0,
|
|
|
|
ownHandle = 1,
|
|
|
|
ownData = 2,
|
|
|
|
};
|
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
inline const GraphicBufferMapper& getBufferMapper() const {
|
|
|
|
return mBufferMapper;
|
|
|
|
}
|
|
|
|
inline GraphicBufferMapper& getBufferMapper() {
|
|
|
|
return mBufferMapper;
|
|
|
|
}
|
2009-10-27 03:12:37 +00:00
|
|
|
uint8_t mOwner;
|
2009-10-06 00:07:12 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class Surface;
|
|
|
|
friend class BpSurface;
|
|
|
|
friend class BnSurface;
|
|
|
|
friend class LightRefBase<GraphicBuffer>;
|
|
|
|
GraphicBuffer(const GraphicBuffer& rhs);
|
|
|
|
GraphicBuffer& operator = (const GraphicBuffer& rhs);
|
|
|
|
const GraphicBuffer& operator = (const GraphicBuffer& rhs) const;
|
|
|
|
|
2014-11-17 20:03:59 +00:00
|
|
|
status_t initSize(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat,
|
|
|
|
uint32_t inUsage);
|
2009-10-06 00:07:12 +00:00
|
|
|
|
2010-02-12 01:30:52 +00:00
|
|
|
void free_handle();
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
GraphicBufferMapper& mBufferMapper;
|
|
|
|
ssize_t mInitCheck;
|
2010-10-07 20:46:55 +00:00
|
|
|
|
|
|
|
// If we're wrapping another buffer then this reference will make sure it
|
|
|
|
// doesn't get freed.
|
2011-05-01 18:33:26 +00:00
|
|
|
sp<ANativeWindowBuffer> mWrappedBuffer;
|
2014-03-28 22:10:52 +00:00
|
|
|
|
|
|
|
uint64_t mId;
|
2009-10-06 00:07:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}; // namespace android
|
|
|
|
|
|
|
|
#endif // ANDROID_GRAPHIC_BUFFER_H
|