0

Remove type field from gfx::GpuFenceHandle

Since owned_fd (and future 'owned' objects) have their own notion of
being null/invalid and are mutually exclusive of one another, there
is no need to keep a separate GpuFenceHandle "type" member variable.

To facilitate empty objects on some platforms, adjust the declaration
of needs_comma to avoid 'variable not used' warnings from the compiler.

Bug: 1131616
Change-Id: I2da1b719ac2770edcbf1f5e9c26b909004925170
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2423164
Reviewed-by: David Reveman <reveman@chromium.org>
Reviewed-by: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: Daniele Castagna <dcastagna@chromium.org>
Reviewed-by: Sunny Sachanandani <sunnyps@chromium.org>
Reviewed-by: Robert Kroeger <rjkroege@chromium.org>
Reviewed-by: Ken Rockot <rockot@google.com>
Reviewed-by: Klaus Weidner <klausw@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#810039}
This commit is contained in:
Rafael Cintron
2020-09-24 01:06:28 +00:00
committed by Commit Bot
parent 56546a55dd
commit 16519e5d58
17 changed files with 40 additions and 139 deletions

@ -96,7 +96,6 @@ void linux_surface_synchronization_set_acquire_fence(wl_client* client,
}
gfx::GpuFenceHandle handle;
handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
handle.owned_fd = std::move(fence_fd);
surface->SetAcquireFence(std::make_unique<gfx::GpuFence>(std::move(handle)));

