From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- gfx/layers/d3d11/GpuProcessD3D11TextureMap.h | 116 +++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 gfx/layers/d3d11/GpuProcessD3D11TextureMap.h (limited to 'gfx/layers/d3d11/GpuProcessD3D11TextureMap.h') diff --git a/gfx/layers/d3d11/GpuProcessD3D11TextureMap.h b/gfx/layers/d3d11/GpuProcessD3D11TextureMap.h new file mode 100644 index 0000000000..6c348aa4d2 --- /dev/null +++ b/gfx/layers/d3d11/GpuProcessD3D11TextureMap.h @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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 MOZILLA_GFX_GpuProcessD3D11TextureMap_H +#define MOZILLA_GFX_GpuProcessD3D11TextureMap_H + +#include +#include +#include + +#include "mozilla/gfx/2D.h" +#include "mozilla/layers/LayersTypes.h" +#include "mozilla/layers/TextureHost.h" +#include "mozilla/Maybe.h" +#include "mozilla/StaticPtr.h" + +namespace mozilla { +namespace layers { + +class IMFSampleUsageInfo; +class TextureWrapperD3D11Allocator; + +/** + * A class to manage ID3D11Texture2Ds that is shared without using shared handle + * in GPU process. On some GPUs, ID3D11Texture2Ds of hardware decoded video + * frames with zero video frame copy could not use shared handle. + */ +class GpuProcessD3D11TextureMap { + struct UpdatingTextureHolder; + + public: + static void Init(); + static void Shutdown(); + static GpuProcessD3D11TextureMap* Get() { return sInstance; } + static GpuProcessTextureId GetNextTextureId(); + + GpuProcessD3D11TextureMap(); + ~GpuProcessD3D11TextureMap(); + + void Register(GpuProcessTextureId aTextureId, ID3D11Texture2D* aTexture, + uint32_t aArrayIndex, const gfx::IntSize& aSize, + RefPtr aUsageInfo); + void Register(const MonitorAutoLock& aProofOfLock, + GpuProcessTextureId aTextureId, ID3D11Texture2D* aTexture, + uint32_t aArrayIndex, const gfx::IntSize& aSize, + RefPtr aUsageInfo); + void Unregister(GpuProcessTextureId aTextureId); + + RefPtr GetTexture(GpuProcessTextureId aTextureId); + Maybe GetSharedHandleOfCopiedTexture(GpuProcessTextureId aTextureId); + + size_t GetWaitingTextureCount() const; + + bool WaitTextureReady(const GpuProcessTextureId aTextureId); + + void PostUpdateTextureDataTask(const GpuProcessTextureId aTextureId, + TextureHost* aTextureHost, + TextureHost* aWrappedTextureHost, + TextureWrapperD3D11Allocator* aAllocator); + + void HandleInTextureUpdateThread(); + + private: + struct TextureHolder { + TextureHolder(ID3D11Texture2D* aTexture, uint32_t aArrayIndex, + const gfx::IntSize& aSize, + RefPtr aUsageInfo); + TextureHolder() = default; + + RefPtr mTexture; + uint32_t mArrayIndex = 0; + gfx::IntSize mSize; + RefPtr mIMFSampleUsageInfo; + RefPtr mCopiedTexture; + RefPtr mCopiedTextureSharedHandle; + }; + + struct UpdatingTextureHolder { + UpdatingTextureHolder(const GpuProcessTextureId aTextureId, + TextureHost* aTextureHost, + TextureHost* aWrappedTextureHost, + TextureWrapperD3D11Allocator* aAllocator); + + ~UpdatingTextureHolder(); + + const GpuProcessTextureId mTextureId; + RefPtr mTextureHost; + CompositableTextureHostRef mWrappedTextureHost; + RefPtr mAllocator; + }; + + enum class UpdatingStatus { Waiting, Updating, Error }; + + RefPtr UpdateTextureData(UpdatingTextureHolder* aHolder); + + mutable Monitor mMonitor MOZ_UNANNOTATED; + + std::unordered_map + mD3D11TexturesById; + + std::deque> mWaitingTextureQueue; + + std::unordered_set + mWaitingTextures; + + static StaticAutoPtr sInstance; +}; + +} // namespace layers +} // namespace mozilla + +#endif /* MOZILLA_GFX_GpuProcessD3D11TextureMap_H */ -- cgit v1.2.3