-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New WPEBackend-android API introduces sync fence which is used when posting buffers to surface control
- Loading branch information
Showing
18 changed files
with
838 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/** | ||
* Copyright (C) 2023 Igalia S.L. <[email protected]> | ||
* Author: Jani Hautakangas <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include "Fence.h" | ||
|
||
#include <algorithm> | ||
#include <android/sync.h> | ||
#include <memory> | ||
#include <poll.h> | ||
|
||
// constexpr uint32_t NO_ERROR = 0; | ||
|
||
using sync_file_info_data = struct sync_file_info; | ||
|
||
/* | ||
* virtual inline Status getStatus() { | ||
// The sync_wait call underlying wait() has been measured to be | ||
// significantly faster than the sync_fence_info call underlying | ||
// getSignalTime(), which might otherwise appear to be the more obvious | ||
// way to check whether a fence has signaled. | ||
switch (wait(0)) { | ||
case NO_ERROR: | ||
return Status::Signaled; | ||
case -ETIME: | ||
return Status::Unsignaled; | ||
default: | ||
return Status::Invalid; | ||
} | ||
} | ||
*/ | ||
/* | ||
namespace { | ||
int syncWait(int fileDescriptor, int timeout) | ||
{ | ||
struct pollfd fds = {}; | ||
int ret = -1; | ||
if (fileDescriptor < 0) { | ||
errno = EINVAL; | ||
return -1; | ||
} | ||
fds.fd = fileDescriptor; | ||
fds.events = POLLIN; | ||
do { | ||
ret = poll(&fds, 1, timeout); | ||
if (ret > 0) { | ||
if ((static_cast<unsigned int>(fds.revents) & (static_cast<unsigned int>(POLLERR) | static_cast<unsigned | ||
int>(POLLNVAL))) != 0U) { | ||
errno = EINVAL; | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
if (ret == 0) { | ||
errno = ETIME; | ||
return -1; | ||
} | ||
} while (ret == -1 && (errno == EINTR || errno == EAGAIN)); | ||
return ret; | ||
} | ||
int32_t wait(int fileDescriptor) | ||
{ | ||
if (fileDescriptor == -1) { | ||
return NO_ERROR; | ||
} | ||
int const err = syncWait(fileDescriptor, 0); | ||
return err < 0 ? -errno : static_cast<int32_t>(NO_ERROR); | ||
} | ||
} // namespace | ||
*/ | ||
Fence::FenceStatus Fence::getStatus(int fileDescriptor) | ||
{ | ||
/* | ||
switch (wait(fileDescriptor)) { | ||
case NO_ERROR: | ||
return FenceStatus::Signaled; | ||
case -ETIME: | ||
return FenceStatus::NotSignaled; | ||
default: | ||
return FenceStatus::Invalid; | ||
} | ||
*/ | ||
auto info = std::unique_ptr<sync_file_info_data, void (*)(sync_file_info_data*)> { | ||
sync_file_info(fileDescriptor), sync_file_info_free}; | ||
if (info == nullptr) { | ||
return FenceStatus::Invalid; | ||
} | ||
|
||
if (info->status != 1) { | ||
return FenceStatus::NotSignaled; | ||
} | ||
|
||
__u64 timestamp = 0U; | ||
auto* fenceInfo = sync_get_fence_info(info.get()); | ||
for (size_t i = 0; i < info->num_fences; i++) { | ||
timestamp = std::max(timestamp, fenceInfo->timestamp_ns); | ||
} | ||
|
||
return FenceStatus::Signaled; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (C) 2023 Igalia S.L. <[email protected]> | ||
* Author: Jani Hautakangas <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#pragma once | ||
|
||
class Fence { | ||
public: | ||
enum FenceStatus { | ||
Signaled, | ||
NotSignaled, | ||
Invalid | ||
}; | ||
|
||
static FenceStatus getStatus(int fileDescriptor); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.