1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef MOZILLA_LAYERS_BLOBYCBCRSURFACE_H
7 #define MOZILLA_LAYERS_BLOBYCBCRSURFACE_H
9 #include <stddef.h> // for size_t
10 #include <stdint.h> // for uint8_t, uint32_t
11 #include "ImageTypes.h" // for StereoMode
12 #include "mozilla/Attributes.h" // for MOZ_STACK_CLASS
13 #include "mozilla/RefPtr.h" // for TemporaryRef
14 #include "mozilla/gfx/Point.h" // for IntSize
18 class DataSourceSurface
;
26 * Convenience class to share code between YCbCrImageDataSerializer
27 * and YCbCrImageDataDeserializer.
30 class YCbCrImageDataDeserializerBase
33 bool IsValid() const { return mIsValid
; }
36 * Returns the Y channel data pointer.
40 * Returns the Cb channel data pointer.
44 * Returns the Cr channel data pointer.
49 * Returns the Y channel stride.
51 uint32_t GetYStride();
53 * Returns the stride of the Cb and Cr channels.
55 uint32_t GetCbCrStride();
58 * Returns the dimensions of the Y Channel.
60 gfx::IntSize
GetYSize();
63 * Returns the dimensions of the Cb and Cr Channel.
65 gfx::IntSize
GetCbCrSize();
68 * Stereo mode for the image.
70 StereoMode
GetStereoMode();
73 * Return a pointer to the begining of the data buffer.
78 * This function is meant as a helper to know how much shared memory we need
79 * to allocate in a shmem in order to place a shared YCbCr image blob of
82 static size_t ComputeMinBufferSize(const gfx::IntSize
& aYSize
,
84 const gfx::IntSize
& aCbCrSize
,
85 uint32_t aCbCrStride
);
86 static size_t ComputeMinBufferSize(const gfx::IntSize
& aYSize
,
87 const gfx::IntSize
& aCbCrSize
);
88 static size_t ComputeMinBufferSize(uint32_t aSize
);
91 YCbCrImageDataDeserializerBase(uint8_t* aData
, size_t aDataSize
)
93 , mDataSize(aDataSize
)
105 * A view on a YCbCr image stored with its metadata in a blob of memory.
106 * It is only meant as a convenience to access the image data, and does not own
107 * the data. The instance can live on the stack and used as follows:
109 * const YCbCrImage& yuv = sharedImage.get_YCbCrImage();
110 * YCbCrImageDataDeserializer deserializer(yuv.data().get<uint8_t>());
111 * if (!deserializer.IsValid()) {
114 * size = deserializer.GetYSize(); // work with the data, etc...
116 class MOZ_STACK_CLASS YCbCrImageDataSerializer
: public YCbCrImageDataDeserializerBase
119 YCbCrImageDataSerializer(uint8_t* aData
, size_t aDataSize
)
120 : YCbCrImageDataDeserializerBase(aData
, aDataSize
)
122 // a serializer needs to be usable before correct buffer info has been written to it
127 * Write the image informations in the buffer for given dimensions.
128 * The provided pointer should point to the beginning of the (chunk of)
129 * buffer on which we want to store the image.
131 void InitializeBufferInfo(uint32_t aYOffset
,
135 uint32_t aCbCrStride
,
136 const gfx::IntSize
& aYSize
,
137 const gfx::IntSize
& aCbCrSize
,
138 StereoMode aStereoMode
);
139 void InitializeBufferInfo(uint32_t aYStride
,
140 uint32_t aCbCrStride
,
141 const gfx::IntSize
& aYSize
,
142 const gfx::IntSize
& aCbCrSize
,
143 StereoMode aStereoMode
);
144 void InitializeBufferInfo(const gfx::IntSize
& aYSize
,
145 const gfx::IntSize
& aCbCrSize
,
146 StereoMode aStereoMode
);
147 bool CopyData(const uint8_t* aYData
,
148 const uint8_t* aCbData
, const uint8_t* aCrData
,
149 gfx::IntSize aYSize
, uint32_t aYStride
,
150 gfx::IntSize aCbCrSize
, uint32_t aCbCrStride
,
151 uint32_t aYSkip
, uint32_t aCbCrSkip
);
155 * A view on a YCbCr image stored with its metadata in a blob of memory.
156 * It is only meant as a convenience to access the image data, and does not own
157 * the data. The instance can live on the stack and used as follows:
159 * const YCbCrImage& yuv = sharedImage.get_YCbCrImage();
160 * YCbCrImageDataDeserializer deserializer(yuv.data().get<uint8_t>());
161 * if (!deserializer.IsValid()) {
164 * size = deserializer.GetYSize(); // work with the data, etc...
166 class MOZ_STACK_CLASS YCbCrImageDataDeserializer
: public YCbCrImageDataDeserializerBase
169 YCbCrImageDataDeserializer(uint8_t* aData
, size_t aDataSize
)
170 : YCbCrImageDataDeserializerBase(aData
, aDataSize
)
176 * Convert the YCbCr data into RGB and return a DataSourceSurface.
177 * This is a costly operation, so use it only when YCbCr compositing is
180 TemporaryRef
<gfx::DataSourceSurface
> ToDataSourceSurface();