diff --git a/gfx/webrender_bindings/DCLayerTree.cpp b/gfx/webrender_bindings/DCLayerTree.cpp index 0c8e08eff27f..eec9cec0cbe3 100644 --- a/gfx/webrender_bindings/DCLayerTree.cpp +++ b/gfx/webrender_bindings/DCLayerTree.cpp @@ -566,7 +566,7 @@ void DCLayerTree::AddSurface(wr::NativeSurfaceId aId, auto* surfaceSc = surface->AsDCSurfaceSwapChain(); if (surfaceSc) { - const auto presentationTransform = surfaceSc->EnsurePresented(transform); + const auto presentationTransform = surfaceSc->EnsurePresented(transform, aImageRendering); if (presentationTransform) { transform = *presentationTransform; } // else EnsurePresented failed, just limp along? @@ -1118,7 +1118,8 @@ static CspaceTransformPlan ChooseCspaceTransformPlan( // - Maybe DCSurfaceSwapChain::EnsurePresented( - const gfx::Matrix& aTransform) { + const gfx::Matrix& aTransform, + const wr::ImageRendering aRendering) { MOZ_RELEASE_ASSERT(mSrc); const auto& srcSize = mSrc->size; @@ -1160,6 +1161,10 @@ Maybe DCSurfaceSwapChain::EnsurePresented( mDest = Nothing(); } + if (mDest && mDest->rendering.value() != aRendering) { + mDest->needsPresent = true; + } + // - // Ok, we have some options: @@ -1241,6 +1246,7 @@ Maybe DCSurfaceSwapChain::EnsurePresented( MOZ_ASSERT(mDest->dest); mVisual->SetContent(mDest->dest->swapChain); } + mDest->rendering = Some(aRendering); if (!CallBlit()) { RenderThread::Get()->NotifyWebRenderError( @@ -1518,6 +1524,12 @@ bool DCSurfaceSwapChain::CallBlitHelper() const { return ret; }; + const auto filter = ToGlTexFilter(mDest->rendering.value()); + const auto SetRenderingTexFilter = [&](const GLenum texTarget) { + gl->fTexParameteri(texTarget, LOCAL_GL_TEXTURE_MAG_FILTER, filter); + gl->fTexParameteri(texTarget, LOCAL_GL_TEXTURE_MIN_FILTER, filter); + }; + // - // Bind LUT @@ -1546,6 +1558,7 @@ bool DCSurfaceSwapChain::CallBlitHelper() const { gl->fActiveTexture(LOCAL_GL_TEXTURE0 + 0); gl->fBindTexture(LOCAL_GL_TEXTURE_EXTERNAL, image0.handle); + SetRenderingTexFilter(LOCAL_GL_TEXTURE_EXTERNAL); // - // Bind swapchain RT @@ -1608,6 +1621,7 @@ bool DCSurfaceSwapChain::CallBlitHelper() const { gl->fActiveTexture(LOCAL_GL_TEXTURE0 + 1); gl->fBindTexture(LOCAL_GL_TEXTURE_EXTERNAL, image1.handle); + SetRenderingTexFilter(LOCAL_GL_TEXTURE_EXTERNAL); yuvArgs = Some(gl::DrawBlitProg::YUVArgs{texCoordMat1, {}}); fragSample = gl::kFragSample_TwoPlane; diff --git a/gfx/webrender_bindings/DCLayerTree.h b/gfx/webrender_bindings/DCLayerTree.h index 632643968883..8f1c87cbbaaa 100644 --- a/gfx/webrender_bindings/DCLayerTree.h +++ b/gfx/webrender_bindings/DCLayerTree.h @@ -320,7 +320,7 @@ class DCSurfaceSwapChain : public DCSurface { DCSurfaceSwapChain(bool aIsOpaque, DCLayerTree* aDCLayerTree); void AttachExternalImage(wr::ExternalImageId aExternalImage); - Maybe EnsurePresented(const gfx::Matrix&); + Maybe EnsurePresented(const gfx::Matrix&, wr::ImageRendering); DCSurfaceSwapChain* AsDCSurfaceSwapChain() override { return this; } @@ -343,6 +343,7 @@ class DCSurfaceSwapChain : public DCSurface { DXGI_COLOR_SPACE_TYPE space; }; struct PlanAndDest final { + Maybe rendering; CspaceAndRange srcSpace; CspaceTransformPlan plan; Maybe dest; diff --git a/gfx/webrender_bindings/RenderTextureHost.cpp b/gfx/webrender_bindings/RenderTextureHost.cpp index d6e00606010f..d2a97e73cc8f 100644 --- a/gfx/webrender_bindings/RenderTextureHost.cpp +++ b/gfx/webrender_bindings/RenderTextureHost.cpp @@ -12,19 +12,27 @@ namespace mozilla { namespace wr { +GLenum ToGlTexFilter(const wr::ImageRendering aRendering) { + switch (aRendering) { + case wr::ImageRendering::Auto: + case wr::ImageRendering::CrispEdges: + return LOCAL_GL_LINEAR; + case wr::ImageRendering::Pixelated: + return LOCAL_GL_NEAREST; + case wr::ImageRendering::Sentinel: + break; + } + MOZ_CRASH("Bad wr::ImageRendering"); +} + void ActivateBindAndTexParameteri(gl::GLContext* aGL, GLenum aActiveTexture, GLenum aBindTarget, GLuint aBindTexture, wr::ImageRendering aRendering) { aGL->fActiveTexture(aActiveTexture); aGL->fBindTexture(aBindTarget, aBindTexture); - aGL->fTexParameteri(aBindTarget, LOCAL_GL_TEXTURE_MIN_FILTER, - aRendering == wr::ImageRendering::Pixelated - ? LOCAL_GL_NEAREST - : LOCAL_GL_LINEAR); - aGL->fTexParameteri(aBindTarget, LOCAL_GL_TEXTURE_MAG_FILTER, - aRendering == wr::ImageRendering::Pixelated - ? LOCAL_GL_NEAREST - : LOCAL_GL_LINEAR); + const auto filter = ToGlTexFilter(aRendering); + aGL->fTexParameteri(aBindTarget, LOCAL_GL_TEXTURE_MIN_FILTER, filter); + aGL->fTexParameteri(aBindTarget, LOCAL_GL_TEXTURE_MAG_FILTER, filter); } RenderTextureHost::RenderTextureHost() diff --git a/gfx/webrender_bindings/RenderTextureHost.h b/gfx/webrender_bindings/RenderTextureHost.h index dacbbc22cdb2..b0f93554fc89 100644 --- a/gfx/webrender_bindings/RenderTextureHost.h +++ b/gfx/webrender_bindings/RenderTextureHost.h @@ -32,6 +32,8 @@ class RenderMacIOSurfaceTextureHost; class RenderBufferTextureHost; class RenderTextureHostSWGL; +GLenum ToGlTexFilter(wr::ImageRendering); + void ActivateBindAndTexParameteri(gl::GLContext* aGL, GLenum aActiveTexture, GLenum aBindTarget, GLuint aBindTexture, wr::ImageRendering aRendering);