Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 | |
| 17 | #include <ui/GraphicTypes.h> |
| 18 | #include <ui/Transform.h> |
| 19 | |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 20 | #include "DisplayDevice.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 21 | #include "FrontEnd/LayerCreationArgs.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 22 | #include "Layer.h" |
| 23 | #include "LayerRenderArea.h" |
| 24 | #include "SurfaceFlinger.h" |
| 25 | |
| 26 | namespace android { |
| 27 | namespace { |
| 28 | |
Robert Carr | 22ceeaa | 2022-03-08 13:13:22 -0800 | [diff] [blame] | 29 | void reparentForDrawing(const sp<Layer>& oldParent, const sp<Layer>& newParent, |
| 30 | const Rect& drawingBounds) { |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 31 | // Compute and cache the bounds for the new parent layer. |
| 32 | newParent->computeBounds(drawingBounds.toFloatRect(), ui::Transform(), |
Robert Carr | 22ceeaa | 2022-03-08 13:13:22 -0800 | [diff] [blame] | 33 | 0.f /* shadowRadius */); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 34 | newParent->updateSnapshot(true /* updateGeometry */); |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 35 | oldParent->setChildrenDrawingParent(newParent); |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | } // namespace |
| 39 | |
| 40 | LayerRenderArea::LayerRenderArea(SurfaceFlinger& flinger, sp<Layer> layer, const Rect& crop, |
| 41 | ui::Size reqSize, ui::Dataspace reqDataSpace, bool childrenOnly, |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame^] | 42 | bool allowSecureLayers, const ui::Transform& layerTransform, |
| 43 | const Rect& layerBufferSize) |
Patrick Williams | 278a88f | 2023-01-27 16:52:40 -0600 | [diff] [blame] | 44 | : RenderArea(reqSize, CaptureFill::CLEAR, reqDataSpace, allowSecureLayers), |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 45 | mLayer(std::move(layer)), |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame^] | 46 | mLayerTransform(layerTransform), |
| 47 | mLayerBufferSize(layerBufferSize), |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 48 | mCrop(crop), |
| 49 | mFlinger(flinger), |
| 50 | mChildrenOnly(childrenOnly) {} |
| 51 | |
| 52 | const ui::Transform& LayerRenderArea::getTransform() const { |
| 53 | return mTransform; |
| 54 | } |
| 55 | |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 56 | bool LayerRenderArea::isSecure() const { |
chaviw | 70cb6a4 | 2020-07-30 13:57:36 -0700 | [diff] [blame] | 57 | return mAllowSecureLayers; |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 58 | } |
| 59 | |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 60 | sp<const DisplayDevice> LayerRenderArea::getDisplayDevice() const { |
| 61 | return nullptr; |
| 62 | } |
| 63 | |
| 64 | Rect LayerRenderArea::getSourceCrop() const { |
| 65 | if (mCrop.isEmpty()) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame^] | 66 | // TODO this should probably be mBounds instead of just buffer bounds |
| 67 | return mLayerBufferSize; |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 68 | } else { |
| 69 | return mCrop; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | void LayerRenderArea::render(std::function<void()> drawLayers) { |
| 74 | using namespace std::string_literals; |
| 75 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 76 | if (!mChildrenOnly) { |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame^] | 77 | mTransform = mLayerTransform.inverse(); |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | if (mFlinger.mLayerLifecycleManagerEnabled) { |
| 81 | drawLayers(); |
| 82 | return; |
| 83 | } |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 84 | // If layer is offscreen, update mirroring info if it exists |
| 85 | if (mLayer->isRemovedFromCurrentState()) { |
| 86 | mLayer->traverse(LayerVector::StateSet::Drawing, |
| 87 | [&](Layer* layer) { layer->updateMirrorInfo(); }); |
| 88 | mLayer->traverse(LayerVector::StateSet::Drawing, |
| 89 | [&](Layer* layer) { layer->updateCloneBufferInfo(); }); |
| 90 | } |
| 91 | |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 92 | if (!mChildrenOnly) { |
chaviw | 79468ab | 2021-10-27 11:11:24 -0500 | [diff] [blame] | 93 | // If the layer is offscreen, compute bounds since we don't compute bounds for offscreen |
| 94 | // layers in a regular cycles. |
| 95 | if (mLayer->isRemovedFromCurrentState()) { |
| 96 | FloatRect maxBounds = mFlinger.getMaxDisplayBounds(); |
| 97 | mLayer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */); |
| 98 | } |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 99 | drawLayers(); |
| 100 | } else { |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 101 | // In the "childrenOnly" case we reparent the children to a screenshot |
| 102 | // layer which has no properties set and which does not draw. |
Robert Carr | 22ceeaa | 2022-03-08 13:13:22 -0800 | [diff] [blame] | 103 | // We hold the statelock as the reparent-for-drawing operation modifies the |
| 104 | // hierarchy and there could be readers on Binder threads, like dump. |
Patrick Williams | 46b61b9 | 2022-09-01 17:25:49 +0000 | [diff] [blame] | 105 | auto screenshotParentLayer = mFlinger.getFactory().createEffectLayer( |
Vishnu Nair | b21272e | 2022-07-01 22:47:33 +0000 | [diff] [blame] | 106 | {&mFlinger, nullptr, "Screenshot Parent"s, ISurfaceComposerClient::eNoColorFill, |
| 107 | LayerMetadata()}); |
Robert Carr | 22ceeaa | 2022-03-08 13:13:22 -0800 | [diff] [blame] | 108 | { |
| 109 | Mutex::Autolock _l(mFlinger.mStateLock); |
Patrick Williams | 278a88f | 2023-01-27 16:52:40 -0600 | [diff] [blame] | 110 | reparentForDrawing(mLayer, screenshotParentLayer, getSourceCrop()); |
Robert Carr | 22ceeaa | 2022-03-08 13:13:22 -0800 | [diff] [blame] | 111 | } |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 112 | drawLayers(); |
Robert Carr | 22ceeaa | 2022-03-08 13:13:22 -0800 | [diff] [blame] | 113 | { |
| 114 | Mutex::Autolock _l(mFlinger.mStateLock); |
| 115 | mLayer->setChildrenDrawingParent(mLayer); |
| 116 | } |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | } // namespace android |