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