2 * Copyright 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "VirtualDisplaySurface.h"
18 #include "HWComposer.h"
20 // ---------------------------------------------------------------------------
22 // ---------------------------------------------------------------------------
24 VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int disp,
25 const sp<IGraphicBufferProducer>& sink, const String8& name)
28 mSource(new BufferQueueInterposer(sink, name)),
30 mReleaseFence(Fence::NO_FENCE)
33 VirtualDisplaySurface::~VirtualDisplaySurface() {
34 if (mAcquiredBuffer != NULL) {
35 status_t result = mSource->releaseBuffer(mReleaseFence);
36 ALOGE_IF(result != NO_ERROR, "VirtualDisplaySurface \"%s\": "
37 "failed to release previous buffer: %d",
38 mName.string(), result);
42 sp<IGraphicBufferProducer> VirtualDisplaySurface::getIGraphicBufferProducer() const {
46 status_t VirtualDisplaySurface::compositionComplete() {
50 status_t VirtualDisplaySurface::advanceFrame() {
51 Mutex::Autolock lock(mMutex);
52 status_t result = NO_ERROR;
54 if (mAcquiredBuffer != NULL) {
55 result = mSource->releaseBuffer(mReleaseFence);
56 ALOGE_IF(result != NO_ERROR, "VirtualDisplaySurface \"%s\": "
57 "failed to release previous buffer: %d",
58 mName.string(), result);
59 mAcquiredBuffer.clear();
60 mReleaseFence = Fence::NO_FENCE;
64 result = mSource->acquireBuffer(&mAcquiredBuffer, &fence);
65 if (result == BufferQueueInterposer::NO_BUFFER_AVAILABLE) {
66 result = mSource->pullEmptyBuffer();
67 if (result != NO_ERROR)
69 result = mSource->acquireBuffer(&mAcquiredBuffer, &fence);
71 if (result != NO_ERROR)
74 return mHwc.fbPost(mDisplayId, fence, mAcquiredBuffer);
77 status_t VirtualDisplaySurface::setReleaseFenceFd(int fenceFd) {
79 sp<Fence> fence(new Fence(fenceFd));
80 Mutex::Autolock lock(mMutex);
81 sp<Fence> mergedFence = Fence::merge(
82 String8::format("VirtualDisplaySurface \"%s\"",
84 mReleaseFence, fence);
85 if (!mergedFence->isValid()) {
86 ALOGE("VirtualDisplaySurface \"%s\": failed to merge release fence",
88 // synchronization is broken, the best we can do is hope fences
89 // signal in order so the new fence will act like a union
90 mReleaseFence = fence;
93 mReleaseFence = mergedFence;
98 void VirtualDisplaySurface::dump(String8& result) const {
101 // ---------------------------------------------------------------------------
102 } // namespace android
103 // ---------------------------------------------------------------------------