Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / gfx / layers / ImageDataSerializer.h
blob8584ea1a10b61dbd65f0cf635c4e59b26f981607
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef GFX_LAYERS_BLOBSURFACE_H
8 #define GFX_LAYERS_BLOBSURFACE_H
10 #include <stdint.h> // for uint8_t, uint32_t
11 #include "mozilla/Attributes.h" // for MOZ_STACK_CLASS
12 #include "mozilla/RefPtr.h" // for already_AddRefed
13 #include "mozilla/gfx/Point.h" // for IntSize
14 #include "mozilla/gfx/Rect.h" // for IntRect
15 #include "mozilla/gfx/Types.h" // for SurfaceFormat
16 #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
18 namespace mozilla {
19 namespace gfx {
20 class DataSourceSurface;
21 class DrawTarget;
22 } // namespace gfx
23 } // namespace mozilla
25 namespace mozilla {
26 namespace layers {
28 namespace ImageDataSerializer {
30 // RGB
32 int32_t ComputeRGBStride(gfx::SurfaceFormat aFormat, int32_t aWidth);
34 int32_t GetRGBStride(const RGBDescriptor& aDescriptor);
36 uint32_t ComputeRGBBufferSize(gfx::IntSize aSize, gfx::SurfaceFormat aFormat);
38 // YCbCr
40 /// This function is meant as a helper to know how much shared memory we need
41 /// to allocate in a shmem in order to place a shared YCbCr image blob of
42 /// given dimensions.
43 uint32_t ComputeYCbCrBufferSize(const gfx::IntSize& aYSize, int32_t aYStride,
44 const gfx::IntSize& aCbCrSize,
45 int32_t aCbCrStride);
46 uint32_t ComputeYCbCrBufferSize(const gfx::IntSize& aYSize, int32_t aYStride,
47 const gfx::IntSize& aCbCrSize,
48 int32_t aCbCrStride, uint32_t aYOffset,
49 uint32_t aCbOffset, uint32_t aCrOffset);
50 uint32_t ComputeYCbCrBufferSize(uint32_t aBufferSize);
52 void ComputeYCbCrOffsets(int32_t yStride, int32_t yHeight, int32_t cbCrStride,
53 int32_t cbCrHeight, uint32_t& outYOffset,
54 uint32_t& outCbOffset, uint32_t& outCrOffset);
56 gfx::SurfaceFormat FormatFromBufferDescriptor(
57 const BufferDescriptor& aDescriptor);
59 gfx::IntSize SizeFromBufferDescriptor(const BufferDescriptor& aDescriptor);
61 gfx::IntRect RectFromBufferDescriptor(const BufferDescriptor& aDescriptor);
63 Maybe<gfx::IntSize> YSizeFromBufferDescriptor(
64 const BufferDescriptor& aDescriptor);
66 Maybe<gfx::IntSize> CbCrSizeFromBufferDescriptor(
67 const BufferDescriptor& aDescriptor);
69 Maybe<int32_t> YStrideFromBufferDescriptor(const BufferDescriptor& aDescriptor);
71 Maybe<int32_t> CbCrStrideFromBufferDescriptor(
72 const BufferDescriptor& aDescriptor);
74 Maybe<gfx::YUVColorSpace> YUVColorSpaceFromBufferDescriptor(
75 const BufferDescriptor& aDescriptor);
77 Maybe<gfx::ColorDepth> ColorDepthFromBufferDescriptor(
78 const BufferDescriptor& aDescriptor);
80 Maybe<gfx::ColorRange> ColorRangeFromBufferDescriptor(
81 const BufferDescriptor& aDescriptor);
83 Maybe<StereoMode> StereoModeFromBufferDescriptor(
84 const BufferDescriptor& aDescriptor);
86 Maybe<gfx::ChromaSubsampling> ChromaSubsamplingFromBufferDescriptor(
87 const BufferDescriptor& aDescriptor);
89 uint8_t* GetYChannel(uint8_t* aBuffer, const YCbCrDescriptor& aDescriptor);
91 uint8_t* GetCbChannel(uint8_t* aBuffer, const YCbCrDescriptor& aDescriptor);
93 uint8_t* GetCrChannel(uint8_t* aBuffer, const YCbCrDescriptor& aDescriptor);
95 already_AddRefed<gfx::DataSourceSurface> DataSourceSurfaceFromYCbCrDescriptor(
96 uint8_t* aBuffer, const YCbCrDescriptor& aDescriptor,
97 gfx::DataSourceSurface* aSurface = nullptr);
99 void ConvertAndScaleFromYCbCrDescriptor(uint8_t* aBuffer,
100 const YCbCrDescriptor& aDescriptor,
101 const gfx::SurfaceFormat& aDestFormat,
102 const gfx::IntSize& aDestSize,
103 unsigned char* aDestBuffer,
104 int32_t aStride);
106 gfx::IntSize GetCroppedCbCrSize(const YCbCrDescriptor& aDescriptor);
108 } // namespace ImageDataSerializer
110 } // namespace layers
111 } // namespace mozilla
113 #endif