Commit 9e61c44d authored by Matt Woodrow's avatar Matt Woodrow
Browse files

Bug 1724839 - Snap transforms for video/canvas painting in the same way that...

Bug 1724839 - Snap transforms for video/canvas painting in the same way that Layer rendering did. r=jrmuizel

This takes the logic used for Image/CanvasLayer::ComputeEffectiveTransforms and uses it to get matching rendering for the Paint path.

Depends on D122175

Differential Revision: https://phabricator.services.mozilla.com/D122176
parent 47d3ec0f
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -336,15 +336,20 @@ class nsDisplayCanvas final : public nsPaintedDisplayItem {
                       destGFXRect.Height() / canvasSizeInPx.height);
    gfxContextMatrixAutoSaveRestore saveMatrix(aCtx);

    aCtx->SetMatrix(
        gfxUtils::SnapTransformTranslation(aCtx->CurrentMatrix(), nullptr));

    if (RefPtr<layers::Image> image = canvas->GetAsImage()) {
      RefPtr<gfx::SourceSurface> surface = image->GetAsSourceSurface();
      if (!surface || !surface->IsValid()) {
        return;
      }
      gfx::IntSize size = surface->GetSize();

      transform = gfxUtils::SnapTransform(
          transform, gfxRect(0, 0, size.width, size.height), nullptr);
      aCtx->Multiply(transform);

      gfx::IntSize size = surface->GetSize();
      aCtx->GetDrawTarget()->FillRect(
          Rect(0, 0, size.width, size.height),
          SurfacePattern(surface, ExtendMode::CLAMP, Matrix(),
@@ -361,6 +366,10 @@ class nsDisplayCanvas final : public nsPaintedDisplayItem {
    if (!snapshot) return;
    const auto& surface = snapshot->mSurf;

    transform = gfxUtils::SnapTransform(
        transform, gfxRect(0, 0, canvasSizeInPx.width, canvasSizeInPx.height),
        nullptr);

    if (!renderer->YIsDown()) {
      // y-flip
      transform.PreTranslate(0.0f, canvasSizeInPx.height).PreScale(1.0f, -1.0f);
+5 −0
Original line number Diff line number Diff line
@@ -734,6 +734,11 @@ class nsDisplayVideo : public nsPaintedDisplayItem {
                       scaleToSize.height / size.Height());

    gfxContextMatrixAutoSaveRestore saveMatrix(aCtx);
    aCtx->SetMatrix(
        gfxUtils::SnapTransformTranslation(aCtx->CurrentMatrix(), nullptr));

    transform = gfxUtils::SnapTransform(
        transform, gfxRect(0, 0, size.width, size.height), nullptr);
    aCtx->Multiply(ThebesMatrix(transform));

    aCtx->GetDrawTarget()->FillRect(