2012-06-13 23:31:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "Fence"
|
|
|
|
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
|
|
|
|
//#define LOG_NDEBUG 0
|
|
|
|
|
|
|
|
#include <sync/sync.h>
|
|
|
|
#include <ui/Fence.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <utils/Log.h>
|
|
|
|
#include <utils/Trace.h>
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
2012-06-14 21:45:17 +00:00
|
|
|
const sp<Fence> Fence::NO_FENCE = sp<Fence>();
|
|
|
|
|
2012-06-13 23:31:43 +00:00
|
|
|
Fence::Fence() :
|
|
|
|
mFenceFd(-1) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Fence::Fence(int fenceFd) :
|
|
|
|
mFenceFd(fenceFd) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Fence::~Fence() {
|
|
|
|
if (mFenceFd != -1) {
|
|
|
|
close(mFenceFd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int Fence::wait(unsigned int timeout) {
|
|
|
|
ATRACE_CALL();
|
|
|
|
if (mFenceFd == -1) {
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
return sync_wait(mFenceFd, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<Fence> Fence::merge(const String8& name, const sp<Fence>& f1,
|
|
|
|
const sp<Fence>& f2) {
|
|
|
|
ATRACE_CALL();
|
|
|
|
int result = sync_merge(name.string(), f1->mFenceFd, f2->mFenceFd);
|
|
|
|
if (result == -1) {
|
|
|
|
ALOGE("merge: sync_merge returned an error: %s (%d)", strerror(-errno),
|
|
|
|
errno);
|
2012-06-14 21:45:17 +00:00
|
|
|
return NO_FENCE;
|
2012-06-13 23:31:43 +00:00
|
|
|
}
|
|
|
|
return sp<Fence>(new Fence(result));
|
|
|
|
}
|
|
|
|
|
2012-06-25 20:54:23 +00:00
|
|
|
int Fence::dup() const {
|
2012-06-28 19:52:05 +00:00
|
|
|
if (mFenceFd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2012-06-25 20:54:23 +00:00
|
|
|
return ::dup(mFenceFd);
|
|
|
|
}
|
|
|
|
|
2012-06-13 23:31:43 +00:00
|
|
|
size_t Fence::getFlattenedSize() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Fence::getFdCount() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t Fence::flatten(void* buffer, size_t size, int fds[],
|
|
|
|
size_t count) const {
|
|
|
|
if (size != 0 || count != 1) {
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
fds[0] = mFenceFd;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t Fence::unflatten(void const* buffer, size_t size, int fds[],
|
|
|
|
size_t count) {
|
|
|
|
if (size != 0 || count != 1) {
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
if (mFenceFd != -1) {
|
|
|
|
// Don't unflatten if we already have a valid fd.
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFenceFd = fds[0];
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace android
|