blob: 337950c3e6ee9e9b0fb1e52f9ec767c1f3ee86b9 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
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"
18
19#include <stdint.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020#include <errno.h>
21#include <sys/types.h>
22#include <sys/stat.h>
23
Mathias Agopian9779b222009-09-07 16:32:45 -070024#include <utils/CallStack.h>
Mathias Agopian7bb843c2011-04-20 14:20:59 -070025#include <utils/Errors.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080026#include <utils/Log.h>
Mathias Agopian7bb843c2011-04-20 14:20:59 -070027#include <utils/threads.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080028
Mathias Agopian7bb843c2011-04-20 14:20:59 -070029#include <binder/IPCThreadState.h>
30
31#include <gui/SurfaceTextureClient.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032
Mathias Agopian1473f462009-04-10 14:24:30 -070033#include <ui/DisplayInfo.h>
Mathias Agopian6950e422009-10-05 17:07:12 -070034#include <ui/GraphicBuffer.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035#include <ui/Rect.h>
36
Mathias Agopian000479f2010-02-09 17:46:37 -080037#include <surfaceflinger/ISurface.h>
38#include <surfaceflinger/ISurfaceComposer.h>
Mathias Agopian7bb843c2011-04-20 14:20:59 -070039#include <surfaceflinger/Surface.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080040#include <surfaceflinger/SurfaceComposerClient.h>
Mathias Agopian1473f462009-04-10 14:24:30 -070041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042namespace android {
43
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070044// ============================================================================
45// SurfaceControl
46// ============================================================================
47
Mathias Agopian17f638b2009-04-16 20:04:08 -070048SurfaceControl::SurfaceControl(
49 const sp<SurfaceComposerClient>& client,
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070050 const sp<ISurface>& surface,
Mathias Agopian50c24a22011-07-20 16:46:11 -070051 const ISurfaceComposerClient::surface_data_t& data)
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070052 : mClient(client), mSurface(surface),
Mathias Agopian50c24a22011-07-20 16:46:11 -070053 mToken(data.token), mIdentity(data.identity)
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070054{
55}
Mathias Agopian69d62092009-04-16 20:30:22 -070056
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070057SurfaceControl::~SurfaceControl()
58{
59 destroy();
60}
61
62void SurfaceControl::destroy()
63{
Mathias Agopian69d62092009-04-16 20:30:22 -070064 if (isValid()) {
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070065 mClient->destroySurface(mToken);
66 }
67
68 // clear all references and trigger an IPC now, to make sure things
69 // happen without delay, since these resources are quite heavy.
70 mClient.clear();
71 mSurface.clear();
72 IPCThreadState::self()->flushCommands();
73}
74
75void SurfaceControl::clear()
76{
77 // here, the window manager tells us explicitly that we should destroy
78 // the surface's resource. Soon after this call, it will also release
79 // its last reference (which will call the dtor); however, it is possible
80 // that a client living in the same process still holds references which
81 // would delay the call to the dtor -- that is why we need this explicit
82 // "clear()" call.
83 destroy();
84}
85
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070086bool SurfaceControl::isSameSurface(
87 const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs)
88{
89 if (lhs == 0 || rhs == 0)
90 return false;
91 return lhs->mSurface->asBinder() == rhs->mSurface->asBinder();
92}
93
Mathias Agopian17f638b2009-04-16 20:04:08 -070094status_t SurfaceControl::setLayer(int32_t layer) {
Mathias Agopian18e02602009-11-13 15:26:29 -080095 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -070096 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -070097 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -070098 return client->setLayer(mToken, layer);
99}
100status_t SurfaceControl::setPosition(int32_t x, int32_t y) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800101 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700102 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700103 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700104 return client->setPosition(mToken, x, y);
105}
106status_t SurfaceControl::setSize(uint32_t w, uint32_t h) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800107 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700108 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700109 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700110 return client->setSize(mToken, w, h);
111}
112status_t SurfaceControl::hide() {
Mathias Agopian18e02602009-11-13 15:26:29 -0800113 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700114 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700115 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700116 return client->hide(mToken);
117}
118status_t SurfaceControl::show(int32_t layer) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800119 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700120 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700121 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700122 return client->show(mToken, layer);
123}
124status_t SurfaceControl::freeze() {
Mathias Agopian18e02602009-11-13 15:26:29 -0800125 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700126 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700127 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700128 return client->freeze(mToken);
129}
130status_t SurfaceControl::unfreeze() {
Mathias Agopian18e02602009-11-13 15:26:29 -0800131 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700132 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700133 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700134 return client->unfreeze(mToken);
135}
136status_t SurfaceControl::setFlags(uint32_t flags, uint32_t mask) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800137 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700138 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700139 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700140 return client->setFlags(mToken, flags, mask);
141}
142status_t SurfaceControl::setTransparentRegionHint(const Region& transparent) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800143 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700144 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700145 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700146 return client->setTransparentRegionHint(mToken, transparent);
147}
148status_t SurfaceControl::setAlpha(float alpha) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800149 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700150 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700151 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700152 return client->setAlpha(mToken, alpha);
153}
154status_t SurfaceControl::setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800155 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700156 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700157 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700158 return client->setMatrix(mToken, dsdx, dtdx, dsdy, dtdy);
159}
160status_t SurfaceControl::setFreezeTint(uint32_t tint) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800161 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700162 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700163 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700164 return client->setFreezeTint(mToken, tint);
165}
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700166
Mathias Agopian18e02602009-11-13 15:26:29 -0800167status_t SurfaceControl::validate() const
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700168{
169 if (mToken<0 || mClient==0) {
Steve Blockc6aacce2012-01-06 19:20:56 +0000170 ALOGE("invalid token (%d, identity=%u) or client (%p)",
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700171 mToken, mIdentity, mClient.get());
172 return NO_INIT;
173 }
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700174 return NO_ERROR;
175}
176
Mathias Agopian17f638b2009-04-16 20:04:08 -0700177status_t SurfaceControl::writeSurfaceToParcel(
178 const sp<SurfaceControl>& control, Parcel* parcel)
179{
Mathias Agopian5e140102010-06-08 19:54:15 -0700180 sp<ISurface> sur;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700181 uint32_t identity = 0;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700182 if (SurfaceControl::isValid(control)) {
Mathias Agopian17f638b2009-04-16 20:04:08 -0700183 sur = control->mSurface;
Mathias Agopian5e140102010-06-08 19:54:15 -0700184 identity = control->mIdentity;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700185 }
Mathias Agopian7623da42010-06-01 15:12:58 -0700186 parcel->writeStrongBinder(sur!=0 ? sur->asBinder() : NULL);
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700187 parcel->writeStrongBinder(NULL); // NULL ISurfaceTexture in this case.
Mathias Agopian17f638b2009-04-16 20:04:08 -0700188 parcel->writeInt32(identity);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700189 return NO_ERROR;
190}
191
192sp<Surface> SurfaceControl::getSurface() const
193{
194 Mutex::Autolock _l(mLock);
195 if (mSurfaceData == 0) {
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700196 sp<SurfaceControl> surface_control(const_cast<SurfaceControl*>(this));
197 mSurfaceData = new Surface(surface_control);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700198 }
199 return mSurfaceData;
200}
201
Mathias Agopian1473f462009-04-10 14:24:30 -0700202// ============================================================================
203// Surface
204// ============================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205
Mathias Agopian7623da42010-06-01 15:12:58 -0700206// ---------------------------------------------------------------------------
207
Mathias Agopian17f638b2009-04-16 20:04:08 -0700208Surface::Surface(const sp<SurfaceControl>& surface)
Mathias Agopian949be322011-07-13 17:39:11 -0700209 : SurfaceTextureClient(),
Mathias Agopian7623da42010-06-01 15:12:58 -0700210 mSurface(surface->mSurface),
Mathias Agopian50c24a22011-07-20 16:46:11 -0700211 mIdentity(surface->mIdentity)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212{
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700213 sp<ISurfaceTexture> st;
214 if (mSurface != NULL) {
215 st = mSurface->getSurfaceTexture();
216 }
217 init(st);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700218}
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700219
Mathias Agopianfae5cb22010-06-04 18:26:32 -0700220Surface::Surface(const Parcel& parcel, const sp<IBinder>& ref)
Mathias Agopian50c24a22011-07-20 16:46:11 -0700221 : SurfaceTextureClient()
Mathias Agopian17f638b2009-04-16 20:04:08 -0700222{
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700223 mSurface = interface_cast<ISurface>(ref);
224 sp<IBinder> st_binder(parcel.readStrongBinder());
225 sp<ISurfaceTexture> st;
226 if (st_binder != NULL) {
227 st = interface_cast<ISurfaceTexture>(st_binder);
228 } else if (mSurface != NULL) {
229 st = mSurface->getSurfaceTexture();
230 }
231
Mathias Agopian17f638b2009-04-16 20:04:08 -0700232 mIdentity = parcel.readInt32();
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700233 init(st);
234}
235
236Surface::Surface(const sp<ISurfaceTexture>& st)
237 : SurfaceTextureClient(),
238 mSurface(NULL),
239 mIdentity(0)
240{
241 init(st);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700242}
243
Mathias Agopian5e140102010-06-08 19:54:15 -0700244status_t Surface::writeToParcel(
245 const sp<Surface>& surface, Parcel* parcel)
246{
247 sp<ISurface> sur;
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700248 sp<ISurfaceTexture> st;
Mathias Agopian5e140102010-06-08 19:54:15 -0700249 uint32_t identity = 0;
Mathias Agopian5e140102010-06-08 19:54:15 -0700250 if (Surface::isValid(surface)) {
251 sur = surface->mSurface;
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700252 st = surface->getISurfaceTexture();
Mathias Agopian5e140102010-06-08 19:54:15 -0700253 identity = surface->mIdentity;
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700254 } else if (surface != 0 &&
255 (surface->mSurface != NULL ||
256 surface->getISurfaceTexture() != NULL)) {
Steve Blockc6aacce2012-01-06 19:20:56 +0000257 ALOGE("Parceling invalid surface with non-NULL ISurface/ISurfaceTexture as NULL: "
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700258 "mSurface = %p, surfaceTexture = %p, mIdentity = %d, ",
259 surface->mSurface.get(), surface->getISurfaceTexture().get(),
260 surface->mIdentity);
Mathias Agopian5e140102010-06-08 19:54:15 -0700261 }
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700262
263 parcel->writeStrongBinder(sur != NULL ? sur->asBinder() : NULL);
264 parcel->writeStrongBinder(st != NULL ? st->asBinder() : NULL);
Mathias Agopian5e140102010-06-08 19:54:15 -0700265 parcel->writeInt32(identity);
Mathias Agopian5e140102010-06-08 19:54:15 -0700266 return NO_ERROR;
267
268}
269
Jamie Gennis5ee65f02010-07-15 17:29:15 -0700270Mutex Surface::sCachedSurfacesLock;
Mathias Agopian06f9ebf2010-12-13 16:47:31 -0800271DefaultKeyedVector<wp<IBinder>, wp<Surface> > Surface::sCachedSurfaces;
Jamie Gennis5ee65f02010-07-15 17:29:15 -0700272
273sp<Surface> Surface::readFromParcel(const Parcel& data) {
274 Mutex::Autolock _l(sCachedSurfacesLock);
Mathias Agopianfae5cb22010-06-04 18:26:32 -0700275 sp<IBinder> binder(data.readStrongBinder());
Jamie Gennis5ee65f02010-07-15 17:29:15 -0700276 sp<Surface> surface = sCachedSurfaces.valueFor(binder).promote();
277 if (surface == 0) {
278 surface = new Surface(data, binder);
279 sCachedSurfaces.add(binder, surface);
Ted Bonkenburg3f945fa2011-08-09 22:38:41 -0700280 } else {
281 // The Surface was found in the cache, but we still should clear any
282 // remaining data from the parcel.
283 data.readStrongBinder(); // ISurfaceTexture
284 data.readInt32(); // identity
Mathias Agopianfae5cb22010-06-04 18:26:32 -0700285 }
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700286 if (surface->mSurface == NULL && surface->getISurfaceTexture() == NULL) {
287 surface = 0;
Jamie Gennis5ee65f02010-07-15 17:29:15 -0700288 }
Mathias Agopian06f9ebf2010-12-13 16:47:31 -0800289 cleanCachedSurfacesLocked();
Jamie Gennis5ee65f02010-07-15 17:29:15 -0700290 return surface;
291}
292
293// Remove the stale entries from the surface cache. This should only be called
294// with sCachedSurfacesLock held.
Mathias Agopian06f9ebf2010-12-13 16:47:31 -0800295void Surface::cleanCachedSurfacesLocked() {
Jamie Gennis5ee65f02010-07-15 17:29:15 -0700296 for (int i = sCachedSurfaces.size()-1; i >= 0; --i) {
297 wp<Surface> s(sCachedSurfaces.valueAt(i));
298 if (s == 0 || s.promote() == 0) {
299 sCachedSurfaces.removeItemsAt(i);
300 }
301 }
Mathias Agopianfae5cb22010-06-04 18:26:32 -0700302}
303
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700304void Surface::init(const sp<ISurfaceTexture>& surfaceTexture)
Mathias Agopian17f638b2009-04-16 20:04:08 -0700305{
Ted Bonkenburg0de171b2011-07-15 15:10:10 -0700306 if (mSurface != NULL || surfaceTexture != NULL) {
Steve Blockc6aacce2012-01-06 19:20:56 +0000307 ALOGE_IF(surfaceTexture==0, "got a NULL ISurfaceTexture from ISurface");
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700308 if (surfaceTexture != NULL) {
Mathias Agopian949be322011-07-13 17:39:11 -0700309 setISurfaceTexture(surfaceTexture);
310 setUsage(GraphicBuffer::USAGE_HW_RENDER);
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700311 }
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700312
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700313 DisplayInfo dinfo;
314 SurfaceComposerClient::getDisplayInfo(0, &dinfo);
315 const_cast<float&>(ANativeWindow::xdpi) = dinfo.xdpi;
316 const_cast<float&>(ANativeWindow::ydpi) = dinfo.ydpi;
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700317 const_cast<uint32_t&>(ANativeWindow::flags) = 0;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319}
320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321Surface::~Surface()
322{
Mathias Agopian402c3462009-04-14 18:21:47 -0700323 // clear all references and trigger an IPC now, to make sure things
324 // happen without delay, since these resources are quite heavy.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 mSurface.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 IPCThreadState::self()->flushCommands();
327}
328
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700329bool Surface::isValid() {
Mathias Agopian50c24a22011-07-20 16:46:11 -0700330 return getISurfaceTexture() != NULL;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331}
332
tedbo4e8a5c92011-06-22 15:52:53 -0700333sp<ISurfaceTexture> Surface::getSurfaceTexture() {
Mathias Agopian50c24a22011-07-20 16:46:11 -0700334 return getISurfaceTexture();
tedbo4e8a5c92011-06-22 15:52:53 -0700335}
336
Mathias Agopianc8a04b52011-04-05 15:44:20 -0700337sp<IBinder> Surface::asBinder() const {
338 return mSurface!=0 ? mSurface->asBinder() : 0;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700339}
340
Mathias Agopian1473f462009-04-10 14:24:30 -0700341// ----------------------------------------------------------------------------
342
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700343int Surface::query(int what, int* value) const {
Mathias Agopian5b5c9142009-07-30 18:14:56 -0700344 switch (what) {
Jamie Gennisc4ca7c52011-03-14 15:00:06 -0700345 case NATIVE_WINDOW_CONCRETE_TYPE:
346 *value = NATIVE_WINDOW_SURFACE;
347 return NO_ERROR;
348 }
Mathias Agopian949be322011-07-13 17:39:11 -0700349 return SurfaceTextureClient::query(what, value);
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800350}
351
Mathias Agopian2be352a2010-05-21 17:24:35 -0700352// ----------------------------------------------------------------------------
353
Mathias Agopianbecc91d2011-08-23 21:09:41 -0700354status_t Surface::lock(SurfaceInfo* other, Region* inOutDirtyRegion) {
Mathias Agopian949be322011-07-13 17:39:11 -0700355 ANativeWindow_Buffer outBuffer;
Mathias Agopian2f7540e2010-03-11 15:06:54 -0800356
Mathias Agopian949be322011-07-13 17:39:11 -0700357 ARect temp;
358 ARect* inOutDirtyBounds = NULL;
Mathias Agopianbecc91d2011-08-23 21:09:41 -0700359 if (inOutDirtyRegion) {
360 temp = inOutDirtyRegion->getBounds();
Mathias Agopian949be322011-07-13 17:39:11 -0700361 inOutDirtyBounds = &temp;
Mathias Agopian2f7540e2010-03-11 15:06:54 -0800362 }
363
Mathias Agopian949be322011-07-13 17:39:11 -0700364 status_t err = SurfaceTextureClient::lock(&outBuffer, inOutDirtyBounds);
Mathias Agopian116e5412010-01-22 11:47:55 -0800365
Mathias Agopian1473f462009-04-10 14:24:30 -0700366 if (err == NO_ERROR) {
Mathias Agopian949be322011-07-13 17:39:11 -0700367 other->w = uint32_t(outBuffer.width);
368 other->h = uint32_t(outBuffer.height);
369 other->s = uint32_t(outBuffer.stride);
370 other->usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
371 other->format = uint32_t(outBuffer.format);
372 other->bits = outBuffer.bits;
Mathias Agopian1473f462009-04-10 14:24:30 -0700373 }
Mathias Agopianbecc91d2011-08-23 21:09:41 -0700374
375 if (inOutDirtyRegion) {
376 inOutDirtyRegion->set( static_cast<Rect const&>(temp) );
377 }
378
Mathias Agopian1473f462009-04-10 14:24:30 -0700379 return err;
380}
Mathias Agopian1473f462009-04-10 14:24:30 -0700381
Mathias Agopian949be322011-07-13 17:39:11 -0700382status_t Surface::unlockAndPost() {
383 return SurfaceTextureClient::unlockAndPost();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384}
385
Mathias Agopian2be352a2010-05-21 17:24:35 -0700386// ----------------------------------------------------------------------------
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387}; // namespace android