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