2013-03-14 21:29:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "VirtualDisplaySurface.h"
|
2013-03-15 19:32:10 +00:00
|
|
|
#include "HWComposer.h"
|
2013-03-14 21:29:29 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
namespace android {
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2013-03-22 22:13:48 +00:00
|
|
|
VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int32_t dispId,
|
2013-03-14 21:29:29 +00:00
|
|
|
const sp<IGraphicBufferProducer>& sink, const String8& name)
|
|
|
|
: mHwc(hwc),
|
2013-03-22 22:13:48 +00:00
|
|
|
mDisplayId(dispId),
|
2013-03-20 00:18:09 +00:00
|
|
|
mName(name)
|
2013-03-22 22:13:48 +00:00
|
|
|
{
|
|
|
|
if (mDisplayId >= 0) {
|
|
|
|
mInterposer = new BufferQueueInterposer(sink, name);
|
|
|
|
mSourceProducer = mInterposer;
|
|
|
|
} else {
|
|
|
|
mSourceProducer = sink;
|
|
|
|
}
|
|
|
|
}
|
2013-03-14 21:29:29 +00:00
|
|
|
|
|
|
|
VirtualDisplaySurface::~VirtualDisplaySurface() {
|
2013-03-15 19:32:10 +00:00
|
|
|
if (mAcquiredBuffer != NULL) {
|
2013-03-22 22:13:48 +00:00
|
|
|
status_t result = mInterposer->releaseBuffer(Fence::NO_FENCE);
|
2013-03-15 19:32:10 +00:00
|
|
|
ALOGE_IF(result != NO_ERROR, "VirtualDisplaySurface \"%s\": "
|
2013-03-20 00:18:09 +00:00
|
|
|
"failed to release buffer: %d", mName.string(), result);
|
2013-03-15 19:32:10 +00:00
|
|
|
}
|
2013-03-14 21:29:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sp<IGraphicBufferProducer> VirtualDisplaySurface::getIGraphicBufferProducer() const {
|
2013-03-22 22:13:48 +00:00
|
|
|
return mSourceProducer;
|
2013-03-14 21:29:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t VirtualDisplaySurface::compositionComplete() {
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t VirtualDisplaySurface::advanceFrame() {
|
2013-03-22 22:13:48 +00:00
|
|
|
if (mInterposer == NULL)
|
|
|
|
return NO_ERROR;
|
|
|
|
|
2013-03-15 19:32:10 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
status_t result = NO_ERROR;
|
|
|
|
|
|
|
|
if (mAcquiredBuffer != NULL) {
|
2013-03-20 00:18:09 +00:00
|
|
|
ALOGE("VirtualDisplaySurface \"%s\": "
|
|
|
|
"advanceFrame called twice without onFrameCommitted",
|
|
|
|
mName.string());
|
|
|
|
return INVALID_OPERATION;
|
2013-03-15 19:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sp<Fence> fence;
|
2013-03-22 22:13:48 +00:00
|
|
|
result = mInterposer->acquireBuffer(&mAcquiredBuffer, &fence);
|
2013-03-15 19:32:10 +00:00
|
|
|
if (result == BufferQueueInterposer::NO_BUFFER_AVAILABLE) {
|
2013-03-22 22:13:48 +00:00
|
|
|
result = mInterposer->pullEmptyBuffer();
|
2013-03-15 19:32:10 +00:00
|
|
|
if (result != NO_ERROR)
|
|
|
|
return result;
|
2013-03-22 22:13:48 +00:00
|
|
|
result = mInterposer->acquireBuffer(&mAcquiredBuffer, &fence);
|
2013-03-15 19:32:10 +00:00
|
|
|
}
|
|
|
|
if (result != NO_ERROR)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
return mHwc.fbPost(mDisplayId, fence, mAcquiredBuffer);
|
2013-03-14 21:29:29 +00:00
|
|
|
}
|
|
|
|
|
2013-03-20 20:44:00 +00:00
|
|
|
void VirtualDisplaySurface::onFrameCommitted() {
|
2013-03-22 22:13:48 +00:00
|
|
|
if (mInterposer == NULL)
|
|
|
|
return;
|
|
|
|
|
2013-03-20 00:18:09 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
if (mAcquiredBuffer != NULL) {
|
2013-03-20 20:44:00 +00:00
|
|
|
// fbFence signals when reads from the framebuffer are finished
|
|
|
|
// outFence signals when writes to the output buffer are finished
|
|
|
|
// It's unlikely that there will be an implementation where fbFence
|
|
|
|
// signals after outFence (in fact they'll typically be the same
|
|
|
|
// sync_pt), but just to be pedantic we merge them so the sink will
|
|
|
|
// be sure to wait until both are complete.
|
|
|
|
sp<Fence> fbFence = mHwc.getAndResetReleaseFence(mDisplayId);
|
|
|
|
sp<Fence> outFence = mHwc.getLastRetireFence(mDisplayId);
|
|
|
|
sp<Fence> fence = Fence::merge(
|
|
|
|
String8::format("HWC done: %.21s", mName.string()),
|
|
|
|
fbFence, outFence);
|
|
|
|
|
2013-03-22 22:13:48 +00:00
|
|
|
status_t result = mInterposer->releaseBuffer(fence);
|
2013-03-20 00:18:09 +00:00
|
|
|
ALOGE_IF(result != NO_ERROR, "VirtualDisplaySurface \"%s\": "
|
|
|
|
"failed to release buffer: %d", mName.string(), result);
|
|
|
|
mAcquiredBuffer.clear();
|
2013-03-14 21:29:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualDisplaySurface::dump(String8& result) const {
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
} // namespace android
|
|
|
|
// ---------------------------------------------------------------------------
|