blob: b7af1681a0def83c1fa0cbdd40538a86bb206e83 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
Mathias Agopiane3c697f2013-02-14 17:11:02 -08002 * Copyright (C) 2010 The Android Open Source Project
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08003 *
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 Agopiane3c697f2013-02-14 17:11:02 -080018#define ATRACE_TAG ATRACE_TAG_GRAPHICS
19//#define LOG_NDEBUG 0
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080020
Mathias Agopian05debe12017-02-08 17:04:18 -080021#include <gui/Surface.h>
Mathias Agopianb0e76f42012-03-23 14:15:44 -070022
Mathias Agopian05debe12017-02-08 17:04:18 -080023#include <android/native_window.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080024
Mathias Agopian9cce3252010-02-09 17:46:37 -080025#include <utils/Log.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080026#include <utils/Trace.h>
Rachad7cb0d392014-07-29 17:53:53 -070027#include <utils/NativeHandle.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080028
Mathias Agopiane3c697f2013-02-14 17:11:02 -080029#include <ui/Fence.h>
Dan Stoza5065a552015-03-17 16:23:42 -070030#include <ui/Region.h>
Ian Elliott62c48c92017-01-20 13:13:20 -070031#include <ui/DisplayStatInfo.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070032
Mathias Agopian2b5dd402017-02-07 17:36:19 -080033#include <gui/BufferItem.h>
Dan Stozaf0eaf252014-03-21 13:05:51 -070034#include <gui/IProducerListener.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080035
Mathias Agopian2b5dd402017-02-07 17:36:19 -080036#include <gui/ISurfaceComposer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080037#include <private/gui/ComposerService.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070038
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039namespace android {
40
Mathias Agopiane3c697f2013-02-14 17:11:02 -080041Surface::Surface(
Mathias Agopian595264f2013-07-16 22:56:09 -070042 const sp<IGraphicBufferProducer>& bufferProducer,
43 bool controlledByApp)
Dan Stoza812ed062015-06-02 15:45:22 -070044 : mGraphicBufferProducer(bufferProducer),
Pablo Ceballos60d69222015-08-07 14:47:20 -070045 mCrop(Rect::EMPTY_RECT),
Pablo Ceballosff95aab2016-01-13 17:09:58 -080046 mGenerationNumber(0),
Pablo Ceballos3559fbf2016-03-17 15:50:23 -070047 mSharedBufferMode(false),
Pablo Ceballosff95aab2016-01-13 17:09:58 -080048 mAutoRefresh(false),
49 mSharedBufferSlot(BufferItem::INVALID_BUFFER_SLOT),
Pablo Ceballosbc8c1922016-07-01 14:15:41 -070050 mSharedBufferHasBeenQueued(false),
Brian Anderson069b3652016-07-22 10:32:47 -070051 mQueriedSupportedTimestamps(false),
52 mFrameTimestampsSupportsPresent(false),
Brian Anderson7c3ba8a2016-07-25 12:48:08 -070053 mFrameTimestampsSupportsRetire(false),
Brian Anderson3da8d272016-07-28 16:20:47 -070054 mEnableFrameTimestamps(false),
55 mFrameEventHistory(std::make_unique<ProducerFrameEventHistory>())
Mathias Agopian62185b72009-04-16 16:19:50 -070056{
Mathias Agopiane3c697f2013-02-14 17:11:02 -080057 // Initialize the ANativeWindow function pointers.
58 ANativeWindow::setSwapInterval = hook_setSwapInterval;
59 ANativeWindow::dequeueBuffer = hook_dequeueBuffer;
60 ANativeWindow::cancelBuffer = hook_cancelBuffer;
61 ANativeWindow::queueBuffer = hook_queueBuffer;
62 ANativeWindow::query = hook_query;
63 ANativeWindow::perform = hook_perform;
64
65 ANativeWindow::dequeueBuffer_DEPRECATED = hook_dequeueBuffer_DEPRECATED;
66 ANativeWindow::cancelBuffer_DEPRECATED = hook_cancelBuffer_DEPRECATED;
67 ANativeWindow::lockBuffer_DEPRECATED = hook_lockBuffer_DEPRECATED;
68 ANativeWindow::queueBuffer_DEPRECATED = hook_queueBuffer_DEPRECATED;
69
70 const_cast<int&>(ANativeWindow::minSwapInterval) = 0;
71 const_cast<int&>(ANativeWindow::maxSwapInterval) = 1;
72
73 mReqWidth = 0;
74 mReqHeight = 0;
75 mReqFormat = 0;
76 mReqUsage = 0;
77 mTimestamp = NATIVE_WINDOW_TIMESTAMP_AUTO;
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -080078 mDataSpace = HAL_DATASPACE_UNKNOWN;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080079 mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
80 mTransform = 0;
Ruben Brunk1681d952014-06-27 15:51:55 -070081 mStickyTransform = 0;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080082 mDefaultWidth = 0;
83 mDefaultHeight = 0;
84 mUserWidth = 0;
85 mUserHeight = 0;
86 mTransformHint = 0;
87 mConsumerRunningBehind = false;
88 mConnectedToCpu = false;
Eino-Ville Talvala7895e902013-08-21 11:53:37 -070089 mProducerControlledByApp = controlledByApp;
Mathias Agopian7cdd7862013-07-18 22:10:56 -070090 mSwapIntervalZero = false;
Mathias Agopian62185b72009-04-16 16:19:50 -070091}
92
Mathias Agopian35ffa6a2013-03-12 18:45:09 -070093Surface::~Surface() {
94 if (mConnectedToCpu) {
95 Surface::disconnect(NATIVE_WINDOW_API_CPU);
96 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -080097}
98
Brian Anderson3da8d272016-07-28 16:20:47 -070099sp<ISurfaceComposer> Surface::composerService() const {
100 return ComposerService::getComposerService();
101}
102
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800103nsecs_t Surface::now() const {
104 return systemTime();
105}
106
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800107sp<IGraphicBufferProducer> Surface::getIGraphicBufferProducer() const {
108 return mGraphicBufferProducer;
109}
110
Wonsik Kim0ee14ca2014-03-17 17:46:53 +0900111void Surface::setSidebandStream(const sp<NativeHandle>& stream) {
112 mGraphicBufferProducer->setSidebandStream(stream);
113}
114
Dan Stoza29a3e902014-06-20 13:13:57 -0700115void Surface::allocateBuffers() {
116 uint32_t reqWidth = mReqWidth ? mReqWidth : mUserWidth;
117 uint32_t reqHeight = mReqHeight ? mReqHeight : mUserHeight;
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700118 mGraphicBufferProducer->allocateBuffers(reqWidth, reqHeight,
119 mReqFormat, mReqUsage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700120}
121
Dan Stoza812ed062015-06-02 15:45:22 -0700122status_t Surface::setGenerationNumber(uint32_t generation) {
123 status_t result = mGraphicBufferProducer->setGenerationNumber(generation);
124 if (result == NO_ERROR) {
125 mGenerationNumber = generation;
126 }
127 return result;
128}
129
Dan Stoza7dde5992015-05-22 09:51:44 -0700130uint64_t Surface::getNextFrameNumber() const {
Pablo Ceballosbc8c1922016-07-01 14:15:41 -0700131 Mutex::Autolock lock(mMutex);
132 return mNextFrameNumber;
Dan Stoza7dde5992015-05-22 09:51:44 -0700133}
134
Dan Stozac6f30bd2015-06-08 09:32:50 -0700135String8 Surface::getConsumerName() const {
136 return mGraphicBufferProducer->getConsumerName();
137}
138
Dan Stoza127fc632015-06-30 13:43:32 -0700139status_t Surface::setDequeueTimeout(nsecs_t timeout) {
140 return mGraphicBufferProducer->setDequeueTimeout(timeout);
141}
142
Dan Stoza50101d02016-04-07 16:53:23 -0700143status_t Surface::getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
John Reck1a61da52016-04-28 13:18:15 -0700144 sp<Fence>* outFence, float outTransformMatrix[16]) {
145 return mGraphicBufferProducer->getLastQueuedBuffer(outBuffer, outFence,
146 outTransformMatrix);
Dan Stoza50101d02016-04-07 16:53:23 -0700147}
148
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800149status_t Surface::getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration) {
150 ATRACE_CALL();
151
152 DisplayStatInfo stats;
153 status_t err = composerService()->getDisplayStats(NULL, &stats);
154
155 *outRefreshDuration = stats.vsyncPeriod;
156
157 return NO_ERROR;
158}
159
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700160void Surface::enableFrameTimestamps(bool enable) {
161 Mutex::Autolock lock(mMutex);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800162 // If going from disabled to enabled, get the initial values for
163 // compositor and display timing.
164 if (!mEnableFrameTimestamps && enable) {
165 FrameEventHistoryDelta delta;
166 mGraphicBufferProducer->getFrameTimestamps(&delta);
167 mFrameEventHistory->applyDelta(delta);
168 }
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700169 mEnableFrameTimestamps = enable;
170}
171
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800172status_t Surface::getCompositorTiming(
173 nsecs_t* compositeDeadline, nsecs_t* compositeInterval,
174 nsecs_t* compositeToPresentLatency) {
175 Mutex::Autolock lock(mMutex);
176 if (!mEnableFrameTimestamps) {
177 return INVALID_OPERATION;
178 }
179
180 if (compositeDeadline != nullptr) {
181 *compositeDeadline =
182 mFrameEventHistory->getNextCompositeDeadline(now());
183 }
184 if (compositeInterval != nullptr) {
185 *compositeInterval = mFrameEventHistory->getCompositeInterval();
186 }
187 if (compositeToPresentLatency != nullptr) {
188 *compositeToPresentLatency =
189 mFrameEventHistory->getCompositeToPresentLatency();
190 }
191 return NO_ERROR;
192}
193
Brian Anderson50143b32016-09-30 14:01:24 -0700194static bool checkConsumerForUpdates(
195 const FrameEvents* e, const uint64_t lastFrameNumber,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700196 const nsecs_t* outLatchTime,
197 const nsecs_t* outFirstRefreshStartTime,
198 const nsecs_t* outLastRefreshStartTime,
Brian Andersonb04c6f02016-10-21 12:57:46 -0700199 const nsecs_t* outGpuCompositionDoneTime,
Brian Anderson50143b32016-09-30 14:01:24 -0700200 const nsecs_t* outDisplayPresentTime,
201 const nsecs_t* outDisplayRetireTime,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700202 const nsecs_t* outDequeueReadyTime,
Brian Anderson50143b32016-09-30 14:01:24 -0700203 const nsecs_t* outReleaseTime) {
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700204 bool checkForLatch = (outLatchTime != nullptr) && !e->hasLatchInfo();
205 bool checkForFirstRefreshStart = (outFirstRefreshStartTime != nullptr) &&
Brian Anderson50143b32016-09-30 14:01:24 -0700206 !e->hasFirstRefreshStartInfo();
Brian Andersonb04c6f02016-10-21 12:57:46 -0700207 bool checkForGpuCompositionDone = (outGpuCompositionDoneTime != nullptr) &&
Brian Anderson50143b32016-09-30 14:01:24 -0700208 !e->hasGpuCompositionDoneInfo();
209 bool checkForDisplayPresent = (outDisplayPresentTime != nullptr) &&
210 !e->hasDisplayPresentInfo();
211
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700212 // LastRefreshStart, DisplayRetire, DequeueReady, and Release are never
213 // available for the last frame.
214 bool checkForLastRefreshStart = (outLastRefreshStartTime != nullptr) &&
215 !e->hasLastRefreshStartInfo() &&
216 (e->frameNumber != lastFrameNumber);
Brian Anderson50143b32016-09-30 14:01:24 -0700217 bool checkForDisplayRetire = (outDisplayRetireTime != nullptr) &&
218 !e->hasDisplayRetireInfo() && (e->frameNumber != lastFrameNumber);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700219 bool checkForDequeueReady = (outDequeueReadyTime != nullptr) &&
220 !e->hasDequeueReadyInfo() && (e->frameNumber != lastFrameNumber);
Brian Anderson50143b32016-09-30 14:01:24 -0700221 bool checkForRelease = (outReleaseTime != nullptr) &&
222 !e->hasReleaseInfo() && (e->frameNumber != lastFrameNumber);
223
224 // RequestedPresent and Acquire info are always available producer-side.
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700225 return checkForLatch || checkForFirstRefreshStart ||
Brian Andersonb04c6f02016-10-21 12:57:46 -0700226 checkForLastRefreshStart || checkForGpuCompositionDone ||
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700227 checkForDisplayPresent || checkForDisplayRetire ||
228 checkForDequeueReady || checkForRelease;
Brian Anderson50143b32016-09-30 14:01:24 -0700229}
230
Brian Anderson3d4039d2016-09-23 16:31:30 -0700231static void getFrameTimestamp(nsecs_t *dst, const nsecs_t& src) {
232 if (dst != nullptr) {
Brian Andersoned816e62016-10-26 16:12:21 -0700233 *dst = FrameEvents::isValidTimestamp(src) ? src : 0;
Brian Anderson3d4039d2016-09-23 16:31:30 -0700234 }
235}
236
237static void getFrameTimestampFence(nsecs_t *dst, const std::shared_ptr<FenceTime>& src) {
238 if (dst != nullptr) {
239 nsecs_t signalTime = src->getSignalTime();
240 *dst = Fence::isValidTimestamp(signalTime) ? signalTime : 0;
241 }
242}
243
Brian Anderson069b3652016-07-22 10:32:47 -0700244status_t Surface::getFrameTimestamps(uint64_t frameNumber,
Brian Andersondbd0ea82016-07-22 09:38:59 -0700245 nsecs_t* outRequestedPresentTime, nsecs_t* outAcquireTime,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700246 nsecs_t* outLatchTime, nsecs_t* outFirstRefreshStartTime,
Brian Andersonb04c6f02016-10-21 12:57:46 -0700247 nsecs_t* outLastRefreshStartTime, nsecs_t* outGpuCompositionDoneTime,
Brian Anderson069b3652016-07-22 10:32:47 -0700248 nsecs_t* outDisplayPresentTime, nsecs_t* outDisplayRetireTime,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700249 nsecs_t* outDequeueReadyTime, nsecs_t* outReleaseTime) {
Pablo Ceballosce796e72016-02-04 19:10:51 -0800250 ATRACE_CALL();
251
Brian Anderson3890c392016-07-25 12:48:08 -0700252 Mutex::Autolock lock(mMutex);
Brian Anderson069b3652016-07-22 10:32:47 -0700253
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700254 if (!mEnableFrameTimestamps) {
255 return INVALID_OPERATION;
256 }
257
Brian Anderson3890c392016-07-25 12:48:08 -0700258 // Verify the requested timestamps are supported.
259 querySupportedTimestampsLocked();
260 if (outDisplayPresentTime != nullptr && !mFrameTimestampsSupportsPresent) {
261 return BAD_VALUE;
262 }
263 if (outDisplayRetireTime != nullptr && !mFrameTimestampsSupportsRetire) {
264 return BAD_VALUE;
Brian Anderson069b3652016-07-22 10:32:47 -0700265 }
266
Brian Anderson3da8d272016-07-28 16:20:47 -0700267 FrameEvents* events = mFrameEventHistory->getFrame(frameNumber);
Brian Anderson50143b32016-09-30 14:01:24 -0700268 if (events == nullptr) {
269 // If the entry isn't available in the producer, it's definitely not
270 // available in the consumer.
271 return NAME_NOT_FOUND;
Brian Anderson3890c392016-07-25 12:48:08 -0700272 }
273
Brian Anderson50143b32016-09-30 14:01:24 -0700274 // Update our cache of events if the requested events are not available.
275 if (checkConsumerForUpdates(events, mLastFrameNumber,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700276 outLatchTime, outFirstRefreshStartTime, outLastRefreshStartTime,
Brian Andersonb04c6f02016-10-21 12:57:46 -0700277 outGpuCompositionDoneTime, outDisplayPresentTime,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700278 outDisplayRetireTime, outDequeueReadyTime, outReleaseTime)) {
Brian Anderson50143b32016-09-30 14:01:24 -0700279 FrameEventHistoryDelta delta;
280 mGraphicBufferProducer->getFrameTimestamps(&delta);
Brian Anderson3da8d272016-07-28 16:20:47 -0700281 mFrameEventHistory->applyDelta(delta);
282 events = mFrameEventHistory->getFrame(frameNumber);
Brian Anderson50143b32016-09-30 14:01:24 -0700283 }
284
Brian Anderson3890c392016-07-25 12:48:08 -0700285 if (events == nullptr) {
Brian Anderson50143b32016-09-30 14:01:24 -0700286 // The entry was available before the update, but was overwritten
287 // after the update. Make sure not to send the wrong frame's data.
Brian Anderson069b3652016-07-22 10:32:47 -0700288 return NAME_NOT_FOUND;
Pablo Ceballosce796e72016-02-04 19:10:51 -0800289 }
Brian Anderson069b3652016-07-22 10:32:47 -0700290
Brian Anderson3d4039d2016-09-23 16:31:30 -0700291 getFrameTimestamp(outRequestedPresentTime, events->requestedPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700292 getFrameTimestamp(outLatchTime, events->latchTime);
293 getFrameTimestamp(outFirstRefreshStartTime, events->firstRefreshStartTime);
294 getFrameTimestamp(outLastRefreshStartTime, events->lastRefreshStartTime);
295 getFrameTimestamp(outDequeueReadyTime, events->dequeueReadyTime);
Brian Anderson3890c392016-07-25 12:48:08 -0700296
Brian Anderson3d4039d2016-09-23 16:31:30 -0700297 getFrameTimestampFence(outAcquireTime, events->acquireFence);
298 getFrameTimestampFence(
Brian Andersonb04c6f02016-10-21 12:57:46 -0700299 outGpuCompositionDoneTime, events->gpuCompositionDoneFence);
Brian Anderson3d4039d2016-09-23 16:31:30 -0700300 getFrameTimestampFence(
301 outDisplayPresentTime, events->displayPresentFence);
302 getFrameTimestampFence(outDisplayRetireTime, events->displayRetireFence);
303 getFrameTimestampFence(outReleaseTime, events->releaseFence);
Brian Anderson069b3652016-07-22 10:32:47 -0700304
305 return NO_ERROR;
Pablo Ceballosce796e72016-02-04 19:10:51 -0800306}
307
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700308status_t Surface::getWideColorSupport(bool* supported) {
309 ATRACE_CALL();
310
311 sp<IBinder> display(
312 composerService()->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
313 Vector<android_color_mode_t> colorModes;
314 status_t err =
315 composerService()->getDisplayColorModes(display, &colorModes);
316
317 if (err)
318 return err;
319
320 *supported = false;
321 for (android_color_mode_t colorMode : colorModes) {
322 switch (colorMode) {
323 case HAL_COLOR_MODE_DISPLAY_P3:
324 case HAL_COLOR_MODE_ADOBE_RGB:
325 case HAL_COLOR_MODE_DCI_P3:
326 *supported = true;
327 break;
328 default:
329 break;
330 }
331 }
332
333 return NO_ERROR;
334}
335
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800336int Surface::hook_setSwapInterval(ANativeWindow* window, int interval) {
337 Surface* c = getSelf(window);
338 return c->setSwapInterval(interval);
339}
340
341int Surface::hook_dequeueBuffer(ANativeWindow* window,
342 ANativeWindowBuffer** buffer, int* fenceFd) {
343 Surface* c = getSelf(window);
344 return c->dequeueBuffer(buffer, fenceFd);
345}
346
347int Surface::hook_cancelBuffer(ANativeWindow* window,
348 ANativeWindowBuffer* buffer, int fenceFd) {
349 Surface* c = getSelf(window);
350 return c->cancelBuffer(buffer, fenceFd);
351}
352
353int Surface::hook_queueBuffer(ANativeWindow* window,
354 ANativeWindowBuffer* buffer, int fenceFd) {
355 Surface* c = getSelf(window);
356 return c->queueBuffer(buffer, fenceFd);
357}
358
359int Surface::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
360 ANativeWindowBuffer** buffer) {
361 Surface* c = getSelf(window);
362 ANativeWindowBuffer* buf;
363 int fenceFd = -1;
364 int result = c->dequeueBuffer(&buf, &fenceFd);
Mike Stroyan87709c92016-06-03 12:43:26 -0600365 if (result != OK) {
366 return result;
367 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800368 sp<Fence> fence(new Fence(fenceFd));
Mathias Agopianea74d3b2013-05-16 18:03:22 -0700369 int waitResult = fence->waitForever("dequeueBuffer_DEPRECATED");
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800370 if (waitResult != OK) {
371 ALOGE("dequeueBuffer_DEPRECATED: Fence::wait returned an error: %d",
372 waitResult);
373 c->cancelBuffer(buf, -1);
374 return waitResult;
Mathias Agopian62185b72009-04-16 16:19:50 -0700375 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800376 *buffer = buf;
377 return result;
Mathias Agopian62185b72009-04-16 16:19:50 -0700378}
379
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800380int Surface::hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
381 ANativeWindowBuffer* buffer) {
382 Surface* c = getSelf(window);
383 return c->cancelBuffer(buffer, -1);
Mathias Agopian62185b72009-04-16 16:19:50 -0700384}
385
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800386int Surface::hook_lockBuffer_DEPRECATED(ANativeWindow* window,
387 ANativeWindowBuffer* buffer) {
388 Surface* c = getSelf(window);
389 return c->lockBuffer_DEPRECATED(buffer);
Mathias Agopian62185b72009-04-16 16:19:50 -0700390}
391
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800392int Surface::hook_queueBuffer_DEPRECATED(ANativeWindow* window,
393 ANativeWindowBuffer* buffer) {
394 Surface* c = getSelf(window);
395 return c->queueBuffer(buffer, -1);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700396}
Mathias Agopian62185b72009-04-16 16:19:50 -0700397
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800398int Surface::hook_query(const ANativeWindow* window,
399 int what, int* value) {
400 const Surface* c = getSelf(window);
401 return c->query(what, value);
402}
403
404int Surface::hook_perform(ANativeWindow* window, int operation, ...) {
405 va_list args;
406 va_start(args, operation);
407 Surface* c = getSelf(window);
Haixia Shid89c2bb2015-09-14 11:02:18 -0700408 int result = c->perform(operation, args);
409 va_end(args);
410 return result;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800411}
412
413int Surface::setSwapInterval(int interval) {
414 ATRACE_CALL();
415 // EGL specification states:
416 // interval is silently clamped to minimum and maximum implementation
417 // dependent values before being stored.
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800418
419 if (interval < minSwapInterval)
420 interval = minSwapInterval;
421
422 if (interval > maxSwapInterval)
423 interval = maxSwapInterval;
424
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700425 mSwapIntervalZero = (interval == 0);
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700426 mGraphicBufferProducer->setAsyncMode(mSwapIntervalZero);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800427
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700428 return NO_ERROR;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800429}
430
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700431int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) {
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800432 ATRACE_CALL();
433 ALOGV("Surface::dequeueBuffer");
Igor Murashkin0f1889e2014-02-28 18:44:21 -0800434
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800435 uint32_t reqWidth;
436 uint32_t reqHeight;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800437 PixelFormat reqFormat;
Igor Murashkin0f1889e2014-02-28 18:44:21 -0800438 uint32_t reqUsage;
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700439 bool enableFrameTimestamps;
Igor Murashkin0f1889e2014-02-28 18:44:21 -0800440
441 {
442 Mutex::Autolock lock(mMutex);
443
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800444 reqWidth = mReqWidth ? mReqWidth : mUserWidth;
445 reqHeight = mReqHeight ? mReqHeight : mUserHeight;
Igor Murashkin0f1889e2014-02-28 18:44:21 -0800446
Igor Murashkin0f1889e2014-02-28 18:44:21 -0800447 reqFormat = mReqFormat;
448 reqUsage = mReqUsage;
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800449
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700450 enableFrameTimestamps = mEnableFrameTimestamps;
451
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700452 if (mSharedBufferMode && mAutoRefresh && mSharedBufferSlot !=
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800453 BufferItem::INVALID_BUFFER_SLOT) {
454 sp<GraphicBuffer>& gbuf(mSlots[mSharedBufferSlot].buffer);
455 if (gbuf != NULL) {
456 *buffer = gbuf.get();
457 *fenceFd = -1;
458 return OK;
459 }
460 }
Igor Murashkin0f1889e2014-02-28 18:44:21 -0800461 } // Drop the lock so that we can still touch the Surface while blocking in IGBP::dequeueBuffer
462
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800463 int buf = -1;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800464 sp<Fence> fence;
Dan Stoza70ccba52016-07-01 14:00:40 -0700465 nsecs_t now = systemTime();
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700466
467 FrameEventHistoryDelta frameTimestamps;
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700468 status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence,
Brian Anderson50143b32016-09-30 14:01:24 -0700469 reqWidth, reqHeight, reqFormat, reqUsage,
470 enableFrameTimestamps ? &frameTimestamps : nullptr);
Dan Stoza70ccba52016-07-01 14:00:40 -0700471 mLastDequeueDuration = systemTime() - now;
Igor Murashkin0f1889e2014-02-28 18:44:21 -0800472
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800473 if (result < 0) {
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700474 ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer"
475 "(%d, %d, %d, %d) failed: %d", reqWidth, reqHeight, reqFormat,
476 reqUsage, result);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800477 return result;
Mathias Agopian62185b72009-04-16 16:19:50 -0700478 }
Igor Murashkin0f1889e2014-02-28 18:44:21 -0800479
480 Mutex::Autolock lock(mMutex);
481
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800482 sp<GraphicBuffer>& gbuf(mSlots[buf].buffer);
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700483
484 // this should never happen
485 ALOGE_IF(fence == NULL, "Surface::dequeueBuffer: received null Fence! buf=%d", buf);
486
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800487 if (result & IGraphicBufferProducer::RELEASE_ALL_BUFFERS) {
488 freeAllBuffers();
Mathias Agopian579b3f82010-06-08 19:54:15 -0700489 }
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700490
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700491 if (enableFrameTimestamps) {
Brian Anderson3da8d272016-07-28 16:20:47 -0700492 mFrameEventHistory->applyDelta(frameTimestamps);
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700493 }
494
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800495 if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) {
496 result = mGraphicBufferProducer->requestBuffer(buf, &gbuf);
497 if (result != NO_ERROR) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700498 ALOGE("dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: %d", result);
Jesse Hall9f5a1b62014-10-02 11:09:03 -0700499 mGraphicBufferProducer->cancelBuffer(buf, fence);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800500 return result;
501 }
502 }
Mathias Agopian579b3f82010-06-08 19:54:15 -0700503
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800504 if (fence->isValid()) {
505 *fenceFd = fence->dup();
506 if (*fenceFd == -1) {
507 ALOGE("dequeueBuffer: error duping fence: %d", errno);
508 // dup() should never fail; something is badly wrong. Soldier on
509 // and hope for the best; the worst that should happen is some
510 // visible corruption that lasts until the next frame.
511 }
Ted Bonkenburge5d6eb82011-08-09 22:38:41 -0700512 } else {
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800513 *fenceFd = -1;
Mathias Agopiana0c30e92010-06-04 18:26:32 -0700514 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800515
516 *buffer = gbuf.get();
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800517
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700518 if (mSharedBufferMode && mAutoRefresh) {
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800519 mSharedBufferSlot = buf;
520 mSharedBufferHasBeenQueued = false;
521 } else if (mSharedBufferSlot == buf) {
522 mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT;
523 mSharedBufferHasBeenQueued = false;
524 }
525
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800526 return OK;
Jamie Gennisaca4e222010-07-15 17:29:15 -0700527}
528
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800529int Surface::cancelBuffer(android_native_buffer_t* buffer,
530 int fenceFd) {
531 ATRACE_CALL();
532 ALOGV("Surface::cancelBuffer");
533 Mutex::Autolock lock(mMutex);
534 int i = getSlotFromBufferLocked(buffer);
535 if (i < 0) {
Taiju Tsuiki4d0cd3f2015-04-30 22:15:33 +0900536 if (fenceFd >= 0) {
537 close(fenceFd);
538 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800539 return i;
540 }
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800541 if (mSharedBufferSlot == i && mSharedBufferHasBeenQueued) {
542 if (fenceFd >= 0) {
543 close(fenceFd);
544 }
545 return OK;
546 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800547 sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE);
548 mGraphicBufferProducer->cancelBuffer(i, fence);
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800549
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700550 if (mSharedBufferMode && mAutoRefresh && mSharedBufferSlot == i) {
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800551 mSharedBufferHasBeenQueued = true;
552 }
553
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800554 return OK;
555}
556
557int Surface::getSlotFromBufferLocked(
558 android_native_buffer_t* buffer) const {
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800559 for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
560 if (mSlots[i].buffer != NULL &&
561 mSlots[i].buffer->handle == buffer->handle) {
562 return i;
Jamie Gennisaca4e222010-07-15 17:29:15 -0700563 }
564 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800565 ALOGE("getSlotFromBufferLocked: unknown buffer: %p", buffer->handle);
566 return BAD_VALUE;
Mathias Agopiana0c30e92010-06-04 18:26:32 -0700567}
568
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800569int Surface::lockBuffer_DEPRECATED(android_native_buffer_t* buffer __attribute__((unused))) {
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800570 ALOGV("Surface::lockBuffer");
571 Mutex::Autolock lock(mMutex);
572 return OK;
573}
Mathias Agopian631f3582010-05-25 17:51:34 -0700574
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800575int Surface::queueBuffer(android_native_buffer_t* buffer, int fenceFd) {
576 ATRACE_CALL();
577 ALOGV("Surface::queueBuffer");
578 Mutex::Autolock lock(mMutex);
579 int64_t timestamp;
Andy McFadden3c256212013-08-16 14:55:39 -0700580 bool isAutoTimestamp = false;
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800581
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800582 if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) {
Andy McFadden4b49e082013-08-02 15:31:45 -0700583 timestamp = systemTime(SYSTEM_TIME_MONOTONIC);
Andy McFadden3c256212013-08-16 14:55:39 -0700584 isAutoTimestamp = true;
Andy McFadden4b49e082013-08-02 15:31:45 -0700585 ALOGV("Surface::queueBuffer making up timestamp: %.2f ms",
Colin Cross9a80d502016-09-27 14:12:48 -0700586 timestamp / 1000000.0);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800587 } else {
588 timestamp = mTimestamp;
Mathias Agopian631f3582010-05-25 17:51:34 -0700589 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800590 int i = getSlotFromBufferLocked(buffer);
591 if (i < 0) {
Taiju Tsuiki4d0cd3f2015-04-30 22:15:33 +0900592 if (fenceFd >= 0) {
593 close(fenceFd);
594 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800595 return i;
596 }
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800597 if (mSharedBufferSlot == i && mSharedBufferHasBeenQueued) {
598 if (fenceFd >= 0) {
599 close(fenceFd);
600 }
601 return OK;
602 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800603
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800604
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800605 // Make sure the crop rectangle is entirely inside the buffer.
Pablo Ceballos60d69222015-08-07 14:47:20 -0700606 Rect crop(Rect::EMPTY_RECT);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800607 mCrop.intersect(Rect(buffer->width, buffer->height), &crop);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800608
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800609 sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE);
610 IGraphicBufferProducer::QueueBufferOutput output;
Andy McFadden3c256212013-08-16 14:55:39 -0700611 IGraphicBufferProducer::QueueBufferInput input(timestamp, isAutoTimestamp,
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800612 mDataSpace, crop, mScalingMode, mTransform ^ mStickyTransform,
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700613 fence, mStickyTransform, mEnableFrameTimestamps);
Dan Stoza5065a552015-03-17 16:23:42 -0700614
Dan Stozac62acbd2015-04-21 16:42:49 -0700615 if (mConnectedToCpu || mDirtyRegion.bounds() == Rect::INVALID_RECT) {
Dan Stoza5065a552015-03-17 16:23:42 -0700616 input.setSurfaceDamage(Region::INVALID_REGION);
617 } else {
Dan Stozadb4850c2015-06-25 16:10:18 -0700618 // Here we do two things:
619 // 1) The surface damage was specified using the OpenGL ES convention of
620 // the origin being in the bottom-left corner. Here we flip to the
621 // convention that the rest of the system uses (top-left corner) by
622 // subtracting all top/bottom coordinates from the buffer height.
623 // 2) If the buffer is coming in rotated (for example, because the EGL
624 // implementation is reacting to the transform hint coming back from
625 // SurfaceFlinger), the surface damage needs to be rotated the
626 // opposite direction, since it was generated assuming an unrotated
627 // buffer (the app doesn't know that the EGL implementation is
628 // reacting to the transform hint behind its back). The
629 // transformations in the switch statement below apply those
630 // complementary rotations (e.g., if 90 degrees, rotate 270 degrees).
631
632 int width = buffer->width;
Dan Stoza0e65e6c2015-05-26 13:22:27 -0700633 int height = buffer->height;
Dan Stozadb4850c2015-06-25 16:10:18 -0700634 bool rotated90 = (mTransform ^ mStickyTransform) &
635 NATIVE_WINDOW_TRANSFORM_ROT_90;
636 if (rotated90) {
637 std::swap(width, height);
Dan Stoza0e65e6c2015-05-26 13:22:27 -0700638 }
Dan Stozadb4850c2015-06-25 16:10:18 -0700639
Dan Stoza5065a552015-03-17 16:23:42 -0700640 Region flippedRegion;
641 for (auto rect : mDirtyRegion) {
Dan Stozadb4850c2015-06-25 16:10:18 -0700642 int left = rect.left;
643 int right = rect.right;
644 int top = height - rect.bottom; // Flip from OpenGL convention
645 int bottom = height - rect.top; // Flip from OpenGL convention
646 switch (mTransform ^ mStickyTransform) {
647 case NATIVE_WINDOW_TRANSFORM_ROT_90: {
648 // Rotate 270 degrees
649 Rect flippedRect{top, width - right, bottom, width - left};
650 flippedRegion.orSelf(flippedRect);
651 break;
652 }
653 case NATIVE_WINDOW_TRANSFORM_ROT_180: {
654 // Rotate 180 degrees
655 Rect flippedRect{width - right, height - bottom,
656 width - left, height - top};
657 flippedRegion.orSelf(flippedRect);
658 break;
659 }
660 case NATIVE_WINDOW_TRANSFORM_ROT_270: {
661 // Rotate 90 degrees
662 Rect flippedRect{height - bottom, left,
663 height - top, right};
664 flippedRegion.orSelf(flippedRect);
665 break;
666 }
667 default: {
668 Rect flippedRect{left, top, right, bottom};
669 flippedRegion.orSelf(flippedRect);
670 break;
671 }
672 }
Dan Stoza5065a552015-03-17 16:23:42 -0700673 }
674
675 input.setSurfaceDamage(flippedRegion);
676 }
677
Dan Stoza70ccba52016-07-01 14:00:40 -0700678 nsecs_t now = systemTime();
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800679 status_t err = mGraphicBufferProducer->queueBuffer(i, input, &output);
Dan Stoza70ccba52016-07-01 14:00:40 -0700680 mLastQueueDuration = systemTime() - now;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800681 if (err != OK) {
682 ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err);
683 }
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800684
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700685 if (mEnableFrameTimestamps) {
Brian Anderson3da8d272016-07-28 16:20:47 -0700686 mFrameEventHistory->applyDelta(output.frameTimestamps);
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700687 // Update timestamps with the local acquire fence.
688 // The consumer doesn't send it back to prevent us from having two
689 // file descriptors of the same fence.
Brian Anderson3da8d272016-07-28 16:20:47 -0700690 mFrameEventHistory->updateAcquireFence(mNextFrameNumber,
Brian Anderson3d4039d2016-09-23 16:31:30 -0700691 std::make_shared<FenceTime>(std::move(fence)));
692
693 // Cache timestamps of signaled fences so we can close their file
694 // descriptors.
Brian Anderson3da8d272016-07-28 16:20:47 -0700695 mFrameEventHistory->updateSignalTimes();
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700696 }
697
Brian Anderson50143b32016-09-30 14:01:24 -0700698 mLastFrameNumber = mNextFrameNumber;
699
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700700 mDefaultWidth = output.width;
701 mDefaultHeight = output.height;
702 mNextFrameNumber = output.nextFrameNumber;
tedbo1e7fa9e2011-06-22 15:52:53 -0700703
Ruben Brunk1681d952014-06-27 15:51:55 -0700704 // Disable transform hint if sticky transform is set.
705 if (mStickyTransform == 0) {
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700706 mTransformHint = output.transformHint;
Ruben Brunk1681d952014-06-27 15:51:55 -0700707 }
708
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700709 mConsumerRunningBehind = (output.numPendingBuffers >= 2);
Mathias Agopian631f3582010-05-25 17:51:34 -0700710
Dan Stozac62acbd2015-04-21 16:42:49 -0700711 if (!mConnectedToCpu) {
712 // Clear surface damage back to full-buffer
713 mDirtyRegion = Region::INVALID_REGION;
714 }
Dan Stoza5065a552015-03-17 16:23:42 -0700715
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700716 if (mSharedBufferMode && mAutoRefresh && mSharedBufferSlot == i) {
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800717 mSharedBufferHasBeenQueued = true;
718 }
719
Robert Carr9f31e292016-04-11 11:15:32 -0700720 mQueueBufferCondition.broadcast();
721
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800722 return err;
723}
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700724
Brian Anderson069b3652016-07-22 10:32:47 -0700725void Surface::querySupportedTimestampsLocked() const {
726 // mMutex must be locked when calling this method.
727
728 if (mQueriedSupportedTimestamps) {
729 return;
730 }
731 mQueriedSupportedTimestamps = true;
732
Brian Anderson3890c392016-07-25 12:48:08 -0700733 std::vector<FrameEvent> supportedFrameTimestamps;
Brian Anderson3da8d272016-07-28 16:20:47 -0700734 status_t err = composerService()->getSupportedFrameTimestamps(
Brian Anderson069b3652016-07-22 10:32:47 -0700735 &supportedFrameTimestamps);
736
737 if (err != NO_ERROR) {
738 return;
739 }
740
741 for (auto sft : supportedFrameTimestamps) {
Brian Anderson3890c392016-07-25 12:48:08 -0700742 if (sft == FrameEvent::DISPLAY_PRESENT) {
Brian Anderson069b3652016-07-22 10:32:47 -0700743 mFrameTimestampsSupportsPresent = true;
Brian Anderson3890c392016-07-25 12:48:08 -0700744 } else if (sft == FrameEvent::DISPLAY_RETIRE) {
Brian Anderson069b3652016-07-22 10:32:47 -0700745 mFrameTimestampsSupportsRetire = true;
746 }
747 }
748}
749
Mathias Agopiana67932f2011-04-20 14:20:59 -0700750int Surface::query(int what, int* value) const {
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800751 ATRACE_CALL();
752 ALOGV("Surface::query");
753 { // scope for the lock
754 Mutex::Autolock lock(mMutex);
755 switch (what) {
756 case NATIVE_WINDOW_FORMAT:
757 if (mReqFormat) {
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800758 *value = static_cast<int>(mReqFormat);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800759 return NO_ERROR;
760 }
761 break;
762 case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: {
Brian Anderson3da8d272016-07-28 16:20:47 -0700763 if (composerService()->authenticateSurfaceTexture(
764 mGraphicBufferProducer)) {
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800765 *value = 1;
766 } else {
767 *value = 0;
768 }
769 return NO_ERROR;
770 }
771 case NATIVE_WINDOW_CONCRETE_TYPE:
772 *value = NATIVE_WINDOW_SURFACE;
773 return NO_ERROR;
774 case NATIVE_WINDOW_DEFAULT_WIDTH:
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800775 *value = static_cast<int>(
776 mUserWidth ? mUserWidth : mDefaultWidth);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800777 return NO_ERROR;
778 case NATIVE_WINDOW_DEFAULT_HEIGHT:
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800779 *value = static_cast<int>(
780 mUserHeight ? mUserHeight : mDefaultHeight);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800781 return NO_ERROR;
782 case NATIVE_WINDOW_TRANSFORM_HINT:
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800783 *value = static_cast<int>(mTransformHint);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800784 return NO_ERROR;
785 case NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND: {
786 status_t err = NO_ERROR;
787 if (!mConsumerRunningBehind) {
788 *value = 0;
789 } else {
790 err = mGraphicBufferProducer->query(what, value);
791 if (err == NO_ERROR) {
792 mConsumerRunningBehind = *value;
793 }
794 }
795 return err;
796 }
Dan Stoza70ccba52016-07-01 14:00:40 -0700797 case NATIVE_WINDOW_LAST_DEQUEUE_DURATION: {
798 int64_t durationUs = mLastDequeueDuration / 1000;
799 *value = durationUs > std::numeric_limits<int>::max() ?
800 std::numeric_limits<int>::max() :
801 static_cast<int>(durationUs);
802 return NO_ERROR;
803 }
804 case NATIVE_WINDOW_LAST_QUEUE_DURATION: {
805 int64_t durationUs = mLastQueueDuration / 1000;
806 *value = durationUs > std::numeric_limits<int>::max() ?
807 std::numeric_limits<int>::max() :
808 static_cast<int>(durationUs);
809 return NO_ERROR;
810 }
Brian Anderson069b3652016-07-22 10:32:47 -0700811 case NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT: {
812 querySupportedTimestampsLocked();
813 *value = mFrameTimestampsSupportsPresent ? 1 : 0;
814 return NO_ERROR;
815 }
816 case NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_RETIRE: {
817 querySupportedTimestampsLocked();
818 *value = mFrameTimestampsSupportsRetire ? 1 : 0;
819 return NO_ERROR;
820 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800821 }
Jamie Gennis391bbe22011-03-14 15:00:06 -0700822 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800823 return mGraphicBufferProducer->query(what, value);
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800824}
825
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800826int Surface::perform(int operation, va_list args)
827{
828 int res = NO_ERROR;
829 switch (operation) {
830 case NATIVE_WINDOW_CONNECT:
831 // deprecated. must return NO_ERROR.
832 break;
833 case NATIVE_WINDOW_DISCONNECT:
834 // deprecated. must return NO_ERROR.
835 break;
836 case NATIVE_WINDOW_SET_USAGE:
837 res = dispatchSetUsage(args);
838 break;
839 case NATIVE_WINDOW_SET_CROP:
840 res = dispatchSetCrop(args);
841 break;
842 case NATIVE_WINDOW_SET_BUFFER_COUNT:
843 res = dispatchSetBufferCount(args);
844 break;
845 case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY:
846 res = dispatchSetBuffersGeometry(args);
847 break;
848 case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM:
849 res = dispatchSetBuffersTransform(args);
850 break;
Ruben Brunk1681d952014-06-27 15:51:55 -0700851 case NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM:
852 res = dispatchSetBuffersStickyTransform(args);
853 break;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800854 case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP:
855 res = dispatchSetBuffersTimestamp(args);
856 break;
857 case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS:
858 res = dispatchSetBuffersDimensions(args);
859 break;
860 case NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS:
861 res = dispatchSetBuffersUserDimensions(args);
862 break;
863 case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
864 res = dispatchSetBuffersFormat(args);
865 break;
866 case NATIVE_WINDOW_LOCK:
867 res = dispatchLock(args);
868 break;
869 case NATIVE_WINDOW_UNLOCK_AND_POST:
870 res = dispatchUnlockAndPost(args);
871 break;
872 case NATIVE_WINDOW_SET_SCALING_MODE:
873 res = dispatchSetScalingMode(args);
874 break;
875 case NATIVE_WINDOW_API_CONNECT:
876 res = dispatchConnect(args);
877 break;
878 case NATIVE_WINDOW_API_DISCONNECT:
879 res = dispatchDisconnect(args);
880 break;
Rachad7cb0d392014-07-29 17:53:53 -0700881 case NATIVE_WINDOW_SET_SIDEBAND_STREAM:
882 res = dispatchSetSidebandStream(args);
883 break;
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800884 case NATIVE_WINDOW_SET_BUFFERS_DATASPACE:
885 res = dispatchSetBuffersDataSpace(args);
886 break;
Dan Stoza5065a552015-03-17 16:23:42 -0700887 case NATIVE_WINDOW_SET_SURFACE_DAMAGE:
888 res = dispatchSetSurfaceDamage(args);
889 break;
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700890 case NATIVE_WINDOW_SET_SHARED_BUFFER_MODE:
891 res = dispatchSetSharedBufferMode(args);
Pablo Ceballosccdfd602015-10-07 15:05:45 -0700892 break;
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800893 case NATIVE_WINDOW_SET_AUTO_REFRESH:
894 res = dispatchSetAutoRefresh(args);
895 break;
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800896 case NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION:
897 res = dispatchGetDisplayRefreshCycleDuration(args);
898 break;
Brian Anderson1049d1d2016-12-16 17:25:57 -0800899 case NATIVE_WINDOW_GET_NEXT_FRAME_ID:
900 res = dispatchGetNextFrameId(args);
901 break;
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700902 case NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS:
903 res = dispatchEnableFrameTimestamps(args);
904 break;
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800905 case NATIVE_WINDOW_GET_COMPOSITOR_TIMING:
906 res = dispatchGetCompositorTiming(args);
907 break;
Pablo Ceballosce796e72016-02-04 19:10:51 -0800908 case NATIVE_WINDOW_GET_FRAME_TIMESTAMPS:
909 res = dispatchGetFrameTimestamps(args);
910 break;
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700911 case NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT:
912 res = dispatchGetWideColorSupport(args);
913 break;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800914 default:
915 res = NAME_NOT_FOUND;
916 break;
917 }
918 return res;
919}
Mathias Agopiana138f892010-05-21 17:24:35 -0700920
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800921int Surface::dispatchConnect(va_list args) {
922 int api = va_arg(args, int);
923 return connect(api);
924}
Mathias Agopian55fa2512010-03-11 15:06:54 -0800925
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800926int Surface::dispatchDisconnect(va_list args) {
927 int api = va_arg(args, int);
928 return disconnect(api);
929}
930
931int Surface::dispatchSetUsage(va_list args) {
932 int usage = va_arg(args, int);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800933 return setUsage(static_cast<uint32_t>(usage));
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800934}
935
936int Surface::dispatchSetCrop(va_list args) {
937 android_native_rect_t const* rect = va_arg(args, android_native_rect_t*);
938 return setCrop(reinterpret_cast<Rect const*>(rect));
939}
940
941int Surface::dispatchSetBufferCount(va_list args) {
942 size_t bufferCount = va_arg(args, size_t);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800943 return setBufferCount(static_cast<int32_t>(bufferCount));
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800944}
945
946int Surface::dispatchSetBuffersGeometry(va_list args) {
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800947 uint32_t width = va_arg(args, uint32_t);
948 uint32_t height = va_arg(args, uint32_t);
949 PixelFormat format = va_arg(args, PixelFormat);
950 int err = setBuffersDimensions(width, height);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800951 if (err != 0) {
952 return err;
953 }
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800954 return setBuffersFormat(format);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800955}
956
957int Surface::dispatchSetBuffersDimensions(va_list args) {
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800958 uint32_t width = va_arg(args, uint32_t);
959 uint32_t height = va_arg(args, uint32_t);
960 return setBuffersDimensions(width, height);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800961}
962
963int Surface::dispatchSetBuffersUserDimensions(va_list args) {
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800964 uint32_t width = va_arg(args, uint32_t);
965 uint32_t height = va_arg(args, uint32_t);
966 return setBuffersUserDimensions(width, height);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800967}
968
969int Surface::dispatchSetBuffersFormat(va_list args) {
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800970 PixelFormat format = va_arg(args, PixelFormat);
971 return setBuffersFormat(format);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800972}
973
974int Surface::dispatchSetScalingMode(va_list args) {
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800975 int mode = va_arg(args, int);
976 return setScalingMode(mode);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800977}
978
979int Surface::dispatchSetBuffersTransform(va_list args) {
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800980 uint32_t transform = va_arg(args, uint32_t);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800981 return setBuffersTransform(transform);
982}
983
Ruben Brunk1681d952014-06-27 15:51:55 -0700984int Surface::dispatchSetBuffersStickyTransform(va_list args) {
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800985 uint32_t transform = va_arg(args, uint32_t);
Ruben Brunk1681d952014-06-27 15:51:55 -0700986 return setBuffersStickyTransform(transform);
987}
988
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800989int Surface::dispatchSetBuffersTimestamp(va_list args) {
990 int64_t timestamp = va_arg(args, int64_t);
991 return setBuffersTimestamp(timestamp);
992}
993
994int Surface::dispatchLock(va_list args) {
995 ANativeWindow_Buffer* outBuffer = va_arg(args, ANativeWindow_Buffer*);
996 ARect* inOutDirtyBounds = va_arg(args, ARect*);
997 return lock(outBuffer, inOutDirtyBounds);
998}
999
Igor Murashkin7d2d1602013-11-12 18:02:20 -08001000int Surface::dispatchUnlockAndPost(va_list args __attribute__((unused))) {
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001001 return unlockAndPost();
1002}
1003
Rachad7cb0d392014-07-29 17:53:53 -07001004int Surface::dispatchSetSidebandStream(va_list args) {
1005 native_handle_t* sH = va_arg(args, native_handle_t*);
1006 sp<NativeHandle> sidebandHandle = NativeHandle::create(sH, false);
1007 setSidebandStream(sidebandHandle);
1008 return OK;
1009}
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001010
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -08001011int Surface::dispatchSetBuffersDataSpace(va_list args) {
1012 android_dataspace dataspace =
1013 static_cast<android_dataspace>(va_arg(args, int));
1014 return setBuffersDataSpace(dataspace);
1015}
1016
Dan Stoza5065a552015-03-17 16:23:42 -07001017int Surface::dispatchSetSurfaceDamage(va_list args) {
1018 android_native_rect_t* rects = va_arg(args, android_native_rect_t*);
1019 size_t numRects = va_arg(args, size_t);
1020 setSurfaceDamage(rects, numRects);
1021 return NO_ERROR;
1022}
1023
Pablo Ceballos3559fbf2016-03-17 15:50:23 -07001024int Surface::dispatchSetSharedBufferMode(va_list args) {
1025 bool sharedBufferMode = va_arg(args, int);
1026 return setSharedBufferMode(sharedBufferMode);
Pablo Ceballosff95aab2016-01-13 17:09:58 -08001027}
1028
1029int Surface::dispatchSetAutoRefresh(va_list args) {
1030 bool autoRefresh = va_arg(args, int);
1031 return setAutoRefresh(autoRefresh);
Pablo Ceballosccdfd602015-10-07 15:05:45 -07001032}
1033
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001034int Surface::dispatchGetDisplayRefreshCycleDuration(va_list args) {
1035 nsecs_t* outRefreshDuration = va_arg(args, int64_t*);
1036 return getDisplayRefreshCycleDuration(outRefreshDuration);
1037}
1038
Brian Anderson1049d1d2016-12-16 17:25:57 -08001039int Surface::dispatchGetNextFrameId(va_list args) {
1040 uint64_t* nextFrameId = va_arg(args, uint64_t*);
1041 *nextFrameId = getNextFrameNumber();
1042 return NO_ERROR;
1043}
1044
Brian Anderson7c3ba8a2016-07-25 12:48:08 -07001045int Surface::dispatchEnableFrameTimestamps(va_list args) {
1046 bool enable = va_arg(args, int);
1047 enableFrameTimestamps(enable);
1048 return NO_ERROR;
1049}
1050
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001051int Surface::dispatchGetCompositorTiming(va_list args) {
1052 nsecs_t* compositeDeadline = va_arg(args, int64_t*);
1053 nsecs_t* compositeInterval = va_arg(args, int64_t*);
1054 nsecs_t* compositeToPresentLatency = va_arg(args, int64_t*);
1055 return getCompositorTiming(compositeDeadline, compositeInterval,
1056 compositeToPresentLatency);
1057}
1058
Pablo Ceballosce796e72016-02-04 19:10:51 -08001059int Surface::dispatchGetFrameTimestamps(va_list args) {
Brian Anderson1049d1d2016-12-16 17:25:57 -08001060 uint64_t frameId = va_arg(args, uint64_t);
Brian Andersondbd0ea82016-07-22 09:38:59 -07001061 nsecs_t* outRequestedPresentTime = va_arg(args, int64_t*);
Pablo Ceballosce796e72016-02-04 19:10:51 -08001062 nsecs_t* outAcquireTime = va_arg(args, int64_t*);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001063 nsecs_t* outLatchTime = va_arg(args, int64_t*);
1064 nsecs_t* outFirstRefreshStartTime = va_arg(args, int64_t*);
1065 nsecs_t* outLastRefreshStartTime = va_arg(args, int64_t*);
Brian Andersonb04c6f02016-10-21 12:57:46 -07001066 nsecs_t* outGpuCompositionDoneTime = va_arg(args, int64_t*);
Brian Anderson069b3652016-07-22 10:32:47 -07001067 nsecs_t* outDisplayPresentTime = va_arg(args, int64_t*);
Pablo Ceballosce796e72016-02-04 19:10:51 -08001068 nsecs_t* outDisplayRetireTime = va_arg(args, int64_t*);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001069 nsecs_t* outDequeueReadyTime = va_arg(args, int64_t*);
Pablo Ceballosce796e72016-02-04 19:10:51 -08001070 nsecs_t* outReleaseTime = va_arg(args, int64_t*);
Brian Anderson1049d1d2016-12-16 17:25:57 -08001071 return getFrameTimestamps(frameId,
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001072 outRequestedPresentTime, outAcquireTime, outLatchTime,
1073 outFirstRefreshStartTime, outLastRefreshStartTime,
Brian Andersonb04c6f02016-10-21 12:57:46 -07001074 outGpuCompositionDoneTime, outDisplayPresentTime,
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001075 outDisplayRetireTime, outDequeueReadyTime, outReleaseTime);
Pablo Ceballosce796e72016-02-04 19:10:51 -08001076}
1077
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -07001078int Surface::dispatchGetWideColorSupport(va_list args) {
1079 bool* outSupport = va_arg(args, bool*);
1080 return getWideColorSupport(outSupport);
1081}
1082
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001083int Surface::connect(int api) {
Dan Stoza966b98b2015-03-02 22:12:37 -08001084 static sp<IProducerListener> listener = new DummyProducerListener();
1085 return connect(api, listener);
1086}
1087
1088int Surface::connect(int api, const sp<IProducerListener>& listener) {
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001089 ATRACE_CALL();
1090 ALOGV("Surface::connect");
1091 Mutex::Autolock lock(mMutex);
1092 IGraphicBufferProducer::QueueBufferOutput output;
Dan Stozaf0eaf252014-03-21 13:05:51 -07001093 int err = mGraphicBufferProducer->connect(listener, api, mProducerControlledByApp, &output);
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001094 if (err == NO_ERROR) {
Brian Anderson7c3ba8a2016-07-25 12:48:08 -07001095 mDefaultWidth = output.width;
1096 mDefaultHeight = output.height;
1097 mNextFrameNumber = output.nextFrameNumber;
Ruben Brunk1681d952014-06-27 15:51:55 -07001098
1099 // Disable transform hint if sticky transform is set.
1100 if (mStickyTransform == 0) {
Brian Anderson7c3ba8a2016-07-25 12:48:08 -07001101 mTransformHint = output.transformHint;
Ruben Brunk1681d952014-06-27 15:51:55 -07001102 }
1103
Brian Anderson7c3ba8a2016-07-25 12:48:08 -07001104 mConsumerRunningBehind = (output.numPendingBuffers >= 2);
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001105 }
1106 if (!err && api == NATIVE_WINDOW_API_CPU) {
1107 mConnectedToCpu = true;
Dan Stoza5065a552015-03-17 16:23:42 -07001108 // Clear the dirty region in case we're switching from a non-CPU API
1109 mDirtyRegion.clear();
1110 } else if (!err) {
1111 // Initialize the dirty region for tracking surface damage
1112 mDirtyRegion = Region::INVALID_REGION;
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001113 }
Dan Stoza5065a552015-03-17 16:23:42 -07001114
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001115 return err;
1116}
1117
Mathias Agopian365857d2013-09-11 19:35:45 -07001118
Robert Carr97b9c862016-09-08 13:54:35 -07001119int Surface::disconnect(int api, IGraphicBufferProducer::DisconnectMode mode) {
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001120 ATRACE_CALL();
1121 ALOGV("Surface::disconnect");
1122 Mutex::Autolock lock(mMutex);
Pablo Ceballosff95aab2016-01-13 17:09:58 -08001123 mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT;
1124 mSharedBufferHasBeenQueued = false;
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001125 freeAllBuffers();
Robert Carr97b9c862016-09-08 13:54:35 -07001126 int err = mGraphicBufferProducer->disconnect(api, mode);
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001127 if (!err) {
1128 mReqFormat = 0;
1129 mReqWidth = 0;
1130 mReqHeight = 0;
1131 mReqUsage = 0;
1132 mCrop.clear();
1133 mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
1134 mTransform = 0;
Ruben Brunk1681d952014-06-27 15:51:55 -07001135 mStickyTransform = 0;
1136
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001137 if (api == NATIVE_WINDOW_API_CPU) {
1138 mConnectedToCpu = false;
1139 }
1140 }
1141 return err;
1142}
1143
Dan Stozad9c49712015-04-27 11:06:01 -07001144int Surface::detachNextBuffer(sp<GraphicBuffer>* outBuffer,
Dan Stoza231832e2015-03-11 11:55:01 -07001145 sp<Fence>* outFence) {
1146 ATRACE_CALL();
1147 ALOGV("Surface::detachNextBuffer");
1148
1149 if (outBuffer == NULL || outFence == NULL) {
1150 return BAD_VALUE;
1151 }
1152
1153 Mutex::Autolock lock(mMutex);
1154
1155 sp<GraphicBuffer> buffer(NULL);
1156 sp<Fence> fence(NULL);
1157 status_t result = mGraphicBufferProducer->detachNextBuffer(
1158 &buffer, &fence);
1159 if (result != NO_ERROR) {
1160 return result;
1161 }
1162
Dan Stozad9c49712015-04-27 11:06:01 -07001163 *outBuffer = buffer;
Dan Stoza231832e2015-03-11 11:55:01 -07001164 if (fence != NULL && fence->isValid()) {
1165 *outFence = fence;
1166 } else {
1167 *outFence = Fence::NO_FENCE;
1168 }
1169
Pablo Ceballos23b4abe2016-01-08 12:15:22 -08001170 for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
1171 if (mSlots[i].buffer != NULL &&
1172 mSlots[i].buffer->handle == buffer->handle) {
1173 mSlots[i].buffer = NULL;
1174 }
1175 }
1176
Dan Stoza231832e2015-03-11 11:55:01 -07001177 return NO_ERROR;
1178}
1179
1180int Surface::attachBuffer(ANativeWindowBuffer* buffer)
1181{
1182 ATRACE_CALL();
1183 ALOGV("Surface::attachBuffer");
1184
1185 Mutex::Autolock lock(mMutex);
1186
1187 sp<GraphicBuffer> graphicBuffer(static_cast<GraphicBuffer*>(buffer));
Dan Stoza812ed062015-06-02 15:45:22 -07001188 uint32_t priorGeneration = graphicBuffer->mGenerationNumber;
1189 graphicBuffer->mGenerationNumber = mGenerationNumber;
Dan Stoza231832e2015-03-11 11:55:01 -07001190 int32_t attachedSlot = -1;
1191 status_t result = mGraphicBufferProducer->attachBuffer(
1192 &attachedSlot, graphicBuffer);
1193 if (result != NO_ERROR) {
1194 ALOGE("attachBuffer: IGraphicBufferProducer call failed (%d)", result);
Dan Stoza812ed062015-06-02 15:45:22 -07001195 graphicBuffer->mGenerationNumber = priorGeneration;
Dan Stoza231832e2015-03-11 11:55:01 -07001196 return result;
1197 }
1198 mSlots[attachedSlot].buffer = graphicBuffer;
1199
1200 return NO_ERROR;
1201}
1202
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001203int Surface::setUsage(uint32_t reqUsage)
1204{
1205 ALOGV("Surface::setUsage");
1206 Mutex::Autolock lock(mMutex);
Pablo Ceballosff95aab2016-01-13 17:09:58 -08001207 if (reqUsage != mReqUsage) {
1208 mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT;
1209 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001210 mReqUsage = reqUsage;
1211 return OK;
1212}
1213
1214int Surface::setCrop(Rect const* rect)
1215{
1216 ATRACE_CALL();
1217
Pablo Ceballos60d69222015-08-07 14:47:20 -07001218 Rect realRect(Rect::EMPTY_RECT);
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001219 if (rect == NULL || rect->isEmpty()) {
1220 realRect.clear();
1221 } else {
1222 realRect = *rect;
Mathias Agopian55fa2512010-03-11 15:06:54 -08001223 }
1224
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001225 ALOGV("Surface::setCrop rect=[%d %d %d %d]",
1226 realRect.left, realRect.top, realRect.right, realRect.bottom);
1227
1228 Mutex::Autolock lock(mMutex);
1229 mCrop = realRect;
1230 return NO_ERROR;
1231}
1232
1233int Surface::setBufferCount(int bufferCount)
1234{
1235 ATRACE_CALL();
1236 ALOGV("Surface::setBufferCount");
1237 Mutex::Autolock lock(mMutex);
1238
Pablo Ceballose5b755a2015-08-13 16:18:19 -07001239 status_t err = NO_ERROR;
1240 if (bufferCount == 0) {
1241 err = mGraphicBufferProducer->setMaxDequeuedBufferCount(1);
1242 } else {
1243 int minUndequeuedBuffers = 0;
1244 err = mGraphicBufferProducer->query(
1245 NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &minUndequeuedBuffers);
1246 if (err == NO_ERROR) {
1247 err = mGraphicBufferProducer->setMaxDequeuedBufferCount(
1248 bufferCount - minUndequeuedBuffers);
1249 }
1250 }
Mathias Agopian90147262010-01-22 11:47:55 -08001251
Pablo Ceballose5b755a2015-08-13 16:18:19 -07001252 ALOGE_IF(err, "IGraphicBufferProducer::setBufferCount(%d) returned %s",
1253 bufferCount, strerror(-err));
1254
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001255 return err;
1256}
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001257
Pablo Ceballosfa455352015-08-12 17:47:47 -07001258int Surface::setMaxDequeuedBufferCount(int maxDequeuedBuffers) {
1259 ATRACE_CALL();
1260 ALOGV("Surface::setMaxDequeuedBufferCount");
1261 Mutex::Autolock lock(mMutex);
1262
1263 status_t err = mGraphicBufferProducer->setMaxDequeuedBufferCount(
1264 maxDequeuedBuffers);
1265 ALOGE_IF(err, "IGraphicBufferProducer::setMaxDequeuedBufferCount(%d) "
1266 "returned %s", maxDequeuedBuffers, strerror(-err));
1267
Pablo Ceballosfa455352015-08-12 17:47:47 -07001268 return err;
1269}
1270
1271int Surface::setAsyncMode(bool async) {
1272 ATRACE_CALL();
1273 ALOGV("Surface::setAsyncMode");
1274 Mutex::Autolock lock(mMutex);
1275
1276 status_t err = mGraphicBufferProducer->setAsyncMode(async);
1277 ALOGE_IF(err, "IGraphicBufferProducer::setAsyncMode(%d) returned %s",
1278 async, strerror(-err));
1279
Pablo Ceballosfa455352015-08-12 17:47:47 -07001280 return err;
1281}
1282
Pablo Ceballos3559fbf2016-03-17 15:50:23 -07001283int Surface::setSharedBufferMode(bool sharedBufferMode) {
Pablo Ceballosccdfd602015-10-07 15:05:45 -07001284 ATRACE_CALL();
Pablo Ceballos3559fbf2016-03-17 15:50:23 -07001285 ALOGV("Surface::setSharedBufferMode (%d)", sharedBufferMode);
Pablo Ceballosccdfd602015-10-07 15:05:45 -07001286 Mutex::Autolock lock(mMutex);
1287
Pablo Ceballos3559fbf2016-03-17 15:50:23 -07001288 status_t err = mGraphicBufferProducer->setSharedBufferMode(
1289 sharedBufferMode);
Pablo Ceballosff95aab2016-01-13 17:09:58 -08001290 if (err == NO_ERROR) {
Pablo Ceballos3559fbf2016-03-17 15:50:23 -07001291 mSharedBufferMode = sharedBufferMode;
Pablo Ceballosff95aab2016-01-13 17:09:58 -08001292 }
Pablo Ceballos3559fbf2016-03-17 15:50:23 -07001293 ALOGE_IF(err, "IGraphicBufferProducer::setSharedBufferMode(%d) returned"
1294 "%s", sharedBufferMode, strerror(-err));
Pablo Ceballosccdfd602015-10-07 15:05:45 -07001295
1296 return err;
1297}
1298
Pablo Ceballosff95aab2016-01-13 17:09:58 -08001299int Surface::setAutoRefresh(bool autoRefresh) {
1300 ATRACE_CALL();
1301 ALOGV("Surface::setAutoRefresh (%d)", autoRefresh);
1302 Mutex::Autolock lock(mMutex);
1303
1304 status_t err = mGraphicBufferProducer->setAutoRefresh(autoRefresh);
1305 if (err == NO_ERROR) {
1306 mAutoRefresh = autoRefresh;
1307 }
1308 ALOGE_IF(err, "IGraphicBufferProducer::setAutoRefresh(%d) returned %s",
1309 autoRefresh, strerror(-err));
1310 return err;
1311}
1312
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001313int Surface::setBuffersDimensions(uint32_t width, uint32_t height)
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001314{
1315 ATRACE_CALL();
1316 ALOGV("Surface::setBuffersDimensions");
1317
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001318 if ((width && !height) || (!width && height))
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001319 return BAD_VALUE;
1320
1321 Mutex::Autolock lock(mMutex);
Pablo Ceballosff95aab2016-01-13 17:09:58 -08001322 if (width != mReqWidth || height != mReqHeight) {
1323 mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT;
1324 }
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001325 mReqWidth = width;
1326 mReqHeight = height;
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001327 return NO_ERROR;
1328}
1329
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001330int Surface::setBuffersUserDimensions(uint32_t width, uint32_t height)
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001331{
1332 ATRACE_CALL();
1333 ALOGV("Surface::setBuffersUserDimensions");
1334
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001335 if ((width && !height) || (!width && height))
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001336 return BAD_VALUE;
1337
1338 Mutex::Autolock lock(mMutex);
Pablo Ceballosff95aab2016-01-13 17:09:58 -08001339 if (width != mUserWidth || height != mUserHeight) {
1340 mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT;
1341 }
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001342 mUserWidth = width;
1343 mUserHeight = height;
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001344 return NO_ERROR;
1345}
1346
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001347int Surface::setBuffersFormat(PixelFormat format)
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001348{
1349 ALOGV("Surface::setBuffersFormat");
1350
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001351 Mutex::Autolock lock(mMutex);
Pablo Ceballosff95aab2016-01-13 17:09:58 -08001352 if (format != mReqFormat) {
1353 mSharedBufferSlot = BufferItem::INVALID_BUFFER_SLOT;
1354 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001355 mReqFormat = format;
1356 return NO_ERROR;
1357}
1358
1359int Surface::setScalingMode(int mode)
1360{
1361 ATRACE_CALL();
1362 ALOGV("Surface::setScalingMode(%d)", mode);
1363
1364 switch (mode) {
1365 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
1366 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
1367 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
Robert Carrc2e77882015-12-16 18:14:03 -08001368 case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP:
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001369 break;
1370 default:
1371 ALOGE("unknown scaling mode: %d", mode);
1372 return BAD_VALUE;
1373 }
1374
1375 Mutex::Autolock lock(mMutex);
1376 mScalingMode = mode;
1377 return NO_ERROR;
1378}
1379
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001380int Surface::setBuffersTransform(uint32_t transform)
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001381{
1382 ATRACE_CALL();
1383 ALOGV("Surface::setBuffersTransform");
1384 Mutex::Autolock lock(mMutex);
1385 mTransform = transform;
1386 return NO_ERROR;
1387}
1388
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001389int Surface::setBuffersStickyTransform(uint32_t transform)
Ruben Brunk1681d952014-06-27 15:51:55 -07001390{
1391 ATRACE_CALL();
1392 ALOGV("Surface::setBuffersStickyTransform");
1393 Mutex::Autolock lock(mMutex);
1394 mStickyTransform = transform;
1395 return NO_ERROR;
1396}
1397
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001398int Surface::setBuffersTimestamp(int64_t timestamp)
1399{
1400 ALOGV("Surface::setBuffersTimestamp");
1401 Mutex::Autolock lock(mMutex);
1402 mTimestamp = timestamp;
1403 return NO_ERROR;
1404}
1405
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -08001406int Surface::setBuffersDataSpace(android_dataspace dataSpace)
1407{
1408 ALOGV("Surface::setBuffersDataSpace");
1409 Mutex::Autolock lock(mMutex);
1410 mDataSpace = dataSpace;
1411 return NO_ERROR;
1412}
1413
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001414void Surface::freeAllBuffers() {
1415 for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
1416 mSlots[i].buffer = 0;
1417 }
1418}
1419
Dan Stoza5065a552015-03-17 16:23:42 -07001420void Surface::setSurfaceDamage(android_native_rect_t* rects, size_t numRects) {
1421 ATRACE_CALL();
1422 ALOGV("Surface::setSurfaceDamage");
1423 Mutex::Autolock lock(mMutex);
1424
Dan Stozac62acbd2015-04-21 16:42:49 -07001425 if (mConnectedToCpu || numRects == 0) {
Dan Stoza5065a552015-03-17 16:23:42 -07001426 mDirtyRegion = Region::INVALID_REGION;
1427 return;
1428 }
1429
1430 mDirtyRegion.clear();
1431 for (size_t r = 0; r < numRects; ++r) {
1432 // We intentionally flip top and bottom here, since because they're
1433 // specified with a bottom-left origin, top > bottom, which fails
1434 // validation in the Region class. We will fix this up when we flip to a
1435 // top-left origin in queueBuffer.
1436 Rect rect(rects[r].left, rects[r].bottom, rects[r].right, rects[r].top);
1437 mDirtyRegion.orSelf(rect);
1438 }
1439}
1440
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001441// ----------------------------------------------------------------------
1442// the lock/unlock APIs must be used from the same thread
1443
1444static status_t copyBlt(
1445 const sp<GraphicBuffer>& dst,
1446 const sp<GraphicBuffer>& src,
Francis Hart7b09e792015-01-09 11:10:54 +02001447 const Region& reg,
1448 int *dstFenceFd)
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001449{
1450 // src and dst with, height and format must be identical. no verification
1451 // is done here.
1452 status_t err;
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001453 uint8_t* src_bits = NULL;
1454 err = src->lock(GRALLOC_USAGE_SW_READ_OFTEN, reg.bounds(),
1455 reinterpret_cast<void**>(&src_bits));
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001456 ALOGE_IF(err, "error locking src buffer %s", strerror(-err));
1457
1458 uint8_t* dst_bits = NULL;
Francis Hart7b09e792015-01-09 11:10:54 +02001459 err = dst->lockAsync(GRALLOC_USAGE_SW_WRITE_OFTEN, reg.bounds(),
1460 reinterpret_cast<void**>(&dst_bits), *dstFenceFd);
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001461 ALOGE_IF(err, "error locking dst buffer %s", strerror(-err));
Francis Hart7b09e792015-01-09 11:10:54 +02001462 *dstFenceFd = -1;
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001463
1464 Region::const_iterator head(reg.begin());
1465 Region::const_iterator tail(reg.end());
1466 if (head != tail && src_bits && dst_bits) {
1467 const size_t bpp = bytesPerPixel(src->format);
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001468 const size_t dbpr = static_cast<uint32_t>(dst->stride) * bpp;
1469 const size_t sbpr = static_cast<uint32_t>(src->stride) * bpp;
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001470
1471 while (head != tail) {
1472 const Rect& r(*head++);
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001473 int32_t h = r.height();
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001474 if (h <= 0) continue;
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001475 size_t size = static_cast<uint32_t>(r.width()) * bpp;
1476 uint8_t const * s = src_bits +
1477 static_cast<uint32_t>(r.left + src->stride * r.top) * bpp;
1478 uint8_t * d = dst_bits +
1479 static_cast<uint32_t>(r.left + dst->stride * r.top) * bpp;
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001480 if (dbpr==sbpr && size==sbpr) {
Dan Stoza3be1c6b2014-11-18 10:24:03 -08001481 size *= static_cast<size_t>(h);
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001482 h = 1;
1483 }
1484 do {
1485 memcpy(d, s, size);
1486 d += dbpr;
1487 s += sbpr;
1488 } while (--h > 0);
1489 }
1490 }
1491
1492 if (src_bits)
1493 src->unlock();
1494
1495 if (dst_bits)
Francis Hart7b09e792015-01-09 11:10:54 +02001496 dst->unlockAsync(dstFenceFd);
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001497
1498 return err;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001499}
1500
Mathias Agopiana138f892010-05-21 17:24:35 -07001501// ----------------------------------------------------------------------------
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001502
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001503status_t Surface::lock(
1504 ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds)
1505{
1506 if (mLockedBuffer != 0) {
1507 ALOGE("Surface::lock failed, already locked");
1508 return INVALID_OPERATION;
1509 }
1510
1511 if (!mConnectedToCpu) {
1512 int err = Surface::connect(NATIVE_WINDOW_API_CPU);
1513 if (err) {
1514 return err;
1515 }
1516 // we're intending to do software rendering from this point
1517 setUsage(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
1518 }
1519
1520 ANativeWindowBuffer* out;
1521 int fenceFd = -1;
1522 status_t err = dequeueBuffer(&out, &fenceFd);
1523 ALOGE_IF(err, "dequeueBuffer failed (%s)", strerror(-err));
1524 if (err == NO_ERROR) {
1525 sp<GraphicBuffer> backBuffer(GraphicBuffer::getSelf(out));
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001526 const Rect bounds(backBuffer->width, backBuffer->height);
1527
1528 Region newDirtyRegion;
1529 if (inOutDirtyBounds) {
1530 newDirtyRegion.set(static_cast<Rect const&>(*inOutDirtyBounds));
1531 newDirtyRegion.andSelf(bounds);
1532 } else {
1533 newDirtyRegion.set(bounds);
1534 }
1535
1536 // figure out if we can copy the frontbuffer back
1537 const sp<GraphicBuffer>& frontBuffer(mPostedBuffer);
1538 const bool canCopyBack = (frontBuffer != 0 &&
1539 backBuffer->width == frontBuffer->width &&
1540 backBuffer->height == frontBuffer->height &&
1541 backBuffer->format == frontBuffer->format);
1542
1543 if (canCopyBack) {
1544 // copy the area that is invalid and not repainted this round
1545 const Region copyback(mDirtyRegion.subtract(newDirtyRegion));
Francis Hartdc10f842014-12-01 16:04:49 +02001546 if (!copyback.isEmpty()) {
Francis Hart7b09e792015-01-09 11:10:54 +02001547 copyBlt(backBuffer, frontBuffer, copyback, &fenceFd);
Francis Hartdc10f842014-12-01 16:04:49 +02001548 }
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001549 } else {
1550 // if we can't copy-back anything, modify the user's dirty
1551 // region to make sure they redraw the whole buffer
1552 newDirtyRegion.set(bounds);
1553 mDirtyRegion.clear();
1554 Mutex::Autolock lock(mMutex);
1555 for (size_t i=0 ; i<NUM_BUFFER_SLOTS ; i++) {
1556 mSlots[i].dirtyRegion.clear();
1557 }
1558 }
1559
1560
1561 { // scope for the lock
1562 Mutex::Autolock lock(mMutex);
1563 int backBufferSlot(getSlotFromBufferLocked(backBuffer.get()));
1564 if (backBufferSlot >= 0) {
1565 Region& dirtyRegion(mSlots[backBufferSlot].dirtyRegion);
1566 mDirtyRegion.subtract(dirtyRegion);
1567 dirtyRegion = newDirtyRegion;
1568 }
1569 }
1570
1571 mDirtyRegion.orSelf(newDirtyRegion);
1572 if (inOutDirtyBounds) {
1573 *inOutDirtyBounds = newDirtyRegion.getBounds();
1574 }
1575
1576 void* vaddr;
Francis Hart8f396012014-04-01 15:30:53 +03001577 status_t res = backBuffer->lockAsync(
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001578 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
Francis Hart8f396012014-04-01 15:30:53 +03001579 newDirtyRegion.bounds(), &vaddr, fenceFd);
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001580
1581 ALOGW_IF(res, "failed locking buffer (handle = %p)",
1582 backBuffer->handle);
1583
1584 if (res != 0) {
1585 err = INVALID_OPERATION;
1586 } else {
1587 mLockedBuffer = backBuffer;
1588 outBuffer->width = backBuffer->width;
1589 outBuffer->height = backBuffer->height;
1590 outBuffer->stride = backBuffer->stride;
1591 outBuffer->format = backBuffer->format;
1592 outBuffer->bits = vaddr;
1593 }
1594 }
1595 return err;
1596}
1597
1598status_t Surface::unlockAndPost()
1599{
1600 if (mLockedBuffer == 0) {
1601 ALOGE("Surface::unlockAndPost failed, no locked buffer");
1602 return INVALID_OPERATION;
1603 }
1604
Francis Hart8f396012014-04-01 15:30:53 +03001605 int fd = -1;
1606 status_t err = mLockedBuffer->unlockAsync(&fd);
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001607 ALOGE_IF(err, "failed unlocking buffer (%p)", mLockedBuffer->handle);
1608
Francis Hart8f396012014-04-01 15:30:53 +03001609 err = queueBuffer(mLockedBuffer.get(), fd);
Mathias Agopiane3c697f2013-02-14 17:11:02 -08001610 ALOGE_IF(err, "queueBuffer (handle=%p) failed (%s)",
1611 mLockedBuffer->handle, strerror(-err));
1612
1613 mPostedBuffer = mLockedBuffer;
1614 mLockedBuffer = 0;
1615 return err;
1616}
1617
Robert Carr9f31e292016-04-11 11:15:32 -07001618bool Surface::waitForNextFrame(uint64_t lastFrame, nsecs_t timeout) {
1619 Mutex::Autolock lock(mMutex);
Pablo Ceballosbc8c1922016-07-01 14:15:41 -07001620 if (mNextFrameNumber > lastFrame) {
Robert Carr9f31e292016-04-11 11:15:32 -07001621 return true;
1622 }
1623 return mQueueBufferCondition.waitRelative(mMutex, timeout) == OK;
1624}
1625
Pablo Ceballos8e3e92b2016-06-27 17:56:53 -07001626status_t Surface::getUniqueId(uint64_t* outId) const {
1627 Mutex::Autolock lock(mMutex);
1628 return mGraphicBufferProducer->getUniqueId(outId);
1629}
1630
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001631}; // namespace android