summaryrefslogtreecommitdiffstats
path: root/dom/plugins/ipc/D3D11SurfaceHolder.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/plugins/ipc/D3D11SurfaceHolder.cpp
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/plugins/ipc/D3D11SurfaceHolder.cpp')
-rw-r--r--dom/plugins/ipc/D3D11SurfaceHolder.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/dom/plugins/ipc/D3D11SurfaceHolder.cpp b/dom/plugins/ipc/D3D11SurfaceHolder.cpp
new file mode 100644
index 0000000000..429f3be673
--- /dev/null
+++ b/dom/plugins/ipc/D3D11SurfaceHolder.cpp
@@ -0,0 +1,81 @@
+/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "nsDebug.h"
+#include "D3D11SurfaceHolder.h"
+#include "mozilla/gfx/2D.h"
+#include "mozilla/gfx/DeviceManagerDx.h"
+#include "mozilla/layers/TextureD3D11.h"
+#include <d3d11.h>
+
+namespace mozilla {
+namespace plugins {
+
+using namespace mozilla::gfx;
+using namespace mozilla::layers;
+
+D3D11SurfaceHolder::D3D11SurfaceHolder(ID3D11Texture2D* back,
+ SurfaceFormat format,
+ const IntSize& size)
+ : mDevice11(DeviceManagerDx::Get()->GetContentDevice()),
+ mBack(back),
+ mFormat(format),
+ mSize(size) {}
+
+D3D11SurfaceHolder::~D3D11SurfaceHolder() {}
+
+bool D3D11SurfaceHolder::IsValid() {
+ // If a TDR occurred, platform devices will be recreated.
+ if (DeviceManagerDx::Get()->GetContentDevice() != mDevice11) {
+ return false;
+ }
+ return true;
+}
+
+bool D3D11SurfaceHolder::CopyToTextureClient(TextureClient* aClient) {
+ MOZ_ASSERT(NS_IsMainThread());
+
+ D3D11TextureData* data = aClient->GetInternalData()->AsD3D11TextureData();
+ if (!data) {
+ // We don't support this yet. We expect to have a D3D11 compositor, and
+ // therefore D3D11 surfaces.
+ NS_WARNING("Plugin DXGI surface has unsupported TextureClient");
+ return false;
+ }
+
+ RefPtr<ID3D11DeviceContext> context;
+ mDevice11->GetImmediateContext(getter_AddRefs(context));
+ if (!context) {
+ NS_WARNING("Could not get an immediate D3D11 context");
+ return false;
+ }
+
+ TextureClientAutoLock autoLock(aClient, OpenMode::OPEN_WRITE_ONLY);
+ if (!autoLock.Succeeded()) {
+ return false;
+ }
+
+ RefPtr<IDXGIKeyedMutex> mutex;
+ HRESULT hr = mBack->QueryInterface(__uuidof(IDXGIKeyedMutex),
+ (void**)getter_AddRefs(mutex));
+ if (FAILED(hr) || !mutex) {
+ NS_WARNING("Could not acquire an IDXGIKeyedMutex");
+ return false;
+ }
+
+ {
+ AutoTextureLock lock(mutex, hr);
+ if (hr == WAIT_ABANDONED || hr == WAIT_TIMEOUT || FAILED(hr)) {
+ NS_WARNING(
+ "Could not acquire DXGI surface lock - plugin forgot to release?");
+ return false;
+ }
+
+ context->CopyResource(data->GetD3D11Texture(), mBack);
+ }
+ return true;
+}
+
+} // namespace plugins
+} // namespace mozilla