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 | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 17 | // #define LOG_NDEBUG 0 |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 18 | #include "VirtualDisplaySurface.h" |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 19 | #include "HWComposer.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 20 | |
Dan Stoza | 11611f9 | 2015-03-12 15:12:44 -0700 | [diff] [blame] | 21 | #include <gui/BufferItem.h> |
Pablo Ceballos | f133d00 | 2015-10-23 12:10:13 -0700 | [diff] [blame] | 22 | #include <gui/IProducerListener.h> |
Dan Stoza | 11611f9 | 2015-03-12 15:12:44 -0700 | [diff] [blame] | 23 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 24 | // --------------------------------------------------------------------------- |
| 25 | namespace android { |
| 26 | // --------------------------------------------------------------------------- |
| 27 | |
Jesse Hall | c354eff | 2013-10-25 10:44:41 -0700 | [diff] [blame] | 28 | #if defined(FORCE_HWC_COPY_FOR_VIRTUAL_DISPLAYS) |
| 29 | static const bool sForceHwcCopy = true; |
| 30 | #else |
| 31 | static const bool sForceHwcCopy = false; |
| 32 | #endif |
Naseer Ahmed | 6a96846 | 2013-10-04 16:15:22 -0400 | [diff] [blame] | 33 | |
Jesse Hall | 24cd98e | 2014-07-13 14:37:16 -0700 | [diff] [blame] | 34 | #define VDS_LOGE(msg, ...) ALOGE("[%s] " msg, \ |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 35 | mDisplayName.string(), ##__VA_ARGS__) |
Jesse Hall | 24cd98e | 2014-07-13 14:37:16 -0700 | [diff] [blame] | 36 | #define VDS_LOGW_IF(cond, msg, ...) ALOGW_IF(cond, "[%s] " msg, \ |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 37 | mDisplayName.string(), ##__VA_ARGS__) |
Jesse Hall | 24cd98e | 2014-07-13 14:37:16 -0700 | [diff] [blame] | 38 | #define VDS_LOGV(msg, ...) ALOGV("[%s] " msg, \ |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 39 | mDisplayName.string(), ##__VA_ARGS__) |
| 40 | |
| 41 | static const char* dbgCompositionTypeStr(DisplaySurface::CompositionType type) { |
| 42 | switch (type) { |
| 43 | case DisplaySurface::COMPOSITION_UNKNOWN: return "UNKNOWN"; |
| 44 | case DisplaySurface::COMPOSITION_GLES: return "GLES"; |
| 45 | case DisplaySurface::COMPOSITION_HWC: return "HWC"; |
| 46 | case DisplaySurface::COMPOSITION_MIXED: return "MIXED"; |
| 47 | default: return "<INVALID>"; |
| 48 | } |
| 49 | } |
| 50 | |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 51 | VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int32_t dispId, |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 52 | const sp<IGraphicBufferProducer>& sink, |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 53 | const sp<IGraphicBufferProducer>& bqProducer, |
| 54 | const sp<IGraphicBufferConsumer>& bqConsumer, |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 55 | const String8& name) |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 56 | : ConsumerBase(bqConsumer), |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 57 | mHwc(hwc), |
| 58 | mDisplayId(dispId), |
| 59 | mDisplayName(name), |
Jesse Hall | 1e27ba2 | 2013-09-27 09:05:09 -0700 | [diff] [blame] | 60 | mOutputUsage(GRALLOC_USAGE_HW_COMPOSER), |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 61 | mProducerSlotSource(0), |
| 62 | mDbgState(DBG_STATE_IDLE), |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 63 | mDbgLastCompositionType(COMPOSITION_UNKNOWN), |
| 64 | mMustRecompose(false) |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 65 | { |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 66 | mSource[SOURCE_SINK] = sink; |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 67 | mSource[SOURCE_SCRATCH] = bqProducer; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 68 | |
| 69 | resetPerFrameState(); |
| 70 | |
| 71 | int sinkWidth, sinkHeight; |
Jesse Hall | 497ba0e | 2013-11-04 16:43:03 -0800 | [diff] [blame] | 72 | sink->query(NATIVE_WINDOW_WIDTH, &sinkWidth); |
| 73 | sink->query(NATIVE_WINDOW_HEIGHT, &sinkHeight); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 74 | mSinkBufferWidth = sinkWidth; |
| 75 | mSinkBufferHeight = sinkHeight; |
Jesse Hall | 497ba0e | 2013-11-04 16:43:03 -0800 | [diff] [blame] | 76 | |
| 77 | // Pick the buffer format to request from the sink when not rendering to it |
| 78 | // with GLES. If the consumer needs CPU access, use the default format |
| 79 | // set by the consumer. Otherwise allow gralloc to decide the format based |
| 80 | // on usage bits. |
| 81 | int sinkUsage; |
| 82 | sink->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, &sinkUsage); |
| 83 | if (sinkUsage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) { |
| 84 | int sinkFormat; |
| 85 | sink->query(NATIVE_WINDOW_FORMAT, &sinkFormat); |
| 86 | mDefaultOutputFormat = sinkFormat; |
| 87 | } else { |
| 88 | mDefaultOutputFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED; |
| 89 | } |
| 90 | mOutputFormat = mDefaultOutputFormat; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 91 | |
| 92 | ConsumerBase::mName = String8::format("VDS: %s", mDisplayName.string()); |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 93 | mConsumer->setConsumerName(ConsumerBase::mName); |
| 94 | mConsumer->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER); |
| 95 | mConsumer->setDefaultBufferSize(sinkWidth, sinkHeight); |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 96 | sink->setAsyncMode(true); |
Pablo Ceballos | f133d00 | 2015-10-23 12:10:13 -0700 | [diff] [blame] | 97 | IGraphicBufferProducer::QueueBufferOutput output; |
| 98 | mSource[SOURCE_SCRATCH]->connect(NULL, NATIVE_WINDOW_API_EGL, false, &output); |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 99 | } |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 100 | |
| 101 | VirtualDisplaySurface::~VirtualDisplaySurface() { |
Pablo Ceballos | f133d00 | 2015-10-23 12:10:13 -0700 | [diff] [blame] | 102 | mSource[SOURCE_SCRATCH]->disconnect(NATIVE_WINDOW_API_EGL); |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 105 | status_t VirtualDisplaySurface::beginFrame(bool mustRecompose) { |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 106 | if (mDisplayId < 0) |
| 107 | return NO_ERROR; |
| 108 | |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 109 | mMustRecompose = mustRecompose; |
| 110 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 111 | VDS_LOGW_IF(mDbgState != DBG_STATE_IDLE, |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 112 | "Unexpected beginFrame() in %s state", dbgStateStr()); |
| 113 | mDbgState = DBG_STATE_BEGUN; |
| 114 | |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 115 | return refreshOutputBuffer(); |
| 116 | } |
| 117 | |
| 118 | status_t VirtualDisplaySurface::prepareFrame(CompositionType compositionType) { |
| 119 | if (mDisplayId < 0) |
| 120 | return NO_ERROR; |
| 121 | |
| 122 | VDS_LOGW_IF(mDbgState != DBG_STATE_BEGUN, |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 123 | "Unexpected prepareFrame() in %s state", dbgStateStr()); |
| 124 | mDbgState = DBG_STATE_PREPARED; |
| 125 | |
| 126 | mCompositionType = compositionType; |
Naseer Ahmed | 6a96846 | 2013-10-04 16:15:22 -0400 | [diff] [blame] | 127 | if (sForceHwcCopy && mCompositionType == COMPOSITION_GLES) { |
| 128 | // Some hardware can do RGB->YUV conversion more efficiently in hardware |
| 129 | // controlled by HWC than in hardware controlled by the video encoder. |
| 130 | // Forcing GLES-composed frames to go through an extra copy by the HWC |
| 131 | // allows the format conversion to happen there, rather than passing RGB |
| 132 | // directly to the consumer. |
| 133 | // |
| 134 | // On the other hand, when the consumer prefers RGB or can consume RGB |
| 135 | // inexpensively, this forces an unnecessary copy. |
| 136 | mCompositionType = COMPOSITION_MIXED; |
| 137 | } |
| 138 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 139 | if (mCompositionType != mDbgLastCompositionType) { |
| 140 | VDS_LOGV("prepareFrame: composition type changed to %s", |
| 141 | dbgCompositionTypeStr(mCompositionType)); |
| 142 | mDbgLastCompositionType = mCompositionType; |
| 143 | } |
| 144 | |
Jesse Hall | 1e27ba2 | 2013-09-27 09:05:09 -0700 | [diff] [blame] | 145 | if (mCompositionType != COMPOSITION_GLES && |
Jesse Hall | 497ba0e | 2013-11-04 16:43:03 -0800 | [diff] [blame] | 146 | (mOutputFormat != mDefaultOutputFormat || |
Jesse Hall | 1e27ba2 | 2013-09-27 09:05:09 -0700 | [diff] [blame] | 147 | mOutputUsage != GRALLOC_USAGE_HW_COMPOSER)) { |
| 148 | // We must have just switched from GLES-only to MIXED or HWC |
| 149 | // composition. Stop using the format and usage requested by the GLES |
| 150 | // driver; they may be suboptimal when HWC is writing to the output |
| 151 | // buffer. For example, if the output is going to a video encoder, and |
| 152 | // HWC can write directly to YUV, some hardware can skip a |
| 153 | // memory-to-memory RGB-to-YUV conversion step. |
| 154 | // |
| 155 | // If we just switched *to* GLES-only mode, we'll change the |
| 156 | // format/usage and get a new buffer when the GLES driver calls |
| 157 | // dequeueBuffer(). |
Jesse Hall | 497ba0e | 2013-11-04 16:43:03 -0800 | [diff] [blame] | 158 | mOutputFormat = mDefaultOutputFormat; |
Jesse Hall | 1e27ba2 | 2013-09-27 09:05:09 -0700 | [diff] [blame] | 159 | mOutputUsage = GRALLOC_USAGE_HW_COMPOSER; |
| 160 | refreshOutputBuffer(); |
| 161 | } |
| 162 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 163 | return NO_ERROR; |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | status_t VirtualDisplaySurface::compositionComplete() { |
| 167 | return NO_ERROR; |
| 168 | } |
| 169 | |
| 170 | status_t VirtualDisplaySurface::advanceFrame() { |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 171 | if (mDisplayId < 0) |
| 172 | return NO_ERROR; |
| 173 | |
| 174 | if (mCompositionType == COMPOSITION_HWC) { |
| 175 | VDS_LOGW_IF(mDbgState != DBG_STATE_PREPARED, |
| 176 | "Unexpected advanceFrame() in %s state on HWC frame", |
| 177 | dbgStateStr()); |
| 178 | } else { |
| 179 | VDS_LOGW_IF(mDbgState != DBG_STATE_GLES_DONE, |
| 180 | "Unexpected advanceFrame() in %s state on GLES/MIXED frame", |
| 181 | dbgStateStr()); |
| 182 | } |
| 183 | mDbgState = DBG_STATE_HWC; |
| 184 | |
Jesse Hall | 14e8b01 | 2013-11-07 12:28:26 -0800 | [diff] [blame] | 185 | if (mOutputProducerSlot < 0 || |
| 186 | (mCompositionType != COMPOSITION_HWC && mFbProducerSlot < 0)) { |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 187 | // Last chance bailout if something bad happened earlier. For example, |
| 188 | // in a GLES configuration, if the sink disappears then dequeueBuffer |
| 189 | // will fail, the GLES driver won't queue a buffer, but SurfaceFlinger |
| 190 | // will soldier on. So we end up here without a buffer. There should |
| 191 | // be lots of scary messages in the log just before this. |
| 192 | VDS_LOGE("advanceFrame: no buffer, bailing out"); |
| 193 | return NO_MEMORY; |
| 194 | } |
| 195 | |
Jesse Hall | 14e8b01 | 2013-11-07 12:28:26 -0800 | [diff] [blame] | 196 | sp<GraphicBuffer> fbBuffer = mFbProducerSlot >= 0 ? |
| 197 | mProducerBuffers[mFbProducerSlot] : sp<GraphicBuffer>(NULL); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 198 | sp<GraphicBuffer> outBuffer = mProducerBuffers[mOutputProducerSlot]; |
| 199 | VDS_LOGV("advanceFrame: fb=%d(%p) out=%d(%p)", |
| 200 | mFbProducerSlot, fbBuffer.get(), |
| 201 | mOutputProducerSlot, outBuffer.get()); |
| 202 | |
Jesse Hall | b716e57 | 2013-10-01 17:25:20 -0700 | [diff] [blame] | 203 | // At this point we know the output buffer acquire fence, |
| 204 | // so update HWC state with it. |
| 205 | mHwc.setOutputBuffer(mDisplayId, mOutputFence, outBuffer); |
| 206 | |
Jesse Hall | 14e8b01 | 2013-11-07 12:28:26 -0800 | [diff] [blame] | 207 | status_t result = NO_ERROR; |
| 208 | if (fbBuffer != NULL) { |
| 209 | result = mHwc.fbPost(mDisplayId, mFbFence, fbBuffer); |
| 210 | } |
| 211 | |
| 212 | return result; |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 215 | void VirtualDisplaySurface::onFrameCommitted() { |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 216 | if (mDisplayId < 0) |
| 217 | return; |
| 218 | |
| 219 | VDS_LOGW_IF(mDbgState != DBG_STATE_HWC, |
| 220 | "Unexpected onFrameCommitted() in %s state", dbgStateStr()); |
| 221 | mDbgState = DBG_STATE_IDLE; |
| 222 | |
| 223 | sp<Fence> fbFence = mHwc.getAndResetReleaseFence(mDisplayId); |
| 224 | if (mCompositionType == COMPOSITION_MIXED && mFbProducerSlot >= 0) { |
| 225 | // release the scratch buffer back to the pool |
| 226 | Mutex::Autolock lock(mMutex); |
| 227 | int sslot = mapProducer2SourceSlot(SOURCE_SCRATCH, mFbProducerSlot); |
| 228 | VDS_LOGV("onFrameCommitted: release scratch sslot=%d", sslot); |
| 229 | addReleaseFenceLocked(sslot, mProducerBuffers[mFbProducerSlot], fbFence); |
| 230 | releaseBufferLocked(sslot, mProducerBuffers[mFbProducerSlot], |
| 231 | EGL_NO_DISPLAY, EGL_NO_SYNC_KHR); |
| 232 | } |
| 233 | |
| 234 | if (mOutputProducerSlot >= 0) { |
| 235 | int sslot = mapProducer2SourceSlot(SOURCE_SINK, mOutputProducerSlot); |
| 236 | QueueBufferOutput qbo; |
| 237 | sp<Fence> outFence = mHwc.getLastRetireFence(mDisplayId); |
| 238 | VDS_LOGV("onFrameCommitted: queue sink sslot=%d", sslot); |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 239 | if (mMustRecompose) { |
| 240 | status_t result = mSource[SOURCE_SINK]->queueBuffer(sslot, |
| 241 | QueueBufferInput( |
| 242 | systemTime(), false /* isAutoTimestamp */, |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 243 | HAL_DATASPACE_UNKNOWN, |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 244 | Rect(mSinkBufferWidth, mSinkBufferHeight), |
| 245 | NATIVE_WINDOW_SCALING_MODE_FREEZE, 0 /* transform */, |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 246 | outFence), |
| 247 | &qbo); |
| 248 | if (result == NO_ERROR) { |
| 249 | updateQueueBufferOutput(qbo); |
| 250 | } |
| 251 | } else { |
| 252 | // If the surface hadn't actually been updated, then we only went |
| 253 | // through the motions of updating the display to keep our state |
| 254 | // machine happy. We cancel the buffer to avoid triggering another |
| 255 | // re-composition and causing an infinite loop. |
| 256 | mSource[SOURCE_SINK]->cancelBuffer(sslot, outFence); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
| 260 | resetPerFrameState(); |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Dan Stoza | 01049c8 | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 263 | void VirtualDisplaySurface::dumpAsString(String8& /* result */) const { |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 266 | void VirtualDisplaySurface::resizeBuffers(const uint32_t w, const uint32_t h) { |
| 267 | uint32_t tmpW, tmpH, transformHint, numPendingBuffers; |
| 268 | mQueueBufferOutput.deflate(&tmpW, &tmpH, &transformHint, &numPendingBuffers); |
| 269 | mQueueBufferOutput.inflate(w, h, transformHint, numPendingBuffers); |
| 270 | |
| 271 | mSinkBufferWidth = w; |
| 272 | mSinkBufferHeight = h; |
| 273 | } |
| 274 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 275 | status_t VirtualDisplaySurface::requestBuffer(int pslot, |
| 276 | sp<GraphicBuffer>* outBuf) { |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 277 | if (mDisplayId < 0) |
| 278 | return mSource[SOURCE_SINK]->requestBuffer(pslot, outBuf); |
| 279 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 280 | VDS_LOGW_IF(mDbgState != DBG_STATE_GLES, |
| 281 | "Unexpected requestBuffer pslot=%d in %s state", |
| 282 | pslot, dbgStateStr()); |
| 283 | |
| 284 | *outBuf = mProducerBuffers[pslot]; |
| 285 | return NO_ERROR; |
| 286 | } |
| 287 | |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 288 | status_t VirtualDisplaySurface::setMaxDequeuedBufferCount( |
| 289 | int maxDequeuedBuffers) { |
| 290 | return mSource[SOURCE_SINK]->setMaxDequeuedBufferCount(maxDequeuedBuffers); |
| 291 | } |
| 292 | |
| 293 | status_t VirtualDisplaySurface::setAsyncMode(bool async) { |
| 294 | return mSource[SOURCE_SINK]->setAsyncMode(async); |
| 295 | } |
| 296 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 297 | status_t VirtualDisplaySurface::dequeueBuffer(Source source, |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 298 | PixelFormat format, uint32_t usage, int* sslot, sp<Fence>* fence) { |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 299 | LOG_FATAL_IF(mDisplayId < 0, "mDisplayId=%d but should not be < 0.", mDisplayId); |
Jesse Hall | 8db9255 | 2013-08-29 16:03:50 -0700 | [diff] [blame] | 300 | |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 301 | status_t result = mSource[source]->dequeueBuffer(sslot, fence, |
Jesse Hall | 1e27ba2 | 2013-09-27 09:05:09 -0700 | [diff] [blame] | 302 | mSinkBufferWidth, mSinkBufferHeight, format, usage); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 303 | if (result < 0) |
| 304 | return result; |
| 305 | int pslot = mapSource2ProducerSlot(source, *sslot); |
| 306 | VDS_LOGV("dequeueBuffer(%s): sslot=%d pslot=%d result=%d", |
| 307 | dbgSourceStr(source), *sslot, pslot, result); |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 308 | uint64_t sourceBit = static_cast<uint64_t>(source) << pslot; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 309 | |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 310 | if ((mProducerSlotSource & (1ULL << pslot)) != sourceBit) { |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 311 | // This slot was previously dequeued from the other source; must |
| 312 | // re-request the buffer. |
| 313 | result |= BUFFER_NEEDS_REALLOCATION; |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 314 | mProducerSlotSource &= ~(1ULL << pslot); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 315 | mProducerSlotSource |= sourceBit; |
| 316 | } |
| 317 | |
| 318 | if (result & RELEASE_ALL_BUFFERS) { |
| 319 | for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) { |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 320 | if ((mProducerSlotSource & (1ULL << i)) == sourceBit) |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 321 | mProducerBuffers[i].clear(); |
| 322 | } |
| 323 | } |
| 324 | if (result & BUFFER_NEEDS_REALLOCATION) { |
Jesse Hall | 0b63cd1 | 2014-04-29 16:14:14 -0700 | [diff] [blame] | 325 | result = mSource[source]->requestBuffer(*sslot, &mProducerBuffers[pslot]); |
| 326 | if (result < 0) { |
| 327 | mProducerBuffers[pslot].clear(); |
| 328 | mSource[source]->cancelBuffer(*sslot, *fence); |
| 329 | return result; |
| 330 | } |
Jesse Hall | 497ba0e | 2013-11-04 16:43:03 -0800 | [diff] [blame] | 331 | VDS_LOGV("dequeueBuffer(%s): buffers[%d]=%p fmt=%d usage=%#x", |
| 332 | dbgSourceStr(source), pslot, mProducerBuffers[pslot].get(), |
| 333 | mProducerBuffers[pslot]->getPixelFormat(), |
| 334 | mProducerBuffers[pslot]->getUsage()); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | return result; |
| 338 | } |
| 339 | |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 340 | status_t VirtualDisplaySurface::dequeueBuffer(int* pslot, sp<Fence>* fence, |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 341 | uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) { |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 342 | if (mDisplayId < 0) |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 343 | return mSource[SOURCE_SINK]->dequeueBuffer(pslot, fence, w, h, format, usage); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 344 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 345 | VDS_LOGW_IF(mDbgState != DBG_STATE_PREPARED, |
| 346 | "Unexpected dequeueBuffer() in %s state", dbgStateStr()); |
| 347 | mDbgState = DBG_STATE_GLES; |
| 348 | |
| 349 | VDS_LOGV("dequeueBuffer %dx%d fmt=%d usage=%#x", w, h, format, usage); |
| 350 | |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 351 | status_t result = NO_ERROR; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 352 | Source source = fbSourceForCompositionType(mCompositionType); |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 353 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 354 | if (source == SOURCE_SINK) { |
Mathias Agopian | 6da15f4 | 2013-09-25 20:40:07 -0700 | [diff] [blame] | 355 | |
| 356 | if (mOutputProducerSlot < 0) { |
| 357 | // Last chance bailout if something bad happened earlier. For example, |
| 358 | // in a GLES configuration, if the sink disappears then dequeueBuffer |
| 359 | // will fail, the GLES driver won't queue a buffer, but SurfaceFlinger |
| 360 | // will soldier on. So we end up here without a buffer. There should |
| 361 | // be lots of scary messages in the log just before this. |
| 362 | VDS_LOGE("dequeueBuffer: no buffer, bailing out"); |
| 363 | return NO_MEMORY; |
| 364 | } |
| 365 | |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 366 | // We already dequeued the output buffer. If the GLES driver wants |
| 367 | // something incompatible, we have to cancel and get a new one. This |
| 368 | // will mean that HWC will see a different output buffer between |
| 369 | // prepare and set, but since we're in GLES-only mode already it |
| 370 | // shouldn't matter. |
| 371 | |
Jesse Hall | 1e27ba2 | 2013-09-27 09:05:09 -0700 | [diff] [blame] | 372 | usage |= GRALLOC_USAGE_HW_COMPOSER; |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 373 | const sp<GraphicBuffer>& buf = mProducerBuffers[mOutputProducerSlot]; |
Jesse Hall | 1e27ba2 | 2013-09-27 09:05:09 -0700 | [diff] [blame] | 374 | if ((usage & ~buf->getUsage()) != 0 || |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 375 | (format != 0 && format != buf->getPixelFormat()) || |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 376 | (w != 0 && w != mSinkBufferWidth) || |
| 377 | (h != 0 && h != mSinkBufferHeight)) { |
Jesse Hall | 1e27ba2 | 2013-09-27 09:05:09 -0700 | [diff] [blame] | 378 | VDS_LOGV("dequeueBuffer: dequeueing new output buffer: " |
| 379 | "want %dx%d fmt=%d use=%#x, " |
| 380 | "have %dx%d fmt=%d use=%#x", |
| 381 | w, h, format, usage, |
| 382 | mSinkBufferWidth, mSinkBufferHeight, |
| 383 | buf->getPixelFormat(), buf->getUsage()); |
| 384 | mOutputFormat = format; |
| 385 | mOutputUsage = usage; |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 386 | result = refreshOutputBuffer(); |
| 387 | if (result < 0) |
| 388 | return result; |
| 389 | } |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 392 | if (source == SOURCE_SINK) { |
| 393 | *pslot = mOutputProducerSlot; |
| 394 | *fence = mOutputFence; |
| 395 | } else { |
| 396 | int sslot; |
Jesse Hall | 1e27ba2 | 2013-09-27 09:05:09 -0700 | [diff] [blame] | 397 | result = dequeueBuffer(source, format, usage, &sslot, fence); |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 398 | if (result >= 0) { |
| 399 | *pslot = mapSource2ProducerSlot(source, sslot); |
| 400 | } |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 401 | } |
| 402 | return result; |
| 403 | } |
| 404 | |
Dan Stoza | 88a459a | 2014-03-12 09:34:36 -0700 | [diff] [blame] | 405 | status_t VirtualDisplaySurface::detachBuffer(int /* slot */) { |
| 406 | VDS_LOGE("detachBuffer is not available for VirtualDisplaySurface"); |
| 407 | return INVALID_OPERATION; |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 410 | status_t VirtualDisplaySurface::detachNextBuffer( |
| 411 | sp<GraphicBuffer>* /* outBuffer */, sp<Fence>* /* outFence */) { |
| 412 | VDS_LOGE("detachNextBuffer is not available for VirtualDisplaySurface"); |
| 413 | return INVALID_OPERATION; |
| 414 | } |
| 415 | |
Dan Stoza | 88a459a | 2014-03-12 09:34:36 -0700 | [diff] [blame] | 416 | status_t VirtualDisplaySurface::attachBuffer(int* /* outSlot */, |
| 417 | const sp<GraphicBuffer>& /* buffer */) { |
| 418 | VDS_LOGE("attachBuffer is not available for VirtualDisplaySurface"); |
| 419 | return INVALID_OPERATION; |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 420 | } |
| 421 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 422 | status_t VirtualDisplaySurface::queueBuffer(int pslot, |
| 423 | const QueueBufferInput& input, QueueBufferOutput* output) { |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 424 | if (mDisplayId < 0) |
| 425 | return mSource[SOURCE_SINK]->queueBuffer(pslot, input, output); |
| 426 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 427 | VDS_LOGW_IF(mDbgState != DBG_STATE_GLES, |
| 428 | "Unexpected queueBuffer(pslot=%d) in %s state", pslot, |
| 429 | dbgStateStr()); |
| 430 | mDbgState = DBG_STATE_GLES_DONE; |
| 431 | |
| 432 | VDS_LOGV("queueBuffer pslot=%d", pslot); |
| 433 | |
| 434 | status_t result; |
| 435 | if (mCompositionType == COMPOSITION_MIXED) { |
| 436 | // Queue the buffer back into the scratch pool |
| 437 | QueueBufferOutput scratchQBO; |
| 438 | int sslot = mapProducer2SourceSlot(SOURCE_SCRATCH, pslot); |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 439 | result = mSource[SOURCE_SCRATCH]->queueBuffer(sslot, input, &scratchQBO); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 440 | if (result != NO_ERROR) |
| 441 | return result; |
| 442 | |
| 443 | // Now acquire the buffer from the scratch pool -- should be the same |
| 444 | // slot and fence as we just queued. |
| 445 | Mutex::Autolock lock(mMutex); |
Dan Stoza | 11611f9 | 2015-03-12 15:12:44 -0700 | [diff] [blame] | 446 | BufferItem item; |
Jesse Hall | bce7611 | 2013-07-16 13:46:20 -0700 | [diff] [blame] | 447 | result = acquireBufferLocked(&item, 0); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 448 | if (result != NO_ERROR) |
| 449 | return result; |
Pablo Ceballos | 47650f4 | 2015-08-04 16:38:17 -0700 | [diff] [blame] | 450 | VDS_LOGW_IF(item.mSlot != sslot, |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 451 | "queueBuffer: acquired sslot %d from SCRATCH after queueing sslot %d", |
Pablo Ceballos | 47650f4 | 2015-08-04 16:38:17 -0700 | [diff] [blame] | 452 | item.mSlot, sslot); |
| 453 | mFbProducerSlot = mapSource2ProducerSlot(SOURCE_SCRATCH, item.mSlot); |
| 454 | mFbFence = mSlots[item.mSlot].mFence; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 455 | |
| 456 | } else { |
| 457 | LOG_FATAL_IF(mCompositionType != COMPOSITION_GLES, |
| 458 | "Unexpected queueBuffer in state %s for compositionType %s", |
| 459 | dbgStateStr(), dbgCompositionTypeStr(mCompositionType)); |
| 460 | |
| 461 | // Extract the GLES release fence for HWC to acquire |
| 462 | int64_t timestamp; |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 463 | bool isAutoTimestamp; |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 464 | android_dataspace dataSpace; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 465 | Rect crop; |
| 466 | int scalingMode; |
| 467 | uint32_t transform; |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 468 | input.deflate(×tamp, &isAutoTimestamp, &dataSpace, &crop, |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 469 | &scalingMode, &transform, &mFbFence); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 470 | |
| 471 | mFbProducerSlot = pslot; |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 472 | mOutputFence = mFbFence; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | *output = mQueueBufferOutput; |
| 476 | return NO_ERROR; |
| 477 | } |
| 478 | |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 479 | status_t VirtualDisplaySurface::cancelBuffer(int pslot, |
| 480 | const sp<Fence>& fence) { |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 481 | if (mDisplayId < 0) |
Michael Lentine | fd9d183 | 2014-07-30 15:39:17 -0700 | [diff] [blame] | 482 | return mSource[SOURCE_SINK]->cancelBuffer(mapProducer2SourceSlot(SOURCE_SINK, pslot), fence); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 483 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 484 | VDS_LOGW_IF(mDbgState != DBG_STATE_GLES, |
| 485 | "Unexpected cancelBuffer(pslot=%d) in %s state", pslot, |
| 486 | dbgStateStr()); |
| 487 | VDS_LOGV("cancelBuffer pslot=%d", pslot); |
| 488 | Source source = fbSourceForCompositionType(mCompositionType); |
| 489 | return mSource[source]->cancelBuffer( |
| 490 | mapProducer2SourceSlot(source, pslot), fence); |
| 491 | } |
| 492 | |
| 493 | int VirtualDisplaySurface::query(int what, int* value) { |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 494 | switch (what) { |
| 495 | case NATIVE_WINDOW_WIDTH: |
| 496 | *value = mSinkBufferWidth; |
| 497 | break; |
| 498 | case NATIVE_WINDOW_HEIGHT: |
| 499 | *value = mSinkBufferHeight; |
| 500 | break; |
| 501 | default: |
| 502 | return mSource[SOURCE_SINK]->query(what, value); |
| 503 | } |
| 504 | return NO_ERROR; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 507 | status_t VirtualDisplaySurface::connect(const sp<IProducerListener>& listener, |
Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 508 | int api, bool producerControlledByApp, |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 509 | QueueBufferOutput* output) { |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 510 | QueueBufferOutput qbo; |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 511 | status_t result = mSource[SOURCE_SINK]->connect(listener, api, |
| 512 | producerControlledByApp, &qbo); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 513 | if (result == NO_ERROR) { |
| 514 | updateQueueBufferOutput(qbo); |
| 515 | *output = mQueueBufferOutput; |
| 516 | } |
| 517 | return result; |
| 518 | } |
| 519 | |
| 520 | status_t VirtualDisplaySurface::disconnect(int api) { |
| 521 | return mSource[SOURCE_SINK]->disconnect(api); |
| 522 | } |
| 523 | |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 524 | status_t VirtualDisplaySurface::setSidebandStream(const sp<NativeHandle>& /*stream*/) { |
| 525 | return INVALID_OPERATION; |
| 526 | } |
| 527 | |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 528 | void VirtualDisplaySurface::allocateBuffers(uint32_t /* width */, |
| 529 | uint32_t /* height */, PixelFormat /* format */, uint32_t /* usage */) { |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 530 | // TODO: Should we actually allocate buffers for a virtual display? |
| 531 | } |
| 532 | |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 533 | status_t VirtualDisplaySurface::allowAllocation(bool /* allow */) { |
| 534 | return INVALID_OPERATION; |
| 535 | } |
| 536 | |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 537 | status_t VirtualDisplaySurface::setGenerationNumber(uint32_t /* generation */) { |
| 538 | ALOGE("setGenerationNumber not supported on VirtualDisplaySurface"); |
| 539 | return INVALID_OPERATION; |
| 540 | } |
| 541 | |
Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 542 | String8 VirtualDisplaySurface::getConsumerName() const { |
| 543 | return String8("VirtualDisplaySurface"); |
| 544 | } |
| 545 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 546 | uint64_t VirtualDisplaySurface::getNextFrameNumber() const { |
| 547 | return 0; |
| 548 | } |
| 549 | |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 550 | status_t VirtualDisplaySurface::setSingleBufferMode(bool /*singleBufferMode*/) { |
| 551 | ALOGE("setSingleBufferMode not supported on VirtualDisplaySurface"); |
| 552 | return INVALID_OPERATION; |
| 553 | } |
| 554 | |
| 555 | status_t VirtualDisplaySurface::setAutoRefresh(bool /*autoRefresh*/) { |
| 556 | ALOGE("setAutoRefresh not supported on VirtualDisplaySurface"); |
| 557 | return INVALID_OPERATION; |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 560 | status_t VirtualDisplaySurface::setDequeueTimeout(nsecs_t /* timeout */) { |
| 561 | ALOGE("setDequeueTimeout not supported on VirtualDisplaySurface"); |
| 562 | return INVALID_OPERATION; |
| 563 | } |
| 564 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 565 | void VirtualDisplaySurface::updateQueueBufferOutput( |
| 566 | const QueueBufferOutput& qbo) { |
| 567 | uint32_t w, h, transformHint, numPendingBuffers; |
| 568 | qbo.deflate(&w, &h, &transformHint, &numPendingBuffers); |
| 569 | mQueueBufferOutput.inflate(w, h, 0, numPendingBuffers); |
| 570 | } |
| 571 | |
| 572 | void VirtualDisplaySurface::resetPerFrameState() { |
| 573 | mCompositionType = COMPOSITION_UNKNOWN; |
mayank parshar | b988f85 | 2014-01-10 10:27:45 +0530 | [diff] [blame] | 574 | mFbFence = Fence::NO_FENCE; |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 575 | mOutputFence = Fence::NO_FENCE; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 576 | mOutputProducerSlot = -1; |
mayank parshar | fdfde88 | 2014-01-23 15:08:31 +0530 | [diff] [blame] | 577 | mFbProducerSlot = -1; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 580 | status_t VirtualDisplaySurface::refreshOutputBuffer() { |
| 581 | if (mOutputProducerSlot >= 0) { |
| 582 | mSource[SOURCE_SINK]->cancelBuffer( |
| 583 | mapProducer2SourceSlot(SOURCE_SINK, mOutputProducerSlot), |
| 584 | mOutputFence); |
| 585 | } |
| 586 | |
| 587 | int sslot; |
Jesse Hall | 1e27ba2 | 2013-09-27 09:05:09 -0700 | [diff] [blame] | 588 | status_t result = dequeueBuffer(SOURCE_SINK, mOutputFormat, mOutputUsage, |
| 589 | &sslot, &mOutputFence); |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 590 | if (result < 0) |
| 591 | return result; |
| 592 | mOutputProducerSlot = mapSource2ProducerSlot(SOURCE_SINK, sslot); |
| 593 | |
Jesse Hall | b716e57 | 2013-10-01 17:25:20 -0700 | [diff] [blame] | 594 | // On GLES-only frames, we don't have the right output buffer acquire fence |
| 595 | // until after GLES calls queueBuffer(). So here we just set the buffer |
| 596 | // (for use in HWC prepare) but not the fence; we'll call this again with |
| 597 | // the proper fence once we have it. |
| 598 | result = mHwc.setOutputBuffer(mDisplayId, Fence::NO_FENCE, |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 599 | mProducerBuffers[mOutputProducerSlot]); |
| 600 | |
| 601 | return result; |
| 602 | } |
| 603 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 604 | // This slot mapping function is its own inverse, so two copies are unnecessary. |
| 605 | // Both are kept to make the intent clear where the function is called, and for |
| 606 | // the (unlikely) chance that we switch to a different mapping function. |
| 607 | int VirtualDisplaySurface::mapSource2ProducerSlot(Source source, int sslot) { |
| 608 | if (source == SOURCE_SCRATCH) { |
| 609 | return BufferQueue::NUM_BUFFER_SLOTS - sslot - 1; |
| 610 | } else { |
| 611 | return sslot; |
| 612 | } |
| 613 | } |
| 614 | int VirtualDisplaySurface::mapProducer2SourceSlot(Source source, int pslot) { |
| 615 | return mapSource2ProducerSlot(source, pslot); |
| 616 | } |
| 617 | |
| 618 | VirtualDisplaySurface::Source |
| 619 | VirtualDisplaySurface::fbSourceForCompositionType(CompositionType type) { |
| 620 | return type == COMPOSITION_MIXED ? SOURCE_SCRATCH : SOURCE_SINK; |
| 621 | } |
| 622 | |
| 623 | const char* VirtualDisplaySurface::dbgStateStr() const { |
| 624 | switch (mDbgState) { |
| 625 | case DBG_STATE_IDLE: return "IDLE"; |
| 626 | case DBG_STATE_PREPARED: return "PREPARED"; |
| 627 | case DBG_STATE_GLES: return "GLES"; |
| 628 | case DBG_STATE_GLES_DONE: return "GLES_DONE"; |
| 629 | case DBG_STATE_HWC: return "HWC"; |
| 630 | default: return "INVALID"; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | const char* VirtualDisplaySurface::dbgSourceStr(Source s) { |
| 635 | switch (s) { |
| 636 | case SOURCE_SINK: return "SINK"; |
| 637 | case SOURCE_SCRATCH: return "SCRATCH"; |
| 638 | default: return "INVALID"; |
| 639 | } |
| 640 | } |
| 641 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 642 | // --------------------------------------------------------------------------- |
| 643 | } // namespace android |
| 644 | // --------------------------------------------------------------------------- |