2013-03-14 21:29:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
// #define LOG_NDEBUG 0
|
2013-03-14 21:29:29 +00:00
|
|
|
#include "VirtualDisplaySurface.h"
|
2013-04-07 06:12:29 +00:00
|
|
|
#include "HWComposer.h"
|
2013-03-14 21:29:29 +00:00
|
|
|
|
2015-03-12 22:12:44 +00:00
|
|
|
#include <gui/BufferItem.h>
|
|
|
|
|
2013-03-14 21:29:29 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
namespace android {
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2013-10-25 17:44:41 +00:00
|
|
|
#if defined(FORCE_HWC_COPY_FOR_VIRTUAL_DISPLAYS)
|
|
|
|
static const bool sForceHwcCopy = true;
|
|
|
|
#else
|
|
|
|
static const bool sForceHwcCopy = false;
|
|
|
|
#endif
|
2013-10-04 20:15:22 +00:00
|
|
|
|
2014-07-13 21:37:16 +00:00
|
|
|
#define VDS_LOGE(msg, ...) ALOGE("[%s] " msg, \
|
2013-04-07 06:12:29 +00:00
|
|
|
mDisplayName.string(), ##__VA_ARGS__)
|
2014-07-13 21:37:16 +00:00
|
|
|
#define VDS_LOGW_IF(cond, msg, ...) ALOGW_IF(cond, "[%s] " msg, \
|
2013-04-07 06:12:29 +00:00
|
|
|
mDisplayName.string(), ##__VA_ARGS__)
|
2014-07-13 21:37:16 +00:00
|
|
|
#define VDS_LOGV(msg, ...) ALOGV("[%s] " msg, \
|
2013-04-07 06:12:29 +00:00
|
|
|
mDisplayName.string(), ##__VA_ARGS__)
|
|
|
|
|
|
|
|
static const char* dbgCompositionTypeStr(DisplaySurface::CompositionType type) {
|
|
|
|
switch (type) {
|
|
|
|
case DisplaySurface::COMPOSITION_UNKNOWN: return "UNKNOWN";
|
|
|
|
case DisplaySurface::COMPOSITION_GLES: return "GLES";
|
|
|
|
case DisplaySurface::COMPOSITION_HWC: return "HWC";
|
|
|
|
case DisplaySurface::COMPOSITION_MIXED: return "MIXED";
|
|
|
|
default: return "<INVALID>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 22:13:48 +00:00
|
|
|
VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int32_t dispId,
|
2013-08-02 08:40:18 +00:00
|
|
|
const sp<IGraphicBufferProducer>& sink,
|
2014-03-13 18:55:57 +00:00
|
|
|
const sp<IGraphicBufferProducer>& bqProducer,
|
|
|
|
const sp<IGraphicBufferConsumer>& bqConsumer,
|
2013-08-02 08:40:18 +00:00
|
|
|
const String8& name)
|
2014-03-13 18:55:57 +00:00
|
|
|
: ConsumerBase(bqConsumer),
|
2013-04-07 06:12:29 +00:00
|
|
|
mHwc(hwc),
|
|
|
|
mDisplayId(dispId),
|
|
|
|
mDisplayName(name),
|
2013-09-27 16:05:09 +00:00
|
|
|
mOutputUsage(GRALLOC_USAGE_HW_COMPOSER),
|
2013-04-07 06:12:29 +00:00
|
|
|
mProducerSlotSource(0),
|
|
|
|
mDbgState(DBG_STATE_IDLE),
|
2014-02-05 00:22:36 +00:00
|
|
|
mDbgLastCompositionType(COMPOSITION_UNKNOWN),
|
|
|
|
mMustRecompose(false)
|
2013-03-22 22:13:48 +00:00
|
|
|
{
|
2013-04-07 06:12:29 +00:00
|
|
|
mSource[SOURCE_SINK] = sink;
|
2014-03-13 18:55:57 +00:00
|
|
|
mSource[SOURCE_SCRATCH] = bqProducer;
|
2013-04-07 06:12:29 +00:00
|
|
|
|
|
|
|
resetPerFrameState();
|
|
|
|
|
|
|
|
int sinkWidth, sinkHeight;
|
2013-11-05 00:43:03 +00:00
|
|
|
sink->query(NATIVE_WINDOW_WIDTH, &sinkWidth);
|
|
|
|
sink->query(NATIVE_WINDOW_HEIGHT, &sinkHeight);
|
2014-07-18 22:34:25 +00:00
|
|
|
mSinkBufferWidth = sinkWidth;
|
|
|
|
mSinkBufferHeight = sinkHeight;
|
2013-11-05 00:43:03 +00:00
|
|
|
|
|
|
|
// Pick the buffer format to request from the sink when not rendering to it
|
|
|
|
// with GLES. If the consumer needs CPU access, use the default format
|
|
|
|
// set by the consumer. Otherwise allow gralloc to decide the format based
|
|
|
|
// on usage bits.
|
|
|
|
int sinkUsage;
|
|
|
|
sink->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, &sinkUsage);
|
|
|
|
if (sinkUsage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) {
|
|
|
|
int sinkFormat;
|
|
|
|
sink->query(NATIVE_WINDOW_FORMAT, &sinkFormat);
|
|
|
|
mDefaultOutputFormat = sinkFormat;
|
|
|
|
} else {
|
|
|
|
mDefaultOutputFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
|
|
|
|
}
|
|
|
|
mOutputFormat = mDefaultOutputFormat;
|
2013-04-07 06:12:29 +00:00
|
|
|
|
|
|
|
ConsumerBase::mName = String8::format("VDS: %s", mDisplayName.string());
|
2013-08-02 08:40:18 +00:00
|
|
|
mConsumer->setConsumerName(ConsumerBase::mName);
|
|
|
|
mConsumer->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER);
|
|
|
|
mConsumer->setDefaultBufferSize(sinkWidth, sinkHeight);
|
|
|
|
mConsumer->setDefaultMaxBufferCount(2);
|
2013-03-22 22:13:48 +00:00
|
|
|
}
|
2013-03-14 21:29:29 +00:00
|
|
|
|
|
|
|
VirtualDisplaySurface::~VirtualDisplaySurface() {
|
|
|
|
}
|
|
|
|
|
2014-02-05 00:22:36 +00:00
|
|
|
status_t VirtualDisplaySurface::beginFrame(bool mustRecompose) {
|
2013-04-07 06:12:29 +00:00
|
|
|
if (mDisplayId < 0)
|
|
|
|
return NO_ERROR;
|
|
|
|
|
2014-02-05 00:22:36 +00:00
|
|
|
mMustRecompose = mustRecompose;
|
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
VDS_LOGW_IF(mDbgState != DBG_STATE_IDLE,
|
2013-08-20 23:35:32 +00:00
|
|
|
"Unexpected beginFrame() in %s state", dbgStateStr());
|
|
|
|
mDbgState = DBG_STATE_BEGUN;
|
|
|
|
|
|
|
|
return refreshOutputBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t VirtualDisplaySurface::prepareFrame(CompositionType compositionType) {
|
|
|
|
if (mDisplayId < 0)
|
|
|
|
return NO_ERROR;
|
|
|
|
|
|
|
|
VDS_LOGW_IF(mDbgState != DBG_STATE_BEGUN,
|
2013-04-07 06:12:29 +00:00
|
|
|
"Unexpected prepareFrame() in %s state", dbgStateStr());
|
|
|
|
mDbgState = DBG_STATE_PREPARED;
|
|
|
|
|
|
|
|
mCompositionType = compositionType;
|
2013-10-04 20:15:22 +00:00
|
|
|
if (sForceHwcCopy && mCompositionType == COMPOSITION_GLES) {
|
|
|
|
// Some hardware can do RGB->YUV conversion more efficiently in hardware
|
|
|
|
// controlled by HWC than in hardware controlled by the video encoder.
|
|
|
|
// Forcing GLES-composed frames to go through an extra copy by the HWC
|
|
|
|
// allows the format conversion to happen there, rather than passing RGB
|
|
|
|
// directly to the consumer.
|
|
|
|
//
|
|
|
|
// On the other hand, when the consumer prefers RGB or can consume RGB
|
|
|
|
// inexpensively, this forces an unnecessary copy.
|
|
|
|
mCompositionType = COMPOSITION_MIXED;
|
|
|
|
}
|
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
if (mCompositionType != mDbgLastCompositionType) {
|
|
|
|
VDS_LOGV("prepareFrame: composition type changed to %s",
|
|
|
|
dbgCompositionTypeStr(mCompositionType));
|
|
|
|
mDbgLastCompositionType = mCompositionType;
|
|
|
|
}
|
|
|
|
|
2013-09-27 16:05:09 +00:00
|
|
|
if (mCompositionType != COMPOSITION_GLES &&
|
2013-11-05 00:43:03 +00:00
|
|
|
(mOutputFormat != mDefaultOutputFormat ||
|
2013-09-27 16:05:09 +00:00
|
|
|
mOutputUsage != GRALLOC_USAGE_HW_COMPOSER)) {
|
|
|
|
// We must have just switched from GLES-only to MIXED or HWC
|
|
|
|
// composition. Stop using the format and usage requested by the GLES
|
|
|
|
// driver; they may be suboptimal when HWC is writing to the output
|
|
|
|
// buffer. For example, if the output is going to a video encoder, and
|
|
|
|
// HWC can write directly to YUV, some hardware can skip a
|
|
|
|
// memory-to-memory RGB-to-YUV conversion step.
|
|
|
|
//
|
|
|
|
// If we just switched *to* GLES-only mode, we'll change the
|
|
|
|
// format/usage and get a new buffer when the GLES driver calls
|
|
|
|
// dequeueBuffer().
|
2013-11-05 00:43:03 +00:00
|
|
|
mOutputFormat = mDefaultOutputFormat;
|
2013-09-27 16:05:09 +00:00
|
|
|
mOutputUsage = GRALLOC_USAGE_HW_COMPOSER;
|
|
|
|
refreshOutputBuffer();
|
|
|
|
}
|
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
return NO_ERROR;
|
2013-03-14 21:29:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t VirtualDisplaySurface::compositionComplete() {
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t VirtualDisplaySurface::advanceFrame() {
|
2013-04-07 06:12:29 +00:00
|
|
|
if (mDisplayId < 0)
|
|
|
|
return NO_ERROR;
|
|
|
|
|
|
|
|
if (mCompositionType == COMPOSITION_HWC) {
|
|
|
|
VDS_LOGW_IF(mDbgState != DBG_STATE_PREPARED,
|
|
|
|
"Unexpected advanceFrame() in %s state on HWC frame",
|
|
|
|
dbgStateStr());
|
|
|
|
} else {
|
|
|
|
VDS_LOGW_IF(mDbgState != DBG_STATE_GLES_DONE,
|
|
|
|
"Unexpected advanceFrame() in %s state on GLES/MIXED frame",
|
|
|
|
dbgStateStr());
|
|
|
|
}
|
|
|
|
mDbgState = DBG_STATE_HWC;
|
|
|
|
|
2013-11-07 20:28:26 +00:00
|
|
|
if (mOutputProducerSlot < 0 ||
|
|
|
|
(mCompositionType != COMPOSITION_HWC && mFbProducerSlot < 0)) {
|
2013-04-07 06:12:29 +00:00
|
|
|
// Last chance bailout if something bad happened earlier. For example,
|
|
|
|
// in a GLES configuration, if the sink disappears then dequeueBuffer
|
|
|
|
// will fail, the GLES driver won't queue a buffer, but SurfaceFlinger
|
|
|
|
// will soldier on. So we end up here without a buffer. There should
|
|
|
|
// be lots of scary messages in the log just before this.
|
|
|
|
VDS_LOGE("advanceFrame: no buffer, bailing out");
|
|
|
|
return NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2013-11-07 20:28:26 +00:00
|
|
|
sp<GraphicBuffer> fbBuffer = mFbProducerSlot >= 0 ?
|
|
|
|
mProducerBuffers[mFbProducerSlot] : sp<GraphicBuffer>(NULL);
|
2013-04-07 06:12:29 +00:00
|
|
|
sp<GraphicBuffer> outBuffer = mProducerBuffers[mOutputProducerSlot];
|
|
|
|
VDS_LOGV("advanceFrame: fb=%d(%p) out=%d(%p)",
|
|
|
|
mFbProducerSlot, fbBuffer.get(),
|
|
|
|
mOutputProducerSlot, outBuffer.get());
|
|
|
|
|
2013-10-02 00:25:20 +00:00
|
|
|
// At this point we know the output buffer acquire fence,
|
|
|
|
// so update HWC state with it.
|
|
|
|
mHwc.setOutputBuffer(mDisplayId, mOutputFence, outBuffer);
|
|
|
|
|
2013-11-07 20:28:26 +00:00
|
|
|
status_t result = NO_ERROR;
|
|
|
|
if (fbBuffer != NULL) {
|
|
|
|
result = mHwc.fbPost(mDisplayId, mFbFence, fbBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2013-03-14 21:29:29 +00:00
|
|
|
}
|
|
|
|
|
2013-03-20 20:44:00 +00:00
|
|
|
void VirtualDisplaySurface::onFrameCommitted() {
|
2013-04-07 06:12:29 +00:00
|
|
|
if (mDisplayId < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VDS_LOGW_IF(mDbgState != DBG_STATE_HWC,
|
|
|
|
"Unexpected onFrameCommitted() in %s state", dbgStateStr());
|
|
|
|
mDbgState = DBG_STATE_IDLE;
|
|
|
|
|
|
|
|
sp<Fence> fbFence = mHwc.getAndResetReleaseFence(mDisplayId);
|
|
|
|
if (mCompositionType == COMPOSITION_MIXED && mFbProducerSlot >= 0) {
|
|
|
|
// release the scratch buffer back to the pool
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
int sslot = mapProducer2SourceSlot(SOURCE_SCRATCH, mFbProducerSlot);
|
|
|
|
VDS_LOGV("onFrameCommitted: release scratch sslot=%d", sslot);
|
|
|
|
addReleaseFenceLocked(sslot, mProducerBuffers[mFbProducerSlot], fbFence);
|
|
|
|
releaseBufferLocked(sslot, mProducerBuffers[mFbProducerSlot],
|
|
|
|
EGL_NO_DISPLAY, EGL_NO_SYNC_KHR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mOutputProducerSlot >= 0) {
|
|
|
|
int sslot = mapProducer2SourceSlot(SOURCE_SINK, mOutputProducerSlot);
|
|
|
|
QueueBufferOutput qbo;
|
|
|
|
sp<Fence> outFence = mHwc.getLastRetireFence(mDisplayId);
|
|
|
|
VDS_LOGV("onFrameCommitted: queue sink sslot=%d", sslot);
|
2014-02-05 00:22:36 +00:00
|
|
|
if (mMustRecompose) {
|
|
|
|
status_t result = mSource[SOURCE_SINK]->queueBuffer(sslot,
|
|
|
|
QueueBufferInput(
|
|
|
|
systemTime(), false /* isAutoTimestamp */,
|
2015-02-20 00:10:43 +00:00
|
|
|
HAL_DATASPACE_UNKNOWN,
|
2014-02-05 00:22:36 +00:00
|
|
|
Rect(mSinkBufferWidth, mSinkBufferHeight),
|
|
|
|
NATIVE_WINDOW_SCALING_MODE_FREEZE, 0 /* transform */,
|
|
|
|
true /* async*/,
|
|
|
|
outFence),
|
|
|
|
&qbo);
|
|
|
|
if (result == NO_ERROR) {
|
|
|
|
updateQueueBufferOutput(qbo);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If the surface hadn't actually been updated, then we only went
|
|
|
|
// through the motions of updating the display to keep our state
|
|
|
|
// machine happy. We cancel the buffer to avoid triggering another
|
|
|
|
// re-composition and causing an infinite loop.
|
|
|
|
mSource[SOURCE_SINK]->cancelBuffer(sslot, outFence);
|
2013-04-07 06:12:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resetPerFrameState();
|
2013-03-14 21:29:29 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 18:32:31 +00:00
|
|
|
void VirtualDisplaySurface::dumpAsString(String8& /* result */) const {
|
2013-03-14 21:29:29 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 22:34:25 +00:00
|
|
|
void VirtualDisplaySurface::resizeBuffers(const uint32_t w, const uint32_t h) {
|
|
|
|
uint32_t tmpW, tmpH, transformHint, numPendingBuffers;
|
|
|
|
mQueueBufferOutput.deflate(&tmpW, &tmpH, &transformHint, &numPendingBuffers);
|
|
|
|
mQueueBufferOutput.inflate(w, h, transformHint, numPendingBuffers);
|
|
|
|
|
|
|
|
mSinkBufferWidth = w;
|
|
|
|
mSinkBufferHeight = h;
|
|
|
|
}
|
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
status_t VirtualDisplaySurface::requestBuffer(int pslot,
|
|
|
|
sp<GraphicBuffer>* outBuf) {
|
2014-07-18 22:34:25 +00:00
|
|
|
if (mDisplayId < 0)
|
|
|
|
return mSource[SOURCE_SINK]->requestBuffer(pslot, outBuf);
|
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
VDS_LOGW_IF(mDbgState != DBG_STATE_GLES,
|
|
|
|
"Unexpected requestBuffer pslot=%d in %s state",
|
|
|
|
pslot, dbgStateStr());
|
|
|
|
|
|
|
|
*outBuf = mProducerBuffers[pslot];
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t VirtualDisplaySurface::setBufferCount(int bufferCount) {
|
|
|
|
return mSource[SOURCE_SINK]->setBufferCount(bufferCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t VirtualDisplaySurface::dequeueBuffer(Source source,
|
2014-11-18 18:24:03 +00:00
|
|
|
PixelFormat format, uint32_t usage, int* sslot, sp<Fence>* fence) {
|
2014-07-18 22:34:25 +00:00
|
|
|
LOG_FATAL_IF(mDisplayId < 0, "mDisplayId=%d but should not be < 0.", mDisplayId);
|
2013-08-29 23:03:50 +00:00
|
|
|
// Don't let a slow consumer block us
|
|
|
|
bool async = (source == SOURCE_SINK);
|
|
|
|
|
2013-07-19 05:10:56 +00:00
|
|
|
status_t result = mSource[source]->dequeueBuffer(sslot, fence, async,
|
2013-09-27 16:05:09 +00:00
|
|
|
mSinkBufferWidth, mSinkBufferHeight, format, usage);
|
2013-04-07 06:12:29 +00:00
|
|
|
if (result < 0)
|
|
|
|
return result;
|
|
|
|
int pslot = mapSource2ProducerSlot(source, *sslot);
|
|
|
|
VDS_LOGV("dequeueBuffer(%s): sslot=%d pslot=%d result=%d",
|
|
|
|
dbgSourceStr(source), *sslot, pslot, result);
|
2014-04-09 23:14:51 +00:00
|
|
|
uint64_t sourceBit = static_cast<uint64_t>(source) << pslot;
|
2013-04-07 06:12:29 +00:00
|
|
|
|
2014-04-09 23:14:51 +00:00
|
|
|
if ((mProducerSlotSource & (1ULL << pslot)) != sourceBit) {
|
2013-04-07 06:12:29 +00:00
|
|
|
// This slot was previously dequeued from the other source; must
|
|
|
|
// re-request the buffer.
|
|
|
|
result |= BUFFER_NEEDS_REALLOCATION;
|
2014-04-09 23:14:51 +00:00
|
|
|
mProducerSlotSource &= ~(1ULL << pslot);
|
2013-04-07 06:12:29 +00:00
|
|
|
mProducerSlotSource |= sourceBit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result & RELEASE_ALL_BUFFERS) {
|
|
|
|
for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
|
2014-04-09 23:14:51 +00:00
|
|
|
if ((mProducerSlotSource & (1ULL << i)) == sourceBit)
|
2013-04-07 06:12:29 +00:00
|
|
|
mProducerBuffers[i].clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result & BUFFER_NEEDS_REALLOCATION) {
|
2014-04-29 23:14:14 +00:00
|
|
|
result = mSource[source]->requestBuffer(*sslot, &mProducerBuffers[pslot]);
|
|
|
|
if (result < 0) {
|
|
|
|
mProducerBuffers[pslot].clear();
|
|
|
|
mSource[source]->cancelBuffer(*sslot, *fence);
|
|
|
|
return result;
|
|
|
|
}
|
2013-11-05 00:43:03 +00:00
|
|
|
VDS_LOGV("dequeueBuffer(%s): buffers[%d]=%p fmt=%d usage=%#x",
|
|
|
|
dbgSourceStr(source), pslot, mProducerBuffers[pslot].get(),
|
|
|
|
mProducerBuffers[pslot]->getPixelFormat(),
|
|
|
|
mProducerBuffers[pslot]->getUsage());
|
2013-04-07 06:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-07-19 05:10:56 +00:00
|
|
|
status_t VirtualDisplaySurface::dequeueBuffer(int* pslot, sp<Fence>* fence, bool async,
|
2014-11-18 18:24:03 +00:00
|
|
|
uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) {
|
2014-07-18 22:34:25 +00:00
|
|
|
if (mDisplayId < 0)
|
|
|
|
return mSource[SOURCE_SINK]->dequeueBuffer(pslot, fence, async, w, h, format, usage);
|
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
VDS_LOGW_IF(mDbgState != DBG_STATE_PREPARED,
|
|
|
|
"Unexpected dequeueBuffer() in %s state", dbgStateStr());
|
|
|
|
mDbgState = DBG_STATE_GLES;
|
|
|
|
|
2013-08-29 23:03:50 +00:00
|
|
|
VDS_LOGW_IF(!async, "EGL called dequeueBuffer with !async despite eglSwapInterval(0)");
|
2013-04-07 06:12:29 +00:00
|
|
|
VDS_LOGV("dequeueBuffer %dx%d fmt=%d usage=%#x", w, h, format, usage);
|
|
|
|
|
2013-08-20 23:35:32 +00:00
|
|
|
status_t result = NO_ERROR;
|
2013-04-07 06:12:29 +00:00
|
|
|
Source source = fbSourceForCompositionType(mCompositionType);
|
2013-08-20 23:35:32 +00:00
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
if (source == SOURCE_SINK) {
|
2013-09-26 03:40:07 +00:00
|
|
|
|
|
|
|
if (mOutputProducerSlot < 0) {
|
|
|
|
// Last chance bailout if something bad happened earlier. For example,
|
|
|
|
// in a GLES configuration, if the sink disappears then dequeueBuffer
|
|
|
|
// will fail, the GLES driver won't queue a buffer, but SurfaceFlinger
|
|
|
|
// will soldier on. So we end up here without a buffer. There should
|
|
|
|
// be lots of scary messages in the log just before this.
|
|
|
|
VDS_LOGE("dequeueBuffer: no buffer, bailing out");
|
|
|
|
return NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2013-08-20 23:35:32 +00:00
|
|
|
// We already dequeued the output buffer. If the GLES driver wants
|
|
|
|
// something incompatible, we have to cancel and get a new one. This
|
|
|
|
// will mean that HWC will see a different output buffer between
|
|
|
|
// prepare and set, but since we're in GLES-only mode already it
|
|
|
|
// shouldn't matter.
|
|
|
|
|
2013-09-27 16:05:09 +00:00
|
|
|
usage |= GRALLOC_USAGE_HW_COMPOSER;
|
2013-08-20 23:35:32 +00:00
|
|
|
const sp<GraphicBuffer>& buf = mProducerBuffers[mOutputProducerSlot];
|
2013-09-27 16:05:09 +00:00
|
|
|
if ((usage & ~buf->getUsage()) != 0 ||
|
2014-11-18 18:24:03 +00:00
|
|
|
(format != 0 && format != buf->getPixelFormat()) ||
|
2013-08-20 23:35:32 +00:00
|
|
|
(w != 0 && w != mSinkBufferWidth) ||
|
|
|
|
(h != 0 && h != mSinkBufferHeight)) {
|
2013-09-27 16:05:09 +00:00
|
|
|
VDS_LOGV("dequeueBuffer: dequeueing new output buffer: "
|
|
|
|
"want %dx%d fmt=%d use=%#x, "
|
|
|
|
"have %dx%d fmt=%d use=%#x",
|
|
|
|
w, h, format, usage,
|
|
|
|
mSinkBufferWidth, mSinkBufferHeight,
|
|
|
|
buf->getPixelFormat(), buf->getUsage());
|
|
|
|
mOutputFormat = format;
|
|
|
|
mOutputUsage = usage;
|
2013-08-20 23:35:32 +00:00
|
|
|
result = refreshOutputBuffer();
|
|
|
|
if (result < 0)
|
|
|
|
return result;
|
|
|
|
}
|
2013-04-07 06:12:29 +00:00
|
|
|
}
|
|
|
|
|
2013-08-20 23:35:32 +00:00
|
|
|
if (source == SOURCE_SINK) {
|
|
|
|
*pslot = mOutputProducerSlot;
|
|
|
|
*fence = mOutputFence;
|
|
|
|
} else {
|
|
|
|
int sslot;
|
2013-09-27 16:05:09 +00:00
|
|
|
result = dequeueBuffer(source, format, usage, &sslot, fence);
|
2013-08-20 23:35:32 +00:00
|
|
|
if (result >= 0) {
|
|
|
|
*pslot = mapSource2ProducerSlot(source, sslot);
|
|
|
|
}
|
2013-04-07 06:12:29 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-03-12 16:34:36 +00:00
|
|
|
status_t VirtualDisplaySurface::detachBuffer(int /* slot */) {
|
|
|
|
VDS_LOGE("detachBuffer is not available for VirtualDisplaySurface");
|
|
|
|
return INVALID_OPERATION;
|
2014-03-06 23:14:33 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 22:25:31 +00:00
|
|
|
status_t VirtualDisplaySurface::detachNextBuffer(
|
|
|
|
sp<GraphicBuffer>* /* outBuffer */, sp<Fence>* /* outFence */) {
|
|
|
|
VDS_LOGE("detachNextBuffer is not available for VirtualDisplaySurface");
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
2014-03-12 16:34:36 +00:00
|
|
|
status_t VirtualDisplaySurface::attachBuffer(int* /* outSlot */,
|
|
|
|
const sp<GraphicBuffer>& /* buffer */) {
|
|
|
|
VDS_LOGE("attachBuffer is not available for VirtualDisplaySurface");
|
|
|
|
return INVALID_OPERATION;
|
2014-03-06 23:14:33 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
status_t VirtualDisplaySurface::queueBuffer(int pslot,
|
|
|
|
const QueueBufferInput& input, QueueBufferOutput* output) {
|
2014-07-18 22:34:25 +00:00
|
|
|
if (mDisplayId < 0)
|
|
|
|
return mSource[SOURCE_SINK]->queueBuffer(pslot, input, output);
|
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
VDS_LOGW_IF(mDbgState != DBG_STATE_GLES,
|
|
|
|
"Unexpected queueBuffer(pslot=%d) in %s state", pslot,
|
|
|
|
dbgStateStr());
|
|
|
|
mDbgState = DBG_STATE_GLES_DONE;
|
|
|
|
|
|
|
|
VDS_LOGV("queueBuffer pslot=%d", pslot);
|
|
|
|
|
|
|
|
status_t result;
|
|
|
|
if (mCompositionType == COMPOSITION_MIXED) {
|
|
|
|
// Queue the buffer back into the scratch pool
|
|
|
|
QueueBufferOutput scratchQBO;
|
|
|
|
int sslot = mapProducer2SourceSlot(SOURCE_SCRATCH, pslot);
|
2013-08-02 08:40:18 +00:00
|
|
|
result = mSource[SOURCE_SCRATCH]->queueBuffer(sslot, input, &scratchQBO);
|
2013-04-07 06:12:29 +00:00
|
|
|
if (result != NO_ERROR)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Now acquire the buffer from the scratch pool -- should be the same
|
|
|
|
// slot and fence as we just queued.
|
|
|
|
Mutex::Autolock lock(mMutex);
|
2015-03-12 22:12:44 +00:00
|
|
|
BufferItem item;
|
2013-07-16 20:46:20 +00:00
|
|
|
result = acquireBufferLocked(&item, 0);
|
2013-04-07 06:12:29 +00:00
|
|
|
if (result != NO_ERROR)
|
|
|
|
return result;
|
|
|
|
VDS_LOGW_IF(item.mBuf != sslot,
|
|
|
|
"queueBuffer: acquired sslot %d from SCRATCH after queueing sslot %d",
|
|
|
|
item.mBuf, sslot);
|
|
|
|
mFbProducerSlot = mapSource2ProducerSlot(SOURCE_SCRATCH, item.mBuf);
|
|
|
|
mFbFence = mSlots[item.mBuf].mFence;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
LOG_FATAL_IF(mCompositionType != COMPOSITION_GLES,
|
|
|
|
"Unexpected queueBuffer in state %s for compositionType %s",
|
|
|
|
dbgStateStr(), dbgCompositionTypeStr(mCompositionType));
|
|
|
|
|
|
|
|
// Extract the GLES release fence for HWC to acquire
|
|
|
|
int64_t timestamp;
|
2013-08-16 21:55:39 +00:00
|
|
|
bool isAutoTimestamp;
|
2015-02-20 00:10:43 +00:00
|
|
|
android_dataspace dataSpace;
|
2013-04-07 06:12:29 +00:00
|
|
|
Rect crop;
|
|
|
|
int scalingMode;
|
|
|
|
uint32_t transform;
|
2013-07-19 05:10:56 +00:00
|
|
|
bool async;
|
2015-02-20 00:10:43 +00:00
|
|
|
input.deflate(×tamp, &isAutoTimestamp, &dataSpace, &crop,
|
|
|
|
&scalingMode, &transform, &async, &mFbFence);
|
2013-04-07 06:12:29 +00:00
|
|
|
|
|
|
|
mFbProducerSlot = pslot;
|
2013-08-20 23:35:32 +00:00
|
|
|
mOutputFence = mFbFence;
|
2013-04-07 06:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*output = mQueueBufferOutput;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualDisplaySurface::cancelBuffer(int pslot, const sp<Fence>& fence) {
|
2014-07-18 22:34:25 +00:00
|
|
|
if (mDisplayId < 0)
|
2014-07-30 22:39:17 +00:00
|
|
|
return mSource[SOURCE_SINK]->cancelBuffer(mapProducer2SourceSlot(SOURCE_SINK, pslot), fence);
|
2014-07-18 22:34:25 +00:00
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
VDS_LOGW_IF(mDbgState != DBG_STATE_GLES,
|
|
|
|
"Unexpected cancelBuffer(pslot=%d) in %s state", pslot,
|
|
|
|
dbgStateStr());
|
|
|
|
VDS_LOGV("cancelBuffer pslot=%d", pslot);
|
|
|
|
Source source = fbSourceForCompositionType(mCompositionType);
|
|
|
|
return mSource[source]->cancelBuffer(
|
|
|
|
mapProducer2SourceSlot(source, pslot), fence);
|
|
|
|
}
|
|
|
|
|
|
|
|
int VirtualDisplaySurface::query(int what, int* value) {
|
2014-07-18 22:34:25 +00:00
|
|
|
switch (what) {
|
|
|
|
case NATIVE_WINDOW_WIDTH:
|
|
|
|
*value = mSinkBufferWidth;
|
|
|
|
break;
|
|
|
|
case NATIVE_WINDOW_HEIGHT:
|
|
|
|
*value = mSinkBufferHeight;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return mSource[SOURCE_SINK]->query(what, value);
|
|
|
|
}
|
|
|
|
return NO_ERROR;
|
2013-04-07 06:12:29 +00:00
|
|
|
}
|
|
|
|
|
2014-03-21 20:05:51 +00:00
|
|
|
status_t VirtualDisplaySurface::connect(const sp<IProducerListener>& listener,
|
2013-09-12 02:35:45 +00:00
|
|
|
int api, bool producerControlledByApp,
|
2013-07-17 05:56:09 +00:00
|
|
|
QueueBufferOutput* output) {
|
2013-04-07 06:12:29 +00:00
|
|
|
QueueBufferOutput qbo;
|
2014-03-21 20:05:51 +00:00
|
|
|
status_t result = mSource[SOURCE_SINK]->connect(listener, api,
|
|
|
|
producerControlledByApp, &qbo);
|
2013-04-07 06:12:29 +00:00
|
|
|
if (result == NO_ERROR) {
|
|
|
|
updateQueueBufferOutput(qbo);
|
|
|
|
*output = mQueueBufferOutput;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t VirtualDisplaySurface::disconnect(int api) {
|
|
|
|
return mSource[SOURCE_SINK]->disconnect(api);
|
|
|
|
}
|
|
|
|
|
2014-03-03 23:42:54 +00:00
|
|
|
status_t VirtualDisplaySurface::setSidebandStream(const sp<NativeHandle>& /*stream*/) {
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
2014-06-20 20:13:57 +00:00
|
|
|
void VirtualDisplaySurface::allocateBuffers(bool /* async */,
|
2014-11-18 18:24:03 +00:00
|
|
|
uint32_t /* width */, uint32_t /* height */, PixelFormat /* format */,
|
2014-06-20 20:13:57 +00:00
|
|
|
uint32_t /* usage */) {
|
|
|
|
// TODO: Should we actually allocate buffers for a virtual display?
|
|
|
|
}
|
|
|
|
|
2015-04-17 00:28:43 +00:00
|
|
|
status_t VirtualDisplaySurface::allowAllocation(bool /* allow */) {
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
2015-06-02 22:45:22 +00:00
|
|
|
status_t VirtualDisplaySurface::setGenerationNumber(uint32_t /* generation */) {
|
|
|
|
ALOGE("setGenerationNumber not supported on VirtualDisplaySurface");
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
2015-06-08 16:32:50 +00:00
|
|
|
String8 VirtualDisplaySurface::getConsumerName() const {
|
|
|
|
return String8("VirtualDisplaySurface");
|
|
|
|
}
|
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
void VirtualDisplaySurface::updateQueueBufferOutput(
|
|
|
|
const QueueBufferOutput& qbo) {
|
|
|
|
uint32_t w, h, transformHint, numPendingBuffers;
|
|
|
|
qbo.deflate(&w, &h, &transformHint, &numPendingBuffers);
|
|
|
|
mQueueBufferOutput.inflate(w, h, 0, numPendingBuffers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualDisplaySurface::resetPerFrameState() {
|
|
|
|
mCompositionType = COMPOSITION_UNKNOWN;
|
2014-01-10 04:57:45 +00:00
|
|
|
mFbFence = Fence::NO_FENCE;
|
2013-08-20 23:35:32 +00:00
|
|
|
mOutputFence = Fence::NO_FENCE;
|
2013-04-07 06:12:29 +00:00
|
|
|
mOutputProducerSlot = -1;
|
2014-01-23 09:38:31 +00:00
|
|
|
mFbProducerSlot = -1;
|
2013-04-07 06:12:29 +00:00
|
|
|
}
|
|
|
|
|
2013-08-20 23:35:32 +00:00
|
|
|
status_t VirtualDisplaySurface::refreshOutputBuffer() {
|
|
|
|
if (mOutputProducerSlot >= 0) {
|
|
|
|
mSource[SOURCE_SINK]->cancelBuffer(
|
|
|
|
mapProducer2SourceSlot(SOURCE_SINK, mOutputProducerSlot),
|
|
|
|
mOutputFence);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sslot;
|
2013-09-27 16:05:09 +00:00
|
|
|
status_t result = dequeueBuffer(SOURCE_SINK, mOutputFormat, mOutputUsage,
|
|
|
|
&sslot, &mOutputFence);
|
2013-08-20 23:35:32 +00:00
|
|
|
if (result < 0)
|
|
|
|
return result;
|
|
|
|
mOutputProducerSlot = mapSource2ProducerSlot(SOURCE_SINK, sslot);
|
|
|
|
|
2013-10-02 00:25:20 +00:00
|
|
|
// On GLES-only frames, we don't have the right output buffer acquire fence
|
|
|
|
// until after GLES calls queueBuffer(). So here we just set the buffer
|
|
|
|
// (for use in HWC prepare) but not the fence; we'll call this again with
|
|
|
|
// the proper fence once we have it.
|
|
|
|
result = mHwc.setOutputBuffer(mDisplayId, Fence::NO_FENCE,
|
2013-08-20 23:35:32 +00:00
|
|
|
mProducerBuffers[mOutputProducerSlot]);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
// This slot mapping function is its own inverse, so two copies are unnecessary.
|
|
|
|
// Both are kept to make the intent clear where the function is called, and for
|
|
|
|
// the (unlikely) chance that we switch to a different mapping function.
|
|
|
|
int VirtualDisplaySurface::mapSource2ProducerSlot(Source source, int sslot) {
|
|
|
|
if (source == SOURCE_SCRATCH) {
|
|
|
|
return BufferQueue::NUM_BUFFER_SLOTS - sslot - 1;
|
|
|
|
} else {
|
|
|
|
return sslot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int VirtualDisplaySurface::mapProducer2SourceSlot(Source source, int pslot) {
|
|
|
|
return mapSource2ProducerSlot(source, pslot);
|
|
|
|
}
|
|
|
|
|
|
|
|
VirtualDisplaySurface::Source
|
|
|
|
VirtualDisplaySurface::fbSourceForCompositionType(CompositionType type) {
|
|
|
|
return type == COMPOSITION_MIXED ? SOURCE_SCRATCH : SOURCE_SINK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* VirtualDisplaySurface::dbgStateStr() const {
|
|
|
|
switch (mDbgState) {
|
|
|
|
case DBG_STATE_IDLE: return "IDLE";
|
|
|
|
case DBG_STATE_PREPARED: return "PREPARED";
|
|
|
|
case DBG_STATE_GLES: return "GLES";
|
|
|
|
case DBG_STATE_GLES_DONE: return "GLES_DONE";
|
|
|
|
case DBG_STATE_HWC: return "HWC";
|
|
|
|
default: return "INVALID";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* VirtualDisplaySurface::dbgSourceStr(Source s) {
|
|
|
|
switch (s) {
|
|
|
|
case SOURCE_SINK: return "SINK";
|
|
|
|
case SOURCE_SCRATCH: return "SCRATCH";
|
|
|
|
default: return "INVALID";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-14 21:29:29 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
} // namespace android
|
|
|
|
// ---------------------------------------------------------------------------
|