blob: c9f1eb51d81dfc116f2bbe0c2a13c2b40c679831 [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
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080017#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019#include <stdlib.h>
20#include <stdint.h>
21#include <sys/types.h>
22
Mathias Agopiana67932f2011-04-20 14:20:59 -070023#include <cutils/compiler.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070024#include <cutils/native_handle.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070025#include <cutils/properties.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026
27#include <utils/Errors.h>
28#include <utils/Log.h>
29#include <utils/StopWatch.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080030#include <utils/Trace.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031
Mathias Agopian3330b202009-10-05 17:07:12 -070032#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033#include <ui/PixelFormat.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080034
Mathias Agopian90ac7992012-02-25 18:48:35 -080035#include <gui/Surface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036
37#include "clz.h"
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070038#include "DisplayDevice.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070039#include "GLExtensions.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040#include "Layer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041#include "SurfaceFlinger.h"
Mathias Agopiana67932f2011-04-20 14:20:59 -070042#include "SurfaceTextureLayer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043
Mathias Agopian1b031492012-06-20 17:51:20 -070044#include "DisplayHardware/HWComposer.h"
45
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046#define DEBUG_RESIZE 0
47
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048namespace android {
49
50// ---------------------------------------------------------------------------
51
Mathias Agopian3ee454a2012-08-27 16:28:24 -070052Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client)
53 : LayerBaseClient(flinger, client),
Mathias Agopiana67932f2011-04-20 14:20:59 -070054 mTextureName(-1U),
55 mQueuedFrames(0),
56 mCurrentTransform(0),
Mathias Agopian933389f2011-07-18 16:15:08 -070057 mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
Mathias Agopiana67932f2011-04-20 14:20:59 -070058 mCurrentOpacity(true),
Mathias Agopian4d143ee2012-02-23 20:05:39 -080059 mRefreshPending(false),
Mathias Agopian82d7ab62012-01-19 18:34:40 -080060 mFrameLatencyNeeded(false),
Mathias Agopian5bf3abe2011-03-11 17:01:07 -080061 mFormat(PIXEL_FORMAT_NONE),
Mathias Agopian1f7bec62010-06-25 18:02:21 -070062 mGLExtensions(GLExtensions::getInstance()),
Mathias Agopiana67932f2011-04-20 14:20:59 -070063 mOpaqueLayer(true),
Mathias Agopianb7e930d2010-06-01 15:12:58 -070064 mSecure(false),
Mathias Agopian933389f2011-07-18 16:15:08 -070065 mProtectedByApp(false)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066{
Mathias Agopiana67932f2011-04-20 14:20:59 -070067 mCurrentCrop.makeInvalid();
68 glGenTextures(1, &mTextureName);
Jamie Gennise8696a42012-01-15 18:54:57 -080069}
70
Mathias Agopian42977342012-08-05 00:40:46 -070071void Layer::onLayerDisplayed(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -070072 HWComposer::HWCLayerInterface* layer) {
Mathias Agopianc3973602012-08-31 17:51:25 -070073 LayerBaseClient::onLayerDisplayed(hw, layer);
Jesse Hallef194142012-06-14 14:45:17 -070074 if (layer) {
Andy McFaddenbf974ab2012-12-04 16:51:15 -080075 mSurfaceFlingerConsumer->setReleaseFence(layer->getAndResetReleaseFenceFd());
Jesse Hallef194142012-06-14 14:45:17 -070076 }
Mathias Agopiand606de62010-05-10 20:06:11 -070077}
78
Mathias Agopiana67932f2011-04-20 14:20:59 -070079void Layer::onFirstRef()
Mathias Agopian96f08192010-06-02 23:28:45 -070080{
Mathias Agopiana67932f2011-04-20 14:20:59 -070081 LayerBaseClient::onFirstRef();
Mathias Agopianddc31c32011-06-12 18:05:53 -070082
Andy McFaddenbf974ab2012-12-04 16:51:15 -080083 // Creates a custom BufferQueue for SurfaceFlingerConsumer to use
Daniel Lamb2675792012-02-23 14:35:13 -080084 sp<BufferQueue> bq = new SurfaceTextureLayer();
Andy McFaddenbf974ab2012-12-04 16:51:15 -080085 mSurfaceFlingerConsumer = new SurfaceFlingerConsumer(mTextureName, true,
Mathias Agopiana0db3082012-04-23 13:59:36 -070086 GL_TEXTURE_EXTERNAL_OES, false, bq);
Daniel Lamb2675792012-02-23 14:35:13 -080087
Andy McFaddenbf974ab2012-12-04 16:51:15 -080088 mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0));
89 mSurfaceFlingerConsumer->setFrameAvailableListener(this);
90 mSurfaceFlingerConsumer->setSynchronousMode(true);
Daniel Lamb2675792012-02-23 14:35:13 -080091
Mathias Agopian7f42a9c2012-04-23 20:00:16 -070092#ifdef TARGET_DISABLE_TRIPLE_BUFFERING
93#warning "disabling triple buffering"
Andy McFaddenbf974ab2012-12-04 16:51:15 -080094 mSurfaceFlingerConsumer->setDefaultMaxBufferCount(2);
Mathias Agopian7f42a9c2012-04-23 20:00:16 -070095#else
Andy McFaddenbf974ab2012-12-04 16:51:15 -080096 mSurfaceFlingerConsumer->setDefaultMaxBufferCount(3);
Mathias Agopian303d5382012-02-05 01:49:16 -080097#endif
Andy McFadden69052052012-09-14 16:10:11 -070098
Mathias Agopian84300952012-11-21 16:02:13 -080099 const sp<const DisplayDevice> hw(mFlinger->getDefaultDisplayDevice());
100 updateTransformHint(hw);
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700101}
102
Mathias Agopiana67932f2011-04-20 14:20:59 -0700103Layer::~Layer()
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700104{
Mathias Agopian921e6ac2012-07-23 23:11:29 -0700105 mFlinger->deleteTextureAsync(mTextureName);
Mathias Agopian96f08192010-06-02 23:28:45 -0700106}
107
Igor Murashkina4a31492012-10-29 13:36:11 -0700108void Layer::onFrameAvailable() {
Jamie Gennis3d8063b2011-06-26 18:27:47 -0700109 android_atomic_inc(&mQueuedFrames);
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800110 mFlinger->signalLayerUpdate();
Mathias Agopian579b3f82010-06-08 19:54:15 -0700111}
112
Mathias Agopiand606de62010-05-10 20:06:11 -0700113// called with SurfaceFlinger::mStateLock as soon as the layer is entered
114// in the purgatory list
115void Layer::onRemoved()
116{
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800117 mSurfaceFlingerConsumer->abandon();
Mathias Agopian48d819a2009-09-10 19:41:18 -0700118}
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700119
Jamie Gennisa249f2d2011-09-16 17:31:54 -0700120void Layer::setName(const String8& name) {
121 LayerBase::setName(name);
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800122 mSurfaceFlingerConsumer->setName(name);
Jamie Gennisa249f2d2011-09-16 17:31:54 -0700123}
124
Mathias Agopiana67932f2011-04-20 14:20:59 -0700125sp<ISurface> Layer::createSurface()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800126{
Andy McFadden882e3a32013-01-08 16:06:15 -0800127 /*
128 * This class provides an implementation of BnSurface (the "native" or
129 * "remote" side of the Binder IPC interface ISurface), and mixes in
130 * LayerCleaner to ensure that mFlinger->onLayerDestroyed() is called for
131 * this layer when the BSurface is destroyed.
132 *
133 * The idea is to provide a handle to the Layer through ISurface that
134 * is cleaned up automatically when the last reference to the ISurface
135 * goes away. (The references will be held on the "proxy" side, while
136 * the Layer exists on the "native" side.)
137 *
138 * The Layer has a reference to an instance of SurfaceFlinger's variant
139 * of GLConsumer, which holds a reference to the BufferQueue. The
140 * getSurfaceTexture() call returns a Binder interface reference for
141 * the producer interface of the buffer queue associated with the Layer.
142 */
Mathias Agopiana67932f2011-04-20 14:20:59 -0700143 class BSurface : public BnSurface, public LayerCleaner {
144 wp<const Layer> mOwner;
Andy McFadden2adaf042012-12-18 09:49:45 -0800145 virtual sp<IGraphicBufferProducer> getSurfaceTexture() const {
146 sp<IGraphicBufferProducer> res;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700147 sp<const Layer> that( mOwner.promote() );
148 if (that != NULL) {
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800149 res = that->mSurfaceFlingerConsumer->getBufferQueue();
Mathias Agopiana67932f2011-04-20 14:20:59 -0700150 }
151 return res;
152 }
153 public:
154 BSurface(const sp<SurfaceFlinger>& flinger,
155 const sp<Layer>& layer)
156 : LayerCleaner(flinger, layer), mOwner(layer) { }
157 };
158 sp<ISurface> sur(new BSurface(mFlinger, this));
Mathias Agopiana1f47b92011-02-15 19:01:06 -0800159 return sur;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800160}
161
Jamie Gennis582270d2011-08-17 18:19:00 -0700162wp<IBinder> Layer::getSurfaceTextureBinder() const
163{
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800164 return mSurfaceFlingerConsumer->getBufferQueue()->asBinder();
Jamie Gennis582270d2011-08-17 18:19:00 -0700165}
166
Mathias Agopianf9d93272009-06-19 17:00:27 -0700167status_t Layer::setBuffers( uint32_t w, uint32_t h,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800168 PixelFormat format, uint32_t flags)
169{
Mathias Agopian401c2572009-09-23 19:16:27 -0700170 // this surfaces pixel format
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800171 PixelFormatInfo info;
172 status_t err = getPixelFormatInfo(format, &info);
Mathias Agopianff615cc2012-02-24 14:58:36 -0800173 if (err) {
174 ALOGE("unsupported pixelformat %d", format);
175 return err;
176 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800177
Mathias Agopianca99fb82010-04-14 16:43:44 -0700178 uint32_t const maxSurfaceDims = min(
Mathias Agopiana4912602012-07-12 14:25:33 -0700179 mFlinger->getMaxTextureSize(), mFlinger->getMaxViewportDims());
Mathias Agopianca99fb82010-04-14 16:43:44 -0700180
181 // never allow a surface larger than what our underlying GL implementation
182 // can handle.
183 if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) {
Mathias Agopianff615cc2012-02-24 14:58:36 -0800184 ALOGE("dimensions too large %u x %u", uint32_t(w), uint32_t(h));
Mathias Agopianca99fb82010-04-14 16:43:44 -0700185 return BAD_VALUE;
186 }
187
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700188 mFormat = format;
Mathias Agopianeff062c2010-08-25 14:59:15 -0700189
Mathias Agopian3165cc22012-08-08 19:42:09 -0700190 mSecure = (flags & ISurfaceComposerClient::eSecure) ? true : false;
191 mProtectedByApp = (flags & ISurfaceComposerClient::eProtectedByApp) ? true : false;
192 mOpaqueLayer = (flags & ISurfaceComposerClient::eOpaque);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700193 mCurrentOpacity = getOpacityForFormat(format);
194
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800195 mSurfaceFlingerConsumer->setDefaultBufferSize(w, h);
196 mSurfaceFlingerConsumer->setDefaultBufferFormat(format);
197 mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0));
Mathias Agopianca99fb82010-04-14 16:43:44 -0700198
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800199 return NO_ERROR;
200}
201
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800202Rect Layer::getContentCrop() const {
203 // this is the crop rectangle that applies to the buffer
204 // itself (as opposed to the window)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700205 Rect crop;
206 if (!mCurrentCrop.isEmpty()) {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800207 // if the buffer crop is defined, we use that
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700208 crop = mCurrentCrop;
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800209 } else if (mActiveBuffer != NULL) {
210 // otherwise we use the whole buffer
211 crop = mActiveBuffer->getBounds();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700212 } else {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800213 // if we don't have a buffer yet, we use an empty/invalid crop
Mathias Agopian4fec8732012-06-29 14:12:52 -0700214 crop.makeInvalid();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700215 }
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700216 return crop;
217}
218
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800219uint32_t Layer::getContentTransform() const {
220 return mCurrentTransform;
221}
222
Mathias Agopian4fec8732012-06-29 14:12:52 -0700223void Layer::setGeometry(
Mathias Agopian42977342012-08-05 00:40:46 -0700224 const sp<const DisplayDevice>& hw,
Mathias Agopian4fec8732012-06-29 14:12:52 -0700225 HWComposer::HWCLayerInterface& layer)
Mathias Agopiana350ff92010-08-10 17:14:02 -0700226{
Mathias Agopian4fec8732012-06-29 14:12:52 -0700227 LayerBaseClient::setGeometry(hw, layer);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700228
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700229 // enable this layer
230 layer.setSkip(false);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700231
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700232 if (isSecure() && !hw->isSecure()) {
233 layer.setSkip(true);
234 }
235
Mathias Agopian9f8386e2013-01-29 18:56:42 -0800236 const State& s(drawingState());
237 layer.setPlaneAlpha(s.alpha);
238
Mathias Agopian29a367b2011-07-12 14:51:45 -0700239 /*
240 * Transformations are applied in this order:
241 * 1) buffer orientation/flip/mirror
242 * 2) state transformation (window manager)
243 * 3) layer orientation (screen orientation)
244 * (NOTE: the matrices are multiplied in reverse order)
245 */
246
247 const Transform bufferOrientation(mCurrentTransform);
Mathias Agopian42977342012-08-05 00:40:46 -0700248 const Transform tr(hw->getTransform() * s.transform * bufferOrientation);
Mathias Agopian29a367b2011-07-12 14:51:45 -0700249
250 // this gives us only the "orientation" component of the transform
251 const uint32_t finalTransform = tr.getOrientation();
252
Mathias Agopiana350ff92010-08-10 17:14:02 -0700253 // we can only handle simple transformation
Mathias Agopian29a367b2011-07-12 14:51:45 -0700254 if (finalTransform & Transform::ROT_INVALID) {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700255 layer.setSkip(true);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700256 } else {
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700257 layer.setTransform(finalTransform);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700258 }
Mathias Agopiana350ff92010-08-10 17:14:02 -0700259}
260
Mathias Agopian42977342012-08-05 00:40:46 -0700261void Layer::setPerFrameData(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700262 HWComposer::HWCLayerInterface& layer) {
Mathias Agopian71e83e12012-09-04 20:25:39 -0700263 LayerBaseClient::setPerFrameData(hw, layer);
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700264 // NOTE: buffer can be NULL if the client never drew into this
265 // layer yet, or if we ran out of memory
Mathias Agopian71e83e12012-09-04 20:25:39 -0700266 layer.setBuffer(mActiveBuffer);
Jesse Hallc5c5a142012-07-02 16:49:28 -0700267}
Jesse Halldc5b4852012-06-29 15:21:18 -0700268
Mathias Agopian42977342012-08-05 00:40:46 -0700269void Layer::setAcquireFence(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700270 HWComposer::HWCLayerInterface& layer) {
Jesse Hallc5c5a142012-07-02 16:49:28 -0700271 int fenceFd = -1;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700272
273 // TODO: there is a possible optimization here: we only need to set the
274 // acquire fence the first time a new buffer is acquired on EACH display.
275
276 if (layer.getCompositionType() == HWC_OVERLAY) {
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800277 sp<Fence> fence = mSurfaceFlingerConsumer->getCurrentFence();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800278 if (fence->isValid()) {
Jesse Hallc5c5a142012-07-02 16:49:28 -0700279 fenceFd = fence->dup();
Jesse Halldc5b4852012-06-29 15:21:18 -0700280 if (fenceFd == -1) {
281 ALOGW("failed to dup layer fence, skipping sync: %d", errno);
282 }
Jesse Halldc5b4852012-06-29 15:21:18 -0700283 }
Jesse Halldc5b4852012-06-29 15:21:18 -0700284 }
Jesse Hallc5c5a142012-07-02 16:49:28 -0700285 layer.setAcquireFenceFd(fenceFd);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700286}
287
Mathias Agopian42977342012-08-05 00:40:46 -0700288void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800289{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800290 ATRACE_CALL();
291
Mathias Agopiana67932f2011-04-20 14:20:59 -0700292 if (CC_UNLIKELY(mActiveBuffer == 0)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800293 // the texture has not been created yet, this Layer has
Mathias Agopian179169e2010-05-06 20:21:45 -0700294 // in fact never been drawn into. This happens frequently with
295 // SurfaceView because the WindowManager can't know when the client
296 // has drawn the first time.
297
298 // If there is nothing under us, we paint the screen in black, otherwise
299 // we just skip this update.
300
301 // figure out if there is something below us
302 Region under;
Mathias Agopianf7ae69d2011-08-23 12:34:29 -0700303 const SurfaceFlinger::LayerVector& drawingLayers(
304 mFlinger->mDrawingState.layersSortedByZ);
Mathias Agopian179169e2010-05-06 20:21:45 -0700305 const size_t count = drawingLayers.size();
306 for (size_t i=0 ; i<count ; ++i) {
307 const sp<LayerBase>& layer(drawingLayers[i]);
308 if (layer.get() == static_cast<LayerBase const*>(this))
309 break;
Mathias Agopian42977342012-08-05 00:40:46 -0700310 under.orSelf( hw->getTransform().transform(layer->visibleRegion) );
Mathias Agopian179169e2010-05-06 20:21:45 -0700311 }
312 // if not everything below us is covered, we plug the holes!
313 Region holes(clip.subtract(under));
314 if (!holes.isEmpty()) {
Mathias Agopian1b031492012-06-20 17:51:20 -0700315 clearWithOpenGL(hw, holes, 0, 0, 0, 1);
Mathias Agopian179169e2010-05-06 20:21:45 -0700316 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800317 return;
318 }
Mathias Agopiana67932f2011-04-20 14:20:59 -0700319
Andy McFadden97eba892012-12-11 15:21:45 -0800320 // Bind the current buffer to the GL texture, and wait for it to be
321 // ready for us to draw into.
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800322 status_t err = mSurfaceFlingerConsumer->bindTextureImage();
323 if (err != NO_ERROR) {
Andy McFadden97eba892012-12-11 15:21:45 -0800324 ALOGW("onDraw: bindTextureImage failed (err=%d)", err);
Jesse Halldc5b4852012-06-29 15:21:18 -0700325 // Go ahead and draw the buffer anyway; no matter what we do the screen
326 // is probably going to have something visibly wrong.
327 }
328
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700329 bool blackOutLayer = isProtected() || (isSecure() && !hw->isSecure());
330
331 if (!blackOutLayer) {
Jamie Genniscbb1a952012-05-08 17:05:52 -0700332 // TODO: we could be more subtle with isFixedSize()
Mathias Agopianeba8c682012-09-19 23:14:45 -0700333 const bool useFiltering = getFiltering() || needsFiltering(hw) || isFixedSize();
Jamie Genniscbb1a952012-05-08 17:05:52 -0700334
335 // Query the texture matrix given our current filtering mode.
336 float textureMatrix[16];
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800337 mSurfaceFlingerConsumer->setFilteringEnabled(useFiltering);
338 mSurfaceFlingerConsumer->getTransformMatrix(textureMatrix);
Jamie Genniscbb1a952012-05-08 17:05:52 -0700339
340 // Set things up for texturing.
Mathias Agopianc492e672011-10-18 14:49:27 -0700341 glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureName);
342 GLenum filter = GL_NEAREST;
Jamie Genniscbb1a952012-05-08 17:05:52 -0700343 if (useFiltering) {
Mathias Agopianc492e672011-10-18 14:49:27 -0700344 filter = GL_LINEAR;
Jamie Gennis9575f602011-10-07 14:51:16 -0700345 }
Mathias Agopianc492e672011-10-18 14:49:27 -0700346 glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, filter);
347 glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, filter);
Jamie Gennis9575f602011-10-07 14:51:16 -0700348 glMatrixMode(GL_TEXTURE);
Jamie Genniscbb1a952012-05-08 17:05:52 -0700349 glLoadMatrixf(textureMatrix);
Jamie Gennis9575f602011-10-07 14:51:16 -0700350 glMatrixMode(GL_MODELVIEW);
Mathias Agopianc492e672011-10-18 14:49:27 -0700351 glDisable(GL_TEXTURE_2D);
Xavier Ducrohet4c4163b2011-10-21 16:18:48 -0700352 glEnable(GL_TEXTURE_EXTERNAL_OES);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700353 } else {
Mathias Agopianc492e672011-10-18 14:49:27 -0700354 glBindTexture(GL_TEXTURE_2D, mFlinger->getProtectedTexName());
Jamie Gennis9575f602011-10-07 14:51:16 -0700355 glMatrixMode(GL_TEXTURE);
356 glLoadIdentity();
357 glMatrixMode(GL_MODELVIEW);
Mathias Agopianc492e672011-10-18 14:49:27 -0700358 glDisable(GL_TEXTURE_EXTERNAL_OES);
359 glEnable(GL_TEXTURE_2D);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700360 }
Mathias Agopiana67932f2011-04-20 14:20:59 -0700361
Mathias Agopian1b031492012-06-20 17:51:20 -0700362 drawWithOpenGL(hw, clip);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700363
Mathias Agopianc492e672011-10-18 14:49:27 -0700364 glDisable(GL_TEXTURE_EXTERNAL_OES);
365 glDisable(GL_TEXTURE_2D);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800366}
367
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800368// As documented in libhardware header, formats in the range
369// 0x100 - 0x1FF are specific to the HAL implementation, and
370// are known to have no alpha channel
371// TODO: move definition for device-specific range into
372// hardware.h, instead of using hard-coded values here.
373#define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF)
374
Mathias Agopiana67932f2011-04-20 14:20:59 -0700375bool Layer::getOpacityForFormat(uint32_t format)
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800376{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700377 if (HARDWARE_IS_DEVICE_FORMAT(format)) {
378 return true;
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800379 }
Mathias Agopiana67932f2011-04-20 14:20:59 -0700380 PixelFormatInfo info;
381 status_t err = getPixelFormatInfo(PixelFormat(format), &info);
382 // in case of error (unknown format), we assume no blending
383 return (err || info.h_alpha <= info.l_alpha);
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800384}
385
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800386
Mathias Agopiana67932f2011-04-20 14:20:59 -0700387bool Layer::isOpaque() const
Mathias Agopiana7f66922010-05-26 22:08:52 -0700388{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700389 // if we don't have a buffer yet, we're translucent regardless of the
390 // layer's opaque flag.
Jamie Gennisdb5230f2011-07-28 14:54:07 -0700391 if (mActiveBuffer == 0) {
Mathias Agopiana67932f2011-04-20 14:20:59 -0700392 return false;
Jamie Gennisdb5230f2011-07-28 14:54:07 -0700393 }
Mathias Agopiana67932f2011-04-20 14:20:59 -0700394
395 // if the layer has the opaque flag, then we're always opaque,
396 // otherwise we use the current buffer's format.
397 return mOpaqueLayer || mCurrentOpacity;
Mathias Agopiana7f66922010-05-26 22:08:52 -0700398}
399
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800400bool Layer::isProtected() const
401{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700402 const sp<GraphicBuffer>& activeBuffer(mActiveBuffer);
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800403 return (activeBuffer != 0) &&
404 (activeBuffer->getUsage() & GRALLOC_USAGE_PROTECTED);
405}
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700406
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800407uint32_t Layer::doTransaction(uint32_t flags)
408{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800409 ATRACE_CALL();
410
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800411 const Layer::State& front(drawingState());
412 const Layer::State& temp(currentState());
413
Mathias Agopian4824d402012-06-04 18:16:30 -0700414 const bool sizeChanged = (temp.requested.w != front.requested.w) ||
415 (temp.requested.h != front.requested.h);
Mathias Agopiana138f892010-05-21 17:24:35 -0700416
417 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700418 // the size changed, we need to ask our client to request a new buffer
Steve Block9d453682011-12-20 16:23:08 +0000419 ALOGD_IF(DEBUG_RESIZE,
Andy McFadden69052052012-09-14 16:10:11 -0700420 "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n"
Mathias Agopian419e1962012-05-23 14:34:07 -0700421 " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
422 " requested={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }}\n"
423 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
424 " requested={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }}\n",
Andy McFadden69052052012-09-14 16:10:11 -0700425 this, (const char*) getName(), mCurrentTransform, mCurrentScalingMode,
Mathias Agopian419e1962012-05-23 14:34:07 -0700426 temp.active.w, temp.active.h,
427 temp.active.crop.left,
428 temp.active.crop.top,
429 temp.active.crop.right,
430 temp.active.crop.bottom,
431 temp.active.crop.getWidth(),
432 temp.active.crop.getHeight(),
433 temp.requested.w, temp.requested.h,
Mathias Agopianb30c4152012-05-16 18:21:32 -0700434 temp.requested.crop.left,
435 temp.requested.crop.top,
436 temp.requested.crop.right,
437 temp.requested.crop.bottom,
438 temp.requested.crop.getWidth(),
439 temp.requested.crop.getHeight(),
Mathias Agopian419e1962012-05-23 14:34:07 -0700440 front.active.w, front.active.h,
441 front.active.crop.left,
442 front.active.crop.top,
443 front.active.crop.right,
444 front.active.crop.bottom,
445 front.active.crop.getWidth(),
446 front.active.crop.getHeight(),
447 front.requested.w, front.requested.h,
Mathias Agopianb30c4152012-05-16 18:21:32 -0700448 front.requested.crop.left,
449 front.requested.crop.top,
450 front.requested.crop.right,
451 front.requested.crop.bottom,
452 front.requested.crop.getWidth(),
Mathias Agopian419e1962012-05-23 14:34:07 -0700453 front.requested.crop.getHeight());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800454
Jamie Gennis2a0d5b62011-09-26 16:54:44 -0700455 // record the new size, form this point on, when the client request
456 // a buffer, it'll get the new size.
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800457 mSurfaceFlingerConsumer->setDefaultBufferSize(
Mathias Agopianb30c4152012-05-16 18:21:32 -0700458 temp.requested.w, temp.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800459 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700460
Mathias Agopian0cd545f2012-06-07 14:18:55 -0700461 if (!isFixedSize()) {
462
463 const bool resizePending = (temp.requested.w != temp.active.w) ||
464 (temp.requested.h != temp.active.h);
465
466 if (resizePending) {
467 // don't let LayerBase::doTransaction update the drawing state
468 // if we have a pending resize, unless we are in fixed-size mode.
469 // the drawing state will be updated only once we receive a buffer
470 // with the correct size.
471 //
472 // in particular, we want to make sure the clip (which is part
473 // of the geometry state) is latched together with the size but is
474 // latched immediately when no resizing is involved.
475
476 flags |= eDontUpdateGeometryState;
477 }
478 }
479
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800480 return LayerBase::doTransaction(flags);
481}
482
Mathias Agopiana138f892010-05-21 17:24:35 -0700483bool Layer::isFixedSize() const {
Mathias Agopian933389f2011-07-18 16:15:08 -0700484 return mCurrentScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700485}
486
487bool Layer::isCropped() const {
488 return !mCurrentCrop.isEmpty();
489}
490
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800491// ----------------------------------------------------------------------------
492// pageflip handling...
493// ----------------------------------------------------------------------------
494
Mathias Agopian4d143ee2012-02-23 20:05:39 -0800495bool Layer::onPreComposition() {
496 mRefreshPending = false;
497 return mQueuedFrames > 0;
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800498}
499
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700500void Layer::onPostComposition() {
501 if (mFrameLatencyNeeded) {
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800502 nsecs_t desiredPresentTime = mSurfaceFlingerConsumer->getTimestamp();
Jamie Gennis82dbc742012-11-08 19:23:28 -0800503 mFrameTracker.setDesiredPresentTime(desiredPresentTime);
504
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800505 sp<Fence> frameReadyFence = mSurfaceFlingerConsumer->getCurrentFence();
Jamie Gennis789a6c32013-02-25 13:37:54 -0800506 if (frameReadyFence->isValid()) {
Jamie Gennis82dbc742012-11-08 19:23:28 -0800507 mFrameTracker.setFrameReadyFence(frameReadyFence);
508 } else {
509 // There was no fence for this frame, so assume that it was ready
510 // to be presented at the desired present time.
511 mFrameTracker.setFrameReadyTime(desiredPresentTime);
512 }
513
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700514 const HWComposer& hwc = mFlinger->getHwComposer();
Jamie Gennis82dbc742012-11-08 19:23:28 -0800515 sp<Fence> presentFence = hwc.getDisplayFence(HWC_DISPLAY_PRIMARY);
Jamie Gennis789a6c32013-02-25 13:37:54 -0800516 if (presentFence->isValid()) {
Jamie Gennis82dbc742012-11-08 19:23:28 -0800517 mFrameTracker.setActualPresentFence(presentFence);
518 } else {
519 // The HWC doesn't support present fences, so use the refresh
520 // timestamp instead.
521 nsecs_t presentTime = hwc.getRefreshTimestamp(HWC_DISPLAY_PRIMARY);
522 mFrameTracker.setActualPresentTime(presentTime);
523 }
524
525 mFrameTracker.advanceFrame();
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700526 mFrameLatencyNeeded = false;
527 }
528}
529
Mathias Agopianda27af92012-09-13 18:17:13 -0700530bool Layer::isVisible() const {
531 return LayerBaseClient::isVisible() && (mActiveBuffer != NULL);
532}
533
Mathias Agopian4fec8732012-06-29 14:12:52 -0700534Region Layer::latchBuffer(bool& recomputeVisibleRegions)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800535{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800536 ATRACE_CALL();
537
Mathias Agopian4fec8732012-06-29 14:12:52 -0700538 Region outDirtyRegion;
Jamie Gennis3d8063b2011-06-26 18:27:47 -0700539 if (mQueuedFrames > 0) {
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800540
541 // if we've already called updateTexImage() without going through
542 // a composition step, we have to skip this layer at this point
543 // because we cannot call updateTeximage() without a corresponding
544 // compositionComplete() call.
545 // we'll trigger an update in onPreComposition().
Mathias Agopian4d143ee2012-02-23 20:05:39 -0800546 if (mRefreshPending) {
Mathias Agopian4fec8732012-06-29 14:12:52 -0700547 return outDirtyRegion;
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800548 }
549
Jamie Gennis351a5132011-09-14 18:23:37 -0700550 // Capture the old state of the layer for comparisons later
Jamie Gennisdb5230f2011-07-28 14:54:07 -0700551 const bool oldOpacity = isOpaque();
Jamie Gennis351a5132011-09-14 18:23:37 -0700552 sp<GraphicBuffer> oldActiveBuffer = mActiveBuffer;
Jamie Gennisdb5230f2011-07-28 14:54:07 -0700553
Jamie Gennis3d8063b2011-06-26 18:27:47 -0700554 // signal another event if we have more frames pending
555 if (android_atomic_dec(&mQueuedFrames) > 1) {
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800556 mFlinger->signalLayerUpdate();
Jamie Gennis3d8063b2011-06-26 18:27:47 -0700557 }
558
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800559 struct Reject : public SurfaceFlingerConsumer::BufferRejecter {
Mathias Agopian2c8207e2012-05-23 17:56:42 -0700560 Layer::State& front;
561 Layer::State& current;
562 bool& recomputeVisibleRegions;
563 Reject(Layer::State& front, Layer::State& current,
564 bool& recomputeVisibleRegions)
565 : front(front), current(current),
566 recomputeVisibleRegions(recomputeVisibleRegions) {
567 }
568
569 virtual bool reject(const sp<GraphicBuffer>& buf,
570 const BufferQueue::BufferItem& item) {
571 if (buf == NULL) {
572 return false;
573 }
574
575 uint32_t bufWidth = buf->getWidth();
576 uint32_t bufHeight = buf->getHeight();
577
578 // check that we received a buffer of the right size
579 // (Take the buffer's orientation into account)
580 if (item.mTransform & Transform::ROT_90) {
581 swap(bufWidth, bufHeight);
582 }
583
584
585 bool isFixedSize = item.mScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE;
586 if (front.active != front.requested) {
587
588 if (isFixedSize ||
589 (bufWidth == front.requested.w &&
590 bufHeight == front.requested.h))
591 {
592 // Here we pretend the transaction happened by updating the
593 // current and drawing states. Drawing state is only accessed
594 // in this thread, no need to have it locked
595 front.active = front.requested;
596
597 // We also need to update the current state so that
598 // we don't end-up overwriting the drawing state with
599 // this stale current state during the next transaction
600 //
601 // NOTE: We don't need to hold the transaction lock here
602 // because State::active is only accessed from this thread.
603 current.active = front.active;
604
605 // recompute visible region
606 recomputeVisibleRegions = true;
607 }
608
609 ALOGD_IF(DEBUG_RESIZE,
Andy McFadden69052052012-09-14 16:10:11 -0700610 "latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n"
Mathias Agopian2c8207e2012-05-23 17:56:42 -0700611 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
612 " requested={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }}\n",
Andy McFadden69052052012-09-14 16:10:11 -0700613 bufWidth, bufHeight, item.mTransform, item.mScalingMode,
Mathias Agopian2c8207e2012-05-23 17:56:42 -0700614 front.active.w, front.active.h,
615 front.active.crop.left,
616 front.active.crop.top,
617 front.active.crop.right,
618 front.active.crop.bottom,
619 front.active.crop.getWidth(),
620 front.active.crop.getHeight(),
621 front.requested.w, front.requested.h,
622 front.requested.crop.left,
623 front.requested.crop.top,
624 front.requested.crop.right,
625 front.requested.crop.bottom,
626 front.requested.crop.getWidth(),
627 front.requested.crop.getHeight());
628 }
629
630 if (!isFixedSize) {
631 if (front.active.w != bufWidth ||
632 front.active.h != bufHeight) {
Mathias Agopian4824d402012-06-04 18:16:30 -0700633 // reject this buffer
Mathias Agopian2c8207e2012-05-23 17:56:42 -0700634 return true;
635 }
636 }
637 return false;
638 }
639 };
640
641
642 Reject r(mDrawingState, currentState(), recomputeVisibleRegions);
643
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800644 if (mSurfaceFlingerConsumer->updateTexImage(&r) != NO_ERROR) {
Mathias Agopiana67932f2011-04-20 14:20:59 -0700645 // something happened!
646 recomputeVisibleRegions = true;
Mathias Agopian4fec8732012-06-29 14:12:52 -0700647 return outDirtyRegion;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700648 }
Mathias Agopian96f08192010-06-02 23:28:45 -0700649
Jamie Gennis351a5132011-09-14 18:23:37 -0700650 // update the active buffer
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800651 mActiveBuffer = mSurfaceFlingerConsumer->getCurrentBuffer();
Mathias Agopiane31564d2012-05-29 20:41:03 -0700652 if (mActiveBuffer == NULL) {
653 // this can only happen if the very first buffer was rejected.
Mathias Agopian4fec8732012-06-29 14:12:52 -0700654 return outDirtyRegion;
Mathias Agopiane31564d2012-05-29 20:41:03 -0700655 }
Mathias Agopianda9584d2010-12-13 18:51:59 -0800656
Mathias Agopian4824d402012-06-04 18:16:30 -0700657 mRefreshPending = true;
Mathias Agopian2c8207e2012-05-23 17:56:42 -0700658 mFrameLatencyNeeded = true;
Mathias Agopiane31564d2012-05-29 20:41:03 -0700659 if (oldActiveBuffer == NULL) {
Mathias Agopian2c8207e2012-05-23 17:56:42 -0700660 // the first time we receive a buffer, we need to trigger a
661 // geometry invalidation.
Andy McFaddenab10c582012-09-26 16:19:12 -0700662 recomputeVisibleRegions = true;
Mathias Agopian2c8207e2012-05-23 17:56:42 -0700663 }
664
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800665 Rect crop(mSurfaceFlingerConsumer->getCurrentCrop());
666 const uint32_t transform(mSurfaceFlingerConsumer->getCurrentTransform());
667 const uint32_t scalingMode(mSurfaceFlingerConsumer->getCurrentScalingMode());
Mathias Agopian702634a2012-05-23 17:50:31 -0700668 if ((crop != mCurrentCrop) ||
669 (transform != mCurrentTransform) ||
670 (scalingMode != mCurrentScalingMode))
671 {
672 mCurrentCrop = crop;
673 mCurrentTransform = transform;
674 mCurrentScalingMode = scalingMode;
Andy McFaddenab10c582012-09-26 16:19:12 -0700675 recomputeVisibleRegions = true;
Mathias Agopian702634a2012-05-23 17:50:31 -0700676 }
677
678 if (oldActiveBuffer != NULL) {
Mathias Agopiane31564d2012-05-29 20:41:03 -0700679 uint32_t bufWidth = mActiveBuffer->getWidth();
680 uint32_t bufHeight = mActiveBuffer->getHeight();
Mathias Agopian702634a2012-05-23 17:50:31 -0700681 if (bufWidth != uint32_t(oldActiveBuffer->width) ||
682 bufHeight != uint32_t(oldActiveBuffer->height)) {
Andy McFaddenab10c582012-09-26 16:19:12 -0700683 recomputeVisibleRegions = true;
Mathias Agopian702634a2012-05-23 17:50:31 -0700684 }
685 }
686
687 mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format);
688 if (oldOpacity != isOpaque()) {
689 recomputeVisibleRegions = true;
690 }
691
Mathias Agopian702634a2012-05-23 17:50:31 -0700692 glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
693 glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Mathias Agopian4fec8732012-06-29 14:12:52 -0700694
695 // FIXME: postedRegion should be dirty & bounds
696 const Layer::State& front(drawingState());
697 Region dirtyRegion(Rect(front.active.w, front.active.h));
698
699 // transform the dirty region to window-manager space
700 outDirtyRegion = (front.transform.transform(dirtyRegion));
Mathias Agopiancaa600c2009-09-16 18:27:24 -0700701 }
Mathias Agopian4fec8732012-06-29 14:12:52 -0700702 return outDirtyRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800703}
704
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700705void Layer::dump(String8& result, char* buffer, size_t SIZE) const
706{
707 LayerBaseClient::dump(result, buffer, SIZE);
708
Mathias Agopiana67932f2011-04-20 14:20:59 -0700709 sp<const GraphicBuffer> buf0(mActiveBuffer);
710 uint32_t w0=0, h0=0, s0=0, f0=0;
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700711 if (buf0 != 0) {
712 w0 = buf0->getWidth();
713 h0 = buf0->getHeight();
714 s0 = buf0->getStride();
Mathias Agopiana67932f2011-04-20 14:20:59 -0700715 f0 = buf0->format;
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700716 }
717 snprintf(buffer, SIZE,
718 " "
Mathias Agopianad795ba2011-08-08 16:02:13 -0700719 "format=%2d, activeBuffer=[%4ux%4u:%4u,%3X],"
Andy McFadden69052052012-09-14 16:10:11 -0700720 " queued-frames=%d, mRefreshPending=%d\n",
Mathias Agopiana67932f2011-04-20 14:20:59 -0700721 mFormat, w0, h0, s0,f0,
Andy McFadden69052052012-09-14 16:10:11 -0700722 mQueuedFrames, mRefreshPending);
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700723
724 result.append(buffer);
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700725
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800726 if (mSurfaceFlingerConsumer != 0) {
727 mSurfaceFlingerConsumer->dump(result, " ", buffer, SIZE);
Mathias Agopian579b3f82010-06-08 19:54:15 -0700728 }
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700729}
730
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800731void Layer::dumpStats(String8& result, char* buffer, size_t SIZE) const
732{
733 LayerBaseClient::dumpStats(result, buffer, SIZE);
Jamie Gennis82dbc742012-11-08 19:23:28 -0800734 mFrameTracker.dump(result);
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800735}
736
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800737void Layer::clearStats()
738{
739 LayerBaseClient::clearStats();
Jamie Gennis82dbc742012-11-08 19:23:28 -0800740 mFrameTracker.clear();
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800741}
742
Mathias Agopiana67932f2011-04-20 14:20:59 -0700743uint32_t Layer::getEffectiveUsage(uint32_t usage) const
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700744{
Mathias Agopiana67932f2011-04-20 14:20:59 -0700745 // TODO: should we do something special if mSecure is set?
746 if (mProtectedByApp) {
747 // need a hardware-protected path to external video sink
748 usage |= GraphicBuffer::USAGE_PROTECTED;
Jamie Gennis54cc83e2010-11-02 11:51:32 -0700749 }
Jamie Gennis3599bf22011-08-10 11:48:07 -0700750 usage |= GraphicBuffer::USAGE_HW_COMPOSER;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700751 return usage;
Mathias Agopianb5b7f262010-05-07 15:58:44 -0700752}
753
Mathias Agopian84300952012-11-21 16:02:13 -0800754void Layer::updateTransformHint(const sp<const DisplayDevice>& hw) const {
Mathias Agopiana4583642011-08-23 18:03:18 -0700755 uint32_t orientation = 0;
756 if (!mFlinger->mDebugDisableTransformHint) {
Mathias Agopian84300952012-11-21 16:02:13 -0800757 // The transform hint is used to improve performance, but we can
758 // only have a single transform hint, it cannot
Mathias Agopian4fec8732012-06-29 14:12:52 -0700759 // apply to all displays.
Mathias Agopian42977342012-08-05 00:40:46 -0700760 const Transform& planeTransform(hw->getTransform());
Mathias Agopian4fec8732012-06-29 14:12:52 -0700761 orientation = planeTransform.getOrientation();
Mathias Agopiana4583642011-08-23 18:03:18 -0700762 if (orientation & Transform::ROT_INVALID) {
763 orientation = 0;
764 }
765 }
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800766 mSurfaceFlingerConsumer->setTransformHint(orientation);
Mathias Agopiana4583642011-08-23 18:03:18 -0700767}
768
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800769// ---------------------------------------------------------------------------
770
771
772}; // namespace android