当前位置: 首页>>代码示例>>C++>>正文


C++ CheckedInt32::value方法代码示例

本文整理汇总了C++中CheckedInt32::value方法的典型用法代码示例。如果您正苦于以下问题:C++ CheckedInt32::value方法的具体用法?C++ CheckedInt32::value怎么用?C++ CheckedInt32::value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CheckedInt32的用法示例。


在下文中一共展示了CheckedInt32::value方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void
ImageBitmap::SetPictureRect(const IntRect& aRect, ErrorResult& aRv)
{
  gfx::IntRect rect = aRect;

  // fix up negative dimensions
  if (rect.width < 0) {
    CheckedInt32 checkedX = CheckedInt32(rect.x) + rect.width;

    if (!checkedX.isValid()) {
      aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
      return;
    }

    rect.x = checkedX.value();
    rect.width = -(rect.width);
  }

  if (rect.height < 0) {
    CheckedInt32 checkedY = CheckedInt32(rect.y) + rect.height;

    if (!checkedY.isValid()) {
      aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
      return;
    }

    rect.y = checkedY.value();
    rect.height = -(rect.height);
  }

  mPictureRect = rect;
}
开发者ID:rhelmer,项目名称:gecko-dev,代码行数:32,代码来源:ImageBitmap.cpp

示例2: GetSize

void
gfxXlibSurface::TakePixmap()
{
    NS_ASSERTION(!mPixmapTaken, "I already own the Pixmap!");
    mPixmapTaken = true;

    // The bit depth returned from Cairo is technically int, but this is
    // the last place we'd be worried about that scenario.
    unsigned int bitDepth = cairo_xlib_surface_get_depth(CairoSurface());
    MOZ_ASSERT((bitDepth % 8) == 0, "Memory used not recorded correctly");    

    // Divide by 8 because surface_get_depth gives us the number of *bits* per
    // pixel.
    gfxIntSize size = GetSize();
    CheckedInt32 totalBytes = CheckedInt32(size.width) * CheckedInt32(size.height) * (bitDepth/8);

    // Don't do anything in the "else" case.  We could add INT32_MAX, but that
    // would overflow the memory used counter.  It would also mean we tried for
    // a 2G image.  For now, we'll just assert,
    MOZ_ASSERT(totalBytes.isValid(),"Did not expect to exceed 2Gb image");
    if (totalBytes.isValid()) {
        RecordMemoryUsed(totalBytes.value());
    }
}
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:24,代码来源:gfxXlibSurface.cpp

示例3: gfxWarning

size_t
BufferSizeFromStrideAndHeight(int32_t aStride,
                              int32_t aHeight,
                              int32_t aExtraBytes)
{
  if (MOZ_UNLIKELY(aHeight <= 0)) {
    return 0;
  }

  // We limit the length returned to values that can be represented by int32_t
  // because we don't want to allocate buffers any bigger than that. This
  // allows for a buffer size of over 2 GiB which is already rediculously
  // large and will make the process janky. (Note the choice of the signed type
  // is deliberate because we specifically don't want the returned value to
  // overflow if someone stores the buffer length in an int32_t variable.)

  CheckedInt32 requiredBytes =
    CheckedInt32(aStride) * CheckedInt32(aHeight) + CheckedInt32(aExtraBytes);
  if (MOZ_UNLIKELY(!requiredBytes.isValid())) {
    gfxWarning() << "Buffer size too big; returning zero";
    return 0;
  }
  return requiredBytes.value();
}
开发者ID:ednapiranha,项目名称:gecko-dev,代码行数:24,代码来源:DataSurfaceHelpers.cpp


注:本文中的CheckedInt32::value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。