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