| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2 | * Copyright (C) 2010 The Android Open Source Project | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 |  | 
|  | 17 | #define LOG_TAG "Surface" | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
|  | 19 | //#define LOG_NDEBUG 0 | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 |  | 
| Mathias Agopian | 05debe1 | 2017-02-08 17:04:18 -0800 | [diff] [blame] | 21 | #include <gui/Surface.h> | 
| Mathias Agopian | b0e76f4 | 2012-03-23 14:15:44 -0700 | [diff] [blame] | 22 |  | 
| Yiwei Zhang | 9e919eb | 2019-03-07 23:21:40 -0800 | [diff] [blame] | 23 | #include <condition_variable> | 
|  | 24 | #include <deque> | 
|  | 25 | #include <mutex> | 
|  | 26 | #include <thread> | 
|  | 27 |  | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 28 | #include <inttypes.h> | 
|  | 29 |  | 
| Mathias Agopian | 05debe1 | 2017-02-08 17:04:18 -0800 | [diff] [blame] | 30 | #include <android/native_window.h> | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 31 |  | 
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 32 | #include <utils/Log.h> | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 33 | #include <utils/Trace.h> | 
| Rachad | 7cb0d39 | 2014-07-29 17:53:53 -0700 | [diff] [blame] | 34 | #include <utils/NativeHandle.h> | 
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 35 |  | 
| Ian Elliott | 62c48c9 | 2017-01-20 13:13:20 -0700 | [diff] [blame] | 36 | #include <ui/DisplayStatInfo.h> | 
| Courtney Goeltzenleuchter | c5b97c5 | 2017-02-26 14:47:13 -0700 | [diff] [blame] | 37 | #include <ui/Fence.h> | 
| Shuzhen Wang | 067fcd3 | 2019-08-14 10:41:12 -0700 | [diff] [blame] | 38 | #include <ui/GraphicBuffer.h> | 
| Courtney Goeltzenleuchter | c5b97c5 | 2017-02-26 14:47:13 -0700 | [diff] [blame] | 39 | #include <ui/HdrCapabilities.h> | 
|  | 40 | #include <ui/Region.h> | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 41 |  | 
| Mathias Agopian | 2b5dd40 | 2017-02-07 17:36:19 -0800 | [diff] [blame] | 42 | #include <gui/BufferItem.h> | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 43 | #include <gui/IProducerListener.h> | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 44 |  | 
| Mathias Agopian | 2b5dd40 | 2017-02-07 17:36:19 -0800 | [diff] [blame] | 45 | #include <gui/ISurfaceComposer.h> | 
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 46 | #include <gui/LayerState.h> | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 47 | #include <private/gui/ComposerService.h> | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 48 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | namespace android { | 
|  | 50 |  | 
| Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 51 | using ui::ColorMode; | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 52 | using ui::Dataspace; | 
| Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 53 |  | 
| Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 54 | namespace { | 
|  | 55 |  | 
|  | 56 | bool isInterceptorRegistrationOp(int op) { | 
|  | 57 | return op == NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR || | 
|  | 58 | op == NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR || | 
|  | 59 | op == NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR || | 
| John Reck | 401cda6 | 2020-05-07 16:04:41 -0700 | [diff] [blame] | 60 | op == NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR || | 
|  | 61 | op == NATIVE_WINDOW_SET_QUERY_INTERCEPTOR; | 
| Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 62 | } | 
|  | 63 |  | 
|  | 64 | } // namespace | 
|  | 65 |  | 
| Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 66 | Surface::Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp) | 
|  | 67 | : mGraphicBufferProducer(bufferProducer), | 
|  | 68 | mCrop(Rect::EMPTY_RECT), | 
|  | 69 | mBufferAge(0), | 
|  | 70 | mGenerationNumber(0), | 
|  | 71 | mSharedBufferMode(false), | 
|  | 72 | mAutoRefresh(false), | 
|  | 73 | mSharedBufferSlot(BufferItem::INVALID_BUFFER_SLOT), | 
|  | 74 | mSharedBufferHasBeenQueued(false), | 
|  | 75 | mQueriedSupportedTimestamps(false), | 
|  | 76 | mFrameTimestampsSupportsPresent(false), | 
|  | 77 | mEnableFrameTimestamps(false), | 
|  | 78 | mFrameEventHistory(std::make_unique<ProducerFrameEventHistory>()) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 79 | // Initialize the ANativeWindow function pointers. | 
|  | 80 | ANativeWindow::setSwapInterval  = hook_setSwapInterval; | 
|  | 81 | ANativeWindow::dequeueBuffer    = hook_dequeueBuffer; | 
|  | 82 | ANativeWindow::cancelBuffer     = hook_cancelBuffer; | 
|  | 83 | ANativeWindow::queueBuffer      = hook_queueBuffer; | 
|  | 84 | ANativeWindow::query            = hook_query; | 
|  | 85 | ANativeWindow::perform          = hook_perform; | 
|  | 86 |  | 
|  | 87 | ANativeWindow::dequeueBuffer_DEPRECATED = hook_dequeueBuffer_DEPRECATED; | 
|  | 88 | ANativeWindow::cancelBuffer_DEPRECATED  = hook_cancelBuffer_DEPRECATED; | 
|  | 89 | ANativeWindow::lockBuffer_DEPRECATED    = hook_lockBuffer_DEPRECATED; | 
|  | 90 | ANativeWindow::queueBuffer_DEPRECATED   = hook_queueBuffer_DEPRECATED; | 
|  | 91 |  | 
|  | 92 | const_cast<int&>(ANativeWindow::minSwapInterval) = 0; | 
|  | 93 | const_cast<int&>(ANativeWindow::maxSwapInterval) = 1; | 
|  | 94 |  | 
|  | 95 | mReqWidth = 0; | 
|  | 96 | mReqHeight = 0; | 
|  | 97 | mReqFormat = 0; | 
|  | 98 | mReqUsage = 0; | 
|  | 99 | mTimestamp = NATIVE_WINDOW_TIMESTAMP_AUTO; | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 100 | mDataSpace = Dataspace::UNKNOWN; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 101 | mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE; | 
|  | 102 | mTransform = 0; | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 103 | mStickyTransform = 0; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 104 | mDefaultWidth = 0; | 
|  | 105 | mDefaultHeight = 0; | 
|  | 106 | mUserWidth = 0; | 
|  | 107 | mUserHeight = 0; | 
|  | 108 | mTransformHint = 0; | 
|  | 109 | mConsumerRunningBehind = false; | 
|  | 110 | mConnectedToCpu = false; | 
| Eino-Ville Talvala | 7895e90 | 2013-08-21 11:53:37 -0700 | [diff] [blame] | 111 | mProducerControlledByApp = controlledByApp; | 
| Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 112 | mSwapIntervalZero = false; | 
| Yiwei Zhang | 74c9cc3 | 2020-06-20 03:35:17 -0700 | [diff] [blame] | 113 | mMaxBufferCount = NUM_BUFFER_SLOTS; | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 114 | } | 
|  | 115 |  | 
| Mathias Agopian | 35ffa6a | 2013-03-12 18:45:09 -0700 | [diff] [blame] | 116 | Surface::~Surface() { | 
|  | 117 | if (mConnectedToCpu) { | 
|  | 118 | Surface::disconnect(NATIVE_WINDOW_API_CPU); | 
|  | 119 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 120 | } | 
|  | 121 |  | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 122 | sp<ISurfaceComposer> Surface::composerService() const { | 
|  | 123 | return ComposerService::getComposerService(); | 
|  | 124 | } | 
|  | 125 |  | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 126 | nsecs_t Surface::now() const { | 
|  | 127 | return systemTime(); | 
|  | 128 | } | 
|  | 129 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 130 | sp<IGraphicBufferProducer> Surface::getIGraphicBufferProducer() const { | 
|  | 131 | return mGraphicBufferProducer; | 
|  | 132 | } | 
|  | 133 |  | 
| Wonsik Kim | 0ee14ca | 2014-03-17 17:46:53 +0900 | [diff] [blame] | 134 | void Surface::setSidebandStream(const sp<NativeHandle>& stream) { | 
|  | 135 | mGraphicBufferProducer->setSidebandStream(stream); | 
|  | 136 | } | 
|  | 137 |  | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 138 | void Surface::allocateBuffers() { | 
|  | 139 | uint32_t reqWidth = mReqWidth ? mReqWidth : mUserWidth; | 
|  | 140 | uint32_t reqHeight = mReqHeight ? mReqHeight : mUserHeight; | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 141 | mGraphicBufferProducer->allocateBuffers(reqWidth, reqHeight, | 
|  | 142 | mReqFormat, mReqUsage); | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 143 | } | 
|  | 144 |  | 
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 145 | status_t Surface::setGenerationNumber(uint32_t generation) { | 
|  | 146 | status_t result = mGraphicBufferProducer->setGenerationNumber(generation); | 
|  | 147 | if (result == NO_ERROR) { | 
|  | 148 | mGenerationNumber = generation; | 
|  | 149 | } | 
|  | 150 | return result; | 
|  | 151 | } | 
|  | 152 |  | 
| Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 153 | uint64_t Surface::getNextFrameNumber() const { | 
| Pablo Ceballos | bc8c192 | 2016-07-01 14:15:41 -0700 | [diff] [blame] | 154 | Mutex::Autolock lock(mMutex); | 
|  | 155 | return mNextFrameNumber; | 
| Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
| Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 158 | String8 Surface::getConsumerName() const { | 
|  | 159 | return mGraphicBufferProducer->getConsumerName(); | 
|  | 160 | } | 
|  | 161 |  | 
| Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 162 | status_t Surface::setDequeueTimeout(nsecs_t timeout) { | 
|  | 163 | return mGraphicBufferProducer->setDequeueTimeout(timeout); | 
|  | 164 | } | 
|  | 165 |  | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 166 | status_t Surface::getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, | 
| John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 167 | sp<Fence>* outFence, float outTransformMatrix[16]) { | 
|  | 168 | return mGraphicBufferProducer->getLastQueuedBuffer(outBuffer, outFence, | 
|  | 169 | outTransformMatrix); | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 170 | } | 
|  | 171 |  | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 172 | status_t Surface::getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration) { | 
|  | 173 | ATRACE_CALL(); | 
|  | 174 |  | 
|  | 175 | DisplayStatInfo stats; | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 176 | status_t result = composerService()->getDisplayStats(nullptr, &stats); | 
| Chih-Hung Hsieh | d66be0a | 2017-10-05 13:51:32 -0700 | [diff] [blame] | 177 | if (result != NO_ERROR) { | 
|  | 178 | return result; | 
|  | 179 | } | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 180 |  | 
|  | 181 | *outRefreshDuration = stats.vsyncPeriod; | 
|  | 182 |  | 
|  | 183 | return NO_ERROR; | 
|  | 184 | } | 
|  | 185 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 186 | void Surface::enableFrameTimestamps(bool enable) { | 
|  | 187 | Mutex::Autolock lock(mMutex); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 188 | // If going from disabled to enabled, get the initial values for | 
|  | 189 | // compositor and display timing. | 
|  | 190 | if (!mEnableFrameTimestamps && enable) { | 
|  | 191 | FrameEventHistoryDelta delta; | 
|  | 192 | mGraphicBufferProducer->getFrameTimestamps(&delta); | 
|  | 193 | mFrameEventHistory->applyDelta(delta); | 
|  | 194 | } | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 195 | mEnableFrameTimestamps = enable; | 
|  | 196 | } | 
|  | 197 |  | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 198 | status_t Surface::getCompositorTiming( | 
|  | 199 | nsecs_t* compositeDeadline, nsecs_t* compositeInterval, | 
|  | 200 | nsecs_t* compositeToPresentLatency) { | 
|  | 201 | Mutex::Autolock lock(mMutex); | 
|  | 202 | if (!mEnableFrameTimestamps) { | 
|  | 203 | return INVALID_OPERATION; | 
|  | 204 | } | 
|  | 205 |  | 
|  | 206 | if (compositeDeadline != nullptr) { | 
|  | 207 | *compositeDeadline = | 
|  | 208 | mFrameEventHistory->getNextCompositeDeadline(now()); | 
|  | 209 | } | 
|  | 210 | if (compositeInterval != nullptr) { | 
|  | 211 | *compositeInterval = mFrameEventHistory->getCompositeInterval(); | 
|  | 212 | } | 
|  | 213 | if (compositeToPresentLatency != nullptr) { | 
|  | 214 | *compositeToPresentLatency = | 
|  | 215 | mFrameEventHistory->getCompositeToPresentLatency(); | 
|  | 216 | } | 
|  | 217 | return NO_ERROR; | 
|  | 218 | } | 
|  | 219 |  | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 220 | static bool checkConsumerForUpdates( | 
|  | 221 | const FrameEvents* e, const uint64_t lastFrameNumber, | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 222 | const nsecs_t* outLatchTime, | 
|  | 223 | const nsecs_t* outFirstRefreshStartTime, | 
|  | 224 | const nsecs_t* outLastRefreshStartTime, | 
| Brian Anderson | b04c6f0 | 2016-10-21 12:57:46 -0700 | [diff] [blame] | 225 | const nsecs_t* outGpuCompositionDoneTime, | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 226 | const nsecs_t* outDisplayPresentTime, | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 227 | const nsecs_t* outDequeueReadyTime, | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 228 | const nsecs_t* outReleaseTime) { | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 229 | bool checkForLatch = (outLatchTime != nullptr) && !e->hasLatchInfo(); | 
|  | 230 | bool checkForFirstRefreshStart = (outFirstRefreshStartTime != nullptr) && | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 231 | !e->hasFirstRefreshStartInfo(); | 
| Brian Anderson | b04c6f0 | 2016-10-21 12:57:46 -0700 | [diff] [blame] | 232 | bool checkForGpuCompositionDone = (outGpuCompositionDoneTime != nullptr) && | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 233 | !e->hasGpuCompositionDoneInfo(); | 
|  | 234 | bool checkForDisplayPresent = (outDisplayPresentTime != nullptr) && | 
|  | 235 | !e->hasDisplayPresentInfo(); | 
|  | 236 |  | 
| Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 237 | // LastRefreshStart, DequeueReady, and Release are never available for the | 
|  | 238 | // last frame. | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 239 | bool checkForLastRefreshStart = (outLastRefreshStartTime != nullptr) && | 
|  | 240 | !e->hasLastRefreshStartInfo() && | 
|  | 241 | (e->frameNumber != lastFrameNumber); | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 242 | bool checkForDequeueReady = (outDequeueReadyTime != nullptr) && | 
|  | 243 | !e->hasDequeueReadyInfo() && (e->frameNumber != lastFrameNumber); | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 244 | bool checkForRelease = (outReleaseTime != nullptr) && | 
|  | 245 | !e->hasReleaseInfo() && (e->frameNumber != lastFrameNumber); | 
|  | 246 |  | 
|  | 247 | // RequestedPresent and Acquire info are always available producer-side. | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 248 | return checkForLatch || checkForFirstRefreshStart || | 
| Brian Anderson | b04c6f0 | 2016-10-21 12:57:46 -0700 | [diff] [blame] | 249 | checkForLastRefreshStart || checkForGpuCompositionDone || | 
| Brian Anderson | 4e606e3 | 2017-03-16 15:34:57 -0700 | [diff] [blame] | 250 | checkForDisplayPresent || checkForDequeueReady || checkForRelease; | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 251 | } | 
|  | 252 |  | 
| Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 253 | static void getFrameTimestamp(nsecs_t *dst, const nsecs_t& src) { | 
|  | 254 | if (dst != nullptr) { | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 255 | // We always get valid timestamps for these eventually. | 
|  | 256 | *dst = (src == FrameEvents::TIMESTAMP_PENDING) ? | 
|  | 257 | NATIVE_WINDOW_TIMESTAMP_PENDING : src; | 
| Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 258 | } | 
|  | 259 | } | 
|  | 260 |  | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 261 | static void getFrameTimestampFence(nsecs_t *dst, | 
|  | 262 | const std::shared_ptr<FenceTime>& src, bool fenceShouldBeKnown) { | 
| Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 263 | if (dst != nullptr) { | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 264 | if (!fenceShouldBeKnown) { | 
|  | 265 | *dst = NATIVE_WINDOW_TIMESTAMP_PENDING; | 
|  | 266 | return; | 
|  | 267 | } | 
|  | 268 |  | 
| Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 269 | nsecs_t signalTime = src->getSignalTime(); | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 270 | *dst = (signalTime == Fence::SIGNAL_TIME_PENDING) ? | 
|  | 271 | NATIVE_WINDOW_TIMESTAMP_PENDING : | 
|  | 272 | (signalTime == Fence::SIGNAL_TIME_INVALID) ? | 
|  | 273 | NATIVE_WINDOW_TIMESTAMP_INVALID : | 
|  | 274 | signalTime; | 
| Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 275 | } | 
|  | 276 | } | 
|  | 277 |  | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 278 | status_t Surface::getFrameTimestamps(uint64_t frameNumber, | 
| Brian Anderson | dbd0ea8 | 2016-07-22 09:38:59 -0700 | [diff] [blame] | 279 | nsecs_t* outRequestedPresentTime, nsecs_t* outAcquireTime, | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 280 | nsecs_t* outLatchTime, nsecs_t* outFirstRefreshStartTime, | 
| Brian Anderson | b04c6f0 | 2016-10-21 12:57:46 -0700 | [diff] [blame] | 281 | nsecs_t* outLastRefreshStartTime, nsecs_t* outGpuCompositionDoneTime, | 
| Brian Anderson | 4e606e3 | 2017-03-16 15:34:57 -0700 | [diff] [blame] | 282 | nsecs_t* outDisplayPresentTime, nsecs_t* outDequeueReadyTime, | 
|  | 283 | nsecs_t* outReleaseTime) { | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 284 | ATRACE_CALL(); | 
|  | 285 |  | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 286 | Mutex::Autolock lock(mMutex); | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 287 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 288 | if (!mEnableFrameTimestamps) { | 
|  | 289 | return INVALID_OPERATION; | 
|  | 290 | } | 
|  | 291 |  | 
| Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 292 | // Verify the requested timestamps are supported. | 
|  | 293 | querySupportedTimestampsLocked(); | 
|  | 294 | if (outDisplayPresentTime != nullptr && !mFrameTimestampsSupportsPresent) { | 
|  | 295 | return BAD_VALUE; | 
|  | 296 | } | 
|  | 297 |  | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 298 | FrameEvents* events = mFrameEventHistory->getFrame(frameNumber); | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 299 | if (events == nullptr) { | 
|  | 300 | // If the entry isn't available in the producer, it's definitely not | 
|  | 301 | // available in the consumer. | 
|  | 302 | return NAME_NOT_FOUND; | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 303 | } | 
|  | 304 |  | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 305 | // Update our cache of events if the requested events are not available. | 
|  | 306 | if (checkConsumerForUpdates(events, mLastFrameNumber, | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 307 | outLatchTime, outFirstRefreshStartTime, outLastRefreshStartTime, | 
| Brian Anderson | b04c6f0 | 2016-10-21 12:57:46 -0700 | [diff] [blame] | 308 | outGpuCompositionDoneTime, outDisplayPresentTime, | 
| Brian Anderson | 4e606e3 | 2017-03-16 15:34:57 -0700 | [diff] [blame] | 309 | outDequeueReadyTime, outReleaseTime)) { | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 310 | FrameEventHistoryDelta delta; | 
|  | 311 | mGraphicBufferProducer->getFrameTimestamps(&delta); | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 312 | mFrameEventHistory->applyDelta(delta); | 
|  | 313 | events = mFrameEventHistory->getFrame(frameNumber); | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 314 | } | 
|  | 315 |  | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 316 | if (events == nullptr) { | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 317 | // The entry was available before the update, but was overwritten | 
|  | 318 | // after the update. Make sure not to send the wrong frame's data. | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 319 | return NAME_NOT_FOUND; | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 320 | } | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 321 |  | 
| Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 322 | getFrameTimestamp(outRequestedPresentTime, events->requestedPresentTime); | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 323 | getFrameTimestamp(outLatchTime, events->latchTime); | 
|  | 324 | getFrameTimestamp(outFirstRefreshStartTime, events->firstRefreshStartTime); | 
|  | 325 | getFrameTimestamp(outLastRefreshStartTime, events->lastRefreshStartTime); | 
|  | 326 | getFrameTimestamp(outDequeueReadyTime, events->dequeueReadyTime); | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 327 |  | 
| Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 328 | getFrameTimestampFence(outAcquireTime, events->acquireFence, | 
|  | 329 | events->hasAcquireInfo()); | 
|  | 330 | getFrameTimestampFence(outGpuCompositionDoneTime, | 
|  | 331 | events->gpuCompositionDoneFence, | 
|  | 332 | events->hasGpuCompositionDoneInfo()); | 
|  | 333 | getFrameTimestampFence(outDisplayPresentTime, events->displayPresentFence, | 
|  | 334 | events->hasDisplayPresentInfo()); | 
|  | 335 | getFrameTimestampFence(outReleaseTime, events->releaseFence, | 
|  | 336 | events->hasReleaseInfo()); | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 337 |  | 
|  | 338 | return NO_ERROR; | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 339 | } | 
|  | 340 |  | 
| Courtney Goeltzenleuchter | 1eb1b27 | 2017-02-02 16:51:06 -0700 | [diff] [blame] | 341 | status_t Surface::getWideColorSupport(bool* supported) { | 
|  | 342 | ATRACE_CALL(); | 
|  | 343 |  | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 344 | const sp<IBinder> display = composerService()->getInternalDisplayToken(); | 
|  | 345 | if (display == nullptr) { | 
|  | 346 | return NAME_NOT_FOUND; | 
|  | 347 | } | 
|  | 348 |  | 
| Courtney Goeltzenleuchter | 1eb1b27 | 2017-02-02 16:51:06 -0700 | [diff] [blame] | 349 | *supported = false; | 
| Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 350 | status_t error = composerService()->isWideColorDisplay(display, supported); | 
|  | 351 | return error; | 
| Courtney Goeltzenleuchter | 1eb1b27 | 2017-02-02 16:51:06 -0700 | [diff] [blame] | 352 | } | 
|  | 353 |  | 
| Courtney Goeltzenleuchter | c5b97c5 | 2017-02-26 14:47:13 -0700 | [diff] [blame] | 354 | status_t Surface::getHdrSupport(bool* supported) { | 
|  | 355 | ATRACE_CALL(); | 
|  | 356 |  | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 357 | const sp<IBinder> display = composerService()->getInternalDisplayToken(); | 
|  | 358 | if (display == nullptr) { | 
|  | 359 | return NAME_NOT_FOUND; | 
|  | 360 | } | 
|  | 361 |  | 
| Courtney Goeltzenleuchter | c5b97c5 | 2017-02-26 14:47:13 -0700 | [diff] [blame] | 362 | HdrCapabilities hdrCapabilities; | 
|  | 363 | status_t err = | 
|  | 364 | composerService()->getHdrCapabilities(display, &hdrCapabilities); | 
|  | 365 |  | 
|  | 366 | if (err) | 
|  | 367 | return err; | 
|  | 368 |  | 
|  | 369 | *supported = !hdrCapabilities.getSupportedHdrTypes().empty(); | 
|  | 370 |  | 
|  | 371 | return NO_ERROR; | 
|  | 372 | } | 
|  | 373 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 374 | int Surface::hook_setSwapInterval(ANativeWindow* window, int interval) { | 
|  | 375 | Surface* c = getSelf(window); | 
|  | 376 | return c->setSwapInterval(interval); | 
|  | 377 | } | 
|  | 378 |  | 
|  | 379 | int Surface::hook_dequeueBuffer(ANativeWindow* window, | 
|  | 380 | ANativeWindowBuffer** buffer, int* fenceFd) { | 
|  | 381 | Surface* c = getSelf(window); | 
| Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 382 | { | 
|  | 383 | std::shared_lock<std::shared_mutex> lock(c->mInterceptorMutex); | 
|  | 384 | if (c->mDequeueInterceptor != nullptr) { | 
|  | 385 | auto interceptor = c->mDequeueInterceptor; | 
|  | 386 | auto data = c->mDequeueInterceptorData; | 
|  | 387 | return interceptor(window, Surface::dequeueBufferInternal, data, buffer, fenceFd); | 
|  | 388 | } | 
|  | 389 | } | 
|  | 390 | return c->dequeueBuffer(buffer, fenceFd); | 
|  | 391 | } | 
|  | 392 |  | 
|  | 393 | int Surface::dequeueBufferInternal(ANativeWindow* window, ANativeWindowBuffer** buffer, | 
|  | 394 | int* fenceFd) { | 
|  | 395 | Surface* c = getSelf(window); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 396 | return c->dequeueBuffer(buffer, fenceFd); | 
|  | 397 | } | 
|  | 398 |  | 
|  | 399 | int Surface::hook_cancelBuffer(ANativeWindow* window, | 
|  | 400 | ANativeWindowBuffer* buffer, int fenceFd) { | 
|  | 401 | Surface* c = getSelf(window); | 
| Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 402 | { | 
|  | 403 | std::shared_lock<std::shared_mutex> lock(c->mInterceptorMutex); | 
|  | 404 | if (c->mCancelInterceptor != nullptr) { | 
|  | 405 | auto interceptor = c->mCancelInterceptor; | 
|  | 406 | auto data = c->mCancelInterceptorData; | 
|  | 407 | return interceptor(window, Surface::cancelBufferInternal, data, buffer, fenceFd); | 
|  | 408 | } | 
|  | 409 | } | 
|  | 410 | return c->cancelBuffer(buffer, fenceFd); | 
|  | 411 | } | 
|  | 412 |  | 
|  | 413 | int Surface::cancelBufferInternal(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) { | 
|  | 414 | Surface* c = getSelf(window); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 415 | return c->cancelBuffer(buffer, fenceFd); | 
|  | 416 | } | 
|  | 417 |  | 
|  | 418 | int Surface::hook_queueBuffer(ANativeWindow* window, | 
|  | 419 | ANativeWindowBuffer* buffer, int fenceFd) { | 
|  | 420 | Surface* c = getSelf(window); | 
| Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 421 | { | 
|  | 422 | std::shared_lock<std::shared_mutex> lock(c->mInterceptorMutex); | 
|  | 423 | if (c->mQueueInterceptor != nullptr) { | 
|  | 424 | auto interceptor = c->mQueueInterceptor; | 
|  | 425 | auto data = c->mQueueInterceptorData; | 
|  | 426 | return interceptor(window, Surface::queueBufferInternal, data, buffer, fenceFd); | 
|  | 427 | } | 
|  | 428 | } | 
|  | 429 | return c->queueBuffer(buffer, fenceFd); | 
|  | 430 | } | 
|  | 431 |  | 
|  | 432 | int Surface::queueBufferInternal(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) { | 
|  | 433 | Surface* c = getSelf(window); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 434 | return c->queueBuffer(buffer, fenceFd); | 
|  | 435 | } | 
|  | 436 |  | 
|  | 437 | int Surface::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window, | 
|  | 438 | ANativeWindowBuffer** buffer) { | 
|  | 439 | Surface* c = getSelf(window); | 
|  | 440 | ANativeWindowBuffer* buf; | 
|  | 441 | int fenceFd = -1; | 
|  | 442 | int result = c->dequeueBuffer(&buf, &fenceFd); | 
| Mike Stroyan | 87709c9 | 2016-06-03 12:43:26 -0600 | [diff] [blame] | 443 | if (result != OK) { | 
|  | 444 | return result; | 
|  | 445 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 446 | sp<Fence> fence(new Fence(fenceFd)); | 
| Mathias Agopian | ea74d3b | 2013-05-16 18:03:22 -0700 | [diff] [blame] | 447 | int waitResult = fence->waitForever("dequeueBuffer_DEPRECATED"); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 448 | if (waitResult != OK) { | 
|  | 449 | ALOGE("dequeueBuffer_DEPRECATED: Fence::wait returned an error: %d", | 
|  | 450 | waitResult); | 
|  | 451 | c->cancelBuffer(buf, -1); | 
|  | 452 | return waitResult; | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 453 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 454 | *buffer = buf; | 
|  | 455 | return result; | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 456 | } | 
|  | 457 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 458 | int Surface::hook_cancelBuffer_DEPRECATED(ANativeWindow* window, | 
|  | 459 | ANativeWindowBuffer* buffer) { | 
|  | 460 | Surface* c = getSelf(window); | 
|  | 461 | return c->cancelBuffer(buffer, -1); | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 462 | } | 
|  | 463 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 464 | int Surface::hook_lockBuffer_DEPRECATED(ANativeWindow* window, | 
|  | 465 | ANativeWindowBuffer* buffer) { | 
|  | 466 | Surface* c = getSelf(window); | 
|  | 467 | return c->lockBuffer_DEPRECATED(buffer); | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 468 | } | 
|  | 469 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 470 | int Surface::hook_queueBuffer_DEPRECATED(ANativeWindow* window, | 
|  | 471 | ANativeWindowBuffer* buffer) { | 
|  | 472 | Surface* c = getSelf(window); | 
|  | 473 | return c->queueBuffer(buffer, -1); | 
| Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 474 | } | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 475 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 476 | int Surface::hook_perform(ANativeWindow* window, int operation, ...) { | 
|  | 477 | va_list args; | 
|  | 478 | va_start(args, operation); | 
|  | 479 | Surface* c = getSelf(window); | 
| Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 480 | int result; | 
|  | 481 | // Don't acquire shared ownership of the interceptor mutex if we're going to | 
|  | 482 | // do interceptor registration, as otherwise we'll deadlock on acquiring | 
|  | 483 | // exclusive ownership. | 
|  | 484 | if (!isInterceptorRegistrationOp(operation)) { | 
|  | 485 | std::shared_lock<std::shared_mutex> lock(c->mInterceptorMutex); | 
|  | 486 | if (c->mPerformInterceptor != nullptr) { | 
|  | 487 | result = c->mPerformInterceptor(window, Surface::performInternal, | 
|  | 488 | c->mPerformInterceptorData, operation, args); | 
|  | 489 | va_end(args); | 
|  | 490 | return result; | 
|  | 491 | } | 
|  | 492 | } | 
|  | 493 | result = c->perform(operation, args); | 
| Haixia Shi | d89c2bb | 2015-09-14 11:02:18 -0700 | [diff] [blame] | 494 | va_end(args); | 
|  | 495 | return result; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 496 | } | 
|  | 497 |  | 
| Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 498 | int Surface::performInternal(ANativeWindow* window, int operation, va_list args) { | 
|  | 499 | Surface* c = getSelf(window); | 
|  | 500 | return c->perform(operation, args); | 
|  | 501 | } | 
|  | 502 |  | 
|  | 503 | int Surface::hook_query(const ANativeWindow* window, int what, int* value) { | 
|  | 504 | const Surface* c = getSelf(window); | 
| John Reck | 401cda6 | 2020-05-07 16:04:41 -0700 | [diff] [blame] | 505 | { | 
|  | 506 | std::shared_lock<std::shared_mutex> lock(c->mInterceptorMutex); | 
|  | 507 | if (c->mQueryInterceptor != nullptr) { | 
|  | 508 | auto interceptor = c->mQueryInterceptor; | 
|  | 509 | auto data = c->mQueryInterceptorData; | 
|  | 510 | return interceptor(window, Surface::queryInternal, data, what, value); | 
|  | 511 | } | 
|  | 512 | } | 
|  | 513 | return c->query(what, value); | 
|  | 514 | } | 
|  | 515 |  | 
|  | 516 | int Surface::queryInternal(const ANativeWindow* window, int what, int* value) { | 
|  | 517 | const Surface* c = getSelf(window); | 
| Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 518 | return c->query(what, value); | 
|  | 519 | } | 
|  | 520 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 521 | int Surface::setSwapInterval(int interval) { | 
|  | 522 | ATRACE_CALL(); | 
|  | 523 | // EGL specification states: | 
|  | 524 | //  interval is silently clamped to minimum and maximum implementation | 
|  | 525 | //  dependent values before being stored. | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 526 |  | 
|  | 527 | if (interval < minSwapInterval) | 
|  | 528 | interval = minSwapInterval; | 
|  | 529 |  | 
|  | 530 | if (interval > maxSwapInterval) | 
|  | 531 | interval = maxSwapInterval; | 
|  | 532 |  | 
| Jorim Jaggi | 0a3e784 | 2018-07-17 13:48:33 +0200 | [diff] [blame] | 533 | const bool wasSwapIntervalZero = mSwapIntervalZero; | 
| Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 534 | mSwapIntervalZero = (interval == 0); | 
| Jorim Jaggi | 0a3e784 | 2018-07-17 13:48:33 +0200 | [diff] [blame] | 535 |  | 
|  | 536 | if (mSwapIntervalZero != wasSwapIntervalZero) { | 
|  | 537 | mGraphicBufferProducer->setAsyncMode(mSwapIntervalZero); | 
|  | 538 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 539 |  | 
| Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 540 | return NO_ERROR; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 541 | } | 
|  | 542 |  | 
| Yiwei Zhang | 9e919eb | 2019-03-07 23:21:40 -0800 | [diff] [blame] | 543 | class FenceMonitor { | 
|  | 544 | public: | 
|  | 545 | explicit FenceMonitor(const char* name) : mName(name), mFencesQueued(0), mFencesSignaled(0) { | 
|  | 546 | std::thread thread(&FenceMonitor::loop, this); | 
|  | 547 | pthread_setname_np(thread.native_handle(), mName); | 
|  | 548 | thread.detach(); | 
|  | 549 | } | 
|  | 550 |  | 
|  | 551 | void queueFence(const sp<Fence>& fence) { | 
|  | 552 | char message[64]; | 
|  | 553 |  | 
|  | 554 | std::lock_guard<std::mutex> lock(mMutex); | 
| Yiwei Zhang | 2817813 | 2019-03-08 17:14:53 -0800 | [diff] [blame] | 555 | if (fence->getSignalTime() != Fence::SIGNAL_TIME_PENDING) { | 
|  | 556 | snprintf(message, sizeof(message), "%s fence %u has signaled", mName, mFencesQueued); | 
|  | 557 | ATRACE_NAME(message); | 
|  | 558 | // Need an increment on both to make the trace number correct. | 
|  | 559 | mFencesQueued++; | 
|  | 560 | mFencesSignaled++; | 
|  | 561 | return; | 
|  | 562 | } | 
|  | 563 | snprintf(message, sizeof(message), "Trace %s fence %u", mName, mFencesQueued); | 
| Yiwei Zhang | 9e919eb | 2019-03-07 23:21:40 -0800 | [diff] [blame] | 564 | ATRACE_NAME(message); | 
|  | 565 |  | 
|  | 566 | mQueue.push_back(fence); | 
|  | 567 | mCondition.notify_one(); | 
|  | 568 | mFencesQueued++; | 
|  | 569 | ATRACE_INT(mName, int32_t(mQueue.size())); | 
|  | 570 | } | 
|  | 571 |  | 
|  | 572 | private: | 
|  | 573 | #pragma clang diagnostic push | 
|  | 574 | #pragma clang diagnostic ignored "-Wmissing-noreturn" | 
|  | 575 | void loop() { | 
|  | 576 | while (true) { | 
|  | 577 | threadLoop(); | 
|  | 578 | } | 
|  | 579 | } | 
|  | 580 | #pragma clang diagnostic pop | 
|  | 581 |  | 
|  | 582 | void threadLoop() { | 
|  | 583 | sp<Fence> fence; | 
|  | 584 | uint32_t fenceNum; | 
|  | 585 | { | 
|  | 586 | std::unique_lock<std::mutex> lock(mMutex); | 
|  | 587 | while (mQueue.empty()) { | 
|  | 588 | mCondition.wait(lock); | 
|  | 589 | } | 
|  | 590 | fence = mQueue[0]; | 
|  | 591 | fenceNum = mFencesSignaled; | 
|  | 592 | } | 
|  | 593 | { | 
|  | 594 | char message[64]; | 
|  | 595 | snprintf(message, sizeof(message), "waiting for %s %u", mName, fenceNum); | 
|  | 596 | ATRACE_NAME(message); | 
|  | 597 |  | 
|  | 598 | status_t result = fence->waitForever(message); | 
|  | 599 | if (result != OK) { | 
|  | 600 | ALOGE("Error waiting for fence: %d", result); | 
|  | 601 | } | 
|  | 602 | } | 
|  | 603 | { | 
|  | 604 | std::lock_guard<std::mutex> lock(mMutex); | 
|  | 605 | mQueue.pop_front(); | 
|  | 606 | mFencesSignaled++; | 
|  | 607 | ATRACE_INT(mName, int32_t(mQueue.size())); | 
|  | 608 | } | 
|  | 609 | } | 
|  | 610 |  | 
|  | 611 | const char* mName; | 
|  | 612 | uint32_t mFencesQueued; | 
|  | 613 | uint32_t mFencesSignaled; | 
|  | 614 | std::deque<sp<Fence>> mQueue; | 
|  | 615 | std::condition_variable mCondition; | 
|  | 616 | std::mutex mMutex; | 
|  | 617 | }; | 
|  | 618 |  | 
| Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 619 | int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 620 | ATRACE_CALL(); | 
|  | 621 | ALOGV("Surface::dequeueBuffer"); | 
| Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 622 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 623 | uint32_t reqWidth; | 
|  | 624 | uint32_t reqHeight; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 625 | PixelFormat reqFormat; | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 626 | uint64_t reqUsage; | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 627 | bool enableFrameTimestamps; | 
| Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 628 |  | 
|  | 629 | { | 
|  | 630 | Mutex::Autolock lock(mMutex); | 
| Yin-Chia Yeh | 1f2af5c | 2017-05-11 16:54:04 -0700 | [diff] [blame] | 631 | if (mReportRemovedBuffers) { | 
|  | 632 | mRemovedBuffers.clear(); | 
|  | 633 | } | 
| Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 634 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 635 | reqWidth = mReqWidth ? mReqWidth : mUserWidth; | 
|  | 636 | reqHeight = mReqHeight ? mReqHeight : mUserHeight; | 
| Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 637 |  | 
| Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 638 | reqFormat = mReqFormat; | 
|  | 639 | reqUsage = mReqUsage; | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 640 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 641 | enableFrameTimestamps = mEnableFrameTimestamps; | 
|  | 642 |  | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 643 | if (mSharedBufferMode && mAutoRefresh && mSharedBufferSlot != | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 644 | BufferItem::INVALID_BUFFER_SLOT) { | 
|  | 645 | sp<GraphicBuffer>& gbuf(mSlots[mSharedBufferSlot].buffer); | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 646 | if (gbuf != nullptr) { | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 647 | *buffer = gbuf.get(); | 
|  | 648 | *fenceFd = -1; | 
|  | 649 | return OK; | 
|  | 650 | } | 
|  | 651 | } | 
| Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 652 | } // Drop the lock so that we can still touch the Surface while blocking in IGBP::dequeueBuffer | 
|  | 653 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 654 | int buf = -1; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 655 | sp<Fence> fence; | 
| Dan Stoza | 932f008 | 2017-05-31 13:50:16 -0700 | [diff] [blame] | 656 | nsecs_t startTime = systemTime(); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 657 |  | 
|  | 658 | FrameEventHistoryDelta frameTimestamps; | 
| Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 659 | status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence, reqWidth, reqHeight, | 
|  | 660 | reqFormat, reqUsage, &mBufferAge, | 
|  | 661 | enableFrameTimestamps ? &frameTimestamps | 
|  | 662 | : nullptr); | 
| Dan Stoza | 932f008 | 2017-05-31 13:50:16 -0700 | [diff] [blame] | 663 | mLastDequeueDuration = systemTime() - startTime; | 
| Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 664 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 665 | if (result < 0) { | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 666 | ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer" | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 667 | "(%d, %d, %d, %#" PRIx64 ") failed: %d", | 
|  | 668 | reqWidth, reqHeight, reqFormat, reqUsage, result); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 669 | return result; | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 670 | } | 
| Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 671 |  | 
| Dan Stoza | 90ce2a9 | 2017-05-01 16:31:53 -0700 | [diff] [blame] | 672 | if (buf < 0 || buf >= NUM_BUFFER_SLOTS) { | 
|  | 673 | ALOGE("dequeueBuffer: IGraphicBufferProducer returned invalid slot number %d", buf); | 
|  | 674 | android_errorWriteLog(0x534e4554, "36991414"); // SafetyNet logging | 
|  | 675 | return FAILED_TRANSACTION; | 
|  | 676 | } | 
|  | 677 |  | 
| Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 678 | Mutex::Autolock lock(mMutex); | 
|  | 679 |  | 
| Dan Stoza | 932f008 | 2017-05-31 13:50:16 -0700 | [diff] [blame] | 680 | // Write this while holding the mutex | 
|  | 681 | mLastDequeueStartTime = startTime; | 
|  | 682 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 683 | sp<GraphicBuffer>& gbuf(mSlots[buf].buffer); | 
| Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 684 |  | 
|  | 685 | // this should never happen | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 686 | ALOGE_IF(fence == nullptr, "Surface::dequeueBuffer: received null Fence! buf=%d", buf); | 
| Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 687 |  | 
| Yiwei Zhang | 9e919eb | 2019-03-07 23:21:40 -0800 | [diff] [blame] | 688 | if (CC_UNLIKELY(atrace_is_tag_enabled(ATRACE_TAG_GRAPHICS))) { | 
|  | 689 | static FenceMonitor hwcReleaseThread("HWC release"); | 
|  | 690 | hwcReleaseThread.queueFence(fence); | 
|  | 691 | } | 
|  | 692 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 693 | if (result & IGraphicBufferProducer::RELEASE_ALL_BUFFERS) { | 
|  | 694 | freeAllBuffers(); | 
| Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 695 | } | 
| Ted Bonkenburg | bd050ab | 2011-07-15 15:10:10 -0700 | [diff] [blame] | 696 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 697 | if (enableFrameTimestamps) { | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 698 | mFrameEventHistory->applyDelta(frameTimestamps); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 699 | } | 
|  | 700 |  | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 701 | if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == nullptr) { | 
|  | 702 | if (mReportRemovedBuffers && (gbuf != nullptr)) { | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 703 | mRemovedBuffers.push_back(gbuf); | 
|  | 704 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 705 | result = mGraphicBufferProducer->requestBuffer(buf, &gbuf); | 
|  | 706 | if (result != NO_ERROR) { | 
| Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 707 | ALOGE("dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: %d", result); | 
| Jesse Hall | 9f5a1b6 | 2014-10-02 11:09:03 -0700 | [diff] [blame] | 708 | mGraphicBufferProducer->cancelBuffer(buf, fence); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 709 | return result; | 
|  | 710 | } | 
|  | 711 | } | 
| Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 712 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 713 | if (fence->isValid()) { | 
|  | 714 | *fenceFd = fence->dup(); | 
|  | 715 | if (*fenceFd == -1) { | 
|  | 716 | ALOGE("dequeueBuffer: error duping fence: %d", errno); | 
|  | 717 | // dup() should never fail; something is badly wrong. Soldier on | 
|  | 718 | // and hope for the best; the worst that should happen is some | 
|  | 719 | // visible corruption that lasts until the next frame. | 
|  | 720 | } | 
| Ted Bonkenburg | e5d6eb8 | 2011-08-09 22:38:41 -0700 | [diff] [blame] | 721 | } else { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 722 | *fenceFd = -1; | 
| Mathias Agopian | a0c30e9 | 2010-06-04 18:26:32 -0700 | [diff] [blame] | 723 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 724 |  | 
|  | 725 | *buffer = gbuf.get(); | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 726 |  | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 727 | if (mSharedBufferMode && mAutoRefresh) { | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 728 | mSharedBufferSlot = buf; | 
|  | 729 | mSharedBufferHasBeenQueued = false; | 
|  | 730 | } else if (mSharedBufferSlot == buf) { | 
|  | 731 | mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT; | 
|  | 732 | mSharedBufferHasBeenQueued = false; | 
|  | 733 | } | 
|  | 734 |  | 
| Yin-Chia Yeh | da2e609 | 2020-07-29 15:00:07 -0700 | [diff] [blame] | 735 | mDequeuedSlots.insert(buf); | 
|  | 736 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 737 | return OK; | 
| Jamie Gennis | aca4e22 | 2010-07-15 17:29:15 -0700 | [diff] [blame] | 738 | } | 
|  | 739 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 740 | int Surface::cancelBuffer(android_native_buffer_t* buffer, | 
|  | 741 | int fenceFd) { | 
|  | 742 | ATRACE_CALL(); | 
|  | 743 | ALOGV("Surface::cancelBuffer"); | 
|  | 744 | Mutex::Autolock lock(mMutex); | 
|  | 745 | int i = getSlotFromBufferLocked(buffer); | 
|  | 746 | if (i < 0) { | 
| Taiju Tsuiki | 4d0cd3f | 2015-04-30 22:15:33 +0900 | [diff] [blame] | 747 | if (fenceFd >= 0) { | 
|  | 748 | close(fenceFd); | 
|  | 749 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 750 | return i; | 
|  | 751 | } | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 752 | if (mSharedBufferSlot == i && mSharedBufferHasBeenQueued) { | 
|  | 753 | if (fenceFd >= 0) { | 
|  | 754 | close(fenceFd); | 
|  | 755 | } | 
|  | 756 | return OK; | 
|  | 757 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 758 | sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); | 
|  | 759 | mGraphicBufferProducer->cancelBuffer(i, fence); | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 760 |  | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 761 | if (mSharedBufferMode && mAutoRefresh && mSharedBufferSlot == i) { | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 762 | mSharedBufferHasBeenQueued = true; | 
|  | 763 | } | 
|  | 764 |  | 
| Yin-Chia Yeh | da2e609 | 2020-07-29 15:00:07 -0700 | [diff] [blame] | 765 | mDequeuedSlots.erase(i); | 
|  | 766 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 767 | return OK; | 
|  | 768 | } | 
|  | 769 |  | 
|  | 770 | int Surface::getSlotFromBufferLocked( | 
|  | 771 | android_native_buffer_t* buffer) const { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 772 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 773 | if (mSlots[i].buffer != nullptr && | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 774 | mSlots[i].buffer->handle == buffer->handle) { | 
|  | 775 | return i; | 
| Jamie Gennis | aca4e22 | 2010-07-15 17:29:15 -0700 | [diff] [blame] | 776 | } | 
|  | 777 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 778 | ALOGE("getSlotFromBufferLocked: unknown buffer: %p", buffer->handle); | 
|  | 779 | return BAD_VALUE; | 
| Mathias Agopian | a0c30e9 | 2010-06-04 18:26:32 -0700 | [diff] [blame] | 780 | } | 
|  | 781 |  | 
| Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 782 | int Surface::lockBuffer_DEPRECATED(android_native_buffer_t* buffer __attribute__((unused))) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 783 | ALOGV("Surface::lockBuffer"); | 
|  | 784 | Mutex::Autolock lock(mMutex); | 
|  | 785 | return OK; | 
|  | 786 | } | 
| Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 787 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 788 | int Surface::queueBuffer(android_native_buffer_t* buffer, int fenceFd) { | 
|  | 789 | ATRACE_CALL(); | 
|  | 790 | ALOGV("Surface::queueBuffer"); | 
|  | 791 | Mutex::Autolock lock(mMutex); | 
|  | 792 | int64_t timestamp; | 
| Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 793 | bool isAutoTimestamp = false; | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 794 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 795 | if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) { | 
| Andy McFadden | 4b49e08 | 2013-08-02 15:31:45 -0700 | [diff] [blame] | 796 | timestamp = systemTime(SYSTEM_TIME_MONOTONIC); | 
| Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 797 | isAutoTimestamp = true; | 
| Andy McFadden | 4b49e08 | 2013-08-02 15:31:45 -0700 | [diff] [blame] | 798 | ALOGV("Surface::queueBuffer making up timestamp: %.2f ms", | 
| Colin Cross | 9a80d50 | 2016-09-27 14:12:48 -0700 | [diff] [blame] | 799 | timestamp / 1000000.0); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 800 | } else { | 
|  | 801 | timestamp = mTimestamp; | 
| Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 802 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 803 | int i = getSlotFromBufferLocked(buffer); | 
|  | 804 | if (i < 0) { | 
| Taiju Tsuiki | 4d0cd3f | 2015-04-30 22:15:33 +0900 | [diff] [blame] | 805 | if (fenceFd >= 0) { | 
|  | 806 | close(fenceFd); | 
|  | 807 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 808 | return i; | 
|  | 809 | } | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 810 | if (mSharedBufferSlot == i && mSharedBufferHasBeenQueued) { | 
|  | 811 | if (fenceFd >= 0) { | 
|  | 812 | close(fenceFd); | 
|  | 813 | } | 
|  | 814 | return OK; | 
|  | 815 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 816 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 818 | // Make sure the crop rectangle is entirely inside the buffer. | 
| Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 819 | Rect crop(Rect::EMPTY_RECT); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 820 | mCrop.intersect(Rect(buffer->width, buffer->height), &crop); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 822 | sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); | 
|  | 823 | IGraphicBufferProducer::QueueBufferOutput output; | 
| Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 824 | IGraphicBufferProducer::QueueBufferInput input(timestamp, isAutoTimestamp, | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 825 | static_cast<android_dataspace>(mDataSpace), crop, mScalingMode, | 
|  | 826 | mTransform ^ mStickyTransform, fence, mStickyTransform, | 
|  | 827 | mEnableFrameTimestamps); | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 828 |  | 
| Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 829 | // we should send HDR metadata as needed if this becomes a bottleneck | 
|  | 830 | input.setHdrMetadata(mHdrMetadata); | 
|  | 831 |  | 
| Dan Stoza | c62acbd | 2015-04-21 16:42:49 -0700 | [diff] [blame] | 832 | if (mConnectedToCpu || mDirtyRegion.bounds() == Rect::INVALID_RECT) { | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 833 | input.setSurfaceDamage(Region::INVALID_REGION); | 
|  | 834 | } else { | 
| Dan Stoza | db4850c | 2015-06-25 16:10:18 -0700 | [diff] [blame] | 835 | // Here we do two things: | 
|  | 836 | // 1) The surface damage was specified using the OpenGL ES convention of | 
|  | 837 | //    the origin being in the bottom-left corner. Here we flip to the | 
|  | 838 | //    convention that the rest of the system uses (top-left corner) by | 
|  | 839 | //    subtracting all top/bottom coordinates from the buffer height. | 
|  | 840 | // 2) If the buffer is coming in rotated (for example, because the EGL | 
|  | 841 | //    implementation is reacting to the transform hint coming back from | 
|  | 842 | //    SurfaceFlinger), the surface damage needs to be rotated the | 
|  | 843 | //    opposite direction, since it was generated assuming an unrotated | 
|  | 844 | //    buffer (the app doesn't know that the EGL implementation is | 
|  | 845 | //    reacting to the transform hint behind its back). The | 
|  | 846 | //    transformations in the switch statement below apply those | 
|  | 847 | //    complementary rotations (e.g., if 90 degrees, rotate 270 degrees). | 
|  | 848 |  | 
|  | 849 | int width = buffer->width; | 
| Dan Stoza | 0e65e6c | 2015-05-26 13:22:27 -0700 | [diff] [blame] | 850 | int height = buffer->height; | 
| Dan Stoza | db4850c | 2015-06-25 16:10:18 -0700 | [diff] [blame] | 851 | bool rotated90 = (mTransform ^ mStickyTransform) & | 
|  | 852 | NATIVE_WINDOW_TRANSFORM_ROT_90; | 
|  | 853 | if (rotated90) { | 
|  | 854 | std::swap(width, height); | 
| Dan Stoza | 0e65e6c | 2015-05-26 13:22:27 -0700 | [diff] [blame] | 855 | } | 
| Dan Stoza | db4850c | 2015-06-25 16:10:18 -0700 | [diff] [blame] | 856 |  | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 857 | Region flippedRegion; | 
|  | 858 | for (auto rect : mDirtyRegion) { | 
| Dan Stoza | db4850c | 2015-06-25 16:10:18 -0700 | [diff] [blame] | 859 | int left = rect.left; | 
|  | 860 | int right = rect.right; | 
|  | 861 | int top = height - rect.bottom; // Flip from OpenGL convention | 
|  | 862 | int bottom = height - rect.top; // Flip from OpenGL convention | 
|  | 863 | switch (mTransform ^ mStickyTransform) { | 
|  | 864 | case NATIVE_WINDOW_TRANSFORM_ROT_90: { | 
|  | 865 | // Rotate 270 degrees | 
|  | 866 | Rect flippedRect{top, width - right, bottom, width - left}; | 
|  | 867 | flippedRegion.orSelf(flippedRect); | 
|  | 868 | break; | 
|  | 869 | } | 
|  | 870 | case NATIVE_WINDOW_TRANSFORM_ROT_180: { | 
|  | 871 | // Rotate 180 degrees | 
|  | 872 | Rect flippedRect{width - right, height - bottom, | 
|  | 873 | width - left, height - top}; | 
|  | 874 | flippedRegion.orSelf(flippedRect); | 
|  | 875 | break; | 
|  | 876 | } | 
|  | 877 | case NATIVE_WINDOW_TRANSFORM_ROT_270: { | 
|  | 878 | // Rotate 90 degrees | 
|  | 879 | Rect flippedRect{height - bottom, left, | 
|  | 880 | height - top, right}; | 
|  | 881 | flippedRegion.orSelf(flippedRect); | 
|  | 882 | break; | 
|  | 883 | } | 
|  | 884 | default: { | 
|  | 885 | Rect flippedRect{left, top, right, bottom}; | 
|  | 886 | flippedRegion.orSelf(flippedRect); | 
|  | 887 | break; | 
|  | 888 | } | 
|  | 889 | } | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 890 | } | 
|  | 891 |  | 
|  | 892 | input.setSurfaceDamage(flippedRegion); | 
|  | 893 | } | 
|  | 894 |  | 
| Dan Stoza | 70ccba5 | 2016-07-01 14:00:40 -0700 | [diff] [blame] | 895 | nsecs_t now = systemTime(); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 896 | status_t err = mGraphicBufferProducer->queueBuffer(i, input, &output); | 
| Dan Stoza | 70ccba5 | 2016-07-01 14:00:40 -0700 | [diff] [blame] | 897 | mLastQueueDuration = systemTime() - now; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 898 | if (err != OK)  { | 
|  | 899 | ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err); | 
|  | 900 | } | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 901 |  | 
| Yin-Chia Yeh | da2e609 | 2020-07-29 15:00:07 -0700 | [diff] [blame] | 902 | mDequeuedSlots.erase(i); | 
|  | 903 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 904 | if (mEnableFrameTimestamps) { | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 905 | mFrameEventHistory->applyDelta(output.frameTimestamps); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 906 | // Update timestamps with the local acquire fence. | 
|  | 907 | // The consumer doesn't send it back to prevent us from having two | 
|  | 908 | // file descriptors of the same fence. | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 909 | mFrameEventHistory->updateAcquireFence(mNextFrameNumber, | 
| Yiwei Zhang | f0c1250 | 2019-03-13 16:09:05 -0700 | [diff] [blame] | 910 | std::make_shared<FenceTime>(fence)); | 
| Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 911 |  | 
|  | 912 | // Cache timestamps of signaled fences so we can close their file | 
|  | 913 | // descriptors. | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 914 | mFrameEventHistory->updateSignalTimes(); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 915 | } | 
|  | 916 |  | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 917 | mLastFrameNumber = mNextFrameNumber; | 
|  | 918 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 919 | mDefaultWidth = output.width; | 
|  | 920 | mDefaultHeight = output.height; | 
|  | 921 | mNextFrameNumber = output.nextFrameNumber; | 
| tedbo | 1e7fa9e | 2011-06-22 15:52:53 -0700 | [diff] [blame] | 922 |  | 
| Vishnu Nair | 5eb3f06 | 2019-04-08 08:21:03 -0700 | [diff] [blame] | 923 | // Ignore transform hint if sticky transform is set or transform to display inverse flag is | 
|  | 924 | // set. | 
|  | 925 | if (mStickyTransform == 0 && !transformToDisplayInverse()) { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 926 | mTransformHint = output.transformHint; | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 927 | } | 
|  | 928 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 929 | mConsumerRunningBehind = (output.numPendingBuffers >= 2); | 
| Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 930 |  | 
| Dan Stoza | c62acbd | 2015-04-21 16:42:49 -0700 | [diff] [blame] | 931 | if (!mConnectedToCpu) { | 
|  | 932 | // Clear surface damage back to full-buffer | 
|  | 933 | mDirtyRegion = Region::INVALID_REGION; | 
|  | 934 | } | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 935 |  | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 936 | if (mSharedBufferMode && mAutoRefresh && mSharedBufferSlot == i) { | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 937 | mSharedBufferHasBeenQueued = true; | 
|  | 938 | } | 
|  | 939 |  | 
| Robert Carr | 9f31e29 | 2016-04-11 11:15:32 -0700 | [diff] [blame] | 940 | mQueueBufferCondition.broadcast(); | 
|  | 941 |  | 
| Yiwei Zhang | 9e919eb | 2019-03-07 23:21:40 -0800 | [diff] [blame] | 942 | if (CC_UNLIKELY(atrace_is_tag_enabled(ATRACE_TAG_GRAPHICS))) { | 
|  | 943 | static FenceMonitor gpuCompletionThread("GPU completion"); | 
|  | 944 | gpuCompletionThread.queueFence(fence); | 
|  | 945 | } | 
|  | 946 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 947 | return err; | 
|  | 948 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 949 |  | 
| Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 950 | void Surface::querySupportedTimestampsLocked() const { | 
|  | 951 | // mMutex must be locked when calling this method. | 
|  | 952 |  | 
|  | 953 | if (mQueriedSupportedTimestamps) { | 
|  | 954 | return; | 
|  | 955 | } | 
|  | 956 | mQueriedSupportedTimestamps = true; | 
|  | 957 |  | 
|  | 958 | std::vector<FrameEvent> supportedFrameTimestamps; | 
|  | 959 | status_t err = composerService()->getSupportedFrameTimestamps( | 
|  | 960 | &supportedFrameTimestamps); | 
|  | 961 |  | 
|  | 962 | if (err != NO_ERROR) { | 
|  | 963 | return; | 
|  | 964 | } | 
|  | 965 |  | 
|  | 966 | for (auto sft : supportedFrameTimestamps) { | 
|  | 967 | if (sft == FrameEvent::DISPLAY_PRESENT) { | 
|  | 968 | mFrameTimestampsSupportsPresent = true; | 
|  | 969 | } | 
|  | 970 | } | 
|  | 971 | } | 
|  | 972 |  | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 973 | int Surface::query(int what, int* value) const { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 974 | ATRACE_CALL(); | 
|  | 975 | ALOGV("Surface::query"); | 
|  | 976 | { // scope for the lock | 
|  | 977 | Mutex::Autolock lock(mMutex); | 
|  | 978 | switch (what) { | 
|  | 979 | case NATIVE_WINDOW_FORMAT: | 
|  | 980 | if (mReqFormat) { | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 981 | *value = static_cast<int>(mReqFormat); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 982 | return NO_ERROR; | 
|  | 983 | } | 
|  | 984 | break; | 
|  | 985 | case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: { | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 986 | if (composerService()->authenticateSurfaceTexture( | 
|  | 987 | mGraphicBufferProducer)) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 988 | *value = 1; | 
|  | 989 | } else { | 
|  | 990 | *value = 0; | 
|  | 991 | } | 
|  | 992 | return NO_ERROR; | 
|  | 993 | } | 
|  | 994 | case NATIVE_WINDOW_CONCRETE_TYPE: | 
|  | 995 | *value = NATIVE_WINDOW_SURFACE; | 
|  | 996 | return NO_ERROR; | 
|  | 997 | case NATIVE_WINDOW_DEFAULT_WIDTH: | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 998 | *value = static_cast<int>( | 
|  | 999 | mUserWidth ? mUserWidth : mDefaultWidth); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1000 | return NO_ERROR; | 
|  | 1001 | case NATIVE_WINDOW_DEFAULT_HEIGHT: | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1002 | *value = static_cast<int>( | 
|  | 1003 | mUserHeight ? mUserHeight : mDefaultHeight); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1004 | return NO_ERROR; | 
|  | 1005 | case NATIVE_WINDOW_TRANSFORM_HINT: | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1006 | *value = static_cast<int>(mTransformHint); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1007 | return NO_ERROR; | 
|  | 1008 | case NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND: { | 
|  | 1009 | status_t err = NO_ERROR; | 
|  | 1010 | if (!mConsumerRunningBehind) { | 
|  | 1011 | *value = 0; | 
|  | 1012 | } else { | 
|  | 1013 | err = mGraphicBufferProducer->query(what, value); | 
|  | 1014 | if (err == NO_ERROR) { | 
|  | 1015 | mConsumerRunningBehind = *value; | 
|  | 1016 | } | 
|  | 1017 | } | 
|  | 1018 | return err; | 
|  | 1019 | } | 
| Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 1020 | case NATIVE_WINDOW_BUFFER_AGE: { | 
|  | 1021 | if (mBufferAge > INT32_MAX) { | 
|  | 1022 | *value = 0; | 
|  | 1023 | } else { | 
|  | 1024 | *value = static_cast<int32_t>(mBufferAge); | 
|  | 1025 | } | 
|  | 1026 | return NO_ERROR; | 
|  | 1027 | } | 
| Dan Stoza | 70ccba5 | 2016-07-01 14:00:40 -0700 | [diff] [blame] | 1028 | case NATIVE_WINDOW_LAST_DEQUEUE_DURATION: { | 
|  | 1029 | int64_t durationUs = mLastDequeueDuration / 1000; | 
|  | 1030 | *value = durationUs > std::numeric_limits<int>::max() ? | 
|  | 1031 | std::numeric_limits<int>::max() : | 
|  | 1032 | static_cast<int>(durationUs); | 
|  | 1033 | return NO_ERROR; | 
|  | 1034 | } | 
|  | 1035 | case NATIVE_WINDOW_LAST_QUEUE_DURATION: { | 
|  | 1036 | int64_t durationUs = mLastQueueDuration / 1000; | 
|  | 1037 | *value = durationUs > std::numeric_limits<int>::max() ? | 
|  | 1038 | std::numeric_limits<int>::max() : | 
|  | 1039 | static_cast<int>(durationUs); | 
|  | 1040 | return NO_ERROR; | 
|  | 1041 | } | 
| Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 1042 | case NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT: { | 
|  | 1043 | querySupportedTimestampsLocked(); | 
|  | 1044 | *value = mFrameTimestampsSupportsPresent ? 1 : 0; | 
|  | 1045 | return NO_ERROR; | 
|  | 1046 | } | 
| Mathias Agopian | 10e9ab5 | 2017-03-08 15:02:55 -0800 | [diff] [blame] | 1047 | case NATIVE_WINDOW_IS_VALID: { | 
|  | 1048 | *value = mGraphicBufferProducer != nullptr ? 1 : 0; | 
|  | 1049 | return NO_ERROR; | 
|  | 1050 | } | 
| Peiyong Lin | 654f87b | 2018-01-30 14:21:33 -0800 | [diff] [blame] | 1051 | case NATIVE_WINDOW_DATASPACE: { | 
|  | 1052 | *value = static_cast<int>(mDataSpace); | 
|  | 1053 | return NO_ERROR; | 
|  | 1054 | } | 
| silence_dogood | e9d092a | 2019-06-19 16:14:53 -0700 | [diff] [blame] | 1055 | case NATIVE_WINDOW_MAX_BUFFER_COUNT: { | 
|  | 1056 | *value = mMaxBufferCount; | 
|  | 1057 | return NO_ERROR; | 
|  | 1058 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1059 | } | 
| Jamie Gennis | 391bbe2 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 1060 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1061 | return mGraphicBufferProducer->query(what, value); | 
| Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 1062 | } | 
|  | 1063 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1064 | int Surface::perform(int operation, va_list args) | 
|  | 1065 | { | 
|  | 1066 | int res = NO_ERROR; | 
|  | 1067 | switch (operation) { | 
|  | 1068 | case NATIVE_WINDOW_CONNECT: | 
|  | 1069 | // deprecated. must return NO_ERROR. | 
|  | 1070 | break; | 
|  | 1071 | case NATIVE_WINDOW_DISCONNECT: | 
|  | 1072 | // deprecated. must return NO_ERROR. | 
|  | 1073 | break; | 
|  | 1074 | case NATIVE_WINDOW_SET_USAGE: | 
|  | 1075 | res = dispatchSetUsage(args); | 
|  | 1076 | break; | 
|  | 1077 | case NATIVE_WINDOW_SET_CROP: | 
|  | 1078 | res = dispatchSetCrop(args); | 
|  | 1079 | break; | 
|  | 1080 | case NATIVE_WINDOW_SET_BUFFER_COUNT: | 
|  | 1081 | res = dispatchSetBufferCount(args); | 
|  | 1082 | break; | 
|  | 1083 | case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY: | 
|  | 1084 | res = dispatchSetBuffersGeometry(args); | 
|  | 1085 | break; | 
|  | 1086 | case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM: | 
|  | 1087 | res = dispatchSetBuffersTransform(args); | 
|  | 1088 | break; | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1089 | case NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM: | 
|  | 1090 | res = dispatchSetBuffersStickyTransform(args); | 
|  | 1091 | break; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1092 | case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP: | 
|  | 1093 | res = dispatchSetBuffersTimestamp(args); | 
|  | 1094 | break; | 
|  | 1095 | case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS: | 
|  | 1096 | res = dispatchSetBuffersDimensions(args); | 
|  | 1097 | break; | 
|  | 1098 | case NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS: | 
|  | 1099 | res = dispatchSetBuffersUserDimensions(args); | 
|  | 1100 | break; | 
|  | 1101 | case NATIVE_WINDOW_SET_BUFFERS_FORMAT: | 
|  | 1102 | res = dispatchSetBuffersFormat(args); | 
|  | 1103 | break; | 
|  | 1104 | case NATIVE_WINDOW_LOCK: | 
|  | 1105 | res = dispatchLock(args); | 
|  | 1106 | break; | 
|  | 1107 | case NATIVE_WINDOW_UNLOCK_AND_POST: | 
|  | 1108 | res = dispatchUnlockAndPost(args); | 
|  | 1109 | break; | 
|  | 1110 | case NATIVE_WINDOW_SET_SCALING_MODE: | 
|  | 1111 | res = dispatchSetScalingMode(args); | 
|  | 1112 | break; | 
|  | 1113 | case NATIVE_WINDOW_API_CONNECT: | 
|  | 1114 | res = dispatchConnect(args); | 
|  | 1115 | break; | 
|  | 1116 | case NATIVE_WINDOW_API_DISCONNECT: | 
|  | 1117 | res = dispatchDisconnect(args); | 
|  | 1118 | break; | 
| Rachad | 7cb0d39 | 2014-07-29 17:53:53 -0700 | [diff] [blame] | 1119 | case NATIVE_WINDOW_SET_SIDEBAND_STREAM: | 
|  | 1120 | res = dispatchSetSidebandStream(args); | 
|  | 1121 | break; | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 1122 | case NATIVE_WINDOW_SET_BUFFERS_DATASPACE: | 
|  | 1123 | res = dispatchSetBuffersDataSpace(args); | 
|  | 1124 | break; | 
| Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 1125 | case NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA: | 
|  | 1126 | res = dispatchSetBuffersSmpte2086Metadata(args); | 
|  | 1127 | break; | 
|  | 1128 | case NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA: | 
|  | 1129 | res = dispatchSetBuffersCta8613Metadata(args); | 
|  | 1130 | break; | 
| Valerie Hau | a82679d | 2018-11-21 09:31:43 -0800 | [diff] [blame] | 1131 | case NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA: | 
|  | 1132 | res = dispatchSetBuffersHdr10PlusMetadata(args); | 
|  | 1133 | break; | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 1134 | case NATIVE_WINDOW_SET_SURFACE_DAMAGE: | 
|  | 1135 | res = dispatchSetSurfaceDamage(args); | 
|  | 1136 | break; | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 1137 | case NATIVE_WINDOW_SET_SHARED_BUFFER_MODE: | 
|  | 1138 | res = dispatchSetSharedBufferMode(args); | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 1139 | break; | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1140 | case NATIVE_WINDOW_SET_AUTO_REFRESH: | 
|  | 1141 | res = dispatchSetAutoRefresh(args); | 
|  | 1142 | break; | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1143 | case NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION: | 
|  | 1144 | res = dispatchGetDisplayRefreshCycleDuration(args); | 
|  | 1145 | break; | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 1146 | case NATIVE_WINDOW_GET_NEXT_FRAME_ID: | 
|  | 1147 | res = dispatchGetNextFrameId(args); | 
|  | 1148 | break; | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1149 | case NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS: | 
|  | 1150 | res = dispatchEnableFrameTimestamps(args); | 
|  | 1151 | break; | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1152 | case NATIVE_WINDOW_GET_COMPOSITOR_TIMING: | 
|  | 1153 | res = dispatchGetCompositorTiming(args); | 
|  | 1154 | break; | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 1155 | case NATIVE_WINDOW_GET_FRAME_TIMESTAMPS: | 
|  | 1156 | res = dispatchGetFrameTimestamps(args); | 
|  | 1157 | break; | 
| Courtney Goeltzenleuchter | 1eb1b27 | 2017-02-02 16:51:06 -0700 | [diff] [blame] | 1158 | case NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT: | 
|  | 1159 | res = dispatchGetWideColorSupport(args); | 
|  | 1160 | break; | 
| Courtney Goeltzenleuchter | c5b97c5 | 2017-02-26 14:47:13 -0700 | [diff] [blame] | 1161 | case NATIVE_WINDOW_GET_HDR_SUPPORT: | 
|  | 1162 | res = dispatchGetHdrSupport(args); | 
|  | 1163 | break; | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 1164 | case NATIVE_WINDOW_SET_USAGE64: | 
|  | 1165 | res = dispatchSetUsage64(args); | 
|  | 1166 | break; | 
| Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 1167 | case NATIVE_WINDOW_GET_CONSUMER_USAGE64: | 
|  | 1168 | res = dispatchGetConsumerUsage64(args); | 
|  | 1169 | break; | 
| Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 1170 | case NATIVE_WINDOW_SET_AUTO_PREROTATION: | 
|  | 1171 | res = dispatchSetAutoPrerotation(args); | 
|  | 1172 | break; | 
| Alec Mouri | a161966 | 2019-08-21 19:30:48 -0700 | [diff] [blame] | 1173 | case NATIVE_WINDOW_GET_LAST_DEQUEUE_START: | 
|  | 1174 | res = dispatchGetLastDequeueStartTime(args); | 
|  | 1175 | break; | 
| Alec Mouri | 04fdb60 | 2019-08-23 19:41:43 -0700 | [diff] [blame] | 1176 | case NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT: | 
|  | 1177 | res = dispatchSetDequeueTimeout(args); | 
|  | 1178 | break; | 
| Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 1179 | case NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION: | 
|  | 1180 | res = dispatchGetLastDequeueDuration(args); | 
|  | 1181 | break; | 
|  | 1182 | case NATIVE_WINDOW_GET_LAST_QUEUE_DURATION: | 
|  | 1183 | res = dispatchGetLastQueueDuration(args); | 
|  | 1184 | break; | 
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1185 | case NATIVE_WINDOW_SET_FRAME_RATE: | 
|  | 1186 | res = dispatchSetFrameRate(args); | 
|  | 1187 | break; | 
| Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 1188 | case NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR: | 
|  | 1189 | res = dispatchAddCancelInterceptor(args); | 
|  | 1190 | break; | 
|  | 1191 | case NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR: | 
|  | 1192 | res = dispatchAddDequeueInterceptor(args); | 
|  | 1193 | break; | 
|  | 1194 | case NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR: | 
|  | 1195 | res = dispatchAddPerformInterceptor(args); | 
|  | 1196 | break; | 
|  | 1197 | case NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR: | 
|  | 1198 | res = dispatchAddQueueInterceptor(args); | 
|  | 1199 | break; | 
| John Reck | 401cda6 | 2020-05-07 16:04:41 -0700 | [diff] [blame] | 1200 | case NATIVE_WINDOW_SET_QUERY_INTERCEPTOR: | 
|  | 1201 | res = dispatchAddQueryInterceptor(args); | 
|  | 1202 | break; | 
| Alec Mouri | 74aef6d | 2019-12-09 17:10:24 -0800 | [diff] [blame] | 1203 | case NATIVE_WINDOW_ALLOCATE_BUFFERS: | 
|  | 1204 | allocateBuffers(); | 
|  | 1205 | res = NO_ERROR; | 
|  | 1206 | break; | 
| Alec Mouri | ef0b153 | 2019-12-17 09:39:07 -0800 | [diff] [blame] | 1207 | case NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER: | 
|  | 1208 | res = dispatchGetLastQueuedBuffer(args); | 
|  | 1209 | break; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1210 | default: | 
|  | 1211 | res = NAME_NOT_FOUND; | 
|  | 1212 | break; | 
|  | 1213 | } | 
|  | 1214 | return res; | 
|  | 1215 | } | 
| Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 1216 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1217 | int Surface::dispatchConnect(va_list args) { | 
|  | 1218 | int api = va_arg(args, int); | 
|  | 1219 | return connect(api); | 
|  | 1220 | } | 
| Mathias Agopian | 55fa251 | 2010-03-11 15:06:54 -0800 | [diff] [blame] | 1221 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1222 | int Surface::dispatchDisconnect(va_list args) { | 
|  | 1223 | int api = va_arg(args, int); | 
|  | 1224 | return disconnect(api); | 
|  | 1225 | } | 
|  | 1226 |  | 
|  | 1227 | int Surface::dispatchSetUsage(va_list args) { | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 1228 | uint64_t usage = va_arg(args, uint32_t); | 
|  | 1229 | return setUsage(usage); | 
|  | 1230 | } | 
|  | 1231 |  | 
|  | 1232 | int Surface::dispatchSetUsage64(va_list args) { | 
|  | 1233 | uint64_t usage = va_arg(args, uint64_t); | 
|  | 1234 | return setUsage(usage); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1235 | } | 
|  | 1236 |  | 
|  | 1237 | int Surface::dispatchSetCrop(va_list args) { | 
|  | 1238 | android_native_rect_t const* rect = va_arg(args, android_native_rect_t*); | 
|  | 1239 | return setCrop(reinterpret_cast<Rect const*>(rect)); | 
|  | 1240 | } | 
|  | 1241 |  | 
|  | 1242 | int Surface::dispatchSetBufferCount(va_list args) { | 
|  | 1243 | size_t bufferCount = va_arg(args, size_t); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1244 | return setBufferCount(static_cast<int32_t>(bufferCount)); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1245 | } | 
|  | 1246 |  | 
|  | 1247 | int Surface::dispatchSetBuffersGeometry(va_list args) { | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1248 | uint32_t width = va_arg(args, uint32_t); | 
|  | 1249 | uint32_t height = va_arg(args, uint32_t); | 
|  | 1250 | PixelFormat format = va_arg(args, PixelFormat); | 
|  | 1251 | int err = setBuffersDimensions(width, height); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1252 | if (err != 0) { | 
|  | 1253 | return err; | 
|  | 1254 | } | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1255 | return setBuffersFormat(format); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1256 | } | 
|  | 1257 |  | 
|  | 1258 | int Surface::dispatchSetBuffersDimensions(va_list args) { | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1259 | uint32_t width = va_arg(args, uint32_t); | 
|  | 1260 | uint32_t height = va_arg(args, uint32_t); | 
|  | 1261 | return setBuffersDimensions(width, height); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1262 | } | 
|  | 1263 |  | 
|  | 1264 | int Surface::dispatchSetBuffersUserDimensions(va_list args) { | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1265 | uint32_t width = va_arg(args, uint32_t); | 
|  | 1266 | uint32_t height = va_arg(args, uint32_t); | 
|  | 1267 | return setBuffersUserDimensions(width, height); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1268 | } | 
|  | 1269 |  | 
|  | 1270 | int Surface::dispatchSetBuffersFormat(va_list args) { | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1271 | PixelFormat format = va_arg(args, PixelFormat); | 
|  | 1272 | return setBuffersFormat(format); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1273 | } | 
|  | 1274 |  | 
|  | 1275 | int Surface::dispatchSetScalingMode(va_list args) { | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1276 | int mode = va_arg(args, int); | 
|  | 1277 | return setScalingMode(mode); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1278 | } | 
|  | 1279 |  | 
|  | 1280 | int Surface::dispatchSetBuffersTransform(va_list args) { | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1281 | uint32_t transform = va_arg(args, uint32_t); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1282 | return setBuffersTransform(transform); | 
|  | 1283 | } | 
|  | 1284 |  | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1285 | int Surface::dispatchSetBuffersStickyTransform(va_list args) { | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1286 | uint32_t transform = va_arg(args, uint32_t); | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1287 | return setBuffersStickyTransform(transform); | 
|  | 1288 | } | 
|  | 1289 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1290 | int Surface::dispatchSetBuffersTimestamp(va_list args) { | 
|  | 1291 | int64_t timestamp = va_arg(args, int64_t); | 
|  | 1292 | return setBuffersTimestamp(timestamp); | 
|  | 1293 | } | 
|  | 1294 |  | 
|  | 1295 | int Surface::dispatchLock(va_list args) { | 
|  | 1296 | ANativeWindow_Buffer* outBuffer = va_arg(args, ANativeWindow_Buffer*); | 
|  | 1297 | ARect* inOutDirtyBounds = va_arg(args, ARect*); | 
|  | 1298 | return lock(outBuffer, inOutDirtyBounds); | 
|  | 1299 | } | 
|  | 1300 |  | 
| Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 1301 | int Surface::dispatchUnlockAndPost(va_list args __attribute__((unused))) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1302 | return unlockAndPost(); | 
|  | 1303 | } | 
|  | 1304 |  | 
| Rachad | 7cb0d39 | 2014-07-29 17:53:53 -0700 | [diff] [blame] | 1305 | int Surface::dispatchSetSidebandStream(va_list args) { | 
|  | 1306 | native_handle_t* sH = va_arg(args, native_handle_t*); | 
|  | 1307 | sp<NativeHandle> sidebandHandle = NativeHandle::create(sH, false); | 
|  | 1308 | setSidebandStream(sidebandHandle); | 
|  | 1309 | return OK; | 
|  | 1310 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1311 |  | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 1312 | int Surface::dispatchSetBuffersDataSpace(va_list args) { | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 1313 | Dataspace dataspace = static_cast<Dataspace>(va_arg(args, int)); | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 1314 | return setBuffersDataSpace(dataspace); | 
|  | 1315 | } | 
|  | 1316 |  | 
| Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 1317 | int Surface::dispatchSetBuffersSmpte2086Metadata(va_list args) { | 
|  | 1318 | const android_smpte2086_metadata* metadata = | 
|  | 1319 | va_arg(args, const android_smpte2086_metadata*); | 
|  | 1320 | return setBuffersSmpte2086Metadata(metadata); | 
|  | 1321 | } | 
|  | 1322 |  | 
|  | 1323 | int Surface::dispatchSetBuffersCta8613Metadata(va_list args) { | 
|  | 1324 | const android_cta861_3_metadata* metadata = | 
|  | 1325 | va_arg(args, const android_cta861_3_metadata*); | 
|  | 1326 | return setBuffersCta8613Metadata(metadata); | 
|  | 1327 | } | 
|  | 1328 |  | 
| Valerie Hau | a82679d | 2018-11-21 09:31:43 -0800 | [diff] [blame] | 1329 | int Surface::dispatchSetBuffersHdr10PlusMetadata(va_list args) { | 
|  | 1330 | const size_t size = va_arg(args, size_t); | 
|  | 1331 | const uint8_t* metadata = va_arg(args, const uint8_t*); | 
|  | 1332 | return setBuffersHdr10PlusMetadata(size, metadata); | 
|  | 1333 | } | 
|  | 1334 |  | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 1335 | int Surface::dispatchSetSurfaceDamage(va_list args) { | 
|  | 1336 | android_native_rect_t* rects = va_arg(args, android_native_rect_t*); | 
|  | 1337 | size_t numRects = va_arg(args, size_t); | 
|  | 1338 | setSurfaceDamage(rects, numRects); | 
|  | 1339 | return NO_ERROR; | 
|  | 1340 | } | 
|  | 1341 |  | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 1342 | int Surface::dispatchSetSharedBufferMode(va_list args) { | 
|  | 1343 | bool sharedBufferMode = va_arg(args, int); | 
|  | 1344 | return setSharedBufferMode(sharedBufferMode); | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1345 | } | 
|  | 1346 |  | 
|  | 1347 | int Surface::dispatchSetAutoRefresh(va_list args) { | 
|  | 1348 | bool autoRefresh = va_arg(args, int); | 
|  | 1349 | return setAutoRefresh(autoRefresh); | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 1350 | } | 
|  | 1351 |  | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1352 | int Surface::dispatchGetDisplayRefreshCycleDuration(va_list args) { | 
|  | 1353 | nsecs_t* outRefreshDuration = va_arg(args, int64_t*); | 
|  | 1354 | return getDisplayRefreshCycleDuration(outRefreshDuration); | 
|  | 1355 | } | 
|  | 1356 |  | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 1357 | int Surface::dispatchGetNextFrameId(va_list args) { | 
|  | 1358 | uint64_t* nextFrameId = va_arg(args, uint64_t*); | 
|  | 1359 | *nextFrameId = getNextFrameNumber(); | 
|  | 1360 | return NO_ERROR; | 
|  | 1361 | } | 
|  | 1362 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1363 | int Surface::dispatchEnableFrameTimestamps(va_list args) { | 
|  | 1364 | bool enable = va_arg(args, int); | 
|  | 1365 | enableFrameTimestamps(enable); | 
|  | 1366 | return NO_ERROR; | 
|  | 1367 | } | 
|  | 1368 |  | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 1369 | int Surface::dispatchGetCompositorTiming(va_list args) { | 
|  | 1370 | nsecs_t* compositeDeadline = va_arg(args, int64_t*); | 
|  | 1371 | nsecs_t* compositeInterval = va_arg(args, int64_t*); | 
|  | 1372 | nsecs_t* compositeToPresentLatency = va_arg(args, int64_t*); | 
|  | 1373 | return getCompositorTiming(compositeDeadline, compositeInterval, | 
|  | 1374 | compositeToPresentLatency); | 
|  | 1375 | } | 
|  | 1376 |  | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 1377 | int Surface::dispatchGetFrameTimestamps(va_list args) { | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 1378 | uint64_t frameId = va_arg(args, uint64_t); | 
| Brian Anderson | dbd0ea8 | 2016-07-22 09:38:59 -0700 | [diff] [blame] | 1379 | nsecs_t* outRequestedPresentTime = va_arg(args, int64_t*); | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 1380 | nsecs_t* outAcquireTime = va_arg(args, int64_t*); | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 1381 | nsecs_t* outLatchTime = va_arg(args, int64_t*); | 
|  | 1382 | nsecs_t* outFirstRefreshStartTime = va_arg(args, int64_t*); | 
|  | 1383 | nsecs_t* outLastRefreshStartTime = va_arg(args, int64_t*); | 
| Brian Anderson | b04c6f0 | 2016-10-21 12:57:46 -0700 | [diff] [blame] | 1384 | nsecs_t* outGpuCompositionDoneTime = va_arg(args, int64_t*); | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 1385 | nsecs_t* outDisplayPresentTime = va_arg(args, int64_t*); | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 1386 | nsecs_t* outDequeueReadyTime = va_arg(args, int64_t*); | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 1387 | nsecs_t* outReleaseTime = va_arg(args, int64_t*); | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 1388 | return getFrameTimestamps(frameId, | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 1389 | outRequestedPresentTime, outAcquireTime, outLatchTime, | 
|  | 1390 | outFirstRefreshStartTime, outLastRefreshStartTime, | 
| Brian Anderson | b04c6f0 | 2016-10-21 12:57:46 -0700 | [diff] [blame] | 1391 | outGpuCompositionDoneTime, outDisplayPresentTime, | 
| Brian Anderson | 4e606e3 | 2017-03-16 15:34:57 -0700 | [diff] [blame] | 1392 | outDequeueReadyTime, outReleaseTime); | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 1393 | } | 
|  | 1394 |  | 
| Courtney Goeltzenleuchter | 1eb1b27 | 2017-02-02 16:51:06 -0700 | [diff] [blame] | 1395 | int Surface::dispatchGetWideColorSupport(va_list args) { | 
|  | 1396 | bool* outSupport = va_arg(args, bool*); | 
|  | 1397 | return getWideColorSupport(outSupport); | 
|  | 1398 | } | 
|  | 1399 |  | 
| Courtney Goeltzenleuchter | c5b97c5 | 2017-02-26 14:47:13 -0700 | [diff] [blame] | 1400 | int Surface::dispatchGetHdrSupport(va_list args) { | 
|  | 1401 | bool* outSupport = va_arg(args, bool*); | 
|  | 1402 | return getHdrSupport(outSupport); | 
|  | 1403 | } | 
|  | 1404 |  | 
| Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 1405 | int Surface::dispatchGetConsumerUsage64(va_list args) { | 
|  | 1406 | uint64_t* usage = va_arg(args, uint64_t*); | 
|  | 1407 | return getConsumerUsage(usage); | 
|  | 1408 | } | 
|  | 1409 |  | 
| Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 1410 | int Surface::dispatchSetAutoPrerotation(va_list args) { | 
|  | 1411 | bool autoPrerotation = va_arg(args, int); | 
|  | 1412 | return setAutoPrerotation(autoPrerotation); | 
|  | 1413 | } | 
|  | 1414 |  | 
| Alec Mouri | a161966 | 2019-08-21 19:30:48 -0700 | [diff] [blame] | 1415 | int Surface::dispatchGetLastDequeueStartTime(va_list args) { | 
|  | 1416 | int64_t* lastDequeueStartTime = va_arg(args, int64_t*); | 
|  | 1417 | *lastDequeueStartTime = mLastDequeueStartTime; | 
|  | 1418 | return NO_ERROR; | 
|  | 1419 | } | 
|  | 1420 |  | 
| Alec Mouri | 04fdb60 | 2019-08-23 19:41:43 -0700 | [diff] [blame] | 1421 | int Surface::dispatchSetDequeueTimeout(va_list args) { | 
|  | 1422 | nsecs_t timeout = va_arg(args, int64_t); | 
|  | 1423 | return setDequeueTimeout(timeout); | 
|  | 1424 | } | 
|  | 1425 |  | 
| Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 1426 | int Surface::dispatchGetLastDequeueDuration(va_list args) { | 
|  | 1427 | int64_t* lastDequeueDuration = va_arg(args, int64_t*); | 
|  | 1428 | *lastDequeueDuration = mLastDequeueDuration; | 
|  | 1429 | return NO_ERROR; | 
|  | 1430 | } | 
|  | 1431 |  | 
|  | 1432 | int Surface::dispatchGetLastQueueDuration(va_list args) { | 
|  | 1433 | int64_t* lastQueueDuration = va_arg(args, int64_t*); | 
|  | 1434 | *lastQueueDuration = mLastQueueDuration; | 
|  | 1435 | return NO_ERROR; | 
|  | 1436 | } | 
|  | 1437 |  | 
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1438 | int Surface::dispatchSetFrameRate(va_list args) { | 
|  | 1439 | float frameRate = static_cast<float>(va_arg(args, double)); | 
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 1440 | int8_t compatibility = static_cast<int8_t>(va_arg(args, int)); | 
|  | 1441 | return setFrameRate(frameRate, compatibility); | 
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1442 | } | 
|  | 1443 |  | 
| Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 1444 | int Surface::dispatchAddCancelInterceptor(va_list args) { | 
|  | 1445 | ANativeWindow_cancelBufferInterceptor interceptor = | 
|  | 1446 | va_arg(args, ANativeWindow_cancelBufferInterceptor); | 
|  | 1447 | void* data = va_arg(args, void*); | 
|  | 1448 | std::lock_guard<std::shared_mutex> lock(mInterceptorMutex); | 
|  | 1449 | mCancelInterceptor = interceptor; | 
|  | 1450 | mCancelInterceptorData = data; | 
|  | 1451 | return NO_ERROR; | 
|  | 1452 | } | 
|  | 1453 |  | 
|  | 1454 | int Surface::dispatchAddDequeueInterceptor(va_list args) { | 
|  | 1455 | ANativeWindow_dequeueBufferInterceptor interceptor = | 
|  | 1456 | va_arg(args, ANativeWindow_dequeueBufferInterceptor); | 
|  | 1457 | void* data = va_arg(args, void*); | 
|  | 1458 | std::lock_guard<std::shared_mutex> lock(mInterceptorMutex); | 
|  | 1459 | mDequeueInterceptor = interceptor; | 
|  | 1460 | mDequeueInterceptorData = data; | 
|  | 1461 | return NO_ERROR; | 
|  | 1462 | } | 
|  | 1463 |  | 
|  | 1464 | int Surface::dispatchAddPerformInterceptor(va_list args) { | 
|  | 1465 | ANativeWindow_performInterceptor interceptor = va_arg(args, ANativeWindow_performInterceptor); | 
|  | 1466 | void* data = va_arg(args, void*); | 
|  | 1467 | std::lock_guard<std::shared_mutex> lock(mInterceptorMutex); | 
|  | 1468 | mPerformInterceptor = interceptor; | 
|  | 1469 | mPerformInterceptorData = data; | 
|  | 1470 | return NO_ERROR; | 
|  | 1471 | } | 
|  | 1472 |  | 
|  | 1473 | int Surface::dispatchAddQueueInterceptor(va_list args) { | 
|  | 1474 | ANativeWindow_queueBufferInterceptor interceptor = | 
|  | 1475 | va_arg(args, ANativeWindow_queueBufferInterceptor); | 
|  | 1476 | void* data = va_arg(args, void*); | 
|  | 1477 | std::lock_guard<std::shared_mutex> lock(mInterceptorMutex); | 
|  | 1478 | mQueueInterceptor = interceptor; | 
|  | 1479 | mQueueInterceptorData = data; | 
|  | 1480 | return NO_ERROR; | 
|  | 1481 | } | 
|  | 1482 |  | 
| John Reck | 401cda6 | 2020-05-07 16:04:41 -0700 | [diff] [blame] | 1483 | int Surface::dispatchAddQueryInterceptor(va_list args) { | 
|  | 1484 | ANativeWindow_queryInterceptor interceptor = va_arg(args, ANativeWindow_queryInterceptor); | 
|  | 1485 | void* data = va_arg(args, void*); | 
|  | 1486 | std::lock_guard<std::shared_mutex> lock(mInterceptorMutex); | 
|  | 1487 | mQueryInterceptor = interceptor; | 
|  | 1488 | mQueryInterceptorData = data; | 
|  | 1489 | return NO_ERROR; | 
|  | 1490 | } | 
|  | 1491 |  | 
| Alec Mouri | ef0b153 | 2019-12-17 09:39:07 -0800 | [diff] [blame] | 1492 | int Surface::dispatchGetLastQueuedBuffer(va_list args) { | 
|  | 1493 | AHardwareBuffer** buffer = va_arg(args, AHardwareBuffer**); | 
|  | 1494 | int* fence = va_arg(args, int*); | 
|  | 1495 | float* matrix = va_arg(args, float*); | 
|  | 1496 | sp<GraphicBuffer> graphicBuffer; | 
|  | 1497 | sp<Fence> spFence; | 
|  | 1498 |  | 
|  | 1499 | int result = mGraphicBufferProducer->getLastQueuedBuffer(&graphicBuffer, &spFence, matrix); | 
|  | 1500 |  | 
|  | 1501 | if (graphicBuffer != nullptr) { | 
|  | 1502 | *buffer = reinterpret_cast<AHardwareBuffer*>(graphicBuffer.get()); | 
|  | 1503 | AHardwareBuffer_acquire(*buffer); | 
|  | 1504 | } else { | 
|  | 1505 | *buffer = nullptr; | 
|  | 1506 | } | 
|  | 1507 |  | 
|  | 1508 | if (spFence != nullptr) { | 
|  | 1509 | *fence = spFence->dup(); | 
|  | 1510 | } else { | 
|  | 1511 | *fence = -1; | 
|  | 1512 | } | 
|  | 1513 | return result; | 
|  | 1514 | } | 
|  | 1515 |  | 
| Vishnu Nair | 5eb3f06 | 2019-04-08 08:21:03 -0700 | [diff] [blame] | 1516 | bool Surface::transformToDisplayInverse() { | 
|  | 1517 | return (mTransform & NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY) == | 
|  | 1518 | NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY; | 
|  | 1519 | } | 
|  | 1520 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1521 | int Surface::connect(int api) { | 
| Peiyong Lin | d8460c8 | 2020-07-28 16:04:22 -0700 | [diff] [blame] | 1522 | static sp<IProducerListener> listener = new StubProducerListener(); | 
| Dan Stoza | 966b98b | 2015-03-02 22:12:37 -0800 | [diff] [blame] | 1523 | return connect(api, listener); | 
|  | 1524 | } | 
|  | 1525 |  | 
|  | 1526 | int Surface::connect(int api, const sp<IProducerListener>& listener) { | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 1527 | return connect(api, listener, false); | 
|  | 1528 | } | 
|  | 1529 |  | 
|  | 1530 | int Surface::connect( | 
| Shuzhen Wang | 067fcd3 | 2019-08-14 10:41:12 -0700 | [diff] [blame] | 1531 | int api, bool reportBufferRemoval, const sp<SurfaceListener>& sListener) { | 
|  | 1532 | if (sListener != nullptr) { | 
|  | 1533 | mListenerProxy = new ProducerListenerProxy(this, sListener); | 
|  | 1534 | } | 
|  | 1535 | return connect(api, mListenerProxy, reportBufferRemoval); | 
|  | 1536 | } | 
|  | 1537 |  | 
|  | 1538 | int Surface::connect( | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 1539 | int api, const sp<IProducerListener>& listener, bool reportBufferRemoval) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1540 | ATRACE_CALL(); | 
|  | 1541 | ALOGV("Surface::connect"); | 
|  | 1542 | Mutex::Autolock lock(mMutex); | 
|  | 1543 | IGraphicBufferProducer::QueueBufferOutput output; | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 1544 | mReportRemovedBuffers = reportBufferRemoval; | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 1545 | int err = mGraphicBufferProducer->connect(listener, api, mProducerControlledByApp, &output); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1546 | if (err == NO_ERROR) { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1547 | mDefaultWidth = output.width; | 
|  | 1548 | mDefaultHeight = output.height; | 
|  | 1549 | mNextFrameNumber = output.nextFrameNumber; | 
| silence_dogood | e9d092a | 2019-06-19 16:14:53 -0700 | [diff] [blame] | 1550 | mMaxBufferCount = output.maxBufferCount; | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1551 |  | 
| Vishnu Nair | 5eb3f06 | 2019-04-08 08:21:03 -0700 | [diff] [blame] | 1552 | // Ignore transform hint if sticky transform is set or transform to display inverse flag is | 
|  | 1553 | // set. Transform hint should be ignored if the client is expected to always submit buffers | 
|  | 1554 | // in the same orientation. | 
|  | 1555 | if (mStickyTransform == 0 && !transformToDisplayInverse()) { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1556 | mTransformHint = output.transformHint; | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1557 | } | 
|  | 1558 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1559 | mConsumerRunningBehind = (output.numPendingBuffers >= 2); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1560 | } | 
|  | 1561 | if (!err && api == NATIVE_WINDOW_API_CPU) { | 
|  | 1562 | mConnectedToCpu = true; | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 1563 | // Clear the dirty region in case we're switching from a non-CPU API | 
|  | 1564 | mDirtyRegion.clear(); | 
|  | 1565 | } else if (!err) { | 
|  | 1566 | // Initialize the dirty region for tracking surface damage | 
|  | 1567 | mDirtyRegion = Region::INVALID_REGION; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1568 | } | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 1569 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1570 | return err; | 
|  | 1571 | } | 
|  | 1572 |  | 
| Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 1573 |  | 
| Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 1574 | int Surface::disconnect(int api, IGraphicBufferProducer::DisconnectMode mode) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1575 | ATRACE_CALL(); | 
|  | 1576 | ALOGV("Surface::disconnect"); | 
|  | 1577 | Mutex::Autolock lock(mMutex); | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 1578 | mRemovedBuffers.clear(); | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1579 | mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT; | 
|  | 1580 | mSharedBufferHasBeenQueued = false; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1581 | freeAllBuffers(); | 
| Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 1582 | int err = mGraphicBufferProducer->disconnect(api, mode); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1583 | if (!err) { | 
|  | 1584 | mReqFormat = 0; | 
|  | 1585 | mReqWidth = 0; | 
|  | 1586 | mReqHeight = 0; | 
|  | 1587 | mReqUsage = 0; | 
|  | 1588 | mCrop.clear(); | 
|  | 1589 | mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE; | 
|  | 1590 | mTransform = 0; | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1591 | mStickyTransform = 0; | 
| Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 1592 | mAutoPrerotation = false; | 
| Yiwei Zhang | c185192 | 2019-08-21 14:02:45 -0700 | [diff] [blame] | 1593 | mEnableFrameTimestamps = false; | 
| Yiwei Zhang | 74c9cc3 | 2020-06-20 03:35:17 -0700 | [diff] [blame] | 1594 | mMaxBufferCount = NUM_BUFFER_SLOTS; | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1595 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1596 | if (api == NATIVE_WINDOW_API_CPU) { | 
|  | 1597 | mConnectedToCpu = false; | 
|  | 1598 | } | 
|  | 1599 | } | 
|  | 1600 | return err; | 
|  | 1601 | } | 
|  | 1602 |  | 
| Dan Stoza | d9c4971 | 2015-04-27 11:06:01 -0700 | [diff] [blame] | 1603 | int Surface::detachNextBuffer(sp<GraphicBuffer>* outBuffer, | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 1604 | sp<Fence>* outFence) { | 
|  | 1605 | ATRACE_CALL(); | 
|  | 1606 | ALOGV("Surface::detachNextBuffer"); | 
|  | 1607 |  | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 1608 | if (outBuffer == nullptr || outFence == nullptr) { | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 1609 | return BAD_VALUE; | 
|  | 1610 | } | 
|  | 1611 |  | 
|  | 1612 | Mutex::Autolock lock(mMutex); | 
| Yin-Chia Yeh | 1f2af5c | 2017-05-11 16:54:04 -0700 | [diff] [blame] | 1613 | if (mReportRemovedBuffers) { | 
|  | 1614 | mRemovedBuffers.clear(); | 
|  | 1615 | } | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 1616 |  | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 1617 | sp<GraphicBuffer> buffer(nullptr); | 
|  | 1618 | sp<Fence> fence(nullptr); | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 1619 | status_t result = mGraphicBufferProducer->detachNextBuffer( | 
|  | 1620 | &buffer, &fence); | 
|  | 1621 | if (result != NO_ERROR) { | 
|  | 1622 | return result; | 
|  | 1623 | } | 
|  | 1624 |  | 
| Dan Stoza | d9c4971 | 2015-04-27 11:06:01 -0700 | [diff] [blame] | 1625 | *outBuffer = buffer; | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 1626 | if (fence != nullptr && fence->isValid()) { | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 1627 | *outFence = fence; | 
|  | 1628 | } else { | 
|  | 1629 | *outFence = Fence::NO_FENCE; | 
|  | 1630 | } | 
|  | 1631 |  | 
| Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 1632 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 1633 | if (mSlots[i].buffer != nullptr && | 
| Shuzhen Wang | 55be505 | 2017-05-23 09:41:54 -0700 | [diff] [blame] | 1634 | mSlots[i].buffer->getId() == buffer->getId()) { | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 1635 | if (mReportRemovedBuffers) { | 
|  | 1636 | mRemovedBuffers.push_back(mSlots[i].buffer); | 
|  | 1637 | } | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 1638 | mSlots[i].buffer = nullptr; | 
| Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 1639 | } | 
|  | 1640 | } | 
|  | 1641 |  | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 1642 | return NO_ERROR; | 
|  | 1643 | } | 
|  | 1644 |  | 
|  | 1645 | int Surface::attachBuffer(ANativeWindowBuffer* buffer) | 
|  | 1646 | { | 
|  | 1647 | ATRACE_CALL(); | 
|  | 1648 | ALOGV("Surface::attachBuffer"); | 
|  | 1649 |  | 
|  | 1650 | Mutex::Autolock lock(mMutex); | 
| Yin-Chia Yeh | 1f2af5c | 2017-05-11 16:54:04 -0700 | [diff] [blame] | 1651 | if (mReportRemovedBuffers) { | 
|  | 1652 | mRemovedBuffers.clear(); | 
|  | 1653 | } | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 1654 |  | 
|  | 1655 | sp<GraphicBuffer> graphicBuffer(static_cast<GraphicBuffer*>(buffer)); | 
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 1656 | uint32_t priorGeneration = graphicBuffer->mGenerationNumber; | 
|  | 1657 | graphicBuffer->mGenerationNumber = mGenerationNumber; | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 1658 | int32_t attachedSlot = -1; | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 1659 | status_t result = mGraphicBufferProducer->attachBuffer(&attachedSlot, graphicBuffer); | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 1660 | if (result != NO_ERROR) { | 
|  | 1661 | ALOGE("attachBuffer: IGraphicBufferProducer call failed (%d)", result); | 
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 1662 | graphicBuffer->mGenerationNumber = priorGeneration; | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 1663 | return result; | 
|  | 1664 | } | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 1665 | if (mReportRemovedBuffers && (mSlots[attachedSlot].buffer != nullptr)) { | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 1666 | mRemovedBuffers.push_back(mSlots[attachedSlot].buffer); | 
|  | 1667 | } | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 1668 | mSlots[attachedSlot].buffer = graphicBuffer; | 
| Yin-Chia Yeh | da2e609 | 2020-07-29 15:00:07 -0700 | [diff] [blame] | 1669 | mDequeuedSlots.insert(attachedSlot); | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 1670 |  | 
|  | 1671 | return NO_ERROR; | 
|  | 1672 | } | 
|  | 1673 |  | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 1674 | int Surface::setUsage(uint64_t reqUsage) | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1675 | { | 
|  | 1676 | ALOGV("Surface::setUsage"); | 
|  | 1677 | Mutex::Autolock lock(mMutex); | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1678 | if (reqUsage != mReqUsage) { | 
|  | 1679 | mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT; | 
|  | 1680 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1681 | mReqUsage = reqUsage; | 
|  | 1682 | return OK; | 
|  | 1683 | } | 
|  | 1684 |  | 
|  | 1685 | int Surface::setCrop(Rect const* rect) | 
|  | 1686 | { | 
|  | 1687 | ATRACE_CALL(); | 
|  | 1688 |  | 
| Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 1689 | Rect realRect(Rect::EMPTY_RECT); | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 1690 | if (rect == nullptr || rect->isEmpty()) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1691 | realRect.clear(); | 
|  | 1692 | } else { | 
|  | 1693 | realRect = *rect; | 
| Mathias Agopian | 55fa251 | 2010-03-11 15:06:54 -0800 | [diff] [blame] | 1694 | } | 
|  | 1695 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1696 | ALOGV("Surface::setCrop rect=[%d %d %d %d]", | 
|  | 1697 | realRect.left, realRect.top, realRect.right, realRect.bottom); | 
|  | 1698 |  | 
|  | 1699 | Mutex::Autolock lock(mMutex); | 
|  | 1700 | mCrop = realRect; | 
|  | 1701 | return NO_ERROR; | 
|  | 1702 | } | 
|  | 1703 |  | 
|  | 1704 | int Surface::setBufferCount(int bufferCount) | 
|  | 1705 | { | 
|  | 1706 | ATRACE_CALL(); | 
|  | 1707 | ALOGV("Surface::setBufferCount"); | 
|  | 1708 | Mutex::Autolock lock(mMutex); | 
|  | 1709 |  | 
| Pablo Ceballos | e5b755a | 2015-08-13 16:18:19 -0700 | [diff] [blame] | 1710 | status_t err = NO_ERROR; | 
|  | 1711 | if (bufferCount == 0) { | 
|  | 1712 | err = mGraphicBufferProducer->setMaxDequeuedBufferCount(1); | 
|  | 1713 | } else { | 
|  | 1714 | int minUndequeuedBuffers = 0; | 
|  | 1715 | err = mGraphicBufferProducer->query( | 
|  | 1716 | NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &minUndequeuedBuffers); | 
|  | 1717 | if (err == NO_ERROR) { | 
|  | 1718 | err = mGraphicBufferProducer->setMaxDequeuedBufferCount( | 
|  | 1719 | bufferCount - minUndequeuedBuffers); | 
|  | 1720 | } | 
|  | 1721 | } | 
| Mathias Agopian | 9014726 | 2010-01-22 11:47:55 -0800 | [diff] [blame] | 1722 |  | 
| Pablo Ceballos | e5b755a | 2015-08-13 16:18:19 -0700 | [diff] [blame] | 1723 | ALOGE_IF(err, "IGraphicBufferProducer::setBufferCount(%d) returned %s", | 
|  | 1724 | bufferCount, strerror(-err)); | 
|  | 1725 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1726 | return err; | 
|  | 1727 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1728 |  | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 1729 | int Surface::setMaxDequeuedBufferCount(int maxDequeuedBuffers) { | 
|  | 1730 | ATRACE_CALL(); | 
|  | 1731 | ALOGV("Surface::setMaxDequeuedBufferCount"); | 
|  | 1732 | Mutex::Autolock lock(mMutex); | 
|  | 1733 |  | 
|  | 1734 | status_t err = mGraphicBufferProducer->setMaxDequeuedBufferCount( | 
|  | 1735 | maxDequeuedBuffers); | 
|  | 1736 | ALOGE_IF(err, "IGraphicBufferProducer::setMaxDequeuedBufferCount(%d) " | 
|  | 1737 | "returned %s", maxDequeuedBuffers, strerror(-err)); | 
|  | 1738 |  | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 1739 | return err; | 
|  | 1740 | } | 
|  | 1741 |  | 
|  | 1742 | int Surface::setAsyncMode(bool async) { | 
|  | 1743 | ATRACE_CALL(); | 
|  | 1744 | ALOGV("Surface::setAsyncMode"); | 
|  | 1745 | Mutex::Autolock lock(mMutex); | 
|  | 1746 |  | 
|  | 1747 | status_t err = mGraphicBufferProducer->setAsyncMode(async); | 
|  | 1748 | ALOGE_IF(err, "IGraphicBufferProducer::setAsyncMode(%d) returned %s", | 
|  | 1749 | async, strerror(-err)); | 
|  | 1750 |  | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 1751 | return err; | 
|  | 1752 | } | 
|  | 1753 |  | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 1754 | int Surface::setSharedBufferMode(bool sharedBufferMode) { | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 1755 | ATRACE_CALL(); | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 1756 | ALOGV("Surface::setSharedBufferMode (%d)", sharedBufferMode); | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 1757 | Mutex::Autolock lock(mMutex); | 
|  | 1758 |  | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 1759 | status_t err = mGraphicBufferProducer->setSharedBufferMode( | 
|  | 1760 | sharedBufferMode); | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1761 | if (err == NO_ERROR) { | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 1762 | mSharedBufferMode = sharedBufferMode; | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1763 | } | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 1764 | ALOGE_IF(err, "IGraphicBufferProducer::setSharedBufferMode(%d) returned" | 
|  | 1765 | "%s", sharedBufferMode, strerror(-err)); | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 1766 |  | 
|  | 1767 | return err; | 
|  | 1768 | } | 
|  | 1769 |  | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1770 | int Surface::setAutoRefresh(bool autoRefresh) { | 
|  | 1771 | ATRACE_CALL(); | 
|  | 1772 | ALOGV("Surface::setAutoRefresh (%d)", autoRefresh); | 
|  | 1773 | Mutex::Autolock lock(mMutex); | 
|  | 1774 |  | 
|  | 1775 | status_t err = mGraphicBufferProducer->setAutoRefresh(autoRefresh); | 
|  | 1776 | if (err == NO_ERROR) { | 
|  | 1777 | mAutoRefresh = autoRefresh; | 
|  | 1778 | } | 
|  | 1779 | ALOGE_IF(err, "IGraphicBufferProducer::setAutoRefresh(%d) returned %s", | 
|  | 1780 | autoRefresh, strerror(-err)); | 
|  | 1781 | return err; | 
|  | 1782 | } | 
|  | 1783 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1784 | int Surface::setBuffersDimensions(uint32_t width, uint32_t height) | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1785 | { | 
|  | 1786 | ATRACE_CALL(); | 
|  | 1787 | ALOGV("Surface::setBuffersDimensions"); | 
|  | 1788 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1789 | if ((width && !height) || (!width && height)) | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1790 | return BAD_VALUE; | 
|  | 1791 |  | 
|  | 1792 | Mutex::Autolock lock(mMutex); | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1793 | if (width != mReqWidth || height != mReqHeight) { | 
|  | 1794 | mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT; | 
|  | 1795 | } | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1796 | mReqWidth = width; | 
|  | 1797 | mReqHeight = height; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1798 | return NO_ERROR; | 
|  | 1799 | } | 
|  | 1800 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1801 | int Surface::setBuffersUserDimensions(uint32_t width, uint32_t height) | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1802 | { | 
|  | 1803 | ATRACE_CALL(); | 
|  | 1804 | ALOGV("Surface::setBuffersUserDimensions"); | 
|  | 1805 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1806 | if ((width && !height) || (!width && height)) | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1807 | return BAD_VALUE; | 
|  | 1808 |  | 
|  | 1809 | Mutex::Autolock lock(mMutex); | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1810 | if (width != mUserWidth || height != mUserHeight) { | 
|  | 1811 | mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT; | 
|  | 1812 | } | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1813 | mUserWidth = width; | 
|  | 1814 | mUserHeight = height; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1815 | return NO_ERROR; | 
|  | 1816 | } | 
|  | 1817 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1818 | int Surface::setBuffersFormat(PixelFormat format) | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1819 | { | 
|  | 1820 | ALOGV("Surface::setBuffersFormat"); | 
|  | 1821 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1822 | Mutex::Autolock lock(mMutex); | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1823 | if (format != mReqFormat) { | 
|  | 1824 | mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT; | 
|  | 1825 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1826 | mReqFormat = format; | 
|  | 1827 | return NO_ERROR; | 
|  | 1828 | } | 
|  | 1829 |  | 
|  | 1830 | int Surface::setScalingMode(int mode) | 
|  | 1831 | { | 
|  | 1832 | ATRACE_CALL(); | 
|  | 1833 | ALOGV("Surface::setScalingMode(%d)", mode); | 
|  | 1834 |  | 
|  | 1835 | switch (mode) { | 
|  | 1836 | case NATIVE_WINDOW_SCALING_MODE_FREEZE: | 
|  | 1837 | case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW: | 
|  | 1838 | case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP: | 
| Robert Carr | c2e7788 | 2015-12-16 18:14:03 -0800 | [diff] [blame] | 1839 | case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP: | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1840 | break; | 
|  | 1841 | default: | 
|  | 1842 | ALOGE("unknown scaling mode: %d", mode); | 
|  | 1843 | return BAD_VALUE; | 
|  | 1844 | } | 
|  | 1845 |  | 
|  | 1846 | Mutex::Autolock lock(mMutex); | 
|  | 1847 | mScalingMode = mode; | 
|  | 1848 | return NO_ERROR; | 
|  | 1849 | } | 
|  | 1850 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1851 | int Surface::setBuffersTransform(uint32_t transform) | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1852 | { | 
|  | 1853 | ATRACE_CALL(); | 
|  | 1854 | ALOGV("Surface::setBuffersTransform"); | 
|  | 1855 | Mutex::Autolock lock(mMutex); | 
| Vishnu Nair | 5eb3f06 | 2019-04-08 08:21:03 -0700 | [diff] [blame] | 1856 | // Ensure NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY is sticky. If the client sets the flag, do not | 
|  | 1857 | // override it until the surface is disconnected. This is a temporary workaround for camera | 
|  | 1858 | // until they switch to using Buffer State Layers. Currently if client sets the buffer transform | 
|  | 1859 | // it may be overriden by the buffer producer when the producer sets the buffer transform. | 
|  | 1860 | if (transformToDisplayInverse()) { | 
|  | 1861 | transform |= NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY; | 
|  | 1862 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1863 | mTransform = transform; | 
|  | 1864 | return NO_ERROR; | 
|  | 1865 | } | 
|  | 1866 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1867 | int Surface::setBuffersStickyTransform(uint32_t transform) | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1868 | { | 
|  | 1869 | ATRACE_CALL(); | 
|  | 1870 | ALOGV("Surface::setBuffersStickyTransform"); | 
|  | 1871 | Mutex::Autolock lock(mMutex); | 
|  | 1872 | mStickyTransform = transform; | 
|  | 1873 | return NO_ERROR; | 
|  | 1874 | } | 
|  | 1875 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1876 | int Surface::setBuffersTimestamp(int64_t timestamp) | 
|  | 1877 | { | 
|  | 1878 | ALOGV("Surface::setBuffersTimestamp"); | 
|  | 1879 | Mutex::Autolock lock(mMutex); | 
|  | 1880 | mTimestamp = timestamp; | 
|  | 1881 | return NO_ERROR; | 
|  | 1882 | } | 
|  | 1883 |  | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 1884 | int Surface::setBuffersDataSpace(Dataspace dataSpace) | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 1885 | { | 
|  | 1886 | ALOGV("Surface::setBuffersDataSpace"); | 
|  | 1887 | Mutex::Autolock lock(mMutex); | 
|  | 1888 | mDataSpace = dataSpace; | 
|  | 1889 | return NO_ERROR; | 
|  | 1890 | } | 
|  | 1891 |  | 
| Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 1892 | int Surface::setBuffersSmpte2086Metadata(const android_smpte2086_metadata* metadata) { | 
|  | 1893 | ALOGV("Surface::setBuffersSmpte2086Metadata"); | 
|  | 1894 | Mutex::Autolock lock(mMutex); | 
|  | 1895 | if (metadata) { | 
|  | 1896 | mHdrMetadata.smpte2086 = *metadata; | 
|  | 1897 | mHdrMetadata.validTypes |= HdrMetadata::SMPTE2086; | 
|  | 1898 | } else { | 
|  | 1899 | mHdrMetadata.validTypes &= ~HdrMetadata::SMPTE2086; | 
|  | 1900 | } | 
|  | 1901 | return NO_ERROR; | 
|  | 1902 | } | 
|  | 1903 |  | 
|  | 1904 | int Surface::setBuffersCta8613Metadata(const android_cta861_3_metadata* metadata) { | 
|  | 1905 | ALOGV("Surface::setBuffersCta8613Metadata"); | 
|  | 1906 | Mutex::Autolock lock(mMutex); | 
|  | 1907 | if (metadata) { | 
|  | 1908 | mHdrMetadata.cta8613 = *metadata; | 
|  | 1909 | mHdrMetadata.validTypes |= HdrMetadata::CTA861_3; | 
|  | 1910 | } else { | 
|  | 1911 | mHdrMetadata.validTypes &= ~HdrMetadata::CTA861_3; | 
|  | 1912 | } | 
|  | 1913 | return NO_ERROR; | 
|  | 1914 | } | 
|  | 1915 |  | 
| Valerie Hau | a82679d | 2018-11-21 09:31:43 -0800 | [diff] [blame] | 1916 | int Surface::setBuffersHdr10PlusMetadata(const size_t size, const uint8_t* metadata) { | 
|  | 1917 | ALOGV("Surface::setBuffersBlobMetadata"); | 
|  | 1918 | Mutex::Autolock lock(mMutex); | 
|  | 1919 | if (size > 0) { | 
|  | 1920 | mHdrMetadata.hdr10plus.assign(metadata, metadata + size); | 
|  | 1921 | mHdrMetadata.validTypes |= HdrMetadata::HDR10PLUS; | 
|  | 1922 | } else { | 
|  | 1923 | mHdrMetadata.validTypes &= ~HdrMetadata::HDR10PLUS; | 
|  | 1924 | mHdrMetadata.hdr10plus.clear(); | 
|  | 1925 | } | 
|  | 1926 | return NO_ERROR; | 
|  | 1927 | } | 
|  | 1928 |  | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 1929 | Dataspace Surface::getBuffersDataSpace() { | 
| Courtney Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 1930 | ALOGV("Surface::getBuffersDataSpace"); | 
|  | 1931 | Mutex::Autolock lock(mMutex); | 
|  | 1932 | return mDataSpace; | 
|  | 1933 | } | 
|  | 1934 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1935 | void Surface::freeAllBuffers() { | 
| Yin-Chia Yeh | da2e609 | 2020-07-29 15:00:07 -0700 | [diff] [blame] | 1936 | if (!mDequeuedSlots.empty()) { | 
|  | 1937 | ALOGE("%s: %zu buffers were freed while being dequeued!", | 
|  | 1938 | __FUNCTION__, mDequeuedSlots.size()); | 
|  | 1939 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1940 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 1941 | mSlots[i].buffer = nullptr; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1942 | } | 
|  | 1943 | } | 
|  | 1944 |  | 
| Shuzhen Wang | 067fcd3 | 2019-08-14 10:41:12 -0700 | [diff] [blame] | 1945 | status_t Surface::getAndFlushBuffersFromSlots(const std::vector<int32_t>& slots, | 
|  | 1946 | std::vector<sp<GraphicBuffer>>* outBuffers) { | 
|  | 1947 | ALOGV("Surface::getAndFlushBuffersFromSlots"); | 
|  | 1948 | for (int32_t i : slots) { | 
|  | 1949 | if (i < 0 || i >= NUM_BUFFER_SLOTS) { | 
|  | 1950 | ALOGE("%s: Invalid slotIndex: %d", __FUNCTION__, i); | 
|  | 1951 | return BAD_VALUE; | 
|  | 1952 | } | 
|  | 1953 | } | 
|  | 1954 |  | 
|  | 1955 | Mutex::Autolock lock(mMutex); | 
|  | 1956 | for (int32_t i : slots) { | 
|  | 1957 | if (mSlots[i].buffer == nullptr) { | 
|  | 1958 | ALOGW("%s: Discarded slot %d doesn't contain buffer!", __FUNCTION__, i); | 
|  | 1959 | continue; | 
|  | 1960 | } | 
| Yin-Chia Yeh | da2e609 | 2020-07-29 15:00:07 -0700 | [diff] [blame] | 1961 | // Don't flush currently dequeued buffers | 
|  | 1962 | if (mDequeuedSlots.count(i) > 0) { | 
|  | 1963 | continue; | 
|  | 1964 | } | 
| Shuzhen Wang | 067fcd3 | 2019-08-14 10:41:12 -0700 | [diff] [blame] | 1965 | outBuffers->push_back(mSlots[i].buffer); | 
|  | 1966 | mSlots[i].buffer = nullptr; | 
|  | 1967 | } | 
|  | 1968 | return OK; | 
|  | 1969 | } | 
|  | 1970 |  | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 1971 | void Surface::setSurfaceDamage(android_native_rect_t* rects, size_t numRects) { | 
|  | 1972 | ATRACE_CALL(); | 
|  | 1973 | ALOGV("Surface::setSurfaceDamage"); | 
|  | 1974 | Mutex::Autolock lock(mMutex); | 
|  | 1975 |  | 
| Dan Stoza | c62acbd | 2015-04-21 16:42:49 -0700 | [diff] [blame] | 1976 | if (mConnectedToCpu || numRects == 0) { | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 1977 | mDirtyRegion = Region::INVALID_REGION; | 
|  | 1978 | return; | 
|  | 1979 | } | 
|  | 1980 |  | 
|  | 1981 | mDirtyRegion.clear(); | 
|  | 1982 | for (size_t r = 0; r < numRects; ++r) { | 
|  | 1983 | // We intentionally flip top and bottom here, since because they're | 
|  | 1984 | // specified with a bottom-left origin, top > bottom, which fails | 
|  | 1985 | // validation in the Region class. We will fix this up when we flip to a | 
|  | 1986 | // top-left origin in queueBuffer. | 
|  | 1987 | Rect rect(rects[r].left, rects[r].bottom, rects[r].right, rects[r].top); | 
|  | 1988 | mDirtyRegion.orSelf(rect); | 
|  | 1989 | } | 
|  | 1990 | } | 
|  | 1991 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1992 | // ---------------------------------------------------------------------- | 
|  | 1993 | // the lock/unlock APIs must be used from the same thread | 
|  | 1994 |  | 
|  | 1995 | static status_t copyBlt( | 
|  | 1996 | const sp<GraphicBuffer>& dst, | 
|  | 1997 | const sp<GraphicBuffer>& src, | 
| Francis Hart | 7b09e79 | 2015-01-09 11:10:54 +0200 | [diff] [blame] | 1998 | const Region& reg, | 
|  | 1999 | int *dstFenceFd) | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2000 | { | 
| Dennis Kempin | add458f | 2017-05-17 19:16:31 -0700 | [diff] [blame] | 2001 | if (dst->getId() == src->getId()) | 
|  | 2002 | return OK; | 
|  | 2003 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2004 | // src and dst with, height and format must be identical. no verification | 
|  | 2005 | // is done here. | 
|  | 2006 | status_t err; | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 2007 | uint8_t* src_bits = nullptr; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 2008 | err = src->lock(GRALLOC_USAGE_SW_READ_OFTEN, reg.bounds(), | 
|  | 2009 | reinterpret_cast<void**>(&src_bits)); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2010 | ALOGE_IF(err, "error locking src buffer %s", strerror(-err)); | 
|  | 2011 |  | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 2012 | uint8_t* dst_bits = nullptr; | 
| Francis Hart | 7b09e79 | 2015-01-09 11:10:54 +0200 | [diff] [blame] | 2013 | err = dst->lockAsync(GRALLOC_USAGE_SW_WRITE_OFTEN, reg.bounds(), | 
|  | 2014 | reinterpret_cast<void**>(&dst_bits), *dstFenceFd); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2015 | ALOGE_IF(err, "error locking dst buffer %s", strerror(-err)); | 
| Francis Hart | 7b09e79 | 2015-01-09 11:10:54 +0200 | [diff] [blame] | 2016 | *dstFenceFd = -1; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2017 |  | 
|  | 2018 | Region::const_iterator head(reg.begin()); | 
|  | 2019 | Region::const_iterator tail(reg.end()); | 
|  | 2020 | if (head != tail && src_bits && dst_bits) { | 
|  | 2021 | const size_t bpp = bytesPerPixel(src->format); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 2022 | const size_t dbpr = static_cast<uint32_t>(dst->stride) * bpp; | 
|  | 2023 | const size_t sbpr = static_cast<uint32_t>(src->stride) * bpp; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2024 |  | 
|  | 2025 | while (head != tail) { | 
|  | 2026 | const Rect& r(*head++); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 2027 | int32_t h = r.height(); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2028 | if (h <= 0) continue; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 2029 | size_t size = static_cast<uint32_t>(r.width()) * bpp; | 
|  | 2030 | uint8_t const * s = src_bits + | 
|  | 2031 | static_cast<uint32_t>(r.left + src->stride * r.top) * bpp; | 
|  | 2032 | uint8_t       * d = dst_bits + | 
|  | 2033 | static_cast<uint32_t>(r.left + dst->stride * r.top) * bpp; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2034 | if (dbpr==sbpr && size==sbpr) { | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 2035 | size *= static_cast<size_t>(h); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2036 | h = 1; | 
|  | 2037 | } | 
|  | 2038 | do { | 
|  | 2039 | memcpy(d, s, size); | 
|  | 2040 | d += dbpr; | 
|  | 2041 | s += sbpr; | 
|  | 2042 | } while (--h > 0); | 
|  | 2043 | } | 
|  | 2044 | } | 
|  | 2045 |  | 
|  | 2046 | if (src_bits) | 
|  | 2047 | src->unlock(); | 
|  | 2048 |  | 
|  | 2049 | if (dst_bits) | 
| Francis Hart | 7b09e79 | 2015-01-09 11:10:54 +0200 | [diff] [blame] | 2050 | dst->unlockAsync(dstFenceFd); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2051 |  | 
|  | 2052 | return err; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2053 | } | 
|  | 2054 |  | 
| Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 2055 | // ---------------------------------------------------------------------------- | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2056 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2057 | status_t Surface::lock( | 
|  | 2058 | ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds) | 
|  | 2059 | { | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 2060 | if (mLockedBuffer != nullptr) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2061 | ALOGE("Surface::lock failed, already locked"); | 
|  | 2062 | return INVALID_OPERATION; | 
|  | 2063 | } | 
|  | 2064 |  | 
|  | 2065 | if (!mConnectedToCpu) { | 
|  | 2066 | int err = Surface::connect(NATIVE_WINDOW_API_CPU); | 
|  | 2067 | if (err) { | 
|  | 2068 | return err; | 
|  | 2069 | } | 
|  | 2070 | // we're intending to do software rendering from this point | 
|  | 2071 | setUsage(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); | 
|  | 2072 | } | 
|  | 2073 |  | 
|  | 2074 | ANativeWindowBuffer* out; | 
|  | 2075 | int fenceFd = -1; | 
|  | 2076 | status_t err = dequeueBuffer(&out, &fenceFd); | 
|  | 2077 | ALOGE_IF(err, "dequeueBuffer failed (%s)", strerror(-err)); | 
|  | 2078 | if (err == NO_ERROR) { | 
|  | 2079 | sp<GraphicBuffer> backBuffer(GraphicBuffer::getSelf(out)); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2080 | const Rect bounds(backBuffer->width, backBuffer->height); | 
|  | 2081 |  | 
|  | 2082 | Region newDirtyRegion; | 
|  | 2083 | if (inOutDirtyBounds) { | 
|  | 2084 | newDirtyRegion.set(static_cast<Rect const&>(*inOutDirtyBounds)); | 
|  | 2085 | newDirtyRegion.andSelf(bounds); | 
|  | 2086 | } else { | 
|  | 2087 | newDirtyRegion.set(bounds); | 
|  | 2088 | } | 
|  | 2089 |  | 
|  | 2090 | // figure out if we can copy the frontbuffer back | 
|  | 2091 | const sp<GraphicBuffer>& frontBuffer(mPostedBuffer); | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 2092 | const bool canCopyBack = (frontBuffer != nullptr && | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2093 | backBuffer->width  == frontBuffer->width && | 
|  | 2094 | backBuffer->height == frontBuffer->height && | 
|  | 2095 | backBuffer->format == frontBuffer->format); | 
|  | 2096 |  | 
|  | 2097 | if (canCopyBack) { | 
|  | 2098 | // copy the area that is invalid and not repainted this round | 
|  | 2099 | const Region copyback(mDirtyRegion.subtract(newDirtyRegion)); | 
| Francis Hart | dc10f84 | 2014-12-01 16:04:49 +0200 | [diff] [blame] | 2100 | if (!copyback.isEmpty()) { | 
| Francis Hart | 7b09e79 | 2015-01-09 11:10:54 +0200 | [diff] [blame] | 2101 | copyBlt(backBuffer, frontBuffer, copyback, &fenceFd); | 
| Francis Hart | dc10f84 | 2014-12-01 16:04:49 +0200 | [diff] [blame] | 2102 | } | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2103 | } else { | 
|  | 2104 | // if we can't copy-back anything, modify the user's dirty | 
|  | 2105 | // region to make sure they redraw the whole buffer | 
|  | 2106 | newDirtyRegion.set(bounds); | 
|  | 2107 | mDirtyRegion.clear(); | 
|  | 2108 | Mutex::Autolock lock(mMutex); | 
|  | 2109 | for (size_t i=0 ; i<NUM_BUFFER_SLOTS ; i++) { | 
|  | 2110 | mSlots[i].dirtyRegion.clear(); | 
|  | 2111 | } | 
|  | 2112 | } | 
|  | 2113 |  | 
|  | 2114 |  | 
|  | 2115 | { // scope for the lock | 
|  | 2116 | Mutex::Autolock lock(mMutex); | 
|  | 2117 | int backBufferSlot(getSlotFromBufferLocked(backBuffer.get())); | 
|  | 2118 | if (backBufferSlot >= 0) { | 
|  | 2119 | Region& dirtyRegion(mSlots[backBufferSlot].dirtyRegion); | 
|  | 2120 | mDirtyRegion.subtract(dirtyRegion); | 
|  | 2121 | dirtyRegion = newDirtyRegion; | 
|  | 2122 | } | 
|  | 2123 | } | 
|  | 2124 |  | 
|  | 2125 | mDirtyRegion.orSelf(newDirtyRegion); | 
|  | 2126 | if (inOutDirtyBounds) { | 
|  | 2127 | *inOutDirtyBounds = newDirtyRegion.getBounds(); | 
|  | 2128 | } | 
|  | 2129 |  | 
|  | 2130 | void* vaddr; | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 2131 | status_t res = backBuffer->lockAsync( | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2132 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 2133 | newDirtyRegion.bounds(), &vaddr, fenceFd); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2134 |  | 
|  | 2135 | ALOGW_IF(res, "failed locking buffer (handle = %p)", | 
|  | 2136 | backBuffer->handle); | 
|  | 2137 |  | 
|  | 2138 | if (res != 0) { | 
|  | 2139 | err = INVALID_OPERATION; | 
|  | 2140 | } else { | 
|  | 2141 | mLockedBuffer = backBuffer; | 
|  | 2142 | outBuffer->width  = backBuffer->width; | 
|  | 2143 | outBuffer->height = backBuffer->height; | 
|  | 2144 | outBuffer->stride = backBuffer->stride; | 
|  | 2145 | outBuffer->format = backBuffer->format; | 
|  | 2146 | outBuffer->bits   = vaddr; | 
|  | 2147 | } | 
|  | 2148 | } | 
|  | 2149 | return err; | 
|  | 2150 | } | 
|  | 2151 |  | 
|  | 2152 | status_t Surface::unlockAndPost() | 
|  | 2153 | { | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 2154 | if (mLockedBuffer == nullptr) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2155 | ALOGE("Surface::unlockAndPost failed, no locked buffer"); | 
|  | 2156 | return INVALID_OPERATION; | 
|  | 2157 | } | 
|  | 2158 |  | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 2159 | int fd = -1; | 
|  | 2160 | status_t err = mLockedBuffer->unlockAsync(&fd); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2161 | ALOGE_IF(err, "failed unlocking buffer (%p)", mLockedBuffer->handle); | 
|  | 2162 |  | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 2163 | err = queueBuffer(mLockedBuffer.get(), fd); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2164 | ALOGE_IF(err, "queueBuffer (handle=%p) failed (%s)", | 
|  | 2165 | mLockedBuffer->handle, strerror(-err)); | 
|  | 2166 |  | 
|  | 2167 | mPostedBuffer = mLockedBuffer; | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 2168 | mLockedBuffer = nullptr; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2169 | return err; | 
|  | 2170 | } | 
|  | 2171 |  | 
| Robert Carr | 9f31e29 | 2016-04-11 11:15:32 -0700 | [diff] [blame] | 2172 | bool Surface::waitForNextFrame(uint64_t lastFrame, nsecs_t timeout) { | 
|  | 2173 | Mutex::Autolock lock(mMutex); | 
| Pablo Ceballos | bc8c192 | 2016-07-01 14:15:41 -0700 | [diff] [blame] | 2174 | if (mNextFrameNumber > lastFrame) { | 
| Robert Carr | 9f31e29 | 2016-04-11 11:15:32 -0700 | [diff] [blame] | 2175 | return true; | 
|  | 2176 | } | 
|  | 2177 | return mQueueBufferCondition.waitRelative(mMutex, timeout) == OK; | 
|  | 2178 | } | 
|  | 2179 |  | 
| Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 2180 | status_t Surface::getUniqueId(uint64_t* outId) const { | 
|  | 2181 | Mutex::Autolock lock(mMutex); | 
|  | 2182 | return mGraphicBufferProducer->getUniqueId(outId); | 
|  | 2183 | } | 
|  | 2184 |  | 
| Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 2185 | int Surface::getConsumerUsage(uint64_t* outUsage) const { | 
|  | 2186 | Mutex::Autolock lock(mMutex); | 
|  | 2187 | return mGraphicBufferProducer->getConsumerUsage(outUsage); | 
|  | 2188 | } | 
|  | 2189 |  | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 2190 | status_t Surface::getAndFlushRemovedBuffers(std::vector<sp<GraphicBuffer>>* out) { | 
|  | 2191 | if (out == nullptr) { | 
|  | 2192 | ALOGE("%s: out must not be null!", __FUNCTION__); | 
|  | 2193 | return BAD_VALUE; | 
|  | 2194 | } | 
|  | 2195 |  | 
|  | 2196 | Mutex::Autolock lock(mMutex); | 
|  | 2197 | *out = mRemovedBuffers; | 
|  | 2198 | mRemovedBuffers.clear(); | 
|  | 2199 | return OK; | 
|  | 2200 | } | 
|  | 2201 |  | 
| Peiyong Lin | 0f6a412 | 2019-06-25 17:25:02 -0700 | [diff] [blame] | 2202 | status_t Surface::attachAndQueueBufferWithDataspace(Surface* surface, sp<GraphicBuffer> buffer, | 
|  | 2203 | Dataspace dataspace) { | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 2204 | if (buffer == nullptr) { | 
|  | 2205 | return BAD_VALUE; | 
|  | 2206 | } | 
|  | 2207 | int err = static_cast<ANativeWindow*>(surface)->perform(surface, NATIVE_WINDOW_API_CONNECT, | 
|  | 2208 | NATIVE_WINDOW_API_CPU); | 
|  | 2209 | if (err != OK) { | 
|  | 2210 | return err; | 
|  | 2211 | } | 
| Peiyong Lin | 0f6a412 | 2019-06-25 17:25:02 -0700 | [diff] [blame] | 2212 | ui::Dataspace tmpDataspace = surface->getBuffersDataSpace(); | 
|  | 2213 | err = surface->setBuffersDataSpace(dataspace); | 
|  | 2214 | if (err != OK) { | 
|  | 2215 | return err; | 
|  | 2216 | } | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 2217 | err = surface->attachBuffer(buffer->getNativeBuffer()); | 
|  | 2218 | if (err != OK) { | 
|  | 2219 | return err; | 
|  | 2220 | } | 
|  | 2221 | err = static_cast<ANativeWindow*>(surface)->queueBuffer(surface, buffer->getNativeBuffer(), -1); | 
|  | 2222 | if (err != OK) { | 
|  | 2223 | return err; | 
|  | 2224 | } | 
| Peiyong Lin | 0f6a412 | 2019-06-25 17:25:02 -0700 | [diff] [blame] | 2225 | err = surface->setBuffersDataSpace(tmpDataspace); | 
|  | 2226 | if (err != OK) { | 
|  | 2227 | return err; | 
|  | 2228 | } | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 2229 | err = surface->disconnect(NATIVE_WINDOW_API_CPU); | 
|  | 2230 | return err; | 
|  | 2231 | } | 
|  | 2232 |  | 
| Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 2233 | int Surface::setAutoPrerotation(bool autoPrerotation) { | 
|  | 2234 | ATRACE_CALL(); | 
|  | 2235 | ALOGV("Surface::setAutoPrerotation (%d)", autoPrerotation); | 
|  | 2236 | Mutex::Autolock lock(mMutex); | 
|  | 2237 |  | 
|  | 2238 | if (mAutoPrerotation == autoPrerotation) { | 
|  | 2239 | return OK; | 
|  | 2240 | } | 
|  | 2241 |  | 
|  | 2242 | status_t err = mGraphicBufferProducer->setAutoPrerotation(autoPrerotation); | 
|  | 2243 | if (err == NO_ERROR) { | 
|  | 2244 | mAutoPrerotation = autoPrerotation; | 
|  | 2245 | } | 
|  | 2246 | ALOGE_IF(err, "IGraphicBufferProducer::setAutoPrerotation(%d) returned %s", autoPrerotation, | 
|  | 2247 | strerror(-err)); | 
|  | 2248 | return err; | 
|  | 2249 | } | 
|  | 2250 |  | 
| Shuzhen Wang | 067fcd3 | 2019-08-14 10:41:12 -0700 | [diff] [blame] | 2251 | void Surface::ProducerListenerProxy::onBuffersDiscarded(const std::vector<int32_t>& slots) { | 
|  | 2252 | ATRACE_CALL(); | 
|  | 2253 | sp<Surface> parent = mParent.promote(); | 
|  | 2254 | if (parent == nullptr) { | 
|  | 2255 | return; | 
|  | 2256 | } | 
|  | 2257 |  | 
|  | 2258 | std::vector<sp<GraphicBuffer>> discardedBufs; | 
|  | 2259 | status_t res = parent->getAndFlushBuffersFromSlots(slots, &discardedBufs); | 
|  | 2260 | if (res != OK) { | 
|  | 2261 | ALOGE("%s: Failed to get buffers from slots: %s(%d)", __FUNCTION__, | 
|  | 2262 | strerror(-res), res); | 
|  | 2263 | return; | 
|  | 2264 | } | 
|  | 2265 |  | 
|  | 2266 | mSurfaceListener->onBuffersDiscarded(discardedBufs); | 
|  | 2267 | } | 
|  | 2268 |  | 
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 2269 | status_t Surface::setFrameRate(float frameRate, int8_t compatibility) { | 
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 2270 | ATRACE_CALL(); | 
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 2271 | ALOGV("Surface::setFrameRate"); | 
|  | 2272 |  | 
|  | 2273 | if (!ValidateFrameRate(frameRate, compatibility, "Surface::setFrameRate")) { | 
|  | 2274 | return BAD_VALUE; | 
|  | 2275 | } | 
|  | 2276 |  | 
|  | 2277 | return composerService()->setFrameRate(mGraphicBufferProducer, frameRate, compatibility); | 
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 2278 | } | 
|  | 2279 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2280 | }; // namespace android |