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