blob: d7590f013c14af0264f58c451109be3256d8c519 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-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 Projectedbf3b62009-03-03 19:31:44 -080020#include <errno.h>
21#include <sys/types.h>
22#include <sys/stat.h>
23
Mathias Agopianb0e76f42012-03-23 14:15:44 -070024#include <android/native_window.h>
25
Mathias Agopiancbb288b2009-09-07 16:32:45 -070026#include <utils/CallStack.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070027#include <utils/Errors.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080028#include <utils/Log.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070029#include <utils/threads.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080030
Mathias Agopiana67932f2011-04-20 14:20:59 -070031#include <binder/IPCThreadState.h>
32
Mathias Agopian076b1cc2009-04-10 14:24:30 -070033#include <ui/DisplayInfo.h>
Mathias Agopian3330b202009-10-05 17:07:12 -070034#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035#include <ui/Rect.h>
36
Mathias Agopian90ac7992012-02-25 18:48:35 -080037#include <gui/ISurface.h>
38#include <gui/ISurfaceComposer.h>
39#include <gui/Surface.h>
40#include <gui/SurfaceComposerClient.h>
41#include <gui/SurfaceTextureClient.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070042
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043namespace android {
44
Mathias Agopian62185b72009-04-16 16:19:50 -070045// ============================================================================
46// SurfaceControl
47// ============================================================================
48
Mathias Agopian01b76682009-04-16 20:04:08 -070049SurfaceControl::SurfaceControl(
50 const sp<SurfaceComposerClient>& client,
Mathias Agopian62185b72009-04-16 16:19:50 -070051 const sp<ISurface>& surface,
Mathias Agopianc10d9d92011-07-20 16:46:11 -070052 const ISurfaceComposerClient::surface_data_t& data)
Mathias Agopian62185b72009-04-16 16:19:50 -070053 : mClient(client), mSurface(surface),
Mathias Agopianc10d9d92011-07-20 16:46:11 -070054 mToken(data.token), mIdentity(data.identity)
Mathias Agopian62185b72009-04-16 16:19:50 -070055{
56}
Mathias Agopian18d84462009-04-16 20:30:22 -070057
Mathias Agopian62185b72009-04-16 16:19:50 -070058SurfaceControl::~SurfaceControl()
59{
60 destroy();
61}
62
63void SurfaceControl::destroy()
64{
Mathias Agopian18d84462009-04-16 20:30:22 -070065 if (isValid()) {
Mathias Agopian62185b72009-04-16 16:19:50 -070066 mClient->destroySurface(mToken);
67 }
68
69 // clear all references and trigger an IPC now, to make sure things
70 // happen without delay, since these resources are quite heavy.
71 mClient.clear();
72 mSurface.clear();
73 IPCThreadState::self()->flushCommands();
74}
75
76void SurfaceControl::clear()
77{
78 // here, the window manager tells us explicitly that we should destroy
79 // the surface's resource. Soon after this call, it will also release
80 // its last reference (which will call the dtor); however, it is possible
81 // that a client living in the same process still holds references which
82 // would delay the call to the dtor -- that is why we need this explicit
83 // "clear()" call.
84 destroy();
85}
86
Mathias Agopian62185b72009-04-16 16:19:50 -070087bool SurfaceControl::isSameSurface(
88 const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs)
89{
90 if (lhs == 0 || rhs == 0)
91 return false;
92 return lhs->mSurface->asBinder() == rhs->mSurface->asBinder();
93}
94
Mathias Agopian01b76682009-04-16 20:04:08 -070095status_t SurfaceControl::setLayer(int32_t layer) {
Mathias Agopian963abad2009-11-13 15:26:29 -080096 status_t err = validate();
Mathias Agopian01b76682009-04-16 20:04:08 -070097 if (err < 0) return err;
Mathias Agopian631f3582010-05-25 17:51:34 -070098 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian01b76682009-04-16 20:04:08 -070099 return client->setLayer(mToken, layer);
100}
101status_t SurfaceControl::setPosition(int32_t x, int32_t y) {
Mathias Agopian963abad2009-11-13 15:26:29 -0800102 status_t err = validate();
Mathias Agopian01b76682009-04-16 20:04:08 -0700103 if (err < 0) return err;
Mathias Agopian631f3582010-05-25 17:51:34 -0700104 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian01b76682009-04-16 20:04:08 -0700105 return client->setPosition(mToken, x, y);
106}
107status_t SurfaceControl::setSize(uint32_t w, uint32_t h) {
Mathias Agopian963abad2009-11-13 15:26:29 -0800108 status_t err = validate();
Mathias Agopian01b76682009-04-16 20:04:08 -0700109 if (err < 0) return err;
Mathias Agopian631f3582010-05-25 17:51:34 -0700110 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian01b76682009-04-16 20:04:08 -0700111 return client->setSize(mToken, w, h);
112}
113status_t SurfaceControl::hide() {
Mathias Agopian963abad2009-11-13 15:26:29 -0800114 status_t err = validate();
Mathias Agopian01b76682009-04-16 20:04:08 -0700115 if (err < 0) return err;
Mathias Agopian631f3582010-05-25 17:51:34 -0700116 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian01b76682009-04-16 20:04:08 -0700117 return client->hide(mToken);
118}
119status_t SurfaceControl::show(int32_t layer) {
Mathias Agopian963abad2009-11-13 15:26:29 -0800120 status_t err = validate();
Mathias Agopian01b76682009-04-16 20:04:08 -0700121 if (err < 0) return err;
Mathias Agopian631f3582010-05-25 17:51:34 -0700122 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian01b76682009-04-16 20:04:08 -0700123 return client->show(mToken, layer);
124}
125status_t SurfaceControl::freeze() {
Mathias Agopian963abad2009-11-13 15:26:29 -0800126 status_t err = validate();
Mathias Agopian01b76682009-04-16 20:04:08 -0700127 if (err < 0) return err;
Mathias Agopian631f3582010-05-25 17:51:34 -0700128 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian01b76682009-04-16 20:04:08 -0700129 return client->freeze(mToken);
130}
131status_t SurfaceControl::unfreeze() {
Mathias Agopian963abad2009-11-13 15:26:29 -0800132 status_t err = validate();
Mathias Agopian01b76682009-04-16 20:04:08 -0700133 if (err < 0) return err;
Mathias Agopian631f3582010-05-25 17:51:34 -0700134 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian01b76682009-04-16 20:04:08 -0700135 return client->unfreeze(mToken);
136}
137status_t SurfaceControl::setFlags(uint32_t flags, uint32_t mask) {
Mathias Agopian963abad2009-11-13 15:26:29 -0800138 status_t err = validate();
Mathias Agopian01b76682009-04-16 20:04:08 -0700139 if (err < 0) return err;
Mathias Agopian631f3582010-05-25 17:51:34 -0700140 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian01b76682009-04-16 20:04:08 -0700141 return client->setFlags(mToken, flags, mask);
142}
143status_t SurfaceControl::setTransparentRegionHint(const Region& transparent) {
Mathias Agopian963abad2009-11-13 15:26:29 -0800144 status_t err = validate();
Mathias Agopian01b76682009-04-16 20:04:08 -0700145 if (err < 0) return err;
Mathias Agopian631f3582010-05-25 17:51:34 -0700146 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian01b76682009-04-16 20:04:08 -0700147 return client->setTransparentRegionHint(mToken, transparent);
148}
149status_t SurfaceControl::setAlpha(float alpha) {
Mathias Agopian963abad2009-11-13 15:26:29 -0800150 status_t err = validate();
Mathias Agopian01b76682009-04-16 20:04:08 -0700151 if (err < 0) return err;
Mathias Agopian631f3582010-05-25 17:51:34 -0700152 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian01b76682009-04-16 20:04:08 -0700153 return client->setAlpha(mToken, alpha);
154}
155status_t SurfaceControl::setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
Mathias Agopian963abad2009-11-13 15:26:29 -0800156 status_t err = validate();
Mathias Agopian01b76682009-04-16 20:04:08 -0700157 if (err < 0) return err;
Mathias Agopian631f3582010-05-25 17:51:34 -0700158 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian01b76682009-04-16 20:04:08 -0700159 return client->setMatrix(mToken, dsdx, dtdx, dsdy, dtdy);
160}
161status_t SurfaceControl::setFreezeTint(uint32_t tint) {
Mathias Agopian963abad2009-11-13 15:26:29 -0800162 status_t err = validate();
Mathias Agopian01b76682009-04-16 20:04:08 -0700163 if (err < 0) return err;
Mathias Agopian631f3582010-05-25 17:51:34 -0700164 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian01b76682009-04-16 20:04:08 -0700165 return client->setFreezeTint(mToken, tint);
166}
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700167status_t SurfaceControl::setCrop(const Rect& crop) {
168 status_t err = validate();
169 if (err < 0) return err;
170 const sp<SurfaceComposerClient>& client(mClient);
171 return client->setCrop(mToken, crop);
172}
Mathias Agopian62185b72009-04-16 16:19:50 -0700173
Mathias Agopian963abad2009-11-13 15:26:29 -0800174status_t SurfaceControl::validate() const
Mathias Agopian62185b72009-04-16 16:19:50 -0700175{
176 if (mToken<0 || mClient==0) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000177 ALOGE("invalid token (%d, identity=%u) or client (%p)",
Mathias Agopian62185b72009-04-16 16:19:50 -0700178 mToken, mIdentity, mClient.get());
179 return NO_INIT;
180 }
Mathias Agopian62185b72009-04-16 16:19:50 -0700181 return NO_ERROR;
182}
183
Mathias Agopian01b76682009-04-16 20:04:08 -0700184status_t SurfaceControl::writeSurfaceToParcel(
185 const sp<SurfaceControl>& control, Parcel* parcel)
186{
Mathias Agopian579b3f82010-06-08 19:54:15 -0700187 sp<ISurface> sur;
Mathias Agopian01b76682009-04-16 20:04:08 -0700188 uint32_t identity = 0;
Mathias Agopian01b76682009-04-16 20:04:08 -0700189 if (SurfaceControl::isValid(control)) {
Mathias Agopian01b76682009-04-16 20:04:08 -0700190 sur = control->mSurface;
Mathias Agopian579b3f82010-06-08 19:54:15 -0700191 identity = control->mIdentity;
Mathias Agopian01b76682009-04-16 20:04:08 -0700192 }
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700193 parcel->writeStrongBinder(sur!=0 ? sur->asBinder() : NULL);
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700194 parcel->writeStrongBinder(NULL); // NULL ISurfaceTexture in this case.
Mathias Agopian01b76682009-04-16 20:04:08 -0700195 parcel->writeInt32(identity);
Mathias Agopian01b76682009-04-16 20:04:08 -0700196 return NO_ERROR;
197}
198
199sp<Surface> SurfaceControl::getSurface() const
200{
201 Mutex::Autolock _l(mLock);
202 if (mSurfaceData == 0) {
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700203 sp<SurfaceControl> surface_control(const_cast<SurfaceControl*>(this));
204 mSurfaceData = new Surface(surface_control);
Mathias Agopian01b76682009-04-16 20:04:08 -0700205 }
206 return mSurfaceData;
207}
208
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700209// ============================================================================
210// Surface
211// ============================================================================
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800212
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700213// ---------------------------------------------------------------------------
214
Mathias Agopian01b76682009-04-16 20:04:08 -0700215Surface::Surface(const sp<SurfaceControl>& surface)
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700216 : SurfaceTextureClient(),
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700217 mSurface(surface->mSurface),
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700218 mIdentity(surface->mIdentity)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800219{
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700220 sp<ISurfaceTexture> st;
221 if (mSurface != NULL) {
222 st = mSurface->getSurfaceTexture();
223 }
224 init(st);
Mathias Agopian01b76682009-04-16 20:04:08 -0700225}
Mathias Agopian62185b72009-04-16 16:19:50 -0700226
Mathias Agopiana0c30e92010-06-04 18:26:32 -0700227Surface::Surface(const Parcel& parcel, const sp<IBinder>& ref)
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700228 : SurfaceTextureClient()
Mathias Agopian01b76682009-04-16 20:04:08 -0700229{
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700230 mSurface = interface_cast<ISurface>(ref);
231 sp<IBinder> st_binder(parcel.readStrongBinder());
232 sp<ISurfaceTexture> st;
233 if (st_binder != NULL) {
234 st = interface_cast<ISurfaceTexture>(st_binder);
235 } else if (mSurface != NULL) {
236 st = mSurface->getSurfaceTexture();
237 }
238
Mathias Agopian01b76682009-04-16 20:04:08 -0700239 mIdentity = parcel.readInt32();
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700240 init(st);
241}
242
243Surface::Surface(const sp<ISurfaceTexture>& st)
244 : SurfaceTextureClient(),
245 mSurface(NULL),
246 mIdentity(0)
247{
248 init(st);
Mathias Agopian01b76682009-04-16 20:04:08 -0700249}
250
Mathias Agopian579b3f82010-06-08 19:54:15 -0700251status_t Surface::writeToParcel(
252 const sp<Surface>& surface, Parcel* parcel)
253{
254 sp<ISurface> sur;
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700255 sp<ISurfaceTexture> st;
Mathias Agopian579b3f82010-06-08 19:54:15 -0700256 uint32_t identity = 0;
Mathias Agopian579b3f82010-06-08 19:54:15 -0700257 if (Surface::isValid(surface)) {
258 sur = surface->mSurface;
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700259 st = surface->getISurfaceTexture();
Mathias Agopian579b3f82010-06-08 19:54:15 -0700260 identity = surface->mIdentity;
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700261 } else if (surface != 0 &&
262 (surface->mSurface != NULL ||
263 surface->getISurfaceTexture() != NULL)) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000264 ALOGE("Parceling invalid surface with non-NULL ISurface/ISurfaceTexture as NULL: "
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700265 "mSurface = %p, surfaceTexture = %p, mIdentity = %d, ",
266 surface->mSurface.get(), surface->getISurfaceTexture().get(),
267 surface->mIdentity);
Mathias Agopian579b3f82010-06-08 19:54:15 -0700268 }
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700269
270 parcel->writeStrongBinder(sur != NULL ? sur->asBinder() : NULL);
271 parcel->writeStrongBinder(st != NULL ? st->asBinder() : NULL);
Mathias Agopian579b3f82010-06-08 19:54:15 -0700272 parcel->writeInt32(identity);
Mathias Agopian579b3f82010-06-08 19:54:15 -0700273 return NO_ERROR;
274
275}
276
Jamie Gennisaca4e222010-07-15 17:29:15 -0700277Mutex Surface::sCachedSurfacesLock;
Mathias Agopian455d18d2010-12-13 16:47:31 -0800278DefaultKeyedVector<wp<IBinder>, wp<Surface> > Surface::sCachedSurfaces;
Jamie Gennisaca4e222010-07-15 17:29:15 -0700279
280sp<Surface> Surface::readFromParcel(const Parcel& data) {
281 Mutex::Autolock _l(sCachedSurfacesLock);
Mathias Agopiana0c30e92010-06-04 18:26:32 -0700282 sp<IBinder> binder(data.readStrongBinder());
Jamie Gennisaca4e222010-07-15 17:29:15 -0700283 sp<Surface> surface = sCachedSurfaces.valueFor(binder).promote();
284 if (surface == 0) {
285 surface = new Surface(data, binder);
286 sCachedSurfaces.add(binder, surface);
Ted Bonkenburge5d6eb82011-08-09 22:38:41 -0700287 } else {
288 // The Surface was found in the cache, but we still should clear any
289 // remaining data from the parcel.
290 data.readStrongBinder(); // ISurfaceTexture
291 data.readInt32(); // identity
Mathias Agopiana0c30e92010-06-04 18:26:32 -0700292 }
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700293 if (surface->mSurface == NULL && surface->getISurfaceTexture() == NULL) {
294 surface = 0;
Jamie Gennisaca4e222010-07-15 17:29:15 -0700295 }
Mathias Agopian455d18d2010-12-13 16:47:31 -0800296 cleanCachedSurfacesLocked();
Jamie Gennisaca4e222010-07-15 17:29:15 -0700297 return surface;
298}
299
300// Remove the stale entries from the surface cache. This should only be called
301// with sCachedSurfacesLock held.
Mathias Agopian455d18d2010-12-13 16:47:31 -0800302void Surface::cleanCachedSurfacesLocked() {
Jamie Gennisaca4e222010-07-15 17:29:15 -0700303 for (int i = sCachedSurfaces.size()-1; i >= 0; --i) {
304 wp<Surface> s(sCachedSurfaces.valueAt(i));
305 if (s == 0 || s.promote() == 0) {
306 sCachedSurfaces.removeItemsAt(i);
307 }
308 }
Mathias Agopiana0c30e92010-06-04 18:26:32 -0700309}
310
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700311void Surface::init(const sp<ISurfaceTexture>& surfaceTexture)
Mathias Agopian01b76682009-04-16 20:04:08 -0700312{
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700313 if (mSurface != NULL || surfaceTexture != NULL) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000314 ALOGE_IF(surfaceTexture==0, "got a NULL ISurfaceTexture from ISurface");
Mathias Agopiana67932f2011-04-20 14:20:59 -0700315 if (surfaceTexture != NULL) {
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700316 setISurfaceTexture(surfaceTexture);
317 setUsage(GraphicBuffer::USAGE_HW_RENDER);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700318 }
Mathias Agopian631f3582010-05-25 17:51:34 -0700319
Mathias Agopiana67932f2011-04-20 14:20:59 -0700320 DisplayInfo dinfo;
321 SurfaceComposerClient::getDisplayInfo(0, &dinfo);
322 const_cast<float&>(ANativeWindow::xdpi) = dinfo.xdpi;
323 const_cast<float&>(ANativeWindow::ydpi) = dinfo.ydpi;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700324 const_cast<uint32_t&>(ANativeWindow::flags) = 0;
Mathias Agopian631f3582010-05-25 17:51:34 -0700325 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800326}
327
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800328Surface::~Surface()
329{
Mathias Agopian40b7f6e2009-04-14 18:21:47 -0700330 // clear all references and trigger an IPC now, to make sure things
331 // happen without delay, since these resources are quite heavy.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800332 mSurface.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800333 IPCThreadState::self()->flushCommands();
334}
335
Mathias Agopian631f3582010-05-25 17:51:34 -0700336bool Surface::isValid() {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700337 return getISurfaceTexture() != NULL;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800338}
339
tedbo1e7fa9e2011-06-22 15:52:53 -0700340sp<ISurfaceTexture> Surface::getSurfaceTexture() {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700341 return getISurfaceTexture();
tedbo1e7fa9e2011-06-22 15:52:53 -0700342}
343
Mathias Agopian47d87302011-04-05 15:44:20 -0700344sp<IBinder> Surface::asBinder() const {
345 return mSurface!=0 ? mSurface->asBinder() : 0;
Mathias Agopian631f3582010-05-25 17:51:34 -0700346}
347
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700348// ----------------------------------------------------------------------------
349
Mathias Agopiana67932f2011-04-20 14:20:59 -0700350int Surface::query(int what, int* value) const {
Mathias Agopiancb6b9042009-07-30 18:14:56 -0700351 switch (what) {
Jamie Gennis391bbe22011-03-14 15:00:06 -0700352 case NATIVE_WINDOW_CONCRETE_TYPE:
353 *value = NATIVE_WINDOW_SURFACE;
354 return NO_ERROR;
355 }
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700356 return SurfaceTextureClient::query(what, value);
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800357}
358
Mathias Agopiana138f892010-05-21 17:24:35 -0700359// ----------------------------------------------------------------------------
360
Mathias Agopian87a96ea2011-08-23 21:09:41 -0700361status_t Surface::lock(SurfaceInfo* other, Region* inOutDirtyRegion) {
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700362 ANativeWindow_Buffer outBuffer;
Mathias Agopian55fa2512010-03-11 15:06:54 -0800363
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700364 ARect temp;
365 ARect* inOutDirtyBounds = NULL;
Mathias Agopian87a96ea2011-08-23 21:09:41 -0700366 if (inOutDirtyRegion) {
367 temp = inOutDirtyRegion->getBounds();
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700368 inOutDirtyBounds = &temp;
Mathias Agopian55fa2512010-03-11 15:06:54 -0800369 }
370
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700371 status_t err = SurfaceTextureClient::lock(&outBuffer, inOutDirtyBounds);
Mathias Agopian90147262010-01-22 11:47:55 -0800372
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700373 if (err == NO_ERROR) {
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700374 other->w = uint32_t(outBuffer.width);
375 other->h = uint32_t(outBuffer.height);
376 other->s = uint32_t(outBuffer.stride);
377 other->usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
378 other->format = uint32_t(outBuffer.format);
379 other->bits = outBuffer.bits;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700380 }
Mathias Agopian87a96ea2011-08-23 21:09:41 -0700381
382 if (inOutDirtyRegion) {
383 inOutDirtyRegion->set( static_cast<Rect const&>(temp) );
384 }
385
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700386 return err;
387}
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700388
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700389status_t Surface::unlockAndPost() {
390 return SurfaceTextureClient::unlockAndPost();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800391}
392
Mathias Agopiana138f892010-05-21 17:24:35 -0700393// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800394}; // namespace android