summaryrefslogtreecommitdiffstats
path: root/gfx/layers/DcompSurfaceImage.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /gfx/layers/DcompSurfaceImage.h
parentInitial commit. (diff)
downloadfirefox-e51783d008170d9ab27d25da98ca3a38b0a41b67.tar.xz
firefox-e51783d008170d9ab27d25da98ca3a38b0a41b67.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/layers/DcompSurfaceImage.h')
-rw-r--r--gfx/layers/DcompSurfaceImage.h131
1 files changed, 131 insertions, 0 deletions
diff --git a/gfx/layers/DcompSurfaceImage.h b/gfx/layers/DcompSurfaceImage.h
new file mode 100644
index 0000000000..c1eb412580
--- /dev/null
+++ b/gfx/layers/DcompSurfaceImage.h
@@ -0,0 +1,131 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#ifndef GFX_LAYER_DCOMP_SURFACE_IMAGE_H
+#define GFX_LAYER_DCOMP_SURFACE_IMAGE_H
+
+#include "ImageContainer.h"
+#include "mozilla/layers/TextureClient.h"
+#include "mozilla/layers/TextureHost.h"
+
+namespace mozilla::wr {
+class DisplayListBuilder;
+class TransactionBuilder;
+} // namespace mozilla::wr
+
+namespace mozilla::layers {
+
+already_AddRefed<TextureHost> CreateTextureHostDcompSurface(
+ const SurfaceDescriptor& aDesc, ISurfaceAllocator* aDeallocator,
+ LayersBackend aBackend, TextureFlags aFlags);
+
+/**
+ * A texture data wrapping a dcomp surface handle, which is provided by the
+ * media foundation media engine. We won't be able to control real texture data
+ * because that is protected by the media engine.
+ */
+class DcompSurfaceTexture final : public TextureData {
+ public:
+ static already_AddRefed<TextureClient> CreateTextureClient(
+ HANDLE aHandle, gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
+ KnowsCompositor* aKnowsCompositor);
+
+ ~DcompSurfaceTexture();
+
+ bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
+ void GetSubDescriptor(RemoteDecoderVideoSubDescriptor* aOutDesc) override;
+ void FillInfo(TextureData::Info& aInfo) const {
+ aInfo.size = mSize;
+ aInfo.supportsMoz2D = false;
+ aInfo.canExposeMappedData = false;
+ aInfo.hasSynchronization = false;
+ }
+ bool Lock(OpenMode) override { return true; }
+ void Unlock() override {}
+ void Deallocate(LayersIPCChannel* aAllocator) override {}
+
+ private:
+ DcompSurfaceTexture(HANDLE aHandle, gfx::IntSize aSize,
+ gfx::SurfaceFormat aFormat)
+ : mHandle(aHandle), mSize(aSize), mFormat(aFormat) {}
+
+ const HANDLE mHandle;
+ const gfx::IntSize mSize;
+ const gfx::SurfaceFormat mFormat;
+};
+
+/**
+ * A image data which holds a dcomp texture which is provided by the media
+ * foundation media engine. As the real texture is protected, it does not
+ * support being accessed as a source surface.
+ */
+class DcompSurfaceImage : public Image {
+ public:
+ DcompSurfaceImage(HANDLE aHandle, gfx::IntSize aSize,
+ gfx::SurfaceFormat aFormat,
+ KnowsCompositor* aKnowsCompositor);
+ virtual ~DcompSurfaceImage() = default;
+
+ already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override {
+ return nullptr;
+ }
+
+ gfx::IntSize GetSize() const { return mTextureClient->GetSize(); };
+
+ TextureClient* GetTextureClient(KnowsCompositor* aKnowsCompositor) override;
+
+ private:
+ RefPtr<TextureClient> mTextureClient;
+};
+
+/**
+ * A Texture host living in GPU process which owns a dcomp surface handle which
+ * is provided by the media foundation media engine.
+ */
+class DcompSurfaceHandleHost : public TextureHost {
+ public:
+ DcompSurfaceHandleHost(TextureFlags aFlags,
+ const SurfaceDescriptorDcompSurface& aDescriptor);
+
+ gfx::SurfaceFormat GetFormat() const override { return mFormat; }
+
+ gfx::IntSize GetSize() const override { return mSize; }
+
+ const char* Name() override { return "DcompSurfaceHandleHost"; }
+
+ already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override {
+ return nullptr;
+ }
+
+ void CreateRenderTexture(
+ const wr::ExternalImageId& aExternalImageId) override;
+
+ void PushResourceUpdates(
+ wr::TransactionBuilder& aResources, ResourceUpdateOp aOp,
+ const Range<wr::ImageKey>& aImageKeys,
+ const wr::ExternalImageId& aExternalImageId) override;
+
+ void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
+ const wr::LayoutRect& aBounds,
+ const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
+ const Range<wr::ImageKey>& aImageKeys,
+ PushDisplayItemFlagSet aFlags) override;
+
+ bool SupportsExternalCompositing(WebRenderBackend aBackend) override {
+ return true;
+ }
+
+ protected:
+ ~DcompSurfaceHandleHost();
+
+ // Handle will be closed automatically when `UniqueFileHandle` gets destroyed.
+ const mozilla::UniqueFileHandle mHandle;
+ const gfx::IntSize mSize;
+ const gfx::SurfaceFormat mFormat;
+};
+
+} // namespace mozilla::layers
+
+#endif // GFX_LAYER_DCOMP_SURFACE_IMAGE_H