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