gfx/layers/YCbCrImageDataSerializer.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/YCbCrImageDataSerializer.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,186 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef MOZILLA_LAYERS_BLOBYCBCRSURFACE_H
    1.10 +#define MOZILLA_LAYERS_BLOBYCBCRSURFACE_H
    1.11 +
    1.12 +#include <stddef.h>                     // for size_t
    1.13 +#include <stdint.h>                     // for uint8_t, uint32_t
    1.14 +#include "ImageTypes.h"                 // for StereoMode
    1.15 +#include "mozilla/Attributes.h"         // for MOZ_STACK_CLASS
    1.16 +#include "mozilla/RefPtr.h"             // for TemporaryRef
    1.17 +#include "mozilla/gfx/Point.h"          // for IntSize
    1.18 +
    1.19 +namespace mozilla {
    1.20 +namespace gfx {
    1.21 +class DataSourceSurface;
    1.22 +}
    1.23 +
    1.24 +namespace layers {
    1.25 +
    1.26 +class Image;
    1.27 +
    1.28 +/**
    1.29 + * Convenience class to share code between YCbCrImageDataSerializer
    1.30 + * and YCbCrImageDataDeserializer.
    1.31 + * Do not use it.
    1.32 + */
    1.33 +class YCbCrImageDataDeserializerBase
    1.34 +{
    1.35 +public:
    1.36 +  bool IsValid() const { return mIsValid; }
    1.37 +
    1.38 +  /**
    1.39 +   * Returns the Y channel data pointer.
    1.40 +   */
    1.41 +  uint8_t* GetYData();
    1.42 +  /**
    1.43 +   * Returns the Cb channel data pointer.
    1.44 +   */
    1.45 +  uint8_t* GetCbData();
    1.46 +  /**
    1.47 +   * Returns the Cr channel data pointer.
    1.48 +   */
    1.49 +  uint8_t* GetCrData();
    1.50 +
    1.51 +  /**
    1.52 +   * Returns the Y channel stride.
    1.53 +   */
    1.54 +  uint32_t GetYStride();
    1.55 +  /**
    1.56 +   * Returns the stride of the Cb and Cr channels.
    1.57 +   */
    1.58 +  uint32_t GetCbCrStride();
    1.59 +
    1.60 +  /**
    1.61 +   * Returns the dimensions of the Y Channel.
    1.62 +   */
    1.63 +  gfx::IntSize GetYSize();
    1.64 +
    1.65 +  /**
    1.66 +   * Returns the dimensions of the Cb and Cr Channel.
    1.67 +   */
    1.68 +  gfx::IntSize GetCbCrSize();
    1.69 +
    1.70 +  /**
    1.71 +   * Stereo mode for the image.
    1.72 +   */
    1.73 +  StereoMode GetStereoMode();
    1.74 +
    1.75 +  /**
    1.76 +   * Return a pointer to the begining of the data buffer.
    1.77 +   */
    1.78 +  uint8_t* GetData();
    1.79 +
    1.80 +  /**
    1.81 +   * This function is meant as a helper to know how much shared memory we need
    1.82 +   * to allocate in a shmem in order to place a shared YCbCr image blob of
    1.83 +   * given dimensions.
    1.84 +   */
    1.85 +  static size_t ComputeMinBufferSize(const gfx::IntSize& aYSize,
    1.86 +                                     uint32_t aYStride,
    1.87 +                                     const gfx::IntSize& aCbCrSize,
    1.88 +                                     uint32_t aCbCrStride);
    1.89 +  static size_t ComputeMinBufferSize(const gfx::IntSize& aYSize,
    1.90 +                                     const gfx::IntSize& aCbCrSize);
    1.91 +  static size_t ComputeMinBufferSize(uint32_t aSize);
    1.92 +
    1.93 +protected:
    1.94 +  YCbCrImageDataDeserializerBase(uint8_t* aData, size_t aDataSize)
    1.95 +    : mData (aData)
    1.96 +    , mDataSize(aDataSize)
    1.97 +    , mIsValid(false)
    1.98 +  {}
    1.99 +
   1.100 +  void Validate();
   1.101 +
   1.102 +  uint8_t* mData;
   1.103 +  size_t mDataSize;
   1.104 +  bool mIsValid;
   1.105 +};
   1.106 +
   1.107 +/**
   1.108 + * A view on a YCbCr image stored with its metadata in a blob of memory.
   1.109 + * It is only meant as a convenience to access the image data, and does not own
   1.110 + * the data. The instance can live on the stack and used as follows:
   1.111 + *
   1.112 + * const YCbCrImage& yuv = sharedImage.get_YCbCrImage();
   1.113 + * YCbCrImageDataDeserializer deserializer(yuv.data().get<uint8_t>());
   1.114 + * if (!deserializer.IsValid()) {
   1.115 + *   // handle error
   1.116 + * }
   1.117 + * size = deserializer.GetYSize(); // work with the data, etc...
   1.118 + */
   1.119 +class MOZ_STACK_CLASS YCbCrImageDataSerializer : public YCbCrImageDataDeserializerBase
   1.120 +{
   1.121 +public:
   1.122 +  YCbCrImageDataSerializer(uint8_t* aData, size_t aDataSize)
   1.123 +    : YCbCrImageDataDeserializerBase(aData, aDataSize)
   1.124 +  {
   1.125 +    // a serializer needs to be usable before correct buffer info has been written to it
   1.126 +    mIsValid = !!mData;
   1.127 +  }
   1.128 +
   1.129 +  /**
   1.130 +   * Write the image informations in the buffer for given dimensions.
   1.131 +   * The provided pointer should point to the beginning of the (chunk of)
   1.132 +   * buffer on which we want to store the image.
   1.133 +   */
   1.134 +  void InitializeBufferInfo(uint32_t aYOffset,
   1.135 +                            uint32_t aCbOffset,
   1.136 +                            uint32_t aCrOffset,
   1.137 +                            uint32_t aYStride,
   1.138 +                            uint32_t aCbCrStride,
   1.139 +                            const gfx::IntSize& aYSize,
   1.140 +                            const gfx::IntSize& aCbCrSize,
   1.141 +                            StereoMode aStereoMode);
   1.142 +  void InitializeBufferInfo(uint32_t aYStride,
   1.143 +                            uint32_t aCbCrStride,
   1.144 +                            const gfx::IntSize& aYSize,
   1.145 +                            const gfx::IntSize& aCbCrSize,
   1.146 +                            StereoMode aStereoMode);
   1.147 +  void InitializeBufferInfo(const gfx::IntSize& aYSize,
   1.148 +                            const gfx::IntSize& aCbCrSize,
   1.149 +                            StereoMode aStereoMode);
   1.150 +  bool CopyData(const uint8_t* aYData,
   1.151 +                const uint8_t* aCbData, const uint8_t* aCrData,
   1.152 +                gfx::IntSize aYSize, uint32_t aYStride,
   1.153 +                gfx::IntSize aCbCrSize, uint32_t aCbCrStride,
   1.154 +                uint32_t aYSkip, uint32_t aCbCrSkip);
   1.155 +};
   1.156 +
   1.157 +/**
   1.158 + * A view on a YCbCr image stored with its metadata in a blob of memory.
   1.159 + * It is only meant as a convenience to access the image data, and does not own
   1.160 + * the data. The instance can live on the stack and used as follows:
   1.161 + *
   1.162 + * const YCbCrImage& yuv = sharedImage.get_YCbCrImage();
   1.163 + * YCbCrImageDataDeserializer deserializer(yuv.data().get<uint8_t>());
   1.164 + * if (!deserializer.IsValid()) {
   1.165 + *   // handle error
   1.166 + * }
   1.167 + * size = deserializer.GetYSize(); // work with the data, etc...
   1.168 + */
   1.169 +class MOZ_STACK_CLASS YCbCrImageDataDeserializer : public YCbCrImageDataDeserializerBase
   1.170 +{
   1.171 +public:
   1.172 +  YCbCrImageDataDeserializer(uint8_t* aData, size_t aDataSize)
   1.173 +    : YCbCrImageDataDeserializerBase(aData, aDataSize)
   1.174 +  {
   1.175 +    Validate();
   1.176 +  }
   1.177 +
   1.178 +  /**
   1.179 +   * Convert the YCbCr data into RGB and return a DataSourceSurface.
   1.180 +   * This is a costly operation, so use it only when YCbCr compositing is
   1.181 +   * not supported.
   1.182 +   */
   1.183 +  TemporaryRef<gfx::DataSourceSurface> ToDataSourceSurface();
   1.184 +};
   1.185 +
   1.186 +} // namespace
   1.187 +} // namespace
   1.188 +
   1.189 +#endif

mercurial