The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 18 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | #include <stdlib.h> |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 22 | #include <math.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 24 | #include <cutils/compiler.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 25 | #include <cutils/native_handle.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 26 | #include <cutils/properties.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | #include <utils/Errors.h> |
| 29 | #include <utils/Log.h> |
| 30 | #include <utils/StopWatch.h> |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 31 | #include <utils/Trace.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 33 | #include <ui/GraphicBuffer.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include <ui/PixelFormat.h> |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 35 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 36 | #include <gui/Surface.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
| 38 | #include "clz.h" |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 39 | #include "DisplayDevice.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 40 | #include "GLExtensions.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | #include "Layer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | #include "SurfaceFlinger.h" |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 43 | #include "SurfaceTextureLayer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 45 | #include "DisplayHardware/HWComposer.h" |
| 46 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | #define DEBUG_RESIZE 0 |
| 48 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | namespace android { |
| 50 | |
| 51 | // --------------------------------------------------------------------------- |
| 52 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 53 | Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client) |
| 54 | : LayerBaseClient(flinger, client), |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 55 | mTextureName(-1U), |
| 56 | mQueuedFrames(0), |
| 57 | mCurrentTransform(0), |
Mathias Agopian | 933389f | 2011-07-18 16:15:08 -0700 | [diff] [blame] | 58 | mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 59 | mCurrentOpacity(true), |
Mathias Agopian | 4d143ee | 2012-02-23 20:05:39 -0800 | [diff] [blame] | 60 | mRefreshPending(false), |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 61 | mFrameLatencyNeeded(false), |
Mathias Agopian | 5bf3abe | 2011-03-11 17:01:07 -0800 | [diff] [blame] | 62 | mFormat(PIXEL_FORMAT_NONE), |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 63 | mGLExtensions(GLExtensions::getInstance()), |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 64 | mOpaqueLayer(true), |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 65 | mSecure(false), |
Mathias Agopian | 933389f | 2011-07-18 16:15:08 -0700 | [diff] [blame] | 66 | mProtectedByApp(false) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 68 | mCurrentCrop.makeInvalid(); |
| 69 | glGenTextures(1, &mTextureName); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 72 | void Layer::onLayerDisplayed(const sp<const DisplayDevice>& hw, |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 73 | HWComposer::HWCLayerInterface* layer) { |
Mathias Agopian | c397360 | 2012-08-31 17:51:25 -0700 | [diff] [blame] | 74 | LayerBaseClient::onLayerDisplayed(hw, layer); |
Jesse Hall | ef19414 | 2012-06-14 14:45:17 -0700 | [diff] [blame] | 75 | if (layer) { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 76 | mSurfaceFlingerConsumer->setReleaseFence(layer->getAndResetReleaseFenceFd()); |
Jesse Hall | ef19414 | 2012-06-14 14:45:17 -0700 | [diff] [blame] | 77 | } |
Mathias Agopian | d606de6 | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 80 | void Layer::onFirstRef() |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 81 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 82 | LayerBaseClient::onFirstRef(); |
Mathias Agopian | ddc31c3 | 2011-06-12 18:05:53 -0700 | [diff] [blame] | 83 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 84 | // Creates a custom BufferQueue for SurfaceFlingerConsumer to use |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 85 | sp<BufferQueue> bq = new SurfaceTextureLayer(); |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 86 | mSurfaceFlingerConsumer = new SurfaceFlingerConsumer(mTextureName, true, |
Mathias Agopian | a0db308 | 2012-04-23 13:59:36 -0700 | [diff] [blame] | 87 | GL_TEXTURE_EXTERNAL_OES, false, bq); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 88 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 89 | mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0)); |
| 90 | mSurfaceFlingerConsumer->setFrameAvailableListener(this); |
| 91 | mSurfaceFlingerConsumer->setSynchronousMode(true); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 92 | |
Mathias Agopian | 7f42a9c | 2012-04-23 20:00:16 -0700 | [diff] [blame] | 93 | #ifdef TARGET_DISABLE_TRIPLE_BUFFERING |
| 94 | #warning "disabling triple buffering" |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 95 | mSurfaceFlingerConsumer->setDefaultMaxBufferCount(2); |
Mathias Agopian | 7f42a9c | 2012-04-23 20:00:16 -0700 | [diff] [blame] | 96 | #else |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 97 | mSurfaceFlingerConsumer->setDefaultMaxBufferCount(3); |
Mathias Agopian | 303d538 | 2012-02-05 01:49:16 -0800 | [diff] [blame] | 98 | #endif |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 99 | |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 100 | const sp<const DisplayDevice> hw(mFlinger->getDefaultDisplayDevice()); |
| 101 | updateTransformHint(hw); |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 104 | Layer::~Layer() |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 105 | { |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 106 | mFlinger->deleteTextureAsync(mTextureName); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Igor Murashkin | a4a3149 | 2012-10-29 13:36:11 -0700 | [diff] [blame] | 109 | void Layer::onFrameAvailable() { |
Jamie Gennis | 3d8063b | 2011-06-26 18:27:47 -0700 | [diff] [blame] | 110 | android_atomic_inc(&mQueuedFrames); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 111 | mFlinger->signalLayerUpdate(); |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Mathias Agopian | d606de6 | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 114 | // called with SurfaceFlinger::mStateLock as soon as the layer is entered |
| 115 | // in the purgatory list |
| 116 | void Layer::onRemoved() |
| 117 | { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 118 | mSurfaceFlingerConsumer->abandon(); |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 119 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 120 | |
Jamie Gennis | a249f2d | 2011-09-16 17:31:54 -0700 | [diff] [blame] | 121 | void Layer::setName(const String8& name) { |
| 122 | LayerBase::setName(name); |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 123 | mSurfaceFlingerConsumer->setName(name); |
Jamie Gennis | a249f2d | 2011-09-16 17:31:54 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 126 | sp<ISurface> Layer::createSurface() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | { |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 128 | /* |
| 129 | * This class provides an implementation of BnSurface (the "native" or |
| 130 | * "remote" side of the Binder IPC interface ISurface), and mixes in |
| 131 | * LayerCleaner to ensure that mFlinger->onLayerDestroyed() is called for |
| 132 | * this layer when the BSurface is destroyed. |
| 133 | * |
| 134 | * The idea is to provide a handle to the Layer through ISurface that |
| 135 | * is cleaned up automatically when the last reference to the ISurface |
| 136 | * goes away. (The references will be held on the "proxy" side, while |
| 137 | * the Layer exists on the "native" side.) |
| 138 | * |
| 139 | * The Layer has a reference to an instance of SurfaceFlinger's variant |
| 140 | * of GLConsumer, which holds a reference to the BufferQueue. The |
| 141 | * getSurfaceTexture() call returns a Binder interface reference for |
| 142 | * the producer interface of the buffer queue associated with the Layer. |
| 143 | */ |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 144 | class BSurface : public BnSurface, public LayerCleaner { |
| 145 | wp<const Layer> mOwner; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 146 | virtual sp<IGraphicBufferProducer> getSurfaceTexture() const { |
| 147 | sp<IGraphicBufferProducer> res; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 148 | sp<const Layer> that( mOwner.promote() ); |
| 149 | if (that != NULL) { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 150 | res = that->mSurfaceFlingerConsumer->getBufferQueue(); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 151 | } |
| 152 | return res; |
| 153 | } |
| 154 | public: |
| 155 | BSurface(const sp<SurfaceFlinger>& flinger, |
| 156 | const sp<Layer>& layer) |
| 157 | : LayerCleaner(flinger, layer), mOwner(layer) { } |
| 158 | }; |
| 159 | sp<ISurface> sur(new BSurface(mFlinger, this)); |
Mathias Agopian | a1f47b9 | 2011-02-15 19:01:06 -0800 | [diff] [blame] | 160 | return sur; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Jamie Gennis | 582270d | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 163 | wp<IBinder> Layer::getSurfaceTextureBinder() const |
| 164 | { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 165 | return mSurfaceFlingerConsumer->getBufferQueue()->asBinder(); |
Jamie Gennis | 582270d | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 168 | status_t Layer::setBuffers( uint32_t w, uint32_t h, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | PixelFormat format, uint32_t flags) |
| 170 | { |
Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 171 | // this surfaces pixel format |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | PixelFormatInfo info; |
| 173 | status_t err = getPixelFormatInfo(format, &info); |
Mathias Agopian | ff615cc | 2012-02-24 14:58:36 -0800 | [diff] [blame] | 174 | if (err) { |
| 175 | ALOGE("unsupported pixelformat %d", format); |
| 176 | return err; |
| 177 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 179 | uint32_t const maxSurfaceDims = min( |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 180 | mFlinger->getMaxTextureSize(), mFlinger->getMaxViewportDims()); |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 181 | |
| 182 | // never allow a surface larger than what our underlying GL implementation |
| 183 | // can handle. |
| 184 | if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) { |
Mathias Agopian | ff615cc | 2012-02-24 14:58:36 -0800 | [diff] [blame] | 185 | ALOGE("dimensions too large %u x %u", uint32_t(w), uint32_t(h)); |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 186 | return BAD_VALUE; |
| 187 | } |
| 188 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 189 | mFormat = format; |
Mathias Agopian | eff062c | 2010-08-25 14:59:15 -0700 | [diff] [blame] | 190 | |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 191 | mSecure = (flags & ISurfaceComposerClient::eSecure) ? true : false; |
| 192 | mProtectedByApp = (flags & ISurfaceComposerClient::eProtectedByApp) ? true : false; |
| 193 | mOpaqueLayer = (flags & ISurfaceComposerClient::eOpaque); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 194 | mCurrentOpacity = getOpacityForFormat(format); |
| 195 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 196 | mSurfaceFlingerConsumer->setDefaultBufferSize(w, h); |
| 197 | mSurfaceFlingerConsumer->setDefaultBufferFormat(format); |
| 198 | mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0)); |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 199 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | return NO_ERROR; |
| 201 | } |
| 202 | |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 203 | Rect Layer::computeBufferCrop() const { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 204 | // Start with the SurfaceFlingerConsumer's buffer crop... |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 205 | Rect crop; |
| 206 | if (!mCurrentCrop.isEmpty()) { |
| 207 | crop = mCurrentCrop; |
| 208 | } else if (mActiveBuffer != NULL){ |
| 209 | crop = Rect(mActiveBuffer->getWidth(), mActiveBuffer->getHeight()); |
| 210 | } else { |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 211 | crop.makeInvalid(); |
| 212 | return crop; |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | // ... then reduce that in the same proportions as the window crop reduces |
| 216 | // the window size. |
| 217 | const State& s(drawingState()); |
Mathias Agopian | 93ffb86 | 2012-05-16 17:07:49 -0700 | [diff] [blame] | 218 | if (!s.active.crop.isEmpty()) { |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 219 | // Transform the window crop to match the buffer coordinate system, |
| 220 | // which means using the inverse of the current transform set on the |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 221 | // SurfaceFlingerConsumer. |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 222 | uint32_t invTransform = mCurrentTransform; |
Mathias Agopian | 93ffb86 | 2012-05-16 17:07:49 -0700 | [diff] [blame] | 223 | int winWidth = s.active.w; |
| 224 | int winHeight = s.active.h; |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 225 | if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) { |
| 226 | invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | |
| 227 | NATIVE_WINDOW_TRANSFORM_FLIP_H; |
Mathias Agopian | 93ffb86 | 2012-05-16 17:07:49 -0700 | [diff] [blame] | 228 | winWidth = s.active.h; |
| 229 | winHeight = s.active.w; |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 230 | } |
Mathias Agopian | 93ffb86 | 2012-05-16 17:07:49 -0700 | [diff] [blame] | 231 | Rect winCrop = s.active.crop.transform(invTransform, |
| 232 | s.active.w, s.active.h); |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 233 | |
| 234 | float xScale = float(crop.width()) / float(winWidth); |
| 235 | float yScale = float(crop.height()) / float(winHeight); |
Mathias Agopian | 93ffb86 | 2012-05-16 17:07:49 -0700 | [diff] [blame] | 236 | crop.left += int(ceilf(float(winCrop.left) * xScale)); |
| 237 | crop.top += int(ceilf(float(winCrop.top) * yScale)); |
| 238 | crop.right -= int(ceilf(float(winWidth - winCrop.right) * xScale)); |
| 239 | crop.bottom -= int(ceilf(float(winHeight - winCrop.bottom) * yScale)); |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | return crop; |
| 243 | } |
| 244 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 245 | void Layer::setGeometry( |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 246 | const sp<const DisplayDevice>& hw, |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 247 | HWComposer::HWCLayerInterface& layer) |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 248 | { |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 249 | LayerBaseClient::setGeometry(hw, layer); |
Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 250 | |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 251 | // enable this layer |
| 252 | layer.setSkip(false); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 253 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 254 | if (isSecure() && !hw->isSecure()) { |
| 255 | layer.setSkip(true); |
| 256 | } |
| 257 | |
Mathias Agopian | 9f8386e | 2013-01-29 18:56:42 -0800 | [diff] [blame^] | 258 | const State& s(drawingState()); |
| 259 | layer.setPlaneAlpha(s.alpha); |
| 260 | |
Mathias Agopian | 29a367b | 2011-07-12 14:51:45 -0700 | [diff] [blame] | 261 | /* |
| 262 | * Transformations are applied in this order: |
| 263 | * 1) buffer orientation/flip/mirror |
| 264 | * 2) state transformation (window manager) |
| 265 | * 3) layer orientation (screen orientation) |
| 266 | * (NOTE: the matrices are multiplied in reverse order) |
| 267 | */ |
| 268 | |
| 269 | const Transform bufferOrientation(mCurrentTransform); |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 270 | const Transform tr(hw->getTransform() * s.transform * bufferOrientation); |
Mathias Agopian | 29a367b | 2011-07-12 14:51:45 -0700 | [diff] [blame] | 271 | |
| 272 | // this gives us only the "orientation" component of the transform |
| 273 | const uint32_t finalTransform = tr.getOrientation(); |
| 274 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 275 | // we can only handle simple transformation |
Mathias Agopian | 29a367b | 2011-07-12 14:51:45 -0700 | [diff] [blame] | 276 | if (finalTransform & Transform::ROT_INVALID) { |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 277 | layer.setSkip(true); |
Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 278 | } else { |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 279 | layer.setTransform(finalTransform); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 280 | } |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 281 | layer.setCrop(computeBufferCrop()); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 284 | void Layer::setPerFrameData(const sp<const DisplayDevice>& hw, |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 285 | HWComposer::HWCLayerInterface& layer) { |
Mathias Agopian | 71e83e1 | 2012-09-04 20:25:39 -0700 | [diff] [blame] | 286 | LayerBaseClient::setPerFrameData(hw, layer); |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 287 | // NOTE: buffer can be NULL if the client never drew into this |
| 288 | // layer yet, or if we ran out of memory |
Mathias Agopian | 71e83e1 | 2012-09-04 20:25:39 -0700 | [diff] [blame] | 289 | layer.setBuffer(mActiveBuffer); |
Jesse Hall | c5c5a14 | 2012-07-02 16:49:28 -0700 | [diff] [blame] | 290 | } |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 291 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 292 | void Layer::setAcquireFence(const sp<const DisplayDevice>& hw, |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 293 | HWComposer::HWCLayerInterface& layer) { |
Jesse Hall | c5c5a14 | 2012-07-02 16:49:28 -0700 | [diff] [blame] | 294 | int fenceFd = -1; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 295 | |
| 296 | // TODO: there is a possible optimization here: we only need to set the |
| 297 | // acquire fence the first time a new buffer is acquired on EACH display. |
| 298 | |
| 299 | if (layer.getCompositionType() == HWC_OVERLAY) { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 300 | sp<Fence> fence = mSurfaceFlingerConsumer->getCurrentFence(); |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 301 | if (fence.get()) { |
Jesse Hall | c5c5a14 | 2012-07-02 16:49:28 -0700 | [diff] [blame] | 302 | fenceFd = fence->dup(); |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 303 | if (fenceFd == -1) { |
| 304 | ALOGW("failed to dup layer fence, skipping sync: %d", errno); |
| 305 | } |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 306 | } |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 307 | } |
Jesse Hall | c5c5a14 | 2012-07-02 16:49:28 -0700 | [diff] [blame] | 308 | layer.setAcquireFenceFd(fenceFd); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 311 | void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 313 | ATRACE_CALL(); |
| 314 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 315 | if (CC_UNLIKELY(mActiveBuffer == 0)) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | // the texture has not been created yet, this Layer has |
Mathias Agopian | 179169e | 2010-05-06 20:21:45 -0700 | [diff] [blame] | 317 | // in fact never been drawn into. This happens frequently with |
| 318 | // SurfaceView because the WindowManager can't know when the client |
| 319 | // has drawn the first time. |
| 320 | |
| 321 | // If there is nothing under us, we paint the screen in black, otherwise |
| 322 | // we just skip this update. |
| 323 | |
| 324 | // figure out if there is something below us |
| 325 | Region under; |
Mathias Agopian | f7ae69d | 2011-08-23 12:34:29 -0700 | [diff] [blame] | 326 | const SurfaceFlinger::LayerVector& drawingLayers( |
| 327 | mFlinger->mDrawingState.layersSortedByZ); |
Mathias Agopian | 179169e | 2010-05-06 20:21:45 -0700 | [diff] [blame] | 328 | const size_t count = drawingLayers.size(); |
| 329 | for (size_t i=0 ; i<count ; ++i) { |
| 330 | const sp<LayerBase>& layer(drawingLayers[i]); |
| 331 | if (layer.get() == static_cast<LayerBase const*>(this)) |
| 332 | break; |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 333 | under.orSelf( hw->getTransform().transform(layer->visibleRegion) ); |
Mathias Agopian | 179169e | 2010-05-06 20:21:45 -0700 | [diff] [blame] | 334 | } |
| 335 | // if not everything below us is covered, we plug the holes! |
| 336 | Region holes(clip.subtract(under)); |
| 337 | if (!holes.isEmpty()) { |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 338 | clearWithOpenGL(hw, holes, 0, 0, 0, 1); |
Mathias Agopian | 179169e | 2010-05-06 20:21:45 -0700 | [diff] [blame] | 339 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | return; |
| 341 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 342 | |
Andy McFadden | 97eba89 | 2012-12-11 15:21:45 -0800 | [diff] [blame] | 343 | // Bind the current buffer to the GL texture, and wait for it to be |
| 344 | // ready for us to draw into. |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 345 | status_t err = mSurfaceFlingerConsumer->bindTextureImage(); |
| 346 | if (err != NO_ERROR) { |
Andy McFadden | 97eba89 | 2012-12-11 15:21:45 -0800 | [diff] [blame] | 347 | ALOGW("onDraw: bindTextureImage failed (err=%d)", err); |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 348 | // Go ahead and draw the buffer anyway; no matter what we do the screen |
| 349 | // is probably going to have something visibly wrong. |
| 350 | } |
| 351 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 352 | bool blackOutLayer = isProtected() || (isSecure() && !hw->isSecure()); |
| 353 | |
| 354 | if (!blackOutLayer) { |
Jamie Gennis | cbb1a95 | 2012-05-08 17:05:52 -0700 | [diff] [blame] | 355 | // TODO: we could be more subtle with isFixedSize() |
Mathias Agopian | eba8c68 | 2012-09-19 23:14:45 -0700 | [diff] [blame] | 356 | const bool useFiltering = getFiltering() || needsFiltering(hw) || isFixedSize(); |
Jamie Gennis | cbb1a95 | 2012-05-08 17:05:52 -0700 | [diff] [blame] | 357 | |
| 358 | // Query the texture matrix given our current filtering mode. |
| 359 | float textureMatrix[16]; |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 360 | mSurfaceFlingerConsumer->setFilteringEnabled(useFiltering); |
| 361 | mSurfaceFlingerConsumer->getTransformMatrix(textureMatrix); |
Jamie Gennis | cbb1a95 | 2012-05-08 17:05:52 -0700 | [diff] [blame] | 362 | |
| 363 | // Set things up for texturing. |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 364 | glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureName); |
| 365 | GLenum filter = GL_NEAREST; |
Jamie Gennis | cbb1a95 | 2012-05-08 17:05:52 -0700 | [diff] [blame] | 366 | if (useFiltering) { |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 367 | filter = GL_LINEAR; |
Jamie Gennis | 9575f60 | 2011-10-07 14:51:16 -0700 | [diff] [blame] | 368 | } |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 369 | glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, filter); |
| 370 | glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, filter); |
Jamie Gennis | 9575f60 | 2011-10-07 14:51:16 -0700 | [diff] [blame] | 371 | glMatrixMode(GL_TEXTURE); |
Jamie Gennis | cbb1a95 | 2012-05-08 17:05:52 -0700 | [diff] [blame] | 372 | glLoadMatrixf(textureMatrix); |
Jamie Gennis | 9575f60 | 2011-10-07 14:51:16 -0700 | [diff] [blame] | 373 | glMatrixMode(GL_MODELVIEW); |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 374 | glDisable(GL_TEXTURE_2D); |
Xavier Ducrohet | 4c4163b | 2011-10-21 16:18:48 -0700 | [diff] [blame] | 375 | glEnable(GL_TEXTURE_EXTERNAL_OES); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 376 | } else { |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 377 | glBindTexture(GL_TEXTURE_2D, mFlinger->getProtectedTexName()); |
Jamie Gennis | 9575f60 | 2011-10-07 14:51:16 -0700 | [diff] [blame] | 378 | glMatrixMode(GL_TEXTURE); |
| 379 | glLoadIdentity(); |
| 380 | glMatrixMode(GL_MODELVIEW); |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 381 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
| 382 | glEnable(GL_TEXTURE_2D); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 383 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 384 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 385 | drawWithOpenGL(hw, clip); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 386 | |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 387 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
| 388 | glDisable(GL_TEXTURE_2D); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 391 | // As documented in libhardware header, formats in the range |
| 392 | // 0x100 - 0x1FF are specific to the HAL implementation, and |
| 393 | // are known to have no alpha channel |
| 394 | // TODO: move definition for device-specific range into |
| 395 | // hardware.h, instead of using hard-coded values here. |
| 396 | #define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF) |
| 397 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 398 | bool Layer::getOpacityForFormat(uint32_t format) |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 399 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 400 | if (HARDWARE_IS_DEVICE_FORMAT(format)) { |
| 401 | return true; |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 402 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 403 | PixelFormatInfo info; |
| 404 | status_t err = getPixelFormatInfo(PixelFormat(format), &info); |
| 405 | // in case of error (unknown format), we assume no blending |
| 406 | return (err || info.h_alpha <= info.l_alpha); |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 407 | } |
| 408 | |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 409 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 410 | bool Layer::isOpaque() const |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 411 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 412 | // if we don't have a buffer yet, we're translucent regardless of the |
| 413 | // layer's opaque flag. |
Jamie Gennis | db5230f | 2011-07-28 14:54:07 -0700 | [diff] [blame] | 414 | if (mActiveBuffer == 0) { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 415 | return false; |
Jamie Gennis | db5230f | 2011-07-28 14:54:07 -0700 | [diff] [blame] | 416 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 417 | |
| 418 | // if the layer has the opaque flag, then we're always opaque, |
| 419 | // otherwise we use the current buffer's format. |
| 420 | return mOpaqueLayer || mCurrentOpacity; |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Jamie Gennis | 7a4d0df | 2011-03-09 17:05:02 -0800 | [diff] [blame] | 423 | bool Layer::isProtected() const |
| 424 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 425 | const sp<GraphicBuffer>& activeBuffer(mActiveBuffer); |
Jamie Gennis | 7a4d0df | 2011-03-09 17:05:02 -0800 | [diff] [blame] | 426 | return (activeBuffer != 0) && |
| 427 | (activeBuffer->getUsage() & GRALLOC_USAGE_PROTECTED); |
| 428 | } |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 429 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | uint32_t Layer::doTransaction(uint32_t flags) |
| 431 | { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 432 | ATRACE_CALL(); |
| 433 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | const Layer::State& front(drawingState()); |
| 435 | const Layer::State& temp(currentState()); |
| 436 | |
Mathias Agopian | 4824d40 | 2012-06-04 18:16:30 -0700 | [diff] [blame] | 437 | const bool sizeChanged = (temp.requested.w != front.requested.w) || |
| 438 | (temp.requested.h != front.requested.h); |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 439 | |
| 440 | if (sizeChanged) { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 441 | // the size changed, we need to ask our client to request a new buffer |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 442 | ALOGD_IF(DEBUG_RESIZE, |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 443 | "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n" |
Mathias Agopian | 419e196 | 2012-05-23 14:34:07 -0700 | [diff] [blame] | 444 | " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n" |
| 445 | " requested={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }}\n" |
| 446 | " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n" |
| 447 | " requested={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }}\n", |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 448 | this, (const char*) getName(), mCurrentTransform, mCurrentScalingMode, |
Mathias Agopian | 419e196 | 2012-05-23 14:34:07 -0700 | [diff] [blame] | 449 | temp.active.w, temp.active.h, |
| 450 | temp.active.crop.left, |
| 451 | temp.active.crop.top, |
| 452 | temp.active.crop.right, |
| 453 | temp.active.crop.bottom, |
| 454 | temp.active.crop.getWidth(), |
| 455 | temp.active.crop.getHeight(), |
| 456 | temp.requested.w, temp.requested.h, |
Mathias Agopian | b30c415 | 2012-05-16 18:21:32 -0700 | [diff] [blame] | 457 | temp.requested.crop.left, |
| 458 | temp.requested.crop.top, |
| 459 | temp.requested.crop.right, |
| 460 | temp.requested.crop.bottom, |
| 461 | temp.requested.crop.getWidth(), |
| 462 | temp.requested.crop.getHeight(), |
Mathias Agopian | 419e196 | 2012-05-23 14:34:07 -0700 | [diff] [blame] | 463 | front.active.w, front.active.h, |
| 464 | front.active.crop.left, |
| 465 | front.active.crop.top, |
| 466 | front.active.crop.right, |
| 467 | front.active.crop.bottom, |
| 468 | front.active.crop.getWidth(), |
| 469 | front.active.crop.getHeight(), |
| 470 | front.requested.w, front.requested.h, |
Mathias Agopian | b30c415 | 2012-05-16 18:21:32 -0700 | [diff] [blame] | 471 | front.requested.crop.left, |
| 472 | front.requested.crop.top, |
| 473 | front.requested.crop.right, |
| 474 | front.requested.crop.bottom, |
| 475 | front.requested.crop.getWidth(), |
Mathias Agopian | 419e196 | 2012-05-23 14:34:07 -0700 | [diff] [blame] | 476 | front.requested.crop.getHeight()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | |
Jamie Gennis | 2a0d5b6 | 2011-09-26 16:54:44 -0700 | [diff] [blame] | 478 | // record the new size, form this point on, when the client request |
| 479 | // a buffer, it'll get the new size. |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 480 | mSurfaceFlingerConsumer->setDefaultBufferSize( |
Mathias Agopian | b30c415 | 2012-05-16 18:21:32 -0700 | [diff] [blame] | 481 | temp.requested.w, temp.requested.h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 483 | |
Mathias Agopian | 0cd545f | 2012-06-07 14:18:55 -0700 | [diff] [blame] | 484 | if (!isFixedSize()) { |
| 485 | |
| 486 | const bool resizePending = (temp.requested.w != temp.active.w) || |
| 487 | (temp.requested.h != temp.active.h); |
| 488 | |
| 489 | if (resizePending) { |
| 490 | // don't let LayerBase::doTransaction update the drawing state |
| 491 | // if we have a pending resize, unless we are in fixed-size mode. |
| 492 | // the drawing state will be updated only once we receive a buffer |
| 493 | // with the correct size. |
| 494 | // |
| 495 | // in particular, we want to make sure the clip (which is part |
| 496 | // of the geometry state) is latched together with the size but is |
| 497 | // latched immediately when no resizing is involved. |
| 498 | |
| 499 | flags |= eDontUpdateGeometryState; |
| 500 | } |
| 501 | } |
| 502 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | return LayerBase::doTransaction(flags); |
| 504 | } |
| 505 | |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 506 | bool Layer::isFixedSize() const { |
Mathias Agopian | 933389f | 2011-07-18 16:15:08 -0700 | [diff] [blame] | 507 | return mCurrentScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | bool Layer::isCropped() const { |
| 511 | return !mCurrentCrop.isEmpty(); |
| 512 | } |
| 513 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | // ---------------------------------------------------------------------------- |
| 515 | // pageflip handling... |
| 516 | // ---------------------------------------------------------------------------- |
| 517 | |
Mathias Agopian | 4d143ee | 2012-02-23 20:05:39 -0800 | [diff] [blame] | 518 | bool Layer::onPreComposition() { |
| 519 | mRefreshPending = false; |
| 520 | return mQueuedFrames > 0; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 521 | } |
| 522 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 523 | void Layer::onPostComposition() { |
| 524 | if (mFrameLatencyNeeded) { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 525 | nsecs_t desiredPresentTime = mSurfaceFlingerConsumer->getTimestamp(); |
Jamie Gennis | 82dbc74 | 2012-11-08 19:23:28 -0800 | [diff] [blame] | 526 | mFrameTracker.setDesiredPresentTime(desiredPresentTime); |
| 527 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 528 | sp<Fence> frameReadyFence = mSurfaceFlingerConsumer->getCurrentFence(); |
Jamie Gennis | 82dbc74 | 2012-11-08 19:23:28 -0800 | [diff] [blame] | 529 | if (frameReadyFence != NULL) { |
| 530 | mFrameTracker.setFrameReadyFence(frameReadyFence); |
| 531 | } else { |
| 532 | // There was no fence for this frame, so assume that it was ready |
| 533 | // to be presented at the desired present time. |
| 534 | mFrameTracker.setFrameReadyTime(desiredPresentTime); |
| 535 | } |
| 536 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 537 | const HWComposer& hwc = mFlinger->getHwComposer(); |
Jamie Gennis | 82dbc74 | 2012-11-08 19:23:28 -0800 | [diff] [blame] | 538 | sp<Fence> presentFence = hwc.getDisplayFence(HWC_DISPLAY_PRIMARY); |
Jamie Gennis | 46b6bce | 2012-12-07 15:42:15 -0800 | [diff] [blame] | 539 | // XXX: Temporarily don't use the present fence from HWC to work |
| 540 | // around a driver bug. |
| 541 | presentFence.clear(); |
Jamie Gennis | 82dbc74 | 2012-11-08 19:23:28 -0800 | [diff] [blame] | 542 | if (presentFence != NULL) { |
| 543 | mFrameTracker.setActualPresentFence(presentFence); |
| 544 | } else { |
| 545 | // The HWC doesn't support present fences, so use the refresh |
| 546 | // timestamp instead. |
| 547 | nsecs_t presentTime = hwc.getRefreshTimestamp(HWC_DISPLAY_PRIMARY); |
| 548 | mFrameTracker.setActualPresentTime(presentTime); |
| 549 | } |
| 550 | |
| 551 | mFrameTracker.advanceFrame(); |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 552 | mFrameLatencyNeeded = false; |
| 553 | } |
| 554 | } |
| 555 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 556 | bool Layer::isVisible() const { |
| 557 | return LayerBaseClient::isVisible() && (mActiveBuffer != NULL); |
| 558 | } |
| 559 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 560 | Region Layer::latchBuffer(bool& recomputeVisibleRegions) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 562 | ATRACE_CALL(); |
| 563 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 564 | Region outDirtyRegion; |
Jamie Gennis | 3d8063b | 2011-06-26 18:27:47 -0700 | [diff] [blame] | 565 | if (mQueuedFrames > 0) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 566 | |
| 567 | // if we've already called updateTexImage() without going through |
| 568 | // a composition step, we have to skip this layer at this point |
| 569 | // because we cannot call updateTeximage() without a corresponding |
| 570 | // compositionComplete() call. |
| 571 | // we'll trigger an update in onPreComposition(). |
Mathias Agopian | 4d143ee | 2012-02-23 20:05:39 -0800 | [diff] [blame] | 572 | if (mRefreshPending) { |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 573 | return outDirtyRegion; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Jamie Gennis | 351a513 | 2011-09-14 18:23:37 -0700 | [diff] [blame] | 576 | // Capture the old state of the layer for comparisons later |
Jamie Gennis | db5230f | 2011-07-28 14:54:07 -0700 | [diff] [blame] | 577 | const bool oldOpacity = isOpaque(); |
Jamie Gennis | 351a513 | 2011-09-14 18:23:37 -0700 | [diff] [blame] | 578 | sp<GraphicBuffer> oldActiveBuffer = mActiveBuffer; |
Jamie Gennis | db5230f | 2011-07-28 14:54:07 -0700 | [diff] [blame] | 579 | |
Jamie Gennis | 3d8063b | 2011-06-26 18:27:47 -0700 | [diff] [blame] | 580 | // signal another event if we have more frames pending |
| 581 | if (android_atomic_dec(&mQueuedFrames) > 1) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 582 | mFlinger->signalLayerUpdate(); |
Jamie Gennis | 3d8063b | 2011-06-26 18:27:47 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 585 | struct Reject : public SurfaceFlingerConsumer::BufferRejecter { |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 586 | Layer::State& front; |
| 587 | Layer::State& current; |
| 588 | bool& recomputeVisibleRegions; |
| 589 | Reject(Layer::State& front, Layer::State& current, |
| 590 | bool& recomputeVisibleRegions) |
| 591 | : front(front), current(current), |
| 592 | recomputeVisibleRegions(recomputeVisibleRegions) { |
| 593 | } |
| 594 | |
| 595 | virtual bool reject(const sp<GraphicBuffer>& buf, |
| 596 | const BufferQueue::BufferItem& item) { |
| 597 | if (buf == NULL) { |
| 598 | return false; |
| 599 | } |
| 600 | |
| 601 | uint32_t bufWidth = buf->getWidth(); |
| 602 | uint32_t bufHeight = buf->getHeight(); |
| 603 | |
| 604 | // check that we received a buffer of the right size |
| 605 | // (Take the buffer's orientation into account) |
| 606 | if (item.mTransform & Transform::ROT_90) { |
| 607 | swap(bufWidth, bufHeight); |
| 608 | } |
| 609 | |
| 610 | |
| 611 | bool isFixedSize = item.mScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE; |
| 612 | if (front.active != front.requested) { |
| 613 | |
| 614 | if (isFixedSize || |
| 615 | (bufWidth == front.requested.w && |
| 616 | bufHeight == front.requested.h)) |
| 617 | { |
| 618 | // Here we pretend the transaction happened by updating the |
| 619 | // current and drawing states. Drawing state is only accessed |
| 620 | // in this thread, no need to have it locked |
| 621 | front.active = front.requested; |
| 622 | |
| 623 | // We also need to update the current state so that |
| 624 | // we don't end-up overwriting the drawing state with |
| 625 | // this stale current state during the next transaction |
| 626 | // |
| 627 | // NOTE: We don't need to hold the transaction lock here |
| 628 | // because State::active is only accessed from this thread. |
| 629 | current.active = front.active; |
| 630 | |
| 631 | // recompute visible region |
| 632 | recomputeVisibleRegions = true; |
| 633 | } |
| 634 | |
| 635 | ALOGD_IF(DEBUG_RESIZE, |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 636 | "latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n" |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 637 | " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n" |
| 638 | " requested={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }}\n", |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 639 | bufWidth, bufHeight, item.mTransform, item.mScalingMode, |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 640 | front.active.w, front.active.h, |
| 641 | front.active.crop.left, |
| 642 | front.active.crop.top, |
| 643 | front.active.crop.right, |
| 644 | front.active.crop.bottom, |
| 645 | front.active.crop.getWidth(), |
| 646 | front.active.crop.getHeight(), |
| 647 | front.requested.w, front.requested.h, |
| 648 | front.requested.crop.left, |
| 649 | front.requested.crop.top, |
| 650 | front.requested.crop.right, |
| 651 | front.requested.crop.bottom, |
| 652 | front.requested.crop.getWidth(), |
| 653 | front.requested.crop.getHeight()); |
| 654 | } |
| 655 | |
| 656 | if (!isFixedSize) { |
| 657 | if (front.active.w != bufWidth || |
| 658 | front.active.h != bufHeight) { |
Mathias Agopian | 4824d40 | 2012-06-04 18:16:30 -0700 | [diff] [blame] | 659 | // reject this buffer |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 660 | return true; |
| 661 | } |
| 662 | } |
| 663 | return false; |
| 664 | } |
| 665 | }; |
| 666 | |
| 667 | |
| 668 | Reject r(mDrawingState, currentState(), recomputeVisibleRegions); |
| 669 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 670 | if (mSurfaceFlingerConsumer->updateTexImage(&r) != NO_ERROR) { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 671 | // something happened! |
| 672 | recomputeVisibleRegions = true; |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 673 | return outDirtyRegion; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 674 | } |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 675 | |
Jamie Gennis | 351a513 | 2011-09-14 18:23:37 -0700 | [diff] [blame] | 676 | // update the active buffer |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 677 | mActiveBuffer = mSurfaceFlingerConsumer->getCurrentBuffer(); |
Mathias Agopian | e31564d | 2012-05-29 20:41:03 -0700 | [diff] [blame] | 678 | if (mActiveBuffer == NULL) { |
| 679 | // this can only happen if the very first buffer was rejected. |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 680 | return outDirtyRegion; |
Mathias Agopian | e31564d | 2012-05-29 20:41:03 -0700 | [diff] [blame] | 681 | } |
Mathias Agopian | da9584d | 2010-12-13 18:51:59 -0800 | [diff] [blame] | 682 | |
Mathias Agopian | 4824d40 | 2012-06-04 18:16:30 -0700 | [diff] [blame] | 683 | mRefreshPending = true; |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 684 | mFrameLatencyNeeded = true; |
Mathias Agopian | e31564d | 2012-05-29 20:41:03 -0700 | [diff] [blame] | 685 | if (oldActiveBuffer == NULL) { |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 686 | // the first time we receive a buffer, we need to trigger a |
| 687 | // geometry invalidation. |
Andy McFadden | ab10c58 | 2012-09-26 16:19:12 -0700 | [diff] [blame] | 688 | recomputeVisibleRegions = true; |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 691 | Rect crop(mSurfaceFlingerConsumer->getCurrentCrop()); |
| 692 | const uint32_t transform(mSurfaceFlingerConsumer->getCurrentTransform()); |
| 693 | const uint32_t scalingMode(mSurfaceFlingerConsumer->getCurrentScalingMode()); |
Mathias Agopian | 702634a | 2012-05-23 17:50:31 -0700 | [diff] [blame] | 694 | if ((crop != mCurrentCrop) || |
| 695 | (transform != mCurrentTransform) || |
| 696 | (scalingMode != mCurrentScalingMode)) |
| 697 | { |
| 698 | mCurrentCrop = crop; |
| 699 | mCurrentTransform = transform; |
| 700 | mCurrentScalingMode = scalingMode; |
Andy McFadden | ab10c58 | 2012-09-26 16:19:12 -0700 | [diff] [blame] | 701 | recomputeVisibleRegions = true; |
Mathias Agopian | 702634a | 2012-05-23 17:50:31 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | if (oldActiveBuffer != NULL) { |
Mathias Agopian | e31564d | 2012-05-29 20:41:03 -0700 | [diff] [blame] | 705 | uint32_t bufWidth = mActiveBuffer->getWidth(); |
| 706 | uint32_t bufHeight = mActiveBuffer->getHeight(); |
Mathias Agopian | 702634a | 2012-05-23 17:50:31 -0700 | [diff] [blame] | 707 | if (bufWidth != uint32_t(oldActiveBuffer->width) || |
| 708 | bufHeight != uint32_t(oldActiveBuffer->height)) { |
Andy McFadden | ab10c58 | 2012-09-26 16:19:12 -0700 | [diff] [blame] | 709 | recomputeVisibleRegions = true; |
Mathias Agopian | 702634a | 2012-05-23 17:50:31 -0700 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
| 713 | mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format); |
| 714 | if (oldOpacity != isOpaque()) { |
| 715 | recomputeVisibleRegions = true; |
| 716 | } |
| 717 | |
Mathias Agopian | 702634a | 2012-05-23 17:50:31 -0700 | [diff] [blame] | 718 | glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 719 | glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 720 | |
| 721 | // FIXME: postedRegion should be dirty & bounds |
| 722 | const Layer::State& front(drawingState()); |
| 723 | Region dirtyRegion(Rect(front.active.w, front.active.h)); |
| 724 | |
| 725 | // transform the dirty region to window-manager space |
| 726 | outDirtyRegion = (front.transform.transform(dirtyRegion)); |
Mathias Agopian | caa600c | 2009-09-16 18:27:24 -0700 | [diff] [blame] | 727 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 728 | return outDirtyRegion; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | } |
| 730 | |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 731 | void Layer::dump(String8& result, char* buffer, size_t SIZE) const |
| 732 | { |
| 733 | LayerBaseClient::dump(result, buffer, SIZE); |
| 734 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 735 | sp<const GraphicBuffer> buf0(mActiveBuffer); |
| 736 | uint32_t w0=0, h0=0, s0=0, f0=0; |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 737 | if (buf0 != 0) { |
| 738 | w0 = buf0->getWidth(); |
| 739 | h0 = buf0->getHeight(); |
| 740 | s0 = buf0->getStride(); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 741 | f0 = buf0->format; |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 742 | } |
| 743 | snprintf(buffer, SIZE, |
| 744 | " " |
Mathias Agopian | ad795ba | 2011-08-08 16:02:13 -0700 | [diff] [blame] | 745 | "format=%2d, activeBuffer=[%4ux%4u:%4u,%3X]," |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 746 | " queued-frames=%d, mRefreshPending=%d\n", |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 747 | mFormat, w0, h0, s0,f0, |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 748 | mQueuedFrames, mRefreshPending); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 749 | |
| 750 | result.append(buffer); |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 751 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 752 | if (mSurfaceFlingerConsumer != 0) { |
| 753 | mSurfaceFlingerConsumer->dump(result, " ", buffer, SIZE); |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 754 | } |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 755 | } |
| 756 | |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 757 | void Layer::dumpStats(String8& result, char* buffer, size_t SIZE) const |
| 758 | { |
| 759 | LayerBaseClient::dumpStats(result, buffer, SIZE); |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 760 | const nsecs_t period = |
| 761 | mFlinger->getHwComposer().getRefreshPeriod(HWC_DISPLAY_PRIMARY); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 762 | result.appendFormat("%lld\n", period); |
Jamie Gennis | 82dbc74 | 2012-11-08 19:23:28 -0800 | [diff] [blame] | 763 | mFrameTracker.dump(result); |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 764 | } |
| 765 | |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 766 | void Layer::clearStats() |
| 767 | { |
| 768 | LayerBaseClient::clearStats(); |
Jamie Gennis | 82dbc74 | 2012-11-08 19:23:28 -0800 | [diff] [blame] | 769 | mFrameTracker.clear(); |
Mathias Agopian | 25e66fc | 2012-01-28 22:31:55 -0800 | [diff] [blame] | 770 | } |
| 771 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 772 | uint32_t Layer::getEffectiveUsage(uint32_t usage) const |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 773 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 774 | // TODO: should we do something special if mSecure is set? |
| 775 | if (mProtectedByApp) { |
| 776 | // need a hardware-protected path to external video sink |
| 777 | usage |= GraphicBuffer::USAGE_PROTECTED; |
Jamie Gennis | 54cc83e | 2010-11-02 11:51:32 -0700 | [diff] [blame] | 778 | } |
Jamie Gennis | 3599bf2 | 2011-08-10 11:48:07 -0700 | [diff] [blame] | 779 | usage |= GraphicBuffer::USAGE_HW_COMPOSER; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 780 | return usage; |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 783 | void Layer::updateTransformHint(const sp<const DisplayDevice>& hw) const { |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 784 | uint32_t orientation = 0; |
| 785 | if (!mFlinger->mDebugDisableTransformHint) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 786 | // The transform hint is used to improve performance, but we can |
| 787 | // only have a single transform hint, it cannot |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 788 | // apply to all displays. |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 789 | const Transform& planeTransform(hw->getTransform()); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 790 | orientation = planeTransform.getOrientation(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 791 | if (orientation & Transform::ROT_INVALID) { |
| 792 | orientation = 0; |
| 793 | } |
| 794 | } |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 795 | mSurfaceFlingerConsumer->setTransformHint(orientation); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 796 | } |
| 797 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | // --------------------------------------------------------------------------- |
| 799 | |
| 800 | |
| 801 | }; // namespace android |