blob: fac6c3eb7a7133a53d88e67e239d496aeac7a23a [file] [log] [blame]
Jesse Hall99c7dbb2013-03-14 14:29:29 -07001/*
2 * Copyright 2013 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
Jesse Hall99c7dbb2013-03-14 14:29:29 -070017#include "VirtualDisplaySurface.h"
Jesse Hall80e0a392013-03-15 12:32:10 -070018#include "HWComposer.h"
Jesse Hall99c7dbb2013-03-14 14:29:29 -070019
20// ---------------------------------------------------------------------------
21namespace android {
22// ---------------------------------------------------------------------------
23
24VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int disp,
25 const sp<IGraphicBufferProducer>& sink, const String8& name)
26: mHwc(hwc),
27 mDisplayId(disp),
Jesse Hall80e0a392013-03-15 12:32:10 -070028 mSource(new BufferQueueInterposer(sink, name)),
Jesse Hall74149652013-03-19 17:18:09 -070029 mName(name)
Jesse Hall99c7dbb2013-03-14 14:29:29 -070030{}
31
32VirtualDisplaySurface::~VirtualDisplaySurface() {
Jesse Hall80e0a392013-03-15 12:32:10 -070033 if (mAcquiredBuffer != NULL) {
Jesse Hall74149652013-03-19 17:18:09 -070034 status_t result = mSource->releaseBuffer(Fence::NO_FENCE);
Jesse Hall80e0a392013-03-15 12:32:10 -070035 ALOGE_IF(result != NO_ERROR, "VirtualDisplaySurface \"%s\": "
Jesse Hall74149652013-03-19 17:18:09 -070036 "failed to release buffer: %d", mName.string(), result);
Jesse Hall80e0a392013-03-15 12:32:10 -070037 }
Jesse Hall99c7dbb2013-03-14 14:29:29 -070038}
39
40sp<IGraphicBufferProducer> VirtualDisplaySurface::getIGraphicBufferProducer() const {
Jesse Hall80e0a392013-03-15 12:32:10 -070041 return mSource;
Jesse Hall99c7dbb2013-03-14 14:29:29 -070042}
43
44status_t VirtualDisplaySurface::compositionComplete() {
45 return NO_ERROR;
46}
47
48status_t VirtualDisplaySurface::advanceFrame() {
Jesse Hall80e0a392013-03-15 12:32:10 -070049 Mutex::Autolock lock(mMutex);
50 status_t result = NO_ERROR;
51
52 if (mAcquiredBuffer != NULL) {
Jesse Hall74149652013-03-19 17:18:09 -070053 ALOGE("VirtualDisplaySurface \"%s\": "
54 "advanceFrame called twice without onFrameCommitted",
55 mName.string());
56 return INVALID_OPERATION;
Jesse Hall80e0a392013-03-15 12:32:10 -070057 }
58
59 sp<Fence> fence;
60 result = mSource->acquireBuffer(&mAcquiredBuffer, &fence);
61 if (result == BufferQueueInterposer::NO_BUFFER_AVAILABLE) {
62 result = mSource->pullEmptyBuffer();
63 if (result != NO_ERROR)
64 return result;
65 result = mSource->acquireBuffer(&mAcquiredBuffer, &fence);
66 }
67 if (result != NO_ERROR)
68 return result;
69
70 return mHwc.fbPost(mDisplayId, fence, mAcquiredBuffer);
Jesse Hall99c7dbb2013-03-14 14:29:29 -070071}
72
Jesse Hall74149652013-03-19 17:18:09 -070073void VirtualDisplaySurface::onFrameCommitted(int fenceFd) {
74 Mutex::Autolock lock(mMutex);
75 sp<Fence> fence(new Fence(fenceFd));
76 if (mAcquiredBuffer != NULL) {
77 status_t result = mSource->releaseBuffer(fence);
78 ALOGE_IF(result != NO_ERROR, "VirtualDisplaySurface \"%s\": "
79 "failed to release buffer: %d", mName.string(), result);
80 mAcquiredBuffer.clear();
Jesse Hall99c7dbb2013-03-14 14:29:29 -070081 }
Jesse Hall99c7dbb2013-03-14 14:29:29 -070082}
83
84void VirtualDisplaySurface::dump(String8& result) const {
85}
86
87// ---------------------------------------------------------------------------
88} // namespace android
89// ---------------------------------------------------------------------------