Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 1 | /* |
| 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 Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 17 | #include "VirtualDisplaySurface.h" |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 18 | #include "HWComposer.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 19 | |
| 20 | // --------------------------------------------------------------------------- |
| 21 | namespace android { |
| 22 | // --------------------------------------------------------------------------- |
| 23 | |
| 24 | VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int disp, |
| 25 | const sp<IGraphicBufferProducer>& sink, const String8& name) |
| 26 | : mHwc(hwc), |
| 27 | mDisplayId(disp), |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 28 | mSource(new BufferQueueInterposer(sink, name)), |
Jesse Hall | 7414965 | 2013-03-19 17:18:09 -0700 | [diff] [blame] | 29 | mName(name) |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 30 | {} |
| 31 | |
| 32 | VirtualDisplaySurface::~VirtualDisplaySurface() { |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 33 | if (mAcquiredBuffer != NULL) { |
Jesse Hall | 7414965 | 2013-03-19 17:18:09 -0700 | [diff] [blame] | 34 | status_t result = mSource->releaseBuffer(Fence::NO_FENCE); |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 35 | ALOGE_IF(result != NO_ERROR, "VirtualDisplaySurface \"%s\": " |
Jesse Hall | 7414965 | 2013-03-19 17:18:09 -0700 | [diff] [blame] | 36 | "failed to release buffer: %d", mName.string(), result); |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 37 | } |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | sp<IGraphicBufferProducer> VirtualDisplaySurface::getIGraphicBufferProducer() const { |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 41 | return mSource; |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | status_t VirtualDisplaySurface::compositionComplete() { |
| 45 | return NO_ERROR; |
| 46 | } |
| 47 | |
| 48 | status_t VirtualDisplaySurface::advanceFrame() { |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 49 | Mutex::Autolock lock(mMutex); |
| 50 | status_t result = NO_ERROR; |
| 51 | |
| 52 | if (mAcquiredBuffer != NULL) { |
Jesse Hall | 7414965 | 2013-03-19 17:18:09 -0700 | [diff] [blame] | 53 | ALOGE("VirtualDisplaySurface \"%s\": " |
| 54 | "advanceFrame called twice without onFrameCommitted", |
| 55 | mName.string()); |
| 56 | return INVALID_OPERATION; |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 57 | } |
| 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 Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame^] | 73 | void VirtualDisplaySurface::onFrameCommitted() { |
Jesse Hall | 7414965 | 2013-03-19 17:18:09 -0700 | [diff] [blame] | 74 | Mutex::Autolock lock(mMutex); |
Jesse Hall | 7414965 | 2013-03-19 17:18:09 -0700 | [diff] [blame] | 75 | if (mAcquiredBuffer != NULL) { |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame^] | 76 | // fbFence signals when reads from the framebuffer are finished |
| 77 | // outFence signals when writes to the output buffer are finished |
| 78 | // It's unlikely that there will be an implementation where fbFence |
| 79 | // signals after outFence (in fact they'll typically be the same |
| 80 | // sync_pt), but just to be pedantic we merge them so the sink will |
| 81 | // be sure to wait until both are complete. |
| 82 | sp<Fence> fbFence = mHwc.getAndResetReleaseFence(mDisplayId); |
| 83 | sp<Fence> outFence = mHwc.getLastRetireFence(mDisplayId); |
| 84 | sp<Fence> fence = Fence::merge( |
| 85 | String8::format("HWC done: %.21s", mName.string()), |
| 86 | fbFence, outFence); |
| 87 | |
Jesse Hall | 7414965 | 2013-03-19 17:18:09 -0700 | [diff] [blame] | 88 | status_t result = mSource->releaseBuffer(fence); |
| 89 | ALOGE_IF(result != NO_ERROR, "VirtualDisplaySurface \"%s\": " |
| 90 | "failed to release buffer: %d", mName.string(), result); |
| 91 | mAcquiredBuffer.clear(); |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 92 | } |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void VirtualDisplaySurface::dump(String8& result) const { |
| 96 | } |
| 97 | |
| 98 | // --------------------------------------------------------------------------- |
| 99 | } // namespace android |
| 100 | // --------------------------------------------------------------------------- |