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