summaryrefslogtreecommitdiffstats
path: root/gfx/webrender_bindings
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/webrender_bindings')
-rw-r--r--gfx/webrender_bindings/Cargo.toml2
-rw-r--r--gfx/webrender_bindings/DCLayerTree.cpp255
-rw-r--r--gfx/webrender_bindings/DCLayerTree.h7
-rw-r--r--gfx/webrender_bindings/RenderCompositor.cpp6
-rw-r--r--gfx/webrender_bindings/RenderCompositorNative.cpp8
-rw-r--r--gfx/webrender_bindings/RenderMacIOSurfaceTextureHost.cpp20
-rw-r--r--gfx/webrender_bindings/RenderThread.cpp54
-rw-r--r--gfx/webrender_bindings/RenderThread.h12
-rw-r--r--gfx/webrender_bindings/moz.build2
-rw-r--r--gfx/webrender_bindings/src/bindings.rs8
-rw-r--r--gfx/webrender_bindings/src/lib.rs6
-rw-r--r--gfx/webrender_bindings/src/moz2d_renderer.rs14
12 files changed, 279 insertions, 115 deletions
diff --git a/gfx/webrender_bindings/Cargo.toml b/gfx/webrender_bindings/Cargo.toml
index f6b3fd637f..0f0c069e87 100644
--- a/gfx/webrender_bindings/Cargo.toml
+++ b/gfx/webrender_bindings/Cargo.toml
@@ -33,7 +33,7 @@ features = ["capture", "serialize_program", "gecko", "sw_compositor"]
dwrote = "0.11"
winapi = "0.3"
-[target.'cfg(target_os = "macos")'.dependencies]
+[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
core-foundation = "0.9"
core-graphics = "0.23"
foreign-types = "0.5.0"
diff --git a/gfx/webrender_bindings/DCLayerTree.cpp b/gfx/webrender_bindings/DCLayerTree.cpp
index eee5601182..177979a466 100644
--- a/gfx/webrender_bindings/DCLayerTree.cpp
+++ b/gfx/webrender_bindings/DCLayerTree.cpp
@@ -1178,6 +1178,126 @@ void DCSurfaceVideo::AttachExternalImage(wr::ExternalImageId aExternalImage) {
mRenderTextureHost = texture;
}
+static UINT GetVendorId(ID3D11VideoDevice* const aVideoDevice) {
+ RefPtr<IDXGIDevice> dxgiDevice;
+ RefPtr<IDXGIAdapter> adapter;
+ aVideoDevice->QueryInterface((IDXGIDevice**)getter_AddRefs(dxgiDevice));
+ dxgiDevice->GetAdapter(getter_AddRefs(adapter));
+
+ DXGI_ADAPTER_DESC adapterDesc;
+ adapter->GetDesc(&adapterDesc);
+
+ return adapterDesc.VendorId;
+}
+
+static HRESULT SetNvidiaVpSuperResolution(ID3D11VideoContext* aVideoContext,
+ ID3D11VideoProcessor* aVideoProcessor,
+ bool aEnable) {
+ LOG("SetNvidiaVpSuperResolution() aEnable=%d", aEnable);
+
+ // Undocumented NVIDIA driver constants
+ constexpr GUID nvGUID = {0xD43CE1B3,
+ 0x1F4B,
+ 0x48AC,
+ {0xBA, 0xEE, 0xC3, 0xC2, 0x53, 0x75, 0xE6, 0xF7}};
+
+ constexpr UINT nvExtensionVersion = 0x1;
+ constexpr UINT nvExtensionMethodSuperResolution = 0x2;
+ struct {
+ UINT version;
+ UINT method;
+ UINT enable;
+ } streamExtensionInfo = {nvExtensionVersion, nvExtensionMethodSuperResolution,
+ aEnable ? 1u : 0};
+
+ HRESULT hr;
+ hr = aVideoContext->VideoProcessorSetStreamExtension(
+ aVideoProcessor, 0, &nvGUID, sizeof(streamExtensionInfo),
+ &streamExtensionInfo);
+ return hr;
+}
+
+static HRESULT SetVpSuperResolution(UINT aGpuVendorId,
+ ID3D11VideoContext* aVideoContext,
+ ID3D11VideoProcessor* aVideoProcessor,
+ bool aEnable) {
+ MOZ_ASSERT(aVideoContext);
+ MOZ_ASSERT(aVideoProcessor);
+
+ if (aGpuVendorId == 0x10DE) {
+ return SetNvidiaVpSuperResolution(aVideoContext, aVideoProcessor, aEnable);
+ }
+ return E_NOTIMPL;
+}
+
+static bool GetNvidiaRTXVideoTrueHDRSupported(
+ ID3D11VideoContext* aVideoContext, ID3D11VideoProcessor* aVideoProcessor) {
+ const GUID kNvidiaTrueHDRInterfaceGUID = {
+ 0xfdd62bb4,
+ 0x620b,
+ 0x4fd7,
+ {0x9a, 0xb3, 0x1e, 0x59, 0xd0, 0xd5, 0x44, 0xb3}};
+ UINT available = 0;
+ HRESULT hr = aVideoContext->VideoProcessorGetStreamExtension(
+ aVideoProcessor, 0, &kNvidiaTrueHDRInterfaceGUID, sizeof(available),
+ &available);
+ if (FAILED(hr)) {
+ return false;
+ }
+
+ bool driverSupportsTrueHdr = (available == 1);
+ return driverSupportsTrueHdr;
+}
+
+static HRESULT SetNvidiaRTXVideoTrueHDR(ID3D11VideoContext* aVideoContext,
+ ID3D11VideoProcessor* aVideoProcessor,
+ bool aEnable) {
+ constexpr GUID kNvidiaTrueHDRInterfaceGUID = {
+ 0xfdd62bb4,
+ 0x620b,
+ 0x4fd7,
+ {0x9a, 0xb3, 0x1e, 0x59, 0xd0, 0xd5, 0x44, 0xb3}};
+ constexpr UINT kStreamExtensionMethodTrueHDR = 0x3;
+ const UINT TrueHDRVersion4 = 4;
+ struct {
+ UINT version;
+ UINT method;
+ UINT enable : 1;
+ UINT reserved : 31;
+ } streamExtensionInfo = {TrueHDRVersion4, kStreamExtensionMethodTrueHDR,
+ aEnable ? 1u : 0u, 0u};
+ HRESULT hr = aVideoContext->VideoProcessorSetStreamExtension(
+ aVideoProcessor, 0, &kNvidiaTrueHDRInterfaceGUID,
+ sizeof(streamExtensionInfo), &streamExtensionInfo);
+ return hr;
+}
+
+static bool GetVpAutoHDRSupported(UINT aGpuVendorId,
+ ID3D11VideoContext* aVideoContext,
+ ID3D11VideoProcessor* aVideoProcessor) {
+ MOZ_ASSERT(aVideoContext);
+ MOZ_ASSERT(aVideoProcessor);
+
+ if (aGpuVendorId == 0x10DE) {
+ return GetNvidiaRTXVideoTrueHDRSupported(aVideoContext, aVideoProcessor);
+ }
+ return false;
+}
+
+static HRESULT SetVpAutoHDR(UINT aGpuVendorId,
+ ID3D11VideoContext* aVideoContext,
+ ID3D11VideoProcessor* aVideoProcessor,
+ bool aEnable) {
+ MOZ_ASSERT(aVideoContext);
+ MOZ_ASSERT(aVideoProcessor);
+
+ if (aGpuVendorId == 0x10DE) {
+ return SetNvidiaRTXVideoTrueHDR(aVideoContext, aVideoProcessor, aEnable);
+ }
+ MOZ_ASSERT_UNREACHABLE("Unexpected to be called");
+ return E_NOTIMPL;
+}
+
bool DCSurfaceVideo::CalculateSwapChainSize(gfx::Matrix& aTransform) {
if (!mRenderTextureHost) {
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
@@ -1225,18 +1345,39 @@ bool DCSurfaceVideo::CalculateSwapChainSize(gfx::Matrix& aTransform) {
transform = gfx::Matrix::Translation(aTransform.GetTranslation());
}
- if (!mVideoSwapChain || mSwapChainSize != swapChainSize || mIsDRM != isDRM) {
+ if (!mDCLayerTree->EnsureVideoProcessor(mVideoSize, swapChainSize)) {
+ gfxCriticalNote << "EnsureVideoProcessor Failed";
+ return false;
+ }
+
+ MOZ_ASSERT(mDCLayerTree->GetVideoContext());
+ MOZ_ASSERT(mDCLayerTree->GetVideoProcessor());
+
+ const UINT vendorId = GetVendorId(mDCLayerTree->GetVideoDevice());
+ const bool driverSupportsTrueHDR =
+ GetVpAutoHDRSupported(vendorId, mDCLayerTree->GetVideoContext(),
+ mDCLayerTree->GetVideoProcessor());
+ const bool contentIsHDR = false; // XXX for now, only non-HDR is supported.
+ const bool monitorIsHDR = gfx::DeviceManagerDx::Get()->SystemHDREnabled();
+ const bool powerIsCharging = RenderThread::Get()->GetPowerIsCharging();
+
+ bool useVpAutoHDR = gfx::gfxVars::WebRenderOverlayVpAutoHDR() &&
+ !contentIsHDR && monitorIsHDR && driverSupportsTrueHDR &&
+ powerIsCharging && !mVpAutoHDRFailed;
+
+ if (!mVideoSwapChain || mSwapChainSize != swapChainSize || mIsDRM != isDRM ||
+ mUseVpAutoHDR != useVpAutoHDR) {
needsToPresent = true;
ReleaseDecodeSwapChainResources();
// Update mSwapChainSize before creating SwapChain
mSwapChainSize = swapChainSize;
mIsDRM = isDRM;
- auto swapChainFormat = GetSwapChainFormat();
+ auto swapChainFormat = GetSwapChainFormat(useVpAutoHDR);
bool useYUVSwapChain = IsYUVSwapChainFormat(swapChainFormat);
if (useYUVSwapChain) {
// Tries to create YUV SwapChain
- CreateVideoSwapChain();
+ CreateVideoSwapChain(swapChainFormat);
if (!mVideoSwapChain) {
mFailedYuvSwapChain = true;
ReleaseDecodeSwapChainResources();
@@ -1246,11 +1387,21 @@ bool DCSurfaceVideo::CalculateSwapChainSize(gfx::Matrix& aTransform) {
}
// Tries to create RGB SwapChain
if (!mVideoSwapChain) {
- CreateVideoSwapChain();
+ CreateVideoSwapChain(swapChainFormat);
+ }
+ if (!mVideoSwapChain && useVpAutoHDR) {
+ mVpAutoHDRFailed = true;
+ gfxCriticalNoteOnce << "Failed to create video SwapChain for VpAutoHDR";
+
+ // Disable VpAutoHDR
+ useVpAutoHDR = false;
+ swapChainFormat = GetSwapChainFormat(useVpAutoHDR);
+ CreateVideoSwapChain(swapChainFormat);
}
}
aTransform = transform;
+ mUseVpAutoHDR = useVpAutoHDR;
return needsToPresent;
}
@@ -1270,8 +1421,7 @@ void DCSurfaceVideo::PresentVideo() {
mVisual->SetContent(mVideoSwapChain);
if (!CallVideoProcessorBlt()) {
- auto swapChainFormat = GetSwapChainFormat();
- bool useYUVSwapChain = IsYUVSwapChainFormat(swapChainFormat);
+ bool useYUVSwapChain = IsYUVSwapChainFormat(mSwapChainFormat);
if (useYUVSwapChain) {
mFailedYuvSwapChain = true;
ReleaseDecodeSwapChainResources();
@@ -1392,14 +1542,17 @@ void DCSurfaceVideo::PresentVideo() {
}
}
-DXGI_FORMAT DCSurfaceVideo::GetSwapChainFormat() {
+DXGI_FORMAT DCSurfaceVideo::GetSwapChainFormat(bool aUseVpAutoHDR) {
+ if (aUseVpAutoHDR) {
+ return DXGI_FORMAT_R16G16B16A16_FLOAT;
+ }
if (mFailedYuvSwapChain || !mDCLayerTree->SupportsHardwareOverlays()) {
return DXGI_FORMAT_B8G8R8A8_UNORM;
}
return mDCLayerTree->GetOverlayFormatForSDR();
}
-bool DCSurfaceVideo::CreateVideoSwapChain() {
+bool DCSurfaceVideo::CreateVideoSwapChain(DXGI_FORMAT aSwapChainFormat) {
MOZ_ASSERT(mRenderTextureHost);
mFirstPresent = true;
@@ -1423,12 +1576,10 @@ bool DCSurfaceVideo::CreateVideoSwapChain() {
return false;
}
- auto swapChainFormat = GetSwapChainFormat();
-
DXGI_SWAP_CHAIN_DESC1 desc = {};
desc.Width = mSwapChainSize.width;
desc.Height = mSwapChainSize.height;
- desc.Format = swapChainFormat;
+ desc.Format = aSwapChainFormat;
desc.Stereo = FALSE;
desc.SampleDesc.Count = 1;
desc.BufferCount = mSwapChainBufferCount;
@@ -1436,7 +1587,7 @@ bool DCSurfaceVideo::CreateVideoSwapChain() {
desc.Scaling = DXGI_SCALING_STRETCH;
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
desc.Flags = DXGI_SWAP_CHAIN_FLAG_FULLSCREEN_VIDEO;
- if (IsYUVSwapChainFormat(swapChainFormat)) {
+ if (IsYUVSwapChainFormat(aSwapChainFormat)) {
desc.Flags |= DXGI_SWAP_CHAIN_FLAG_YUV_VIDEO;
}
if (mIsDRM) {
@@ -1455,7 +1606,7 @@ bool DCSurfaceVideo::CreateVideoSwapChain() {
return false;
}
- mSwapChainFormat = swapChainFormat;
+ mSwapChainFormat = aSwapChainFormat;
return true;
}
@@ -1494,50 +1645,6 @@ static Maybe<DXGI_COLOR_SPACE_TYPE> GetSourceDXGIColorSpace(
return GetSourceDXGIColorSpace(info.space, info.range);
}
-static void SetNvidiaVideoSuperRes(ID3D11VideoContext* videoContext,
- ID3D11VideoProcessor* videoProcessor,
- bool enabled) {
- LOG("SetNvidiaVideoSuperRes() enabled=%d", enabled);
-
- // Undocumented NVIDIA driver constants
- constexpr GUID nvGUID = {0xD43CE1B3,
- 0x1F4B,
- 0x48AC,
- {0xBA, 0xEE, 0xC3, 0xC2, 0x53, 0x75, 0xE6, 0xF7}};
-
- constexpr UINT nvExtensionVersion = 0x1;
- constexpr UINT nvExtensionMethodSuperResolution = 0x2;
- struct {
- UINT version;
- UINT method;
- UINT enable;
- } streamExtensionInfo = {nvExtensionVersion, nvExtensionMethodSuperResolution,
- enabled ? 1u : 0};
-
- HRESULT hr;
- hr = videoContext->VideoProcessorSetStreamExtension(
- videoProcessor, 0, &nvGUID, sizeof(streamExtensionInfo),
- &streamExtensionInfo);
-
- // Ignore errors as could be unsupported
- if (FAILED(hr)) {
- LOG("SetNvidiaVideoSuperRes() error: %lx", hr);
- return;
- }
-}
-
-static UINT GetVendorId(ID3D11VideoDevice* const videoDevice) {
- RefPtr<IDXGIDevice> dxgiDevice;
- RefPtr<IDXGIAdapter> adapter;
- videoDevice->QueryInterface((IDXGIDevice**)getter_AddRefs(dxgiDevice));
- dxgiDevice->GetAdapter(getter_AddRefs(adapter));
-
- DXGI_ADAPTER_DESC adapterDesc;
- adapter->GetDesc(&adapterDesc);
-
- return adapterDesc.VendorId;
-}
-
bool DCSurfaceVideo::CallVideoProcessorBlt() {
MOZ_ASSERT(mRenderTextureHost);
@@ -1576,11 +1683,6 @@ bool DCSurfaceVideo::CallVideoProcessorBlt() {
}
}
- if (!mDCLayerTree->EnsureVideoProcessor(mVideoSize, mSwapChainSize)) {
- gfxCriticalNote << "EnsureVideoProcessor Failed";
- return false;
- }
-
RefPtr<IDXGISwapChain3> swapChain3;
mVideoSwapChain->QueryInterface(
(IDXGISwapChain3**)getter_AddRefs(swapChain3));
@@ -1609,6 +1711,13 @@ bool DCSurfaceVideo::CallVideoProcessorBlt() {
IsYUVSwapChainFormat(mSwapChainFormat)
? inputColorSpace
: DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709;
+
+ if (mUseVpAutoHDR) {
+ outputColorSpace = mSwapChainFormat == DXGI_FORMAT_R16G16B16A16_FLOAT
+ ? DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709
+ : DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020;
+ }
+
hr = swapChain3->SetColorSpace1(outputColorSpace);
if (FAILED(hr)) {
gfxCriticalNoteOnce << "SetColorSpace1 failed: " << gfx::hexa(hr);
@@ -1679,9 +1788,24 @@ bool DCSurfaceVideo::CallVideoProcessorBlt() {
}
const UINT vendorId = GetVendorId(videoDevice);
- if (vendorId == 0x10DE &&
- StaticPrefs::gfx_webrender_super_resolution_nvidia_AtStartup()) {
- SetNvidiaVideoSuperRes(videoContext, videoProcessor, true);
+ const auto powerIsCharging = RenderThread::Get()->GetPowerIsCharging();
+ if (gfx::gfxVars::WebRenderOverlayVpSuperResolution() &&
+ !mVpSuperResolutionFailed && powerIsCharging) {
+ hr = SetVpSuperResolution(vendorId, videoContext, videoProcessor, true);
+ if (FAILED(hr)) {
+ if (hr != E_NOTIMPL) {
+ gfxCriticalNoteOnce << "SetVpSuperResolution failed: " << gfx::hexa(hr);
+ }
+ mVpSuperResolutionFailed = true;
+ }
+ }
+
+ if (mUseVpAutoHDR) {
+ hr = SetVpAutoHDR(vendorId, videoContext, videoProcessor, true);
+ if (FAILED(hr)) {
+ gfxCriticalNoteOnce << "SetVpAutoHDR failed: " << gfx::hexa(hr);
+ mVpAutoHDRFailed = true;
+ }
}
hr = videoContext->VideoProcessorBlt(videoProcessor, mOutputView, 0, 1,
@@ -1703,6 +1827,7 @@ void DCSurfaceVideo::ReleaseDecodeSwapChainResources() {
::CloseHandle(mSwapChainSurfaceHandle);
mSwapChainSurfaceHandle = 0;
}
+ mUseVpAutoHDR = false;
}
DCSurfaceHandle::DCSurfaceHandle(bool aIsOpaque, DCLayerTree* aDCLayerTree)
diff --git a/gfx/webrender_bindings/DCLayerTree.h b/gfx/webrender_bindings/DCLayerTree.h
index babd1112fb..6d3a611802 100644
--- a/gfx/webrender_bindings/DCLayerTree.h
+++ b/gfx/webrender_bindings/DCLayerTree.h
@@ -389,8 +389,8 @@ class DCSurfaceVideo : public DCSurface {
protected:
virtual ~DCSurfaceVideo();
- DXGI_FORMAT GetSwapChainFormat();
- bool CreateVideoSwapChain();
+ DXGI_FORMAT GetSwapChainFormat(bool aUseVpAutoHDR);
+ bool CreateVideoSwapChain(DXGI_FORMAT aFormat);
bool CallVideoProcessorBlt();
void ReleaseDecodeSwapChainResources();
@@ -409,6 +409,9 @@ class DCSurfaceVideo : public DCSurface {
int mSlowPresentCount = 0;
bool mFirstPresent = true;
const UINT mSwapChainBufferCount;
+ bool mUseVpAutoHDR = false;
+ bool mVpAutoHDRFailed = false;
+ bool mVpSuperResolutionFailed = false;
};
/**
diff --git a/gfx/webrender_bindings/RenderCompositor.cpp b/gfx/webrender_bindings/RenderCompositor.cpp
index 8dd6e8ff00..1712eca855 100644
--- a/gfx/webrender_bindings/RenderCompositor.cpp
+++ b/gfx/webrender_bindings/RenderCompositor.cpp
@@ -31,7 +31,7 @@
# include "mozilla/webrender/RenderCompositorNative.h"
#endif
-#ifdef XP_MACOSX
+#ifdef XP_DARWIN
# include "mozilla/webrender/RenderCompositorNative.h"
#endif
@@ -168,7 +168,7 @@ void wr_partial_present_compositor_set_buffer_damage_region(
UniquePtr<RenderCompositor> RenderCompositor::Create(
const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError) {
if (aWidget->GetCompositorOptions().UseSoftwareWebRender()) {
-#ifdef XP_MACOSX
+#ifdef XP_DARWIN
// Mac uses NativeLayerCA
if (!gfxPlatform::IsHeadless()) {
return RenderCompositorNativeSWGL::Create(aWidget, aError);
@@ -216,7 +216,7 @@ UniquePtr<RenderCompositor> RenderCompositor::Create(
#if defined(MOZ_WIDGET_ANDROID)
// RenderCompositorOGL is not used on android
return nullptr;
-#elif defined(XP_MACOSX)
+#elif defined(XP_DARWIN)
// Mac uses NativeLayerCA
return RenderCompositorNativeOGL::Create(aWidget, aError);
#else
diff --git a/gfx/webrender_bindings/RenderCompositorNative.cpp b/gfx/webrender_bindings/RenderCompositorNative.cpp
index 81cafd1fd6..3b5a29948e 100644
--- a/gfx/webrender_bindings/RenderCompositorNative.cpp
+++ b/gfx/webrender_bindings/RenderCompositorNative.cpp
@@ -31,7 +31,7 @@ RenderCompositorNative::RenderCompositorNative(
mNativeLayerRoot(GetWidget()->GetNativeLayerRoot()) {
LOG("RenderCompositorNative::RenderCompositorNative()");
-#if defined(XP_MACOSX) || defined(MOZ_WAYLAND)
+#if defined(XP_DARWIN) || defined(MOZ_WAYLAND)
auto pool = RenderThread::Get()->SharedSurfacePool();
if (pool) {
mSurfacePoolHandle = pool->GetHandleForGL(aGL);
@@ -103,7 +103,7 @@ bool RenderCompositorNative::Resume() { return true; }
inline layers::WebRenderCompositor RenderCompositorNative::CompositorType()
const {
if (gfx::gfxVars::UseWebRenderCompositor()) {
-#if defined(XP_MACOSX)
+#if defined(XP_DARWIN)
return layers::WebRenderCompositor::CORE_ANIMATION;
#elif defined(MOZ_WAYLAND)
return layers::WebRenderCompositor::WAYLAND;
@@ -123,7 +123,7 @@ bool RenderCompositorNative::ShouldUseNativeCompositor() {
void RenderCompositorNative::GetCompositorCapabilities(
CompositorCapabilities* aCaps) {
RenderCompositor::GetCompositorCapabilities(aCaps);
-#if defined(XP_MACOSX)
+#if defined(XP_DARWIN)
aCaps->supports_surface_for_backdrop = !gfx::gfxVars::UseSoftwareWebRender();
#endif
}
@@ -509,7 +509,7 @@ void RenderCompositorNativeOGL::DoSwap() {
void RenderCompositorNativeOGL::DoFlush() { mGL->fFlush(); }
void RenderCompositorNativeOGL::InsertFrameDoneSync() {
-#ifdef XP_MACOSX
+#ifdef XP_DARWIN
// Only do this on macOS.
// On other platforms, SwapBuffers automatically applies back-pressure.
if (mThisFrameDoneSync) {
diff --git a/gfx/webrender_bindings/RenderMacIOSurfaceTextureHost.cpp b/gfx/webrender_bindings/RenderMacIOSurfaceTextureHost.cpp
index bb0575949b..c1f93327e5 100644
--- a/gfx/webrender_bindings/RenderMacIOSurfaceTextureHost.cpp
+++ b/gfx/webrender_bindings/RenderMacIOSurfaceTextureHost.cpp
@@ -6,16 +6,20 @@
#include "RenderMacIOSurfaceTextureHost.h"
-#include "GLContextCGL.h"
+#ifdef XP_MACOSX
+# include "GLContextCGL.h"
+#else
+# include "GLContextEAGL.h"
+#endif
+
#include "mozilla/gfx/Logging.h"
#include "ScopedGLHelpers.h"
namespace mozilla {
namespace wr {
-static CGLError CreateTextureForPlane(uint8_t aPlaneID, gl::GLContext* aGL,
- MacIOSurface* aSurface,
- GLuint* aTexture) {
+static bool CreateTextureForPlane(uint8_t aPlaneID, gl::GLContext* aGL,
+ MacIOSurface* aSurface, GLuint* aTexture) {
MOZ_ASSERT(aGL && aSurface && aTexture);
aGL->fGenTextures(1, aTexture);
@@ -26,10 +30,8 @@ static CGLError CreateTextureForPlane(uint8_t aPlaneID, gl::GLContext* aGL,
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S,
LOCAL_GL_CLAMP_TO_EDGE);
- CGLError result = kCGLNoError;
gfx::SurfaceFormat readFormat = gfx::SurfaceFormat::UNKNOWN;
- result = aSurface->CGLTexImageIOSurface2D(
- aGL, gl::GLContextCGL::Cast(aGL)->GetCGLContext(), aPlaneID, &readFormat);
+ bool result = aSurface->BindTexImage(aGL, aPlaneID, &readFormat);
// If this is a yuv format, the Webrender only supports YUV422 interleaving
// format.
MOZ_ASSERT(aSurface->GetFormat() != gfx::SurfaceFormat::YUV422 ||
@@ -89,7 +91,11 @@ wr::WrExternalImage RenderMacIOSurfaceTextureHost::Lock(uint8_t aChannelIndex,
}
if (!mTextureHandles[0]) {
+#ifdef XP_MACOSX
MOZ_ASSERT(gl::GLContextCGL::Cast(mGL.get())->GetCGLContext());
+#else
+ MOZ_ASSERT(gl::GLContextEAGL::Cast(mGL.get())->GetEAGLContext());
+#endif
// The result of GetPlaneCount() is 0 for single plane format, but it will
// be 2 if the format has 2 planar data.
diff --git a/gfx/webrender_bindings/RenderThread.cpp b/gfx/webrender_bindings/RenderThread.cpp
index 89fc339c03..e1a41ee225 100644
--- a/gfx/webrender_bindings/RenderThread.cpp
+++ b/gfx/webrender_bindings/RenderThread.cpp
@@ -70,12 +70,15 @@ static mozilla::BackgroundHangMonitor* sBackgroundHangMonitor;
#ifdef DEBUG
static bool sRenderThreadEverStarted = false;
#endif
+size_t RenderThread::sRendererCount = 0;
+size_t RenderThread::sActiveRendererCount = 0;
RenderThread::RenderThread(RefPtr<nsIThread> aThread)
: mThread(std::move(aThread)),
mThreadPool(false),
mThreadPoolLP(true),
mSingletonGLIsForHardwareWebRender(true),
+ mBatteryInfo("RenderThread.mBatteryInfo"),
mWindowInfos("RenderThread.mWindowInfos"),
mRenderTextureMapLock("RenderThread.mRenderTextureMapLock"),
mHasShutdown(false),
@@ -149,6 +152,11 @@ void RenderThread::Start(uint32_t aNamespace) {
}
sRenderThread = new RenderThread(thread);
+ CrashReporter::RegisterAnnotationUSize(
+ CrashReporter::Annotation::GraphicsNumRenderers, &sRendererCount);
+ CrashReporter::RegisterAnnotationUSize(
+ CrashReporter::Annotation::GraphicsNumActiveRenderers,
+ &sActiveRendererCount);
#ifdef XP_WIN
widget::WinCompositorWindowThread::Start();
#endif
@@ -291,6 +299,26 @@ RefPtr<MemoryReportPromise> RenderThread::AccumulateMemoryReport(
return p;
}
+void RenderThread::SetBatteryInfo(const hal::BatteryInformation& aBatteryInfo) {
+ MOZ_ASSERT(XRE_IsGPUProcess());
+
+ auto batteryInfo = mBatteryInfo.Lock();
+ batteryInfo.ref() = Some(aBatteryInfo);
+}
+
+bool RenderThread::GetPowerIsCharging() {
+ MOZ_ASSERT(XRE_IsGPUProcess());
+
+ auto batteryInfo = mBatteryInfo.Lock();
+ if (batteryInfo.ref().isSome()) {
+ return batteryInfo.ref().ref().charging();
+ }
+
+ gfxCriticalNoteOnce << "BatteryInfo is not set";
+ MOZ_ASSERT_UNREACHABLE("unexpected to be called");
+ return false;
+}
+
void RenderThread::AddRenderer(wr::WindowId aWindowId,
UniquePtr<RendererOGL> aRenderer) {
MOZ_ASSERT(IsInRenderThread());
@@ -301,9 +329,7 @@ void RenderThread::AddRenderer(wr::WindowId aWindowId,
}
mRenderers[aWindowId] = std::move(aRenderer);
- CrashReporter::AnnotateCrashReport(
- CrashReporter::Annotation::GraphicsNumRenderers,
- (unsigned int)mRenderers.size());
+ sRendererCount = mRenderers.size();
auto windows = mWindowInfos.Lock();
windows->emplace(AsUint64(aWindowId), new WindowInfo());
@@ -321,9 +347,7 @@ void RenderThread::RemoveRenderer(wr::WindowId aWindowId) {
}
mRenderers.erase(aWindowId);
- CrashReporter::AnnotateCrashReport(
- CrashReporter::Annotation::GraphicsNumRenderers,
- (unsigned int)mRenderers.size());
+ sRendererCount = mRenderers.size();
if (mRenderers.empty()) {
if (mHandlingDeviceReset) {
@@ -370,7 +394,7 @@ size_t RenderThread::RendererCount() const {
return mRenderers.size();
}
-size_t RenderThread::ActiveRendererCount() const {
+void RenderThread::UpdateActiveRendererCount() {
MOZ_ASSERT(IsInRenderThread());
size_t num_active = 0;
for (const auto& it : mRenderers) {
@@ -378,7 +402,7 @@ size_t RenderThread::ActiveRendererCount() const {
num_active++;
}
}
- return num_active;
+ sActiveRendererCount = num_active;
}
void RenderThread::WrNotifierEvent_WakeUp(WrWindowId aWindowId,
@@ -842,9 +866,7 @@ void RenderThread::Pause(wr::WindowId aWindowId) {
auto& renderer = it->second;
renderer->Pause();
- CrashReporter::AnnotateCrashReport(
- CrashReporter::Annotation::GraphicsNumActiveRenderers,
- (unsigned int)ActiveRendererCount());
+ UpdateActiveRendererCount();
}
bool RenderThread::Resume(wr::WindowId aWindowId) {
@@ -861,9 +883,7 @@ bool RenderThread::Resume(wr::WindowId aWindowId) {
auto& renderer = it->second;
bool resumed = renderer->Resume();
- CrashReporter::AnnotateCrashReport(
- CrashReporter::Annotation::GraphicsNumActiveRenderers,
- (unsigned int)ActiveRendererCount());
+ UpdateActiveRendererCount();
return resumed;
}
@@ -1378,7 +1398,7 @@ RenderThread::GetProgramsForCompositorOGL() {
}
RefPtr<layers::SurfacePool> RenderThread::SharedSurfacePool() {
-#if defined(XP_MACOSX) || defined(MOZ_WAYLAND)
+#if defined(XP_DARWIN) || defined(MOZ_WAYLAND)
if (!mSurfacePool) {
size_t poolSizeLimit =
StaticPrefs::gfx_webrender_compositor_surface_pool_size_AtStartup();
@@ -1555,7 +1575,7 @@ static already_AddRefed<gl::GLContext> CreateGLContextEGL() {
}
#endif
-#ifdef XP_MACOSX
+#ifdef XP_DARWIN
static already_AddRefed<gl::GLContext> CreateGLContextCGL() {
nsCString failureUnused;
return gl::GLContextProvider::CreateHeadless(
@@ -1578,7 +1598,7 @@ static already_AddRefed<gl::GLContext> CreateGLContext(nsACString& aError) {
if (gfx::gfxVars::UseEGL()) {
gl = CreateGLContextEGL();
}
-#elif XP_MACOSX
+#elif XP_DARWIN
gl = CreateGLContextCGL();
#endif
diff --git a/gfx/webrender_bindings/RenderThread.h b/gfx/webrender_bindings/RenderThread.h
index aa508e5581..f9ab1e742e 100644
--- a/gfx/webrender_bindings/RenderThread.h
+++ b/gfx/webrender_bindings/RenderThread.h
@@ -14,6 +14,7 @@
#include "GLTypes.h" // for GLenum
#include "nsISupportsImpl.h"
#include "mozilla/gfx/Point.h"
+#include "mozilla/Hal.h"
#include "mozilla/MozPromise.h"
#include "mozilla/DataMutex.h"
#include "mozilla/Maybe.h"
@@ -292,7 +293,8 @@ class RenderThread final {
bool SyncObjectNeeded();
size_t RendererCount() const;
- size_t ActiveRendererCount() const;
+ size_t ActiveRendererCount() const { return sActiveRendererCount; };
+ void UpdateActiveRendererCount();
void BeginRecordingForWindow(wr::WindowId aWindowId,
const TimeStamp& aRecordingStart,
@@ -302,7 +304,13 @@ class RenderThread final {
static void MaybeEnableGLDebugMessage(gl::GLContext* aGLContext);
+ void SetBatteryInfo(const hal::BatteryInformation& aBatteryInfo);
+ bool GetPowerIsCharging();
+
private:
+ static size_t sRendererCount;
+ static size_t sActiveRendererCount;
+
enum class RenderTextureOp {
PrepareForUse,
NotifyForUse,
@@ -434,6 +442,8 @@ class RenderThread final {
std::map<wr::WindowId, UniquePtr<RendererOGL>> mRenderers;
+ DataMutex<Maybe<hal::BatteryInformation>> mBatteryInfo;
+
struct PendingFrameInfo {
TimeStamp mStartTime;
VsyncId mStartId;
diff --git a/gfx/webrender_bindings/moz.build b/gfx/webrender_bindings/moz.build
index f17c77e4cb..6cca348acb 100644
--- a/gfx/webrender_bindings/moz.build
+++ b/gfx/webrender_bindings/moz.build
@@ -51,7 +51,7 @@ UNIFIED_SOURCES += [
"WebRenderTypes.cpp",
]
-if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
+if CONFIG["MOZ_WIDGET_TOOLKIT"] in ("cocoa", "uikit"):
EXPORTS.mozilla.webrender += [
"RenderCompositorNative.h",
"RenderMacIOSurfaceTextureHost.h",
diff --git a/gfx/webrender_bindings/src/bindings.rs b/gfx/webrender_bindings/src/bindings.rs
index 1f3bca644a..047791c76b 100644
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -7,7 +7,7 @@
use gleam::gl;
use std::cell::RefCell;
-#[cfg(not(target_os = "macos"))]
+#[cfg(not(any(target_os = "macos", target_os = "ios")))]
use std::ffi::OsString;
use std::ffi::{CStr, CString};
use std::io::Cursor;
@@ -16,7 +16,7 @@ use std::ops::Range;
#[cfg(target_os = "android")]
use std::os::raw::c_int;
use std::os::raw::{c_char, c_float, c_void};
-#[cfg(not(any(target_os = "macos", target_os = "windows")))]
+#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))]
use std::os::unix::ffi::OsStringExt;
#[cfg(target_os = "windows")]
use std::os::windows::ffi::OsStringExt;
@@ -2326,7 +2326,7 @@ fn read_font_descriptor(bytes: &mut WrVecU8, index: u32) -> NativeFontHandle {
}
}
-#[cfg(target_os = "macos")]
+#[cfg(any(target_os = "macos", target_os = "ios"))]
fn read_font_descriptor(bytes: &mut WrVecU8, index: u32) -> NativeFontHandle {
// On macOS, the descriptor string is a concatenation of the PostScript name
// and the font file path (to disambiguate cases where there are multiple
@@ -2340,7 +2340,7 @@ fn read_font_descriptor(bytes: &mut WrVecU8, index: u32) -> NativeFontHandle {
}
}
-#[cfg(not(any(target_os = "macos", target_os = "windows")))]
+#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))]
fn read_font_descriptor(bytes: &mut WrVecU8, index: u32) -> NativeFontHandle {
let chars = bytes.flush_into_vec();
NativeFontHandle {
diff --git a/gfx/webrender_bindings/src/lib.rs b/gfx/webrender_bindings/src/lib.rs
index 9e94302e0f..b3c6e6ac56 100644
--- a/gfx/webrender_bindings/src/lib.rs
+++ b/gfx/webrender_bindings/src/lib.rs
@@ -28,11 +28,11 @@ extern crate dwrote;
#[cfg(target_os = "windows")]
extern crate winapi;
-#[cfg(target_os = "macos")]
+#[cfg(any(target_os = "macos", target_os = "ios"))]
extern crate core_foundation;
-#[cfg(target_os = "macos")]
+#[cfg(any(target_os = "macos", target_os = "ios"))]
extern crate core_graphics;
-#[cfg(target_os = "macos")]
+#[cfg(any(target_os = "macos", target_os = "ios"))]
extern crate foreign_types;
mod program_cache;
diff --git a/gfx/webrender_bindings/src/moz2d_renderer.rs b/gfx/webrender_bindings/src/moz2d_renderer.rs
index 4c7a32c912..ca1e76f96f 100644
--- a/gfx/webrender_bindings/src/moz2d_renderer.rs
+++ b/gfx/webrender_bindings/src/moz2d_renderer.rs
@@ -33,16 +33,16 @@ use std::sync::Arc;
#[cfg(target_os = "windows")]
use dwrote;
-#[cfg(target_os = "macos")]
+#[cfg(any(target_os = "macos", target_os = "ios"))]
use core_foundation::string::CFString;
-#[cfg(target_os = "macos")]
+#[cfg(any(target_os = "macos", target_os = "ios"))]
use core_graphics::font::CGFont;
-#[cfg(target_os = "macos")]
+#[cfg(any(target_os = "macos", target_os = "ios"))]
use foreign_types::ForeignType;
-#[cfg(not(any(target_os = "macos", target_os = "windows")))]
+#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))]
use std::ffi::CString;
-#[cfg(not(any(target_os = "macos", target_os = "windows")))]
+#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))]
use std::os::unix::ffi::OsStrExt;
/// Local print-debugging utility
@@ -787,7 +787,7 @@ impl Moz2dBlobImageHandler {
unsafe { AddNativeFontHandle(key, face.as_ptr() as *mut c_void, 0) };
}
- #[cfg(target_os = "macos")]
+ #[cfg(any(target_os = "macos", target_os = "ios"))]
fn process_native_font_handle(key: FontKey, handle: &NativeFontHandle) {
let font = match CGFont::from_name(&CFString::new(&handle.name)) {
Ok(font) => font,
@@ -804,7 +804,7 @@ impl Moz2dBlobImageHandler {
unsafe { AddNativeFontHandle(key, font.as_ptr() as *mut c_void, 0) };
}
- #[cfg(not(any(target_os = "macos", target_os = "windows")))]
+ #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))]
fn process_native_font_handle(key: FontKey, handle: &NativeFontHandle) {
let cstr = CString::new(handle.path.as_os_str().as_bytes()).unwrap();
unsafe { AddNativeFontHandle(key, cstr.as_ptr() as *mut c_void, handle.index) };