blob: 81fc019eab63af7879690a17f46d07ba6b839634 [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 Agopianac9fa422013-02-11 16:40:36 -080051 const sp<ISurface>& surface)
52 : mClient(client)
Mathias Agopian62185b72009-04-16 16:19:50 -070053{
Mathias Agopianac9fa422013-02-11 16:40:36 -080054 if (surface != 0) {
55 mSurface = surface->asBinder();
56 }
Mathias Agopian62185b72009-04-16 16:19:50 -070057}
Mathias Agopian18d84462009-04-16 20:30:22 -070058
Mathias Agopian62185b72009-04-16 16:19:50 -070059SurfaceControl::~SurfaceControl()
60{
61 destroy();
62}
63
64void SurfaceControl::destroy()
65{
Mathias Agopian18d84462009-04-16 20:30:22 -070066 if (isValid()) {
Mathias Agopianac9fa422013-02-11 16:40:36 -080067 mClient->destroySurface(mSurface);
Mathias Agopian62185b72009-04-16 16:19:50 -070068 }
Mathias Agopian62185b72009-04-16 16:19:50 -070069 // 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;
Mathias Agopianac9fa422013-02-11 16:40:36 -080092 return lhs->mSurface == rhs->mSurface;
Mathias Agopian62185b72009-04-16 16:19:50 -070093}
94
Jeff Brown9d4e3d22012-08-24 20:00:51 -070095status_t SurfaceControl::setLayerStack(int32_t layerStack) {
96 status_t err = validate();
97 if (err < 0) return err;
98 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopianac9fa422013-02-11 16:40:36 -080099 return client->setLayerStack(mSurface, layerStack);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700100}
Mathias Agopian01b76682009-04-16 20:04:08 -0700101status_t SurfaceControl::setLayer(int32_t layer) {
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 Agopianac9fa422013-02-11 16:40:36 -0800105 return client->setLayer(mSurface, layer);
Mathias Agopian01b76682009-04-16 20:04:08 -0700106}
107status_t SurfaceControl::setPosition(int32_t x, int32_t y) {
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 Agopianac9fa422013-02-11 16:40:36 -0800111 return client->setPosition(mSurface, x, y);
Mathias Agopian01b76682009-04-16 20:04:08 -0700112}
113status_t SurfaceControl::setSize(uint32_t w, uint32_t h) {
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 Agopianac9fa422013-02-11 16:40:36 -0800117 return client->setSize(mSurface, w, h);
Mathias Agopian01b76682009-04-16 20:04:08 -0700118}
119status_t SurfaceControl::hide() {
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 Agopianac9fa422013-02-11 16:40:36 -0800123 return client->hide(mSurface);
Mathias Agopian01b76682009-04-16 20:04:08 -0700124}
Jeff Brown380223b2012-08-26 22:49:35 -0700125status_t SurfaceControl::show() {
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 Agopianac9fa422013-02-11 16:40:36 -0800129 return client->show(mSurface);
Mathias Agopian01b76682009-04-16 20:04:08 -0700130}
Mathias Agopian01b76682009-04-16 20:04:08 -0700131status_t SurfaceControl::setFlags(uint32_t flags, uint32_t mask) {
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 Agopianac9fa422013-02-11 16:40:36 -0800135 return client->setFlags(mSurface, flags, mask);
Mathias Agopian01b76682009-04-16 20:04:08 -0700136}
137status_t SurfaceControl::setTransparentRegionHint(const Region& transparent) {
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 Agopianac9fa422013-02-11 16:40:36 -0800141 return client->setTransparentRegionHint(mSurface, transparent);
Mathias Agopian01b76682009-04-16 20:04:08 -0700142}
143status_t SurfaceControl::setAlpha(float alpha) {
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 Agopianac9fa422013-02-11 16:40:36 -0800147 return client->setAlpha(mSurface, alpha);
Mathias Agopian01b76682009-04-16 20:04:08 -0700148}
149status_t SurfaceControl::setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
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 Agopianac9fa422013-02-11 16:40:36 -0800153 return client->setMatrix(mSurface, dsdx, dtdx, dsdy, dtdy);
Mathias Agopian01b76682009-04-16 20:04:08 -0700154}
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700155status_t SurfaceControl::setCrop(const Rect& crop) {
156 status_t err = validate();
157 if (err < 0) return err;
158 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800159 return client->setCrop(mSurface, crop);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700160}
Mathias Agopian62185b72009-04-16 16:19:50 -0700161
Mathias Agopian963abad2009-11-13 15:26:29 -0800162status_t SurfaceControl::validate() const
Mathias Agopian62185b72009-04-16 16:19:50 -0700163{
Mathias Agopianac9fa422013-02-11 16:40:36 -0800164 if (mSurface==0 || mClient==0) {
165 ALOGE("invalid ISurface (%p) or client (%p)",
166 mSurface.get(), mClient.get());
Mathias Agopian62185b72009-04-16 16:19:50 -0700167 return NO_INIT;
168 }
Mathias Agopian62185b72009-04-16 16:19:50 -0700169 return NO_ERROR;
170}
171
Mathias Agopian01b76682009-04-16 20:04:08 -0700172status_t SurfaceControl::writeSurfaceToParcel(
173 const sp<SurfaceControl>& control, Parcel* parcel)
174{
Mathias Agopianac9fa422013-02-11 16:40:36 -0800175 sp<IBinder> sur;
Mathias Agopian01b76682009-04-16 20:04:08 -0700176 if (SurfaceControl::isValid(control)) {
Mathias Agopianac9fa422013-02-11 16:40:36 -0800177 sur = control->mSurface;
Mathias Agopian01b76682009-04-16 20:04:08 -0700178 }
Mathias Agopianac9fa422013-02-11 16:40:36 -0800179 parcel->writeStrongBinder(sur);
Andy McFadden2adaf042012-12-18 09:49:45 -0800180 parcel->writeStrongBinder(NULL); // NULL IGraphicBufferProducer in this case.
Mathias Agopian01b76682009-04-16 20:04:08 -0700181 return NO_ERROR;
182}
183
184sp<Surface> SurfaceControl::getSurface() const
185{
186 Mutex::Autolock _l(mLock);
187 if (mSurfaceData == 0) {
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700188 sp<SurfaceControl> surface_control(const_cast<SurfaceControl*>(this));
189 mSurfaceData = new Surface(surface_control);
Mathias Agopian01b76682009-04-16 20:04:08 -0700190 }
191 return mSurfaceData;
192}
193
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700194// ============================================================================
195// Surface
196// ============================================================================
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800197
Mathias Agopian01b76682009-04-16 20:04:08 -0700198Surface::Surface(const sp<SurfaceControl>& surface)
Mathias Agopianac9fa422013-02-11 16:40:36 -0800199 : SurfaceTextureClient()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800200{
Mathias Agopianac9fa422013-02-11 16:40:36 -0800201 mSurface = interface_cast<ISurface>(surface->mSurface);
Andy McFadden2adaf042012-12-18 09:49:45 -0800202 sp<IGraphicBufferProducer> st;
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700203 if (mSurface != NULL) {
204 st = mSurface->getSurfaceTexture();
205 }
206 init(st);
Mathias Agopian01b76682009-04-16 20:04:08 -0700207}
Mathias Agopian62185b72009-04-16 16:19:50 -0700208
Mathias Agopiana0c30e92010-06-04 18:26:32 -0700209Surface::Surface(const Parcel& parcel, const sp<IBinder>& ref)
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700210 : SurfaceTextureClient()
Mathias Agopian01b76682009-04-16 20:04:08 -0700211{
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700212 mSurface = interface_cast<ISurface>(ref);
213 sp<IBinder> st_binder(parcel.readStrongBinder());
Andy McFadden2adaf042012-12-18 09:49:45 -0800214 sp<IGraphicBufferProducer> st;
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700215 if (st_binder != NULL) {
Andy McFadden2adaf042012-12-18 09:49:45 -0800216 st = interface_cast<IGraphicBufferProducer>(st_binder);
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700217 } else if (mSurface != NULL) {
218 st = mSurface->getSurfaceTexture();
219 }
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700220 init(st);
221}
222
Andy McFadden2adaf042012-12-18 09:49:45 -0800223Surface::Surface(const sp<IGraphicBufferProducer>& st)
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700224 : SurfaceTextureClient(),
Mathias Agopianac9fa422013-02-11 16:40:36 -0800225 mSurface(NULL)
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700226{
227 init(st);
Mathias Agopian01b76682009-04-16 20:04:08 -0700228}
229
Mathias Agopian579b3f82010-06-08 19:54:15 -0700230status_t Surface::writeToParcel(
231 const sp<Surface>& surface, Parcel* parcel)
232{
233 sp<ISurface> sur;
Andy McFadden2adaf042012-12-18 09:49:45 -0800234 sp<IGraphicBufferProducer> st;
Mathias Agopian579b3f82010-06-08 19:54:15 -0700235 uint32_t identity = 0;
Mathias Agopian579b3f82010-06-08 19:54:15 -0700236 if (Surface::isValid(surface)) {
237 sur = surface->mSurface;
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700238 st = surface->getISurfaceTexture();
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700239 } else if (surface != 0 &&
240 (surface->mSurface != NULL ||
241 surface->getISurfaceTexture() != NULL)) {
Andy McFadden2adaf042012-12-18 09:49:45 -0800242 ALOGE("Parceling invalid surface with non-NULL ISurface/IGraphicBufferProducer "
Mathias Agopianac9fa422013-02-11 16:40:36 -0800243 "as NULL: mSurface = %p, bufferProducer = %p ",
244 surface->mSurface.get(), surface->getISurfaceTexture().get());
Mathias Agopian579b3f82010-06-08 19:54:15 -0700245 }
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700246
247 parcel->writeStrongBinder(sur != NULL ? sur->asBinder() : NULL);
248 parcel->writeStrongBinder(st != NULL ? st->asBinder() : NULL);
Mathias Agopian579b3f82010-06-08 19:54:15 -0700249 return NO_ERROR;
250
251}
252
Jamie Gennisaca4e222010-07-15 17:29:15 -0700253Mutex Surface::sCachedSurfacesLock;
Mathias Agopian455d18d2010-12-13 16:47:31 -0800254DefaultKeyedVector<wp<IBinder>, wp<Surface> > Surface::sCachedSurfaces;
Jamie Gennisaca4e222010-07-15 17:29:15 -0700255
256sp<Surface> Surface::readFromParcel(const Parcel& data) {
257 Mutex::Autolock _l(sCachedSurfacesLock);
Mathias Agopiana0c30e92010-06-04 18:26:32 -0700258 sp<IBinder> binder(data.readStrongBinder());
Jamie Gennisaca4e222010-07-15 17:29:15 -0700259 sp<Surface> surface = sCachedSurfaces.valueFor(binder).promote();
260 if (surface == 0) {
261 surface = new Surface(data, binder);
262 sCachedSurfaces.add(binder, surface);
Ted Bonkenburge5d6eb82011-08-09 22:38:41 -0700263 } else {
264 // The Surface was found in the cache, but we still should clear any
265 // remaining data from the parcel.
Andy McFadden2adaf042012-12-18 09:49:45 -0800266 data.readStrongBinder(); // IGraphicBufferProducer
Ted Bonkenburge5d6eb82011-08-09 22:38:41 -0700267 data.readInt32(); // identity
Mathias Agopiana0c30e92010-06-04 18:26:32 -0700268 }
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700269 if (surface->mSurface == NULL && surface->getISurfaceTexture() == NULL) {
270 surface = 0;
Jamie Gennisaca4e222010-07-15 17:29:15 -0700271 }
Mathias Agopian455d18d2010-12-13 16:47:31 -0800272 cleanCachedSurfacesLocked();
Jamie Gennisaca4e222010-07-15 17:29:15 -0700273 return surface;
274}
275
276// Remove the stale entries from the surface cache. This should only be called
277// with sCachedSurfacesLock held.
Mathias Agopian455d18d2010-12-13 16:47:31 -0800278void Surface::cleanCachedSurfacesLocked() {
Jamie Gennisaca4e222010-07-15 17:29:15 -0700279 for (int i = sCachedSurfaces.size()-1; i >= 0; --i) {
280 wp<Surface> s(sCachedSurfaces.valueAt(i));
281 if (s == 0 || s.promote() == 0) {
282 sCachedSurfaces.removeItemsAt(i);
283 }
284 }
Mathias Agopiana0c30e92010-06-04 18:26:32 -0700285}
286
Andy McFadden2adaf042012-12-18 09:49:45 -0800287void Surface::init(const sp<IGraphicBufferProducer>& bufferProducer)
Mathias Agopian01b76682009-04-16 20:04:08 -0700288{
Andy McFadden2adaf042012-12-18 09:49:45 -0800289 if (mSurface != NULL || bufferProducer != NULL) {
290 ALOGE_IF(bufferProducer==0, "got a NULL IGraphicBufferProducer from ISurface");
291 if (bufferProducer != NULL) {
292 setISurfaceTexture(bufferProducer);
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700293 setUsage(GraphicBuffer::USAGE_HW_RENDER);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700294 }
Mathias Agopian631f3582010-05-25 17:51:34 -0700295
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700296 // TODO: the display metrics should come from the display manager
Mathias Agopiana67932f2011-04-20 14:20:59 -0700297 DisplayInfo dinfo;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700298 sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay(
299 ISurfaceComposer::eDisplayIdMain);
300 SurfaceComposerClient::getDisplayInfo(display, &dinfo);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700301 const_cast<float&>(ANativeWindow::xdpi) = dinfo.xdpi;
302 const_cast<float&>(ANativeWindow::ydpi) = dinfo.ydpi;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700303 const_cast<uint32_t&>(ANativeWindow::flags) = 0;
Mathias Agopian631f3582010-05-25 17:51:34 -0700304 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800305}
306
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800307Surface::~Surface()
308{
Mathias Agopian40b7f6e2009-04-14 18:21:47 -0700309 // clear all references and trigger an IPC now, to make sure things
310 // happen without delay, since these resources are quite heavy.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800311 mSurface.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800312 IPCThreadState::self()->flushCommands();
313}
314
Mathias Agopian631f3582010-05-25 17:51:34 -0700315bool Surface::isValid() {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700316 return getISurfaceTexture() != NULL;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800317}
318
Andy McFadden2adaf042012-12-18 09:49:45 -0800319sp<IGraphicBufferProducer> Surface::getSurfaceTexture() {
Mathias Agopianc10d9d92011-07-20 16:46:11 -0700320 return getISurfaceTexture();
tedbo1e7fa9e2011-06-22 15:52:53 -0700321}
322
Mathias Agopian47d87302011-04-05 15:44:20 -0700323sp<IBinder> Surface::asBinder() const {
324 return mSurface!=0 ? mSurface->asBinder() : 0;
Mathias Agopian631f3582010-05-25 17:51:34 -0700325}
326
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700327// ----------------------------------------------------------------------------
328
Mathias Agopiana67932f2011-04-20 14:20:59 -0700329int Surface::query(int what, int* value) const {
Mathias Agopiancb6b9042009-07-30 18:14:56 -0700330 switch (what) {
Jamie Gennis391bbe22011-03-14 15:00:06 -0700331 case NATIVE_WINDOW_CONCRETE_TYPE:
332 *value = NATIVE_WINDOW_SURFACE;
333 return NO_ERROR;
334 }
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700335 return SurfaceTextureClient::query(what, value);
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800336}
337
Mathias Agopiana138f892010-05-21 17:24:35 -0700338// ----------------------------------------------------------------------------
339
Mathias Agopian87a96ea2011-08-23 21:09:41 -0700340status_t Surface::lock(SurfaceInfo* other, Region* inOutDirtyRegion) {
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700341 ANativeWindow_Buffer outBuffer;
Mathias Agopian55fa2512010-03-11 15:06:54 -0800342
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700343 ARect temp;
344 ARect* inOutDirtyBounds = NULL;
Mathias Agopian87a96ea2011-08-23 21:09:41 -0700345 if (inOutDirtyRegion) {
346 temp = inOutDirtyRegion->getBounds();
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700347 inOutDirtyBounds = &temp;
Mathias Agopian55fa2512010-03-11 15:06:54 -0800348 }
349
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700350 status_t err = SurfaceTextureClient::lock(&outBuffer, inOutDirtyBounds);
Mathias Agopian90147262010-01-22 11:47:55 -0800351
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700352 if (err == NO_ERROR) {
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700353 other->w = uint32_t(outBuffer.width);
354 other->h = uint32_t(outBuffer.height);
355 other->s = uint32_t(outBuffer.stride);
356 other->usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
357 other->format = uint32_t(outBuffer.format);
358 other->bits = outBuffer.bits;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700359 }
Mathias Agopian87a96ea2011-08-23 21:09:41 -0700360
361 if (inOutDirtyRegion) {
362 inOutDirtyRegion->set( static_cast<Rect const&>(temp) );
363 }
364
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700365 return err;
366}
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700367
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700368status_t Surface::unlockAndPost() {
369 return SurfaceTextureClient::unlockAndPost();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800370}
371
Mathias Agopiana138f892010-05-21 17:24:35 -0700372// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373}; // namespace android