2012-08-21 03:22:58 -07: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-24 19:13:35 -07:00
|
|
|
#include "ImageContainer.h"
|
2014-02-24 20:23:41 -08:00
|
|
|
#include "mozilla/gfx/Point.h"
|
|
|
|
#include "mozilla/layers/AtomicRefCountedWithFinalize.h"
|
|
|
|
#include "mozilla/layers/FenceUtils.h"
|
|
|
|
#include "mozilla/layers/LayersSurfaces.h"
|
2012-08-21 03:22:58 -07:00
|
|
|
|
|
|
|
#include <ui/GraphicBuffer.h>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2013-08-09 08:23:46 -07:00
|
|
|
class GrallocTextureClientOGL;
|
|
|
|
|
2012-08-21 03:22:58 -07: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 08:23:46 -07:00
|
|
|
class GrallocImage : public PlanarYCbCrImage
|
|
|
|
, public ISharedImage
|
|
|
|
{
|
2013-10-01 17:57:50 -07:00
|
|
|
typedef PlanarYCbCrData Data;
|
2013-07-24 19:13:35 -07:00
|
|
|
static uint32_t sColorIdMap[];
|
2012-08-21 03:22:58 -07:00
|
|
|
public:
|
2013-07-24 19:13:35 -07:00
|
|
|
struct GrallocData {
|
2014-03-31 08:24:28 -07:00
|
|
|
nsRefPtr<TextureClient> mGraphicBuffer;
|
2013-12-20 08:46:31 -08:00
|
|
|
gfx::IntSize mPicSize;
|
2013-07-24 19:13:35 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
GrallocImage();
|
2012-08-21 03:22:58 -07:00
|
|
|
|
2013-07-24 19:13:35 -07:00
|
|
|
virtual ~GrallocImage();
|
2012-08-21 03:22:58 -07: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-24 19:13:35 -07: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 02:40:26 -07:00
|
|
|
HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED = 0x7FA30C03,
|
|
|
|
HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS = 0x7FA30C04,
|
2013-07-24 19:13:35 -07:00
|
|
|
};
|
2012-08-21 03:22:58 -07:00
|
|
|
|
2014-04-30 18:52:00 -07:00
|
|
|
enum {
|
|
|
|
GRALLOC_SW_UAGE = android::GraphicBuffer::USAGE_SOFTWARE_MASK,
|
|
|
|
};
|
|
|
|
|
2014-01-28 06:13:58 -08:00
|
|
|
virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
|
2013-07-24 19:13:35 -07:00
|
|
|
|
2014-04-11 06:13:12 -07:00
|
|
|
android::sp<android::GraphicBuffer> GetGraphicBuffer() const;
|
2013-07-24 19:13:35 -07:00
|
|
|
|
2014-04-11 06:13:12 -07:00
|
|
|
void* GetNativeBuffer();
|
2012-08-21 03:22:58 -07:00
|
|
|
|
2014-04-11 06:13:12 -07:00
|
|
|
virtual bool IsValid() { return !!mTextureClient; }
|
2012-08-21 03:22:58 -07:00
|
|
|
|
2013-08-09 08:23:46 -07:00
|
|
|
virtual ISharedImage* AsSharedImage() MOZ_OVERRIDE { return this; }
|
|
|
|
|
2014-02-16 14:23:39 -08:00
|
|
|
virtual TextureClient* GetTextureClient(CompositableClient* aClient) MOZ_OVERRIDE;
|
2013-08-09 08:23:46 -07:00
|
|
|
|
|
|
|
virtual uint8_t* GetBuffer()
|
|
|
|
{
|
|
|
|
return static_cast<uint8_t*>(GetNativeBuffer());
|
|
|
|
}
|
|
|
|
|
2014-04-30 18:52:00 -07:00
|
|
|
int GetUsage()
|
|
|
|
{
|
|
|
|
return (static_cast<ANativeWindowBuffer*>(GetNativeBuffer()))->usage;
|
|
|
|
}
|
|
|
|
|
2014-07-03 17:38:00 -07: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 03:22:58 -07:00
|
|
|
private:
|
2013-08-09 08:23:46 -07:00
|
|
|
RefPtr<GrallocTextureClientOGL> mTextureClient;
|
2012-08-21 03:22:58 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* GRALLOCIMAGES_H */
|