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 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 17 | //#define LOG_NDEBUG 0 |
| 18 | #undef LOG_TAG |
| 19 | #define LOG_TAG "Layer" |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 20 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 21 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <stdlib.h> |
| 23 | #include <stdint.h> |
| 24 | #include <sys/types.h> |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 25 | #include <math.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 27 | #include <cutils/compiler.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 28 | #include <cutils/native_handle.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 29 | #include <cutils/properties.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
| 31 | #include <utils/Errors.h> |
| 32 | #include <utils/Log.h> |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 33 | #include <utils/NativeHandle.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include <utils/StopWatch.h> |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 35 | #include <utils/Trace.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 37 | #include <ui/GraphicBuffer.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | #include <ui/PixelFormat.h> |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 39 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 40 | #include <gui/BufferItem.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 41 | #include <gui/Surface.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
| 43 | #include "clz.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 44 | #include "Colorizer.h" |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 45 | #include "DisplayDevice.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | #include "Layer.h" |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 47 | #include "MonitoredProducer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | #include "SurfaceFlinger.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 50 | #include "DisplayHardware/HWComposer.h" |
| 51 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 52 | #include "RenderEngine/RenderEngine.h" |
| 53 | |
Dan Stoza | c5da271 | 2016-07-20 15:38:12 -0700 | [diff] [blame] | 54 | #include <mutex> |
| 55 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | #define DEBUG_RESIZE 0 |
| 57 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | namespace android { |
| 59 | |
| 60 | // --------------------------------------------------------------------------- |
| 61 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 62 | int32_t Layer::sSequence = 1; |
| 63 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 64 | Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, |
| 65 | const String8& name, uint32_t w, uint32_t h, uint32_t flags) |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 66 | : contentDirty(false), |
| 67 | sequence(uint32_t(android_atomic_inc(&sSequence))), |
| 68 | mFlinger(flinger), |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 69 | mTextureName(-1U), |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 70 | mPremultipliedAlpha(true), |
| 71 | mName("unnamed"), |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 72 | mFormat(PIXEL_FORMAT_NONE), |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 73 | mTransactionFlags(0), |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 74 | mPendingStateMutex(), |
| 75 | mPendingStates(), |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 76 | mQueuedFrames(0), |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 77 | mSidebandStreamChanged(false), |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 78 | mCurrentTransform(0), |
Mathias Agopian | 933389f | 2011-07-18 16:15:08 -0700 | [diff] [blame] | 79 | mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 80 | mOverrideScalingMode(-1), |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 81 | mCurrentOpacity(true), |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 82 | mCurrentFrameNumber(0), |
Mathias Agopian | 4d143ee | 2012-02-23 20:05:39 -0800 | [diff] [blame] | 83 | mRefreshPending(false), |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 84 | mFrameLatencyNeeded(false), |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 85 | mFiltering(false), |
| 86 | mNeedsFiltering(false), |
Mathias Agopian | 5cdc899 | 2013-08-13 20:51:23 -0700 | [diff] [blame] | 87 | mMesh(Mesh::TRIANGLE_FAN, 4, 2, 2), |
Pablo Ceballos | 40845df | 2016-01-25 17:41:15 -0800 | [diff] [blame] | 88 | #ifndef USE_HWC2 |
| 89 | mIsGlesComposition(false), |
| 90 | #endif |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 91 | mProtectedByApp(false), |
| 92 | mHasSurface(false), |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 93 | mClientRef(client), |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 94 | mPotentialCursor(false), |
| 95 | mQueueItemLock(), |
| 96 | mQueueItemCondition(), |
| 97 | mQueueItems(), |
Dan Stoza | 65476f3 | 2015-05-14 09:27:25 -0700 | [diff] [blame] | 98 | mLastFrameNumberReceived(0), |
Pablo Ceballos | 04839ab | 2015-11-13 13:39:23 -0800 | [diff] [blame] | 99 | mUpdateTexImageFailed(false), |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 100 | mAutoRefresh(false), |
| 101 | mFreezePositionUpdates(false) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 103 | #ifdef USE_HWC2 |
| 104 | ALOGV("Creating Layer %s", name.string()); |
| 105 | #endif |
| 106 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 107 | mCurrentCrop.makeInvalid(); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 108 | mFlinger->getRenderEngine().genTextures(1, &mTextureName); |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 109 | mTexture.init(Texture::TEXTURE_EXTERNAL, mTextureName); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 110 | |
| 111 | uint32_t layerFlags = 0; |
| 112 | if (flags & ISurfaceComposerClient::eHidden) |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 113 | layerFlags |= layer_state_t::eLayerHidden; |
| 114 | if (flags & ISurfaceComposerClient::eOpaque) |
| 115 | layerFlags |= layer_state_t::eLayerOpaque; |
Dan Stoza | 2311608 | 2015-06-18 14:58:39 -0700 | [diff] [blame] | 116 | if (flags & ISurfaceComposerClient::eSecure) |
| 117 | layerFlags |= layer_state_t::eLayerSecure; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 118 | |
| 119 | if (flags & ISurfaceComposerClient::eNonPremultiplied) |
| 120 | mPremultipliedAlpha = false; |
| 121 | |
| 122 | mName = name; |
| 123 | |
| 124 | mCurrentState.active.w = w; |
| 125 | mCurrentState.active.h = h; |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 126 | mCurrentState.active.transform.set(0, 0); |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 127 | mCurrentState.crop.makeInvalid(); |
| 128 | mCurrentState.finalCrop.makeInvalid(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 129 | mCurrentState.z = 0; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 130 | #ifdef USE_HWC2 |
| 131 | mCurrentState.alpha = 1.0f; |
| 132 | #else |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 133 | mCurrentState.alpha = 0xFF; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 134 | #endif |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 135 | mCurrentState.layerStack = 0; |
| 136 | mCurrentState.flags = layerFlags; |
| 137 | mCurrentState.sequence = 0; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 138 | mCurrentState.requested = mCurrentState.active; |
| 139 | |
| 140 | // drawing state & current state are identical |
| 141 | mDrawingState = mCurrentState; |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 142 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 143 | #ifdef USE_HWC2 |
| 144 | const auto& hwc = flinger->getHwComposer(); |
| 145 | const auto& activeConfig = hwc.getActiveConfig(HWC_DISPLAY_PRIMARY); |
| 146 | nsecs_t displayPeriod = activeConfig->getVsyncPeriod(); |
| 147 | #else |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 148 | nsecs_t displayPeriod = |
| 149 | flinger->getHwComposer().getRefreshPeriod(HWC_DISPLAY_PRIMARY); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 150 | #endif |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 151 | mFrameTracker.setDisplayRefreshPeriod(displayPeriod); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 154 | void Layer::onFirstRef() { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 155 | // Creates a custom BufferQueue for SurfaceFlingerConsumer to use |
Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 156 | sp<IGraphicBufferProducer> producer; |
| 157 | sp<IGraphicBufferConsumer> consumer; |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 158 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 159 | mProducer = new MonitoredProducer(producer, mFlinger); |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 160 | mSurfaceFlingerConsumer = new SurfaceFlingerConsumer(consumer, mTextureName, |
| 161 | this); |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 162 | mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0)); |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 163 | mSurfaceFlingerConsumer->setContentsChangedListener(this); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 164 | mSurfaceFlingerConsumer->setName(mName); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 165 | |
Mathias Agopian | 7f42a9c | 2012-04-23 20:00:16 -0700 | [diff] [blame] | 166 | #ifdef TARGET_DISABLE_TRIPLE_BUFFERING |
| 167 | #warning "disabling triple buffering" |
Mathias Agopian | 7f42a9c | 2012-04-23 20:00:16 -0700 | [diff] [blame] | 168 | #else |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 169 | mProducer->setMaxDequeuedBufferCount(2); |
Mathias Agopian | 303d538 | 2012-02-05 01:49:16 -0800 | [diff] [blame] | 170 | #endif |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 171 | |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 172 | const sp<const DisplayDevice> hw(mFlinger->getDefaultDisplayDevice()); |
| 173 | updateTransformHint(hw); |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 176 | Layer::~Layer() { |
Pablo Ceballos | 8ea4e7b | 2016-03-03 15:20:02 -0800 | [diff] [blame] | 177 | sp<Client> c(mClientRef.promote()); |
| 178 | if (c != 0) { |
| 179 | c->detachLayer(this); |
| 180 | } |
| 181 | |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 182 | for (auto& point : mRemoteSyncPoints) { |
| 183 | point->setTransactionApplied(); |
| 184 | } |
Dan Stoza | c814517 | 2016-04-28 16:29:06 -0700 | [diff] [blame] | 185 | for (auto& point : mLocalSyncPoints) { |
| 186 | point->setFrameAvailable(); |
| 187 | } |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 188 | mFlinger->deleteTextureAsync(mTextureName); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 189 | mFrameTracker.logAndResetStats(mName); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 192 | // --------------------------------------------------------------------------- |
| 193 | // callbacks |
| 194 | // --------------------------------------------------------------------------- |
| 195 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 196 | #ifdef USE_HWC2 |
| 197 | void Layer::onLayerDisplayed(const sp<Fence>& releaseFence) { |
| 198 | if (mHwcLayers.empty()) { |
| 199 | return; |
| 200 | } |
| 201 | mSurfaceFlingerConsumer->setReleaseFence(releaseFence); |
| 202 | } |
| 203 | #else |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 204 | void Layer::onLayerDisplayed(const sp<const DisplayDevice>& /* hw */, |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 205 | HWComposer::HWCLayerInterface* layer) { |
| 206 | if (layer) { |
| 207 | layer->onDisplayed(); |
Jesse Hall | 13f01cb | 2013-03-20 11:37:21 -0700 | [diff] [blame] | 208 | mSurfaceFlingerConsumer->setReleaseFence(layer->getAndResetReleaseFence()); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 209 | } |
| 210 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 211 | #endif |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 212 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 213 | void Layer::onFrameAvailable(const BufferItem& item) { |
| 214 | // Add this buffer from our internal queue tracker |
| 215 | { // Autolock scope |
| 216 | Mutex::Autolock lock(mQueueItemLock); |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 217 | |
| 218 | // Reset the frame number tracker when we receive the first buffer after |
| 219 | // a frame number reset |
| 220 | if (item.mFrameNumber == 1) { |
| 221 | mLastFrameNumberReceived = 0; |
| 222 | } |
| 223 | |
| 224 | // Ensure that callbacks are handled in order |
| 225 | while (item.mFrameNumber != mLastFrameNumberReceived + 1) { |
| 226 | status_t result = mQueueItemCondition.waitRelative(mQueueItemLock, |
| 227 | ms2ns(500)); |
| 228 | if (result != NO_ERROR) { |
| 229 | ALOGE("[%s] Timed out waiting on callback", mName.string()); |
| 230 | } |
| 231 | } |
| 232 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 233 | mQueueItems.push_back(item); |
Dan Stoza | ecc5040 | 2015-04-28 14:42:06 -0700 | [diff] [blame] | 234 | android_atomic_inc(&mQueuedFrames); |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 235 | |
| 236 | // Wake up any pending callbacks |
| 237 | mLastFrameNumberReceived = item.mFrameNumber; |
| 238 | mQueueItemCondition.broadcast(); |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 241 | mFlinger->signalLayerUpdate(); |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 244 | void Layer::onFrameReplaced(const BufferItem& item) { |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 245 | { // Autolock scope |
| 246 | Mutex::Autolock lock(mQueueItemLock); |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 247 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 248 | // Ensure that callbacks are handled in order |
| 249 | while (item.mFrameNumber != mLastFrameNumberReceived + 1) { |
| 250 | status_t result = mQueueItemCondition.waitRelative(mQueueItemLock, |
| 251 | ms2ns(500)); |
| 252 | if (result != NO_ERROR) { |
| 253 | ALOGE("[%s] Timed out waiting on callback", mName.string()); |
| 254 | } |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 255 | } |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 256 | |
| 257 | if (mQueueItems.empty()) { |
| 258 | ALOGE("Can't replace a frame on an empty queue"); |
| 259 | return; |
| 260 | } |
Pablo Ceballos | 4d85da4 | 2016-04-19 20:11:56 -0700 | [diff] [blame] | 261 | mQueueItems.editItemAt(mQueueItems.size() - 1) = item; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 262 | |
| 263 | // Wake up any pending callbacks |
| 264 | mLastFrameNumberReceived = item.mFrameNumber; |
| 265 | mQueueItemCondition.broadcast(); |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 266 | } |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 269 | void Layer::onSidebandStreamChanged() { |
| 270 | if (android_atomic_release_cas(false, true, &mSidebandStreamChanged) == 0) { |
| 271 | // mSidebandStreamChanged was false |
| 272 | mFlinger->signalLayerUpdate(); |
| 273 | } |
| 274 | } |
| 275 | |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 276 | // called with SurfaceFlinger::mStateLock from the drawing thread after |
| 277 | // the layer has been remove from the current state list (and just before |
| 278 | // it's removed from the drawing state list) |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 279 | void Layer::onRemoved() { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 280 | mSurfaceFlingerConsumer->abandon(); |
Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 281 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 282 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 283 | // --------------------------------------------------------------------------- |
| 284 | // set-up |
| 285 | // --------------------------------------------------------------------------- |
| 286 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 287 | const String8& Layer::getName() const { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 288 | return mName; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | } |
| 290 | |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 291 | 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] | 292 | PixelFormat format, uint32_t flags) |
| 293 | { |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 294 | uint32_t const maxSurfaceDims = min( |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 295 | mFlinger->getMaxTextureSize(), mFlinger->getMaxViewportDims()); |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 296 | |
| 297 | // never allow a surface larger than what our underlying GL implementation |
| 298 | // can handle. |
| 299 | if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) { |
Mathias Agopian | ff615cc | 2012-02-24 14:58:36 -0800 | [diff] [blame] | 300 | 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] | 301 | return BAD_VALUE; |
| 302 | } |
| 303 | |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 304 | mFormat = format; |
Mathias Agopian | eff062c | 2010-08-25 14:59:15 -0700 | [diff] [blame] | 305 | |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 306 | mPotentialCursor = (flags & ISurfaceComposerClient::eCursorWindow) ? true : false; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 307 | mProtectedByApp = (flags & ISurfaceComposerClient::eProtectedByApp) ? true : false; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 308 | mCurrentOpacity = getOpacityForFormat(format); |
| 309 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 310 | mSurfaceFlingerConsumer->setDefaultBufferSize(w, h); |
| 311 | mSurfaceFlingerConsumer->setDefaultBufferFormat(format); |
| 312 | mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0)); |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 313 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | return NO_ERROR; |
| 315 | } |
| 316 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 317 | /* |
| 318 | * The layer handle is just a BBinder object passed to the client |
| 319 | * (remote process) -- we don't keep any reference on our side such that |
| 320 | * the dtor is called when the remote side let go of its reference. |
| 321 | * |
| 322 | * LayerCleaner ensures that mFlinger->onLayerDestroyed() is called for |
| 323 | * this layer when the handle is destroyed. |
| 324 | */ |
| 325 | class Layer::Handle : public BBinder, public LayerCleaner { |
| 326 | public: |
| 327 | Handle(const sp<SurfaceFlinger>& flinger, const sp<Layer>& layer) |
| 328 | : LayerCleaner(flinger, layer), owner(layer) {} |
| 329 | |
| 330 | wp<Layer> owner; |
| 331 | }; |
| 332 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 333 | sp<IBinder> Layer::getHandle() { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 334 | Mutex::Autolock _l(mLock); |
| 335 | |
| 336 | LOG_ALWAYS_FATAL_IF(mHasSurface, |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 337 | "Layer::getHandle() has already been called"); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 338 | |
| 339 | mHasSurface = true; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 340 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 341 | return new Handle(mFlinger, this); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 342 | } |
| 343 | |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 344 | sp<IGraphicBufferProducer> Layer::getProducer() const { |
| 345 | return mProducer; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 348 | // --------------------------------------------------------------------------- |
| 349 | // h/w composer set-up |
| 350 | // --------------------------------------------------------------------------- |
| 351 | |
Mathias Agopian | a8bca8d | 2013-02-27 22:03:19 -0800 | [diff] [blame] | 352 | Rect Layer::getContentCrop() const { |
| 353 | // this is the crop rectangle that applies to the buffer |
| 354 | // itself (as opposed to the window) |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 355 | Rect crop; |
| 356 | if (!mCurrentCrop.isEmpty()) { |
Mathias Agopian | a8bca8d | 2013-02-27 22:03:19 -0800 | [diff] [blame] | 357 | // if the buffer crop is defined, we use that |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 358 | crop = mCurrentCrop; |
Mathias Agopian | a8bca8d | 2013-02-27 22:03:19 -0800 | [diff] [blame] | 359 | } else if (mActiveBuffer != NULL) { |
| 360 | // otherwise we use the whole buffer |
| 361 | crop = mActiveBuffer->getBounds(); |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 362 | } else { |
Mathias Agopian | a8bca8d | 2013-02-27 22:03:19 -0800 | [diff] [blame] | 363 | // if we don't have a buffer yet, we use an empty/invalid crop |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 364 | crop.makeInvalid(); |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 365 | } |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 366 | return crop; |
| 367 | } |
| 368 | |
Mathias Agopian | f3e85d4 | 2013-05-10 18:01:12 -0700 | [diff] [blame] | 369 | static Rect reduce(const Rect& win, const Region& exclude) { |
| 370 | if (CC_LIKELY(exclude.isEmpty())) { |
| 371 | return win; |
| 372 | } |
| 373 | if (exclude.isRect()) { |
| 374 | return win.reduce(exclude.getBounds()); |
| 375 | } |
| 376 | return Region(win).subtract(exclude).getBounds(); |
| 377 | } |
| 378 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 379 | Rect Layer::computeBounds() const { |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 380 | const Layer::State& s(getDrawingState()); |
Michael Lentine | 6c925ed | 2014-09-26 17:55:01 -0700 | [diff] [blame] | 381 | return computeBounds(s.activeTransparentRegion); |
| 382 | } |
| 383 | |
| 384 | Rect Layer::computeBounds(const Region& activeTransparentRegion) const { |
| 385 | const Layer::State& s(getDrawingState()); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 386 | Rect win(s.active.w, s.active.h); |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 387 | |
| 388 | if (!s.crop.isEmpty()) { |
| 389 | win.intersect(s.crop, &win); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 390 | } |
Mathias Agopian | 6c7f25a | 2013-05-09 20:37:10 -0700 | [diff] [blame] | 391 | // subtract the transparent region and snap to the bounds |
Michael Lentine | 6c925ed | 2014-09-26 17:55:01 -0700 | [diff] [blame] | 392 | return reduce(win, activeTransparentRegion); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 393 | } |
| 394 | |
Mathias Agopian | 6b44267 | 2013-07-09 21:24:52 -0700 | [diff] [blame] | 395 | FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 396 | // the content crop is the area of the content that gets scaled to the |
| 397 | // layer's size. |
Mathias Agopian | 6b44267 | 2013-07-09 21:24:52 -0700 | [diff] [blame] | 398 | FloatRect crop(getContentCrop()); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 399 | |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 400 | // the crop is the area of the window that gets cropped, but not |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 401 | // scaled in any ways. |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 402 | const State& s(getDrawingState()); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 403 | |
| 404 | // apply the projection's clipping to the window crop in |
| 405 | // layerstack space, and convert-back to layer space. |
Mathias Agopian | 6b44267 | 2013-07-09 21:24:52 -0700 | [diff] [blame] | 406 | // if there are no window scaling involved, this operation will map to full |
| 407 | // pixels in the buffer. |
| 408 | // FIXME: the 3 lines below can produce slightly incorrect clipping when we have |
| 409 | // a viewport clipping and a window transform. we should use floating point to fix this. |
Mathias Agopian | 0e8f144 | 2013-08-20 21:41:07 -0700 | [diff] [blame] | 410 | |
| 411 | Rect activeCrop(s.active.w, s.active.h); |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 412 | if (!s.crop.isEmpty()) { |
| 413 | activeCrop = s.crop; |
Mathias Agopian | 0e8f144 | 2013-08-20 21:41:07 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 416 | activeCrop = s.active.transform.transform(activeCrop); |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 417 | if (!activeCrop.intersect(hw->getViewport(), &activeCrop)) { |
| 418 | activeCrop.clear(); |
| 419 | } |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 420 | if (!s.finalCrop.isEmpty()) { |
| 421 | if(!activeCrop.intersect(s.finalCrop, &activeCrop)) { |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 422 | activeCrop.clear(); |
| 423 | } |
| 424 | } |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 425 | activeCrop = s.active.transform.inverse().transform(activeCrop); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 426 | |
Michael Lentine | 28ea217 | 2014-11-19 18:32:37 -0800 | [diff] [blame] | 427 | // This needs to be here as transform.transform(Rect) computes the |
| 428 | // transformed rect and then takes the bounding box of the result before |
| 429 | // returning. This means |
| 430 | // transform.inverse().transform(transform.transform(Rect)) != Rect |
| 431 | // in which case we need to make sure the final rect is clipped to the |
| 432 | // display bounds. |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 433 | if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) { |
| 434 | activeCrop.clear(); |
| 435 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 436 | |
Mathias Agopian | f3e85d4 | 2013-05-10 18:01:12 -0700 | [diff] [blame] | 437 | // subtract the transparent region and snap to the bounds |
| 438 | activeCrop = reduce(activeCrop, s.activeTransparentRegion); |
| 439 | |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 440 | // Transform the window crop to match the buffer coordinate system, |
| 441 | // which means using the inverse of the current transform set on the |
| 442 | // SurfaceFlingerConsumer. |
| 443 | uint32_t invTransform = mCurrentTransform; |
| 444 | if (mSurfaceFlingerConsumer->getTransformToDisplayInverse()) { |
| 445 | /* |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 446 | * the code below applies the primary display's inverse transform to the |
| 447 | * buffer |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 448 | */ |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 449 | uint32_t invTransformOrient = |
| 450 | DisplayDevice::getPrimaryDisplayOrientationTransform(); |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 451 | // calculate the inverse transform |
| 452 | if (invTransformOrient & NATIVE_WINDOW_TRANSFORM_ROT_90) { |
| 453 | invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | |
| 454 | NATIVE_WINDOW_TRANSFORM_FLIP_H; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 455 | } |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 456 | // and apply to the current transform |
Pablo Ceballos | 0f5131f | 2016-05-17 13:34:45 -0700 | [diff] [blame] | 457 | invTransform = (Transform(invTransformOrient) * Transform(invTransform)) |
| 458 | .getOrientation(); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 459 | } |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 460 | |
| 461 | int winWidth = s.active.w; |
| 462 | int winHeight = s.active.h; |
| 463 | if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) { |
| 464 | // If the activeCrop has been rotate the ends are rotated but not |
| 465 | // the space itself so when transforming ends back we can't rely on |
| 466 | // a modification of the axes of rotation. To account for this we |
| 467 | // need to reorient the inverse rotation in terms of the current |
| 468 | // axes of rotation. |
| 469 | bool is_h_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) != 0; |
| 470 | bool is_v_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) != 0; |
| 471 | if (is_h_flipped == is_v_flipped) { |
| 472 | invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | |
| 473 | NATIVE_WINDOW_TRANSFORM_FLIP_H; |
| 474 | } |
| 475 | winWidth = s.active.h; |
| 476 | winHeight = s.active.w; |
| 477 | } |
| 478 | const Rect winCrop = activeCrop.transform( |
| 479 | invTransform, s.active.w, s.active.h); |
| 480 | |
| 481 | // below, crop is intersected with winCrop expressed in crop's coordinate space |
| 482 | float xScale = crop.getWidth() / float(winWidth); |
| 483 | float yScale = crop.getHeight() / float(winHeight); |
| 484 | |
| 485 | float insetL = winCrop.left * xScale; |
| 486 | float insetT = winCrop.top * yScale; |
| 487 | float insetR = (winWidth - winCrop.right ) * xScale; |
| 488 | float insetB = (winHeight - winCrop.bottom) * yScale; |
| 489 | |
| 490 | crop.left += insetL; |
| 491 | crop.top += insetT; |
| 492 | crop.right -= insetR; |
| 493 | crop.bottom -= insetB; |
| 494 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 495 | return crop; |
| 496 | } |
| 497 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 498 | #ifdef USE_HWC2 |
| 499 | void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice) |
| 500 | #else |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 501 | void Layer::setGeometry( |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 502 | const sp<const DisplayDevice>& hw, |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 503 | HWComposer::HWCLayerInterface& layer) |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 504 | #endif |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 505 | { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 506 | #ifdef USE_HWC2 |
| 507 | const auto hwcId = displayDevice->getHwcDisplayId(); |
| 508 | auto& hwcInfo = mHwcLayers[hwcId]; |
| 509 | #else |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 510 | layer.setDefaultState(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 511 | #endif |
Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 512 | |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 513 | // enable this layer |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 514 | #ifdef USE_HWC2 |
| 515 | hwcInfo.forceClientComposition = false; |
| 516 | |
| 517 | if (isSecure() && !displayDevice->isSecure()) { |
| 518 | hwcInfo.forceClientComposition = true; |
| 519 | } |
| 520 | |
| 521 | auto& hwcLayer = hwcInfo.layer; |
| 522 | #else |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 523 | layer.setSkip(false); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 524 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 525 | if (isSecure() && !hw->isSecure()) { |
| 526 | layer.setSkip(true); |
| 527 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 528 | #endif |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 529 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 530 | // this gives us only the "orientation" component of the transform |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 531 | const State& s(getDrawingState()); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 532 | #ifdef USE_HWC2 |
| 533 | if (!isOpaque(s) || s.alpha != 1.0f) { |
| 534 | auto blendMode = mPremultipliedAlpha ? |
| 535 | HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage; |
| 536 | auto error = hwcLayer->setBlendMode(blendMode); |
| 537 | ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set blend mode %s:" |
| 538 | " %s (%d)", mName.string(), to_string(blendMode).c_str(), |
| 539 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 540 | } |
| 541 | #else |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 542 | if (!isOpaque(s) || s.alpha != 0xFF) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 543 | layer.setBlending(mPremultipliedAlpha ? |
| 544 | HWC_BLENDING_PREMULT : |
| 545 | HWC_BLENDING_COVERAGE); |
| 546 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 547 | #endif |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 548 | |
| 549 | // apply the layer's transform, followed by the display's global transform |
| 550 | // here we're guaranteed that the layer's transform preserves rects |
Michael Lentine | 6c925ed | 2014-09-26 17:55:01 -0700 | [diff] [blame] | 551 | Region activeTransparentRegion(s.activeTransparentRegion); |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 552 | if (!s.crop.isEmpty()) { |
| 553 | Rect activeCrop(s.crop); |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 554 | activeCrop = s.active.transform.transform(activeCrop); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 555 | #ifdef USE_HWC2 |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 556 | if(!activeCrop.intersect(displayDevice->getViewport(), &activeCrop)) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 557 | #else |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 558 | if(!activeCrop.intersect(hw->getViewport(), &activeCrop)) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 559 | #endif |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 560 | activeCrop.clear(); |
| 561 | } |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 562 | activeCrop = s.active.transform.inverse().transform(activeCrop); |
Michael Lentine | 28ea217 | 2014-11-19 18:32:37 -0800 | [diff] [blame] | 563 | // This needs to be here as transform.transform(Rect) computes the |
| 564 | // transformed rect and then takes the bounding box of the result before |
| 565 | // returning. This means |
| 566 | // transform.inverse().transform(transform.transform(Rect)) != Rect |
| 567 | // in which case we need to make sure the final rect is clipped to the |
| 568 | // display bounds. |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 569 | if(!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) { |
| 570 | activeCrop.clear(); |
| 571 | } |
Michael Lentine | 6c925ed | 2014-09-26 17:55:01 -0700 | [diff] [blame] | 572 | // mark regions outside the crop as transparent |
| 573 | activeTransparentRegion.orSelf(Rect(0, 0, s.active.w, activeCrop.top)); |
| 574 | activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom, |
| 575 | s.active.w, s.active.h)); |
| 576 | activeTransparentRegion.orSelf(Rect(0, activeCrop.top, |
| 577 | activeCrop.left, activeCrop.bottom)); |
| 578 | activeTransparentRegion.orSelf(Rect(activeCrop.right, activeCrop.top, |
| 579 | s.active.w, activeCrop.bottom)); |
| 580 | } |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 581 | Rect frame(s.active.transform.transform(computeBounds(activeTransparentRegion))); |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 582 | if (!s.finalCrop.isEmpty()) { |
| 583 | if(!frame.intersect(s.finalCrop, &frame)) { |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 584 | frame.clear(); |
| 585 | } |
| 586 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 587 | #ifdef USE_HWC2 |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 588 | if (!frame.intersect(displayDevice->getViewport(), &frame)) { |
| 589 | frame.clear(); |
| 590 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 591 | const Transform& tr(displayDevice->getTransform()); |
| 592 | Rect transformedFrame = tr.transform(frame); |
| 593 | auto error = hwcLayer->setDisplayFrame(transformedFrame); |
| 594 | ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set display frame " |
| 595 | "[%d, %d, %d, %d]: %s (%d)", mName.string(), transformedFrame.left, |
| 596 | transformedFrame.top, transformedFrame.right, |
| 597 | transformedFrame.bottom, to_string(error).c_str(), |
| 598 | static_cast<int32_t>(error)); |
| 599 | |
| 600 | FloatRect sourceCrop = computeCrop(displayDevice); |
| 601 | error = hwcLayer->setSourceCrop(sourceCrop); |
| 602 | ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set source crop " |
| 603 | "[%.3f, %.3f, %.3f, %.3f]: %s (%d)", mName.string(), |
| 604 | sourceCrop.left, sourceCrop.top, sourceCrop.right, |
| 605 | sourceCrop.bottom, to_string(error).c_str(), |
| 606 | static_cast<int32_t>(error)); |
| 607 | |
| 608 | error = hwcLayer->setPlaneAlpha(s.alpha); |
| 609 | ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set plane alpha %.3f: " |
| 610 | "%s (%d)", mName.string(), s.alpha, to_string(error).c_str(), |
| 611 | static_cast<int32_t>(error)); |
| 612 | |
| 613 | error = hwcLayer->setZOrder(s.z); |
| 614 | ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set Z %u: %s (%d)", |
| 615 | mName.string(), s.z, to_string(error).c_str(), |
| 616 | static_cast<int32_t>(error)); |
| 617 | #else |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 618 | if (!frame.intersect(hw->getViewport(), &frame)) { |
| 619 | frame.clear(); |
| 620 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 621 | const Transform& tr(hw->getTransform()); |
| 622 | layer.setFrame(tr.transform(frame)); |
| 623 | layer.setCrop(computeCrop(hw)); |
Mathias Agopian | 9f8386e | 2013-01-29 18:56:42 -0800 | [diff] [blame] | 624 | layer.setPlaneAlpha(s.alpha); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 625 | #endif |
Mathias Agopian | 9f8386e | 2013-01-29 18:56:42 -0800 | [diff] [blame] | 626 | |
Mathias Agopian | 29a367b | 2011-07-12 14:51:45 -0700 | [diff] [blame] | 627 | /* |
| 628 | * Transformations are applied in this order: |
| 629 | * 1) buffer orientation/flip/mirror |
| 630 | * 2) state transformation (window manager) |
| 631 | * 3) layer orientation (screen orientation) |
| 632 | * (NOTE: the matrices are multiplied in reverse order) |
| 633 | */ |
| 634 | |
| 635 | const Transform bufferOrientation(mCurrentTransform); |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 636 | Transform transform(tr * s.active.transform * bufferOrientation); |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 637 | |
| 638 | if (mSurfaceFlingerConsumer->getTransformToDisplayInverse()) { |
| 639 | /* |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 640 | * the code below applies the primary display's inverse transform to the |
| 641 | * buffer |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 642 | */ |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 643 | uint32_t invTransform = |
| 644 | DisplayDevice::getPrimaryDisplayOrientationTransform(); |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 645 | // calculate the inverse transform |
| 646 | if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) { |
| 647 | invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | |
| 648 | NATIVE_WINDOW_TRANSFORM_FLIP_H; |
| 649 | } |
| 650 | // and apply to the current transform |
Pablo Ceballos | 0f5131f | 2016-05-17 13:34:45 -0700 | [diff] [blame] | 651 | transform = Transform(invTransform) * transform; |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 652 | } |
Mathias Agopian | 29a367b | 2011-07-12 14:51:45 -0700 | [diff] [blame] | 653 | |
| 654 | // this gives us only the "orientation" component of the transform |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 655 | const uint32_t orientation = transform.getOrientation(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 656 | #ifdef USE_HWC2 |
| 657 | if (orientation & Transform::ROT_INVALID) { |
| 658 | // we can only handle simple transformation |
| 659 | hwcInfo.forceClientComposition = true; |
| 660 | } else { |
| 661 | auto transform = static_cast<HWC2::Transform>(orientation); |
| 662 | auto error = hwcLayer->setTransform(transform); |
| 663 | ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set transform %s: " |
| 664 | "%s (%d)", mName.string(), to_string(transform).c_str(), |
| 665 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 666 | } |
| 667 | #else |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 668 | if (orientation & Transform::ROT_INVALID) { |
| 669 | // we can only handle simple transformation |
Mathias Agopian | 3e8b853 | 2012-05-13 20:42:01 -0700 | [diff] [blame] | 670 | layer.setSkip(true); |
Mathias Agopian | a537c0f | 2011-08-02 15:51:37 -0700 | [diff] [blame] | 671 | } else { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 672 | layer.setTransform(orientation); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 673 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 674 | #endif |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 677 | #ifdef USE_HWC2 |
| 678 | void Layer::forceClientComposition(int32_t hwcId) { |
| 679 | if (mHwcLayers.count(hwcId) == 0) { |
| 680 | ALOGE("forceClientComposition: no HWC layer found (%d)", hwcId); |
| 681 | return; |
| 682 | } |
| 683 | |
| 684 | mHwcLayers[hwcId].forceClientComposition = true; |
| 685 | } |
| 686 | #endif |
| 687 | |
| 688 | #ifdef USE_HWC2 |
| 689 | void Layer::setPerFrameData(const sp<const DisplayDevice>& displayDevice) { |
| 690 | // Apply this display's projection's viewport to the visible region |
| 691 | // before giving it to the HWC HAL. |
| 692 | const Transform& tr = displayDevice->getTransform(); |
| 693 | const auto& viewport = displayDevice->getViewport(); |
| 694 | Region visible = tr.transform(visibleRegion.intersect(viewport)); |
| 695 | auto hwcId = displayDevice->getHwcDisplayId(); |
| 696 | auto& hwcLayer = mHwcLayers[hwcId].layer; |
| 697 | auto error = hwcLayer->setVisibleRegion(visible); |
| 698 | if (error != HWC2::Error::None) { |
| 699 | ALOGE("[%s] Failed to set visible region: %s (%d)", mName.string(), |
| 700 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 701 | visible.dump(LOG_TAG); |
| 702 | } |
| 703 | |
| 704 | error = hwcLayer->setSurfaceDamage(surfaceDamageRegion); |
| 705 | if (error != HWC2::Error::None) { |
| 706 | ALOGE("[%s] Failed to set surface damage: %s (%d)", mName.string(), |
| 707 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 708 | surfaceDamageRegion.dump(LOG_TAG); |
| 709 | } |
| 710 | |
Dan Stoza | 0f67b3f | 2016-05-17 10:48:38 -0700 | [diff] [blame] | 711 | // Sideband layers |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 712 | if (mSidebandStream.get()) { |
Dan Stoza | 0f67b3f | 2016-05-17 10:48:38 -0700 | [diff] [blame] | 713 | setCompositionType(hwcId, HWC2::Composition::Sideband); |
| 714 | ALOGV("[%s] Requesting Sideband composition", mName.string()); |
| 715 | error = hwcLayer->setSidebandStream(mSidebandStream->handle()); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 716 | if (error != HWC2::Error::None) { |
| 717 | ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", |
| 718 | mName.string(), mSidebandStream->handle(), |
| 719 | to_string(error).c_str(), static_cast<int32_t>(error)); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 720 | } |
Dan Stoza | 0f67b3f | 2016-05-17 10:48:38 -0700 | [diff] [blame] | 721 | return; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 722 | } |
| 723 | |
Dan Stoza | 0f67b3f | 2016-05-17 10:48:38 -0700 | [diff] [blame] | 724 | // Client or SolidColor layers |
| 725 | if (mActiveBuffer == nullptr || mActiveBuffer->handle == nullptr || |
| 726 | mHwcLayers[hwcId].forceClientComposition) { |
| 727 | // TODO: This also includes solid color layers, but no API exists to |
| 728 | // setup a solid color layer yet |
| 729 | ALOGV("[%s] Requesting Client composition", mName.string()); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 730 | setCompositionType(hwcId, HWC2::Composition::Client); |
Dan Stoza | 0f67b3f | 2016-05-17 10:48:38 -0700 | [diff] [blame] | 731 | return; |
| 732 | } |
| 733 | |
| 734 | // Device or Cursor layers |
| 735 | if (mPotentialCursor) { |
| 736 | ALOGV("[%s] Requesting Cursor composition", mName.string()); |
| 737 | setCompositionType(hwcId, HWC2::Composition::Cursor); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 738 | } else { |
| 739 | ALOGV("[%s] Requesting Device composition", mName.string()); |
| 740 | setCompositionType(hwcId, HWC2::Composition::Device); |
| 741 | } |
Dan Stoza | 0f67b3f | 2016-05-17 10:48:38 -0700 | [diff] [blame] | 742 | |
| 743 | auto acquireFence = mSurfaceFlingerConsumer->getCurrentFence(); |
| 744 | error = hwcLayer->setBuffer(mActiveBuffer->handle, acquireFence); |
| 745 | if (error != HWC2::Error::None) { |
| 746 | ALOGE("[%s] Failed to set buffer %p: %s (%d)", mName.string(), |
| 747 | mActiveBuffer->handle, to_string(error).c_str(), |
| 748 | static_cast<int32_t>(error)); |
| 749 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 750 | } |
| 751 | #else |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 752 | void Layer::setPerFrameData(const sp<const DisplayDevice>& hw, |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 753 | HWComposer::HWCLayerInterface& layer) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 754 | // we have to set the visible region on every frame because |
| 755 | // we currently free it during onLayerDisplayed(), which is called |
| 756 | // after HWComposer::commit() -- every frame. |
| 757 | // Apply this display's projection's viewport to the visible region |
| 758 | // before giving it to the HWC HAL. |
| 759 | const Transform& tr = hw->getTransform(); |
| 760 | Region visible = tr.transform(visibleRegion.intersect(hw->getViewport())); |
| 761 | layer.setVisibleRegionScreen(visible); |
Dan Stoza | db4850c | 2015-06-25 16:10:18 -0700 | [diff] [blame] | 762 | layer.setSurfaceDamage(surfaceDamageRegion); |
Pablo Ceballos | 40845df | 2016-01-25 17:41:15 -0800 | [diff] [blame] | 763 | mIsGlesComposition = (layer.getCompositionType() == HWC_FRAMEBUFFER); |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 764 | |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 765 | if (mSidebandStream.get()) { |
| 766 | layer.setSidebandStream(mSidebandStream); |
| 767 | } else { |
| 768 | // NOTE: buffer can be NULL if the client never drew into this |
| 769 | // layer yet, or if we ran out of memory |
| 770 | layer.setBuffer(mActiveBuffer); |
| 771 | } |
Jesse Hall | c5c5a14 | 2012-07-02 16:49:28 -0700 | [diff] [blame] | 772 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 773 | #endif |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 774 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 775 | #ifdef USE_HWC2 |
| 776 | void Layer::updateCursorPosition(const sp<const DisplayDevice>& displayDevice) { |
| 777 | auto hwcId = displayDevice->getHwcDisplayId(); |
| 778 | if (mHwcLayers.count(hwcId) == 0 || |
| 779 | getCompositionType(hwcId) != HWC2::Composition::Cursor) { |
| 780 | return; |
| 781 | } |
| 782 | |
| 783 | // This gives us only the "orientation" component of the transform |
| 784 | const State& s(getCurrentState()); |
| 785 | |
| 786 | // Apply the layer's transform, followed by the display's global transform |
| 787 | // Here we're guaranteed that the layer's transform preserves rects |
| 788 | Rect win(s.active.w, s.active.h); |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 789 | if (!s.crop.isEmpty()) { |
| 790 | win.intersect(s.crop, &win); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 791 | } |
| 792 | // Subtract the transparent region and snap to the bounds |
| 793 | Rect bounds = reduce(win, s.activeTransparentRegion); |
Dan Stoza | baf416d | 2016-03-10 11:57:08 -0800 | [diff] [blame] | 794 | Rect frame(s.active.transform.transform(bounds)); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 795 | frame.intersect(displayDevice->getViewport(), &frame); |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 796 | if (!s.finalCrop.isEmpty()) { |
| 797 | frame.intersect(s.finalCrop, &frame); |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 798 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 799 | auto& displayTransform(displayDevice->getTransform()); |
| 800 | auto position = displayTransform.transform(frame); |
| 801 | |
| 802 | auto error = mHwcLayers[hwcId].layer->setCursorPosition(position.left, |
| 803 | position.top); |
| 804 | ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set cursor position " |
| 805 | "to (%d, %d): %s (%d)", mName.string(), position.left, |
| 806 | position.top, to_string(error).c_str(), |
| 807 | static_cast<int32_t>(error)); |
| 808 | } |
| 809 | #else |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 810 | void Layer::setAcquireFence(const sp<const DisplayDevice>& /* hw */, |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 811 | HWComposer::HWCLayerInterface& layer) { |
Jesse Hall | c5c5a14 | 2012-07-02 16:49:28 -0700 | [diff] [blame] | 812 | int fenceFd = -1; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 813 | |
| 814 | // TODO: there is a possible optimization here: we only need to set the |
| 815 | // acquire fence the first time a new buffer is acquired on EACH display. |
| 816 | |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 817 | if (layer.getCompositionType() == HWC_OVERLAY || layer.getCompositionType() == HWC_CURSOR_OVERLAY) { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 818 | sp<Fence> fence = mSurfaceFlingerConsumer->getCurrentFence(); |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 819 | if (fence->isValid()) { |
Jesse Hall | c5c5a14 | 2012-07-02 16:49:28 -0700 | [diff] [blame] | 820 | fenceFd = fence->dup(); |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 821 | if (fenceFd == -1) { |
| 822 | ALOGW("failed to dup layer fence, skipping sync: %d", errno); |
| 823 | } |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 824 | } |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 825 | } |
Jesse Hall | c5c5a14 | 2012-07-02 16:49:28 -0700 | [diff] [blame] | 826 | layer.setAcquireFenceFd(fenceFd); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 829 | Rect Layer::getPosition( |
| 830 | const sp<const DisplayDevice>& hw) |
| 831 | { |
| 832 | // this gives us only the "orientation" component of the transform |
| 833 | const State& s(getCurrentState()); |
| 834 | |
| 835 | // apply the layer's transform, followed by the display's global transform |
| 836 | // here we're guaranteed that the layer's transform preserves rects |
| 837 | Rect win(s.active.w, s.active.h); |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 838 | if (!s.crop.isEmpty()) { |
| 839 | win.intersect(s.crop, &win); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 840 | } |
| 841 | // subtract the transparent region and snap to the bounds |
| 842 | Rect bounds = reduce(win, s.activeTransparentRegion); |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 843 | Rect frame(s.active.transform.transform(bounds)); |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 844 | frame.intersect(hw->getViewport(), &frame); |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 845 | if (!s.finalCrop.isEmpty()) { |
| 846 | frame.intersect(s.finalCrop, &frame); |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 847 | } |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 848 | const Transform& tr(hw->getTransform()); |
| 849 | return Rect(tr.transform(frame)); |
| 850 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 851 | #endif |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 852 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 853 | // --------------------------------------------------------------------------- |
| 854 | // drawing... |
| 855 | // --------------------------------------------------------------------------- |
| 856 | |
| 857 | void Layer::draw(const sp<const DisplayDevice>& hw, const Region& clip) const { |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 858 | onDraw(hw, clip, false); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 859 | } |
| 860 | |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 861 | void Layer::draw(const sp<const DisplayDevice>& hw, |
| 862 | bool useIdentityTransform) const { |
| 863 | onDraw(hw, Region(hw->bounds()), useIdentityTransform); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 864 | } |
| 865 | |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 866 | void Layer::draw(const sp<const DisplayDevice>& hw) const { |
| 867 | onDraw(hw, Region(hw->bounds()), false); |
| 868 | } |
| 869 | |
| 870 | void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip, |
| 871 | bool useIdentityTransform) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 873 | ATRACE_CALL(); |
| 874 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 875 | if (CC_UNLIKELY(mActiveBuffer == 0)) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | // the texture has not been created yet, this Layer has |
Mathias Agopian | 179169e | 2010-05-06 20:21:45 -0700 | [diff] [blame] | 877 | // in fact never been drawn into. This happens frequently with |
| 878 | // SurfaceView because the WindowManager can't know when the client |
| 879 | // has drawn the first time. |
| 880 | |
| 881 | // If there is nothing under us, we paint the screen in black, otherwise |
| 882 | // we just skip this update. |
| 883 | |
| 884 | // figure out if there is something below us |
| 885 | Region under; |
Mathias Agopian | f7ae69d | 2011-08-23 12:34:29 -0700 | [diff] [blame] | 886 | const SurfaceFlinger::LayerVector& drawingLayers( |
| 887 | mFlinger->mDrawingState.layersSortedByZ); |
Mathias Agopian | 179169e | 2010-05-06 20:21:45 -0700 | [diff] [blame] | 888 | const size_t count = drawingLayers.size(); |
| 889 | for (size_t i=0 ; i<count ; ++i) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 890 | const sp<Layer>& layer(drawingLayers[i]); |
| 891 | if (layer.get() == static_cast<Layer const*>(this)) |
Mathias Agopian | 179169e | 2010-05-06 20:21:45 -0700 | [diff] [blame] | 892 | break; |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 893 | under.orSelf( hw->getTransform().transform(layer->visibleRegion) ); |
Mathias Agopian | 179169e | 2010-05-06 20:21:45 -0700 | [diff] [blame] | 894 | } |
| 895 | // if not everything below us is covered, we plug the holes! |
| 896 | Region holes(clip.subtract(under)); |
| 897 | if (!holes.isEmpty()) { |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 898 | clearWithOpenGL(hw, holes, 0, 0, 0, 1); |
Mathias Agopian | 179169e | 2010-05-06 20:21:45 -0700 | [diff] [blame] | 899 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | return; |
| 901 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 902 | |
Andy McFadden | 97eba89 | 2012-12-11 15:21:45 -0800 | [diff] [blame] | 903 | // Bind the current buffer to the GL texture, and wait for it to be |
| 904 | // ready for us to draw into. |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 905 | status_t err = mSurfaceFlingerConsumer->bindTextureImage(); |
| 906 | if (err != NO_ERROR) { |
Andy McFadden | 97eba89 | 2012-12-11 15:21:45 -0800 | [diff] [blame] | 907 | ALOGW("onDraw: bindTextureImage failed (err=%d)", err); |
Jesse Hall | dc5b485 | 2012-06-29 15:21:18 -0700 | [diff] [blame] | 908 | // Go ahead and draw the buffer anyway; no matter what we do the screen |
| 909 | // is probably going to have something visibly wrong. |
| 910 | } |
| 911 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 912 | bool blackOutLayer = isProtected() || (isSecure() && !hw->isSecure()); |
| 913 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 914 | RenderEngine& engine(mFlinger->getRenderEngine()); |
| 915 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 916 | if (!blackOutLayer) { |
Jamie Gennis | cbb1a95 | 2012-05-08 17:05:52 -0700 | [diff] [blame] | 917 | // TODO: we could be more subtle with isFixedSize() |
Mathias Agopian | eba8c68 | 2012-09-19 23:14:45 -0700 | [diff] [blame] | 918 | const bool useFiltering = getFiltering() || needsFiltering(hw) || isFixedSize(); |
Jamie Gennis | cbb1a95 | 2012-05-08 17:05:52 -0700 | [diff] [blame] | 919 | |
| 920 | // Query the texture matrix given our current filtering mode. |
| 921 | float textureMatrix[16]; |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 922 | mSurfaceFlingerConsumer->setFilteringEnabled(useFiltering); |
| 923 | mSurfaceFlingerConsumer->getTransformMatrix(textureMatrix); |
Jamie Gennis | cbb1a95 | 2012-05-08 17:05:52 -0700 | [diff] [blame] | 924 | |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 925 | if (mSurfaceFlingerConsumer->getTransformToDisplayInverse()) { |
| 926 | |
| 927 | /* |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 928 | * the code below applies the primary display's inverse transform to |
| 929 | * the texture transform |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 930 | */ |
| 931 | |
| 932 | // create a 4x4 transform matrix from the display transform flags |
| 933 | const mat4 flipH(-1,0,0,0, 0,1,0,0, 0,0,1,0, 1,0,0,1); |
| 934 | const mat4 flipV( 1,0,0,0, 0,-1,0,0, 0,0,1,0, 0,1,0,1); |
| 935 | const mat4 rot90( 0,1,0,0, -1,0,0,0, 0,0,1,0, 1,0,0,1); |
| 936 | |
| 937 | mat4 tr; |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 938 | uint32_t transform = |
| 939 | DisplayDevice::getPrimaryDisplayOrientationTransform(); |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 940 | if (transform & NATIVE_WINDOW_TRANSFORM_ROT_90) |
| 941 | tr = tr * rot90; |
| 942 | if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_H) |
| 943 | tr = tr * flipH; |
| 944 | if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_V) |
| 945 | tr = tr * flipV; |
| 946 | |
| 947 | // calculate the inverse |
| 948 | tr = inverse(tr); |
| 949 | |
| 950 | // and finally apply it to the original texture matrix |
| 951 | const mat4 texTransform(mat4(static_cast<const float*>(textureMatrix)) * tr); |
| 952 | memcpy(textureMatrix, texTransform.asArray(), sizeof(textureMatrix)); |
| 953 | } |
| 954 | |
Jamie Gennis | cbb1a95 | 2012-05-08 17:05:52 -0700 | [diff] [blame] | 955 | // Set things up for texturing. |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 956 | mTexture.setDimensions(mActiveBuffer->getWidth(), mActiveBuffer->getHeight()); |
| 957 | mTexture.setFiltering(useFiltering); |
| 958 | mTexture.setMatrix(textureMatrix); |
| 959 | |
| 960 | engine.setupLayerTexturing(mTexture); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 961 | } else { |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 962 | engine.setupLayerBlackedOut(); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 963 | } |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 964 | drawWithOpenGL(hw, clip, useIdentityTransform); |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 965 | engine.disableTexturing(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 966 | } |
| 967 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 968 | |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 969 | void Layer::clearWithOpenGL(const sp<const DisplayDevice>& hw, |
| 970 | const Region& /* clip */, float red, float green, float blue, |
| 971 | float alpha) const |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 972 | { |
Mathias Agopian | 19733a3 | 2013-08-28 18:13:56 -0700 | [diff] [blame] | 973 | RenderEngine& engine(mFlinger->getRenderEngine()); |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 974 | computeGeometry(hw, mMesh, false); |
Mathias Agopian | 19733a3 | 2013-08-28 18:13:56 -0700 | [diff] [blame] | 975 | engine.setupFillWithColor(red, green, blue, alpha); |
| 976 | engine.drawMesh(mMesh); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | void Layer::clearWithOpenGL( |
| 980 | const sp<const DisplayDevice>& hw, const Region& clip) const { |
| 981 | clearWithOpenGL(hw, clip, 0,0,0,0); |
| 982 | } |
| 983 | |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 984 | void Layer::drawWithOpenGL(const sp<const DisplayDevice>& hw, |
| 985 | const Region& /* clip */, bool useIdentityTransform) const { |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 986 | const State& s(getDrawingState()); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 987 | |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 988 | computeGeometry(hw, mMesh, useIdentityTransform); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 989 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 990 | /* |
| 991 | * NOTE: the way we compute the texture coordinates here produces |
| 992 | * different results than when we take the HWC path -- in the later case |
| 993 | * the "source crop" is rounded to texel boundaries. |
| 994 | * This can produce significantly different results when the texture |
| 995 | * is scaled by a large amount. |
| 996 | * |
| 997 | * The GL code below is more logical (imho), and the difference with |
| 998 | * HWC is due to a limitation of the HWC API to integers -- a question |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 999 | * is suspend is whether we should ignore this problem or revert to |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1000 | * GL composition when a buffer scaling is applied (maybe with some |
| 1001 | * minimal value)? Or, we could make GL behave like HWC -- but this feel |
| 1002 | * like more of a hack. |
| 1003 | */ |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 1004 | Rect win(computeBounds()); |
| 1005 | |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1006 | if (!s.finalCrop.isEmpty()) { |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 1007 | win = s.active.transform.transform(win); |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1008 | if (!win.intersect(s.finalCrop, &win)) { |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 1009 | win.clear(); |
| 1010 | } |
| 1011 | win = s.active.transform.inverse().transform(win); |
| 1012 | if (!win.intersect(computeBounds(), &win)) { |
| 1013 | win.clear(); |
| 1014 | } |
| 1015 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1016 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 1017 | float left = float(win.left) / float(s.active.w); |
| 1018 | float top = float(win.top) / float(s.active.h); |
| 1019 | float right = float(win.right) / float(s.active.w); |
| 1020 | float bottom = float(win.bottom) / float(s.active.h); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1021 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 1022 | // TODO: we probably want to generate the texture coords with the mesh |
| 1023 | // here we assume that we only have 4 vertices |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 1024 | Mesh::VertexArray<vec2> texCoords(mMesh.getTexCoordArray<vec2>()); |
| 1025 | texCoords[0] = vec2(left, 1.0f - top); |
| 1026 | texCoords[1] = vec2(left, 1.0f - bottom); |
| 1027 | texCoords[2] = vec2(right, 1.0f - bottom); |
| 1028 | texCoords[3] = vec2(right, 1.0f - top); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1029 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 1030 | RenderEngine& engine(mFlinger->getRenderEngine()); |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 1031 | engine.setupLayerBlending(mPremultipliedAlpha, isOpaque(s), s.alpha); |
Mathias Agopian | 5cdc899 | 2013-08-13 20:51:23 -0700 | [diff] [blame] | 1032 | engine.drawMesh(mMesh); |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 1033 | engine.disableBlending(); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1036 | #ifdef USE_HWC2 |
| 1037 | void Layer::setCompositionType(int32_t hwcId, HWC2::Composition type, |
| 1038 | bool callIntoHwc) { |
| 1039 | if (mHwcLayers.count(hwcId) == 0) { |
| 1040 | ALOGE("setCompositionType called without a valid HWC layer"); |
| 1041 | return; |
| 1042 | } |
| 1043 | auto& hwcInfo = mHwcLayers[hwcId]; |
| 1044 | auto& hwcLayer = hwcInfo.layer; |
| 1045 | ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", hwcLayer->getId(), |
| 1046 | to_string(type).c_str(), static_cast<int>(callIntoHwc)); |
| 1047 | if (hwcInfo.compositionType != type) { |
| 1048 | ALOGV(" actually setting"); |
| 1049 | hwcInfo.compositionType = type; |
| 1050 | if (callIntoHwc) { |
| 1051 | auto error = hwcLayer->setCompositionType(type); |
| 1052 | ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set " |
| 1053 | "composition type %s: %s (%d)", mName.string(), |
| 1054 | to_string(type).c_str(), to_string(error).c_str(), |
| 1055 | static_cast<int32_t>(error)); |
| 1056 | } |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | HWC2::Composition Layer::getCompositionType(int32_t hwcId) const { |
| 1061 | if (mHwcLayers.count(hwcId) == 0) { |
| 1062 | ALOGE("getCompositionType called without a valid HWC layer"); |
| 1063 | return HWC2::Composition::Invalid; |
| 1064 | } |
| 1065 | return mHwcLayers.at(hwcId).compositionType; |
| 1066 | } |
| 1067 | |
| 1068 | void Layer::setClearClientTarget(int32_t hwcId, bool clear) { |
| 1069 | if (mHwcLayers.count(hwcId) == 0) { |
| 1070 | ALOGE("setClearClientTarget called without a valid HWC layer"); |
| 1071 | return; |
| 1072 | } |
| 1073 | mHwcLayers[hwcId].clearClientTarget = clear; |
| 1074 | } |
| 1075 | |
| 1076 | bool Layer::getClearClientTarget(int32_t hwcId) const { |
| 1077 | if (mHwcLayers.count(hwcId) == 0) { |
| 1078 | ALOGE("getClearClientTarget called without a valid HWC layer"); |
| 1079 | return false; |
| 1080 | } |
| 1081 | return mHwcLayers.at(hwcId).clearClientTarget; |
| 1082 | } |
| 1083 | #endif |
| 1084 | |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1085 | uint32_t Layer::getProducerStickyTransform() const { |
| 1086 | int producerStickyTransform = 0; |
| 1087 | int ret = mProducer->query(NATIVE_WINDOW_STICKY_TRANSFORM, &producerStickyTransform); |
| 1088 | if (ret != OK) { |
| 1089 | ALOGW("%s: Error %s (%d) while querying window sticky transform.", __FUNCTION__, |
| 1090 | strerror(-ret), ret); |
| 1091 | return 0; |
| 1092 | } |
| 1093 | return static_cast<uint32_t>(producerStickyTransform); |
| 1094 | } |
| 1095 | |
Dan Stoza | c5da271 | 2016-07-20 15:38:12 -0700 | [diff] [blame] | 1096 | bool Layer::latchUnsignaledBuffers() { |
| 1097 | static bool propertyLoaded = false; |
| 1098 | static bool latch = false; |
| 1099 | static std::mutex mutex; |
| 1100 | std::lock_guard<std::mutex> lock(mutex); |
| 1101 | if (!propertyLoaded) { |
| 1102 | char value[PROPERTY_VALUE_MAX] = {}; |
| 1103 | property_get("debug.sf.latch_unsignaled", value, "0"); |
| 1104 | latch = atoi(value); |
| 1105 | propertyLoaded = true; |
| 1106 | } |
| 1107 | return latch; |
| 1108 | } |
| 1109 | |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 1110 | uint64_t Layer::getHeadFrameNumber() const { |
| 1111 | Mutex::Autolock lock(mQueueItemLock); |
| 1112 | if (!mQueueItems.empty()) { |
| 1113 | return mQueueItems[0].mFrameNumber; |
| 1114 | } else { |
| 1115 | return mCurrentFrameNumber; |
| 1116 | } |
| 1117 | } |
| 1118 | |
Dan Stoza | 1ce6581 | 2016-06-15 16:26:27 -0700 | [diff] [blame] | 1119 | bool Layer::headFenceHasSignaled() const { |
| 1120 | #ifdef USE_HWC2 |
Dan Stoza | c5da271 | 2016-07-20 15:38:12 -0700 | [diff] [blame] | 1121 | if (latchUnsignaledBuffers()) { |
| 1122 | return true; |
| 1123 | } |
| 1124 | |
Dan Stoza | 1ce6581 | 2016-06-15 16:26:27 -0700 | [diff] [blame] | 1125 | Mutex::Autolock lock(mQueueItemLock); |
| 1126 | if (mQueueItems.empty()) { |
| 1127 | return true; |
| 1128 | } |
| 1129 | if (mQueueItems[0].mIsDroppable) { |
| 1130 | // Even though this buffer's fence may not have signaled yet, it could |
| 1131 | // be replaced by another buffer before it has a chance to, which means |
| 1132 | // that it's possible to get into a situation where a buffer is never |
| 1133 | // able to be latched. To avoid this, grab this buffer anyway. |
| 1134 | return true; |
| 1135 | } |
| 1136 | return mQueueItems[0].mFence->getSignalTime() != INT64_MAX; |
| 1137 | #else |
| 1138 | return true; |
| 1139 | #endif |
| 1140 | } |
| 1141 | |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 1142 | bool Layer::addSyncPoint(const std::shared_ptr<SyncPoint>& point) { |
| 1143 | if (point->getFrameNumber() <= mCurrentFrameNumber) { |
| 1144 | // Don't bother with a SyncPoint, since we've already latched the |
| 1145 | // relevant frame |
| 1146 | return false; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 1149 | Mutex::Autolock lock(mLocalSyncPointMutex); |
| 1150 | mLocalSyncPoints.push_back(point); |
| 1151 | return true; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1154 | void Layer::setFiltering(bool filtering) { |
| 1155 | mFiltering = filtering; |
| 1156 | } |
| 1157 | |
| 1158 | bool Layer::getFiltering() const { |
| 1159 | return mFiltering; |
| 1160 | } |
| 1161 | |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 1162 | // As documented in libhardware header, formats in the range |
| 1163 | // 0x100 - 0x1FF are specific to the HAL implementation, and |
| 1164 | // are known to have no alpha channel |
| 1165 | // TODO: move definition for device-specific range into |
| 1166 | // hardware.h, instead of using hard-coded values here. |
| 1167 | #define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF) |
| 1168 | |
Mathias Agopian | 5773d3f | 2013-07-25 19:24:31 -0700 | [diff] [blame] | 1169 | bool Layer::getOpacityForFormat(uint32_t format) { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1170 | if (HARDWARE_IS_DEVICE_FORMAT(format)) { |
| 1171 | return true; |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 1172 | } |
Mathias Agopian | 5773d3f | 2013-07-25 19:24:31 -0700 | [diff] [blame] | 1173 | switch (format) { |
| 1174 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 1175 | case HAL_PIXEL_FORMAT_BGRA_8888: |
Mathias Agopian | dd53371 | 2013-07-26 15:31:39 -0700 | [diff] [blame] | 1176 | return false; |
Mathias Agopian | 5773d3f | 2013-07-25 19:24:31 -0700 | [diff] [blame] | 1177 | } |
| 1178 | // in all other case, we have no blending (also for unknown formats) |
Mathias Agopian | dd53371 | 2013-07-26 15:31:39 -0700 | [diff] [blame] | 1179 | return true; |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 1180 | } |
| 1181 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1182 | // ---------------------------------------------------------------------------- |
| 1183 | // local state |
| 1184 | // ---------------------------------------------------------------------------- |
| 1185 | |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 1186 | static void boundPoint(vec2* point, const Rect& crop) { |
| 1187 | if (point->x < crop.left) { |
| 1188 | point->x = crop.left; |
| 1189 | } |
| 1190 | if (point->x > crop.right) { |
| 1191 | point->x = crop.right; |
| 1192 | } |
| 1193 | if (point->y < crop.top) { |
| 1194 | point->y = crop.top; |
| 1195 | } |
| 1196 | if (point->y > crop.bottom) { |
| 1197 | point->y = crop.bottom; |
| 1198 | } |
| 1199 | } |
| 1200 | |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 1201 | void Layer::computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh, |
| 1202 | bool useIdentityTransform) const |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1203 | { |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1204 | const Layer::State& s(getDrawingState()); |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 1205 | const Transform tr(hw->getTransform()); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1206 | const uint32_t hw_h = hw->getHeight(); |
| 1207 | Rect win(s.active.w, s.active.h); |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1208 | if (!s.crop.isEmpty()) { |
| 1209 | win.intersect(s.crop, &win); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1210 | } |
Mathias Agopian | 6c7f25a | 2013-05-09 20:37:10 -0700 | [diff] [blame] | 1211 | // subtract the transparent region and snap to the bounds |
Mathias Agopian | f3e85d4 | 2013-05-10 18:01:12 -0700 | [diff] [blame] | 1212 | win = reduce(win, s.activeTransparentRegion); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 1213 | |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 1214 | vec2 lt = vec2(win.left, win.top); |
| 1215 | vec2 lb = vec2(win.left, win.bottom); |
| 1216 | vec2 rb = vec2(win.right, win.bottom); |
| 1217 | vec2 rt = vec2(win.right, win.top); |
| 1218 | |
| 1219 | if (!useIdentityTransform) { |
| 1220 | lt = s.active.transform.transform(lt); |
| 1221 | lb = s.active.transform.transform(lb); |
| 1222 | rb = s.active.transform.transform(rb); |
| 1223 | rt = s.active.transform.transform(rt); |
| 1224 | } |
| 1225 | |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1226 | if (!s.finalCrop.isEmpty()) { |
| 1227 | boundPoint(<, s.finalCrop); |
| 1228 | boundPoint(&lb, s.finalCrop); |
| 1229 | boundPoint(&rb, s.finalCrop); |
| 1230 | boundPoint(&rt, s.finalCrop); |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 1231 | } |
| 1232 | |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 1233 | Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>()); |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 1234 | position[0] = tr.transform(lt); |
| 1235 | position[1] = tr.transform(lb); |
| 1236 | position[2] = tr.transform(rb); |
| 1237 | position[3] = tr.transform(rt); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 1238 | for (size_t i=0 ; i<4 ; i++) { |
Mathias Agopian | 5cdc899 | 2013-08-13 20:51:23 -0700 | [diff] [blame] | 1239 | position[i].y = hw_h - position[i].y; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1240 | } |
| 1241 | } |
Eric Hassold | ac45e6b | 2011-02-10 14:41:26 -0800 | [diff] [blame] | 1242 | |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 1243 | bool Layer::isOpaque(const Layer::State& s) const |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 1244 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1245 | // if we don't have a buffer yet, we're translucent regardless of the |
| 1246 | // layer's opaque flag. |
Jamie Gennis | db5230f | 2011-07-28 14:54:07 -0700 | [diff] [blame] | 1247 | if (mActiveBuffer == 0) { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1248 | return false; |
Jamie Gennis | db5230f | 2011-07-28 14:54:07 -0700 | [diff] [blame] | 1249 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1250 | |
| 1251 | // if the layer has the opaque flag, then we're always opaque, |
| 1252 | // otherwise we use the current buffer's format. |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 1253 | return ((s.flags & layer_state_t::eLayerOpaque) != 0) || mCurrentOpacity; |
Mathias Agopian | a7f6692 | 2010-05-26 22:08:52 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
Dan Stoza | 2311608 | 2015-06-18 14:58:39 -0700 | [diff] [blame] | 1256 | bool Layer::isSecure() const |
| 1257 | { |
| 1258 | const Layer::State& s(mDrawingState); |
| 1259 | return (s.flags & layer_state_t::eLayerSecure); |
| 1260 | } |
| 1261 | |
Jamie Gennis | 7a4d0df | 2011-03-09 17:05:02 -0800 | [diff] [blame] | 1262 | bool Layer::isProtected() const |
| 1263 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1264 | const sp<GraphicBuffer>& activeBuffer(mActiveBuffer); |
Jamie Gennis | 7a4d0df | 2011-03-09 17:05:02 -0800 | [diff] [blame] | 1265 | return (activeBuffer != 0) && |
| 1266 | (activeBuffer->getUsage() & GRALLOC_USAGE_PROTECTED); |
| 1267 | } |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 1268 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1269 | bool Layer::isFixedSize() const { |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 1270 | return getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | bool Layer::isCropped() const { |
| 1274 | return !mCurrentCrop.isEmpty(); |
| 1275 | } |
| 1276 | |
| 1277 | bool Layer::needsFiltering(const sp<const DisplayDevice>& hw) const { |
| 1278 | return mNeedsFiltering || hw->needsFiltering(); |
| 1279 | } |
| 1280 | |
| 1281 | void Layer::setVisibleRegion(const Region& visibleRegion) { |
| 1282 | // always called from main thread |
| 1283 | this->visibleRegion = visibleRegion; |
| 1284 | } |
| 1285 | |
| 1286 | void Layer::setCoveredRegion(const Region& coveredRegion) { |
| 1287 | // always called from main thread |
| 1288 | this->coveredRegion = coveredRegion; |
| 1289 | } |
| 1290 | |
| 1291 | void Layer::setVisibleNonTransparentRegion(const Region& |
| 1292 | setVisibleNonTransparentRegion) { |
| 1293 | // always called from main thread |
| 1294 | this->visibleNonTransparentRegion = setVisibleNonTransparentRegion; |
| 1295 | } |
| 1296 | |
| 1297 | // ---------------------------------------------------------------------------- |
| 1298 | // transaction |
| 1299 | // ---------------------------------------------------------------------------- |
| 1300 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1301 | void Layer::pushPendingState() { |
| 1302 | if (!mCurrentState.modified) { |
| 1303 | return; |
| 1304 | } |
| 1305 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1306 | // If this transaction is waiting on the receipt of a frame, generate a sync |
| 1307 | // point and send it to the remote layer. |
| 1308 | if (mCurrentState.handle != nullptr) { |
| 1309 | sp<Handle> handle = static_cast<Handle*>(mCurrentState.handle.get()); |
| 1310 | sp<Layer> handleLayer = handle->owner.promote(); |
| 1311 | if (handleLayer == nullptr) { |
| 1312 | ALOGE("[%s] Unable to promote Layer handle", mName.string()); |
| 1313 | // If we can't promote the layer we are intended to wait on, |
| 1314 | // then it is expired or otherwise invalid. Allow this transaction |
| 1315 | // to be applied as per normal (no synchronization). |
| 1316 | mCurrentState.handle = nullptr; |
Pablo Ceballos | 3bddd5b | 2015-11-19 14:39:14 -0800 | [diff] [blame] | 1317 | } else { |
| 1318 | auto syncPoint = std::make_shared<SyncPoint>( |
| 1319 | mCurrentState.frameNumber); |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 1320 | if (handleLayer->addSyncPoint(syncPoint)) { |
| 1321 | mRemoteSyncPoints.push_back(std::move(syncPoint)); |
| 1322 | } else { |
| 1323 | // We already missed the frame we're supposed to synchronize |
| 1324 | // on, so go ahead and apply the state update |
| 1325 | mCurrentState.handle = nullptr; |
| 1326 | } |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1329 | // Wake us up to check if the frame has been received |
| 1330 | setTransactionFlags(eTransactionNeeded); |
| 1331 | } |
| 1332 | mPendingStates.push_back(mCurrentState); |
| 1333 | } |
| 1334 | |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1335 | void Layer::popPendingState(State* stateToCommit) { |
| 1336 | auto oldFlags = stateToCommit->flags; |
| 1337 | *stateToCommit = mPendingStates[0]; |
| 1338 | stateToCommit->flags = (oldFlags & ~stateToCommit->mask) | |
| 1339 | (stateToCommit->flags & stateToCommit->mask); |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1340 | |
| 1341 | mPendingStates.removeAt(0); |
| 1342 | } |
| 1343 | |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1344 | bool Layer::applyPendingStates(State* stateToCommit) { |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1345 | bool stateUpdateAvailable = false; |
| 1346 | while (!mPendingStates.empty()) { |
| 1347 | if (mPendingStates[0].handle != nullptr) { |
| 1348 | if (mRemoteSyncPoints.empty()) { |
| 1349 | // If we don't have a sync point for this, apply it anyway. It |
| 1350 | // will be visually wrong, but it should keep us from getting |
| 1351 | // into too much trouble. |
| 1352 | ALOGE("[%s] No local sync point found", mName.string()); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1353 | popPendingState(stateToCommit); |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1354 | stateUpdateAvailable = true; |
| 1355 | continue; |
| 1356 | } |
| 1357 | |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 1358 | if (mRemoteSyncPoints.front()->getFrameNumber() != |
| 1359 | mPendingStates[0].frameNumber) { |
| 1360 | ALOGE("[%s] Unexpected sync point frame number found", |
| 1361 | mName.string()); |
| 1362 | |
| 1363 | // Signal our end of the sync point and then dispose of it |
| 1364 | mRemoteSyncPoints.front()->setTransactionApplied(); |
| 1365 | mRemoteSyncPoints.pop_front(); |
| 1366 | continue; |
| 1367 | } |
| 1368 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1369 | if (mRemoteSyncPoints.front()->frameIsAvailable()) { |
| 1370 | // Apply the state update |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1371 | popPendingState(stateToCommit); |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1372 | stateUpdateAvailable = true; |
| 1373 | |
| 1374 | // Signal our end of the sync point and then dispose of it |
| 1375 | mRemoteSyncPoints.front()->setTransactionApplied(); |
| 1376 | mRemoteSyncPoints.pop_front(); |
Dan Stoza | 792e529 | 2016-02-11 11:43:58 -0800 | [diff] [blame] | 1377 | } else { |
| 1378 | break; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1379 | } |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1380 | } else { |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1381 | popPendingState(stateToCommit); |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1382 | stateUpdateAvailable = true; |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | // If we still have pending updates, wake SurfaceFlinger back up and point |
| 1387 | // it at this layer so we can process them |
| 1388 | if (!mPendingStates.empty()) { |
| 1389 | setTransactionFlags(eTransactionNeeded); |
| 1390 | mFlinger->setTransactionFlags(eTraversalNeeded); |
| 1391 | } |
| 1392 | |
| 1393 | mCurrentState.modified = false; |
| 1394 | return stateUpdateAvailable; |
| 1395 | } |
| 1396 | |
| 1397 | void Layer::notifyAvailableFrames() { |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 1398 | auto headFrameNumber = getHeadFrameNumber(); |
Dan Stoza | 1ce6581 | 2016-06-15 16:26:27 -0700 | [diff] [blame] | 1399 | bool headFenceSignaled = headFenceHasSignaled(); |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 1400 | Mutex::Autolock lock(mLocalSyncPointMutex); |
| 1401 | for (auto& point : mLocalSyncPoints) { |
Dan Stoza | 1ce6581 | 2016-06-15 16:26:27 -0700 | [diff] [blame] | 1402 | if (headFrameNumber >= point->getFrameNumber() && headFenceSignaled) { |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 1403 | point->setFrameAvailable(); |
| 1404 | } |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1408 | uint32_t Layer::doTransaction(uint32_t flags) { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 1409 | ATRACE_CALL(); |
| 1410 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1411 | pushPendingState(); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1412 | Layer::State c = getCurrentState(); |
| 1413 | if (!applyPendingStates(&c)) { |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1414 | return 0; |
| 1415 | } |
| 1416 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1417 | const Layer::State& s(getDrawingState()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1418 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1419 | const bool sizeChanged = (c.requested.w != s.requested.w) || |
| 1420 | (c.requested.h != s.requested.h); |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 1421 | |
| 1422 | if (sizeChanged) { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1423 | // 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] | 1424 | ALOGD_IF(DEBUG_RESIZE, |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 1425 | "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n" |
Mathias Agopian | 419e196 | 2012-05-23 14:34:07 -0700 | [diff] [blame] | 1426 | " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n" |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1427 | " requested={ wh={%4u,%4u} }}\n" |
Mathias Agopian | 419e196 | 2012-05-23 14:34:07 -0700 | [diff] [blame] | 1428 | " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n" |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1429 | " requested={ wh={%4u,%4u} }}\n", |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 1430 | this, getName().string(), mCurrentTransform, |
| 1431 | getEffectiveScalingMode(), |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1432 | c.active.w, c.active.h, |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1433 | c.crop.left, |
| 1434 | c.crop.top, |
| 1435 | c.crop.right, |
| 1436 | c.crop.bottom, |
| 1437 | c.crop.getWidth(), |
| 1438 | c.crop.getHeight(), |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1439 | c.requested.w, c.requested.h, |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1440 | s.active.w, s.active.h, |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1441 | s.crop.left, |
| 1442 | s.crop.top, |
| 1443 | s.crop.right, |
| 1444 | s.crop.bottom, |
| 1445 | s.crop.getWidth(), |
| 1446 | s.crop.getHeight(), |
| 1447 | s.requested.w, s.requested.h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1448 | |
Jamie Gennis | 2a0d5b6 | 2011-09-26 16:54:44 -0700 | [diff] [blame] | 1449 | // record the new size, form this point on, when the client request |
| 1450 | // a buffer, it'll get the new size. |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 1451 | mSurfaceFlingerConsumer->setDefaultBufferSize( |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1452 | c.requested.w, c.requested.h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1454 | |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 1455 | const bool resizePending = (c.requested.w != c.active.w) || |
| 1456 | (c.requested.h != c.active.h); |
Mathias Agopian | 0cd545f | 2012-06-07 14:18:55 -0700 | [diff] [blame] | 1457 | if (!isFixedSize()) { |
Dan Stoza | 9e9b044 | 2015-04-22 14:59:08 -0700 | [diff] [blame] | 1458 | if (resizePending && mSidebandStream == NULL) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1459 | // don't let Layer::doTransaction update the drawing state |
Mathias Agopian | 0cd545f | 2012-06-07 14:18:55 -0700 | [diff] [blame] | 1460 | // if we have a pending resize, unless we are in fixed-size mode. |
| 1461 | // the drawing state will be updated only once we receive a buffer |
| 1462 | // with the correct size. |
| 1463 | // |
| 1464 | // in particular, we want to make sure the clip (which is part |
| 1465 | // of the geometry state) is latched together with the size but is |
| 1466 | // latched immediately when no resizing is involved. |
Dan Stoza | 9e9b044 | 2015-04-22 14:59:08 -0700 | [diff] [blame] | 1467 | // |
| 1468 | // If a sideband stream is attached, however, we want to skip this |
| 1469 | // optimization so that transactions aren't missed when a buffer |
| 1470 | // never arrives |
Mathias Agopian | 0cd545f | 2012-06-07 14:18:55 -0700 | [diff] [blame] | 1471 | |
| 1472 | flags |= eDontUpdateGeometryState; |
| 1473 | } |
| 1474 | } |
| 1475 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1476 | // always set active to requested, unless we're asked not to |
| 1477 | // this is used by Layer, which special cases resizes. |
| 1478 | if (flags & eDontUpdateGeometryState) { |
| 1479 | } else { |
Pablo Ceballos | 7d05257 | 2016-06-02 17:46:05 -0700 | [diff] [blame] | 1480 | Layer::State& editCurrentState(getCurrentState()); |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 1481 | if (mFreezePositionUpdates) { |
| 1482 | float tx = c.active.transform.tx(); |
| 1483 | float ty = c.active.transform.ty(); |
| 1484 | c.active = c.requested; |
| 1485 | c.active.transform.set(tx, ty); |
| 1486 | editCurrentState.active = c.active; |
| 1487 | } else { |
| 1488 | editCurrentState.active = editCurrentState.requested; |
| 1489 | c.active = c.requested; |
| 1490 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1491 | } |
| 1492 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1493 | if (s.active != c.active) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1494 | // invalidate and recompute the visible regions if needed |
| 1495 | flags |= Layer::eVisibleRegion; |
| 1496 | } |
| 1497 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 1498 | if (c.sequence != s.sequence) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1499 | // invalidate and recompute the visible regions if needed |
| 1500 | flags |= eVisibleRegion; |
| 1501 | this->contentDirty = true; |
| 1502 | |
| 1503 | // we may use linear filtering, if the matrix scales us |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 1504 | const uint8_t type = c.active.transform.getType(); |
| 1505 | mNeedsFiltering = (!c.active.transform.preserveRects() || |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1506 | (type >= Transform::SCALE)); |
| 1507 | } |
| 1508 | |
Dan Stoza | c814517 | 2016-04-28 16:29:06 -0700 | [diff] [blame] | 1509 | // If the layer is hidden, signal and clear out all local sync points so |
| 1510 | // that transactions for layers depending on this layer's frames becoming |
| 1511 | // visible are not blocked |
| 1512 | if (c.flags & layer_state_t::eLayerHidden) { |
| 1513 | Mutex::Autolock lock(mLocalSyncPointMutex); |
| 1514 | for (auto& point : mLocalSyncPoints) { |
| 1515 | point->setFrameAvailable(); |
| 1516 | } |
| 1517 | mLocalSyncPoints.clear(); |
| 1518 | } |
| 1519 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1520 | // Commit the transaction |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1521 | commitTransaction(c); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1522 | return flags; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | } |
| 1524 | |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1525 | void Layer::commitTransaction(const State& stateToCommit) { |
| 1526 | mDrawingState = stateToCommit; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1529 | uint32_t Layer::getTransactionFlags(uint32_t flags) { |
| 1530 | return android_atomic_and(~flags, &mTransactionFlags) & flags; |
| 1531 | } |
| 1532 | |
| 1533 | uint32_t Layer::setTransactionFlags(uint32_t flags) { |
| 1534 | return android_atomic_or(flags, &mTransactionFlags); |
| 1535 | } |
| 1536 | |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 1537 | bool Layer::setPosition(float x, float y, bool immediate) { |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 1538 | if (mCurrentState.requested.transform.tx() == x && mCurrentState.requested.transform.ty() == y) |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1539 | return false; |
| 1540 | mCurrentState.sequence++; |
Robert Carr | 69663fb | 2016-03-27 19:59:19 -0700 | [diff] [blame] | 1541 | |
| 1542 | // We update the requested and active position simultaneously because |
| 1543 | // we want to apply the position portion of the transform matrix immediately, |
| 1544 | // but still delay scaling when resizing a SCALING_MODE_FREEZE layer. |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 1545 | mCurrentState.requested.transform.set(x, y); |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 1546 | if (immediate && !mFreezePositionUpdates) { |
| 1547 | mCurrentState.active.transform.set(x, y); |
| 1548 | } |
| 1549 | mFreezePositionUpdates = mFreezePositionUpdates || !immediate; |
Robert Carr | 69663fb | 2016-03-27 19:59:19 -0700 | [diff] [blame] | 1550 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1551 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1552 | setTransactionFlags(eTransactionNeeded); |
| 1553 | return true; |
| 1554 | } |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 1555 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1556 | bool Layer::setLayer(uint32_t z) { |
| 1557 | if (mCurrentState.z == z) |
| 1558 | return false; |
| 1559 | mCurrentState.sequence++; |
| 1560 | mCurrentState.z = z; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1561 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1562 | setTransactionFlags(eTransactionNeeded); |
| 1563 | return true; |
| 1564 | } |
| 1565 | bool Layer::setSize(uint32_t w, uint32_t h) { |
| 1566 | if (mCurrentState.requested.w == w && mCurrentState.requested.h == h) |
| 1567 | return false; |
| 1568 | mCurrentState.requested.w = w; |
| 1569 | mCurrentState.requested.h = h; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1570 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1571 | setTransactionFlags(eTransactionNeeded); |
| 1572 | return true; |
| 1573 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1574 | #ifdef USE_HWC2 |
| 1575 | bool Layer::setAlpha(float alpha) { |
| 1576 | #else |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1577 | bool Layer::setAlpha(uint8_t alpha) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1578 | #endif |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1579 | if (mCurrentState.alpha == alpha) |
| 1580 | return false; |
| 1581 | mCurrentState.sequence++; |
| 1582 | mCurrentState.alpha = alpha; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1583 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1584 | setTransactionFlags(eTransactionNeeded); |
| 1585 | return true; |
| 1586 | } |
| 1587 | bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) { |
| 1588 | mCurrentState.sequence++; |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 1589 | mCurrentState.requested.transform.set( |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1590 | matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy); |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1591 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1592 | setTransactionFlags(eTransactionNeeded); |
| 1593 | return true; |
| 1594 | } |
| 1595 | bool Layer::setTransparentRegionHint(const Region& transparent) { |
Mathias Agopian | 2ca7939 | 2013-04-02 18:30:32 -0700 | [diff] [blame] | 1596 | mCurrentState.requestedTransparentRegion = transparent; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1597 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1598 | setTransactionFlags(eTransactionNeeded); |
| 1599 | return true; |
| 1600 | } |
| 1601 | bool Layer::setFlags(uint8_t flags, uint8_t mask) { |
| 1602 | const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask); |
| 1603 | if (mCurrentState.flags == newFlags) |
| 1604 | return false; |
| 1605 | mCurrentState.sequence++; |
| 1606 | mCurrentState.flags = newFlags; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1607 | mCurrentState.mask = mask; |
| 1608 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1609 | setTransactionFlags(eTransactionNeeded); |
| 1610 | return true; |
| 1611 | } |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 1612 | |
| 1613 | bool Layer::setCrop(const Rect& crop, bool immediate) { |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1614 | if (mCurrentState.crop == crop) |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1615 | return false; |
| 1616 | mCurrentState.sequence++; |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 1617 | mCurrentState.requestedCrop = crop; |
| 1618 | if (immediate) { |
| 1619 | mCurrentState.crop = crop; |
| 1620 | } |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1621 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1622 | setTransactionFlags(eTransactionNeeded); |
| 1623 | return true; |
| 1624 | } |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 1625 | bool Layer::setFinalCrop(const Rect& crop) { |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1626 | if (mCurrentState.finalCrop == crop) |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 1627 | return false; |
| 1628 | mCurrentState.sequence++; |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1629 | mCurrentState.finalCrop = crop; |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 1630 | mCurrentState.modified = true; |
| 1631 | setTransactionFlags(eTransactionNeeded); |
| 1632 | return true; |
| 1633 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1634 | |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 1635 | bool Layer::setOverrideScalingMode(int32_t scalingMode) { |
| 1636 | if (scalingMode == mOverrideScalingMode) |
| 1637 | return false; |
| 1638 | mOverrideScalingMode = scalingMode; |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 1639 | setTransactionFlags(eTransactionNeeded); |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 1640 | return true; |
| 1641 | } |
| 1642 | |
| 1643 | uint32_t Layer::getEffectiveScalingMode() const { |
| 1644 | if (mOverrideScalingMode >= 0) { |
| 1645 | return mOverrideScalingMode; |
| 1646 | } |
| 1647 | return mCurrentScalingMode; |
| 1648 | } |
| 1649 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1650 | bool Layer::setLayerStack(uint32_t layerStack) { |
| 1651 | if (mCurrentState.layerStack == layerStack) |
| 1652 | return false; |
| 1653 | mCurrentState.sequence++; |
| 1654 | mCurrentState.layerStack = layerStack; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1655 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1656 | setTransactionFlags(eTransactionNeeded); |
| 1657 | return true; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1660 | void Layer::deferTransactionUntil(const sp<IBinder>& handle, |
| 1661 | uint64_t frameNumber) { |
| 1662 | mCurrentState.handle = handle; |
| 1663 | mCurrentState.frameNumber = frameNumber; |
| 1664 | // We don't set eTransactionNeeded, because just receiving a deferral |
| 1665 | // request without any other state updates shouldn't actually induce a delay |
| 1666 | mCurrentState.modified = true; |
| 1667 | pushPendingState(); |
Dan Stoza | 792e529 | 2016-02-11 11:43:58 -0800 | [diff] [blame] | 1668 | mCurrentState.handle = nullptr; |
| 1669 | mCurrentState.frameNumber = 0; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1670 | mCurrentState.modified = false; |
| 1671 | } |
| 1672 | |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 1673 | void Layer::useSurfaceDamage() { |
| 1674 | if (mFlinger->mForceFullDamage) { |
| 1675 | surfaceDamageRegion = Region::INVALID_REGION; |
| 1676 | } else { |
| 1677 | surfaceDamageRegion = mSurfaceFlingerConsumer->getSurfaceDamage(); |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | void Layer::useEmptyDamage() { |
| 1682 | surfaceDamageRegion.clear(); |
| 1683 | } |
| 1684 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1685 | // ---------------------------------------------------------------------------- |
| 1686 | // pageflip handling... |
| 1687 | // ---------------------------------------------------------------------------- |
| 1688 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 1689 | bool Layer::shouldPresentNow(const DispSync& dispSync) const { |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1690 | if (mSidebandStreamChanged || mAutoRefresh) { |
Dan Stoza | d87defa | 2015-07-29 16:15:50 -0700 | [diff] [blame] | 1691 | return true; |
| 1692 | } |
| 1693 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 1694 | Mutex::Autolock lock(mQueueItemLock); |
Dan Stoza | 0eb2d39 | 2015-07-06 12:56:50 -0700 | [diff] [blame] | 1695 | if (mQueueItems.empty()) { |
| 1696 | return false; |
| 1697 | } |
| 1698 | auto timestamp = mQueueItems[0].mTimestamp; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 1699 | nsecs_t expectedPresent = |
| 1700 | mSurfaceFlingerConsumer->computeExpectedPresent(dispSync); |
Dan Stoza | 0eb2d39 | 2015-07-06 12:56:50 -0700 | [diff] [blame] | 1701 | |
| 1702 | // Ignore timestamps more than a second in the future |
| 1703 | bool isPlausible = timestamp < (expectedPresent + s2ns(1)); |
| 1704 | ALOGW_IF(!isPlausible, "[%s] Timestamp %" PRId64 " seems implausible " |
| 1705 | "relative to expectedPresent %" PRId64, mName.string(), timestamp, |
| 1706 | expectedPresent); |
| 1707 | |
| 1708 | bool isDue = timestamp < expectedPresent; |
| 1709 | return isDue || !isPlausible; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 1710 | } |
| 1711 | |
Mathias Agopian | 4d143ee | 2012-02-23 20:05:39 -0800 | [diff] [blame] | 1712 | bool Layer::onPreComposition() { |
| 1713 | mRefreshPending = false; |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1714 | return mQueuedFrames > 0 || mSidebandStreamChanged || mAutoRefresh; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1715 | } |
| 1716 | |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 1717 | bool Layer::onPostComposition() { |
| 1718 | bool frameLatencyNeeded = mFrameLatencyNeeded; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 1719 | if (mFrameLatencyNeeded) { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 1720 | nsecs_t desiredPresentTime = mSurfaceFlingerConsumer->getTimestamp(); |
Jamie Gennis | 82dbc74 | 2012-11-08 19:23:28 -0800 | [diff] [blame] | 1721 | mFrameTracker.setDesiredPresentTime(desiredPresentTime); |
| 1722 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 1723 | sp<Fence> frameReadyFence = mSurfaceFlingerConsumer->getCurrentFence(); |
Jamie Gennis | 789a6c3 | 2013-02-25 13:37:54 -0800 | [diff] [blame] | 1724 | if (frameReadyFence->isValid()) { |
Jamie Gennis | 82dbc74 | 2012-11-08 19:23:28 -0800 | [diff] [blame] | 1725 | mFrameTracker.setFrameReadyFence(frameReadyFence); |
| 1726 | } else { |
| 1727 | // There was no fence for this frame, so assume that it was ready |
| 1728 | // to be presented at the desired present time. |
| 1729 | mFrameTracker.setFrameReadyTime(desiredPresentTime); |
| 1730 | } |
| 1731 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 1732 | const HWComposer& hwc = mFlinger->getHwComposer(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1733 | #ifdef USE_HWC2 |
| 1734 | sp<Fence> presentFence = hwc.getRetireFence(HWC_DISPLAY_PRIMARY); |
| 1735 | #else |
Jamie Gennis | 82dbc74 | 2012-11-08 19:23:28 -0800 | [diff] [blame] | 1736 | sp<Fence> presentFence = hwc.getDisplayFence(HWC_DISPLAY_PRIMARY); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1737 | #endif |
Jamie Gennis | 789a6c3 | 2013-02-25 13:37:54 -0800 | [diff] [blame] | 1738 | if (presentFence->isValid()) { |
Jamie Gennis | 82dbc74 | 2012-11-08 19:23:28 -0800 | [diff] [blame] | 1739 | mFrameTracker.setActualPresentFence(presentFence); |
| 1740 | } else { |
| 1741 | // The HWC doesn't support present fences, so use the refresh |
| 1742 | // timestamp instead. |
| 1743 | nsecs_t presentTime = hwc.getRefreshTimestamp(HWC_DISPLAY_PRIMARY); |
| 1744 | mFrameTracker.setActualPresentTime(presentTime); |
| 1745 | } |
| 1746 | |
| 1747 | mFrameTracker.advanceFrame(); |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 1748 | mFrameLatencyNeeded = false; |
| 1749 | } |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 1750 | return frameLatencyNeeded; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1753 | #ifdef USE_HWC2 |
| 1754 | void Layer::releasePendingBuffer() { |
| 1755 | mSurfaceFlingerConsumer->releasePendingBuffer(); |
| 1756 | } |
| 1757 | #endif |
| 1758 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 1759 | bool Layer::isVisible() const { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1760 | const Layer::State& s(mDrawingState); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1761 | #ifdef USE_HWC2 |
| 1762 | return !(s.flags & layer_state_t::eLayerHidden) && s.alpha > 0.0f |
| 1763 | && (mActiveBuffer != NULL || mSidebandStream != NULL); |
| 1764 | #else |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1765 | return !(s.flags & layer_state_t::eLayerHidden) && s.alpha |
Wonsik Kim | afe3081 | 2014-03-31 23:16:08 +0900 | [diff] [blame] | 1766 | && (mActiveBuffer != NULL || mSidebandStream != NULL); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 1767 | #endif |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1770 | Region Layer::latchBuffer(bool& recomputeVisibleRegions) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1771 | { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 1772 | ATRACE_CALL(); |
| 1773 | |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 1774 | if (android_atomic_acquire_cas(true, false, &mSidebandStreamChanged) == 0) { |
| 1775 | // mSidebandStreamChanged was true |
| 1776 | mSidebandStream = mSurfaceFlingerConsumer->getSidebandStream(); |
Dan Stoza | 12e0a27 | 2015-05-05 14:00:52 -0700 | [diff] [blame] | 1777 | if (mSidebandStream != NULL) { |
| 1778 | setTransactionFlags(eTransactionNeeded); |
| 1779 | mFlinger->setTransactionFlags(eTraversalNeeded); |
| 1780 | } |
Jesse Hall | 5bf786d | 2014-09-30 10:35:11 -0700 | [diff] [blame] | 1781 | recomputeVisibleRegions = true; |
| 1782 | |
| 1783 | const State& s(getDrawingState()); |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 1784 | return s.active.transform.transform(Region(Rect(s.active.w, s.active.h))); |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 1785 | } |
| 1786 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1787 | Region outDirtyRegion; |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1788 | if (mQueuedFrames > 0 || mAutoRefresh) { |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1789 | |
| 1790 | // if we've already called updateTexImage() without going through |
| 1791 | // a composition step, we have to skip this layer at this point |
| 1792 | // because we cannot call updateTeximage() without a corresponding |
| 1793 | // compositionComplete() call. |
| 1794 | // we'll trigger an update in onPreComposition(). |
Mathias Agopian | 4d143ee | 2012-02-23 20:05:39 -0800 | [diff] [blame] | 1795 | if (mRefreshPending) { |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 1796 | return outDirtyRegion; |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 1797 | } |
| 1798 | |
Dan Stoza | 1ce6581 | 2016-06-15 16:26:27 -0700 | [diff] [blame] | 1799 | // If the head buffer's acquire fence hasn't signaled yet, return and |
| 1800 | // try again later |
| 1801 | if (!headFenceHasSignaled()) { |
| 1802 | mFlinger->signalLayerUpdate(); |
| 1803 | return outDirtyRegion; |
| 1804 | } |
| 1805 | |
Jamie Gennis | 351a513 | 2011-09-14 18:23:37 -0700 | [diff] [blame] | 1806 | // Capture the old state of the layer for comparisons later |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 1807 | const State& s(getDrawingState()); |
| 1808 | const bool oldOpacity = isOpaque(s); |
Jamie Gennis | 351a513 | 2011-09-14 18:23:37 -0700 | [diff] [blame] | 1809 | sp<GraphicBuffer> oldActiveBuffer = mActiveBuffer; |
Jamie Gennis | db5230f | 2011-07-28 14:54:07 -0700 | [diff] [blame] | 1810 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 1811 | struct Reject : public SurfaceFlingerConsumer::BufferRejecter { |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1812 | Layer::State& front; |
| 1813 | Layer::State& current; |
| 1814 | bool& recomputeVisibleRegions; |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1815 | bool stickyTransformSet; |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1816 | const char* name; |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 1817 | int32_t overrideScalingMode; |
Robert Carr | a392073 | 2016-06-20 21:49:49 -0700 | [diff] [blame] | 1818 | bool& freezePositionUpdates; |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1819 | |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1820 | Reject(Layer::State& front, Layer::State& current, |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1821 | bool& recomputeVisibleRegions, bool stickySet, |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 1822 | const char* name, |
Robert Carr | a392073 | 2016-06-20 21:49:49 -0700 | [diff] [blame] | 1823 | int32_t overrideScalingMode, |
| 1824 | bool& freezePositionUpdates) |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1825 | : front(front), current(current), |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1826 | recomputeVisibleRegions(recomputeVisibleRegions), |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1827 | stickyTransformSet(stickySet), |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 1828 | name(name), |
Robert Carr | a392073 | 2016-06-20 21:49:49 -0700 | [diff] [blame] | 1829 | overrideScalingMode(overrideScalingMode), |
| 1830 | freezePositionUpdates(freezePositionUpdates) { |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | virtual bool reject(const sp<GraphicBuffer>& buf, |
Dan Stoza | 11611f9 | 2015-03-12 15:12:44 -0700 | [diff] [blame] | 1834 | const BufferItem& item) { |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1835 | if (buf == NULL) { |
| 1836 | return false; |
| 1837 | } |
| 1838 | |
| 1839 | uint32_t bufWidth = buf->getWidth(); |
| 1840 | uint32_t bufHeight = buf->getHeight(); |
| 1841 | |
| 1842 | // check that we received a buffer of the right size |
| 1843 | // (Take the buffer's orientation into account) |
| 1844 | if (item.mTransform & Transform::ROT_90) { |
| 1845 | swap(bufWidth, bufHeight); |
| 1846 | } |
| 1847 | |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 1848 | int actualScalingMode = overrideScalingMode >= 0 ? |
| 1849 | overrideScalingMode : item.mScalingMode; |
| 1850 | bool isFixedSize = actualScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE; |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1851 | if (front.active != front.requested) { |
| 1852 | |
| 1853 | if (isFixedSize || |
| 1854 | (bufWidth == front.requested.w && |
| 1855 | bufHeight == front.requested.h)) |
| 1856 | { |
| 1857 | // Here we pretend the transaction happened by updating the |
| 1858 | // current and drawing states. Drawing state is only accessed |
| 1859 | // in this thread, no need to have it locked |
| 1860 | front.active = front.requested; |
| 1861 | |
| 1862 | // We also need to update the current state so that |
| 1863 | // we don't end-up overwriting the drawing state with |
| 1864 | // this stale current state during the next transaction |
| 1865 | // |
| 1866 | // NOTE: We don't need to hold the transaction lock here |
| 1867 | // because State::active is only accessed from this thread. |
| 1868 | current.active = front.active; |
Pablo Ceballos | 39c88e8 | 2016-05-10 17:15:24 -0700 | [diff] [blame] | 1869 | current.modified = true; |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1870 | |
| 1871 | // recompute visible region |
| 1872 | recomputeVisibleRegions = true; |
| 1873 | } |
| 1874 | |
| 1875 | ALOGD_IF(DEBUG_RESIZE, |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1876 | "[%s] latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n" |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1877 | " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n" |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1878 | " requested={ wh={%4u,%4u} }}\n", |
| 1879 | name, |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 1880 | bufWidth, bufHeight, item.mTransform, item.mScalingMode, |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1881 | front.active.w, front.active.h, |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1882 | front.crop.left, |
| 1883 | front.crop.top, |
| 1884 | front.crop.right, |
| 1885 | front.crop.bottom, |
| 1886 | front.crop.getWidth(), |
| 1887 | front.crop.getHeight(), |
| 1888 | front.requested.w, front.requested.h); |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1891 | if (!isFixedSize && !stickyTransformSet) { |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1892 | if (front.active.w != bufWidth || |
| 1893 | front.active.h != bufHeight) { |
Mathias Agopian | 4824d40 | 2012-06-04 18:16:30 -0700 | [diff] [blame] | 1894 | // reject this buffer |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 1895 | ALOGE("[%s] rejecting buffer: " |
| 1896 | "bufWidth=%d, bufHeight=%d, front.active.{w=%d, h=%d}", |
| 1897 | name, bufWidth, bufHeight, front.active.w, front.active.h); |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1898 | return true; |
| 1899 | } |
| 1900 | } |
Mathias Agopian | 2ca7939 | 2013-04-02 18:30:32 -0700 | [diff] [blame] | 1901 | |
| 1902 | // if the transparent region has changed (this test is |
| 1903 | // conservative, but that's fine, worst case we're doing |
| 1904 | // a bit of extra work), we latch the new one and we |
| 1905 | // trigger a visible-region recompute. |
| 1906 | if (!front.activeTransparentRegion.isTriviallyEqual( |
| 1907 | front.requestedTransparentRegion)) { |
| 1908 | front.activeTransparentRegion = front.requestedTransparentRegion; |
Mathias Agopian | 6c67f0f | 2013-04-12 16:58:11 -0700 | [diff] [blame] | 1909 | |
| 1910 | // We also need to update the current state so that |
| 1911 | // we don't end-up overwriting the drawing state with |
| 1912 | // this stale current state during the next transaction |
| 1913 | // |
| 1914 | // NOTE: We don't need to hold the transaction lock here |
| 1915 | // because State::active is only accessed from this thread. |
| 1916 | current.activeTransparentRegion = front.activeTransparentRegion; |
| 1917 | |
| 1918 | // recompute visible region |
Mathias Agopian | 2ca7939 | 2013-04-02 18:30:32 -0700 | [diff] [blame] | 1919 | recomputeVisibleRegions = true; |
| 1920 | } |
| 1921 | |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 1922 | if (front.crop != front.requestedCrop) { |
| 1923 | front.crop = front.requestedCrop; |
| 1924 | current.crop = front.requestedCrop; |
| 1925 | recomputeVisibleRegions = true; |
| 1926 | } |
Robert Carr | a392073 | 2016-06-20 21:49:49 -0700 | [diff] [blame] | 1927 | freezePositionUpdates = false; |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 1928 | |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1929 | return false; |
| 1930 | } |
| 1931 | }; |
| 1932 | |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1933 | Reject r(mDrawingState, getCurrentState(), recomputeVisibleRegions, |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 1934 | getProducerStickyTransform() != 0, mName.string(), |
Robert Carr | a392073 | 2016-06-20 21:49:49 -0700 | [diff] [blame] | 1935 | mOverrideScalingMode, mFreezePositionUpdates); |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 1936 | |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 1937 | |
| 1938 | // Check all of our local sync points to ensure that all transactions |
| 1939 | // which need to have been applied prior to the frame which is about to |
| 1940 | // be latched have signaled |
| 1941 | |
| 1942 | auto headFrameNumber = getHeadFrameNumber(); |
| 1943 | bool matchingFramesFound = false; |
| 1944 | bool allTransactionsApplied = true; |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 1945 | { |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 1946 | Mutex::Autolock lock(mLocalSyncPointMutex); |
| 1947 | for (auto& point : mLocalSyncPoints) { |
| 1948 | if (point->getFrameNumber() > headFrameNumber) { |
| 1949 | break; |
| 1950 | } |
| 1951 | |
| 1952 | matchingFramesFound = true; |
| 1953 | |
| 1954 | if (!point->frameIsAvailable()) { |
| 1955 | // We haven't notified the remote layer that the frame for |
| 1956 | // this point is available yet. Notify it now, and then |
| 1957 | // abort this attempt to latch. |
| 1958 | point->setFrameAvailable(); |
| 1959 | allTransactionsApplied = false; |
| 1960 | break; |
| 1961 | } |
| 1962 | |
| 1963 | allTransactionsApplied &= point->transactionIsApplied(); |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 1964 | } |
| 1965 | } |
| 1966 | |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 1967 | if (matchingFramesFound && !allTransactionsApplied) { |
| 1968 | mFlinger->signalLayerUpdate(); |
| 1969 | return outDirtyRegion; |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 1972 | // This boolean is used to make sure that SurfaceFlinger's shadow copy |
| 1973 | // of the buffer queue isn't modified when the buffer queue is returning |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 1974 | // BufferItem's that weren't actually queued. This can happen in shared |
Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 1975 | // buffer mode. |
| 1976 | bool queuedBuffer = false; |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 1977 | status_t updateResult = mSurfaceFlingerConsumer->updateTexImage(&r, |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1978 | mFlinger->mPrimaryDispSync, &mAutoRefresh, &queuedBuffer, |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 1979 | mLastFrameNumberReceived); |
Andy McFadden | 1585c4d | 2013-06-28 13:52:40 -0700 | [diff] [blame] | 1980 | if (updateResult == BufferQueue::PRESENT_LATER) { |
| 1981 | // Producer doesn't want buffer to be displayed yet. Signal a |
| 1982 | // layer update so we check again at the next opportunity. |
| 1983 | mFlinger->signalLayerUpdate(); |
| 1984 | return outDirtyRegion; |
Dan Stoza | ecc5040 | 2015-04-28 14:42:06 -0700 | [diff] [blame] | 1985 | } else if (updateResult == SurfaceFlingerConsumer::BUFFER_REJECTED) { |
| 1986 | // If the buffer has been rejected, remove it from the shadow queue |
| 1987 | // and return early |
Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 1988 | if (queuedBuffer) { |
| 1989 | Mutex::Autolock lock(mQueueItemLock); |
| 1990 | mQueueItems.removeAt(0); |
| 1991 | android_atomic_dec(&mQueuedFrames); |
| 1992 | } |
Dan Stoza | ecc5040 | 2015-04-28 14:42:06 -0700 | [diff] [blame] | 1993 | return outDirtyRegion; |
Dan Stoza | 65476f3 | 2015-05-14 09:27:25 -0700 | [diff] [blame] | 1994 | } else if (updateResult != NO_ERROR || mUpdateTexImageFailed) { |
| 1995 | // This can occur if something goes wrong when trying to create the |
| 1996 | // EGLImage for this buffer. If this happens, the buffer has already |
| 1997 | // been released, so we need to clean up the queue and bug out |
| 1998 | // early. |
Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 1999 | if (queuedBuffer) { |
Dan Stoza | 65476f3 | 2015-05-14 09:27:25 -0700 | [diff] [blame] | 2000 | Mutex::Autolock lock(mQueueItemLock); |
| 2001 | mQueueItems.clear(); |
| 2002 | android_atomic_and(0, &mQueuedFrames); |
| 2003 | } |
| 2004 | |
| 2005 | // Once we have hit this state, the shadow queue may no longer |
| 2006 | // correctly reflect the incoming BufferQueue's contents, so even if |
| 2007 | // updateTexImage starts working, the only safe course of action is |
| 2008 | // to continue to ignore updates. |
| 2009 | mUpdateTexImageFailed = true; |
| 2010 | |
| 2011 | return outDirtyRegion; |
Andy McFadden | 1585c4d | 2013-06-28 13:52:40 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 2014 | if (queuedBuffer) { |
| 2015 | // Autolock scope |
Dan Stoza | ecc5040 | 2015-04-28 14:42:06 -0700 | [diff] [blame] | 2016 | auto currentFrameNumber = mSurfaceFlingerConsumer->getFrameNumber(); |
| 2017 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 2018 | Mutex::Autolock lock(mQueueItemLock); |
Dan Stoza | ecc5040 | 2015-04-28 14:42:06 -0700 | [diff] [blame] | 2019 | |
| 2020 | // Remove any stale buffers that have been dropped during |
| 2021 | // updateTexImage |
| 2022 | while (mQueueItems[0].mFrameNumber != currentFrameNumber) { |
| 2023 | mQueueItems.removeAt(0); |
| 2024 | android_atomic_dec(&mQueuedFrames); |
| 2025 | } |
| 2026 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 2027 | mQueueItems.removeAt(0); |
| 2028 | } |
| 2029 | |
Dan Stoza | ecc5040 | 2015-04-28 14:42:06 -0700 | [diff] [blame] | 2030 | |
Andy McFadden | 1585c4d | 2013-06-28 13:52:40 -0700 | [diff] [blame] | 2031 | // Decrement the queued-frames count. Signal another event if we |
| 2032 | // have more frames pending. |
Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 2033 | if ((queuedBuffer && android_atomic_dec(&mQueuedFrames) > 1) |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 2034 | || mAutoRefresh) { |
Andy McFadden | 1585c4d | 2013-06-28 13:52:40 -0700 | [diff] [blame] | 2035 | mFlinger->signalLayerUpdate(); |
| 2036 | } |
| 2037 | |
| 2038 | if (updateResult != NO_ERROR) { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2039 | // something happened! |
| 2040 | recomputeVisibleRegions = true; |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2041 | return outDirtyRegion; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2042 | } |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 2043 | |
Jamie Gennis | 351a513 | 2011-09-14 18:23:37 -0700 | [diff] [blame] | 2044 | // update the active buffer |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 2045 | mActiveBuffer = mSurfaceFlingerConsumer->getCurrentBuffer(); |
Mathias Agopian | e31564d | 2012-05-29 20:41:03 -0700 | [diff] [blame] | 2046 | if (mActiveBuffer == NULL) { |
| 2047 | // this can only happen if the very first buffer was rejected. |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2048 | return outDirtyRegion; |
Mathias Agopian | e31564d | 2012-05-29 20:41:03 -0700 | [diff] [blame] | 2049 | } |
Mathias Agopian | da9584d | 2010-12-13 18:51:59 -0800 | [diff] [blame] | 2050 | |
Mathias Agopian | 4824d40 | 2012-06-04 18:16:30 -0700 | [diff] [blame] | 2051 | mRefreshPending = true; |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 2052 | mFrameLatencyNeeded = true; |
Mathias Agopian | e31564d | 2012-05-29 20:41:03 -0700 | [diff] [blame] | 2053 | if (oldActiveBuffer == NULL) { |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 2054 | // the first time we receive a buffer, we need to trigger a |
| 2055 | // geometry invalidation. |
Andy McFadden | ab10c58 | 2012-09-26 16:19:12 -0700 | [diff] [blame] | 2056 | recomputeVisibleRegions = true; |
Mathias Agopian | 2c8207e | 2012-05-23 17:56:42 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 2059 | Rect crop(mSurfaceFlingerConsumer->getCurrentCrop()); |
| 2060 | const uint32_t transform(mSurfaceFlingerConsumer->getCurrentTransform()); |
| 2061 | const uint32_t scalingMode(mSurfaceFlingerConsumer->getCurrentScalingMode()); |
Mathias Agopian | 702634a | 2012-05-23 17:50:31 -0700 | [diff] [blame] | 2062 | if ((crop != mCurrentCrop) || |
| 2063 | (transform != mCurrentTransform) || |
| 2064 | (scalingMode != mCurrentScalingMode)) |
| 2065 | { |
| 2066 | mCurrentCrop = crop; |
| 2067 | mCurrentTransform = transform; |
| 2068 | mCurrentScalingMode = scalingMode; |
Andy McFadden | ab10c58 | 2012-09-26 16:19:12 -0700 | [diff] [blame] | 2069 | recomputeVisibleRegions = true; |
Mathias Agopian | 702634a | 2012-05-23 17:50:31 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | if (oldActiveBuffer != NULL) { |
Mathias Agopian | e31564d | 2012-05-29 20:41:03 -0700 | [diff] [blame] | 2073 | uint32_t bufWidth = mActiveBuffer->getWidth(); |
| 2074 | uint32_t bufHeight = mActiveBuffer->getHeight(); |
Mathias Agopian | 702634a | 2012-05-23 17:50:31 -0700 | [diff] [blame] | 2075 | if (bufWidth != uint32_t(oldActiveBuffer->width) || |
| 2076 | bufHeight != uint32_t(oldActiveBuffer->height)) { |
Andy McFadden | ab10c58 | 2012-09-26 16:19:12 -0700 | [diff] [blame] | 2077 | recomputeVisibleRegions = true; |
Mathias Agopian | 702634a | 2012-05-23 17:50:31 -0700 | [diff] [blame] | 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format); |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 2082 | if (oldOpacity != isOpaque(s)) { |
Mathias Agopian | 702634a | 2012-05-23 17:50:31 -0700 | [diff] [blame] | 2083 | recomputeVisibleRegions = true; |
| 2084 | } |
| 2085 | |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 2086 | mCurrentFrameNumber = mSurfaceFlingerConsumer->getFrameNumber(); |
| 2087 | |
| 2088 | // Remove any sync points corresponding to the buffer which was just |
| 2089 | // latched |
| 2090 | { |
| 2091 | Mutex::Autolock lock(mLocalSyncPointMutex); |
| 2092 | auto point = mLocalSyncPoints.begin(); |
| 2093 | while (point != mLocalSyncPoints.end()) { |
| 2094 | if (!(*point)->frameIsAvailable() || |
| 2095 | !(*point)->transactionIsApplied()) { |
| 2096 | // This sync point must have been added since we started |
| 2097 | // latching. Don't drop it yet. |
| 2098 | ++point; |
| 2099 | continue; |
| 2100 | } |
| 2101 | |
| 2102 | if ((*point)->getFrameNumber() <= mCurrentFrameNumber) { |
| 2103 | point = mLocalSyncPoints.erase(point); |
| 2104 | } else { |
| 2105 | ++point; |
| 2106 | } |
| 2107 | } |
| 2108 | } |
| 2109 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2110 | // FIXME: postedRegion should be dirty & bounds |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 2111 | Region dirtyRegion(Rect(s.active.w, s.active.h)); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2112 | |
| 2113 | // transform the dirty region to window-manager space |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 2114 | outDirtyRegion = (s.active.transform.transform(dirtyRegion)); |
Mathias Agopian | caa600c | 2009-09-16 18:27:24 -0700 | [diff] [blame] | 2115 | } |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2116 | return outDirtyRegion; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2117 | } |
| 2118 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2119 | uint32_t Layer::getEffectiveUsage(uint32_t usage) const |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 2120 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2121 | // TODO: should we do something special if mSecure is set? |
| 2122 | if (mProtectedByApp) { |
| 2123 | // need a hardware-protected path to external video sink |
| 2124 | usage |= GraphicBuffer::USAGE_PROTECTED; |
Jamie Gennis | 54cc83e | 2010-11-02 11:51:32 -0700 | [diff] [blame] | 2125 | } |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 2126 | if (mPotentialCursor) { |
| 2127 | usage |= GraphicBuffer::USAGE_CURSOR; |
| 2128 | } |
Jamie Gennis | 3599bf2 | 2011-08-10 11:48:07 -0700 | [diff] [blame] | 2129 | usage |= GraphicBuffer::USAGE_HW_COMPOSER; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 2130 | return usage; |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 2131 | } |
| 2132 | |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 2133 | void Layer::updateTransformHint(const sp<const DisplayDevice>& hw) const { |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 2134 | uint32_t orientation = 0; |
| 2135 | if (!mFlinger->mDebugDisableTransformHint) { |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 2136 | // The transform hint is used to improve performance, but we can |
| 2137 | // only have a single transform hint, it cannot |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2138 | // apply to all displays. |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 2139 | const Transform& planeTransform(hw->getTransform()); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 2140 | orientation = planeTransform.getOrientation(); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 2141 | if (orientation & Transform::ROT_INVALID) { |
| 2142 | orientation = 0; |
| 2143 | } |
| 2144 | } |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 2145 | mSurfaceFlingerConsumer->setTransformHint(orientation); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2148 | // ---------------------------------------------------------------------------- |
| 2149 | // debugging |
| 2150 | // ---------------------------------------------------------------------------- |
| 2151 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2152 | void Layer::dump(String8& result, Colorizer& colorizer) const |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2153 | { |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 2154 | const Layer::State& s(getDrawingState()); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2155 | |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2156 | colorizer.colorize(result, Colorizer::GREEN); |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2157 | result.appendFormat( |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2158 | "+ %s %p (%s)\n", |
| 2159 | getTypeId(), this, getName().string()); |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 2160 | colorizer.reset(result); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2161 | |
Mathias Agopian | 2ca7939 | 2013-04-02 18:30:32 -0700 | [diff] [blame] | 2162 | s.activeTransparentRegion.dump(result, "transparentRegion"); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2163 | visibleRegion.dump(result, "visibleRegion"); |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 2164 | surfaceDamageRegion.dump(result, "surfaceDamageRegion"); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2165 | sp<Client> client(mClientRef.promote()); |
| 2166 | |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2167 | result.appendFormat( " " |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 2168 | "layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), " |
| 2169 | "crop=(%4d,%4d,%4d,%4d), finalCrop=(%4d,%4d,%4d,%4d), " |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2170 | "isOpaque=%1d, invalidate=%1d, " |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2171 | #ifdef USE_HWC2 |
| 2172 | "alpha=%.3f, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n" |
| 2173 | #else |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2174 | "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n" |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 2175 | #endif |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2176 | " client=%p\n", |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 2177 | s.layerStack, s.z, s.active.transform.tx(), s.active.transform.ty(), s.active.w, s.active.h, |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 2178 | s.crop.left, s.crop.top, |
| 2179 | s.crop.right, s.crop.bottom, |
| 2180 | s.finalCrop.left, s.finalCrop.top, |
| 2181 | s.finalCrop.right, s.finalCrop.bottom, |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 2182 | isOpaque(s), contentDirty, |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2183 | s.alpha, s.flags, |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 2184 | s.active.transform[0][0], s.active.transform[0][1], |
| 2185 | s.active.transform[1][0], s.active.transform[1][1], |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2186 | client.get()); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2187 | |
| 2188 | sp<const GraphicBuffer> buf0(mActiveBuffer); |
| 2189 | uint32_t w0=0, h0=0, s0=0, f0=0; |
| 2190 | if (buf0 != 0) { |
| 2191 | w0 = buf0->getWidth(); |
| 2192 | h0 = buf0->getHeight(); |
| 2193 | s0 = buf0->getStride(); |
| 2194 | f0 = buf0->format; |
| 2195 | } |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2196 | result.appendFormat( |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2197 | " " |
| 2198 | "format=%2d, activeBuffer=[%4ux%4u:%4u,%3X]," |
| 2199 | " queued-frames=%d, mRefreshPending=%d\n", |
| 2200 | mFormat, w0, h0, s0,f0, |
| 2201 | mQueuedFrames, mRefreshPending); |
| 2202 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2203 | if (mSurfaceFlingerConsumer != 0) { |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 2204 | mSurfaceFlingerConsumer->dump(result, " "); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 2208 | void Layer::dumpFrameStats(String8& result) const { |
| 2209 | mFrameTracker.dumpStats(result); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2210 | } |
| 2211 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 2212 | void Layer::clearFrameStats() { |
| 2213 | mFrameTracker.clearStats(); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2214 | } |
| 2215 | |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 2216 | void Layer::logFrameStats() { |
| 2217 | mFrameTracker.logAndResetStats(mName); |
| 2218 | } |
| 2219 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 2220 | void Layer::getFrameStats(FrameStats* outStats) const { |
| 2221 | mFrameTracker.getStats(outStats); |
| 2222 | } |
| 2223 | |
Pablo Ceballos | 40845df | 2016-01-25 17:41:15 -0800 | [diff] [blame] | 2224 | void Layer::getFenceData(String8* outName, uint64_t* outFrameNumber, |
| 2225 | bool* outIsGlesComposition, nsecs_t* outPostedTime, |
| 2226 | sp<Fence>* outAcquireFence, sp<Fence>* outPrevReleaseFence) const { |
| 2227 | *outName = mName; |
| 2228 | *outFrameNumber = mSurfaceFlingerConsumer->getFrameNumber(); |
| 2229 | |
| 2230 | #ifdef USE_HWC2 |
| 2231 | *outIsGlesComposition = mHwcLayers.count(HWC_DISPLAY_PRIMARY) ? |
| 2232 | mHwcLayers.at(HWC_DISPLAY_PRIMARY).compositionType == |
| 2233 | HWC2::Composition::Client : true; |
| 2234 | #else |
| 2235 | *outIsGlesComposition = mIsGlesComposition; |
| 2236 | #endif |
| 2237 | *outPostedTime = mSurfaceFlingerConsumer->getTimestamp(); |
| 2238 | *outAcquireFence = mSurfaceFlingerConsumer->getCurrentFence(); |
| 2239 | *outPrevReleaseFence = mSurfaceFlingerConsumer->getPrevReleaseFence(); |
| 2240 | } |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 2241 | |
| 2242 | std::vector<OccupancyTracker::Segment> Layer::getOccupancyHistory( |
| 2243 | bool forceFlush) { |
| 2244 | std::vector<OccupancyTracker::Segment> history; |
| 2245 | status_t result = mSurfaceFlingerConsumer->getOccupancyHistory(forceFlush, |
| 2246 | &history); |
| 2247 | if (result != NO_ERROR) { |
| 2248 | ALOGW("[%s] Failed to obtain occupancy history (%d)", mName.string(), |
| 2249 | result); |
| 2250 | return {}; |
| 2251 | } |
| 2252 | return history; |
| 2253 | } |
| 2254 | |
Robert Carr | 367c568 | 2016-06-20 11:55:28 -0700 | [diff] [blame] | 2255 | bool Layer::getTransformToDisplayInverse() const { |
| 2256 | return mSurfaceFlingerConsumer->getTransformToDisplayInverse(); |
| 2257 | } |
| 2258 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2259 | // --------------------------------------------------------------------------- |
| 2260 | |
| 2261 | Layer::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger, |
| 2262 | const sp<Layer>& layer) |
| 2263 | : mFlinger(flinger), mLayer(layer) { |
| 2264 | } |
| 2265 | |
| 2266 | Layer::LayerCleaner::~LayerCleaner() { |
| 2267 | // destroy client resources |
| 2268 | mFlinger->onLayerDestroyed(mLayer); |
| 2269 | } |
| 2270 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2271 | // --------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2272 | }; // namespace android |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 2273 | |
| 2274 | #if defined(__gl_h_) |
| 2275 | #error "don't include gl/gl.h in this file" |
| 2276 | #endif |
| 2277 | |
| 2278 | #if defined(__gl2_h_) |
| 2279 | #error "don't include gl2/gl2.h in this file" |
| 2280 | #endif |