michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MOZILLA_LAYERS_BLOBYCBCRSURFACE_H michael@0: #define MOZILLA_LAYERS_BLOBYCBCRSURFACE_H michael@0: michael@0: #include // for size_t michael@0: #include // for uint8_t, uint32_t michael@0: #include "ImageTypes.h" // for StereoMode michael@0: #include "mozilla/Attributes.h" // for MOZ_STACK_CLASS michael@0: #include "mozilla/RefPtr.h" // for TemporaryRef michael@0: #include "mozilla/gfx/Point.h" // for IntSize michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: class DataSourceSurface; michael@0: } michael@0: michael@0: namespace layers { michael@0: michael@0: class Image; michael@0: michael@0: /** michael@0: * Convenience class to share code between YCbCrImageDataSerializer michael@0: * and YCbCrImageDataDeserializer. michael@0: * Do not use it. michael@0: */ michael@0: class YCbCrImageDataDeserializerBase michael@0: { michael@0: public: michael@0: bool IsValid() const { return mIsValid; } michael@0: michael@0: /** michael@0: * Returns the Y channel data pointer. michael@0: */ michael@0: uint8_t* GetYData(); michael@0: /** michael@0: * Returns the Cb channel data pointer. michael@0: */ michael@0: uint8_t* GetCbData(); michael@0: /** michael@0: * Returns the Cr channel data pointer. michael@0: */ michael@0: uint8_t* GetCrData(); michael@0: michael@0: /** michael@0: * Returns the Y channel stride. michael@0: */ michael@0: uint32_t GetYStride(); michael@0: /** michael@0: * Returns the stride of the Cb and Cr channels. michael@0: */ michael@0: uint32_t GetCbCrStride(); michael@0: michael@0: /** michael@0: * Returns the dimensions of the Y Channel. michael@0: */ michael@0: gfx::IntSize GetYSize(); michael@0: michael@0: /** michael@0: * Returns the dimensions of the Cb and Cr Channel. michael@0: */ michael@0: gfx::IntSize GetCbCrSize(); michael@0: michael@0: /** michael@0: * Stereo mode for the image. michael@0: */ michael@0: StereoMode GetStereoMode(); michael@0: michael@0: /** michael@0: * Return a pointer to the begining of the data buffer. michael@0: */ michael@0: uint8_t* GetData(); michael@0: michael@0: /** michael@0: * This function is meant as a helper to know how much shared memory we need michael@0: * to allocate in a shmem in order to place a shared YCbCr image blob of michael@0: * given dimensions. michael@0: */ michael@0: static size_t ComputeMinBufferSize(const gfx::IntSize& aYSize, michael@0: uint32_t aYStride, michael@0: const gfx::IntSize& aCbCrSize, michael@0: uint32_t aCbCrStride); michael@0: static size_t ComputeMinBufferSize(const gfx::IntSize& aYSize, michael@0: const gfx::IntSize& aCbCrSize); michael@0: static size_t ComputeMinBufferSize(uint32_t aSize); michael@0: michael@0: protected: michael@0: YCbCrImageDataDeserializerBase(uint8_t* aData, size_t aDataSize) michael@0: : mData (aData) michael@0: , mDataSize(aDataSize) michael@0: , mIsValid(false) michael@0: {} michael@0: michael@0: void Validate(); michael@0: michael@0: uint8_t* mData; michael@0: size_t mDataSize; michael@0: bool mIsValid; michael@0: }; michael@0: michael@0: /** michael@0: * A view on a YCbCr image stored with its metadata in a blob of memory. michael@0: * It is only meant as a convenience to access the image data, and does not own michael@0: * the data. The instance can live on the stack and used as follows: michael@0: * michael@0: * const YCbCrImage& yuv = sharedImage.get_YCbCrImage(); michael@0: * YCbCrImageDataDeserializer deserializer(yuv.data().get()); michael@0: * if (!deserializer.IsValid()) { michael@0: * // handle error michael@0: * } michael@0: * size = deserializer.GetYSize(); // work with the data, etc... michael@0: */ michael@0: class MOZ_STACK_CLASS YCbCrImageDataSerializer : public YCbCrImageDataDeserializerBase michael@0: { michael@0: public: michael@0: YCbCrImageDataSerializer(uint8_t* aData, size_t aDataSize) michael@0: : YCbCrImageDataDeserializerBase(aData, aDataSize) michael@0: { michael@0: // a serializer needs to be usable before correct buffer info has been written to it michael@0: mIsValid = !!mData; michael@0: } michael@0: michael@0: /** michael@0: * Write the image informations in the buffer for given dimensions. michael@0: * The provided pointer should point to the beginning of the (chunk of) michael@0: * buffer on which we want to store the image. michael@0: */ michael@0: void InitializeBufferInfo(uint32_t aYOffset, michael@0: uint32_t aCbOffset, michael@0: uint32_t aCrOffset, michael@0: uint32_t aYStride, michael@0: uint32_t aCbCrStride, michael@0: const gfx::IntSize& aYSize, michael@0: const gfx::IntSize& aCbCrSize, michael@0: StereoMode aStereoMode); michael@0: void InitializeBufferInfo(uint32_t aYStride, michael@0: uint32_t aCbCrStride, michael@0: const gfx::IntSize& aYSize, michael@0: const gfx::IntSize& aCbCrSize, michael@0: StereoMode aStereoMode); michael@0: void InitializeBufferInfo(const gfx::IntSize& aYSize, michael@0: const gfx::IntSize& aCbCrSize, michael@0: StereoMode aStereoMode); michael@0: bool CopyData(const uint8_t* aYData, michael@0: const uint8_t* aCbData, const uint8_t* aCrData, michael@0: gfx::IntSize aYSize, uint32_t aYStride, michael@0: gfx::IntSize aCbCrSize, uint32_t aCbCrStride, michael@0: uint32_t aYSkip, uint32_t aCbCrSkip); michael@0: }; michael@0: michael@0: /** michael@0: * A view on a YCbCr image stored with its metadata in a blob of memory. michael@0: * It is only meant as a convenience to access the image data, and does not own michael@0: * the data. The instance can live on the stack and used as follows: michael@0: * michael@0: * const YCbCrImage& yuv = sharedImage.get_YCbCrImage(); michael@0: * YCbCrImageDataDeserializer deserializer(yuv.data().get()); michael@0: * if (!deserializer.IsValid()) { michael@0: * // handle error michael@0: * } michael@0: * size = deserializer.GetYSize(); // work with the data, etc... michael@0: */ michael@0: class MOZ_STACK_CLASS YCbCrImageDataDeserializer : public YCbCrImageDataDeserializerBase michael@0: { michael@0: public: michael@0: YCbCrImageDataDeserializer(uint8_t* aData, size_t aDataSize) michael@0: : YCbCrImageDataDeserializerBase(aData, aDataSize) michael@0: { michael@0: Validate(); michael@0: } michael@0: michael@0: /** michael@0: * Convert the YCbCr data into RGB and return a DataSourceSurface. michael@0: * This is a costly operation, so use it only when YCbCr compositing is michael@0: * not supported. michael@0: */ michael@0: TemporaryRef ToDataSourceSurface(); michael@0: }; michael@0: michael@0: } // namespace michael@0: } // namespace michael@0: michael@0: #endif