Verified Commit 40581f92 authored by Lee Salzman's avatar Lee Salzman Committed by Pier Angelo Vendrame
Browse files

Bug 1990970. r=gfx-reviewers,ahale a=RyanVM

Differential Revision: https://phabricator.services.mozilla.com/D266513

Resolved conflicts in gfx/2d/HelpersSkia.h
parent 5901e49a
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -374,8 +374,14 @@ void SharedContextWebgl::ClearCachesIfNecessary() {
// not exceed the available texture limits and that shader creation succeeded.
bool DrawTargetWebgl::Init(const IntSize& size, const SurfaceFormat format,
                           const RefPtr<SharedContextWebgl>& aSharedContext) {
  MOZ_ASSERT(format == SurfaceFormat::B8G8R8A8 ||
             format == SurfaceFormat::B8G8R8X8);
  switch (format) {
    case SurfaceFormat::B8G8R8A8:
    case SurfaceFormat::B8G8R8X8:
      break;
    default:
      MOZ_ASSERT_UNREACHABLE("Unsupported format for DrawTargetWebgl.");
      return false;
  }

  mSize = size;
  mFormat = format;
+18 −3
Original line number Diff line number Diff line
@@ -1733,8 +1733,11 @@ bool DrawTargetSkia::Init(const IntSize& aSize, SurfaceFormat aFormat) {
  // we need to have surfaces that have a stride aligned to 4 for interop with
  // cairo
  SkImageInfo info = MakeSkiaImageInfo(aSize, aFormat);
  if (info.bytesPerPixel() != BytesPerPixel(aFormat)) {
    return false;
  }
  size_t stride = GetAlignedStride<4>(info.width(), info.bytesPerPixel());
  if (!stride) {
  if (!stride || stride < info.minRowBytes64()) {
    return false;
  }
  SkSurfaceProps props(0, GetSkPixelGeometry());
@@ -1803,9 +1806,14 @@ bool DrawTargetSkia::Init(unsigned char* aData, const IntSize& aSize,
  MOZ_ASSERT((aFormat != SurfaceFormat::B8G8R8X8) || aUninitialized ||
             VerifyRGBXFormat(aData, aSize, aStride, aFormat));

  SkImageInfo info = MakeSkiaImageInfo(aSize, aFormat);
  if (info.bytesPerPixel() != BytesPerPixel(aFormat) || aStride <= 0 ||
      size_t(aStride) < info.minRowBytes64()) {
    return false;
  }

  SkSurfaceProps props(0, GetSkPixelGeometry());
  mSurface = AsRefPtr(SkSurfaces::WrapPixels(MakeSkiaImageInfo(aSize, aFormat),
                                             aData, aStride, &props));
  mSurface = AsRefPtr(SkSurfaces::WrapPixels(info, aData, aStride, &props));
  if (!mSurface) {
    return false;
  }
@@ -1830,6 +1838,13 @@ bool DrawTargetSkia::Init(RefPtr<DataSourceSurface>&& aSurface) {
  MOZ_ASSERT((format != SurfaceFormat::B8G8R8X8) ||
             VerifyRGBXFormat(map->GetData(), size, map->GetStride(), format));

  SkImageInfo info = MakeSkiaImageInfo(size, format);
  if (info.bytesPerPixel() != BytesPerPixel(format) ||
      size_t(map->GetStride()) < info.minRowBytes64()) {
    delete map;
    return false;
  }

  SkSurfaceProps props(0, GetSkPixelGeometry());
  mSurface = AsRefPtr(SkSurfaces::WrapPixels(
      MakeSkiaImageInfo(size, format), map->GetData(), map->GetStride(),
+5 −0
Original line number Diff line number Diff line
@@ -41,7 +41,12 @@ static inline SkColorType GfxFormatToSkiaColorType(SurfaceFormat format) {
      return kRGBA_8888_SkColorType;
    default:
      MOZ_DIAGNOSTIC_ASSERT(false, "Unknown surface format");
      switch (BytesPerPixel(format)) {
        case 4:
          return kRGBA_8888_SkColorType;
        default:
          return kAlpha_8_SkColorType;
      }
  }
}

+18 −8
Original line number Diff line number Diff line
@@ -3456,9 +3456,14 @@ inline bool RecordedSourceSurfaceCreation::PlayEvent(
    return false;
  }

  RefPtr<SourceSurface> src = Factory::CreateWrappingDataSourceSurface(
      mData, mSize.width * BytesPerPixel(mFormat), mSize, mFormat,
      [](void* aClosure) { delete[] static_cast<uint8_t*>(aClosure); }, mData);
  CheckedInt32 stride = CheckedInt32(mSize.width) * BytesPerPixel(mFormat);
  RefPtr<SourceSurface> src;
  if (!mSize.IsEmpty() && stride.isValid() && stride.value() > 0) {
    src = Factory::CreateWrappingDataSourceSurface(
        mData, stride.value(), mSize, mFormat,
        [](void* aClosure) { delete[] static_cast<uint8_t*>(aClosure); },
        mData);
  }
  if (src) {
    mDataOwned = false;
  }
@@ -3498,18 +3503,23 @@ RecordedSourceSurfaceCreation::RecordedSourceSurfaceCreation(S& aStream)
    return;
  }

  size_t size = 0;
  CheckedInt<size_t> size;
  if (mSize.width >= 0 && mSize.height >= 0) {
    size = size_t(mSize.width) * size_t(mSize.height) * BytesPerPixel(mFormat);
    mData = new (fallible) uint8_t[size];
    CheckedInt32 stride = CheckedInt32(mSize.width) * BytesPerPixel(mFormat);
    if (stride.isValid() && stride.value() >= 0) {
      size = CheckedInt<size_t>(stride.value()) * size_t(mSize.height);
      if (size.isValid()) {
        mData = new (fallible) uint8_t[size.value()];
      }
    }
  }
  if (!mData) {
    gfxCriticalNote
        << "RecordedSourceSurfaceCreation failed to allocate data of size "
        << size;
        << (size.isValid() ? size.value() : 0);
    aStream.SetIsBad();
  } else {
    aStream.read((char*)mData, size);
    aStream.read((char*)mData, size.value());
  }
}

+8 −2
Original line number Diff line number Diff line
@@ -131,12 +131,18 @@ bool SourceSurfaceSkia::InitFromImage(const sk_sp<SkImage>& aImage,
        aFormat != SurfaceFormat::UNKNOWN
            ? aFormat
            : SkiaColorTypeToGfxFormat(pixmap.colorType(), pixmap.alphaType());
    if (pixmap.info().bytesPerPixel() != BytesPerPixel(mFormat)) {
      return false;
    }
    mStride = pixmap.rowBytes();
  } else if (aFormat != SurfaceFormat::UNKNOWN) {
    mFormat = aFormat;
    SkImageInfo info = MakeSkiaImageInfo(mSize, mFormat);
    const SkImageInfo& info = aImage->imageInfo();
    if (info.bytesPerPixel() != BytesPerPixel(mFormat)) {
      return false;
    }
    mStride = GetAlignedStride<4>(info.width(), info.bytesPerPixel());
    if (!mStride) {
    if (mStride <= 0 || size_t(mStride) < info.minRowBytes64()) {
      return false;
    }
  } else {