blob: dabe643f270c02b9beafd572f6b97563be1e4052 [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 Agopian07952722009-05-19 19:08:10 -070029#include <binder/IMemory.h>
Mathias Agopian7bb843c2011-04-20 14:20:59 -070030#include <binder/IPCThreadState.h>
31
32#include <gui/SurfaceTextureClient.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
Mathias Agopian1473f462009-04-10 14:24:30 -070034#include <ui/DisplayInfo.h>
Mathias Agopian6950e422009-10-05 17:07:12 -070035#include <ui/GraphicBuffer.h>
36#include <ui/GraphicBufferMapper.h>
Mathias Agopian04262e92010-09-13 22:57:58 -070037#include <ui/GraphicLog.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038#include <ui/Rect.h>
39
Mathias Agopian000479f2010-02-09 17:46:37 -080040#include <surfaceflinger/ISurface.h>
41#include <surfaceflinger/ISurfaceComposer.h>
Mathias Agopian7bb843c2011-04-20 14:20:59 -070042#include <surfaceflinger/Surface.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080043#include <surfaceflinger/SurfaceComposerClient.h>
Mathias Agopian1473f462009-04-10 14:24:30 -070044
Mathias Agopian000479f2010-02-09 17:46:37 -080045#include <private/surfaceflinger/LayerState.h>
Mathias Agopian1473f462009-04-10 14:24:30 -070046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047namespace android {
48
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070049// ============================================================================
50// SurfaceControl
51// ============================================================================
52
Mathias Agopian17f638b2009-04-16 20:04:08 -070053SurfaceControl::SurfaceControl(
54 const sp<SurfaceComposerClient>& client,
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070055 const sp<ISurface>& surface,
Mathias Agopian770492c2010-05-28 14:22:23 -070056 const ISurfaceComposerClient::surface_data_t& data,
Mathias Agopian69d62092009-04-16 20:30:22 -070057 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags)
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070058 : mClient(client), mSurface(surface),
59 mToken(data.token), mIdentity(data.identity),
Mathias Agopian18b6b492009-08-19 17:46:26 -070060 mWidth(data.width), mHeight(data.height), mFormat(data.format),
61 mFlags(flags)
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070062{
63}
Mathias Agopian69d62092009-04-16 20:30:22 -070064
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070065SurfaceControl::~SurfaceControl()
66{
67 destroy();
68}
69
70void SurfaceControl::destroy()
71{
Mathias Agopian69d62092009-04-16 20:30:22 -070072 if (isValid()) {
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070073 mClient->destroySurface(mToken);
74 }
75
76 // clear all references and trigger an IPC now, to make sure things
77 // happen without delay, since these resources are quite heavy.
78 mClient.clear();
79 mSurface.clear();
80 IPCThreadState::self()->flushCommands();
81}
82
83void SurfaceControl::clear()
84{
85 // here, the window manager tells us explicitly that we should destroy
86 // the surface's resource. Soon after this call, it will also release
87 // its last reference (which will call the dtor); however, it is possible
88 // that a client living in the same process still holds references which
89 // would delay the call to the dtor -- that is why we need this explicit
90 // "clear()" call.
91 destroy();
92}
93
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -070094bool SurfaceControl::isSameSurface(
95 const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs)
96{
97 if (lhs == 0 || rhs == 0)
98 return false;
99 return lhs->mSurface->asBinder() == rhs->mSurface->asBinder();
100}
101
Mathias Agopian17f638b2009-04-16 20:04:08 -0700102status_t SurfaceControl::setLayer(int32_t layer) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800103 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700104 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700105 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700106 return client->setLayer(mToken, layer);
107}
108status_t SurfaceControl::setPosition(int32_t x, int32_t y) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800109 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700110 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700111 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700112 return client->setPosition(mToken, x, y);
113}
114status_t SurfaceControl::setSize(uint32_t w, uint32_t h) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800115 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700116 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700117 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700118 return client->setSize(mToken, w, h);
119}
120status_t SurfaceControl::hide() {
Mathias Agopian18e02602009-11-13 15:26:29 -0800121 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700122 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700123 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700124 return client->hide(mToken);
125}
126status_t SurfaceControl::show(int32_t layer) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800127 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700128 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700129 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700130 return client->show(mToken, layer);
131}
132status_t SurfaceControl::freeze() {
Mathias Agopian18e02602009-11-13 15:26:29 -0800133 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700134 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700135 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700136 return client->freeze(mToken);
137}
138status_t SurfaceControl::unfreeze() {
Mathias Agopian18e02602009-11-13 15:26:29 -0800139 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700140 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700141 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700142 return client->unfreeze(mToken);
143}
144status_t SurfaceControl::setFlags(uint32_t flags, uint32_t mask) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800145 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700146 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700147 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700148 return client->setFlags(mToken, flags, mask);
149}
150status_t SurfaceControl::setTransparentRegionHint(const Region& transparent) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800151 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700152 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700153 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700154 return client->setTransparentRegionHint(mToken, transparent);
155}
156status_t SurfaceControl::setAlpha(float alpha) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800157 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700158 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700159 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700160 return client->setAlpha(mToken, alpha);
161}
162status_t SurfaceControl::setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800163 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700164 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700165 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700166 return client->setMatrix(mToken, dsdx, dtdx, dsdy, dtdy);
167}
168status_t SurfaceControl::setFreezeTint(uint32_t tint) {
Mathias Agopian18e02602009-11-13 15:26:29 -0800169 status_t err = validate();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700170 if (err < 0) return err;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700171 const sp<SurfaceComposerClient>& client(mClient);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700172 return client->setFreezeTint(mToken, tint);
173}
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700174
Mathias Agopian18e02602009-11-13 15:26:29 -0800175status_t SurfaceControl::validate() const
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700176{
177 if (mToken<0 || mClient==0) {
178 LOGE("invalid token (%d, identity=%u) or client (%p)",
179 mToken, mIdentity, mClient.get());
180 return NO_INIT;
181 }
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700182 return NO_ERROR;
183}
184
Mathias Agopian17f638b2009-04-16 20:04:08 -0700185status_t SurfaceControl::writeSurfaceToParcel(
186 const sp<SurfaceControl>& control, Parcel* parcel)
187{
Mathias Agopian5e140102010-06-08 19:54:15 -0700188 sp<ISurface> sur;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700189 uint32_t identity = 0;
Mathias Agopian5b5c9142009-07-30 18:14:56 -0700190 uint32_t width = 0;
191 uint32_t height = 0;
Mathias Agopian5e140102010-06-08 19:54:15 -0700192 uint32_t format = 0;
193 uint32_t flags = 0;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700194 if (SurfaceControl::isValid(control)) {
Mathias Agopian17f638b2009-04-16 20:04:08 -0700195 sur = control->mSurface;
Mathias Agopian5e140102010-06-08 19:54:15 -0700196 identity = control->mIdentity;
Mathias Agopian5b5c9142009-07-30 18:14:56 -0700197 width = control->mWidth;
198 height = control->mHeight;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700199 format = control->mFormat;
200 flags = control->mFlags;
201 }
Mathias Agopian7623da42010-06-01 15:12:58 -0700202 parcel->writeStrongBinder(sur!=0 ? sur->asBinder() : NULL);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700203 parcel->writeInt32(identity);
Mathias Agopian5b5c9142009-07-30 18:14:56 -0700204 parcel->writeInt32(width);
205 parcel->writeInt32(height);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700206 parcel->writeInt32(format);
207 parcel->writeInt32(flags);
208 return NO_ERROR;
209}
210
211sp<Surface> SurfaceControl::getSurface() const
212{
213 Mutex::Autolock _l(mLock);
214 if (mSurfaceData == 0) {
215 mSurfaceData = new Surface(const_cast<SurfaceControl*>(this));
216 }
217 return mSurfaceData;
218}
219
Mathias Agopian1473f462009-04-10 14:24:30 -0700220// ============================================================================
221// Surface
222// ============================================================================
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
Mathias Agopian7623da42010-06-01 15:12:58 -0700224// ---------------------------------------------------------------------------
225
Mathias Agopian17f638b2009-04-16 20:04:08 -0700226Surface::Surface(const sp<SurfaceControl>& surface)
Mathias Agopian949be322011-07-13 17:39:11 -0700227 : SurfaceTextureClient(),
228 mInitCheck(NO_INIT),
Mathias Agopian7623da42010-06-01 15:12:58 -0700229 mSurface(surface->mSurface),
230 mIdentity(surface->mIdentity),
231 mFormat(surface->mFormat), mFlags(surface->mFlags),
Mathias Agopian321abdb2009-08-14 18:52:17 -0700232 mWidth(surface->mWidth), mHeight(surface->mHeight)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233{
Mathias Agopian17f638b2009-04-16 20:04:08 -0700234 init();
235}
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700236
Mathias Agopianfae5cb22010-06-04 18:26:32 -0700237Surface::Surface(const Parcel& parcel, const sp<IBinder>& ref)
Mathias Agopian949be322011-07-13 17:39:11 -0700238 : SurfaceTextureClient(),
239 mInitCheck(NO_INIT)
Mathias Agopian17f638b2009-04-16 20:04:08 -0700240{
Mathias Agopianfae5cb22010-06-04 18:26:32 -0700241 mSurface = interface_cast<ISurface>(ref);
Mathias Agopian17f638b2009-04-16 20:04:08 -0700242 mIdentity = parcel.readInt32();
Mathias Agopian5b5c9142009-07-30 18:14:56 -0700243 mWidth = parcel.readInt32();
244 mHeight = parcel.readInt32();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700245 mFormat = parcel.readInt32();
246 mFlags = parcel.readInt32();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700247 init();
248}
249
Mathias Agopian5e140102010-06-08 19:54:15 -0700250status_t Surface::writeToParcel(
251 const sp<Surface>& surface, Parcel* parcel)
252{
253 sp<ISurface> sur;
254 uint32_t identity = 0;
255 uint32_t width = 0;
256 uint32_t height = 0;
257 uint32_t format = 0;
258 uint32_t flags = 0;
259 if (Surface::isValid(surface)) {
260 sur = surface->mSurface;
261 identity = surface->mIdentity;
262 width = surface->mWidth;
263 height = surface->mHeight;
264 format = surface->mFormat;
265 flags = surface->mFlags;
Jamie Gennis85cfdd02010-08-10 16:37:53 -0700266 } else if (surface != 0 && surface->mSurface != 0) {
267 LOGW("Parceling invalid surface with non-NULL ISurface as NULL: "
268 "mSurface = %p, mIdentity = %d, mWidth = %d, mHeight = %d, "
269 "mFormat = %d, mFlags = 0x%08x, mInitCheck = %d",
270 surface->mSurface.get(), surface->mIdentity, surface->mWidth,
271 surface->mHeight, surface->mFormat, surface->mFlags,
272 surface->mInitCheck);
Mathias Agopian5e140102010-06-08 19:54:15 -0700273 }
274 parcel->writeStrongBinder(sur!=0 ? sur->asBinder() : NULL);
275 parcel->writeInt32(identity);
276 parcel->writeInt32(width);
277 parcel->writeInt32(height);
278 parcel->writeInt32(format);
279 parcel->writeInt32(flags);
280 return NO_ERROR;
281
282}
283
Jamie Gennis5ee65f02010-07-15 17:29:15 -0700284Mutex Surface::sCachedSurfacesLock;
Mathias Agopian06f9ebf2010-12-13 16:47:31 -0800285DefaultKeyedVector<wp<IBinder>, wp<Surface> > Surface::sCachedSurfaces;
Jamie Gennis5ee65f02010-07-15 17:29:15 -0700286
287sp<Surface> Surface::readFromParcel(const Parcel& data) {
288 Mutex::Autolock _l(sCachedSurfacesLock);
Mathias Agopianfae5cb22010-06-04 18:26:32 -0700289 sp<IBinder> binder(data.readStrongBinder());
Jamie Gennis5ee65f02010-07-15 17:29:15 -0700290 sp<Surface> surface = sCachedSurfaces.valueFor(binder).promote();
291 if (surface == 0) {
292 surface = new Surface(data, binder);
293 sCachedSurfaces.add(binder, surface);
Mathias Agopianfae5cb22010-06-04 18:26:32 -0700294 }
Jamie Gennis5ee65f02010-07-15 17:29:15 -0700295 if (surface->mSurface == 0) {
296 surface = 0;
297 }
Mathias Agopian06f9ebf2010-12-13 16:47:31 -0800298 cleanCachedSurfacesLocked();
Jamie Gennis5ee65f02010-07-15 17:29:15 -0700299 return surface;
300}
301
302// Remove the stale entries from the surface cache. This should only be called
303// with sCachedSurfacesLock held.
Mathias Agopian06f9ebf2010-12-13 16:47:31 -0800304void Surface::cleanCachedSurfacesLocked() {
Jamie Gennis5ee65f02010-07-15 17:29:15 -0700305 for (int i = sCachedSurfaces.size()-1; i >= 0; --i) {
306 wp<Surface> s(sCachedSurfaces.valueAt(i));
307 if (s == 0 || s.promote() == 0) {
308 sCachedSurfaces.removeItemsAt(i);
309 }
310 }
Mathias Agopianfae5cb22010-06-04 18:26:32 -0700311}
312
Mathias Agopian17f638b2009-04-16 20:04:08 -0700313void Surface::init()
314{
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700315 if (mSurface != NULL) {
316 sp<ISurfaceTexture> surfaceTexture(mSurface->getSurfaceTexture());
317 LOGE_IF(surfaceTexture==0, "got a NULL ISurfaceTexture from ISurface");
318 if (surfaceTexture != NULL) {
Mathias Agopian949be322011-07-13 17:39:11 -0700319 setISurfaceTexture(surfaceTexture);
320 setUsage(GraphicBuffer::USAGE_HW_RENDER);
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700321 }
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700322
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700323 DisplayInfo dinfo;
324 SurfaceComposerClient::getDisplayInfo(0, &dinfo);
325 const_cast<float&>(ANativeWindow::xdpi) = dinfo.xdpi;
326 const_cast<float&>(ANativeWindow::ydpi) = dinfo.ydpi;
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700327 const_cast<uint32_t&>(ANativeWindow::flags) = 0;
328
Mathias Agopian949be322011-07-13 17:39:11 -0700329 if (surfaceTexture != NULL) {
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700330 mInitCheck = NO_ERROR;
Mathias Agopian7623da42010-06-01 15:12:58 -0700331 }
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700332 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333}
334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335Surface::~Surface()
336{
Mathias Agopian402c3462009-04-14 18:21:47 -0700337 // clear all references and trigger an IPC now, to make sure things
338 // happen without delay, since these resources are quite heavy.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 mSurface.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 IPCThreadState::self()->flushCommands();
341}
342
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700343bool Surface::isValid() {
344 return mInitCheck == NO_ERROR;
345}
346
Mathias Agopianafc724b2011-01-14 11:04:34 -0800347status_t Surface::validate(bool inCancelBuffer) const
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700348{
349 // check that we initialized ourself properly
350 if (mInitCheck != NO_ERROR) {
Mathias Agopian5e140102010-06-08 19:54:15 -0700351 LOGE("invalid token (identity=%u)", mIdentity);
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700352 return mInitCheck;
353 }
Mathias Agopian1473f462009-04-10 14:24:30 -0700354 return NO_ERROR;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355}
356
tedbo4e8a5c92011-06-22 15:52:53 -0700357sp<ISurfaceTexture> Surface::getSurfaceTexture() {
358 return mSurface != NULL ? mSurface->getSurfaceTexture() : NULL;
359}
360
Mathias Agopianc8a04b52011-04-05 15:44:20 -0700361sp<IBinder> Surface::asBinder() const {
362 return mSurface!=0 ? mSurface->asBinder() : 0;
Mathias Agopian2ce19af2010-05-25 17:51:34 -0700363}
364
Mathias Agopian1473f462009-04-10 14:24:30 -0700365// ----------------------------------------------------------------------------
366
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700367int Surface::query(int what, int* value) const {
Mathias Agopian5b5c9142009-07-30 18:14:56 -0700368 switch (what) {
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700369 case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER:
370 // TODO: this is not needed anymore
371 *value = 1;
Mathias Agopian9779b222009-09-07 16:32:45 -0700372 return NO_ERROR;
Jamie Gennisc4ca7c52011-03-14 15:00:06 -0700373 case NATIVE_WINDOW_CONCRETE_TYPE:
374 *value = NATIVE_WINDOW_SURFACE;
375 return NO_ERROR;
376 }
Mathias Agopian949be322011-07-13 17:39:11 -0700377 return SurfaceTextureClient::query(what, value);
Eino-Ville Talvalac5f94d82011-02-18 11:02:42 -0800378}
379
Mathias Agopian2be352a2010-05-21 17:24:35 -0700380// ----------------------------------------------------------------------------
381
Mathias Agopian949be322011-07-13 17:39:11 -0700382status_t Surface::lock(SurfaceInfo* other, Region* dirtyIn) {
383 ANativeWindow_Buffer outBuffer;
Mathias Agopian2f7540e2010-03-11 15:06:54 -0800384
Mathias Agopian949be322011-07-13 17:39:11 -0700385 ARect temp;
386 ARect* inOutDirtyBounds = NULL;
387 if (dirtyIn) {
388 temp = dirtyIn->getBounds();
389 inOutDirtyBounds = &temp;
Mathias Agopian2f7540e2010-03-11 15:06:54 -0800390 }
391
Mathias Agopian949be322011-07-13 17:39:11 -0700392 status_t err = SurfaceTextureClient::lock(&outBuffer, inOutDirtyBounds);
Mathias Agopian116e5412010-01-22 11:47:55 -0800393
Mathias Agopian1473f462009-04-10 14:24:30 -0700394 if (err == NO_ERROR) {
Mathias Agopian949be322011-07-13 17:39:11 -0700395 other->w = uint32_t(outBuffer.width);
396 other->h = uint32_t(outBuffer.height);
397 other->s = uint32_t(outBuffer.stride);
398 other->usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
399 other->format = uint32_t(outBuffer.format);
400 other->bits = outBuffer.bits;
Mathias Agopian1473f462009-04-10 14:24:30 -0700401 }
402 return err;
403}
Mathias Agopian1473f462009-04-10 14:24:30 -0700404
Mathias Agopian949be322011-07-13 17:39:11 -0700405status_t Surface::unlockAndPost() {
406 return SurfaceTextureClient::unlockAndPost();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407}
408
Mathias Agopian2be352a2010-05-21 17:24:35 -0700409// ----------------------------------------------------------------------------
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410}; // namespace android