DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (dcc6d7a0dc00)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef MOZILLA_LAYERS_BLOBYCBCRSURFACE_H
#define MOZILLA_LAYERS_BLOBYCBCRSURFACE_H

#include <stddef.h>                     // for size_t
#include <stdint.h>                     // for uint8_t, uint32_t
#include "ImageTypes.h"                 // for StereoMode
#include "mozilla/Attributes.h"         // for MOZ_STACK_CLASS
#include "mozilla/RefPtr.h"             // for already_AddRefed
#include "mozilla/gfx/Point.h"          // for IntSize

namespace mozilla {
namespace gfx {
class DataSourceSurface;
} // namespace gfx

namespace layers {

class Image;

/**
 * Convenience class to share code between YCbCrImageDataSerializer
 * and YCbCrImageDataDeserializer.
 * Do not use it.
 */
class YCbCrImageDataDeserializerBase
{
public:
  bool IsValid() const { return mIsValid; }

  /**
   * Returns the Y channel data pointer.
   */
  uint8_t* GetYData();
  /**
   * Returns the Cb channel data pointer.
   */
  uint8_t* GetCbData();
  /**
   * Returns the Cr channel data pointer.
   */
  uint8_t* GetCrData();

  /**
   * Returns the Y channel stride.
   */
  uint32_t GetYStride();
  /**
   * Returns the stride of the Cb and Cr channels.
   */
  uint32_t GetCbCrStride();

  /**
   * Returns the dimensions of the Y Channel.
   */
  gfx::IntSize GetYSize();

  /**
   * Returns the dimensions of the Cb and Cr Channel.
   */
  gfx::IntSize GetCbCrSize();

  /**
   * Stereo mode for the image.
   */
  StereoMode GetStereoMode();

  /**
   * Return a pointer to the begining of the data buffer.
   */
  uint8_t* GetData();

  /**
   * This function is meant as a helper to know how much shared memory we need
   * to allocate in a shmem in order to place a shared YCbCr image blob of
   * given dimensions.
   */
  static size_t ComputeMinBufferSize(const gfx::IntSize& aYSize,
                                     uint32_t aYStride,
                                     const gfx::IntSize& aCbCrSize,
                                     uint32_t aCbCrStride);
  static size_t ComputeMinBufferSize(const gfx::IntSize& aYSize,
                                     const gfx::IntSize& aCbCrSize);
  static size_t ComputeMinBufferSize(uint32_t aSize);

protected:
  YCbCrImageDataDeserializerBase(uint8_t* aData, size_t aDataSize)
    : mData (aData)
    , mDataSize(aDataSize)
    , mIsValid(false)
  {}

  void Validate();

  uint8_t* mData;
  size_t mDataSize;
  bool mIsValid;
};

/**
 * A view on a YCbCr image stored with its metadata in a blob of memory.
 * It is only meant as a convenience to access the image data, and does not own
 * the data. The instance can live on the stack and used as follows:
 *
 * const YCbCrImage& yuv = sharedImage.get_YCbCrImage();
 * YCbCrImageDataDeserializer deserializer(yuv.data().get<uint8_t>());
 * if (!deserializer.IsValid()) {
 *   // handle error
 * }
 * size = deserializer.GetYSize(); // work with the data, etc...
 */
class MOZ_STACK_CLASS YCbCrImageDataSerializer : public YCbCrImageDataDeserializerBase
{
public:
  YCbCrImageDataSerializer(uint8_t* aData, size_t aDataSize)
    : YCbCrImageDataDeserializerBase(aData, aDataSize)
  {
    // a serializer needs to be usable before correct buffer info has been written to it
    mIsValid = !!mData;
  }

  /**
   * Write the image informations in the buffer for given dimensions.
   * The provided pointer should point to the beginning of the (chunk of)
   * buffer on which we want to store the image.
   */
  void InitializeBufferInfo(uint32_t aYOffset,
                            uint32_t aCbOffset,
                            uint32_t aCrOffset,
                            uint32_t aYStride,
                            uint32_t aCbCrStride,
                            const gfx::IntSize& aYSize,
                            const gfx::IntSize& aCbCrSize,
                            StereoMode aStereoMode);
  void InitializeBufferInfo(uint32_t aYStride,
                            uint32_t aCbCrStride,
                            const gfx::IntSize& aYSize,
                            const gfx::IntSize& aCbCrSize,
                            StereoMode aStereoMode);
  void InitializeBufferInfo(const gfx::IntSize& aYSize,
                            const gfx::IntSize& aCbCrSize,
                            StereoMode aStereoMode);
  bool CopyData(const uint8_t* aYData,
                const uint8_t* aCbData, const uint8_t* aCrData,
                gfx::IntSize aYSize, uint32_t aYStride,
                gfx::IntSize aCbCrSize, uint32_t aCbCrStride,
                uint32_t aYSkip, uint32_t aCbCrSkip);
};

/**
 * A view on a YCbCr image stored with its metadata in a blob of memory.
 * It is only meant as a convenience to access the image data, and does not own
 * the data. The instance can live on the stack and used as follows:
 *
 * const YCbCrImage& yuv = sharedImage.get_YCbCrImage();
 * YCbCrImageDataDeserializer deserializer(yuv.data().get<uint8_t>());
 * if (!deserializer.IsValid()) {
 *   // handle error
 * }
 * size = deserializer.GetYSize(); // work with the data, etc...
 */
class MOZ_STACK_CLASS YCbCrImageDataDeserializer : public YCbCrImageDataDeserializerBase
{
public:
  YCbCrImageDataDeserializer(uint8_t* aData, size_t aDataSize)
    : YCbCrImageDataDeserializerBase(aData, aDataSize)
  {
    Validate();
  }

  /**
   * Convert the YCbCr data into RGB and return a DataSourceSurface.
   * This is a costly operation, so use it only when YCbCr compositing is
   * not supported.
   */
  already_AddRefed<gfx::DataSourceSurface> ToDataSourceSurface();
};

} // namespace layers
} // namespace mozilla

#endif