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 // #define LOG_NDEBUG 0
18 #include "VirtualDisplaySurface.h"
19 #include "HWComposer.h"
21 #include <gui/BufferItem.h>
22 #include <gui/IProducerListener.h>
24 // ---------------------------------------------------------------------------
26 // ---------------------------------------------------------------------------
28 #if defined(FORCE_HWC_COPY_FOR_VIRTUAL_DISPLAYS)
29 static const bool sForceHwcCopy = true;
31 static const bool sForceHwcCopy = false;
34 #define VDS_LOGE(msg, ...) ALOGE("[%s] " msg, \
35 mDisplayName.string(), ##__VA_ARGS__)
36 #define VDS_LOGW_IF(cond, msg, ...) ALOGW_IF(cond, "[%s] " msg, \
37 mDisplayName.string(), ##__VA_ARGS__)
38 #define VDS_LOGV(msg, ...) ALOGV("[%s] " msg, \
39 mDisplayName.string(), ##__VA_ARGS__)
41 static const char* dbgCompositionTypeStr(DisplaySurface::CompositionType 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>";
51 VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int32_t dispId,
52 const sp<IGraphicBufferProducer>& sink,
53 const sp<IGraphicBufferProducer>& bqProducer,
54 const sp<IGraphicBufferConsumer>& bqConsumer,
56 : ConsumerBase(bqConsumer),
61 mDefaultOutputFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED),
62 mOutputFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED),
63 mOutputUsage(GRALLOC_USAGE_HW_COMPOSER),
64 mProducerSlotSource(0),
69 mCompositionType(COMPOSITION_UNKNOWN),
70 mFbFence(Fence::NO_FENCE),
71 mOutputFence(Fence::NO_FENCE),
72 mFbProducerSlot(BufferQueue::INVALID_BUFFER_SLOT),
73 mOutputProducerSlot(BufferQueue::INVALID_BUFFER_SLOT),
74 mDbgState(DBG_STATE_IDLE),
75 mDbgLastCompositionType(COMPOSITION_UNKNOWN),
78 mSource[SOURCE_SINK] = sink;
79 mSource[SOURCE_SCRATCH] = bqProducer;
83 int sinkWidth, sinkHeight;
84 sink->query(NATIVE_WINDOW_WIDTH, &sinkWidth);
85 sink->query(NATIVE_WINDOW_HEIGHT, &sinkHeight);
86 mSinkBufferWidth = sinkWidth;
87 mSinkBufferHeight = sinkHeight;
89 // Pick the buffer format to request from the sink when not rendering to it
90 // with GLES. If the consumer needs CPU access, use the default format
91 // set by the consumer. Otherwise allow gralloc to decide the format based
94 sink->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, &sinkUsage);
95 if (sinkUsage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) {
97 sink->query(NATIVE_WINDOW_FORMAT, &sinkFormat);
98 mDefaultOutputFormat = sinkFormat;
100 mDefaultOutputFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
102 mOutputFormat = mDefaultOutputFormat;
104 ConsumerBase::mName = String8::format("VDS: %s", mDisplayName.string());
105 mConsumer->setConsumerName(ConsumerBase::mName);
106 mConsumer->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER);
107 mConsumer->setDefaultBufferSize(sinkWidth, sinkHeight);
108 sink->setAsyncMode(true);
109 IGraphicBufferProducer::QueueBufferOutput output;
110 mSource[SOURCE_SCRATCH]->connect(NULL, NATIVE_WINDOW_API_EGL, false, &output);
113 VirtualDisplaySurface::~VirtualDisplaySurface() {
114 mSource[SOURCE_SCRATCH]->disconnect(NATIVE_WINDOW_API_EGL);
117 status_t VirtualDisplaySurface::beginFrame(bool mustRecompose) {
121 mMustRecompose = mustRecompose;
123 VDS_LOGW_IF(mDbgState != DBG_STATE_IDLE,
124 "Unexpected beginFrame() in %s state", dbgStateStr());
125 mDbgState = DBG_STATE_BEGUN;
127 return refreshOutputBuffer();
130 status_t VirtualDisplaySurface::prepareFrame(CompositionType compositionType) {
134 VDS_LOGW_IF(mDbgState != DBG_STATE_BEGUN,
135 "Unexpected prepareFrame() in %s state", dbgStateStr());
136 mDbgState = DBG_STATE_PREPARED;
138 mCompositionType = compositionType;
139 if (sForceHwcCopy && mCompositionType == COMPOSITION_GLES) {
140 // Some hardware can do RGB->YUV conversion more efficiently in hardware
141 // controlled by HWC than in hardware controlled by the video encoder.
142 // Forcing GLES-composed frames to go through an extra copy by the HWC
143 // allows the format conversion to happen there, rather than passing RGB
144 // directly to the consumer.
146 // On the other hand, when the consumer prefers RGB or can consume RGB
147 // inexpensively, this forces an unnecessary copy.
148 mCompositionType = COMPOSITION_MIXED;
151 if (mCompositionType != mDbgLastCompositionType) {
152 VDS_LOGV("prepareFrame: composition type changed to %s",
153 dbgCompositionTypeStr(mCompositionType));
154 mDbgLastCompositionType = mCompositionType;
157 if (mCompositionType != COMPOSITION_GLES &&
158 (mOutputFormat != mDefaultOutputFormat ||
159 mOutputUsage != GRALLOC_USAGE_HW_COMPOSER)) {
160 // We must have just switched from GLES-only to MIXED or HWC
161 // composition. Stop using the format and usage requested by the GLES
162 // driver; they may be suboptimal when HWC is writing to the output
163 // buffer. For example, if the output is going to a video encoder, and
164 // HWC can write directly to YUV, some hardware can skip a
165 // memory-to-memory RGB-to-YUV conversion step.
167 // If we just switched *to* GLES-only mode, we'll change the
168 // format/usage and get a new buffer when the GLES driver calls
170 mOutputFormat = mDefaultOutputFormat;
171 mOutputUsage = GRALLOC_USAGE_HW_COMPOSER;
172 refreshOutputBuffer();
179 status_t VirtualDisplaySurface::compositionComplete() {
184 status_t VirtualDisplaySurface::advanceFrame() {
188 if (mCompositionType == COMPOSITION_HWC) {
189 VDS_LOGW_IF(mDbgState != DBG_STATE_PREPARED,
190 "Unexpected advanceFrame() in %s state on HWC frame",
193 VDS_LOGW_IF(mDbgState != DBG_STATE_GLES_DONE,
194 "Unexpected advanceFrame() in %s state on GLES/MIXED frame",
197 mDbgState = DBG_STATE_HWC;
199 if (mOutputProducerSlot < 0 ||
200 (mCompositionType != COMPOSITION_HWC && mFbProducerSlot < 0)) {
201 // Last chance bailout if something bad happened earlier. For example,
202 // in a GLES configuration, if the sink disappears then dequeueBuffer
203 // will fail, the GLES driver won't queue a buffer, but SurfaceFlinger
204 // will soldier on. So we end up here without a buffer. There should
205 // be lots of scary messages in the log just before this.
206 VDS_LOGE("advanceFrame: no buffer, bailing out");
210 sp<GraphicBuffer> fbBuffer = mFbProducerSlot >= 0 ?
211 mProducerBuffers[mFbProducerSlot] : sp<GraphicBuffer>(NULL);
212 sp<GraphicBuffer> outBuffer = mProducerBuffers[mOutputProducerSlot];
213 VDS_LOGV("advanceFrame: fb=%d(%p) out=%d(%p)",
214 mFbProducerSlot, fbBuffer.get(),
215 mOutputProducerSlot, outBuffer.get());
217 // At this point we know the output buffer acquire fence,
218 // so update HWC state with it.
219 mHwc.setOutputBuffer(mDisplayId, mOutputFence, outBuffer);
221 status_t result = NO_ERROR;
222 if (fbBuffer != NULL) {
224 // TODO: Correctly propagate the dataspace from GL composition
225 result = mHwc.setClientTarget(mDisplayId, mFbFence, fbBuffer,
226 HAL_DATASPACE_UNKNOWN);
228 result = mHwc.fbPost(mDisplayId, mFbFence, fbBuffer);
235 void VirtualDisplaySurface::onFrameCommitted() {
239 VDS_LOGW_IF(mDbgState != DBG_STATE_HWC,
240 "Unexpected onFrameCommitted() in %s state", dbgStateStr());
241 mDbgState = DBG_STATE_IDLE;
244 sp<Fence> retireFence = mHwc.getRetireFence(mDisplayId);
246 sp<Fence> fbFence = mHwc.getAndResetReleaseFence(mDisplayId);
248 if (mCompositionType == COMPOSITION_MIXED && mFbProducerSlot >= 0) {
249 // release the scratch buffer back to the pool
250 Mutex::Autolock lock(mMutex);
251 int sslot = mapProducer2SourceSlot(SOURCE_SCRATCH, mFbProducerSlot);
252 VDS_LOGV("onFrameCommitted: release scratch sslot=%d", sslot);
254 addReleaseFenceLocked(sslot, mProducerBuffers[mFbProducerSlot],
257 addReleaseFenceLocked(sslot, mProducerBuffers[mFbProducerSlot], fbFence);
259 releaseBufferLocked(sslot, mProducerBuffers[mFbProducerSlot],
260 EGL_NO_DISPLAY, EGL_NO_SYNC_KHR);
263 if (mOutputProducerSlot >= 0) {
264 int sslot = mapProducer2SourceSlot(SOURCE_SINK, mOutputProducerSlot);
265 QueueBufferOutput qbo;
267 sp<Fence> outFence = mHwc.getLastRetireFence(mDisplayId);
269 VDS_LOGV("onFrameCommitted: queue sink sslot=%d", sslot);
270 if (mMustRecompose) {
271 status_t result = mSource[SOURCE_SINK]->queueBuffer(sslot,
273 systemTime(), false /* isAutoTimestamp */,
274 HAL_DATASPACE_UNKNOWN,
275 Rect(mSinkBufferWidth, mSinkBufferHeight),
276 NATIVE_WINDOW_SCALING_MODE_FREEZE, 0 /* transform */,
283 if (result == NO_ERROR) {
284 updateQueueBufferOutput(qbo);
287 // If the surface hadn't actually been updated, then we only went
288 // through the motions of updating the display to keep our state
289 // machine happy. We cancel the buffer to avoid triggering another
290 // re-composition and causing an infinite loop.
292 mSource[SOURCE_SINK]->cancelBuffer(sslot, retireFence);
294 mSource[SOURCE_SINK]->cancelBuffer(sslot, outFence);
299 resetPerFrameState();
302 void VirtualDisplaySurface::dumpAsString(String8& /* result */) const {
305 void VirtualDisplaySurface::resizeBuffers(const uint32_t w, const uint32_t h) {
306 uint32_t tmpW, tmpH, transformHint, numPendingBuffers;
307 uint64_t nextFrameNumber;
308 mQueueBufferOutput.deflate(&tmpW, &tmpH, &transformHint, &numPendingBuffers,
310 mQueueBufferOutput.inflate(w, h, transformHint, numPendingBuffers,
313 mSinkBufferWidth = w;
314 mSinkBufferHeight = h;
317 const sp<Fence>& VirtualDisplaySurface::getClientTargetAcquireFence() const {
321 status_t VirtualDisplaySurface::requestBuffer(int pslot,
322 sp<GraphicBuffer>* outBuf) {
324 return mSource[SOURCE_SINK]->requestBuffer(pslot, outBuf);
326 VDS_LOGW_IF(mDbgState != DBG_STATE_GLES,
327 "Unexpected requestBuffer pslot=%d in %s state",
328 pslot, dbgStateStr());
330 *outBuf = mProducerBuffers[pslot];
334 status_t VirtualDisplaySurface::setMaxDequeuedBufferCount(
335 int maxDequeuedBuffers) {
336 return mSource[SOURCE_SINK]->setMaxDequeuedBufferCount(maxDequeuedBuffers);
339 status_t VirtualDisplaySurface::setAsyncMode(bool async) {
340 return mSource[SOURCE_SINK]->setAsyncMode(async);
343 status_t VirtualDisplaySurface::dequeueBuffer(Source source,
344 PixelFormat format, uint32_t usage, int* sslot, sp<Fence>* fence) {
345 LOG_FATAL_IF(mDisplayId < 0, "mDisplayId=%d but should not be < 0.", mDisplayId);
347 status_t result = mSource[source]->dequeueBuffer(sslot, fence,
348 mSinkBufferWidth, mSinkBufferHeight, format, usage);
351 int pslot = mapSource2ProducerSlot(source, *sslot);
352 VDS_LOGV("dequeueBuffer(%s): sslot=%d pslot=%d result=%d",
353 dbgSourceStr(source), *sslot, pslot, result);
354 uint64_t sourceBit = static_cast<uint64_t>(source) << pslot;
356 if ((mProducerSlotSource & (1ULL << pslot)) != sourceBit) {
357 // This slot was previously dequeued from the other source; must
358 // re-request the buffer.
359 result |= BUFFER_NEEDS_REALLOCATION;
360 mProducerSlotSource &= ~(1ULL << pslot);
361 mProducerSlotSource |= sourceBit;
364 if (result & RELEASE_ALL_BUFFERS) {
365 for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
366 if ((mProducerSlotSource & (1ULL << i)) == sourceBit)
367 mProducerBuffers[i].clear();
370 if (result & BUFFER_NEEDS_REALLOCATION) {
371 result = mSource[source]->requestBuffer(*sslot, &mProducerBuffers[pslot]);
373 mProducerBuffers[pslot].clear();
374 mSource[source]->cancelBuffer(*sslot, *fence);
377 VDS_LOGV("dequeueBuffer(%s): buffers[%d]=%p fmt=%d usage=%#x",
378 dbgSourceStr(source), pslot, mProducerBuffers[pslot].get(),
379 mProducerBuffers[pslot]->getPixelFormat(),
380 mProducerBuffers[pslot]->getUsage());
386 status_t VirtualDisplaySurface::dequeueBuffer(int* pslot, sp<Fence>* fence,
387 uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) {
389 return mSource[SOURCE_SINK]->dequeueBuffer(pslot, fence, w, h, format, usage);
391 VDS_LOGW_IF(mDbgState != DBG_STATE_PREPARED,
392 "Unexpected dequeueBuffer() in %s state", dbgStateStr());
393 mDbgState = DBG_STATE_GLES;
395 VDS_LOGV("dequeueBuffer %dx%d fmt=%d usage=%#x", w, h, format, usage);
397 status_t result = NO_ERROR;
398 Source source = fbSourceForCompositionType(mCompositionType);
400 if (source == SOURCE_SINK) {
402 if (mOutputProducerSlot < 0) {
403 // Last chance bailout if something bad happened earlier. For example,
404 // in a GLES configuration, if the sink disappears then dequeueBuffer
405 // will fail, the GLES driver won't queue a buffer, but SurfaceFlinger
406 // will soldier on. So we end up here without a buffer. There should
407 // be lots of scary messages in the log just before this.
408 VDS_LOGE("dequeueBuffer: no buffer, bailing out");
412 // We already dequeued the output buffer. If the GLES driver wants
413 // something incompatible, we have to cancel and get a new one. This
414 // will mean that HWC will see a different output buffer between
415 // prepare and set, but since we're in GLES-only mode already it
418 usage |= GRALLOC_USAGE_HW_COMPOSER;
419 const sp<GraphicBuffer>& buf = mProducerBuffers[mOutputProducerSlot];
420 if ((usage & ~buf->getUsage()) != 0 ||
421 (format != 0 && format != buf->getPixelFormat()) ||
422 (w != 0 && w != mSinkBufferWidth) ||
423 (h != 0 && h != mSinkBufferHeight)) {
424 VDS_LOGV("dequeueBuffer: dequeueing new output buffer: "
425 "want %dx%d fmt=%d use=%#x, "
426 "have %dx%d fmt=%d use=%#x",
428 mSinkBufferWidth, mSinkBufferHeight,
429 buf->getPixelFormat(), buf->getUsage());
430 mOutputFormat = format;
431 mOutputUsage = usage;
432 result = refreshOutputBuffer();
438 if (source == SOURCE_SINK) {
439 *pslot = mOutputProducerSlot;
440 *fence = mOutputFence;
443 result = dequeueBuffer(source, format, usage, &sslot, fence);
445 *pslot = mapSource2ProducerSlot(source, sslot);
451 status_t VirtualDisplaySurface::detachBuffer(int /* slot */) {
452 VDS_LOGE("detachBuffer is not available for VirtualDisplaySurface");
453 return INVALID_OPERATION;
456 status_t VirtualDisplaySurface::detachNextBuffer(
457 sp<GraphicBuffer>* /* outBuffer */, sp<Fence>* /* outFence */) {
458 VDS_LOGE("detachNextBuffer is not available for VirtualDisplaySurface");
459 return INVALID_OPERATION;
462 status_t VirtualDisplaySurface::attachBuffer(int* /* outSlot */,
463 const sp<GraphicBuffer>& /* buffer */) {
464 VDS_LOGE("attachBuffer is not available for VirtualDisplaySurface");
465 return INVALID_OPERATION;
468 status_t VirtualDisplaySurface::queueBuffer(int pslot,
469 const QueueBufferInput& input, QueueBufferOutput* output) {
471 return mSource[SOURCE_SINK]->queueBuffer(pslot, input, output);
473 VDS_LOGW_IF(mDbgState != DBG_STATE_GLES,
474 "Unexpected queueBuffer(pslot=%d) in %s state", pslot,
476 mDbgState = DBG_STATE_GLES_DONE;
478 VDS_LOGV("queueBuffer pslot=%d", pslot);
481 if (mCompositionType == COMPOSITION_MIXED) {
482 // Queue the buffer back into the scratch pool
483 QueueBufferOutput scratchQBO;
484 int sslot = mapProducer2SourceSlot(SOURCE_SCRATCH, pslot);
485 result = mSource[SOURCE_SCRATCH]->queueBuffer(sslot, input, &scratchQBO);
486 if (result != NO_ERROR)
489 // Now acquire the buffer from the scratch pool -- should be the same
490 // slot and fence as we just queued.
491 Mutex::Autolock lock(mMutex);
493 result = acquireBufferLocked(&item, 0);
494 if (result != NO_ERROR)
496 VDS_LOGW_IF(item.mSlot != sslot,
497 "queueBuffer: acquired sslot %d from SCRATCH after queueing sslot %d",
499 mFbProducerSlot = mapSource2ProducerSlot(SOURCE_SCRATCH, item.mSlot);
500 mFbFence = mSlots[item.mSlot].mFence;
503 LOG_FATAL_IF(mCompositionType != COMPOSITION_GLES,
504 "Unexpected queueBuffer in state %s for compositionType %s",
505 dbgStateStr(), dbgCompositionTypeStr(mCompositionType));
507 // Extract the GLES release fence for HWC to acquire
509 bool isAutoTimestamp;
510 android_dataspace dataSpace;
514 input.deflate(×tamp, &isAutoTimestamp, &dataSpace, &crop,
515 &scalingMode, &transform, &mFbFence);
517 mFbProducerSlot = pslot;
518 mOutputFence = mFbFence;
521 *output = mQueueBufferOutput;
525 status_t VirtualDisplaySurface::cancelBuffer(int pslot,
526 const sp<Fence>& fence) {
528 return mSource[SOURCE_SINK]->cancelBuffer(mapProducer2SourceSlot(SOURCE_SINK, pslot), fence);
530 VDS_LOGW_IF(mDbgState != DBG_STATE_GLES,
531 "Unexpected cancelBuffer(pslot=%d) in %s state", pslot,
533 VDS_LOGV("cancelBuffer pslot=%d", pslot);
534 Source source = fbSourceForCompositionType(mCompositionType);
535 return mSource[source]->cancelBuffer(
536 mapProducer2SourceSlot(source, pslot), fence);
539 int VirtualDisplaySurface::query(int what, int* value) {
541 case NATIVE_WINDOW_WIDTH:
542 *value = mSinkBufferWidth;
544 case NATIVE_WINDOW_HEIGHT:
545 *value = mSinkBufferHeight;
548 return mSource[SOURCE_SINK]->query(what, value);
553 status_t VirtualDisplaySurface::connect(const sp<IProducerListener>& listener,
554 int api, bool producerControlledByApp,
555 QueueBufferOutput* output) {
556 QueueBufferOutput qbo;
557 status_t result = mSource[SOURCE_SINK]->connect(listener, api,
558 producerControlledByApp, &qbo);
559 if (result == NO_ERROR) {
560 updateQueueBufferOutput(qbo);
561 *output = mQueueBufferOutput;
566 status_t VirtualDisplaySurface::disconnect(int api, DisconnectMode mode) {
567 return mSource[SOURCE_SINK]->disconnect(api, mode);
570 status_t VirtualDisplaySurface::setSidebandStream(const sp<NativeHandle>& /*stream*/) {
571 return INVALID_OPERATION;
574 void VirtualDisplaySurface::allocateBuffers(uint32_t /* width */,
575 uint32_t /* height */, PixelFormat /* format */, uint32_t /* usage */) {
576 // TODO: Should we actually allocate buffers for a virtual display?
579 status_t VirtualDisplaySurface::allowAllocation(bool /* allow */) {
580 return INVALID_OPERATION;
583 status_t VirtualDisplaySurface::setGenerationNumber(uint32_t /* generation */) {
584 ALOGE("setGenerationNumber not supported on VirtualDisplaySurface");
585 return INVALID_OPERATION;
588 String8 VirtualDisplaySurface::getConsumerName() const {
589 return String8("VirtualDisplaySurface");
592 status_t VirtualDisplaySurface::setSharedBufferMode(bool /*sharedBufferMode*/) {
593 ALOGE("setSharedBufferMode not supported on VirtualDisplaySurface");
594 return INVALID_OPERATION;
597 status_t VirtualDisplaySurface::setAutoRefresh(bool /*autoRefresh*/) {
598 ALOGE("setAutoRefresh not supported on VirtualDisplaySurface");
599 return INVALID_OPERATION;
602 status_t VirtualDisplaySurface::setDequeueTimeout(nsecs_t /* timeout */) {
603 ALOGE("setDequeueTimeout not supported on VirtualDisplaySurface");
604 return INVALID_OPERATION;
607 status_t VirtualDisplaySurface::getLastQueuedBuffer(
608 sp<GraphicBuffer>* /*outBuffer*/, sp<Fence>* /*outFence*/,
609 float[16] /* outTransformMatrix*/) {
610 ALOGE("getLastQueuedBuffer not supported on VirtualDisplaySurface");
611 return INVALID_OPERATION;
614 status_t VirtualDisplaySurface::getUniqueId(uint64_t* /*outId*/) const {
615 ALOGE("getUniqueId not supported on VirtualDisplaySurface");
616 return INVALID_OPERATION;
619 void VirtualDisplaySurface::updateQueueBufferOutput(
620 const QueueBufferOutput& qbo) {
621 uint32_t w, h, transformHint, numPendingBuffers;
622 uint64_t nextFrameNumber;
623 qbo.deflate(&w, &h, &transformHint, &numPendingBuffers, &nextFrameNumber);
624 mQueueBufferOutput.inflate(w, h, 0, numPendingBuffers, nextFrameNumber);
627 void VirtualDisplaySurface::resetPerFrameState() {
628 mCompositionType = COMPOSITION_UNKNOWN;
629 mFbFence = Fence::NO_FENCE;
630 mOutputFence = Fence::NO_FENCE;
631 mOutputProducerSlot = -1;
632 mFbProducerSlot = -1;
635 status_t VirtualDisplaySurface::refreshOutputBuffer() {
636 if (mOutputProducerSlot >= 0) {
637 mSource[SOURCE_SINK]->cancelBuffer(
638 mapProducer2SourceSlot(SOURCE_SINK, mOutputProducerSlot),
643 status_t result = dequeueBuffer(SOURCE_SINK, mOutputFormat, mOutputUsage,
644 &sslot, &mOutputFence);
647 mOutputProducerSlot = mapSource2ProducerSlot(SOURCE_SINK, sslot);
649 // On GLES-only frames, we don't have the right output buffer acquire fence
650 // until after GLES calls queueBuffer(). So here we just set the buffer
651 // (for use in HWC prepare) but not the fence; we'll call this again with
652 // the proper fence once we have it.
653 result = mHwc.setOutputBuffer(mDisplayId, Fence::NO_FENCE,
654 mProducerBuffers[mOutputProducerSlot]);
659 // This slot mapping function is its own inverse, so two copies are unnecessary.
660 // Both are kept to make the intent clear where the function is called, and for
661 // the (unlikely) chance that we switch to a different mapping function.
662 int VirtualDisplaySurface::mapSource2ProducerSlot(Source source, int sslot) {
663 if (source == SOURCE_SCRATCH) {
664 return BufferQueue::NUM_BUFFER_SLOTS - sslot - 1;
669 int VirtualDisplaySurface::mapProducer2SourceSlot(Source source, int pslot) {
670 return mapSource2ProducerSlot(source, pslot);
673 VirtualDisplaySurface::Source
674 VirtualDisplaySurface::fbSourceForCompositionType(CompositionType type) {
675 return type == COMPOSITION_MIXED ? SOURCE_SCRATCH : SOURCE_SINK;
678 const char* VirtualDisplaySurface::dbgStateStr() const {
680 case DBG_STATE_IDLE: return "IDLE";
681 case DBG_STATE_PREPARED: return "PREPARED";
682 case DBG_STATE_GLES: return "GLES";
683 case DBG_STATE_GLES_DONE: return "GLES_DONE";
684 case DBG_STATE_HWC: return "HWC";
685 default: return "INVALID";
689 const char* VirtualDisplaySurface::dbgSourceStr(Source s) {
691 case SOURCE_SINK: return "SINK";
692 case SOURCE_SCRATCH: return "SCRATCH";
693 default: return "INVALID";
697 // ---------------------------------------------------------------------------
698 } // namespace android
699 // ---------------------------------------------------------------------------