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