Commit 16519e5d authored by Rafael Cintron's avatar Rafael Cintron Committed by Commit Bot

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/+/2423164Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#810039}
parent 56546a55
...@@ -96,7 +96,6 @@ void linux_surface_synchronization_set_acquire_fence(wl_client* client, ...@@ -96,7 +96,6 @@ void linux_surface_synchronization_set_acquire_fence(wl_client* client,
} }
gfx::GpuFenceHandle handle; gfx::GpuFenceHandle handle;
handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
handle.owned_fd = std::move(fence_fd); handle.owned_fd = std::move(fence_fd);
surface->SetAcquireFence(std::make_unique<gfx::GpuFence>(std::move(handle))); surface->SetAcquireFence(std::make_unique<gfx::GpuFence>(std::move(handle)));
......
...@@ -174,7 +174,6 @@ TEST_F(GpuFenceManagerTest, GetGpuFence) { ...@@ -174,7 +174,6 @@ TEST_F(GpuFenceManagerTest, GetGpuFence) {
EXPECT_TRUE(gpu_fence); EXPECT_TRUE(gpu_fence);
const gfx::GpuFenceHandle& handle = gpu_fence->GetGpuFenceHandle(); const gfx::GpuFenceHandle& handle = gpu_fence->GetGpuFenceHandle();
EXPECT_EQ(handle.type, gfx::GpuFenceHandleType::kAndroidNativeFenceSync);
EXPECT_EQ(handle.owned_fd.get(), kFenceFD); EXPECT_EQ(handle.owned_fd.get(), kFenceFD);
// Removing the fence marks it invalid. // Removing the fence marks it invalid.
...@@ -194,7 +193,6 @@ TEST_F(GpuFenceManagerTest, Duplication) { ...@@ -194,7 +193,6 @@ TEST_F(GpuFenceManagerTest, Duplication) {
// Create a handle. // Create a handle.
gfx::GpuFenceHandle handle; gfx::GpuFenceHandle handle;
handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
handle.owned_fd = base::ScopedFD(kFenceFD); handle.owned_fd = base::ScopedFD(kFenceFD);
// Create a duplicate fence object from it. // Create a duplicate fence object from it.
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#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) { \ 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("("); l->append("(");
#define IPC_STRUCT_TRAITS_MEMBER(name) \ #define IPC_STRUCT_TRAITS_MEMBER(name) \
if (needs_comma) \ if (needs_comma) \
......
...@@ -966,18 +966,6 @@ struct FuzzTraits<gfx::ColorSpace::TransferID> { ...@@ -966,18 +966,6 @@ struct FuzzTraits<gfx::ColorSpace::TransferID> {
template <> template <>
struct FuzzTraits<gfx::GpuFenceHandle> { struct FuzzTraits<gfx::GpuFenceHandle> {
static bool Fuzz(gfx::GpuFenceHandle* p, Fuzzer* fuzzer) { 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; return true;
} }
}; };
......
...@@ -33,22 +33,19 @@ GpuFence* GpuFence::FromClientGpuFence(ClientGpuFence gpu_fence) { ...@@ -33,22 +33,19 @@ GpuFence* GpuFence::FromClientGpuFence(ClientGpuFence gpu_fence) {
} }
void GpuFence::Wait() { void GpuFence::Wait() {
switch (fence_handle_.type) { if (fence_handle_.is_null()) {
case GpuFenceHandleType::kEmpty: return;
break; }
case GpuFenceHandleType::kAndroidNativeFenceSync:
#if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
static const int kInfiniteSyncWaitTimeout = -1; static const int kInfiniteSyncWaitTimeout = -1;
DCHECK_GE(fence_handle_.owned_fd.get(), 0); DCHECK_GE(fence_handle_.owned_fd.get(), 0);
if (sync_wait(fence_handle_.owned_fd.get(), kInfiniteSyncWaitTimeout) < if (sync_wait(fence_handle_.owned_fd.get(), kInfiniteSyncWaitTimeout) < 0) {
0) {
LOG(FATAL) << "Failed while waiting for gpu fence fd"; LOG(FATAL) << "Failed while waiting for gpu fence fd";
} }
#else #else
NOTREACHED(); NOTREACHED();
#endif #endif
break;
}
} }
// static // static
......
...@@ -22,24 +22,25 @@ GpuFenceHandle& GpuFenceHandle::operator=(GpuFenceHandle&& other) = default; ...@@ -22,24 +22,25 @@ GpuFenceHandle& GpuFenceHandle::operator=(GpuFenceHandle&& other) = default;
GpuFenceHandle::~GpuFenceHandle() = default; GpuFenceHandle::~GpuFenceHandle() = default;
bool GpuFenceHandle::is_null() const {
#if defined(OS_POSIX)
return !owned_fd.is_valid();
#else
return true;
#endif
}
GpuFenceHandle GpuFenceHandle::Clone() const { GpuFenceHandle GpuFenceHandle::Clone() const {
switch (type) {
case GpuFenceHandleType::kEmpty:
break;
case GpuFenceHandleType::kAndroidNativeFenceSync: {
gfx::GpuFenceHandle handle; gfx::GpuFenceHandle handle;
#if defined(OS_POSIX) #if defined(OS_POSIX)
handle.type = GpuFenceHandleType::kAndroidNativeFenceSync;
const int duped_handle = HANDLE_EINTR(dup(owned_fd.get())); const int duped_handle = HANDLE_EINTR(dup(owned_fd.get()));
if (duped_handle < 0) if (duped_handle < 0)
return GpuFenceHandle(); return GpuFenceHandle();
handle.owned_fd = base::ScopedFD(duped_handle); handle.owned_fd = base::ScopedFD(duped_handle);
#else
NOTREACHED();
#endif #endif
return handle; return handle;
}
}
NOTREACHED();
return gfx::GpuFenceHandle();
} }
} // namespace gfx } // namespace gfx
...@@ -15,18 +15,6 @@ ...@@ -15,18 +15,6 @@
namespace gfx { 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 { struct GFX_EXPORT GpuFenceHandle {
GpuFenceHandle(const GpuFenceHandle&) = delete; GpuFenceHandle(const GpuFenceHandle&) = delete;
GpuFenceHandle& operator=(const GpuFenceHandle&) = delete; GpuFenceHandle& operator=(const GpuFenceHandle&) = delete;
...@@ -36,14 +24,16 @@ struct GFX_EXPORT GpuFenceHandle { ...@@ -36,14 +24,16 @@ struct GFX_EXPORT GpuFenceHandle {
GpuFenceHandle& operator=(GpuFenceHandle&& other); GpuFenceHandle& operator=(GpuFenceHandle&& other);
~GpuFenceHandle(); ~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 // 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 // the handle so that IPC code can take ownership of it without invalidating
// |handle| itself. // |handle| itself.
GpuFenceHandle Clone() const; 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) #if defined(OS_POSIX) || defined(OS_FUCHSIA)
base::ScopedFD owned_fd; base::ScopedFD owned_fd;
#endif #endif
......
...@@ -32,9 +32,6 @@ IPC_ENUM_TRAITS_MAX_VALUE(gfx::SwapResult, gfx::SwapResult::SWAP_RESULT_LAST) ...@@ -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::SelectionBound::Type, gfx::SelectionBound::LAST)
IPC_ENUM_TRAITS_MAX_VALUE(gfx::GpuFenceHandleType,
gfx::GpuFenceHandleType::kLast)
IPC_STRUCT_TRAITS_BEGIN(gfx::CALayerParams) IPC_STRUCT_TRAITS_BEGIN(gfx::CALayerParams)
IPC_STRUCT_TRAITS_MEMBER(is_empty) IPC_STRUCT_TRAITS_MEMBER(is_empty)
#if defined(OS_MAC) #if defined(OS_MAC)
...@@ -109,7 +106,6 @@ IPC_STRUCT_TRAITS_BEGIN(gfx::PresentationFeedback) ...@@ -109,7 +106,6 @@ IPC_STRUCT_TRAITS_BEGIN(gfx::PresentationFeedback)
IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(gfx::GpuFenceHandle) IPC_STRUCT_TRAITS_BEGIN(gfx::GpuFenceHandle)
IPC_STRUCT_TRAITS_MEMBER(type)
#if defined(OS_POSIX) #if defined(OS_POSIX)
IPC_STRUCT_TRAITS_MEMBER(owned_fd) IPC_STRUCT_TRAITS_MEMBER(owned_fd)
#endif #endif
......
...@@ -5,12 +5,6 @@ ...@@ -5,12 +5,6 @@
module gfx.mojom; module gfx.mojom;
// See ui/gfx/ipc/gpu_fence_handle.h // See ui/gfx/ipc/gpu_fence_handle.h
enum GpuFenceHandleType {
kEmpty,
kAndroidNativeFenceSync,
};
struct GpuFenceHandle { struct GpuFenceHandle {
GpuFenceHandleType type;
handle<platform>? native_fd; handle<platform>? native_fd;
}; };
...@@ -13,8 +13,6 @@ mojo::PlatformHandle ...@@ -13,8 +13,6 @@ mojo::PlatformHandle
StructTraits<gfx::mojom::GpuFenceHandleDataView, StructTraits<gfx::mojom::GpuFenceHandleDataView,
gfx::GpuFenceHandle>::native_fd(gfx::GpuFenceHandle& handle) { gfx::GpuFenceHandle>::native_fd(gfx::GpuFenceHandle& handle) {
#if defined(OS_POSIX) #if defined(OS_POSIX)
if (handle.type != gfx::GpuFenceHandleType::kAndroidNativeFenceSync)
return mojo::PlatformHandle();
return mojo::PlatformHandle(std::move(handle.owned_fd)); return mojo::PlatformHandle(std::move(handle.owned_fd));
#else #else
return mojo::PlatformHandle(); return mojo::PlatformHandle();
...@@ -23,24 +21,16 @@ StructTraits<gfx::mojom::GpuFenceHandleDataView, ...@@ -23,24 +21,16 @@ StructTraits<gfx::mojom::GpuFenceHandleDataView,
bool StructTraits<gfx::mojom::GpuFenceHandleDataView, gfx::GpuFenceHandle>:: bool StructTraits<gfx::mojom::GpuFenceHandleDataView, gfx::GpuFenceHandle>::
Read(gfx::mojom::GpuFenceHandleDataView data, gfx::GpuFenceHandle* out) { 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) #if defined(OS_POSIX)
out->owned_fd = data.TakeNativeFd().TakeFD(); out->owned_fd = data.TakeNativeFd().TakeFD();
return true; return true;
#else #else
NOTREACHED();
return false; return false;
#endif #endif
}
return true;
} }
void StructTraits<gfx::mojom::GpuFenceHandleDataView, void StructTraits<gfx::mojom::GpuFenceHandleDataView,
gfx::GpuFenceHandle>::SetToNull(gfx::GpuFenceHandle* handle) { gfx::GpuFenceHandle>::SetToNull(gfx::GpuFenceHandle* handle) {
handle->type = gfx::GpuFenceHandleType::kEmpty;
#if defined(OS_POSIX) #if defined(OS_POSIX)
handle->owned_fd.reset(); handle->owned_fd.reset();
#endif #endif
...@@ -49,13 +39,7 @@ void StructTraits<gfx::mojom::GpuFenceHandleDataView, ...@@ -49,13 +39,7 @@ void StructTraits<gfx::mojom::GpuFenceHandleDataView,
bool StructTraits<gfx::mojom::GpuFenceHandleDataView, bool StructTraits<gfx::mojom::GpuFenceHandleDataView,
gfx::GpuFenceHandle>::IsNull(const gfx::GpuFenceHandle& gfx::GpuFenceHandle>::IsNull(const gfx::GpuFenceHandle&
handle) { handle) {
if (handle.type != gfx::GpuFenceHandleType::kEmpty) return handle.is_null();
return false;
#if defined(OS_POSIX)
if (handle.owned_fd.is_valid())
return false;
#endif
return true;
} }
} // namespace mojo } // namespace mojo
...@@ -11,40 +11,9 @@ ...@@ -11,40 +11,9 @@
namespace mojo { 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 <> template <>
struct COMPONENT_EXPORT(GFX_SHARED_MOJOM_TRAITS) struct COMPONENT_EXPORT(GFX_SHARED_MOJOM_TRAITS)
StructTraits<gfx::mojom::GpuFenceHandleDataView, gfx::GpuFenceHandle> { 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 mojo::PlatformHandle native_fd(gfx::GpuFenceHandle& handle);
static bool Read(gfx::mojom::GpuFenceHandleDataView data, static bool Read(gfx::mojom::GpuFenceHandleDataView data,
gfx::GpuFenceHandle* handle); gfx::GpuFenceHandle* handle);
......
...@@ -104,18 +104,12 @@ bool GLFence::IsGpuFenceSupported() { ...@@ -104,18 +104,12 @@ bool GLFence::IsGpuFenceSupported() {
std::unique_ptr<GLFence> GLFence::CreateFromGpuFence( std::unique_ptr<GLFence> GLFence::CreateFromGpuFence(
const gfx::GpuFence& gpu_fence) { const gfx::GpuFence& gpu_fence) {
DCHECK(IsGpuFenceSupported()); DCHECK(IsGpuFenceSupported());
switch (gpu_fence.GetGpuFenceHandle().type) {
case gfx::GpuFenceHandleType::kAndroidNativeFenceSync:
#if defined(USE_GL_FENCE_ANDROID_NATIVE_FENCE_SYNC) #if defined(USE_GL_FENCE_ANDROID_NATIVE_FENCE_SYNC)
return GLFenceAndroidNativeFenceSync::CreateFromGpuFence(gpu_fence); return GLFenceAndroidNativeFenceSync::CreateFromGpuFence(gpu_fence);
#else #else
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
#endif #endif
default:
NOTREACHED();
return nullptr;
}
} }
// static // static
......
...@@ -64,7 +64,6 @@ std::unique_ptr<gfx::GpuFence> GLFenceAndroidNativeFenceSync::GetGpuFence() { ...@@ -64,7 +64,6 @@ std::unique_ptr<gfx::GpuFence> GLFenceAndroidNativeFenceSync::GetGpuFence() {
return nullptr; return nullptr;
gfx::GpuFenceHandle handle; gfx::GpuFenceHandle handle;
handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
handle.owned_fd = base::ScopedFD(sync_fd); handle.owned_fd = base::ScopedFD(sync_fd);
return std::make_unique<gfx::GpuFence>(std::move(handle)); return std::make_unique<gfx::GpuFence>(std::move(handle));
......
...@@ -75,7 +75,6 @@ class GLImageAHardwareBuffer::ScopedHardwareBufferFenceSyncImpl ...@@ -75,7 +75,6 @@ class GLImageAHardwareBuffer::ScopedHardwareBufferFenceSyncImpl
return; return;
gfx::GpuFenceHandle handle; gfx::GpuFenceHandle handle;
handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
handle.owned_fd = std::move(fence_fd); handle.owned_fd = std::move(fence_fd);
gfx::GpuFence gpu_fence(std::move(handle)); gfx::GpuFence gpu_fence(std::move(handle));
auto gl_fence = GLFence::CreateFromGpuFence(gpu_fence); auto gl_fence = GLFence::CreateFromGpuFence(gpu_fence);
......
...@@ -44,7 +44,6 @@ std::unique_ptr<gfx::GpuFence> CreateMergedGpuFenceFromFDs( ...@@ -44,7 +44,6 @@ std::unique_ptr<gfx::GpuFence> CreateMergedGpuFenceFromFDs(
if (merged_fd.is_valid()) { if (merged_fd.is_valid()) {
gfx::GpuFenceHandle handle; gfx::GpuFenceHandle handle;
handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
handle.owned_fd = std::move(merged_fd); handle.owned_fd = std::move(merged_fd);
return std::make_unique<gfx::GpuFence>(std::move(handle)); return std::make_unique<gfx::GpuFence>(std::move(handle));
} }
...@@ -300,11 +299,6 @@ bool HardwareDisplayPlaneManagerAtomic::SetPlaneData( ...@@ -300,11 +299,6 @@ bool HardwareDisplayPlaneManagerAtomic::SetPlaneData(
if (overlay.gpu_fence) { if (overlay.gpu_fence) {
const auto& gpu_fence_handle = overlay.gpu_fence->GetGpuFenceHandle(); 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(); fence_fd = gpu_fence_handle.owned_fd.get();
} }
......
...@@ -1036,7 +1036,6 @@ FakeFenceFD::FakeFenceFD() { ...@@ -1036,7 +1036,6 @@ FakeFenceFD::FakeFenceFD() {
std::unique_ptr<gfx::GpuFence> FakeFenceFD::GetGpuFence() const { std::unique_ptr<gfx::GpuFence> FakeFenceFD::GetGpuFence() const {
gfx::GpuFenceHandle handle; gfx::GpuFenceHandle handle;
handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
handle.owned_fd = base::ScopedFD(HANDLE_EINTR(dup(read_fd.get()))); handle.owned_fd = base::ScopedFD(HANDLE_EINTR(dup(read_fd.get())));
return std::make_unique<gfx::GpuFence>(std::move(handle)); return std::make_unique<gfx::GpuFence>(std::move(handle));
} }
......
...@@ -134,7 +134,6 @@ std::unique_ptr<gfx::GpuFence> VulkanImplementationGbm::ExportVkFenceToGpuFence( ...@@ -134,7 +134,6 @@ std::unique_ptr<gfx::GpuFence> VulkanImplementationGbm::ExportVkFenceToGpuFence(
} }
gfx::GpuFenceHandle gpu_fence_handle; gfx::GpuFenceHandle gpu_fence_handle;
gpu_fence_handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
gpu_fence_handle.owned_fd = base::ScopedFD(fence_fd); gpu_fence_handle.owned_fd = base::ScopedFD(fence_fd);
return std::make_unique<gfx::GpuFence>(std::move(gpu_fence_handle)); return std::make_unique<gfx::GpuFence>(std::move(gpu_fence_handle));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment