mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1811170 - Make GpuProcessTextureId strongly-typed r=gfx-reviewers,lsalzman
uint64_t is used for GpuProcessTextureId. It should be strongly-typed. Differential Revision: https://phabricator.services.mozilla.com/D167224
This commit is contained in:
parent
55482f1a14
commit
0bb743f94a
@ -69,5 +69,16 @@ RemoteTextureOwnerId RemoteTextureOwnerId::GetNext() {
|
||||
return RemoteTextureOwnerId{++sCounter};
|
||||
}
|
||||
|
||||
/* static */
|
||||
GpuProcessTextureId GpuProcessTextureId::GetNext() {
|
||||
if (!XRE_IsGPUProcess()) {
|
||||
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
||||
return GpuProcessTextureId{};
|
||||
}
|
||||
|
||||
static std::atomic<uint64_t> sCounter = 0;
|
||||
return GpuProcessTextureId{++sCounter};
|
||||
}
|
||||
|
||||
} // namespace layers
|
||||
} // namespace mozilla
|
||||
|
@ -410,6 +410,36 @@ struct RemoteTextureOwnerId {
|
||||
};
|
||||
};
|
||||
|
||||
// TextureId allocated in GPU process
|
||||
struct GpuProcessTextureId {
|
||||
uint64_t mId = 0;
|
||||
|
||||
static GpuProcessTextureId GetNext();
|
||||
|
||||
bool IsValid() const { return mId != 0; }
|
||||
|
||||
// Allow explicit cast to a uint64_t for now
|
||||
explicit operator uint64_t() const { return mId; }
|
||||
|
||||
bool operator==(const GpuProcessTextureId& aOther) const {
|
||||
return mId == aOther.mId;
|
||||
}
|
||||
|
||||
bool operator!=(const GpuProcessTextureId& aOther) const {
|
||||
return !(*this == aOther);
|
||||
}
|
||||
|
||||
// Helper struct that allow this class to be used as a key in
|
||||
// std::unordered_map like so:
|
||||
// std::unordered_map<GpuProcessTextureId, ValueType,
|
||||
// GpuProcessTextureId::HashFn> myMap;
|
||||
struct HashFn {
|
||||
std::size_t operator()(const GpuProcessTextureId aKey) const {
|
||||
return std::hash<uint64_t>{}(aKey.mId);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
MOZ_DEFINE_ENUM_CLASS_WITH_BASE(ScrollDirection, uint8_t, (
|
||||
eVertical,
|
||||
|
@ -1797,12 +1797,9 @@ void GpuProcessD3D11TextureMap::Shutdown() {
|
||||
}
|
||||
|
||||
/* static */
|
||||
uint64_t GpuProcessD3D11TextureMap::GetNextTextureId() {
|
||||
GpuProcessTextureId GpuProcessD3D11TextureMap::GetNextTextureId() {
|
||||
MOZ_ASSERT(XRE_IsGPUProcess());
|
||||
|
||||
static std::atomic<uint64_t> sNextId = 0;
|
||||
uint64_t id = ++sNextId;
|
||||
return id;
|
||||
return GpuProcessTextureId::GetNext();
|
||||
}
|
||||
|
||||
GpuProcessD3D11TextureMap::GpuProcessD3D11TextureMap()
|
||||
@ -1811,8 +1808,9 @@ GpuProcessD3D11TextureMap::GpuProcessD3D11TextureMap()
|
||||
GpuProcessD3D11TextureMap::~GpuProcessD3D11TextureMap() {}
|
||||
|
||||
void GpuProcessD3D11TextureMap::Register(
|
||||
uint64_t aTextureId, ID3D11Texture2D* aTexture, uint32_t aArrayIndex,
|
||||
const gfx::IntSize& aSize, RefPtr<IMFSampleUsageInfo> aUsageInfo) {
|
||||
GpuProcessTextureId aTextureId, ID3D11Texture2D* aTexture,
|
||||
uint32_t aArrayIndex, const gfx::IntSize& aSize,
|
||||
RefPtr<IMFSampleUsageInfo> aUsageInfo) {
|
||||
MOZ_RELEASE_ASSERT(aTexture);
|
||||
MOZ_RELEASE_ASSERT(aUsageInfo);
|
||||
|
||||
@ -1827,7 +1825,7 @@ void GpuProcessD3D11TextureMap::Register(
|
||||
TextureHolder(aTexture, aArrayIndex, aSize, aUsageInfo));
|
||||
}
|
||||
|
||||
void GpuProcessD3D11TextureMap::Unregister(uint64_t aTextureId) {
|
||||
void GpuProcessD3D11TextureMap::Unregister(GpuProcessTextureId aTextureId) {
|
||||
auto textures = mD3D11TexturesById.Lock();
|
||||
|
||||
auto it = textures->find(aTextureId);
|
||||
@ -1838,7 +1836,7 @@ void GpuProcessD3D11TextureMap::Unregister(uint64_t aTextureId) {
|
||||
}
|
||||
|
||||
RefPtr<ID3D11Texture2D> GpuProcessD3D11TextureMap::GetTexture(
|
||||
uint64_t aTextureId) {
|
||||
GpuProcessTextureId aTextureId) {
|
||||
auto textures = mD3D11TexturesById.Lock();
|
||||
|
||||
auto it = textures->find(aTextureId);
|
||||
@ -1850,7 +1848,7 @@ RefPtr<ID3D11Texture2D> GpuProcessD3D11TextureMap::GetTexture(
|
||||
}
|
||||
|
||||
Maybe<HANDLE> GpuProcessD3D11TextureMap::GetSharedHandleOfCopiedTexture(
|
||||
uint64_t aTextureId) {
|
||||
GpuProcessTextureId aTextureId) {
|
||||
TextureHolder holder;
|
||||
{
|
||||
auto textures = mD3D11TexturesById.Lock();
|
||||
|
@ -103,11 +103,13 @@ class D3D11TextureData final : public TextureData {
|
||||
|
||||
TextureFlags GetTextureFlags() const override;
|
||||
|
||||
void SetGpuProcessTextureId(uint64_t aTextureId) {
|
||||
void SetGpuProcessTextureId(GpuProcessTextureId aTextureId) {
|
||||
mGpuProcessTextureId = Some(aTextureId);
|
||||
}
|
||||
|
||||
Maybe<uint64_t> GetGpuProcessTextureId() { return mGpuProcessTextureId; }
|
||||
Maybe<GpuProcessTextureId> GetGpuProcessTextureId() {
|
||||
return mGpuProcessTextureId;
|
||||
}
|
||||
|
||||
private:
|
||||
D3D11TextureData(ID3D11Texture2D* aTexture, uint32_t aArrayIndex,
|
||||
@ -142,7 +144,7 @@ class D3D11TextureData final : public TextureData {
|
||||
const bool mHasSynchronization;
|
||||
|
||||
RefPtr<ID3D11Texture2D> mTexture;
|
||||
Maybe<uint64_t> mGpuProcessTextureId;
|
||||
Maybe<GpuProcessTextureId> mGpuProcessTextureId;
|
||||
uint32_t mArrayIndex = 0;
|
||||
const TextureAllocationFlags mAllocationFlags;
|
||||
};
|
||||
@ -383,7 +385,7 @@ class DXGITextureHostD3D11 : public TextureHost {
|
||||
|
||||
RefPtr<ID3D11Device> mDevice;
|
||||
RefPtr<ID3D11Texture2D> mTexture;
|
||||
Maybe<uint64_t> mGpuProcessTextureId;
|
||||
Maybe<GpuProcessTextureId> mGpuProcessTextureId;
|
||||
uint32_t mArrayIndex = 0;
|
||||
RefPtr<DataTextureSourceD3D11> mTextureSource;
|
||||
gfx::IntSize mSize;
|
||||
@ -606,18 +608,18 @@ class GpuProcessD3D11TextureMap {
|
||||
static void Init();
|
||||
static void Shutdown();
|
||||
static GpuProcessD3D11TextureMap* Get() { return sInstance; }
|
||||
static uint64_t GetNextTextureId();
|
||||
static GpuProcessTextureId GetNextTextureId();
|
||||
|
||||
GpuProcessD3D11TextureMap();
|
||||
~GpuProcessD3D11TextureMap();
|
||||
|
||||
void Register(uint64_t aTextureId, ID3D11Texture2D* aTexture,
|
||||
void Register(GpuProcessTextureId aTextureId, ID3D11Texture2D* aTexture,
|
||||
uint32_t aArrayIndex, const gfx::IntSize& aSize,
|
||||
RefPtr<IMFSampleUsageInfo> aUsageInfo);
|
||||
void Unregister(uint64_t aTextureId);
|
||||
void Unregister(GpuProcessTextureId aTextureId);
|
||||
|
||||
RefPtr<ID3D11Texture2D> GetTexture(uint64_t aTextureId);
|
||||
Maybe<HANDLE> GetSharedHandleOfCopiedTexture(uint64_t aTextureId);
|
||||
RefPtr<ID3D11Texture2D> GetTexture(GpuProcessTextureId aTextureId);
|
||||
Maybe<HANDLE> GetSharedHandleOfCopiedTexture(GpuProcessTextureId aTextureId);
|
||||
|
||||
private:
|
||||
struct TextureHolder {
|
||||
@ -634,7 +636,9 @@ class GpuProcessD3D11TextureMap {
|
||||
Maybe<HANDLE> mCopiedTextureSharedHandle;
|
||||
};
|
||||
|
||||
DataMutex<std::unordered_map<uint64_t, TextureHolder>> mD3D11TexturesById;
|
||||
DataMutex<std::unordered_map<GpuProcessTextureId, TextureHolder,
|
||||
GpuProcessTextureId::HashFn>>
|
||||
mD3D11TexturesById;
|
||||
|
||||
static StaticAutoPtr<GpuProcessD3D11TextureMap> sInstance;
|
||||
};
|
||||
|
@ -234,6 +234,18 @@ struct ParamTraits<mozilla::layers::RemoteTextureOwnerId> {
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::layers::GpuProcessTextureId> {
|
||||
typedef mozilla::layers::GpuProcessTextureId paramType;
|
||||
|
||||
static void Write(MessageWriter* writer, const paramType& param) {
|
||||
WriteParam(writer, param.mId);
|
||||
}
|
||||
static bool Read(MessageReader* reader, paramType* result) {
|
||||
return ReadParam(reader, &result->mId);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::layers::FrameMetrics>
|
||||
: BitfieldHelper<mozilla::layers::FrameMetrics> {
|
||||
|
@ -25,13 +25,14 @@ using gfxImageFormat from "gfxTypes.h";
|
||||
using mozilla::layers::MaybeVideoBridgeSource from "mozilla/layers/VideoBridgeUtils.h";
|
||||
using mozilla::layers::RemoteTextureId from "mozilla/layers/LayersTypes.h";
|
||||
using mozilla::layers::RemoteTextureOwnerId from "mozilla/layers/LayersTypes.h";
|
||||
using mozilla::layers::GpuProcessTextureId from "mozilla/layers/LayersTypes.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
[Comparable] struct SurfaceDescriptorD3D10 {
|
||||
WindowsHandle handle;
|
||||
uint64_t? gpuProcessTextureId;
|
||||
GpuProcessTextureId? gpuProcessTextureId;
|
||||
uint32_t arrayIndex;
|
||||
SurfaceFormat format;
|
||||
IntSize size;
|
||||
|
@ -18,7 +18,8 @@ namespace mozilla {
|
||||
namespace wr {
|
||||
|
||||
RenderDXGITextureHost::RenderDXGITextureHost(
|
||||
WindowsHandle aHandle, Maybe<uint64_t>& aGpuProcessTextureId,
|
||||
WindowsHandle aHandle,
|
||||
Maybe<layers::GpuProcessTextureId>& aGpuProcessTextureId,
|
||||
uint32_t aArrayIndex, gfx::SurfaceFormat aFormat,
|
||||
gfx::ColorSpace2 aColorSpace, gfx::ColorRange aColorRange,
|
||||
gfx::IntSize aSize)
|
||||
|
@ -19,11 +19,11 @@ namespace wr {
|
||||
|
||||
class RenderDXGITextureHost final : public RenderTextureHostSWGL {
|
||||
public:
|
||||
RenderDXGITextureHost(WindowsHandle aHandle,
|
||||
Maybe<uint64_t>& aGpuProcessTextureId,
|
||||
uint32_t aArrayIndex, gfx::SurfaceFormat aFormat,
|
||||
gfx::ColorSpace2, gfx::ColorRange aColorRange,
|
||||
gfx::IntSize aSize);
|
||||
RenderDXGITextureHost(
|
||||
WindowsHandle aHandle,
|
||||
Maybe<layers::GpuProcessTextureId>& aGpuProcessTextureId,
|
||||
uint32_t aArrayIndex, gfx::SurfaceFormat aFormat, gfx::ColorSpace2,
|
||||
gfx::ColorRange aColorRange, gfx::IntSize aSize);
|
||||
|
||||
wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
|
||||
void Unlock() override;
|
||||
@ -90,7 +90,7 @@ class RenderDXGITextureHost final : public RenderTextureHostSWGL {
|
||||
RefPtr<gl::GLContext> mGL;
|
||||
|
||||
WindowsHandle mHandle;
|
||||
Maybe<uint64_t> mGpuProcessTextureId;
|
||||
Maybe<layers::GpuProcessTextureId> mGpuProcessTextureId;
|
||||
RefPtr<ID3D11Texture2D> mTexture;
|
||||
uint32_t mArrayIndex = 0;
|
||||
RefPtr<IDXGIKeyedMutex> mKeyedMutex;
|
||||
|
Loading…
Reference in New Issue
Block a user