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 {
|
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
class TextureClient;
|
2013-08-09 19:23:46 +04:00
|
|
|
|
2015-10-27 08:43:07 +03:00
|
|
|
already_AddRefed<gfx::DataSourceSurface>
|
|
|
|
GetDataSourceSurfaceFrom(android::sp<android::GraphicBuffer>& aGraphicBuffer,
|
|
|
|
gfx::IntSize aSize,
|
|
|
|
const layers::PlanarYCbCrData& aYcbcrData);
|
|
|
|
|
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.
|
|
|
|
*/
|
2015-11-06 21:55:31 +03:00
|
|
|
class GrallocImage : public RecyclingPlanarYCbCrImage
|
2013-08-09 19:23:46 +04:00
|
|
|
{
|
2013-10-02 04:57:50 +04:00
|
|
|
typedef PlanarYCbCrData Data;
|
2014-11-25 03:54:33 +03:00
|
|
|
static int32_t sColorIdMap[];
|
2012-08-21 14:22:58 +04:00
|
|
|
public:
|
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.
|
|
|
|
*/
|
2015-11-03 14:24:26 +03:00
|
|
|
virtual bool SetData(const Data& aData);
|
2012-08-21 14:22:58 +04:00
|
|
|
|
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.
|
|
|
|
*/
|
2015-11-17 11:09:01 +03:00
|
|
|
void SetData(TextureClient* aGraphicBuffer, const gfx::IntSize& aSize);
|
2013-07-25 06:13:35 +04:00
|
|
|
|
|
|
|
// 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,
|
|
|
|
};
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() 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
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual TextureClient* GetTextureClient(CompositableClient* aClient) override;
|
2013-08-09 19:23:46 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual GrallocImage* AsGrallocImage() override
|
2014-12-18 07:42:00 +03:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
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:
|
2015-10-15 18:53:37 +03:00
|
|
|
RefPtr<TextureClient> mTextureClient;
|
2012-08-21 14:22:58 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
2015-07-13 18:25:42 +03:00
|
|
|
|
2012-08-21 14:22:58 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* GRALLOCIMAGES_H */
|