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) |
Mathias Agopian | 35ffa6a | 2013-03-12 18:45:09 -0700 | [diff] [blame] | 45 | : mGraphicBufferProducer(bufferProducer) |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 46 | { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 47 | // Initialize the ANativeWindow function pointers. |
| 48 | ANativeWindow::setSwapInterval = hook_setSwapInterval; |
| 49 | ANativeWindow::dequeueBuffer = hook_dequeueBuffer; |
| 50 | ANativeWindow::cancelBuffer = hook_cancelBuffer; |
| 51 | ANativeWindow::queueBuffer = hook_queueBuffer; |
| 52 | ANativeWindow::query = hook_query; |
| 53 | ANativeWindow::perform = hook_perform; |
| 54 | |
| 55 | ANativeWindow::dequeueBuffer_DEPRECATED = hook_dequeueBuffer_DEPRECATED; |
| 56 | ANativeWindow::cancelBuffer_DEPRECATED = hook_cancelBuffer_DEPRECATED; |
| 57 | ANativeWindow::lockBuffer_DEPRECATED = hook_lockBuffer_DEPRECATED; |
| 58 | ANativeWindow::queueBuffer_DEPRECATED = hook_queueBuffer_DEPRECATED; |
| 59 | |
| 60 | const_cast<int&>(ANativeWindow::minSwapInterval) = 0; |
| 61 | const_cast<int&>(ANativeWindow::maxSwapInterval) = 1; |
| 62 | |
| 63 | mReqWidth = 0; |
| 64 | mReqHeight = 0; |
| 65 | mReqFormat = 0; |
| 66 | mReqUsage = 0; |
| 67 | mTimestamp = NATIVE_WINDOW_TIMESTAMP_AUTO; |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 68 | mDataSpace = HAL_DATASPACE_UNKNOWN; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 69 | mCrop.clear(); |
| 70 | mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE; |
| 71 | mTransform = 0; |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 72 | mStickyTransform = 0; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 73 | mDefaultWidth = 0; |
| 74 | mDefaultHeight = 0; |
| 75 | mUserWidth = 0; |
| 76 | mUserHeight = 0; |
| 77 | mTransformHint = 0; |
| 78 | mConsumerRunningBehind = false; |
| 79 | mConnectedToCpu = false; |
Eino-Ville Talvala | 7895e90 | 2013-08-21 11:53:37 -0700 | [diff] [blame] | 80 | mProducerControlledByApp = controlledByApp; |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 81 | mSwapIntervalZero = false; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Mathias Agopian | 35ffa6a | 2013-03-12 18:45:09 -0700 | [diff] [blame] | 84 | Surface::~Surface() { |
| 85 | if (mConnectedToCpu) { |
| 86 | Surface::disconnect(NATIVE_WINDOW_API_CPU); |
| 87 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | sp<IGraphicBufferProducer> Surface::getIGraphicBufferProducer() const { |
| 91 | return mGraphicBufferProducer; |
| 92 | } |
| 93 | |
Wonsik Kim | 0ee14ca | 2014-03-17 17:46:53 +0900 | [diff] [blame] | 94 | void Surface::setSidebandStream(const sp<NativeHandle>& stream) { |
| 95 | mGraphicBufferProducer->setSidebandStream(stream); |
| 96 | } |
| 97 | |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 98 | void Surface::allocateBuffers() { |
| 99 | uint32_t reqWidth = mReqWidth ? mReqWidth : mUserWidth; |
| 100 | uint32_t reqHeight = mReqHeight ? mReqHeight : mUserHeight; |
Andreas Gampe | 7398a5a | 2014-12-08 20:42:40 -0800 | [diff] [blame] | 101 | mGraphicBufferProducer->allocateBuffers(mSwapIntervalZero, reqWidth, |
| 102 | reqHeight, mReqFormat, mReqUsage); |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 105 | int Surface::hook_setSwapInterval(ANativeWindow* window, int interval) { |
| 106 | Surface* c = getSelf(window); |
| 107 | return c->setSwapInterval(interval); |
| 108 | } |
| 109 | |
| 110 | int Surface::hook_dequeueBuffer(ANativeWindow* window, |
| 111 | ANativeWindowBuffer** buffer, int* fenceFd) { |
| 112 | Surface* c = getSelf(window); |
| 113 | return c->dequeueBuffer(buffer, fenceFd); |
| 114 | } |
| 115 | |
| 116 | int Surface::hook_cancelBuffer(ANativeWindow* window, |
| 117 | ANativeWindowBuffer* buffer, int fenceFd) { |
| 118 | Surface* c = getSelf(window); |
| 119 | return c->cancelBuffer(buffer, fenceFd); |
| 120 | } |
| 121 | |
| 122 | int Surface::hook_queueBuffer(ANativeWindow* window, |
| 123 | ANativeWindowBuffer* buffer, int fenceFd) { |
| 124 | Surface* c = getSelf(window); |
| 125 | return c->queueBuffer(buffer, fenceFd); |
| 126 | } |
| 127 | |
| 128 | int Surface::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window, |
| 129 | ANativeWindowBuffer** buffer) { |
| 130 | Surface* c = getSelf(window); |
| 131 | ANativeWindowBuffer* buf; |
| 132 | int fenceFd = -1; |
| 133 | int result = c->dequeueBuffer(&buf, &fenceFd); |
| 134 | sp<Fence> fence(new Fence(fenceFd)); |
Mathias Agopian | ea74d3b | 2013-05-16 18:03:22 -0700 | [diff] [blame] | 135 | int waitResult = fence->waitForever("dequeueBuffer_DEPRECATED"); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 136 | if (waitResult != OK) { |
| 137 | ALOGE("dequeueBuffer_DEPRECATED: Fence::wait returned an error: %d", |
| 138 | waitResult); |
| 139 | c->cancelBuffer(buf, -1); |
| 140 | return waitResult; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 141 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 142 | *buffer = buf; |
| 143 | return result; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 146 | int Surface::hook_cancelBuffer_DEPRECATED(ANativeWindow* window, |
| 147 | ANativeWindowBuffer* buffer) { |
| 148 | Surface* c = getSelf(window); |
| 149 | return c->cancelBuffer(buffer, -1); |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 152 | int Surface::hook_lockBuffer_DEPRECATED(ANativeWindow* window, |
| 153 | ANativeWindowBuffer* buffer) { |
| 154 | Surface* c = getSelf(window); |
| 155 | return c->lockBuffer_DEPRECATED(buffer); |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 158 | int Surface::hook_queueBuffer_DEPRECATED(ANativeWindow* window, |
| 159 | ANativeWindowBuffer* buffer) { |
| 160 | Surface* c = getSelf(window); |
| 161 | return c->queueBuffer(buffer, -1); |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 162 | } |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 163 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 164 | int Surface::hook_query(const ANativeWindow* window, |
| 165 | int what, int* value) { |
| 166 | const Surface* c = getSelf(window); |
| 167 | return c->query(what, value); |
| 168 | } |
| 169 | |
| 170 | int Surface::hook_perform(ANativeWindow* window, int operation, ...) { |
| 171 | va_list args; |
| 172 | va_start(args, operation); |
| 173 | Surface* c = getSelf(window); |
| 174 | return c->perform(operation, args); |
| 175 | } |
| 176 | |
| 177 | int Surface::setSwapInterval(int interval) { |
| 178 | ATRACE_CALL(); |
| 179 | // EGL specification states: |
| 180 | // interval is silently clamped to minimum and maximum implementation |
| 181 | // dependent values before being stored. |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 182 | |
| 183 | if (interval < minSwapInterval) |
| 184 | interval = minSwapInterval; |
| 185 | |
| 186 | if (interval > maxSwapInterval) |
| 187 | interval = maxSwapInterval; |
| 188 | |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 189 | mSwapIntervalZero = (interval == 0); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 190 | |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 191 | return NO_ERROR; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 194 | int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 195 | ATRACE_CALL(); |
| 196 | ALOGV("Surface::dequeueBuffer"); |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 197 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 198 | uint32_t reqWidth; |
| 199 | uint32_t reqHeight; |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 200 | bool swapIntervalZero; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 201 | PixelFormat reqFormat; |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 202 | uint32_t reqUsage; |
| 203 | |
| 204 | { |
| 205 | Mutex::Autolock lock(mMutex); |
| 206 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 207 | reqWidth = mReqWidth ? mReqWidth : mUserWidth; |
| 208 | reqHeight = mReqHeight ? mReqHeight : mUserHeight; |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 209 | |
| 210 | swapIntervalZero = mSwapIntervalZero; |
| 211 | reqFormat = mReqFormat; |
| 212 | reqUsage = mReqUsage; |
| 213 | } // Drop the lock so that we can still touch the Surface while blocking in IGBP::dequeueBuffer |
| 214 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 215 | int buf = -1; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 216 | sp<Fence> fence; |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 217 | status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence, swapIntervalZero, |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 218 | reqWidth, reqHeight, reqFormat, reqUsage); |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 219 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 220 | if (result < 0) { |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 221 | ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer(%d, %d, %d, %d, %d)" |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 222 | "failed: %d", swapIntervalZero, reqWidth, reqHeight, reqFormat, |
| 223 | reqUsage, result); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 224 | return result; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 225 | } |
Igor Murashkin | 0f1889e | 2014-02-28 18:44:21 -0800 | [diff] [blame] | 226 | |
| 227 | Mutex::Autolock lock(mMutex); |
| 228 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 229 | sp<GraphicBuffer>& gbuf(mSlots[buf].buffer); |
Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 230 | |
| 231 | // this should never happen |
| 232 | ALOGE_IF(fence == NULL, "Surface::dequeueBuffer: received null Fence! buf=%d", buf); |
| 233 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 234 | if (result & IGraphicBufferProducer::RELEASE_ALL_BUFFERS) { |
| 235 | freeAllBuffers(); |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 236 | } |
Ted Bonkenburg | bd050ab | 2011-07-15 15:10:10 -0700 | [diff] [blame] | 237 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 238 | if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) { |
| 239 | result = mGraphicBufferProducer->requestBuffer(buf, &gbuf); |
| 240 | if (result != NO_ERROR) { |
Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 241 | ALOGE("dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: %d", result); |
Jesse Hall | 9f5a1b6 | 2014-10-02 11:09:03 -0700 | [diff] [blame] | 242 | mGraphicBufferProducer->cancelBuffer(buf, fence); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 243 | return result; |
| 244 | } |
| 245 | } |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 246 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 247 | if (fence->isValid()) { |
| 248 | *fenceFd = fence->dup(); |
| 249 | if (*fenceFd == -1) { |
| 250 | ALOGE("dequeueBuffer: error duping fence: %d", errno); |
| 251 | // dup() should never fail; something is badly wrong. Soldier on |
| 252 | // and hope for the best; the worst that should happen is some |
| 253 | // visible corruption that lasts until the next frame. |
| 254 | } |
Ted Bonkenburg | e5d6eb8 | 2011-08-09 22:38:41 -0700 | [diff] [blame] | 255 | } else { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 256 | *fenceFd = -1; |
Mathias Agopian | a0c30e9 | 2010-06-04 18:26:32 -0700 | [diff] [blame] | 257 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 258 | |
| 259 | *buffer = gbuf.get(); |
| 260 | return OK; |
Jamie Gennis | aca4e22 | 2010-07-15 17:29:15 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 263 | int Surface::cancelBuffer(android_native_buffer_t* buffer, |
| 264 | int fenceFd) { |
| 265 | ATRACE_CALL(); |
| 266 | ALOGV("Surface::cancelBuffer"); |
| 267 | Mutex::Autolock lock(mMutex); |
| 268 | int i = getSlotFromBufferLocked(buffer); |
| 269 | if (i < 0) { |
| 270 | return i; |
| 271 | } |
| 272 | sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); |
| 273 | mGraphicBufferProducer->cancelBuffer(i, fence); |
| 274 | return OK; |
| 275 | } |
| 276 | |
| 277 | int Surface::getSlotFromBufferLocked( |
| 278 | android_native_buffer_t* buffer) const { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 279 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
| 280 | if (mSlots[i].buffer != NULL && |
| 281 | mSlots[i].buffer->handle == buffer->handle) { |
| 282 | return i; |
Jamie Gennis | aca4e22 | 2010-07-15 17:29:15 -0700 | [diff] [blame] | 283 | } |
| 284 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 285 | ALOGE("getSlotFromBufferLocked: unknown buffer: %p", buffer->handle); |
| 286 | return BAD_VALUE; |
Mathias Agopian | a0c30e9 | 2010-06-04 18:26:32 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 289 | int Surface::lockBuffer_DEPRECATED(android_native_buffer_t* buffer __attribute__((unused))) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 290 | ALOGV("Surface::lockBuffer"); |
| 291 | Mutex::Autolock lock(mMutex); |
| 292 | return OK; |
| 293 | } |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 294 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 295 | int Surface::queueBuffer(android_native_buffer_t* buffer, int fenceFd) { |
| 296 | ATRACE_CALL(); |
| 297 | ALOGV("Surface::queueBuffer"); |
| 298 | Mutex::Autolock lock(mMutex); |
| 299 | int64_t timestamp; |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 300 | bool isAutoTimestamp = false; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 301 | if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) { |
Andy McFadden | 4b49e08 | 2013-08-02 15:31:45 -0700 | [diff] [blame] | 302 | timestamp = systemTime(SYSTEM_TIME_MONOTONIC); |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 303 | isAutoTimestamp = true; |
Andy McFadden | 4b49e08 | 2013-08-02 15:31:45 -0700 | [diff] [blame] | 304 | ALOGV("Surface::queueBuffer making up timestamp: %.2f ms", |
| 305 | timestamp / 1000000.f); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 306 | } else { |
| 307 | timestamp = mTimestamp; |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 308 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 309 | int i = getSlotFromBufferLocked(buffer); |
| 310 | if (i < 0) { |
| 311 | return i; |
| 312 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 315 | // Make sure the crop rectangle is entirely inside the buffer. |
| 316 | Rect crop; |
| 317 | mCrop.intersect(Rect(buffer->width, buffer->height), &crop); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 319 | sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); |
| 320 | IGraphicBufferProducer::QueueBufferOutput output; |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 321 | IGraphicBufferProducer::QueueBufferInput input(timestamp, isAutoTimestamp, |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 322 | mDataSpace, crop, mScalingMode, mTransform ^ mStickyTransform, |
| 323 | mSwapIntervalZero, fence, mStickyTransform); |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 324 | |
Dan Stoza | c62acbd | 2015-04-21 16:42:49 -0700 | [diff] [blame^] | 325 | if (mConnectedToCpu || mDirtyRegion.bounds() == Rect::INVALID_RECT) { |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 326 | input.setSurfaceDamage(Region::INVALID_REGION); |
| 327 | } else { |
| 328 | // The surface damage was specified using the OpenGL ES convention of |
| 329 | // the origin being in the bottom-left corner. Here we flip to the |
| 330 | // convention that the rest of the system uses (top-left corner) by |
| 331 | // subtracting all top/bottom coordinates from the buffer height. |
| 332 | Region flippedRegion; |
| 333 | for (auto rect : mDirtyRegion) { |
| 334 | auto top = buffer->height - rect.bottom; |
| 335 | auto bottom = buffer->height - rect.top; |
| 336 | Rect flippedRect{rect.left, top, rect.right, bottom}; |
| 337 | flippedRegion.orSelf(flippedRect); |
| 338 | } |
| 339 | |
| 340 | input.setSurfaceDamage(flippedRegion); |
| 341 | } |
| 342 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 343 | status_t err = mGraphicBufferProducer->queueBuffer(i, input, &output); |
| 344 | if (err != OK) { |
| 345 | ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err); |
| 346 | } |
| 347 | uint32_t numPendingBuffers = 0; |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 348 | uint32_t hint = 0; |
| 349 | output.deflate(&mDefaultWidth, &mDefaultHeight, &hint, |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 350 | &numPendingBuffers); |
tedbo | 1e7fa9e | 2011-06-22 15:52:53 -0700 | [diff] [blame] | 351 | |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 352 | // Disable transform hint if sticky transform is set. |
| 353 | if (mStickyTransform == 0) { |
| 354 | mTransformHint = hint; |
| 355 | } |
| 356 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 357 | mConsumerRunningBehind = (numPendingBuffers >= 2); |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 358 | |
Dan Stoza | c62acbd | 2015-04-21 16:42:49 -0700 | [diff] [blame^] | 359 | if (!mConnectedToCpu) { |
| 360 | // Clear surface damage back to full-buffer |
| 361 | mDirtyRegion = Region::INVALID_REGION; |
| 362 | } |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 363 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 364 | return err; |
| 365 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 366 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 367 | int Surface::query(int what, int* value) const { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 368 | ATRACE_CALL(); |
| 369 | ALOGV("Surface::query"); |
| 370 | { // scope for the lock |
| 371 | Mutex::Autolock lock(mMutex); |
| 372 | switch (what) { |
| 373 | case NATIVE_WINDOW_FORMAT: |
| 374 | if (mReqFormat) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 375 | *value = static_cast<int>(mReqFormat); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 376 | return NO_ERROR; |
| 377 | } |
| 378 | break; |
| 379 | case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: { |
| 380 | sp<ISurfaceComposer> composer( |
| 381 | ComposerService::getComposerService()); |
| 382 | if (composer->authenticateSurfaceTexture(mGraphicBufferProducer)) { |
| 383 | *value = 1; |
| 384 | } else { |
| 385 | *value = 0; |
| 386 | } |
| 387 | return NO_ERROR; |
| 388 | } |
| 389 | case NATIVE_WINDOW_CONCRETE_TYPE: |
| 390 | *value = NATIVE_WINDOW_SURFACE; |
| 391 | return NO_ERROR; |
| 392 | case NATIVE_WINDOW_DEFAULT_WIDTH: |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 393 | *value = static_cast<int>( |
| 394 | mUserWidth ? mUserWidth : mDefaultWidth); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 395 | return NO_ERROR; |
| 396 | case NATIVE_WINDOW_DEFAULT_HEIGHT: |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 397 | *value = static_cast<int>( |
| 398 | mUserHeight ? mUserHeight : mDefaultHeight); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 399 | return NO_ERROR; |
| 400 | case NATIVE_WINDOW_TRANSFORM_HINT: |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 401 | *value = static_cast<int>(mTransformHint); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 402 | return NO_ERROR; |
| 403 | case NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND: { |
| 404 | status_t err = NO_ERROR; |
| 405 | if (!mConsumerRunningBehind) { |
| 406 | *value = 0; |
| 407 | } else { |
| 408 | err = mGraphicBufferProducer->query(what, value); |
| 409 | if (err == NO_ERROR) { |
| 410 | mConsumerRunningBehind = *value; |
| 411 | } |
| 412 | } |
| 413 | return err; |
| 414 | } |
| 415 | } |
Jamie Gennis | 391bbe2 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 416 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 417 | return mGraphicBufferProducer->query(what, value); |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 420 | int Surface::perform(int operation, va_list args) |
| 421 | { |
| 422 | int res = NO_ERROR; |
| 423 | switch (operation) { |
| 424 | case NATIVE_WINDOW_CONNECT: |
| 425 | // deprecated. must return NO_ERROR. |
| 426 | break; |
| 427 | case NATIVE_WINDOW_DISCONNECT: |
| 428 | // deprecated. must return NO_ERROR. |
| 429 | break; |
| 430 | case NATIVE_WINDOW_SET_USAGE: |
| 431 | res = dispatchSetUsage(args); |
| 432 | break; |
| 433 | case NATIVE_WINDOW_SET_CROP: |
| 434 | res = dispatchSetCrop(args); |
| 435 | break; |
| 436 | case NATIVE_WINDOW_SET_BUFFER_COUNT: |
| 437 | res = dispatchSetBufferCount(args); |
| 438 | break; |
| 439 | case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY: |
| 440 | res = dispatchSetBuffersGeometry(args); |
| 441 | break; |
| 442 | case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM: |
| 443 | res = dispatchSetBuffersTransform(args); |
| 444 | break; |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 445 | case NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM: |
| 446 | res = dispatchSetBuffersStickyTransform(args); |
| 447 | break; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 448 | case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP: |
| 449 | res = dispatchSetBuffersTimestamp(args); |
| 450 | break; |
| 451 | case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS: |
| 452 | res = dispatchSetBuffersDimensions(args); |
| 453 | break; |
| 454 | case NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS: |
| 455 | res = dispatchSetBuffersUserDimensions(args); |
| 456 | break; |
| 457 | case NATIVE_WINDOW_SET_BUFFERS_FORMAT: |
| 458 | res = dispatchSetBuffersFormat(args); |
| 459 | break; |
| 460 | case NATIVE_WINDOW_LOCK: |
| 461 | res = dispatchLock(args); |
| 462 | break; |
| 463 | case NATIVE_WINDOW_UNLOCK_AND_POST: |
| 464 | res = dispatchUnlockAndPost(args); |
| 465 | break; |
| 466 | case NATIVE_WINDOW_SET_SCALING_MODE: |
| 467 | res = dispatchSetScalingMode(args); |
| 468 | break; |
| 469 | case NATIVE_WINDOW_API_CONNECT: |
| 470 | res = dispatchConnect(args); |
| 471 | break; |
| 472 | case NATIVE_WINDOW_API_DISCONNECT: |
| 473 | res = dispatchDisconnect(args); |
| 474 | break; |
Rachad | 7cb0d39 | 2014-07-29 17:53:53 -0700 | [diff] [blame] | 475 | case NATIVE_WINDOW_SET_SIDEBAND_STREAM: |
| 476 | res = dispatchSetSidebandStream(args); |
| 477 | break; |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 478 | case NATIVE_WINDOW_SET_BUFFERS_DATASPACE: |
| 479 | res = dispatchSetBuffersDataSpace(args); |
| 480 | break; |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 481 | case NATIVE_WINDOW_SET_SURFACE_DAMAGE: |
| 482 | res = dispatchSetSurfaceDamage(args); |
| 483 | break; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 484 | default: |
| 485 | res = NAME_NOT_FOUND; |
| 486 | break; |
| 487 | } |
| 488 | return res; |
| 489 | } |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 490 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 491 | int Surface::dispatchConnect(va_list args) { |
| 492 | int api = va_arg(args, int); |
| 493 | return connect(api); |
| 494 | } |
Mathias Agopian | 55fa251 | 2010-03-11 15:06:54 -0800 | [diff] [blame] | 495 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 496 | int Surface::dispatchDisconnect(va_list args) { |
| 497 | int api = va_arg(args, int); |
| 498 | return disconnect(api); |
| 499 | } |
| 500 | |
| 501 | int Surface::dispatchSetUsage(va_list args) { |
| 502 | int usage = va_arg(args, int); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 503 | return setUsage(static_cast<uint32_t>(usage)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | int Surface::dispatchSetCrop(va_list args) { |
| 507 | android_native_rect_t const* rect = va_arg(args, android_native_rect_t*); |
| 508 | return setCrop(reinterpret_cast<Rect const*>(rect)); |
| 509 | } |
| 510 | |
| 511 | int Surface::dispatchSetBufferCount(va_list args) { |
| 512 | size_t bufferCount = va_arg(args, size_t); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 513 | return setBufferCount(static_cast<int32_t>(bufferCount)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | int Surface::dispatchSetBuffersGeometry(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 517 | uint32_t width = va_arg(args, uint32_t); |
| 518 | uint32_t height = va_arg(args, uint32_t); |
| 519 | PixelFormat format = va_arg(args, PixelFormat); |
| 520 | int err = setBuffersDimensions(width, height); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 521 | if (err != 0) { |
| 522 | return err; |
| 523 | } |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 524 | return setBuffersFormat(format); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | int Surface::dispatchSetBuffersDimensions(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 528 | uint32_t width = va_arg(args, uint32_t); |
| 529 | uint32_t height = va_arg(args, uint32_t); |
| 530 | return setBuffersDimensions(width, height); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | int Surface::dispatchSetBuffersUserDimensions(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 534 | uint32_t width = va_arg(args, uint32_t); |
| 535 | uint32_t height = va_arg(args, uint32_t); |
| 536 | return setBuffersUserDimensions(width, height); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | int Surface::dispatchSetBuffersFormat(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 540 | PixelFormat format = va_arg(args, PixelFormat); |
| 541 | return setBuffersFormat(format); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | int Surface::dispatchSetScalingMode(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 545 | int mode = va_arg(args, int); |
| 546 | return setScalingMode(mode); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | int Surface::dispatchSetBuffersTransform(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 550 | uint32_t transform = va_arg(args, uint32_t); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 551 | return setBuffersTransform(transform); |
| 552 | } |
| 553 | |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 554 | int Surface::dispatchSetBuffersStickyTransform(va_list args) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 555 | uint32_t transform = va_arg(args, uint32_t); |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 556 | return setBuffersStickyTransform(transform); |
| 557 | } |
| 558 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 559 | int Surface::dispatchSetBuffersTimestamp(va_list args) { |
| 560 | int64_t timestamp = va_arg(args, int64_t); |
| 561 | return setBuffersTimestamp(timestamp); |
| 562 | } |
| 563 | |
| 564 | int Surface::dispatchLock(va_list args) { |
| 565 | ANativeWindow_Buffer* outBuffer = va_arg(args, ANativeWindow_Buffer*); |
| 566 | ARect* inOutDirtyBounds = va_arg(args, ARect*); |
| 567 | return lock(outBuffer, inOutDirtyBounds); |
| 568 | } |
| 569 | |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 570 | int Surface::dispatchUnlockAndPost(va_list args __attribute__((unused))) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 571 | return unlockAndPost(); |
| 572 | } |
| 573 | |
Rachad | 7cb0d39 | 2014-07-29 17:53:53 -0700 | [diff] [blame] | 574 | int Surface::dispatchSetSidebandStream(va_list args) { |
| 575 | native_handle_t* sH = va_arg(args, native_handle_t*); |
| 576 | sp<NativeHandle> sidebandHandle = NativeHandle::create(sH, false); |
| 577 | setSidebandStream(sidebandHandle); |
| 578 | return OK; |
| 579 | } |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 580 | |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 581 | int Surface::dispatchSetBuffersDataSpace(va_list args) { |
| 582 | android_dataspace dataspace = |
| 583 | static_cast<android_dataspace>(va_arg(args, int)); |
| 584 | return setBuffersDataSpace(dataspace); |
| 585 | } |
| 586 | |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 587 | int Surface::dispatchSetSurfaceDamage(va_list args) { |
| 588 | android_native_rect_t* rects = va_arg(args, android_native_rect_t*); |
| 589 | size_t numRects = va_arg(args, size_t); |
| 590 | setSurfaceDamage(rects, numRects); |
| 591 | return NO_ERROR; |
| 592 | } |
| 593 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 594 | int Surface::connect(int api) { |
Dan Stoza | 966b98b | 2015-03-02 22:12:37 -0800 | [diff] [blame] | 595 | static sp<IProducerListener> listener = new DummyProducerListener(); |
| 596 | return connect(api, listener); |
| 597 | } |
| 598 | |
| 599 | int Surface::connect(int api, const sp<IProducerListener>& listener) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 600 | ATRACE_CALL(); |
| 601 | ALOGV("Surface::connect"); |
| 602 | Mutex::Autolock lock(mMutex); |
| 603 | IGraphicBufferProducer::QueueBufferOutput output; |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 604 | int err = mGraphicBufferProducer->connect(listener, api, mProducerControlledByApp, &output); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 605 | if (err == NO_ERROR) { |
| 606 | uint32_t numPendingBuffers = 0; |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 607 | uint32_t hint = 0; |
| 608 | output.deflate(&mDefaultWidth, &mDefaultHeight, &hint, |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 609 | &numPendingBuffers); |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 610 | |
| 611 | // Disable transform hint if sticky transform is set. |
| 612 | if (mStickyTransform == 0) { |
| 613 | mTransformHint = hint; |
| 614 | } |
| 615 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 616 | mConsumerRunningBehind = (numPendingBuffers >= 2); |
| 617 | } |
| 618 | if (!err && api == NATIVE_WINDOW_API_CPU) { |
| 619 | mConnectedToCpu = true; |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 620 | // Clear the dirty region in case we're switching from a non-CPU API |
| 621 | mDirtyRegion.clear(); |
| 622 | } else if (!err) { |
| 623 | // Initialize the dirty region for tracking surface damage |
| 624 | mDirtyRegion = Region::INVALID_REGION; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 625 | } |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 626 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 627 | return err; |
| 628 | } |
| 629 | |
Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 630 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 631 | int Surface::disconnect(int api) { |
| 632 | ATRACE_CALL(); |
| 633 | ALOGV("Surface::disconnect"); |
| 634 | Mutex::Autolock lock(mMutex); |
| 635 | freeAllBuffers(); |
| 636 | int err = mGraphicBufferProducer->disconnect(api); |
| 637 | if (!err) { |
| 638 | mReqFormat = 0; |
| 639 | mReqWidth = 0; |
| 640 | mReqHeight = 0; |
| 641 | mReqUsage = 0; |
| 642 | mCrop.clear(); |
| 643 | mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE; |
| 644 | mTransform = 0; |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 645 | mStickyTransform = 0; |
| 646 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 647 | if (api == NATIVE_WINDOW_API_CPU) { |
| 648 | mConnectedToCpu = false; |
| 649 | } |
| 650 | } |
| 651 | return err; |
| 652 | } |
| 653 | |
Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 654 | int Surface::detachNextBuffer(ANativeWindowBuffer** outBuffer, |
| 655 | sp<Fence>* outFence) { |
| 656 | ATRACE_CALL(); |
| 657 | ALOGV("Surface::detachNextBuffer"); |
| 658 | |
| 659 | if (outBuffer == NULL || outFence == NULL) { |
| 660 | return BAD_VALUE; |
| 661 | } |
| 662 | |
| 663 | Mutex::Autolock lock(mMutex); |
| 664 | |
| 665 | sp<GraphicBuffer> buffer(NULL); |
| 666 | sp<Fence> fence(NULL); |
| 667 | status_t result = mGraphicBufferProducer->detachNextBuffer( |
| 668 | &buffer, &fence); |
| 669 | if (result != NO_ERROR) { |
| 670 | return result; |
| 671 | } |
| 672 | |
| 673 | *outBuffer = buffer.get(); |
| 674 | if (fence != NULL && fence->isValid()) { |
| 675 | *outFence = fence; |
| 676 | } else { |
| 677 | *outFence = Fence::NO_FENCE; |
| 678 | } |
| 679 | |
| 680 | return NO_ERROR; |
| 681 | } |
| 682 | |
| 683 | int Surface::attachBuffer(ANativeWindowBuffer* buffer) |
| 684 | { |
| 685 | ATRACE_CALL(); |
| 686 | ALOGV("Surface::attachBuffer"); |
| 687 | |
| 688 | Mutex::Autolock lock(mMutex); |
| 689 | |
| 690 | sp<GraphicBuffer> graphicBuffer(static_cast<GraphicBuffer*>(buffer)); |
| 691 | int32_t attachedSlot = -1; |
| 692 | status_t result = mGraphicBufferProducer->attachBuffer( |
| 693 | &attachedSlot, graphicBuffer); |
| 694 | if (result != NO_ERROR) { |
| 695 | ALOGE("attachBuffer: IGraphicBufferProducer call failed (%d)", result); |
| 696 | return result; |
| 697 | } |
| 698 | mSlots[attachedSlot].buffer = graphicBuffer; |
| 699 | |
| 700 | return NO_ERROR; |
| 701 | } |
| 702 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 703 | int Surface::setUsage(uint32_t reqUsage) |
| 704 | { |
| 705 | ALOGV("Surface::setUsage"); |
| 706 | Mutex::Autolock lock(mMutex); |
| 707 | mReqUsage = reqUsage; |
| 708 | return OK; |
| 709 | } |
| 710 | |
| 711 | int Surface::setCrop(Rect const* rect) |
| 712 | { |
| 713 | ATRACE_CALL(); |
| 714 | |
| 715 | Rect realRect; |
| 716 | if (rect == NULL || rect->isEmpty()) { |
| 717 | realRect.clear(); |
| 718 | } else { |
| 719 | realRect = *rect; |
Mathias Agopian | 55fa251 | 2010-03-11 15:06:54 -0800 | [diff] [blame] | 720 | } |
| 721 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 722 | ALOGV("Surface::setCrop rect=[%d %d %d %d]", |
| 723 | realRect.left, realRect.top, realRect.right, realRect.bottom); |
| 724 | |
| 725 | Mutex::Autolock lock(mMutex); |
| 726 | mCrop = realRect; |
| 727 | return NO_ERROR; |
| 728 | } |
| 729 | |
| 730 | int Surface::setBufferCount(int bufferCount) |
| 731 | { |
| 732 | ATRACE_CALL(); |
| 733 | ALOGV("Surface::setBufferCount"); |
| 734 | Mutex::Autolock lock(mMutex); |
| 735 | |
| 736 | status_t err = mGraphicBufferProducer->setBufferCount(bufferCount); |
| 737 | ALOGE_IF(err, "IGraphicBufferProducer::setBufferCount(%d) returned %s", |
| 738 | bufferCount, strerror(-err)); |
Mathias Agopian | 9014726 | 2010-01-22 11:47:55 -0800 | [diff] [blame] | 739 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 740 | if (err == NO_ERROR) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 741 | freeAllBuffers(); |
Mathias Agopian | 87a96ea | 2011-08-23 21:09:41 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 744 | return err; |
| 745 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 746 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 747 | int Surface::setBuffersDimensions(uint32_t width, uint32_t height) |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 748 | { |
| 749 | ATRACE_CALL(); |
| 750 | ALOGV("Surface::setBuffersDimensions"); |
| 751 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 752 | if ((width && !height) || (!width && height)) |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 753 | return BAD_VALUE; |
| 754 | |
| 755 | Mutex::Autolock lock(mMutex); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 756 | mReqWidth = width; |
| 757 | mReqHeight = height; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 758 | return NO_ERROR; |
| 759 | } |
| 760 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 761 | int Surface::setBuffersUserDimensions(uint32_t width, uint32_t height) |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 762 | { |
| 763 | ATRACE_CALL(); |
| 764 | ALOGV("Surface::setBuffersUserDimensions"); |
| 765 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 766 | if ((width && !height) || (!width && height)) |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 767 | return BAD_VALUE; |
| 768 | |
| 769 | Mutex::Autolock lock(mMutex); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 770 | mUserWidth = width; |
| 771 | mUserHeight = height; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 772 | return NO_ERROR; |
| 773 | } |
| 774 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 775 | int Surface::setBuffersFormat(PixelFormat format) |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 776 | { |
| 777 | ALOGV("Surface::setBuffersFormat"); |
| 778 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 779 | Mutex::Autolock lock(mMutex); |
| 780 | mReqFormat = format; |
| 781 | return NO_ERROR; |
| 782 | } |
| 783 | |
| 784 | int Surface::setScalingMode(int mode) |
| 785 | { |
| 786 | ATRACE_CALL(); |
| 787 | ALOGV("Surface::setScalingMode(%d)", mode); |
| 788 | |
| 789 | switch (mode) { |
| 790 | case NATIVE_WINDOW_SCALING_MODE_FREEZE: |
| 791 | case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW: |
| 792 | case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP: |
| 793 | break; |
| 794 | default: |
| 795 | ALOGE("unknown scaling mode: %d", mode); |
| 796 | return BAD_VALUE; |
| 797 | } |
| 798 | |
| 799 | Mutex::Autolock lock(mMutex); |
| 800 | mScalingMode = mode; |
| 801 | return NO_ERROR; |
| 802 | } |
| 803 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 804 | int Surface::setBuffersTransform(uint32_t transform) |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 805 | { |
| 806 | ATRACE_CALL(); |
| 807 | ALOGV("Surface::setBuffersTransform"); |
| 808 | Mutex::Autolock lock(mMutex); |
| 809 | mTransform = transform; |
| 810 | return NO_ERROR; |
| 811 | } |
| 812 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 813 | int Surface::setBuffersStickyTransform(uint32_t transform) |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 814 | { |
| 815 | ATRACE_CALL(); |
| 816 | ALOGV("Surface::setBuffersStickyTransform"); |
| 817 | Mutex::Autolock lock(mMutex); |
| 818 | mStickyTransform = transform; |
| 819 | return NO_ERROR; |
| 820 | } |
| 821 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 822 | int Surface::setBuffersTimestamp(int64_t timestamp) |
| 823 | { |
| 824 | ALOGV("Surface::setBuffersTimestamp"); |
| 825 | Mutex::Autolock lock(mMutex); |
| 826 | mTimestamp = timestamp; |
| 827 | return NO_ERROR; |
| 828 | } |
| 829 | |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 830 | int Surface::setBuffersDataSpace(android_dataspace dataSpace) |
| 831 | { |
| 832 | ALOGV("Surface::setBuffersDataSpace"); |
| 833 | Mutex::Autolock lock(mMutex); |
| 834 | mDataSpace = dataSpace; |
| 835 | return NO_ERROR; |
| 836 | } |
| 837 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 838 | void Surface::freeAllBuffers() { |
| 839 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
| 840 | mSlots[i].buffer = 0; |
| 841 | } |
| 842 | } |
| 843 | |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 844 | void Surface::setSurfaceDamage(android_native_rect_t* rects, size_t numRects) { |
| 845 | ATRACE_CALL(); |
| 846 | ALOGV("Surface::setSurfaceDamage"); |
| 847 | Mutex::Autolock lock(mMutex); |
| 848 | |
Dan Stoza | c62acbd | 2015-04-21 16:42:49 -0700 | [diff] [blame^] | 849 | if (mConnectedToCpu || numRects == 0) { |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 850 | mDirtyRegion = Region::INVALID_REGION; |
| 851 | return; |
| 852 | } |
| 853 | |
| 854 | mDirtyRegion.clear(); |
| 855 | for (size_t r = 0; r < numRects; ++r) { |
| 856 | // We intentionally flip top and bottom here, since because they're |
| 857 | // specified with a bottom-left origin, top > bottom, which fails |
| 858 | // validation in the Region class. We will fix this up when we flip to a |
| 859 | // top-left origin in queueBuffer. |
| 860 | Rect rect(rects[r].left, rects[r].bottom, rects[r].right, rects[r].top); |
| 861 | mDirtyRegion.orSelf(rect); |
| 862 | } |
| 863 | } |
| 864 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 865 | // ---------------------------------------------------------------------- |
| 866 | // the lock/unlock APIs must be used from the same thread |
| 867 | |
| 868 | static status_t copyBlt( |
| 869 | const sp<GraphicBuffer>& dst, |
| 870 | const sp<GraphicBuffer>& src, |
| 871 | const Region& reg) |
| 872 | { |
| 873 | // src and dst with, height and format must be identical. no verification |
| 874 | // is done here. |
| 875 | status_t err; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 876 | uint8_t* src_bits = NULL; |
| 877 | err = src->lock(GRALLOC_USAGE_SW_READ_OFTEN, reg.bounds(), |
| 878 | reinterpret_cast<void**>(&src_bits)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 879 | ALOGE_IF(err, "error locking src buffer %s", strerror(-err)); |
| 880 | |
| 881 | uint8_t* dst_bits = NULL; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 882 | err = dst->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, reg.bounds(), |
| 883 | reinterpret_cast<void**>(&dst_bits)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 884 | ALOGE_IF(err, "error locking dst buffer %s", strerror(-err)); |
| 885 | |
| 886 | Region::const_iterator head(reg.begin()); |
| 887 | Region::const_iterator tail(reg.end()); |
| 888 | if (head != tail && src_bits && dst_bits) { |
| 889 | const size_t bpp = bytesPerPixel(src->format); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 890 | const size_t dbpr = static_cast<uint32_t>(dst->stride) * bpp; |
| 891 | const size_t sbpr = static_cast<uint32_t>(src->stride) * bpp; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 892 | |
| 893 | while (head != tail) { |
| 894 | const Rect& r(*head++); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 895 | int32_t h = r.height(); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 896 | if (h <= 0) continue; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 897 | size_t size = static_cast<uint32_t>(r.width()) * bpp; |
| 898 | uint8_t const * s = src_bits + |
| 899 | static_cast<uint32_t>(r.left + src->stride * r.top) * bpp; |
| 900 | uint8_t * d = dst_bits + |
| 901 | static_cast<uint32_t>(r.left + dst->stride * r.top) * bpp; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 902 | if (dbpr==sbpr && size==sbpr) { |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 903 | size *= static_cast<size_t>(h); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 904 | h = 1; |
| 905 | } |
| 906 | do { |
| 907 | memcpy(d, s, size); |
| 908 | d += dbpr; |
| 909 | s += sbpr; |
| 910 | } while (--h > 0); |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | if (src_bits) |
| 915 | src->unlock(); |
| 916 | |
| 917 | if (dst_bits) |
| 918 | dst->unlock(); |
| 919 | |
| 920 | return err; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | } |
| 922 | |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 923 | // ---------------------------------------------------------------------------- |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 924 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 925 | status_t Surface::lock( |
| 926 | ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds) |
| 927 | { |
| 928 | if (mLockedBuffer != 0) { |
| 929 | ALOGE("Surface::lock failed, already locked"); |
| 930 | return INVALID_OPERATION; |
| 931 | } |
| 932 | |
| 933 | if (!mConnectedToCpu) { |
| 934 | int err = Surface::connect(NATIVE_WINDOW_API_CPU); |
| 935 | if (err) { |
| 936 | return err; |
| 937 | } |
| 938 | // we're intending to do software rendering from this point |
| 939 | setUsage(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); |
| 940 | } |
| 941 | |
| 942 | ANativeWindowBuffer* out; |
| 943 | int fenceFd = -1; |
| 944 | status_t err = dequeueBuffer(&out, &fenceFd); |
| 945 | ALOGE_IF(err, "dequeueBuffer failed (%s)", strerror(-err)); |
| 946 | if (err == NO_ERROR) { |
| 947 | sp<GraphicBuffer> backBuffer(GraphicBuffer::getSelf(out)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 948 | const Rect bounds(backBuffer->width, backBuffer->height); |
| 949 | |
| 950 | Region newDirtyRegion; |
| 951 | if (inOutDirtyBounds) { |
| 952 | newDirtyRegion.set(static_cast<Rect const&>(*inOutDirtyBounds)); |
| 953 | newDirtyRegion.andSelf(bounds); |
| 954 | } else { |
| 955 | newDirtyRegion.set(bounds); |
| 956 | } |
| 957 | |
| 958 | // figure out if we can copy the frontbuffer back |
| 959 | const sp<GraphicBuffer>& frontBuffer(mPostedBuffer); |
| 960 | const bool canCopyBack = (frontBuffer != 0 && |
| 961 | backBuffer->width == frontBuffer->width && |
| 962 | backBuffer->height == frontBuffer->height && |
| 963 | backBuffer->format == frontBuffer->format); |
| 964 | |
| 965 | if (canCopyBack) { |
| 966 | // copy the area that is invalid and not repainted this round |
| 967 | const Region copyback(mDirtyRegion.subtract(newDirtyRegion)); |
| 968 | if (!copyback.isEmpty()) |
| 969 | copyBlt(backBuffer, frontBuffer, copyback); |
| 970 | } else { |
| 971 | // if we can't copy-back anything, modify the user's dirty |
| 972 | // region to make sure they redraw the whole buffer |
| 973 | newDirtyRegion.set(bounds); |
| 974 | mDirtyRegion.clear(); |
| 975 | Mutex::Autolock lock(mMutex); |
| 976 | for (size_t i=0 ; i<NUM_BUFFER_SLOTS ; i++) { |
| 977 | mSlots[i].dirtyRegion.clear(); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | |
| 982 | { // scope for the lock |
| 983 | Mutex::Autolock lock(mMutex); |
| 984 | int backBufferSlot(getSlotFromBufferLocked(backBuffer.get())); |
| 985 | if (backBufferSlot >= 0) { |
| 986 | Region& dirtyRegion(mSlots[backBufferSlot].dirtyRegion); |
| 987 | mDirtyRegion.subtract(dirtyRegion); |
| 988 | dirtyRegion = newDirtyRegion; |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | mDirtyRegion.orSelf(newDirtyRegion); |
| 993 | if (inOutDirtyBounds) { |
| 994 | *inOutDirtyBounds = newDirtyRegion.getBounds(); |
| 995 | } |
| 996 | |
| 997 | void* vaddr; |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 998 | status_t res = backBuffer->lockAsync( |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 999 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 1000 | newDirtyRegion.bounds(), &vaddr, fenceFd); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1001 | |
| 1002 | ALOGW_IF(res, "failed locking buffer (handle = %p)", |
| 1003 | backBuffer->handle); |
| 1004 | |
| 1005 | if (res != 0) { |
| 1006 | err = INVALID_OPERATION; |
| 1007 | } else { |
| 1008 | mLockedBuffer = backBuffer; |
| 1009 | outBuffer->width = backBuffer->width; |
| 1010 | outBuffer->height = backBuffer->height; |
| 1011 | outBuffer->stride = backBuffer->stride; |
| 1012 | outBuffer->format = backBuffer->format; |
| 1013 | outBuffer->bits = vaddr; |
| 1014 | } |
| 1015 | } |
| 1016 | return err; |
| 1017 | } |
| 1018 | |
| 1019 | status_t Surface::unlockAndPost() |
| 1020 | { |
| 1021 | if (mLockedBuffer == 0) { |
| 1022 | ALOGE("Surface::unlockAndPost failed, no locked buffer"); |
| 1023 | return INVALID_OPERATION; |
| 1024 | } |
| 1025 | |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 1026 | int fd = -1; |
| 1027 | status_t err = mLockedBuffer->unlockAsync(&fd); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1028 | ALOGE_IF(err, "failed unlocking buffer (%p)", mLockedBuffer->handle); |
| 1029 | |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 1030 | err = queueBuffer(mLockedBuffer.get(), fd); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 1031 | ALOGE_IF(err, "queueBuffer (handle=%p) failed (%s)", |
| 1032 | mLockedBuffer->handle, strerror(-err)); |
| 1033 | |
| 1034 | mPostedBuffer = mLockedBuffer; |
| 1035 | mLockedBuffer = 0; |
| 1036 | return err; |
| 1037 | } |
| 1038 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | }; // namespace android |