blob: c8cd442e114c4890f9a5e1805b2a5958e926ddb4 [file] [log] [blame]
Jesse Hall99c7dbb2013-03-14 14:29:29 -07001/*
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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Jesse Hall38efe862013-04-06 23:12:29 -070021// #define LOG_NDEBUG 0
Jesse Hall99c7dbb2013-03-14 14:29:29 -070022#include "VirtualDisplaySurface.h"
Mathias Agopiancb496ac2017-05-22 14:21:00 -070023
24#include <inttypes.h>
25
Jesse Hall38efe862013-04-06 23:12:29 -070026#include "HWComposer.h"
Fabien Sanglarda34ed632017-03-14 11:43:52 -070027#include "SurfaceFlinger.h"
Jesse Hall99c7dbb2013-03-14 14:29:29 -070028
Dan Stoza11611f92015-03-12 15:12:44 -070029#include <gui/BufferItem.h>
Mathias Agopiana9347642017-02-13 16:42:28 -080030#include <gui/BufferQueue.h>
Pablo Ceballosf133d002015-10-23 12:10:13 -070031#include <gui/IProducerListener.h>
Mathias Agopian6a3c05b2017-04-27 20:06:55 -070032#include <system/window.h>
Dan Stoza11611f92015-03-12 15:12:44 -070033
Jesse Hall99c7dbb2013-03-14 14:29:29 -070034// ---------------------------------------------------------------------------
35namespace android {
36// ---------------------------------------------------------------------------
37
Jesse Hall24cd98e2014-07-13 14:37:16 -070038#define VDS_LOGE(msg, ...) ALOGE("[%s] " msg, \
Dominik Laskowskibf170d92018-04-19 15:08:05 -070039 mDisplayName.c_str(), ##__VA_ARGS__)
Jesse Hall24cd98e2014-07-13 14:37:16 -070040#define VDS_LOGW_IF(cond, msg, ...) ALOGW_IF(cond, "[%s] " msg, \
Dominik Laskowskibf170d92018-04-19 15:08:05 -070041 mDisplayName.c_str(), ##__VA_ARGS__)
Jesse Hall24cd98e2014-07-13 14:37:16 -070042#define VDS_LOGV(msg, ...) ALOGV("[%s] " msg, \
Dominik Laskowskibf170d92018-04-19 15:08:05 -070043 mDisplayName.c_str(), ##__VA_ARGS__)
Jesse Hall38efe862013-04-06 23:12:29 -070044
Lloyd Pique542307f2018-10-19 13:24:08 -070045static const char* dbgCompositionTypeStr(compositionengine::DisplaySurface::CompositionType type) {
Jesse Hall38efe862013-04-06 23:12:29 -070046 switch (type) {
Lloyd Pique542307f2018-10-19 13:24:08 -070047 case compositionengine::DisplaySurface::COMPOSITION_UNKNOWN:
48 return "UNKNOWN";
Peiyong Linf3ffc4e2019-12-13 00:46:24 -080049 case compositionengine::DisplaySurface::COMPOSITION_GPU:
50 return "GPU";
Lloyd Pique542307f2018-10-19 13:24:08 -070051 case compositionengine::DisplaySurface::COMPOSITION_HWC:
52 return "HWC";
53 case compositionengine::DisplaySurface::COMPOSITION_MIXED:
54 return "MIXED";
Peiyong Linf3ffc4e2019-12-13 00:46:24 -080055 default:
56 return "<INVALID>";
Jesse Hall38efe862013-04-06 23:12:29 -070057 }
58}
59
Dominik Laskowski075d3172018-05-24 15:50:06 -070060VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc,
61 const std::optional<DisplayId>& displayId,
62 const sp<IGraphicBufferProducer>& sink,
63 const sp<IGraphicBufferProducer>& bqProducer,
64 const sp<IGraphicBufferConsumer>& bqConsumer,
65 const std::string& name)
66 : ConsumerBase(bqConsumer),
67 mHwc(hwc),
68 mDisplayId(displayId),
69 mDisplayName(name),
70 mSource{},
71 mDefaultOutputFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED),
72 mOutputFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED),
73 mOutputUsage(GRALLOC_USAGE_HW_COMPOSER),
74 mProducerSlotSource(0),
75 mProducerBuffers(),
KaiChieh Chuangc5222132019-12-20 07:38:19 +080076 mProducerSlotNeedReallocation(0),
Dominik Laskowski075d3172018-05-24 15:50:06 -070077 mQueueBufferOutput(),
78 mSinkBufferWidth(0),
79 mSinkBufferHeight(0),
80 mCompositionType(COMPOSITION_UNKNOWN),
81 mFbFence(Fence::NO_FENCE),
82 mOutputFence(Fence::NO_FENCE),
83 mFbProducerSlot(BufferQueue::INVALID_BUFFER_SLOT),
84 mOutputProducerSlot(BufferQueue::INVALID_BUFFER_SLOT),
85 mDbgState(DBG_STATE_IDLE),
86 mDbgLastCompositionType(COMPOSITION_UNKNOWN),
87 mMustRecompose(false),
88 mForceHwcCopy(SurfaceFlinger::useHwcForRgbToYuv) {
Jesse Hall38efe862013-04-06 23:12:29 -070089 mSource[SOURCE_SINK] = sink;
Dan Stozab9b08832014-03-13 11:55:57 -070090 mSource[SOURCE_SCRATCH] = bqProducer;
Jesse Hall38efe862013-04-06 23:12:29 -070091
92 resetPerFrameState();
93
94 int sinkWidth, sinkHeight;
Jesse Hall497ba0e2013-11-04 16:43:03 -080095 sink->query(NATIVE_WINDOW_WIDTH, &sinkWidth);
96 sink->query(NATIVE_WINDOW_HEIGHT, &sinkHeight);
Michael Lentine47e45402014-07-18 15:34:25 -070097 mSinkBufferWidth = sinkWidth;
98 mSinkBufferHeight = sinkHeight;
Jesse Hall497ba0e2013-11-04 16:43:03 -080099
100 // Pick the buffer format to request from the sink when not rendering to it
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800101 // with GPU. If the consumer needs CPU access, use the default format
Jesse Hall497ba0e2013-11-04 16:43:03 -0800102 // set by the consumer. Otherwise allow gralloc to decide the format based
103 // on usage bits.
104 int sinkUsage;
105 sink->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, &sinkUsage);
106 if (sinkUsage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) {
107 int sinkFormat;
108 sink->query(NATIVE_WINDOW_FORMAT, &sinkFormat);
109 mDefaultOutputFormat = sinkFormat;
110 } else {
111 mDefaultOutputFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
112 }
113 mOutputFormat = mDefaultOutputFormat;
Jesse Hall38efe862013-04-06 23:12:29 -0700114
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700115 ConsumerBase::mName = String8::format("VDS: %s", mDisplayName.c_str());
Mathias Agopiandb89edc2013-08-02 01:40:18 -0700116 mConsumer->setConsumerName(ConsumerBase::mName);
117 mConsumer->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER);
118 mConsumer->setDefaultBufferSize(sinkWidth, sinkHeight);
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700119 sink->setAsyncMode(true);
Alec Mouri8d4f90a2018-11-14 22:33:24 +0000120 IGraphicBufferProducer::QueueBufferOutput output;
121 mSource[SOURCE_SCRATCH]->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &output);
Jesse Hallffe1f192013-03-22 15:13:48 -0700122}
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700123
124VirtualDisplaySurface::~VirtualDisplaySurface() {
Pablo Ceballosf133d002015-10-23 12:10:13 -0700125 mSource[SOURCE_SCRATCH]->disconnect(NATIVE_WINDOW_API_EGL);
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700126}
127
Dan Stoza71433162014-02-04 16:22:36 -0800128status_t VirtualDisplaySurface::beginFrame(bool mustRecompose) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700129 if (!mDisplayId) {
Jesse Hall38efe862013-04-06 23:12:29 -0700130 return NO_ERROR;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700131 }
Jesse Hall38efe862013-04-06 23:12:29 -0700132
Dan Stoza71433162014-02-04 16:22:36 -0800133 mMustRecompose = mustRecompose;
134
Jesse Hall38efe862013-04-06 23:12:29 -0700135 VDS_LOGW_IF(mDbgState != DBG_STATE_IDLE,
Jesse Hall028dc8f2013-08-20 16:35:32 -0700136 "Unexpected beginFrame() in %s state", dbgStateStr());
137 mDbgState = DBG_STATE_BEGUN;
138
Jesse Hall028dc8f2013-08-20 16:35:32 -0700139 return refreshOutputBuffer();
140}
141
142status_t VirtualDisplaySurface::prepareFrame(CompositionType compositionType) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700143 if (!mDisplayId) {
Jesse Hall028dc8f2013-08-20 16:35:32 -0700144 return NO_ERROR;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700145 }
Jesse Hall028dc8f2013-08-20 16:35:32 -0700146
147 VDS_LOGW_IF(mDbgState != DBG_STATE_BEGUN,
Jesse Hall38efe862013-04-06 23:12:29 -0700148 "Unexpected prepareFrame() in %s state", dbgStateStr());
149 mDbgState = DBG_STATE_PREPARED;
150
151 mCompositionType = compositionType;
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800152 if (mForceHwcCopy && mCompositionType == COMPOSITION_GPU) {
Naseer Ahmed6a968462013-10-04 16:15:22 -0400153 // Some hardware can do RGB->YUV conversion more efficiently in hardware
154 // controlled by HWC than in hardware controlled by the video encoder.
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800155 // Forcing GPU-composed frames to go through an extra copy by the HWC
Naseer Ahmed6a968462013-10-04 16:15:22 -0400156 // allows the format conversion to happen there, rather than passing RGB
157 // directly to the consumer.
158 //
159 // On the other hand, when the consumer prefers RGB or can consume RGB
160 // inexpensively, this forces an unnecessary copy.
161 mCompositionType = COMPOSITION_MIXED;
162 }
163
Jesse Hall38efe862013-04-06 23:12:29 -0700164 if (mCompositionType != mDbgLastCompositionType) {
165 VDS_LOGV("prepareFrame: composition type changed to %s",
166 dbgCompositionTypeStr(mCompositionType));
167 mDbgLastCompositionType = mCompositionType;
168 }
169
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800170 if (mCompositionType != COMPOSITION_GPU &&
171 (mOutputFormat != mDefaultOutputFormat || mOutputUsage != GRALLOC_USAGE_HW_COMPOSER)) {
172 // We must have just switched from GPU-only to MIXED or HWC
173 // composition. Stop using the format and usage requested by the GPU
Jesse Hall1e27ba22013-09-27 09:05:09 -0700174 // driver; they may be suboptimal when HWC is writing to the output
175 // buffer. For example, if the output is going to a video encoder, and
176 // HWC can write directly to YUV, some hardware can skip a
177 // memory-to-memory RGB-to-YUV conversion step.
178 //
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800179 // If we just switched *to* GPU-only mode, we'll change the
180 // format/usage and get a new buffer when the GPU driver calls
Jesse Hall1e27ba22013-09-27 09:05:09 -0700181 // dequeueBuffer().
Jesse Hall497ba0e2013-11-04 16:43:03 -0800182 mOutputFormat = mDefaultOutputFormat;
Jesse Hall1e27ba22013-09-27 09:05:09 -0700183 mOutputUsage = GRALLOC_USAGE_HW_COMPOSER;
184 refreshOutputBuffer();
185 }
186
Jesse Hall38efe862013-04-06 23:12:29 -0700187 return NO_ERROR;
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700188}
189
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700190status_t VirtualDisplaySurface::advanceFrame() {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700191 if (!mDisplayId) {
Jesse Hall38efe862013-04-06 23:12:29 -0700192 return NO_ERROR;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700193 }
Jesse Hall38efe862013-04-06 23:12:29 -0700194
195 if (mCompositionType == COMPOSITION_HWC) {
196 VDS_LOGW_IF(mDbgState != DBG_STATE_PREPARED,
197 "Unexpected advanceFrame() in %s state on HWC frame",
198 dbgStateStr());
199 } else {
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800200 VDS_LOGW_IF(mDbgState != DBG_STATE_GPU_DONE,
201 "Unexpected advanceFrame() in %s state on GPU/MIXED frame", dbgStateStr());
Jesse Hall38efe862013-04-06 23:12:29 -0700202 }
203 mDbgState = DBG_STATE_HWC;
204
Jesse Hall14e8b012013-11-07 12:28:26 -0800205 if (mOutputProducerSlot < 0 ||
206 (mCompositionType != COMPOSITION_HWC && mFbProducerSlot < 0)) {
Jesse Hall38efe862013-04-06 23:12:29 -0700207 // Last chance bailout if something bad happened earlier. For example,
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800208 // in a graphics API configuration, if the sink disappears then dequeueBuffer
209 // will fail, the GPU driver won't queue a buffer, but SurfaceFlinger
Jesse Hall38efe862013-04-06 23:12:29 -0700210 // will soldier on. So we end up here without a buffer. There should
211 // be lots of scary messages in the log just before this.
212 VDS_LOGE("advanceFrame: no buffer, bailing out");
213 return NO_MEMORY;
214 }
215
Jesse Hall14e8b012013-11-07 12:28:26 -0800216 sp<GraphicBuffer> fbBuffer = mFbProducerSlot >= 0 ?
Peiyong Lin566a3b42018-01-09 18:22:43 -0800217 mProducerBuffers[mFbProducerSlot] : sp<GraphicBuffer>(nullptr);
Jesse Hall38efe862013-04-06 23:12:29 -0700218 sp<GraphicBuffer> outBuffer = mProducerBuffers[mOutputProducerSlot];
219 VDS_LOGV("advanceFrame: fb=%d(%p) out=%d(%p)",
220 mFbProducerSlot, fbBuffer.get(),
221 mOutputProducerSlot, outBuffer.get());
222
Jesse Hallb716e572013-10-01 17:25:20 -0700223 // At this point we know the output buffer acquire fence,
224 // so update HWC state with it.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700225 mHwc.setOutputBuffer(*mDisplayId, mOutputFence, outBuffer);
Jesse Hallb716e572013-10-01 17:25:20 -0700226
Jesse Hall14e8b012013-11-07 12:28:26 -0800227 status_t result = NO_ERROR;
Peiyong Lin566a3b42018-01-09 18:22:43 -0800228 if (fbBuffer != nullptr) {
Chia-I Wu06d63de2017-01-04 14:58:51 +0800229 uint32_t hwcSlot = 0;
230 sp<GraphicBuffer> hwcBuffer;
Valerie Hau13f0d1a2019-03-22 10:35:42 -0700231 mHwcBufferCache.getHwcBuffer(mFbProducerSlot, fbBuffer, &hwcSlot, &hwcBuffer);
Chia-I Wu06d63de2017-01-04 14:58:51 +0800232
Dan Stoza9e56aa02015-11-02 13:00:03 -0800233 // TODO: Correctly propagate the dataspace from GL composition
Dominik Laskowski075d3172018-05-24 15:50:06 -0700234 result = mHwc.setClientTarget(*mDisplayId, hwcSlot, mFbFence, hwcBuffer,
235 ui::Dataspace::UNKNOWN);
Jesse Hall14e8b012013-11-07 12:28:26 -0800236 }
237
238 return result;
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700239}
240
Jesse Hall851cfe82013-03-20 13:44:00 -0700241void VirtualDisplaySurface::onFrameCommitted() {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700242 if (!mDisplayId) {
Jesse Hall38efe862013-04-06 23:12:29 -0700243 return;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700244 }
Jesse Hall38efe862013-04-06 23:12:29 -0700245
246 VDS_LOGW_IF(mDbgState != DBG_STATE_HWC,
247 "Unexpected onFrameCommitted() in %s state", dbgStateStr());
248 mDbgState = DBG_STATE_IDLE;
249
Dominik Laskowski075d3172018-05-24 15:50:06 -0700250 sp<Fence> retireFence = mHwc.getPresentFence(*mDisplayId);
Jesse Hall38efe862013-04-06 23:12:29 -0700251 if (mCompositionType == COMPOSITION_MIXED && mFbProducerSlot >= 0) {
252 // release the scratch buffer back to the pool
253 Mutex::Autolock lock(mMutex);
254 int sslot = mapProducer2SourceSlot(SOURCE_SCRATCH, mFbProducerSlot);
255 VDS_LOGV("onFrameCommitted: release scratch sslot=%d", sslot);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800256 addReleaseFenceLocked(sslot, mProducerBuffers[mFbProducerSlot],
257 retireFence);
Chia-I Wu1e24cce2017-11-10 10:36:01 -0800258 releaseBufferLocked(sslot, mProducerBuffers[mFbProducerSlot]);
Jesse Hall38efe862013-04-06 23:12:29 -0700259 }
260
261 if (mOutputProducerSlot >= 0) {
262 int sslot = mapProducer2SourceSlot(SOURCE_SINK, mOutputProducerSlot);
263 QueueBufferOutput qbo;
Jesse Hall38efe862013-04-06 23:12:29 -0700264 VDS_LOGV("onFrameCommitted: queue sink sslot=%d", sslot);
Dan Stoza71433162014-02-04 16:22:36 -0800265 if (mMustRecompose) {
266 status_t result = mSource[SOURCE_SINK]->queueBuffer(sslot,
267 QueueBufferInput(
268 systemTime(), false /* isAutoTimestamp */,
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800269 HAL_DATASPACE_UNKNOWN,
Dan Stoza71433162014-02-04 16:22:36 -0800270 Rect(mSinkBufferWidth, mSinkBufferHeight),
271 NATIVE_WINDOW_SCALING_MODE_FREEZE, 0 /* transform */,
Dan Stoza9e56aa02015-11-02 13:00:03 -0800272 retireFence),
Dan Stoza71433162014-02-04 16:22:36 -0800273 &qbo);
274 if (result == NO_ERROR) {
Brian Anderson3d4039d2016-09-23 16:31:30 -0700275 updateQueueBufferOutput(std::move(qbo));
Dan Stoza71433162014-02-04 16:22:36 -0800276 }
277 } else {
278 // If the surface hadn't actually been updated, then we only went
279 // through the motions of updating the display to keep our state
280 // machine happy. We cancel the buffer to avoid triggering another
281 // re-composition and causing an infinite loop.
Dan Stoza9e56aa02015-11-02 13:00:03 -0800282 mSource[SOURCE_SINK]->cancelBuffer(sslot, retireFence);
Jesse Hall38efe862013-04-06 23:12:29 -0700283 }
284 }
285
286 resetPerFrameState();
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700287}
288
Dan Stoza01049c82014-11-11 10:32:31 -0800289void VirtualDisplaySurface::dumpAsString(String8& /* result */) const {
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700290}
291
Michael Lentine47e45402014-07-18 15:34:25 -0700292void VirtualDisplaySurface::resizeBuffers(const uint32_t w, const uint32_t h) {
Brian Andersonbaaad322016-07-22 15:55:13 -0700293 mQueueBufferOutput.width = w;
294 mQueueBufferOutput.height = h;
Michael Lentine47e45402014-07-18 15:34:25 -0700295 mSinkBufferWidth = w;
296 mSinkBufferHeight = h;
297}
298
Dan Stoza9e56aa02015-11-02 13:00:03 -0800299const sp<Fence>& VirtualDisplaySurface::getClientTargetAcquireFence() const {
300 return mFbFence;
301}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800302
Jesse Hall38efe862013-04-06 23:12:29 -0700303status_t VirtualDisplaySurface::requestBuffer(int pslot,
304 sp<GraphicBuffer>* outBuf) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700305 if (!mDisplayId) {
Michael Lentine47e45402014-07-18 15:34:25 -0700306 return mSource[SOURCE_SINK]->requestBuffer(pslot, outBuf);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700307 }
Michael Lentine47e45402014-07-18 15:34:25 -0700308
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800309 VDS_LOGW_IF(mDbgState != DBG_STATE_GPU, "Unexpected requestBuffer pslot=%d in %s state", pslot,
310 dbgStateStr());
Jesse Hall38efe862013-04-06 23:12:29 -0700311
312 *outBuf = mProducerBuffers[pslot];
313 return NO_ERROR;
314}
315
Pablo Ceballosfa455352015-08-12 17:47:47 -0700316status_t VirtualDisplaySurface::setMaxDequeuedBufferCount(
317 int maxDequeuedBuffers) {
318 return mSource[SOURCE_SINK]->setMaxDequeuedBufferCount(maxDequeuedBuffers);
319}
320
321status_t VirtualDisplaySurface::setAsyncMode(bool async) {
322 return mSource[SOURCE_SINK]->setAsyncMode(async);
323}
324
Jesse Hall38efe862013-04-06 23:12:29 -0700325status_t VirtualDisplaySurface::dequeueBuffer(Source source,
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700326 PixelFormat format, uint64_t usage, int* sslot, sp<Fence>* fence) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700327 LOG_FATAL_IF(!mDisplayId);
Jesse Hall8db92552013-08-29 16:03:50 -0700328
Ian Elliotta2eb34c2017-07-18 11:05:49 -0600329 status_t result =
330 mSource[source]->dequeueBuffer(sslot, fence, mSinkBufferWidth, mSinkBufferHeight,
331 format, usage, nullptr, nullptr);
Jesse Hall38efe862013-04-06 23:12:29 -0700332 if (result < 0)
333 return result;
334 int pslot = mapSource2ProducerSlot(source, *sslot);
335 VDS_LOGV("dequeueBuffer(%s): sslot=%d pslot=%d result=%d",
336 dbgSourceStr(source), *sslot, pslot, result);
Dan Stozafebd4f42014-04-09 16:14:51 -0700337 uint64_t sourceBit = static_cast<uint64_t>(source) << pslot;
Jesse Hall38efe862013-04-06 23:12:29 -0700338
KaiChieh Chuangc5222132019-12-20 07:38:19 +0800339 // reset producer slot reallocation flag
340 mProducerSlotNeedReallocation &= ~(1ULL << pslot);
341
Dan Stozafebd4f42014-04-09 16:14:51 -0700342 if ((mProducerSlotSource & (1ULL << pslot)) != sourceBit) {
Jesse Hall38efe862013-04-06 23:12:29 -0700343 // This slot was previously dequeued from the other source; must
344 // re-request the buffer.
KaiChieh Chuangc5222132019-12-20 07:38:19 +0800345 mProducerSlotNeedReallocation |= 1ULL << pslot;
346
Dan Stozafebd4f42014-04-09 16:14:51 -0700347 mProducerSlotSource &= ~(1ULL << pslot);
Jesse Hall38efe862013-04-06 23:12:29 -0700348 mProducerSlotSource |= sourceBit;
349 }
350
351 if (result & RELEASE_ALL_BUFFERS) {
352 for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
Dan Stozafebd4f42014-04-09 16:14:51 -0700353 if ((mProducerSlotSource & (1ULL << i)) == sourceBit)
Jesse Hall38efe862013-04-06 23:12:29 -0700354 mProducerBuffers[i].clear();
355 }
356 }
357 if (result & BUFFER_NEEDS_REALLOCATION) {
Jesse Hall0b63cd12014-04-29 16:14:14 -0700358 result = mSource[source]->requestBuffer(*sslot, &mProducerBuffers[pslot]);
359 if (result < 0) {
360 mProducerBuffers[pslot].clear();
361 mSource[source]->cancelBuffer(*sslot, *fence);
362 return result;
363 }
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700364 VDS_LOGV("dequeueBuffer(%s): buffers[%d]=%p fmt=%d usage=%#" PRIx64,
Jesse Hall497ba0e2013-11-04 16:43:03 -0800365 dbgSourceStr(source), pslot, mProducerBuffers[pslot].get(),
366 mProducerBuffers[pslot]->getPixelFormat(),
367 mProducerBuffers[pslot]->getUsage());
KaiChieh Chuangc5222132019-12-20 07:38:19 +0800368
369 // propagate reallocation to VDS consumer
370 mProducerSlotNeedReallocation |= 1ULL << pslot;
Jesse Hall38efe862013-04-06 23:12:29 -0700371 }
372
373 return result;
374}
375
Ian Elliotta2eb34c2017-07-18 11:05:49 -0600376status_t VirtualDisplaySurface::dequeueBuffer(int* pslot, sp<Fence>* fence, uint32_t w, uint32_t h,
377 PixelFormat format, uint64_t usage,
378 uint64_t* outBufferAge,
379 FrameEventHistoryDelta* outTimestamps) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700380 if (!mDisplayId) {
Ian Elliotta2eb34c2017-07-18 11:05:49 -0600381 return mSource[SOURCE_SINK]->dequeueBuffer(pslot, fence, w, h, format, usage, outBufferAge,
382 outTimestamps);
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700383 }
Michael Lentine47e45402014-07-18 15:34:25 -0700384
Jesse Hall38efe862013-04-06 23:12:29 -0700385 VDS_LOGW_IF(mDbgState != DBG_STATE_PREPARED,
386 "Unexpected dequeueBuffer() in %s state", dbgStateStr());
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800387 mDbgState = DBG_STATE_GPU;
Jesse Hall38efe862013-04-06 23:12:29 -0700388
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700389 VDS_LOGV("dequeueBuffer %dx%d fmt=%d usage=%#" PRIx64, w, h, format, usage);
Jesse Hall38efe862013-04-06 23:12:29 -0700390
Jesse Hall028dc8f2013-08-20 16:35:32 -0700391 status_t result = NO_ERROR;
Jesse Hall38efe862013-04-06 23:12:29 -0700392 Source source = fbSourceForCompositionType(mCompositionType);
Jesse Hall028dc8f2013-08-20 16:35:32 -0700393
Jesse Hall38efe862013-04-06 23:12:29 -0700394 if (source == SOURCE_SINK) {
Mathias Agopian6da15f42013-09-25 20:40:07 -0700395
396 if (mOutputProducerSlot < 0) {
397 // Last chance bailout if something bad happened earlier. For example,
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800398 // in a graphics API configuration, if the sink disappears then dequeueBuffer
399 // will fail, the GPU driver won't queue a buffer, but SurfaceFlinger
Mathias Agopian6da15f42013-09-25 20:40:07 -0700400 // will soldier on. So we end up here without a buffer. There should
401 // be lots of scary messages in the log just before this.
402 VDS_LOGE("dequeueBuffer: no buffer, bailing out");
403 return NO_MEMORY;
404 }
405
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800406 // We already dequeued the output buffer. If the GPU driver wants
Jesse Hall028dc8f2013-08-20 16:35:32 -0700407 // something incompatible, we have to cancel and get a new one. This
408 // will mean that HWC will see a different output buffer between
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800409 // prepare and set, but since we're in GPU-only mode already it
Jesse Hall028dc8f2013-08-20 16:35:32 -0700410 // shouldn't matter.
411
Jesse Hall1e27ba22013-09-27 09:05:09 -0700412 usage |= GRALLOC_USAGE_HW_COMPOSER;
Jesse Hall028dc8f2013-08-20 16:35:32 -0700413 const sp<GraphicBuffer>& buf = mProducerBuffers[mOutputProducerSlot];
Jesse Hall1e27ba22013-09-27 09:05:09 -0700414 if ((usage & ~buf->getUsage()) != 0 ||
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800415 (format != 0 && format != buf->getPixelFormat()) ||
Jesse Hall028dc8f2013-08-20 16:35:32 -0700416 (w != 0 && w != mSinkBufferWidth) ||
417 (h != 0 && h != mSinkBufferHeight)) {
Jesse Hall1e27ba22013-09-27 09:05:09 -0700418 VDS_LOGV("dequeueBuffer: dequeueing new output buffer: "
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700419 "want %dx%d fmt=%d use=%#" PRIx64 ", "
420 "have %dx%d fmt=%d use=%#" PRIx64,
Jesse Hall1e27ba22013-09-27 09:05:09 -0700421 w, h, format, usage,
422 mSinkBufferWidth, mSinkBufferHeight,
423 buf->getPixelFormat(), buf->getUsage());
424 mOutputFormat = format;
425 mOutputUsage = usage;
Jesse Hall028dc8f2013-08-20 16:35:32 -0700426 result = refreshOutputBuffer();
427 if (result < 0)
428 return result;
429 }
Jesse Hall38efe862013-04-06 23:12:29 -0700430 }
431
Jesse Hall028dc8f2013-08-20 16:35:32 -0700432 if (source == SOURCE_SINK) {
433 *pslot = mOutputProducerSlot;
434 *fence = mOutputFence;
435 } else {
436 int sslot;
Jesse Hall1e27ba22013-09-27 09:05:09 -0700437 result = dequeueBuffer(source, format, usage, &sslot, fence);
Jesse Hall028dc8f2013-08-20 16:35:32 -0700438 if (result >= 0) {
439 *pslot = mapSource2ProducerSlot(source, sslot);
440 }
Jesse Hall38efe862013-04-06 23:12:29 -0700441 }
Ian Elliotta2eb34c2017-07-18 11:05:49 -0600442 if (outBufferAge) {
443 *outBufferAge = 0;
444 }
KaiChieh Chuangc5222132019-12-20 07:38:19 +0800445
446 if ((mProducerSlotNeedReallocation & (1ULL << *pslot)) != 0) {
447 result |= BUFFER_NEEDS_REALLOCATION;
448 }
449
Jesse Hall38efe862013-04-06 23:12:29 -0700450 return result;
451}
452
Dan Stoza88a459a2014-03-12 09:34:36 -0700453status_t VirtualDisplaySurface::detachBuffer(int /* slot */) {
454 VDS_LOGE("detachBuffer is not available for VirtualDisplaySurface");
455 return INVALID_OPERATION;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800456}
457
Dan Stozad9822a32014-03-28 15:25:31 -0700458status_t VirtualDisplaySurface::detachNextBuffer(
459 sp<GraphicBuffer>* /* outBuffer */, sp<Fence>* /* outFence */) {
460 VDS_LOGE("detachNextBuffer is not available for VirtualDisplaySurface");
461 return INVALID_OPERATION;
462}
463
Dan Stoza88a459a2014-03-12 09:34:36 -0700464status_t VirtualDisplaySurface::attachBuffer(int* /* outSlot */,
465 const sp<GraphicBuffer>& /* buffer */) {
466 VDS_LOGE("attachBuffer is not available for VirtualDisplaySurface");
467 return INVALID_OPERATION;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800468}
469
Jesse Hall38efe862013-04-06 23:12:29 -0700470status_t VirtualDisplaySurface::queueBuffer(int pslot,
471 const QueueBufferInput& input, QueueBufferOutput* output) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700472 if (!mDisplayId) {
Michael Lentine47e45402014-07-18 15:34:25 -0700473 return mSource[SOURCE_SINK]->queueBuffer(pslot, input, output);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700474 }
Michael Lentine47e45402014-07-18 15:34:25 -0700475
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800476 VDS_LOGW_IF(mDbgState != DBG_STATE_GPU, "Unexpected queueBuffer(pslot=%d) in %s state", pslot,
477 dbgStateStr());
478 mDbgState = DBG_STATE_GPU_DONE;
Jesse Hall38efe862013-04-06 23:12:29 -0700479
480 VDS_LOGV("queueBuffer pslot=%d", pslot);
481
482 status_t result;
483 if (mCompositionType == COMPOSITION_MIXED) {
484 // Queue the buffer back into the scratch pool
485 QueueBufferOutput scratchQBO;
486 int sslot = mapProducer2SourceSlot(SOURCE_SCRATCH, pslot);
Mathias Agopiandb89edc2013-08-02 01:40:18 -0700487 result = mSource[SOURCE_SCRATCH]->queueBuffer(sslot, input, &scratchQBO);
Jesse Hall38efe862013-04-06 23:12:29 -0700488 if (result != NO_ERROR)
489 return result;
490
491 // Now acquire the buffer from the scratch pool -- should be the same
492 // slot and fence as we just queued.
493 Mutex::Autolock lock(mMutex);
Dan Stoza11611f92015-03-12 15:12:44 -0700494 BufferItem item;
Jesse Hallbce76112013-07-16 13:46:20 -0700495 result = acquireBufferLocked(&item, 0);
Jesse Hall38efe862013-04-06 23:12:29 -0700496 if (result != NO_ERROR)
497 return result;
Pablo Ceballos47650f42015-08-04 16:38:17 -0700498 VDS_LOGW_IF(item.mSlot != sslot,
Jesse Hall38efe862013-04-06 23:12:29 -0700499 "queueBuffer: acquired sslot %d from SCRATCH after queueing sslot %d",
Pablo Ceballos47650f42015-08-04 16:38:17 -0700500 item.mSlot, sslot);
501 mFbProducerSlot = mapSource2ProducerSlot(SOURCE_SCRATCH, item.mSlot);
502 mFbFence = mSlots[item.mSlot].mFence;
Jesse Hall38efe862013-04-06 23:12:29 -0700503
504 } else {
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800505 LOG_FATAL_IF(mCompositionType != COMPOSITION_GPU,
506 "Unexpected queueBuffer in state %s for compositionType %s", dbgStateStr(),
507 dbgCompositionTypeStr(mCompositionType));
Jesse Hall38efe862013-04-06 23:12:29 -0700508
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800509 // Extract the GPU release fence for HWC to acquire
Jesse Hall38efe862013-04-06 23:12:29 -0700510 int64_t timestamp;
Andy McFadden3c256212013-08-16 14:55:39 -0700511 bool isAutoTimestamp;
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800512 android_dataspace dataSpace;
Jesse Hall38efe862013-04-06 23:12:29 -0700513 Rect crop;
514 int scalingMode;
515 uint32_t transform;
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800516 input.deflate(&timestamp, &isAutoTimestamp, &dataSpace, &crop,
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700517 &scalingMode, &transform, &mFbFence);
Jesse Hall38efe862013-04-06 23:12:29 -0700518
519 mFbProducerSlot = pslot;
Jesse Hall028dc8f2013-08-20 16:35:32 -0700520 mOutputFence = mFbFence;
Jesse Hall38efe862013-04-06 23:12:29 -0700521 }
522
Brian Anderson3d4039d2016-09-23 16:31:30 -0700523 // This moves the frame timestamps and keeps a copy of all other fields.
524 *output = std::move(mQueueBufferOutput);
Jesse Hall38efe862013-04-06 23:12:29 -0700525 return NO_ERROR;
526}
527
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700528status_t VirtualDisplaySurface::cancelBuffer(int pslot,
529 const sp<Fence>& fence) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700530 if (!mDisplayId) {
Michael Lentinefd9d1832014-07-30 15:39:17 -0700531 return mSource[SOURCE_SINK]->cancelBuffer(mapProducer2SourceSlot(SOURCE_SINK, pslot), fence);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700532 }
Michael Lentine47e45402014-07-18 15:34:25 -0700533
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800534 VDS_LOGW_IF(mDbgState != DBG_STATE_GPU, "Unexpected cancelBuffer(pslot=%d) in %s state", pslot,
535 dbgStateStr());
Jesse Hall38efe862013-04-06 23:12:29 -0700536 VDS_LOGV("cancelBuffer pslot=%d", pslot);
537 Source source = fbSourceForCompositionType(mCompositionType);
538 return mSource[source]->cancelBuffer(
539 mapProducer2SourceSlot(source, pslot), fence);
540}
541
542int VirtualDisplaySurface::query(int what, int* value) {
Michael Lentine47e45402014-07-18 15:34:25 -0700543 switch (what) {
544 case NATIVE_WINDOW_WIDTH:
545 *value = mSinkBufferWidth;
546 break;
547 case NATIVE_WINDOW_HEIGHT:
548 *value = mSinkBufferHeight;
549 break;
550 default:
551 return mSource[SOURCE_SINK]->query(what, value);
552 }
553 return NO_ERROR;
Jesse Hall38efe862013-04-06 23:12:29 -0700554}
555
Dan Stozaf0eaf252014-03-21 13:05:51 -0700556status_t VirtualDisplaySurface::connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700557 int api, bool producerControlledByApp,
Mathias Agopian595264f2013-07-16 22:56:09 -0700558 QueueBufferOutput* output) {
Jesse Hall38efe862013-04-06 23:12:29 -0700559 QueueBufferOutput qbo;
Dan Stozaf0eaf252014-03-21 13:05:51 -0700560 status_t result = mSource[SOURCE_SINK]->connect(listener, api,
561 producerControlledByApp, &qbo);
Jesse Hall38efe862013-04-06 23:12:29 -0700562 if (result == NO_ERROR) {
Brian Anderson3d4039d2016-09-23 16:31:30 -0700563 updateQueueBufferOutput(std::move(qbo));
564 // This moves the frame timestamps and keeps a copy of all other fields.
565 *output = std::move(mQueueBufferOutput);
Jesse Hall38efe862013-04-06 23:12:29 -0700566 }
567 return result;
568}
569
Robert Carr97b9c862016-09-08 13:54:35 -0700570status_t VirtualDisplaySurface::disconnect(int api, DisconnectMode mode) {
571 return mSource[SOURCE_SINK]->disconnect(api, mode);
Jesse Hall38efe862013-04-06 23:12:29 -0700572}
573
Jesse Hall399184a2014-03-03 15:42:54 -0800574status_t VirtualDisplaySurface::setSidebandStream(const sp<NativeHandle>& /*stream*/) {
575 return INVALID_OPERATION;
576}
577
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700578void VirtualDisplaySurface::allocateBuffers(uint32_t /* width */,
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700579 uint32_t /* height */, PixelFormat /* format */, uint64_t /* usage */) {
Dan Stoza29a3e902014-06-20 13:13:57 -0700580 // TODO: Should we actually allocate buffers for a virtual display?
581}
582
Dan Stoza9de72932015-04-16 17:28:43 -0700583status_t VirtualDisplaySurface::allowAllocation(bool /* allow */) {
584 return INVALID_OPERATION;
585}
586
Dan Stoza812ed062015-06-02 15:45:22 -0700587status_t VirtualDisplaySurface::setGenerationNumber(uint32_t /* generation */) {
588 ALOGE("setGenerationNumber not supported on VirtualDisplaySurface");
589 return INVALID_OPERATION;
590}
591
Dan Stozac6f30bd2015-06-08 09:32:50 -0700592String8 VirtualDisplaySurface::getConsumerName() const {
593 return String8("VirtualDisplaySurface");
594}
595
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700596status_t VirtualDisplaySurface::setSharedBufferMode(bool /*sharedBufferMode*/) {
597 ALOGE("setSharedBufferMode not supported on VirtualDisplaySurface");
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800598 return INVALID_OPERATION;
599}
600
601status_t VirtualDisplaySurface::setAutoRefresh(bool /*autoRefresh*/) {
602 ALOGE("setAutoRefresh not supported on VirtualDisplaySurface");
603 return INVALID_OPERATION;
Pablo Ceballosccdfd602015-10-07 15:05:45 -0700604}
605
Dan Stoza127fc632015-06-30 13:43:32 -0700606status_t VirtualDisplaySurface::setDequeueTimeout(nsecs_t /* timeout */) {
607 ALOGE("setDequeueTimeout not supported on VirtualDisplaySurface");
608 return INVALID_OPERATION;
609}
610
Dan Stoza50101d02016-04-07 16:53:23 -0700611status_t VirtualDisplaySurface::getLastQueuedBuffer(
John Reck1a61da52016-04-28 13:18:15 -0700612 sp<GraphicBuffer>* /*outBuffer*/, sp<Fence>* /*outFence*/,
613 float[16] /* outTransformMatrix*/) {
Dan Stoza50101d02016-04-07 16:53:23 -0700614 ALOGE("getLastQueuedBuffer not supported on VirtualDisplaySurface");
615 return INVALID_OPERATION;
616}
617
Pablo Ceballos8e3e92b2016-06-27 17:56:53 -0700618status_t VirtualDisplaySurface::getUniqueId(uint64_t* /*outId*/) const {
619 ALOGE("getUniqueId not supported on VirtualDisplaySurface");
620 return INVALID_OPERATION;
621}
622
Chia-I Wue2786ea2017-08-07 10:36:08 -0700623status_t VirtualDisplaySurface::getConsumerUsage(uint64_t* outUsage) const {
624 return mSource[SOURCE_SINK]->getConsumerUsage(outUsage);
625}
626
Jesse Hall38efe862013-04-06 23:12:29 -0700627void VirtualDisplaySurface::updateQueueBufferOutput(
Brian Anderson3d4039d2016-09-23 16:31:30 -0700628 QueueBufferOutput&& qbo) {
629 mQueueBufferOutput = std::move(qbo);
Brian Andersonbaaad322016-07-22 15:55:13 -0700630 mQueueBufferOutput.transformHint = 0;
Jesse Hall38efe862013-04-06 23:12:29 -0700631}
632
633void VirtualDisplaySurface::resetPerFrameState() {
634 mCompositionType = COMPOSITION_UNKNOWN;
mayank parsharb988f852014-01-10 10:27:45 +0530635 mFbFence = Fence::NO_FENCE;
Jesse Hall028dc8f2013-08-20 16:35:32 -0700636 mOutputFence = Fence::NO_FENCE;
Jesse Hall38efe862013-04-06 23:12:29 -0700637 mOutputProducerSlot = -1;
mayank parsharfdfde882014-01-23 15:08:31 +0530638 mFbProducerSlot = -1;
Jesse Hall38efe862013-04-06 23:12:29 -0700639}
640
Jesse Hall028dc8f2013-08-20 16:35:32 -0700641status_t VirtualDisplaySurface::refreshOutputBuffer() {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700642 LOG_FATAL_IF(!mDisplayId);
643
Jesse Hall028dc8f2013-08-20 16:35:32 -0700644 if (mOutputProducerSlot >= 0) {
645 mSource[SOURCE_SINK]->cancelBuffer(
646 mapProducer2SourceSlot(SOURCE_SINK, mOutputProducerSlot),
647 mOutputFence);
648 }
649
650 int sslot;
Jesse Hall1e27ba22013-09-27 09:05:09 -0700651 status_t result = dequeueBuffer(SOURCE_SINK, mOutputFormat, mOutputUsage,
652 &sslot, &mOutputFence);
Jesse Hall028dc8f2013-08-20 16:35:32 -0700653 if (result < 0)
654 return result;
655 mOutputProducerSlot = mapSource2ProducerSlot(SOURCE_SINK, sslot);
656
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800657 // On GPU-only frames, we don't have the right output buffer acquire fence
658 // until after GPU calls queueBuffer(). So here we just set the buffer
Jesse Hallb716e572013-10-01 17:25:20 -0700659 // (for use in HWC prepare) but not the fence; we'll call this again with
660 // the proper fence once we have it.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700661 result = mHwc.setOutputBuffer(*mDisplayId, Fence::NO_FENCE,
662 mProducerBuffers[mOutputProducerSlot]);
Jesse Hall028dc8f2013-08-20 16:35:32 -0700663
664 return result;
665}
666
Jesse Hall38efe862013-04-06 23:12:29 -0700667// This slot mapping function is its own inverse, so two copies are unnecessary.
668// Both are kept to make the intent clear where the function is called, and for
669// the (unlikely) chance that we switch to a different mapping function.
670int VirtualDisplaySurface::mapSource2ProducerSlot(Source source, int sslot) {
671 if (source == SOURCE_SCRATCH) {
672 return BufferQueue::NUM_BUFFER_SLOTS - sslot - 1;
673 } else {
674 return sslot;
675 }
676}
677int VirtualDisplaySurface::mapProducer2SourceSlot(Source source, int pslot) {
678 return mapSource2ProducerSlot(source, pslot);
679}
680
681VirtualDisplaySurface::Source
682VirtualDisplaySurface::fbSourceForCompositionType(CompositionType type) {
683 return type == COMPOSITION_MIXED ? SOURCE_SCRATCH : SOURCE_SINK;
684}
685
686const char* VirtualDisplaySurface::dbgStateStr() const {
687 switch (mDbgState) {
Peiyong Linf3ffc4e2019-12-13 00:46:24 -0800688 case DBG_STATE_IDLE:
689 return "IDLE";
690 case DBG_STATE_PREPARED:
691 return "PREPARED";
692 case DBG_STATE_GPU:
693 return "GPU";
694 case DBG_STATE_GPU_DONE:
695 return "GPU_DONE";
696 case DBG_STATE_HWC:
697 return "HWC";
698 default:
699 return "INVALID";
Jesse Hall38efe862013-04-06 23:12:29 -0700700 }
701}
702
703const char* VirtualDisplaySurface::dbgSourceStr(Source s) {
704 switch (s) {
705 case SOURCE_SINK: return "SINK";
706 case SOURCE_SCRATCH: return "SCRATCH";
707 default: return "INVALID";
708 }
709}
710
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700711// ---------------------------------------------------------------------------
712} // namespace android
713// ---------------------------------------------------------------------------
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800714
715// TODO(b/129481165): remove the #pragma below and fix conversion issues
716#pragma clang diagnostic pop // ignored "-Wconversion"