2012-08-21 10:22:58 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef GRALLOCIMAGES_H
|
|
|
|
#define GRALLOCIMAGES_H
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
|
|
|
|
#include "ImageLayers.h"
|
2013-07-25 02:13:35 +00:00
|
|
|
#include "ImageContainer.h"
|
2014-02-25 04:23:41 +00:00
|
|
|
#include "mozilla/gfx/Point.h"
|
|
|
|
#include "mozilla/layers/AtomicRefCountedWithFinalize.h"
|
|
|
|
#include "mozilla/layers/FenceUtils.h"
|
|
|
|
#include "mozilla/layers/LayersSurfaces.h"
|
2012-08-21 10:22:58 +00:00
|
|
|
|
|
|
|
#include <ui/GraphicBuffer.h>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2013-08-09 15:23:46 +00:00
|
|
|
class GrallocTextureClientOGL;
|
|
|
|
|
2012-08-21 10:22:58 +00:00
|
|
|
/**
|
|
|
|
* The YUV format supported by Android HAL
|
|
|
|
*
|
|
|
|
* 4:2:0 - CbCr width and height is half that of Y.
|
|
|
|
*
|
|
|
|
* This format assumes
|
|
|
|
* - an even width
|
|
|
|
* - an even height
|
|
|
|
* - a horizontal stride multiple of 16 pixels
|
|
|
|
* - a vertical stride equal to the height
|
|
|
|
*
|
|
|
|
* y_size = stride * height
|
|
|
|
* c_size = ALIGN(stride/2, 16) * height/2
|
|
|
|
* size = y_size + c_size * 2
|
|
|
|
* cr_offset = y_size
|
|
|
|
* cb_offset = y_size + c_size
|
|
|
|
*
|
|
|
|
* The Image that is rendered is the picture region defined by
|
|
|
|
* mPicX, mPicY and mPicSize. The size of the rendered image is
|
|
|
|
* mPicSize, not mYSize or mCbCrSize.
|
|
|
|
*/
|
2013-08-09 15:23:46 +00:00
|
|
|
class GrallocImage : public PlanarYCbCrImage
|
|
|
|
{
|
2013-10-02 00:57:50 +00:00
|
|
|
typedef PlanarYCbCrData Data;
|
2014-11-25 00:54:33 +00:00
|
|
|
static int32_t sColorIdMap[];
|
2012-08-21 10:22:58 +00:00
|
|
|
public:
|
2013-07-25 02:13:35 +00:00
|
|
|
struct GrallocData {
|
2014-03-31 15:24:28 +00:00
|
|
|
nsRefPtr<TextureClient> mGraphicBuffer;
|
2013-12-20 16:46:31 +00:00
|
|
|
gfx::IntSize mPicSize;
|
2013-07-25 02:13:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GrallocImage();
|
2012-08-21 10:22:58 +00:00
|
|
|
|
2013-07-25 02:13:35 +00:00
|
|
|
virtual ~GrallocImage();
|
2012-08-21 10:22:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This makes a copy of the data buffers, in order to support functioning
|
|
|
|
* in all different layer managers.
|
|
|
|
*/
|
|
|
|
virtual void SetData(const Data& aData);
|
|
|
|
|
2013-07-25 02:13:35 +00:00
|
|
|
/**
|
|
|
|
* Share the SurfaceDescriptor without making the copy, in order
|
|
|
|
* to support functioning in all different layer managers.
|
|
|
|
*/
|
|
|
|
virtual void SetData(const GrallocData& aData);
|
|
|
|
|
|
|
|
// From [android 4.0.4]/hardware/msm7k/libgralloc-qsd8k/gralloc_priv.h
|
|
|
|
enum {
|
|
|
|
/* OEM specific HAL formats */
|
|
|
|
HAL_PIXEL_FORMAT_YCbCr_422_P = 0x102,
|
|
|
|
HAL_PIXEL_FORMAT_YCbCr_420_P = 0x103,
|
|
|
|
HAL_PIXEL_FORMAT_YCbCr_420_SP = 0x109,
|
|
|
|
HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x10A,
|
2013-09-12 09:40:26 +00:00
|
|
|
HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED = 0x7FA30C03,
|
|
|
|
HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS = 0x7FA30C04,
|
2013-07-25 02:13:35 +00:00
|
|
|
};
|
2012-08-21 10:22:58 +00:00
|
|
|
|
2014-05-01 01:52:00 +00:00
|
|
|
enum {
|
|
|
|
GRALLOC_SW_UAGE = android::GraphicBuffer::USAGE_SOFTWARE_MASK,
|
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() override;
|
2013-07-25 02:13:35 +00:00
|
|
|
|
2014-04-11 13:13:12 +00:00
|
|
|
android::sp<android::GraphicBuffer> GetGraphicBuffer() const;
|
2013-07-25 02:13:35 +00:00
|
|
|
|
2014-04-11 13:13:12 +00:00
|
|
|
void* GetNativeBuffer();
|
2012-08-21 10:22:58 +00:00
|
|
|
|
2014-04-11 13:13:12 +00:00
|
|
|
virtual bool IsValid() { return !!mTextureClient; }
|
2012-08-21 10:22:58 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual TextureClient* GetTextureClient(CompositableClient* aClient) override;
|
2013-08-09 15:23:46 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual GrallocImage* AsGrallocImage() override
|
2014-12-18 04:42:00 +00:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-08-09 15:23:46 +00:00
|
|
|
virtual uint8_t* GetBuffer()
|
|
|
|
{
|
|
|
|
return static_cast<uint8_t*>(GetNativeBuffer());
|
|
|
|
}
|
|
|
|
|
2014-05-01 01:52:00 +00:00
|
|
|
int GetUsage()
|
|
|
|
{
|
|
|
|
return (static_cast<ANativeWindowBuffer*>(GetNativeBuffer()))->usage;
|
|
|
|
}
|
|
|
|
|
2014-07-04 00:38:00 +00:00
|
|
|
static int GetOmxFormat(int aFormat)
|
|
|
|
{
|
|
|
|
uint32_t omxFormat = 0;
|
|
|
|
|
|
|
|
for (int i = 0; sColorIdMap[i]; i += 2) {
|
|
|
|
if (sColorIdMap[i] == aFormat) {
|
|
|
|
omxFormat = sColorIdMap[i + 1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return omxFormat;
|
|
|
|
}
|
|
|
|
|
2012-08-21 10:22:58 +00:00
|
|
|
private:
|
2013-08-09 15:23:46 +00:00
|
|
|
RefPtr<GrallocTextureClientOGL> mTextureClient;
|
2012-08-21 10:22:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* GRALLOCIMAGES_H */
|