@ -174,7 +174,6 @@ TEST_F(GpuFenceManagerTest, GetGpuFence) {
EXPECT_TRUE(gpu_fence);
const gfx::GpuFenceHandle& handle = gpu_fence->GetGpuFenceHandle();
EXPECT_EQ(handle.type, gfx::GpuFenceHandleType::kAndroidNativeFenceSync);
EXPECT_EQ(handle.owned_fd.get(), kFenceFD);
// Removing the fence marks it invalid.
@ -194,7 +193,6 @@ TEST_F(GpuFenceManagerTest, Duplication) {
// Create a handle.
gfx::GpuFenceHandle handle;
handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
handle.owned_fd = base::ScopedFD(kFenceFD);
// Create a duplicate fence object from it.

@ -24,9 +24,10 @@
#undef IPC_STRUCT_TRAITS_MEMBER
#undef IPC_STRUCT_TRAITS_PARENT
#undef IPC_STRUCT_TRAITS_END
#define IPC_STRUCT_TRAITS_BEGIN(struct_name) \
#define IPC_STRUCT_TRAITS_BEGIN(struct_name) \
void ParamTraits<struct_name>::Log(const param_type& p, std::string* l) { \
bool needs_comma = false; \
bool needs_comma = false; \
(void)needs_comma; \
l->append("(");
#define IPC_STRUCT_TRAITS_MEMBER(name) \
if (needs_comma) \
@ -39,7 +40,7 @@
ParamTraits<type>::Log(p, l); \
needs_comma = true;
#define IPC_STRUCT_TRAITS_END() \
l->append(")"); \
l->append(")"); \
}
#undef IPC_ENUM_TRAITS_VALIDATE

@ -966,18 +966,6 @@ struct FuzzTraits<gfx::ColorSpace::TransferID> {
template <>
struct FuzzTraits<gfx::GpuFenceHandle> {
static bool Fuzz(gfx::GpuFenceHandle* p, Fuzzer* fuzzer) {
if (!FuzzParam(&p->type, fuzzer))
return false;
return true;
}
};
template <>
struct FuzzTraits<gfx::GpuFenceHandleType> {
static bool Fuzz(gfx::GpuFenceHandleType* p, Fuzzer* fuzzer) {
int type =
RandInRange(static_cast<int>(gfx::GpuFenceHandleType::kLast) + 1);
*p = static_cast<gfx::GpuFenceHandleType>(type);
return true;
}
};

@ -33,22 +33,19 @@ GpuFence* GpuFence::FromClientGpuFence(ClientGpuFence gpu_fence) {
}
void GpuFence::Wait() {
switch (fence_handle_.type) {
case GpuFenceHandleType::kEmpty:
break;
case GpuFenceHandleType::kAndroidNativeFenceSync:
#if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
static const int kInfiniteSyncWaitTimeout = -1;
DCHECK_GE(fence_handle_.owned_fd.get(), 0);
if (sync_wait(fence_handle_.owned_fd.get(), kInfiniteSyncWaitTimeout) <
0) {
LOG(FATAL) << "Failed while waiting for gpu fence fd";
}
#else
NOTREACHED();
#endif
break;
if (fence_handle_.is_null()) {
return;
}
#if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
static const int kInfiniteSyncWaitTimeout = -1;
DCHECK_GE(fence_handle_.owned_fd.get(), 0);
if (sync_wait(fence_handle_.owned_fd.get(), kInfiniteSyncWaitTimeout) < 0) {
LOG(FATAL) << "Failed while waiting for gpu fence fd";
}
#else
NOTREACHED();
#endif
}
// static

@ -22,24 +22,25 @@ GpuFenceHandle& GpuFenceHandle::operator=(GpuFenceHandle&& other) = default;
GpuFenceHandle::~GpuFenceHandle() = default;
GpuFenceHandle GpuFenceHandle::Clone() const {
switch (type) {
case GpuFenceHandleType::kEmpty:
break;
case GpuFenceHandleType::kAndroidNativeFenceSync: {
gfx::GpuFenceHandle handle;
bool GpuFenceHandle::is_null() const {
#if defined(OS_POSIX)
handle.type = GpuFenceHandleType::kAndroidNativeFenceSync;
const int duped_handle = HANDLE_EINTR(dup(owned_fd.get()));
if (duped_handle < 0)
return GpuFenceHandle();
handle.owned_fd = base::ScopedFD(duped_handle);
return !owned_fd.is_valid();
#else
return true;
#endif
return handle;
}
}
}
GpuFenceHandle GpuFenceHandle::Clone() const {
gfx::GpuFenceHandle handle;
#if defined(OS_POSIX)
const int duped_handle = HANDLE_EINTR(dup(owned_fd.get()));
if (duped_handle < 0)
return GpuFenceHandle();
handle.owned_fd = base::ScopedFD(duped_handle);
#else
NOTREACHED();
return gfx::GpuFenceHandle();
#endif
return handle;
}
} // namespace gfx

@ -15,18 +15,6 @@
namespace gfx {
enum class GpuFenceHandleType {
// A null handle for transport. It cannot be used for making a waitable fence
// object.
kEmpty,
// A file descriptor for a native fence object as used by the
// EGL_ANDROID_native_fence_sync extension.
kAndroidNativeFenceSync,
kLast = kAndroidNativeFenceSync
};
struct GFX_EXPORT GpuFenceHandle {
GpuFenceHandle(const GpuFenceHandle&) = delete;
GpuFenceHandle& operator=(const GpuFenceHandle&) = delete;
@ -36,14 +24,16 @@ struct GFX_EXPORT GpuFenceHandle {
GpuFenceHandle& operator=(GpuFenceHandle&& other);
~GpuFenceHandle();
bool is_null() const { return type == GpuFenceHandleType::kEmpty; }
bool is_null() const;
// Returns an instance of |handle| which can be sent over IPC. This duplicates
// the handle so that IPC code can take ownership of it without invalidating
// |handle| itself.
GpuFenceHandle Clone() const;
GpuFenceHandleType type = GpuFenceHandleType::kEmpty;
// owned_fd is defined here for both OS_FUCHSIA and OS_POSIX but all
// of the handling for owned_fd is only for POSIX. Consider adjusting the
// defines in the future.
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
base::ScopedFD owned_fd;
#endif

@ -32,9 +32,6 @@ IPC_ENUM_TRAITS_MAX_VALUE(gfx::SwapResult, gfx::SwapResult::SWAP_RESULT_LAST)
IPC_ENUM_TRAITS_MAX_VALUE(gfx::SelectionBound::Type, gfx::SelectionBound::LAST)
IPC_ENUM_TRAITS_MAX_VALUE(gfx::GpuFenceHandleType,
gfx::GpuFenceHandleType::kLast)
IPC_STRUCT_TRAITS_BEGIN(gfx::CALayerParams)
IPC_STRUCT_TRAITS_MEMBER(is_empty)
#if defined(OS_MAC)
@ -109,7 +106,6 @@ IPC_STRUCT_TRAITS_BEGIN(gfx::PresentationFeedback)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(gfx::GpuFenceHandle)
IPC_STRUCT_TRAITS_MEMBER(type)
#if defined(OS_POSIX)
IPC_STRUCT_TRAITS_MEMBER(owned_fd)
#endif

@ -5,12 +5,6 @@
module gfx.mojom;
// See ui/gfx/ipc/gpu_fence_handle.h
enum GpuFenceHandleType {
kEmpty,
kAndroidNativeFenceSync,
};
struct GpuFenceHandle {
GpuFenceHandleType type;
handle<platform>? native_fd;
};

@ -13,8 +13,6 @@ mojo::PlatformHandle
StructTraits<gfx::mojom::GpuFenceHandleDataView,
gfx::GpuFenceHandle>::native_fd(gfx::GpuFenceHandle& handle) {
#if defined(OS_POSIX)
if (handle.type != gfx::GpuFenceHandleType::kAndroidNativeFenceSync)
return mojo::PlatformHandle();
return mojo::PlatformHandle(std::move(handle.owned_fd));
#else
return mojo::PlatformHandle();
@ -23,24 +21,16 @@ StructTraits<gfx::mojom::GpuFenceHandleDataView,
bool StructTraits<gfx::mojom::GpuFenceHandleDataView, gfx::GpuFenceHandle>::
Read(gfx::mojom::GpuFenceHandleDataView data, gfx::GpuFenceHandle* out) {
if (!data.ReadType(&out->type))
return false;
if (out->type == gfx::GpuFenceHandleType::kAndroidNativeFenceSync) {
#if defined(OS_POSIX)
out->owned_fd = data.TakeNativeFd().TakeFD();
return true;
#else
NOTREACHED();
return false;
#endif
}
return true;
}
void StructTraits<gfx::mojom::GpuFenceHandleDataView,
gfx::GpuFenceHandle>::SetToNull(gfx::GpuFenceHandle* handle) {
handle->type = gfx::GpuFenceHandleType::kEmpty;
#if defined(OS_POSIX)
handle->owned_fd.reset();
#endif
@ -49,13 +39,7 @@ void StructTraits<gfx::mojom::GpuFenceHandleDataView,
bool StructTraits<gfx::mojom::GpuFenceHandleDataView,
gfx::GpuFenceHandle>::IsNull(const gfx::GpuFenceHandle&
handle) {
if (handle.type != gfx::GpuFenceHandleType::kEmpty)
return false;
#if defined(OS_POSIX)
if (handle.owned_fd.is_valid())
return false;
#endif
return true;
return handle.is_null();
}
} // namespace mojo

@ -11,40 +11,9 @@
namespace mojo {
template <>
struct COMPONENT_EXPORT(GFX_SHARED_MOJOM_TRAITS)
EnumTraits<gfx::mojom::GpuFenceHandleType, gfx::GpuFenceHandleType> {
static gfx::mojom::GpuFenceHandleType ToMojom(gfx::GpuFenceHandleType type) {
switch (type) {
case gfx::GpuFenceHandleType::kEmpty:
return gfx::mojom::GpuFenceHandleType::kEmpty;
case gfx::GpuFenceHandleType::kAndroidNativeFenceSync:
return gfx::mojom::GpuFenceHandleType::kAndroidNativeFenceSync;
}
NOTREACHED();
return gfx::mojom::GpuFenceHandleType::kEmpty;
}
static bool FromMojom(gfx::mojom::GpuFenceHandleType input,
gfx::GpuFenceHandleType* out) {
switch (input) {
case gfx::mojom::GpuFenceHandleType::kEmpty:
*out = gfx::GpuFenceHandleType::kEmpty;
return true;
case gfx::mojom::GpuFenceHandleType::kAndroidNativeFenceSync:
*out = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
return true;
}
return false;
}
};
template <>
struct COMPONENT_EXPORT(GFX_SHARED_MOJOM_TRAITS)
StructTraits<gfx::mojom::GpuFenceHandleDataView, gfx::GpuFenceHandle> {
static gfx::GpuFenceHandleType type(const gfx::GpuFenceHandle& handle) {
return handle.type;
}
static mojo::PlatformHandle native_fd(gfx::GpuFenceHandle& handle);
static bool Read(gfx::mojom::GpuFenceHandleDataView data,
gfx::GpuFenceHandle* handle);

@ -104,18 +104,12 @@ bool GLFence::IsGpuFenceSupported() {
std::unique_ptr<GLFence> GLFence::CreateFromGpuFence(
const gfx::GpuFence& gpu_fence) {
DCHECK(IsGpuFenceSupported());
switch (gpu_fence.GetGpuFenceHandle().type) {
case gfx::GpuFenceHandleType::kAndroidNativeFenceSync:
#if defined(USE_GL_FENCE_ANDROID_NATIVE_FENCE_SYNC)
return GLFenceAndroidNativeFenceSync::CreateFromGpuFence(gpu_fence);
return GLFenceAndroidNativeFenceSync::CreateFromGpuFence(gpu_fence);
#else
NOTREACHED();
return nullptr;
NOTREACHED();
return nullptr;
#endif
default:
NOTREACHED();
return nullptr;
}
}
// static

@ -64,7 +64,6 @@ std::unique_ptr<gfx::GpuFence> GLFenceAndroidNativeFenceSync::GetGpuFence() {
return nullptr;
gfx::GpuFenceHandle handle;
handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
handle.owned_fd = base::ScopedFD(sync_fd);
return std::make_unique<gfx::GpuFence>(std::move(handle));

@ -75,7 +75,6 @@ class GLImageAHardwareBuffer::ScopedHardwareBufferFenceSyncImpl
return;
gfx::GpuFenceHandle handle;
handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
handle.owned_fd = std::move(fence_fd);
gfx::GpuFence gpu_fence(std::move(handle));
auto gl_fence = GLFence::CreateFromGpuFence(gpu_fence);

@ -44,7 +44,6 @@ std::unique_ptr<gfx::GpuFence> CreateMergedGpuFenceFromFDs(
if (merged_fd.is_valid()) {
gfx::GpuFenceHandle handle;
handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
handle.owned_fd = std::move(merged_fd);
return std::make_unique<gfx::GpuFence>(std::move(handle));
}
@ -300,11 +299,6 @@ bool HardwareDisplayPlaneManagerAtomic::SetPlaneData(
if (overlay.gpu_fence) {
const auto& gpu_fence_handle = overlay.gpu_fence->GetGpuFenceHandle();
if (gpu_fence_handle.type !=
gfx::GpuFenceHandleType::kAndroidNativeFenceSync) {
LOG(ERROR) << "Received invalid gpu fence";
return false;
}
fence_fd = gpu_fence_handle.owned_fd.get();
}

@ -1036,7 +1036,6 @@ FakeFenceFD::FakeFenceFD() {
std::unique_ptr<gfx::GpuFence> FakeFenceFD::GetGpuFence() const {
gfx::GpuFenceHandle handle;
handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
handle.owned_fd = base::ScopedFD(HANDLE_EINTR(dup(read_fd.get())));
return std::make_unique<gfx::GpuFence>(std::move(handle));
}

@ -134,7 +134,6 @@ std::unique_ptr<gfx::GpuFence> VulkanImplementationGbm::ExportVkFenceToGpuFence(
}
gfx::GpuFenceHandle gpu_fence_handle;
gpu_fence_handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
gpu_fence_handle.owned_fd = base::ScopedFD(fence_fd);
return std::make_unique<gfx::GpuFence>(std::move(gpu_fence_handle));
}