2012-09-13 20:52:26 +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/. */
|
|
|
|
|
2013-05-23 07:17:10 +00:00
|
|
|
#ifndef MOZILLA_LAYERS_BLOBYCBCRSURFACE_H
|
|
|
|
#define MOZILLA_LAYERS_BLOBYCBCRSURFACE_H
|
2012-09-13 20:52:26 +00:00
|
|
|
|
2013-08-11 23:17:23 +00:00
|
|
|
#include <stddef.h> // for size_t
|
|
|
|
#include <stdint.h> // for uint8_t, uint32_t
|
|
|
|
#include "ImageTypes.h" // for StereoMode
|
|
|
|
#include "mozilla/Attributes.h" // for MOZ_STACK_CLASS
|
|
|
|
#include "mozilla/RefPtr.h" // for TemporaryRef
|
|
|
|
#include "mozilla/gfx/Point.h" // for IntSize
|
2012-09-13 20:52:26 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-07-30 09:59:51 +00:00
|
|
|
namespace gfx {
|
2013-08-11 23:17:23 +00:00
|
|
|
class DataSourceSurface;
|
2013-07-30 09:59:51 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 20:52:26 +00:00
|
|
|
namespace layers {
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 09:20:52 +00:00
|
|
|
class Image;
|
|
|
|
|
2012-09-13 20:52:26 +00:00
|
|
|
/**
|
2013-05-23 07:17:10 +00:00
|
|
|
* Convenience class to share code between YCbCrImageDataSerializer
|
|
|
|
* and YCbCrImageDataDeserializer.
|
|
|
|
* Do not use it.
|
2012-09-13 20:52:26 +00:00
|
|
|
*/
|
2013-05-23 07:17:10 +00:00
|
|
|
class YCbCrImageDataDeserializerBase
|
2012-09-13 20:52:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-02-20 21:04:13 +00:00
|
|
|
bool IsValid() const { return mIsValid; }
|
2012-09-13 20:52:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the Y channel data pointer.
|
|
|
|
*/
|
|
|
|
uint8_t* GetYData();
|
|
|
|
/**
|
|
|
|
* Returns the Cb channel data pointer.
|
|
|
|
*/
|
|
|
|
uint8_t* GetCbData();
|
|
|
|
/**
|
|
|
|
* Returns the Cr channel data pointer.
|
|
|
|
*/
|
|
|
|
uint8_t* GetCrData();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the Y channel stride.
|
|
|
|
*/
|
|
|
|
uint32_t GetYStride();
|
|
|
|
/**
|
|
|
|
* Returns the stride of the Cb and Cr channels.
|
|
|
|
*/
|
|
|
|
uint32_t GetCbCrStride();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the dimensions of the Y Channel.
|
|
|
|
*/
|
2013-12-20 16:46:30 +00:00
|
|
|
gfx::IntSize GetYSize();
|
2012-09-13 20:52:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the dimensions of the Cb and Cr Channel.
|
|
|
|
*/
|
2013-12-20 16:46:30 +00:00
|
|
|
gfx::IntSize GetCbCrSize();
|
2012-09-13 20:52:26 +00:00
|
|
|
|
2013-08-04 07:46:17 +00:00
|
|
|
/**
|
|
|
|
* Stereo mode for the image.
|
|
|
|
*/
|
|
|
|
StereoMode GetStereoMode();
|
|
|
|
|
2013-04-05 17:24:58 +00:00
|
|
|
/**
|
|
|
|
* Return a pointer to the begining of the data buffer.
|
|
|
|
*/
|
|
|
|
uint8_t* GetData();
|
2014-02-20 21:04:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is meant as a helper to know how much shared memory we need
|
|
|
|
* to allocate in a shmem in order to place a shared YCbCr image blob of
|
|
|
|
* given dimensions.
|
|
|
|
*/
|
|
|
|
static size_t ComputeMinBufferSize(const gfx::IntSize& aYSize,
|
|
|
|
uint32_t aYStride,
|
|
|
|
const gfx::IntSize& aCbCrSize,
|
|
|
|
uint32_t aCbCrStride);
|
|
|
|
static size_t ComputeMinBufferSize(const gfx::IntSize& aYSize,
|
|
|
|
const gfx::IntSize& aCbCrSize);
|
|
|
|
static size_t ComputeMinBufferSize(uint32_t aSize);
|
|
|
|
|
2013-05-23 07:17:10 +00:00
|
|
|
protected:
|
2014-02-20 21:04:13 +00:00
|
|
|
YCbCrImageDataDeserializerBase(uint8_t* aData, size_t aDataSize)
|
|
|
|
: mData (aData)
|
|
|
|
, mDataSize(aDataSize)
|
|
|
|
, mIsValid(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void Validate();
|
2013-05-23 07:17:10 +00:00
|
|
|
|
|
|
|
uint8_t* mData;
|
2014-02-20 21:04:13 +00:00
|
|
|
size_t mDataSize;
|
|
|
|
bool mIsValid;
|
2013-05-23 07:17:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A view on a YCbCr image stored with its metadata in a blob of memory.
|
|
|
|
* It is only meant as a convenience to access the image data, and does not own
|
|
|
|
* the data. The instance can live on the stack and used as follows:
|
|
|
|
*
|
|
|
|
* const YCbCrImage& yuv = sharedImage.get_YCbCrImage();
|
|
|
|
* YCbCrImageDataDeserializer deserializer(yuv.data().get<uint8_t>());
|
|
|
|
* if (!deserializer.IsValid()) {
|
|
|
|
* // handle error
|
|
|
|
* }
|
|
|
|
* size = deserializer.GetYSize(); // work with the data, etc...
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS YCbCrImageDataSerializer : public YCbCrImageDataDeserializerBase
|
|
|
|
{
|
|
|
|
public:
|
2014-02-20 21:04:13 +00:00
|
|
|
YCbCrImageDataSerializer(uint8_t* aData, size_t aDataSize)
|
|
|
|
: YCbCrImageDataDeserializerBase(aData, aDataSize)
|
|
|
|
{
|
|
|
|
// a serializer needs to be usable before correct buffer info has been written to it
|
|
|
|
mIsValid = !!mData;
|
|
|
|
}
|
2013-05-23 07:17:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the image informations in the buffer for given dimensions.
|
|
|
|
* The provided pointer should point to the beginning of the (chunk of)
|
|
|
|
* buffer on which we want to store the image.
|
|
|
|
*/
|
2013-12-16 22:33:47 +00:00
|
|
|
void InitializeBufferInfo(uint32_t aYOffset,
|
|
|
|
uint32_t aCbOffset,
|
|
|
|
uint32_t aCrOffset,
|
2014-01-02 15:50:14 +00:00
|
|
|
uint32_t aYStride,
|
|
|
|
uint32_t aCbCrStride,
|
|
|
|
const gfx::IntSize& aYSize,
|
|
|
|
const gfx::IntSize& aCbCrSize,
|
|
|
|
StereoMode aStereoMode);
|
|
|
|
void InitializeBufferInfo(uint32_t aYStride,
|
|
|
|
uint32_t aCbCrStride,
|
2013-12-16 22:33:47 +00:00
|
|
|
const gfx::IntSize& aYSize,
|
|
|
|
const gfx::IntSize& aCbCrSize,
|
|
|
|
StereoMode aStereoMode);
|
2013-05-23 07:17:10 +00:00
|
|
|
void InitializeBufferInfo(const gfx::IntSize& aYSize,
|
2013-08-04 07:46:17 +00:00
|
|
|
const gfx::IntSize& aCbCrSize,
|
|
|
|
StereoMode aStereoMode);
|
2012-12-04 10:36:33 +00:00
|
|
|
bool CopyData(const uint8_t* aYData,
|
|
|
|
const uint8_t* aCbData, const uint8_t* aCrData,
|
2013-12-20 16:46:30 +00:00
|
|
|
gfx::IntSize aYSize, uint32_t aYStride,
|
|
|
|
gfx::IntSize aCbCrSize, uint32_t aCbCrStride,
|
2012-12-04 10:36:33 +00:00
|
|
|
uint32_t aYSkip, uint32_t aCbCrSkip);
|
2013-05-23 07:17:10 +00:00
|
|
|
};
|
2012-10-29 15:08:06 +00:00
|
|
|
|
2013-05-23 07:17:10 +00:00
|
|
|
/**
|
|
|
|
* A view on a YCbCr image stored with its metadata in a blob of memory.
|
|
|
|
* It is only meant as a convenience to access the image data, and does not own
|
|
|
|
* the data. The instance can live on the stack and used as follows:
|
|
|
|
*
|
|
|
|
* const YCbCrImage& yuv = sharedImage.get_YCbCrImage();
|
|
|
|
* YCbCrImageDataDeserializer deserializer(yuv.data().get<uint8_t>());
|
|
|
|
* if (!deserializer.IsValid()) {
|
|
|
|
* // handle error
|
|
|
|
* }
|
|
|
|
* size = deserializer.GetYSize(); // work with the data, etc...
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS YCbCrImageDataDeserializer : public YCbCrImageDataDeserializerBase
|
|
|
|
{
|
|
|
|
public:
|
2014-02-20 21:04:13 +00:00
|
|
|
YCbCrImageDataDeserializer(uint8_t* aData, size_t aDataSize)
|
|
|
|
: YCbCrImageDataDeserializerBase(aData, aDataSize)
|
|
|
|
{
|
|
|
|
Validate();
|
|
|
|
}
|
2013-07-30 09:59:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert the YCbCr data into RGB and return a DataSourceSurface.
|
|
|
|
* This is a costly operation, so use it only when YCbCr compositing is
|
|
|
|
* not supported.
|
|
|
|
*/
|
|
|
|
TemporaryRef<gfx::DataSourceSurface> ToDataSourceSurface();
|
2012-09-13 20:52:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|