Bumping manifests a=b2g-bump
[gecko.git] / gfx / layers / YCbCrImageDataSerializer.h
blob5534251e5f3464cfaf41aecd0c9b0bf415c4c7b6
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
16 namespace mozilla {
17 namespace gfx {
18 class DataSourceSurface;
21 namespace layers {
23 class Image;
25 /**
26 * Convenience class to share code between YCbCrImageDataSerializer
27 * and YCbCrImageDataDeserializer.
28 * Do not use it.
30 class YCbCrImageDataDeserializerBase
32 public:
33 bool IsValid() const { return mIsValid; }
35 /**
36 * Returns the Y channel data pointer.
38 uint8_t* GetYData();
39 /**
40 * Returns the Cb channel data pointer.
42 uint8_t* GetCbData();
43 /**
44 * Returns the Cr channel data pointer.
46 uint8_t* GetCrData();
48 /**
49 * Returns the Y channel stride.
51 uint32_t GetYStride();
52 /**
53 * Returns the stride of the Cb and Cr channels.
55 uint32_t GetCbCrStride();
57 /**
58 * Returns the dimensions of the Y Channel.
60 gfx::IntSize GetYSize();
62 /**
63 * Returns the dimensions of the Cb and Cr Channel.
65 gfx::IntSize GetCbCrSize();
67 /**
68 * Stereo mode for the image.
70 StereoMode GetStereoMode();
72 /**
73 * Return a pointer to the begining of the data buffer.
75 uint8_t* GetData();
77 /**
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
80 * given dimensions.
82 static size_t ComputeMinBufferSize(const gfx::IntSize& aYSize,
83 uint32_t aYStride,
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);
90 protected:
91 YCbCrImageDataDeserializerBase(uint8_t* aData, size_t aDataSize)
92 : mData (aData)
93 , mDataSize(aDataSize)
94 , mIsValid(false)
97 void Validate();
99 uint8_t* mData;
100 size_t mDataSize;
101 bool mIsValid;
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()) {
112 * // handle error
114 * size = deserializer.GetYSize(); // work with the data, etc...
116 class MOZ_STACK_CLASS YCbCrImageDataSerializer : public YCbCrImageDataDeserializerBase
118 public:
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
123 mIsValid = !!mData;
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,
132 uint32_t aCbOffset,
133 uint32_t aCrOffset,
134 uint32_t aYStride,
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()) {
162 * // handle error
164 * size = deserializer.GetYSize(); // work with the data, etc...
166 class MOZ_STACK_CLASS YCbCrImageDataDeserializer : public YCbCrImageDataDeserializerBase
168 public:
169 YCbCrImageDataDeserializer(uint8_t* aData, size_t aDataSize)
170 : YCbCrImageDataDeserializerBase(aData, aDataSize)
172 Validate();
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
178 * not supported.
180 TemporaryRef<gfx::DataSourceSurface> ToDataSourceSurface();
183 } // namespace
184 } // namespace
186 #endif