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