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 | b0e76f4 | 2012-03-23 14:15:44 -0700 | [diff] [blame] | 21 | #include <android/native_window.h> |
| 22 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 23 | #include <binder/Parcel.h> |
| 24 | |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 25 | #include <utils/Log.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 26 | #include <utils/Trace.h> |
Rachad | 7cb0d39 | 2014-07-29 17:53:53 -0700 | [diff] [blame] | 27 | #include <utils/NativeHandle.h> |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 28 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 29 | #include <ui/Fence.h> |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 30 | #include <ui/Region.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 31 | |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 32 | #include <gui/IProducerListener.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 33 | #include <gui/ISurfaceComposer.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 34 | #include <gui/SurfaceComposerClient.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 35 | #include <gui/GLConsumer.h> |
| 36 | #include <gui/Surface.h> |
| 37 | |
| 38 | #include <private/gui/ComposerService.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 39 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | namespace android { |
| 41 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 42 | Surface::Surface( |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 43 | const sp<IGraphicBufferProducer>& bufferProducer, |
| 44 | bool controlledByApp) |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 45 | : mGraphicBufferProducer(bufferProducer), |
Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 46 | mCrop(Rect::EMPTY_RECT), |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 47 | mGenerationNumber(0), |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 48 | mSharedBufferMode(false), |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 49 | mAutoRefresh(false), |
| 50 | mSharedBufferSlot(BufferItem::INVALID_BUFFER_SLOT), |
| 51 | mSharedBufferHasBeenQueued(false) |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 52 | { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 53 | // Initialize the ANativeWindow function pointers. |
| 54 | ANativeWindow::setSwapInterval = hook_setSwapInterval; |
| 55 | ANativeWindow::dequeueBuffer = hook_dequeueBuffer; |
| 56 | ANativeWindow::cancelBuffer = hook_cancelBuffer; |
| 57 | ANativeWindow::queueBuffer = hook_queueBuffer; |
| 58 | ANativeWindow::query = hook_query; |
| 59 | ANativeWindow::perform = hook_perform; |
| 60 | |
| 61 | ANativeWindow::dequeueBuffer_DEPRECATED = hook_dequeueBuffer_DEPRECATED; |
| 62 | ANativeWindow::cancelBuffer_DEPRECATED = hook_cancelBuffer_DEPRECATED; |
| 63 | ANativeWindow::lockBuffer_DEPRECATED = hook_lockBuffer_DEPRECATED; |
| 64 | ANativeWindow::queueBuffer_DEPRECATED = hook_queueBuffer_DEPRECATED; |
| 65 | |
| 66 | const_cast<int&>(ANativeWindow::minSwapInterval) = 0; |
| 67 | const_cast<int&>(ANativeWindow::maxSwapInterval) = 1; |
| 68 | |
| 69 | mReqWidth = 0; |
| 70 | mReqHeight = 0; |
| 71 | mReqFormat = 0; |
| 72 | mReqUsage = 0; |
| 73 | mTimestamp = NATIVE_WINDOW_TIMESTAMP_AUTO; |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 74 | mDataSpace = HAL_DATASPACE_UNKNOWN; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 75 | mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE; |
| 76 | mTransform = 0; |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 77 | mStickyTransform = 0; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 78 | mDefaultWidth = 0; |
| 79 | mDefaultHeight = 0; |
| 80 | mUserWidth = 0; |
| 81 | mUserHeight = 0; |
| 82 | mTransformHint = 0; |
| 83 | mConsumerRunningBehind = false; |
| 84 | mConnectedToCpu = false; |
Eino-Ville Talvala | 7895e90 | 2013-08-21 11:53:37 -0700 | [diff] [blame] | 85 | mProducerControlledByApp = controlledByApp; |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 86 | mSwapIntervalZero = false; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Mathias Agopian | 35ffa6a | 2013-03-12 18:45:09 -0700 | [diff] [blame] | 89 | Surface::~Surface() { |
| 90 | if (mConnectedToCpu) { |
| 91 | Surface::disconnect(NATIVE_WINDOW_API_CPU); |
| 92 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | sp<IGraphicBufferProducer> Surface::getIGraphicBufferProducer() const { |
| 96 | return mGraphicBufferProducer; |
| 97 | } |
| 98 | |
Wonsik Kim | 0ee14ca | 2014-03-17 17:46:53 +0900 | [diff] [blame] | 99 | void Surface::setSidebandStream(const sp<NativeHandle>& stream) { |
| 100 | mGraphicBufferProducer->setSidebandStream(stream); |
| 101 | } |
| 102 | |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 103 | void Surface::allocateBuffers() { |
| 104 | uint32_t reqWidth = mReqWidth ? mReqWidth : mUserWidth; |
| 105 | uint32_t reqHeight = mReqHeight ? mReqHeight : mUserHeight; |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 106 | mGraphicBufferProducer->allocateBuffers(reqWidth, reqHeight, |
| 107 | mReqFormat, mReqUsage); |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 110 | status_t Surface::setGenerationNumber(uint32_t generation) { |
| 111 | status_t result = mGraphicBufferProducer->setGenerationNumber(generation); |
| 112 | if (result == NO_ERROR) { |
| 113 | mGenerationNumber = generation; |
| 114 | } |
| 115 | return result; |
| 116 | } |
| 117 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 118 | uint64_t Surface::getNextFrameNumber() const { |
| 119 | return mGraphicBufferProducer->getNextFrameNumber(); |
| 120 | } |
| 121 | |
Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 122 | String8 Surface::getConsumerName() const { |
| 123 | return mGraphicBufferProducer->getConsumerName(); |
| 124 | } |
| 125 | |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 126 | status_t Surface::setDequeueTimeout(nsecs_t timeout) { |
| 127 | return mGraphicBufferProducer->setDequeueTimeout(timeout); |
| 128 | } |
| 129 | |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 130 | status_t Surface::getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, |
John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame^] | 131 | sp<Fence>* outFence, float outTransformMatrix[16]) { |
| 132 | return mGraphicBufferProducer->getLastQueuedBuffer(outBuffer, outFence, |
| 133 | outTransformMatrix); |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 136 | int Surface::hook_setSwapInterval(ANativeWindow* window, int interval) { |
| 137 | Surface* c = getSelf(window); |
| 138 | return c->setSwapInterval(interval); |
| 139 | } |
| 140 | |
| 141 | int Surface::hook_dequeueBuffer(ANativeWindow* window, |
| 142 | ANativeWindowBuffer** buffer, int* fenceFd) { |
| 143 | Surface* c = getSelf(window); |
| 144 | return c->dequeueBuffer(buffer, fenceFd); |
| 145 | } |
| 146 | |
| 147 | int Surface::hook_cancelBuffer(ANativeWindow* window, |
| 148 | ANativeWindowBuffer* buffer, int fenceFd) { |
| 149 | Surface* c = getSelf(window); |
| 150 | return c->cancelBuffer(buffer, fenceFd); |
| 151 | } |
| 152 | |
| 153 | int Surface::hook_queueBuffer(ANativeWindow* window, |
| 154 | ANativeWindowBuffer* buffer, int fenceFd) { |
| 155 | Surface* c = getSelf(window); |
| 156 | return c->queueBuffer(buffer, fenceFd); |
| 157 | } |
| 158 | |
| 159 | int Surface::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window, |
| 160 | ANativeWindowBuffer** buffer) { |
| 161 | Surface* c = getSelf(window); |
| 162 | ANativeWindowBuffer* buf; |
| 163 | int fenceFd = -1; |
| 164 | int result = c->dequeueBuffer(&buf, &fenceFd); |
| 165 | sp<Fence> fence(new Fence(fenceFd)); |
Mathias Agopian | ea74d3b | 2013-05-16 18:03:22 -0700 | [diff] [blame] | 166 | int waitResult = fence->waitForever("dequeueBuffer_DEPRECATED"); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 167 | if (waitResult != OK) { |
| 168 | ALOGE("dequeueBuffer_DEPRECATED: Fence::wait returned an error: %d", |
| 169 | waitResult); |
| 170 | c->cancelBuffer(buf, -1); |
| 171 | return waitResult; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 172 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 173 | *buffer = buf; |
| 174 | return result; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 177 | int Surface::hook_cancelBuffer_DEPRECATED(ANativeWindow* window, |
| 178 | ANativeWindowBuffer* buffer) { |
| 179 | Surface* c = getSelf(window); |
| 180 | return c->cancelBuffer(buffer, -1); |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 183 | int Surface::hook_lockBuffer_DEPRECATED(ANativeWindow* window, |
| 184 | ANativeWindowBuffer* buffer) { |
| 185 | Surface* c = getSelf(window); |
| 186 | return c->lockBuffer_DEPRECATED(buffer); |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 189 | int Surface::hook_queueBuffer_DEPRECATED(ANativeWindow* window, |
| 190 | ANativeWindowBuffer* buffer) { |
| 191 | Surface* c = getSelf(window); |
| 192 | return c->queueBuffer(buffer, -1); |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 193 | } |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 194 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 195 | int Surface::hook_query(const ANativeWindow* window, |
| 196 | int what, int* value) { |
| 197 | const Surface* c = getSelf(window); |
| 198 | return c->query(what, value); |
| 199 | } |
| 200 | |
| 201 | int Surface::hook_perform(ANativeWindow* window, int operation, ...) { |
| 202 | va_list args; |
| 203 | va_start(args, operation); |
| 204 | Surface* c = getSelf(window); |
Haixia Shi | d89c2bb | 2015-09-14 11:02:18 -0700 | [diff] [blame] | 205 | int result = c->perform(operation, args); |
| 206 | va_end(args); |
| 207 | return result; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | int Surface::setSwapInterval(int interval) { |
| 211 | ATRACE_CALL(); |
| 212 | // EGL specification states: |
| 213 | // interval is silently clamped to minimum and maximum implementation |
| 214 | // dependent values before being stored. |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 215 | |
| 216 | if (interval < minSwapInterval) |
| 217 | interval = minSwapInterval; |
| 218 | |
| 219 | if (interval > maxSwapInterval) |
| 220 | interval = maxSwapInterval; |
| 221 | |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 222 | mSwapIntervalZero = (interval == 0); |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 223 | mGraphicBufferProducer->setAsyncMode(mSwapIntervalZero); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 224 | |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 225 | return NO_ERROR; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 228 | int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 229 | ATRACE_CALL(); |
| 230 | ALOGV("Surface::dequeueBuffer"); |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 231 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 232 | uint32_t reqWidth; |
| 233 | uint32_t reqHeight; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 234 | PixelFormat reqFormat; |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 235 | uint32_t reqUsage; |
| 236 | |
| 237 | { |
| 238 | Mutex::Autolock lock(mMutex); |
| 239 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 240 | reqWidth = mReqWidth ? mReqWidth : mUserWidth; |
| 241 | reqHeight = mReqHeight ? mReqHeight : mUserHeight; |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 242 | |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 243 | reqFormat = mReqFormat; |
| 244 | reqUsage = mReqUsage; |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 245 | |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 246 | if (mSharedBufferMode && mAutoRefresh && mSharedBufferSlot != |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 247 | BufferItem::INVALID_BUFFER_SLOT) { |
| 248 | sp<GraphicBuffer>& gbuf(mSlots[mSharedBufferSlot].buffer); |
| 249 | if (gbuf != NULL) { |
| 250 | *buffer = gbuf.get(); |
| 251 | *fenceFd = -1; |
| 252 | return OK; |
| 253 | } |
| 254 | } |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 255 | } // Drop the lock so that we can still touch the Surface while blocking in IGBP::dequeueBuffer |
| 256 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 257 | int buf = -1; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 258 | sp<Fence> fence; |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 259 | status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence, |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 260 | reqWidth, reqHeight, reqFormat, reqUsage); |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 261 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 262 | if (result < 0) { |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 263 | ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer" |
| 264 | "(%d, %d, %d, %d) failed: %d", reqWidth, reqHeight, reqFormat, |
| 265 | reqUsage, result); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 266 | return result; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 267 | } |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 268 | |
| 269 | Mutex::Autolock lock(mMutex); |
| 270 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 271 | sp<GraphicBuffer>& gbuf(mSlots[buf].buffer); |
Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 272 | |
| 273 | // this should never happen |
| 274 | ALOGE_IF(fence == NULL, "Surface::dequeueBuffer: received null Fence! buf=%d", buf); |
| 275 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 276 | if (result & IGraphicBufferProducer::RELEASE_ALL_BUFFERS) { |
| 277 | freeAllBuffers(); |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 278 | } |
Ted Bonkenburg | bd050ab | 2011-07-15 15:10:10 -0700 | [diff] [blame] | 279 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 280 | if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) { |
| 281 | result = mGraphicBufferProducer->requestBuffer(buf, &gbuf); |
| 282 | if (result != NO_ERROR) { |
Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 283 | ALOGE("dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: %d", result); |
Jesse Hall | 9f5a1b6 | 2014-10-02 11:09:03 -0700 | [diff] [blame] | 284 | mGraphicBufferProducer->cancelBuffer(buf, fence); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 285 | return result; |
| 286 | } |
| 287 | } |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 288 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 289 | if (fence->isValid()) { |
| 290 | *fenceFd = fence->dup(); |
| 291 | if (*fenceFd == -1) { |
| 292 | ALOGE("dequeueBuffer: error duping fence: %d", errno); |
| 293 | // dup() should never fail; something is badly wrong. Soldier on |
| 294 | // and hope for the best; the worst that should happen is some |
| 295 | // visible corruption that lasts until the next frame. |
| 296 | } |
Ted Bonkenburg | e5d6eb8 | 2011-08-09 22:38:41 -0700 | [diff] [blame] | 297 | } else { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 298 | *fenceFd = -1; |
Mathias Agopian | a0c30e9 | 2010-06-04 18:26:32 -0700 | [diff] [blame] | 299 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 300 | |
| 301 | *buffer = gbuf.get(); |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 302 | |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 303 | if (mSharedBufferMode && mAutoRefresh) { |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 304 | mSharedBufferSlot = buf; |
| 305 | mSharedBufferHasBeenQueued = false; |
| 306 | } else if (mSharedBufferSlot == buf) { |
| 307 | mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT; |
| 308 | mSharedBufferHasBeenQueued = false; |
| 309 | } |
| 310 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 311 | return OK; |
Jamie Gennis | aca4e22 | 2010-07-15 17:29:15 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 314 | int Surface::cancelBuffer(android_native_buffer_t* buffer, |
| 315 | int fenceFd) { |
| 316 | ATRACE_CALL(); |
| 317 | ALOGV("Surface::cancelBuffer"); |
| 318 | Mutex::Autolock lock(mMutex); |
| 319 | int i = getSlotFromBufferLocked(buffer); |
| 320 | if (i < 0) { |
Taiju Tsuiki | 4d0cd3f | 2015-04-30 22:15:33 +0900 | [diff] [blame] | 321 | if (fenceFd >= 0) { |
| 322 | close(fenceFd); |
| 323 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 324 | return i; |
| 325 | } |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 326 | if (mSharedBufferSlot == i && mSharedBufferHasBeenQueued) { |
| 327 | if (fenceFd >= 0) { |
| 328 | close(fenceFd); |
| 329 | } |
| 330 | return OK; |
| 331 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 332 | sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); |
| 333 | mGraphicBufferProducer->cancelBuffer(i, fence); |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 334 | |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 335 | if (mSharedBufferMode && mAutoRefresh && mSharedBufferSlot == i) { |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 336 | mSharedBufferHasBeenQueued = true; |
| 337 | } |
| 338 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 339 | return OK; |
| 340 | } |
| 341 | |
| 342 | int Surface::getSlotFromBufferLocked( |
| 343 | android_native_buffer_t* buffer) const { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 344 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
| 345 | if (mSlots[i].buffer != NULL && |
| 346 | mSlots[i].buffer->handle == buffer->handle) { |
| 347 | return i; |
Jamie Gennis | aca4e22 | 2010-07-15 17:29:15 -0700 | [diff] [blame] | 348 | } |
| 349 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 350 | ALOGE("getSlotFromBufferLocked: unknown buffer: %p", buffer->handle); |
| 351 | return BAD_VALUE; |
Mathias Agopian | a0c30e9 | 2010-06-04 18:26:32 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 354 | int Surface::lockBuffer_DEPRECATED(android_native_buffer_t* buffer __attribute__((unused))) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 355 | ALOGV("Surface::lockBuffer"); |
| 356 | Mutex::Autolock lock(mMutex); |
| 357 | return OK; |
| 358 | } |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 359 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 360 | int Surface::queueBuffer(android_native_buffer_t* buffer, int fenceFd) { |
| 361 | ATRACE_CALL(); |
| 362 | ALOGV("Surface::queueBuffer"); |
| 363 | Mutex::Autolock lock(mMutex); |
| 364 | int64_t timestamp; |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 365 | bool isAutoTimestamp = false; |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 366 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 367 | if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) { |
Andy McFadden | 4b49e08 | 2013-08-02 15:31:45 -0700 | [diff] [blame] | 368 | timestamp = systemTime(SYSTEM_TIME_MONOTONIC); |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 369 | isAutoTimestamp = true; |
Andy McFadden | 4b49e08 | 2013-08-02 15:31:45 -0700 | [diff] [blame] | 370 | ALOGV("Surface::queueBuffer making up timestamp: %.2f ms", |
| 371 | timestamp / 1000000.f); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 372 | } else { |
| 373 | timestamp = mTimestamp; |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 374 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 375 | int i = getSlotFromBufferLocked(buffer); |
| 376 | if (i < 0) { |
Taiju Tsuiki | 4d0cd3f | 2015-04-30 22:15:33 +0900 | [diff] [blame] | 377 | if (fenceFd >= 0) { |
| 378 | close(fenceFd); |
| 379 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 380 | return i; |
| 381 | } |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 382 | if (mSharedBufferSlot == i && mSharedBufferHasBeenQueued) { |
| 383 | if (fenceFd >= 0) { |
| 384 | close(fenceFd); |
| 385 | } |
| 386 | return OK; |
| 387 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 390 | // Make sure the crop rectangle is entirely inside the buffer. |
Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 391 | Rect crop(Rect::EMPTY_RECT); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 392 | mCrop.intersect(Rect(buffer->width, buffer->height), &crop); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 394 | sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); |
| 395 | IGraphicBufferProducer::QueueBufferOutput output; |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 396 | IGraphicBufferProducer::QueueBufferInput input(timestamp, isAutoTimestamp, |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 397 | mDataSpace, crop, mScalingMode, mTransform ^ mStickyTransform, |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 398 | fence, mStickyTransform); |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 399 | |
Dan Stoza | c62acbd | 2015-04-21 16:42:49 -0700 | [diff] [blame] | 400 | if (mConnectedToCpu || mDirtyRegion.bounds() == Rect::INVALID_RECT) { |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 401 | input.setSurfaceDamage(Region::INVALID_REGION); |
| 402 | } else { |
Dan Stoza | db4850c | 2015-06-25 16:10:18 -0700 | [diff] [blame] | 403 | // Here we do two things: |
| 404 | // 1) The surface damage was specified using the OpenGL ES convention of |
| 405 | // the origin being in the bottom-left corner. Here we flip to the |
| 406 | // convention that the rest of the system uses (top-left corner) by |
| 407 | // subtracting all top/bottom coordinates from the buffer height. |
| 408 | // 2) If the buffer is coming in rotated (for example, because the EGL |
| 409 | // implementation is reacting to the transform hint coming back from |
| 410 | // SurfaceFlinger), the surface damage needs to be rotated the |
| 411 | // opposite direction, since it was generated assuming an unrotated |
| 412 | // buffer (the app doesn't know that the EGL implementation is |
| 413 | // reacting to the transform hint behind its back). The |
| 414 | // transformations in the switch statement below apply those |
| 415 | // complementary rotations (e.g., if 90 degrees, rotate 270 degrees). |
| 416 | |
| 417 | int width = buffer->width; |
Dan Stoza | 0e65e6c | 2015-05-26 13:22:27 -0700 | [diff] [blame] | 418 | int height = buffer->height; |
Dan Stoza | db4850c | 2015-06-25 16:10:18 -0700 | [diff] [blame] | 419 | bool rotated90 = (mTransform ^ mStickyTransform) & |
| 420 | NATIVE_WINDOW_TRANSFORM_ROT_90; |
| 421 | if (rotated90) { |
| 422 | std::swap(width, height); |
Dan Stoza | 0e65e6c | 2015-05-26 13:22:27 -0700 | [diff] [blame] | 423 | } |
Dan Stoza | db4850c | 2015-06-25 16:10:18 -0700 | [diff] [blame] | 424 | |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 425 | Region flippedRegion; |
| 426 | for (auto rect : mDirtyRegion) { |
Dan Stoza | db4850c | 2015-06-25 16:10:18 -0700 | [diff] [blame] | 427 | int left = rect.left; |
| 428 | int right = rect.right; |
| 429 | int top = height - rect.bottom; // Flip from OpenGL convention |
| 430 | int bottom = height - rect.top; // Flip from OpenGL convention |
| 431 | switch (mTransform ^ mStickyTransform) { |
| 432 | case NATIVE_WINDOW_TRANSFORM_ROT_90: { |
| 433 | // Rotate 270 degrees |
| 434 | Rect flippedRect{top, width - right, bottom, width - left}; |
| 435 | flippedRegion.orSelf(flippedRect); |
| 436 | break; |
| 437 | } |
| 438 | case NATIVE_WINDOW_TRANSFORM_ROT_180: { |
| 439 | // Rotate 180 degrees |
| 440 | Rect flippedRect{width - right, height - bottom, |
| 441 | width - left, height - top}; |
| 442 | flippedRegion.orSelf(flippedRect); |
| 443 | break; |
| 444 | } |
| 445 | case NATIVE_WINDOW_TRANSFORM_ROT_270: { |
| 446 | // Rotate 90 degrees |
| 447 | Rect flippedRect{height - bottom, left, |
| 448 | height - top, right}; |
| 449 | flippedRegion.orSelf(flippedRect); |
| 450 | break; |
| 451 | } |
| 452 | default: { |
| 453 | Rect flippedRect{left, top, right, bottom}; |
| 454 | flippedRegion.orSelf(flippedRect); |
| 455 | break; |
| 456 | } |
| 457 | } |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | input.setSurfaceDamage(flippedRegion); |
| 461 | } |
| 462 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 463 | status_t err = mGraphicBufferProducer->queueBuffer(i, input, &output); |
| 464 | if (err != OK) { |
| 465 | ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err); |
| 466 | } |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 467 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 468 | uint32_t numPendingBuffers = 0; |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 469 | uint32_t hint = 0; |
| 470 | output.deflate(&mDefaultWidth, &mDefaultHeight, &hint, |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 471 | &numPendingBuffers); |
tedbo | 1e7fa9e | 2011-06-22 15:52:53 -0700 | [diff] [blame] | 472 | |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 473 | // Disable transform hint if sticky transform is set. |
| 474 | if (mStickyTransform == 0) { |
| 475 | mTransformHint = hint; |
| 476 | } |
| 477 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 478 | mConsumerRunningBehind = (numPendingBuffers >= 2); |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 479 | |
Dan Stoza | c62acbd | 2015-04-21 16:42:49 -0700 | [diff] [blame] | 480 | if (!mConnectedToCpu) { |
| 481 | // Clear surface damage back to full-buffer |
| 482 | mDirtyRegion = Region::INVALID_REGION; |
| 483 | } |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 484 | |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 485 | if (mSharedBufferMode && mAutoRefresh && mSharedBufferSlot == i) { |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 486 | mSharedBufferHasBeenQueued = true; |
| 487 | } |
| 488 | |
Robert Carr | 9f31e29 | 2016-04-11 11:15:32 -0700 | [diff] [blame] | 489 | mQueueBufferCondition.broadcast(); |
| 490 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 491 | return err; |
| 492 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 493 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 494 | int Surface::query(int what, int* value) const { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 495 | ATRACE_CALL(); |
| 496 | ALOGV("Surface::query"); |
| 497 | { // scope for the lock |
| 498 | Mutex::Autolock lock(mMutex); |
| 499 | switch (what) { |
| 500 | case NATIVE_WINDOW_FORMAT: |
| 501 | if (mReqFormat) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 502 | *value = static_cast<int>(mReqFormat); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 503 | return NO_ERROR; |
| 504 | } |
| 505 | break; |
| 506 | case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: { |
| 507 | sp<ISurfaceComposer> composer( |
| 508 | ComposerService::getComposerService()); |
| 509 | if (composer->authenticateSurfaceTexture(mGraphicBufferProducer)) { |
| 510 | *value = 1; |
| 511 | } else { |
| 512 | *value = 0; |
| 513 | } |
| 514 | return NO_ERROR; |
| 515 | } |
| 516 | case NATIVE_WINDOW_CONCRETE_TYPE: |
| 517 | *value = NATIVE_WINDOW_SURFACE; |
| 518 | return NO_ERROR; |
| 519 | case NATIVE_WINDOW_DEFAULT_WIDTH: |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 520 | *value = static_cast<int>( |
| 521 | mUserWidth ? mUserWidth : mDefaultWidth); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 522 | return NO_ERROR; |
| 523 | case NATIVE_WINDOW_DEFAULT_HEIGHT: |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 524 | *value = static_cast<int>( |
| 525 | mUserHeight ? mUserHeight : mDefaultHeight); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 526 | return NO_ERROR; |
| 527 | case NATIVE_WINDOW_TRANSFORM_HINT: |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 528 | *value = static_cast<int>(mTransformHint); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 529 | return NO_ERROR; |
| 530 | case NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND: { |
| 531 | status_t err = NO_ERROR; |
| 532 | if (!mConsumerRunningBehind) { |
| 533 | *value = 0; |
| 534 | } else { |
| 535 | err = mGraphicBufferProducer->query(what, value); |
| 536 | if (err == NO_ERROR) { |
| 537 | mConsumerRunningBehind = *value; |
| 538 | } |
| 539 | } |
| 540 | return err; |
| 541 | } |
| 542 | } |
Jamie Gennis | 391bbe2 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 543 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 544 | return mGraphicBufferProducer->query(what, value); |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 547 | int Surface::perform(int operation, va_list args) |
| 548 | { |
| 549 | int res = NO_ERROR; |
| 550 | switch (operation) { |
| 551 | case NATIVE_WINDOW_CONNECT: |
| 552 | // deprecated. must return NO_ERROR. |
| 553 | break; |
| 554 | case NATIVE_WINDOW_DISCONNECT: |
| 555 | // deprecated. must return NO_ERROR. |
| 556 | break; |
| 557 | case NATIVE_WINDOW_SET_USAGE: |
| 558 | res = dispatchSetUsage(args); |
| 559 | break; |
| 560 | case NATIVE_WINDOW_SET_CROP: |
| 561 | res = dispatchSetCrop(args); |
| 562 | break; |
| 563 | case NATIVE_WINDOW_SET_BUFFER_COUNT: |
| 564 | res = dispatchSetBufferCount(args); |
| 565 | break; |
| 566 | case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY: |
| 567 | res = dispatchSetBuffersGeometry(args); |
| 568 | break; |
| 569 | case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM: |
| 570 | res = dispatchSetBuffersTransform(args); |
| 571 | break; |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 572 | case NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM: |
| 573 | res = dispatchSetBuffersStickyTransform(args); |
| 574 | break; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 575 | case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP: |
| 576 | res = dispatchSetBuffersTimestamp(args); |
| 577 | break; |
| 578 | case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS: |
| 579 | res = dispatchSetBuffersDimensions(args); |
| 580 | break; |
| 581 | case NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS: |
| 582 | res = dispatchSetBuffersUserDimensions(args); |
| 583 | break; |
| 584 | case NATIVE_WINDOW_SET_BUFFERS_FORMAT: |
| 585 | res = dispatchSetBuffersFormat(args); |
| 586 | break; |
| 587 | case NATIVE_WINDOW_LOCK: |
| 588 | res = dispatchLock(args); |
| 589 | break; |
| 590 | case NATIVE_WINDOW_UNLOCK_AND_POST: |
| 591 | res = dispatchUnlockAndPost(args); |
| 592 | break; |
| 593 | case NATIVE_WINDOW_SET_SCALING_MODE: |
| 594 | res = dispatchSetScalingMode(args); |
| 595 | break; |
| 596 | case NATIVE_WINDOW_API_CONNECT: |
| 597 | res = dispatchConnect(args); |
| 598 | break; |
| 599 | case NATIVE_WINDOW_API_DISCONNECT: |
| 600 | res = dispatchDisconnect(args); |
| 601 | break; |
Rachad | 7cb0d39 | 2014-07-29 17:53:53 -0700 | [diff] [blame] | 602 | case NATIVE_WINDOW_SET_SIDEBAND_STREAM: |
| 603 | res = dispatchSetSidebandStream(args); |
| 604 | break; |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 605 | case NATIVE_WINDOW_SET_BUFFERS_DATASPACE: |
| 606 | res = dispatchSetBuffersDataSpace(args); |
| 607 | break; |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 608 | case NATIVE_WINDOW_SET_SURFACE_DAMAGE: |
| 609 | res = dispatchSetSurfaceDamage(args); |
| 610 | break; |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 611 | case NATIVE_WINDOW_SET_SHARED_BUFFER_MODE: |
| 612 | res = dispatchSetSharedBufferMode(args); |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 613 | break; |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 614 | case NATIVE_WINDOW_SET_AUTO_REFRESH: |
| 615 | res = dispatchSetAutoRefresh(args); |
| 616 | break; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 617 | default: |
| 618 | res = NAME_NOT_FOUND; |
| 619 | break; |
| 620 | } |
| 621 | return res; |
| 622 | } |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 623 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 624 | int Surface::dispatchConnect(va_list args) { |
| 625 | int api = va_arg(args, int); |
| 626 | return connect(api); |
| 627 | } |
Mathias Agopian | 55fa251 | 2010-03-11 15:06:54 -0800 | [diff] [blame] | 628 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 629 | int Surface::dispatchDisconnect(va_list args) { |
| 630 | int api = va_arg(args, int); |
| 631 | return disconnect(api); |
| 632 | } |
| 633 | |
| 634 | int Surface::dispatchSetUsage(va_list args) { |
| 635 | int usage = va_arg(args, int); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 636 | return setUsage(static_cast<uint32_t>(usage)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | int Surface::dispatchSetCrop(va_list args) { |
| 640 | android_native_rect_t const* rect = va_arg(args, android_native_rect_t*); |
| 641 | return setCrop(reinterpret_cast<Rect const*>(rect)); |
| 642 | } |
| 643 | |
| 644 | int Surface::dispatchSetBufferCount(va_list args) { |
| 645 | size_t bufferCount = va_arg(args, size_t); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 646 | return setBufferCount(static_cast<int32_t>(bufferCount)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | int Surface::dispatchSetBuffersGeometry(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 650 | uint32_t width = va_arg(args, uint32_t); |
| 651 | uint32_t height = va_arg(args, uint32_t); |
| 652 | PixelFormat format = va_arg(args, PixelFormat); |
| 653 | int err = setBuffersDimensions(width, height); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 654 | if (err != 0) { |
| 655 | return err; |
| 656 | } |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 657 | return setBuffersFormat(format); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | int Surface::dispatchSetBuffersDimensions(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 661 | uint32_t width = va_arg(args, uint32_t); |
| 662 | uint32_t height = va_arg(args, uint32_t); |
| 663 | return setBuffersDimensions(width, height); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | int Surface::dispatchSetBuffersUserDimensions(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 667 | uint32_t width = va_arg(args, uint32_t); |
| 668 | uint32_t height = va_arg(args, uint32_t); |
| 669 | return setBuffersUserDimensions(width, height); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | int Surface::dispatchSetBuffersFormat(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 673 | PixelFormat format = va_arg(args, PixelFormat); |
| 674 | return setBuffersFormat(format); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | int Surface::dispatchSetScalingMode(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 678 | int mode = va_arg(args, int); |
| 679 | return setScalingMode(mode); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | int Surface::dispatchSetBuffersTransform(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 683 | uint32_t transform = va_arg(args, uint32_t); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 684 | return setBuffersTransform(transform); |
| 685 | } |
| 686 | |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 687 | int Surface::dispatchSetBuffersStickyTransform(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 688 | uint32_t transform = va_arg(args, uint32_t); |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 689 | return setBuffersStickyTransform(transform); |
| 690 | } |
| 691 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 692 | int Surface::dispatchSetBuffersTimestamp(va_list args) { |
| 693 | int64_t timestamp = va_arg(args, int64_t); |
| 694 | return setBuffersTimestamp(timestamp); |
| 695 | } |
| 696 | |
| 697 | int Surface::dispatchLock(va_list args) { |
| 698 | ANativeWindow_Buffer* outBuffer = va_arg(args, ANativeWindow_Buffer*); |
| 699 | ARect* inOutDirtyBounds = va_arg(args, ARect*); |
| 700 | return lock(outBuffer, inOutDirtyBounds); |
| 701 | } |
| 702 | |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 703 | int Surface::dispatchUnlockAndPost(va_list args __attribute__((unused))) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 704 | return unlockAndPost(); |
| 705 | } |
| 706 | |
Rachad | 7cb0d39 | 2014-07-29 17:53:53 -0700 | [diff] [blame] | 707 | int Surface::dispatchSetSidebandStream(va_list args) { |
| 708 | native_handle_t* sH = va_arg(args, native_handle_t*); |
| 709 | sp<NativeHandle> sidebandHandle = NativeHandle::create(sH, false); |
| 710 | setSidebandStream(sidebandHandle); |
| 711 | return OK; |
| 712 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 713 | |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 714 | int Surface::dispatchSetBuffersDataSpace(va_list args) { |
| 715 | android_dataspace dataspace = |
| 716 | static_cast<android_dataspace>(va_arg(args, int)); |
| 717 | return setBuffersDataSpace(dataspace); |
| 718 | } |
| 719 | |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 720 | int Surface::dispatchSetSurfaceDamage(va_list args) { |
| 721 | android_native_rect_t* rects = va_arg(args, android_native_rect_t*); |
| 722 | size_t numRects = va_arg(args, size_t); |
| 723 | setSurfaceDamage(rects, numRects); |
| 724 | return NO_ERROR; |
| 725 | } |
| 726 | |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 727 | int Surface::dispatchSetSharedBufferMode(va_list args) { |
| 728 | bool sharedBufferMode = va_arg(args, int); |
| 729 | return setSharedBufferMode(sharedBufferMode); |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | int Surface::dispatchSetAutoRefresh(va_list args) { |
| 733 | bool autoRefresh = va_arg(args, int); |
| 734 | return setAutoRefresh(autoRefresh); |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 737 | int Surface::connect(int api) { |
Dan Stoza | 966b98b | 2015-03-02 22:12:37 -0800 | [diff] [blame] | 738 | static sp<IProducerListener> listener = new DummyProducerListener(); |
| 739 | return connect(api, listener); |
| 740 | } |
| 741 | |
| 742 | int Surface::connect(int api, const sp<IProducerListener>& listener) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 743 | ATRACE_CALL(); |
| 744 | ALOGV("Surface::connect"); |
| 745 | Mutex::Autolock lock(mMutex); |
| 746 | IGraphicBufferProducer::QueueBufferOutput output; |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 747 | int err = mGraphicBufferProducer->connect(listener, api, mProducerControlledByApp, &output); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 748 | if (err == NO_ERROR) { |
| 749 | uint32_t numPendingBuffers = 0; |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 750 | uint32_t hint = 0; |
| 751 | output.deflate(&mDefaultWidth, &mDefaultHeight, &hint, |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 752 | &numPendingBuffers); |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 753 | |
| 754 | // Disable transform hint if sticky transform is set. |
| 755 | if (mStickyTransform == 0) { |
| 756 | mTransformHint = hint; |
| 757 | } |
| 758 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 759 | mConsumerRunningBehind = (numPendingBuffers >= 2); |
| 760 | } |
| 761 | if (!err && api == NATIVE_WINDOW_API_CPU) { |
| 762 | mConnectedToCpu = true; |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 763 | // Clear the dirty region in case we're switching from a non-CPU API |
| 764 | mDirtyRegion.clear(); |
| 765 | } else if (!err) { |
| 766 | // Initialize the dirty region for tracking surface damage |
| 767 | mDirtyRegion = Region::INVALID_REGION; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 768 | } |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 769 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 770 | return err; |
| 771 | } |
| 772 | |
Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 773 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 774 | int Surface::disconnect(int api) { |
| 775 | ATRACE_CALL(); |
| 776 | ALOGV("Surface::disconnect"); |
| 777 | Mutex::Autolock lock(mMutex); |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 778 | mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT; |
| 779 | mSharedBufferHasBeenQueued = false; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 780 | freeAllBuffers(); |
| 781 | int err = mGraphicBufferProducer->disconnect(api); |
| 782 | if (!err) { |
| 783 | mReqFormat = 0; |
| 784 | mReqWidth = 0; |
| 785 | mReqHeight = 0; |
| 786 | mReqUsage = 0; |
| 787 | mCrop.clear(); |
| 788 | mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE; |
| 789 | mTransform = 0; |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 790 | mStickyTransform = 0; |
| 791 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 792 | if (api == NATIVE_WINDOW_API_CPU) { |
| 793 | mConnectedToCpu = false; |
| 794 | } |
| 795 | } |
| 796 | return err; |
| 797 | } |
| 798 | |
Dan Stoza | d9c4971 | 2015-04-27 11:06:01 -0700 | [diff] [blame] | 799 | int Surface::detachNextBuffer(sp<GraphicBuffer>* outBuffer, |
Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 800 | sp<Fence>* outFence) { |
| 801 | ATRACE_CALL(); |
| 802 | ALOGV("Surface::detachNextBuffer"); |
| 803 | |
| 804 | if (outBuffer == NULL || outFence == NULL) { |
| 805 | return BAD_VALUE; |
| 806 | } |
| 807 | |
| 808 | Mutex::Autolock lock(mMutex); |
| 809 | |
| 810 | sp<GraphicBuffer> buffer(NULL); |
| 811 | sp<Fence> fence(NULL); |
| 812 | status_t result = mGraphicBufferProducer->detachNextBuffer( |
| 813 | &buffer, &fence); |
| 814 | if (result != NO_ERROR) { |
| 815 | return result; |
| 816 | } |
| 817 | |
Dan Stoza | d9c4971 | 2015-04-27 11:06:01 -0700 | [diff] [blame] | 818 | *outBuffer = buffer; |
Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 819 | if (fence != NULL && fence->isValid()) { |
| 820 | *outFence = fence; |
| 821 | } else { |
| 822 | *outFence = Fence::NO_FENCE; |
| 823 | } |
| 824 | |
Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 825 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
| 826 | if (mSlots[i].buffer != NULL && |
| 827 | mSlots[i].buffer->handle == buffer->handle) { |
| 828 | mSlots[i].buffer = NULL; |
| 829 | } |
| 830 | } |
| 831 | |
Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 832 | return NO_ERROR; |
| 833 | } |
| 834 | |
| 835 | int Surface::attachBuffer(ANativeWindowBuffer* buffer) |
| 836 | { |
| 837 | ATRACE_CALL(); |
| 838 | ALOGV("Surface::attachBuffer"); |
| 839 | |
| 840 | Mutex::Autolock lock(mMutex); |
| 841 | |
| 842 | sp<GraphicBuffer> graphicBuffer(static_cast<GraphicBuffer*>(buffer)); |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 843 | uint32_t priorGeneration = graphicBuffer->mGenerationNumber; |
| 844 | graphicBuffer->mGenerationNumber = mGenerationNumber; |
Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 845 | int32_t attachedSlot = -1; |
| 846 | status_t result = mGraphicBufferProducer->attachBuffer( |
| 847 | &attachedSlot, graphicBuffer); |
| 848 | if (result != NO_ERROR) { |
| 849 | ALOGE("attachBuffer: IGraphicBufferProducer call failed (%d)", result); |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 850 | graphicBuffer->mGenerationNumber = priorGeneration; |
Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 851 | return result; |
| 852 | } |
| 853 | mSlots[attachedSlot].buffer = graphicBuffer; |
| 854 | |
| 855 | return NO_ERROR; |
| 856 | } |
| 857 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 858 | int Surface::setUsage(uint32_t reqUsage) |
| 859 | { |
| 860 | ALOGV("Surface::setUsage"); |
| 861 | Mutex::Autolock lock(mMutex); |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 862 | if (reqUsage != mReqUsage) { |
| 863 | mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT; |
| 864 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 865 | mReqUsage = reqUsage; |
| 866 | return OK; |
| 867 | } |
| 868 | |
| 869 | int Surface::setCrop(Rect const* rect) |
| 870 | { |
| 871 | ATRACE_CALL(); |
| 872 | |
Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 873 | Rect realRect(Rect::EMPTY_RECT); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 874 | if (rect == NULL || rect->isEmpty()) { |
| 875 | realRect.clear(); |
| 876 | } else { |
| 877 | realRect = *rect; |
Mathias Agopian | 55fa251 | 2010-03-11 15:06:54 -0800 | [diff] [blame] | 878 | } |
| 879 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 880 | ALOGV("Surface::setCrop rect=[%d %d %d %d]", |
| 881 | realRect.left, realRect.top, realRect.right, realRect.bottom); |
| 882 | |
| 883 | Mutex::Autolock lock(mMutex); |
| 884 | mCrop = realRect; |
| 885 | return NO_ERROR; |
| 886 | } |
| 887 | |
| 888 | int Surface::setBufferCount(int bufferCount) |
| 889 | { |
| 890 | ATRACE_CALL(); |
| 891 | ALOGV("Surface::setBufferCount"); |
| 892 | Mutex::Autolock lock(mMutex); |
| 893 | |
Pablo Ceballos | e5b755a | 2015-08-13 16:18:19 -0700 | [diff] [blame] | 894 | status_t err = NO_ERROR; |
| 895 | if (bufferCount == 0) { |
| 896 | err = mGraphicBufferProducer->setMaxDequeuedBufferCount(1); |
| 897 | } else { |
| 898 | int minUndequeuedBuffers = 0; |
| 899 | err = mGraphicBufferProducer->query( |
| 900 | NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &minUndequeuedBuffers); |
| 901 | if (err == NO_ERROR) { |
| 902 | err = mGraphicBufferProducer->setMaxDequeuedBufferCount( |
| 903 | bufferCount - minUndequeuedBuffers); |
| 904 | } |
| 905 | } |
Mathias Agopian | 9014726 | 2010-01-22 11:47:55 -0800 | [diff] [blame] | 906 | |
Pablo Ceballos | e5b755a | 2015-08-13 16:18:19 -0700 | [diff] [blame] | 907 | ALOGE_IF(err, "IGraphicBufferProducer::setBufferCount(%d) returned %s", |
| 908 | bufferCount, strerror(-err)); |
| 909 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 910 | return err; |
| 911 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 912 | |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 913 | int Surface::setMaxDequeuedBufferCount(int maxDequeuedBuffers) { |
| 914 | ATRACE_CALL(); |
| 915 | ALOGV("Surface::setMaxDequeuedBufferCount"); |
| 916 | Mutex::Autolock lock(mMutex); |
| 917 | |
| 918 | status_t err = mGraphicBufferProducer->setMaxDequeuedBufferCount( |
| 919 | maxDequeuedBuffers); |
| 920 | ALOGE_IF(err, "IGraphicBufferProducer::setMaxDequeuedBufferCount(%d) " |
| 921 | "returned %s", maxDequeuedBuffers, strerror(-err)); |
| 922 | |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 923 | return err; |
| 924 | } |
| 925 | |
| 926 | int Surface::setAsyncMode(bool async) { |
| 927 | ATRACE_CALL(); |
| 928 | ALOGV("Surface::setAsyncMode"); |
| 929 | Mutex::Autolock lock(mMutex); |
| 930 | |
| 931 | status_t err = mGraphicBufferProducer->setAsyncMode(async); |
| 932 | ALOGE_IF(err, "IGraphicBufferProducer::setAsyncMode(%d) returned %s", |
| 933 | async, strerror(-err)); |
| 934 | |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 935 | return err; |
| 936 | } |
| 937 | |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 938 | int Surface::setSharedBufferMode(bool sharedBufferMode) { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 939 | ATRACE_CALL(); |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 940 | ALOGV("Surface::setSharedBufferMode (%d)", sharedBufferMode); |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 941 | Mutex::Autolock lock(mMutex); |
| 942 | |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 943 | status_t err = mGraphicBufferProducer->setSharedBufferMode( |
| 944 | sharedBufferMode); |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 945 | if (err == NO_ERROR) { |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 946 | mSharedBufferMode = sharedBufferMode; |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 947 | } |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 948 | ALOGE_IF(err, "IGraphicBufferProducer::setSharedBufferMode(%d) returned" |
| 949 | "%s", sharedBufferMode, strerror(-err)); |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 950 | |
| 951 | return err; |
| 952 | } |
| 953 | |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 954 | int Surface::setAutoRefresh(bool autoRefresh) { |
| 955 | ATRACE_CALL(); |
| 956 | ALOGV("Surface::setAutoRefresh (%d)", autoRefresh); |
| 957 | Mutex::Autolock lock(mMutex); |
| 958 | |
| 959 | status_t err = mGraphicBufferProducer->setAutoRefresh(autoRefresh); |
| 960 | if (err == NO_ERROR) { |
| 961 | mAutoRefresh = autoRefresh; |
| 962 | } |
| 963 | ALOGE_IF(err, "IGraphicBufferProducer::setAutoRefresh(%d) returned %s", |
| 964 | autoRefresh, strerror(-err)); |
| 965 | return err; |
| 966 | } |
| 967 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 968 | int Surface::setBuffersDimensions(uint32_t width, uint32_t height) |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 969 | { |
| 970 | ATRACE_CALL(); |
| 971 | ALOGV("Surface::setBuffersDimensions"); |
| 972 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 973 | if ((width && !height) || (!width && height)) |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 974 | return BAD_VALUE; |
| 975 | |
| 976 | Mutex::Autolock lock(mMutex); |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 977 | if (width != mReqWidth || height != mReqHeight) { |
| 978 | mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT; |
| 979 | } |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 980 | mReqWidth = width; |
| 981 | mReqHeight = height; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 982 | return NO_ERROR; |
| 983 | } |
| 984 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 985 | int Surface::setBuffersUserDimensions(uint32_t width, uint32_t height) |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 986 | { |
| 987 | ATRACE_CALL(); |
| 988 | ALOGV("Surface::setBuffersUserDimensions"); |
| 989 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 990 | if ((width && !height) || (!width && height)) |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 991 | return BAD_VALUE; |
| 992 | |
| 993 | Mutex::Autolock lock(mMutex); |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 994 | if (width != mUserWidth || height != mUserHeight) { |
| 995 | mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT; |
| 996 | } |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 997 | mUserWidth = width; |
| 998 | mUserHeight = height; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 999 | return NO_ERROR; |
| 1000 | } |
| 1001 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1002 | int Surface::setBuffersFormat(PixelFormat format) |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1003 | { |
| 1004 | ALOGV("Surface::setBuffersFormat"); |
| 1005 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1006 | Mutex::Autolock lock(mMutex); |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1007 | if (format != mReqFormat) { |
| 1008 | mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT; |
| 1009 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1010 | mReqFormat = format; |
| 1011 | return NO_ERROR; |
| 1012 | } |
| 1013 | |
| 1014 | int Surface::setScalingMode(int mode) |
| 1015 | { |
| 1016 | ATRACE_CALL(); |
| 1017 | ALOGV("Surface::setScalingMode(%d)", mode); |
| 1018 | |
| 1019 | switch (mode) { |
| 1020 | case NATIVE_WINDOW_SCALING_MODE_FREEZE: |
| 1021 | case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW: |
| 1022 | case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP: |
Robert Carr | c2e7788 | 2015-12-16 18:14:03 -0800 | [diff] [blame] | 1023 | case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP: |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1024 | break; |
| 1025 | default: |
| 1026 | ALOGE("unknown scaling mode: %d", mode); |
| 1027 | return BAD_VALUE; |
| 1028 | } |
| 1029 | |
| 1030 | Mutex::Autolock lock(mMutex); |
| 1031 | mScalingMode = mode; |
| 1032 | return NO_ERROR; |
| 1033 | } |
| 1034 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1035 | int Surface::setBuffersTransform(uint32_t transform) |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1036 | { |
| 1037 | ATRACE_CALL(); |
| 1038 | ALOGV("Surface::setBuffersTransform"); |
| 1039 | Mutex::Autolock lock(mMutex); |
| 1040 | mTransform = transform; |
| 1041 | return NO_ERROR; |
| 1042 | } |
| 1043 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1044 | int Surface::setBuffersStickyTransform(uint32_t transform) |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1045 | { |
| 1046 | ATRACE_CALL(); |
| 1047 | ALOGV("Surface::setBuffersStickyTransform"); |
| 1048 | Mutex::Autolock lock(mMutex); |
| 1049 | mStickyTransform = transform; |
| 1050 | return NO_ERROR; |
| 1051 | } |
| 1052 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1053 | int Surface::setBuffersTimestamp(int64_t timestamp) |
| 1054 | { |
| 1055 | ALOGV("Surface::setBuffersTimestamp"); |
| 1056 | Mutex::Autolock lock(mMutex); |
| 1057 | mTimestamp = timestamp; |
| 1058 | return NO_ERROR; |
| 1059 | } |
| 1060 | |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 1061 | int Surface::setBuffersDataSpace(android_dataspace dataSpace) |
| 1062 | { |
| 1063 | ALOGV("Surface::setBuffersDataSpace"); |
| 1064 | Mutex::Autolock lock(mMutex); |
| 1065 | mDataSpace = dataSpace; |
| 1066 | return NO_ERROR; |
| 1067 | } |
| 1068 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1069 | void Surface::freeAllBuffers() { |
| 1070 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
| 1071 | mSlots[i].buffer = 0; |
| 1072 | } |
| 1073 | } |
| 1074 | |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 1075 | void Surface::setSurfaceDamage(android_native_rect_t* rects, size_t numRects) { |
| 1076 | ATRACE_CALL(); |
| 1077 | ALOGV("Surface::setSurfaceDamage"); |
| 1078 | Mutex::Autolock lock(mMutex); |
| 1079 | |
Dan Stoza | c62acbd | 2015-04-21 16:42:49 -0700 | [diff] [blame] | 1080 | if (mConnectedToCpu || numRects == 0) { |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 1081 | mDirtyRegion = Region::INVALID_REGION; |
| 1082 | return; |
| 1083 | } |
| 1084 | |
| 1085 | mDirtyRegion.clear(); |
| 1086 | for (size_t r = 0; r < numRects; ++r) { |
| 1087 | // We intentionally flip top and bottom here, since because they're |
| 1088 | // specified with a bottom-left origin, top > bottom, which fails |
| 1089 | // validation in the Region class. We will fix this up when we flip to a |
| 1090 | // top-left origin in queueBuffer. |
| 1091 | Rect rect(rects[r].left, rects[r].bottom, rects[r].right, rects[r].top); |
| 1092 | mDirtyRegion.orSelf(rect); |
| 1093 | } |
| 1094 | } |
| 1095 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1096 | // ---------------------------------------------------------------------- |
| 1097 | // the lock/unlock APIs must be used from the same thread |
| 1098 | |
| 1099 | static status_t copyBlt( |
| 1100 | const sp<GraphicBuffer>& dst, |
| 1101 | const sp<GraphicBuffer>& src, |
| 1102 | const Region& reg) |
| 1103 | { |
| 1104 | // src and dst with, height and format must be identical. no verification |
| 1105 | // is done here. |
| 1106 | status_t err; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1107 | uint8_t* src_bits = NULL; |
| 1108 | err = src->lock(GRALLOC_USAGE_SW_READ_OFTEN, reg.bounds(), |
| 1109 | reinterpret_cast<void**>(&src_bits)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1110 | ALOGE_IF(err, "error locking src buffer %s", strerror(-err)); |
| 1111 | |
| 1112 | uint8_t* dst_bits = NULL; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1113 | err = dst->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, reg.bounds(), |
| 1114 | reinterpret_cast<void**>(&dst_bits)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1115 | ALOGE_IF(err, "error locking dst buffer %s", strerror(-err)); |
| 1116 | |
| 1117 | Region::const_iterator head(reg.begin()); |
| 1118 | Region::const_iterator tail(reg.end()); |
| 1119 | if (head != tail && src_bits && dst_bits) { |
| 1120 | const size_t bpp = bytesPerPixel(src->format); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1121 | const size_t dbpr = static_cast<uint32_t>(dst->stride) * bpp; |
| 1122 | const size_t sbpr = static_cast<uint32_t>(src->stride) * bpp; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1123 | |
| 1124 | while (head != tail) { |
| 1125 | const Rect& r(*head++); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1126 | int32_t h = r.height(); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1127 | if (h <= 0) continue; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1128 | size_t size = static_cast<uint32_t>(r.width()) * bpp; |
| 1129 | uint8_t const * s = src_bits + |
| 1130 | static_cast<uint32_t>(r.left + src->stride * r.top) * bpp; |
| 1131 | uint8_t * d = dst_bits + |
| 1132 | static_cast<uint32_t>(r.left + dst->stride * r.top) * bpp; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1133 | if (dbpr==sbpr && size==sbpr) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1134 | size *= static_cast<size_t>(h); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1135 | h = 1; |
| 1136 | } |
| 1137 | do { |
| 1138 | memcpy(d, s, size); |
| 1139 | d += dbpr; |
| 1140 | s += sbpr; |
| 1141 | } while (--h > 0); |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | if (src_bits) |
| 1146 | src->unlock(); |
| 1147 | |
| 1148 | if (dst_bits) |
| 1149 | dst->unlock(); |
| 1150 | |
| 1151 | return err; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | } |
| 1153 | |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 1154 | // ---------------------------------------------------------------------------- |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1155 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1156 | status_t Surface::lock( |
| 1157 | ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds) |
| 1158 | { |
| 1159 | if (mLockedBuffer != 0) { |
| 1160 | ALOGE("Surface::lock failed, already locked"); |
| 1161 | return INVALID_OPERATION; |
| 1162 | } |
| 1163 | |
| 1164 | if (!mConnectedToCpu) { |
| 1165 | int err = Surface::connect(NATIVE_WINDOW_API_CPU); |
| 1166 | if (err) { |
| 1167 | return err; |
| 1168 | } |
| 1169 | // we're intending to do software rendering from this point |
| 1170 | setUsage(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
| 1171 | } |
| 1172 | |
| 1173 | ANativeWindowBuffer* out; |
| 1174 | int fenceFd = -1; |
| 1175 | status_t err = dequeueBuffer(&out, &fenceFd); |
| 1176 | ALOGE_IF(err, "dequeueBuffer failed (%s)", strerror(-err)); |
| 1177 | if (err == NO_ERROR) { |
| 1178 | sp<GraphicBuffer> backBuffer(GraphicBuffer::getSelf(out)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1179 | const Rect bounds(backBuffer->width, backBuffer->height); |
| 1180 | |
| 1181 | Region newDirtyRegion; |
| 1182 | if (inOutDirtyBounds) { |
| 1183 | newDirtyRegion.set(static_cast<Rect const&>(*inOutDirtyBounds)); |
| 1184 | newDirtyRegion.andSelf(bounds); |
| 1185 | } else { |
| 1186 | newDirtyRegion.set(bounds); |
| 1187 | } |
| 1188 | |
| 1189 | // figure out if we can copy the frontbuffer back |
| 1190 | const sp<GraphicBuffer>& frontBuffer(mPostedBuffer); |
| 1191 | const bool canCopyBack = (frontBuffer != 0 && |
| 1192 | backBuffer->width == frontBuffer->width && |
| 1193 | backBuffer->height == frontBuffer->height && |
| 1194 | backBuffer->format == frontBuffer->format); |
| 1195 | |
| 1196 | if (canCopyBack) { |
| 1197 | // copy the area that is invalid and not repainted this round |
| 1198 | const Region copyback(mDirtyRegion.subtract(newDirtyRegion)); |
| 1199 | if (!copyback.isEmpty()) |
| 1200 | copyBlt(backBuffer, frontBuffer, copyback); |
| 1201 | } else { |
| 1202 | // if we can't copy-back anything, modify the user's dirty |
| 1203 | // region to make sure they redraw the whole buffer |
| 1204 | newDirtyRegion.set(bounds); |
| 1205 | mDirtyRegion.clear(); |
| 1206 | Mutex::Autolock lock(mMutex); |
| 1207 | for (size_t i=0 ; i<NUM_BUFFER_SLOTS ; i++) { |
| 1208 | mSlots[i].dirtyRegion.clear(); |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | { // scope for the lock |
| 1214 | Mutex::Autolock lock(mMutex); |
| 1215 | int backBufferSlot(getSlotFromBufferLocked(backBuffer.get())); |
| 1216 | if (backBufferSlot >= 0) { |
| 1217 | Region& dirtyRegion(mSlots[backBufferSlot].dirtyRegion); |
| 1218 | mDirtyRegion.subtract(dirtyRegion); |
| 1219 | dirtyRegion = newDirtyRegion; |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | mDirtyRegion.orSelf(newDirtyRegion); |
| 1224 | if (inOutDirtyBounds) { |
| 1225 | *inOutDirtyBounds = newDirtyRegion.getBounds(); |
| 1226 | } |
| 1227 | |
| 1228 | void* vaddr; |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 1229 | status_t res = backBuffer->lockAsync( |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1230 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 1231 | newDirtyRegion.bounds(), &vaddr, fenceFd); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1232 | |
| 1233 | ALOGW_IF(res, "failed locking buffer (handle = %p)", |
| 1234 | backBuffer->handle); |
| 1235 | |
| 1236 | if (res != 0) { |
| 1237 | err = INVALID_OPERATION; |
| 1238 | } else { |
| 1239 | mLockedBuffer = backBuffer; |
| 1240 | outBuffer->width = backBuffer->width; |
| 1241 | outBuffer->height = backBuffer->height; |
| 1242 | outBuffer->stride = backBuffer->stride; |
| 1243 | outBuffer->format = backBuffer->format; |
| 1244 | outBuffer->bits = vaddr; |
| 1245 | } |
| 1246 | } |
| 1247 | return err; |
| 1248 | } |
| 1249 | |
| 1250 | status_t Surface::unlockAndPost() |
| 1251 | { |
| 1252 | if (mLockedBuffer == 0) { |
| 1253 | ALOGE("Surface::unlockAndPost failed, no locked buffer"); |
| 1254 | return INVALID_OPERATION; |
| 1255 | } |
| 1256 | |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 1257 | int fd = -1; |
| 1258 | status_t err = mLockedBuffer->unlockAsync(&fd); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1259 | ALOGE_IF(err, "failed unlocking buffer (%p)", mLockedBuffer->handle); |
| 1260 | |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 1261 | err = queueBuffer(mLockedBuffer.get(), fd); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1262 | ALOGE_IF(err, "queueBuffer (handle=%p) failed (%s)", |
| 1263 | mLockedBuffer->handle, strerror(-err)); |
| 1264 | |
| 1265 | mPostedBuffer = mLockedBuffer; |
| 1266 | mLockedBuffer = 0; |
| 1267 | return err; |
| 1268 | } |
| 1269 | |
Robert Carr | 9f31e29 | 2016-04-11 11:15:32 -0700 | [diff] [blame] | 1270 | bool Surface::waitForNextFrame(uint64_t lastFrame, nsecs_t timeout) { |
| 1271 | Mutex::Autolock lock(mMutex); |
| 1272 | uint64_t currentFrame = mGraphicBufferProducer->getNextFrameNumber(); |
| 1273 | if (currentFrame > lastFrame) { |
| 1274 | return true; |
| 1275 | } |
| 1276 | return mQueueBufferCondition.waitRelative(mMutex, timeout) == OK; |
| 1277 | } |
| 1278 | |
Eino-Ville Talvala | 8861291 | 2016-01-06 12:09:11 -0800 | [diff] [blame] | 1279 | namespace view { |
| 1280 | |
| 1281 | status_t Surface::writeToParcel(Parcel* parcel) const { |
| 1282 | return writeToParcel(parcel, false); |
| 1283 | } |
| 1284 | |
| 1285 | status_t Surface::writeToParcel(Parcel* parcel, bool nameAlreadyWritten) const { |
| 1286 | if (parcel == nullptr) return BAD_VALUE; |
| 1287 | |
| 1288 | status_t res = OK; |
| 1289 | |
| 1290 | if (!nameAlreadyWritten) res = parcel->writeString16(name); |
| 1291 | |
| 1292 | if (res == OK) { |
| 1293 | res = parcel->writeStrongBinder( |
| 1294 | IGraphicBufferProducer::asBinder(graphicBufferProducer)); |
| 1295 | } |
| 1296 | return res; |
| 1297 | } |
| 1298 | |
| 1299 | status_t Surface::readFromParcel(const Parcel* parcel) { |
| 1300 | return readFromParcel(parcel, false); |
| 1301 | } |
| 1302 | |
| 1303 | status_t Surface::readFromParcel(const Parcel* parcel, bool nameAlreadyRead) { |
| 1304 | if (parcel == nullptr) return BAD_VALUE; |
| 1305 | |
| 1306 | if (!nameAlreadyRead) { |
| 1307 | name = readMaybeEmptyString16(parcel); |
| 1308 | } |
| 1309 | |
| 1310 | sp<IBinder> binder; |
| 1311 | |
| 1312 | status_t res = parcel->readStrongBinder(&binder); |
| 1313 | if (res != OK) return res; |
| 1314 | |
| 1315 | graphicBufferProducer = interface_cast<IGraphicBufferProducer>(binder); |
| 1316 | |
| 1317 | return OK; |
| 1318 | } |
| 1319 | |
| 1320 | String16 Surface::readMaybeEmptyString16(const Parcel* parcel) { |
| 1321 | size_t len; |
| 1322 | const char16_t* str = parcel->readString16Inplace(&len); |
| 1323 | if (str != nullptr) { |
| 1324 | return String16(str, len); |
| 1325 | } else { |
| 1326 | return String16(); |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | } // namespace view |
| 1331 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1332 | }; // namespace android |