gfx/layers/YCbCrImageDataSerializer.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef MOZILLA_LAYERS_BLOBYCBCRSURFACE_H
michael@0 7 #define MOZILLA_LAYERS_BLOBYCBCRSURFACE_H
michael@0 8
michael@0 9 #include <stddef.h> // for size_t
michael@0 10 #include <stdint.h> // for uint8_t, uint32_t
michael@0 11 #include "ImageTypes.h" // for StereoMode
michael@0 12 #include "mozilla/Attributes.h" // for MOZ_STACK_CLASS
michael@0 13 #include "mozilla/RefPtr.h" // for TemporaryRef
michael@0 14 #include "mozilla/gfx/Point.h" // for IntSize
michael@0 15
michael@0 16 namespace mozilla {
michael@0 17 namespace gfx {
michael@0 18 class DataSourceSurface;
michael@0 19 }
michael@0 20
michael@0 21 namespace layers {
michael@0 22
michael@0 23 class Image;
michael@0 24
michael@0 25 /**
michael@0 26 * Convenience class to share code between YCbCrImageDataSerializer
michael@0 27 * and YCbCrImageDataDeserializer.
michael@0 28 * Do not use it.
michael@0 29 */
michael@0 30 class YCbCrImageDataDeserializerBase
michael@0 31 {
michael@0 32 public:
michael@0 33 bool IsValid() const { return mIsValid; }
michael@0 34
michael@0 35 /**
michael@0 36 * Returns the Y channel data pointer.
michael@0 37 */
michael@0 38 uint8_t* GetYData();
michael@0 39 /**
michael@0 40 * Returns the Cb channel data pointer.
michael@0 41 */
michael@0 42 uint8_t* GetCbData();
michael@0 43 /**
michael@0 44 * Returns the Cr channel data pointer.
michael@0 45 */
michael@0 46 uint8_t* GetCrData();
michael@0 47
michael@0 48 /**
michael@0 49 * Returns the Y channel stride.
michael@0 50 */
michael@0 51 uint32_t GetYStride();
michael@0 52 /**
michael@0 53 * Returns the stride of the Cb and Cr channels.
michael@0 54 */
michael@0 55 uint32_t GetCbCrStride();
michael@0 56
michael@0 57 /**
michael@0 58 * Returns the dimensions of the Y Channel.
michael@0 59 */
michael@0 60 gfx::IntSize GetYSize();
michael@0 61
michael@0 62 /**
michael@0 63 * Returns the dimensions of the Cb and Cr Channel.
michael@0 64 */
michael@0 65 gfx::IntSize GetCbCrSize();
michael@0 66
michael@0 67 /**
michael@0 68 * Stereo mode for the image.
michael@0 69 */
michael@0 70 StereoMode GetStereoMode();
michael@0 71
michael@0 72 /**
michael@0 73 * Return a pointer to the begining of the data buffer.
michael@0 74 */
michael@0 75 uint8_t* GetData();
michael@0 76
michael@0 77 /**
michael@0 78 * This function is meant as a helper to know how much shared memory we need
michael@0 79 * to allocate in a shmem in order to place a shared YCbCr image blob of
michael@0 80 * given dimensions.
michael@0 81 */
michael@0 82 static size_t ComputeMinBufferSize(const gfx::IntSize& aYSize,
michael@0 83 uint32_t aYStride,
michael@0 84 const gfx::IntSize& aCbCrSize,
michael@0 85 uint32_t aCbCrStride);
michael@0 86 static size_t ComputeMinBufferSize(const gfx::IntSize& aYSize,
michael@0 87 const gfx::IntSize& aCbCrSize);
michael@0 88 static size_t ComputeMinBufferSize(uint32_t aSize);
michael@0 89
michael@0 90 protected:
michael@0 91 YCbCrImageDataDeserializerBase(uint8_t* aData, size_t aDataSize)
michael@0 92 : mData (aData)
michael@0 93 , mDataSize(aDataSize)
michael@0 94 , mIsValid(false)
michael@0 95 {}
michael@0 96
michael@0 97 void Validate();
michael@0 98
michael@0 99 uint8_t* mData;
michael@0 100 size_t mDataSize;
michael@0 101 bool mIsValid;
michael@0 102 };
michael@0 103
michael@0 104 /**
michael@0 105 * A view on a YCbCr image stored with its metadata in a blob of memory.
michael@0 106 * It is only meant as a convenience to access the image data, and does not own
michael@0 107 * the data. The instance can live on the stack and used as follows:
michael@0 108 *
michael@0 109 * const YCbCrImage& yuv = sharedImage.get_YCbCrImage();
michael@0 110 * YCbCrImageDataDeserializer deserializer(yuv.data().get<uint8_t>());
michael@0 111 * if (!deserializer.IsValid()) {
michael@0 112 * // handle error
michael@0 113 * }
michael@0 114 * size = deserializer.GetYSize(); // work with the data, etc...
michael@0 115 */
michael@0 116 class MOZ_STACK_CLASS YCbCrImageDataSerializer : public YCbCrImageDataDeserializerBase
michael@0 117 {
michael@0 118 public:
michael@0 119 YCbCrImageDataSerializer(uint8_t* aData, size_t aDataSize)
michael@0 120 : YCbCrImageDataDeserializerBase(aData, aDataSize)
michael@0 121 {
michael@0 122 // a serializer needs to be usable before correct buffer info has been written to it
michael@0 123 mIsValid = !!mData;
michael@0 124 }
michael@0 125
michael@0 126 /**
michael@0 127 * Write the image informations in the buffer for given dimensions.
michael@0 128 * The provided pointer should point to the beginning of the (chunk of)
michael@0 129 * buffer on which we want to store the image.
michael@0 130 */
michael@0 131 void InitializeBufferInfo(uint32_t aYOffset,
michael@0 132 uint32_t aCbOffset,
michael@0 133 uint32_t aCrOffset,
michael@0 134 uint32_t aYStride,
michael@0 135 uint32_t aCbCrStride,
michael@0 136 const gfx::IntSize& aYSize,
michael@0 137 const gfx::IntSize& aCbCrSize,
michael@0 138 StereoMode aStereoMode);
michael@0 139 void InitializeBufferInfo(uint32_t aYStride,
michael@0 140 uint32_t aCbCrStride,
michael@0 141 const gfx::IntSize& aYSize,
michael@0 142 const gfx::IntSize& aCbCrSize,
michael@0 143 StereoMode aStereoMode);
michael@0 144 void InitializeBufferInfo(const gfx::IntSize& aYSize,
michael@0 145 const gfx::IntSize& aCbCrSize,
michael@0 146 StereoMode aStereoMode);
michael@0 147 bool CopyData(const uint8_t* aYData,
michael@0 148 const uint8_t* aCbData, const uint8_t* aCrData,
michael@0 149 gfx::IntSize aYSize, uint32_t aYStride,
michael@0 150 gfx::IntSize aCbCrSize, uint32_t aCbCrStride,
michael@0 151 uint32_t aYSkip, uint32_t aCbCrSkip);
michael@0 152 };
michael@0 153
michael@0 154 /**
michael@0 155 * A view on a YCbCr image stored with its metadata in a blob of memory.
michael@0 156 * It is only meant as a convenience to access the image data, and does not own
michael@0 157 * the data. The instance can live on the stack and used as follows:
michael@0 158 *
michael@0 159 * const YCbCrImage& yuv = sharedImage.get_YCbCrImage();
michael@0 160 * YCbCrImageDataDeserializer deserializer(yuv.data().get<uint8_t>());
michael@0 161 * if (!deserializer.IsValid()) {
michael@0 162 * // handle error
michael@0 163 * }
michael@0 164 * size = deserializer.GetYSize(); // work with the data, etc...
michael@0 165 */
michael@0 166 class MOZ_STACK_CLASS YCbCrImageDataDeserializer : public YCbCrImageDataDeserializerBase
michael@0 167 {
michael@0 168 public:
michael@0 169 YCbCrImageDataDeserializer(uint8_t* aData, size_t aDataSize)
michael@0 170 : YCbCrImageDataDeserializerBase(aData, aDataSize)
michael@0 171 {
michael@0 172 Validate();
michael@0 173 }
michael@0 174
michael@0 175 /**
michael@0 176 * Convert the YCbCr data into RGB and return a DataSourceSurface.
michael@0 177 * This is a costly operation, so use it only when YCbCr compositing is
michael@0 178 * not supported.
michael@0 179 */
michael@0 180 TemporaryRef<gfx::DataSourceSurface> ToDataSourceSurface();
michael@0 181 };
michael@0 182
michael@0 183 } // namespace
michael@0 184 } // namespace
michael@0 185
michael@0 186 #endif

mercurial