1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
/*
* Copyright 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <optional>
#include <ostream>
#include <unordered_set>
#include "ui/LayerStack.h"
// TODO(b/129481165): remove the #pragma below and fix conversion issues
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconversion"
#pragma clang diagnostic ignored "-Wextra"
#include <renderengine/LayerSettings.h>
// TODO(b/129481165): remove the #pragma below and fix conversion issues
#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
#include <ftl/future.h>
#include <ui/FenceResult.h>
#include <utils/RefBase.h>
#include <utils/Timers.h>
namespace android {
class Fence;
namespace gui {
struct LayerMetadata;
}
namespace compositionengine {
struct LayerFECompositionState;
// Defines the interface used by the CompositionEngine to make requests
// of the front-end layer
class LayerFE : public virtual RefBase {
public:
// Gets the raw front-end composition state data for the layer
virtual const LayerFECompositionState* getCompositionState() const = 0;
// Called before composition starts. Should return true if this layer has
// pending updates which would require an extra display refresh cycle to
// process.
virtual bool onPreComposition(nsecs_t refreshStartTime,
bool updatingOutputGeometryThisFrame) = 0;
struct ClientCompositionTargetSettings {
enum class BlurSetting {
Disabled,
BackgroundBlurOnly,
BlurRegionsOnly,
Enabled,
};
friend std::string toString(BlurSetting blurSetting) {
switch (blurSetting) {
case BlurSetting::Enabled:
return "Enabled";
case BlurSetting::BlurRegionsOnly:
return "BlurRegionsOnly";
case BlurSetting::BackgroundBlurOnly:
return "BackgroundBlurOnly";
case BlurSetting::Disabled:
return "Disabled";
}
}
friend std::ostream& operator<<(std::ostream& os, const BlurSetting& setting) {
return os << toString(setting);
}
// The clip region, or visible region that is being rendered to
const Region& clip;
// If set to true, the layer should enable filtering when rendering.
const bool needsFiltering;
// If set to true, the buffer is being sent to a destination that is
// expected to treat the buffer contents as secure.
const bool isSecure;
// If set to true, the target buffer has protected content support.
const bool isProtected;
// Viewport of the target being rendered to. This is used to determine
// the shadow light position.
const Rect& viewport;
// Dataspace of the output so we can optimize how to render the shadow
// by avoiding unnecessary color space conversions.
const ui::Dataspace dataspace;
// True if the region excluding the shadow is visible.
const bool realContentIsVisible;
// If set to true, change the layer settings to render a clear output.
// This may be requested by the HWC
const bool clearContent;
// Configure layer settings for using blurs
BlurSetting blurSetting;
// Requested white point of the layer in nits
const float whitePointNits;
// True if layers with 170M dataspace should be overridden to sRGB.
const bool treat170mAsSrgb;
};
// A superset of LayerSettings required by RenderEngine to compose a layer
// and buffer info to determine duplicate client composition requests.
struct LayerSettings : renderengine::LayerSettings {
// Currently latched buffer if, 0 if invalid.
uint64_t bufferId = 0;
// Currently latched frame number, 0 if invalid.
uint64_t frameNumber = 0;
};
// Returns the LayerSettings to pass to RenderEngine::drawLayers. The state may contain shadows
// casted by the layer or the content of the layer itself. If the layer does not render then an
// empty optional will be returned.
virtual std::optional<LayerSettings> prepareClientComposition(
ClientCompositionTargetSettings&) const = 0;
// Called after the layer is displayed to update the presentation fence
virtual void onLayerDisplayed(ftl::SharedFuture<FenceResult>, ui::LayerStack layerStack) = 0;
// Gets some kind of identifier for the layer for debug purposes.
virtual const char* getDebugName() const = 0;
// Gets the sequence number: a serial number that uniquely identifies a Layer
virtual int32_t getSequence() const = 0;
// Whether the layer should be rendered with rounded corners.
virtual bool hasRoundedCorners() const = 0;
virtual void setWasClientComposed(const sp<Fence>&) {}
virtual const gui::LayerMetadata* getMetadata() const = 0;
virtual const gui::LayerMetadata* getRelativeMetadata() const = 0;
};
// TODO(b/121291683): Specialize std::hash<> for sp<T> so these and others can
// be removed.
struct LayerFESpHash {
size_t operator()(const sp<LayerFE>& p) const { return std::hash<LayerFE*>()(p.get()); }
};
using LayerFESet = std::unordered_set<sp<LayerFE>, LayerFESpHash>;
static inline bool operator==(const LayerFE::ClientCompositionTargetSettings& lhs,
const LayerFE::ClientCompositionTargetSettings& rhs) {
return lhs.clip.hasSameRects(rhs.clip) && lhs.needsFiltering == rhs.needsFiltering &&
lhs.isSecure == rhs.isSecure && lhs.isProtected == rhs.isProtected &&
lhs.viewport == rhs.viewport && lhs.dataspace == rhs.dataspace &&
lhs.realContentIsVisible == rhs.realContentIsVisible &&
lhs.clearContent == rhs.clearContent;
}
static inline bool operator==(const LayerFE::LayerSettings& lhs,
const LayerFE::LayerSettings& rhs) {
return static_cast<const renderengine::LayerSettings&>(lhs) ==
static_cast<const renderengine::LayerSettings&>(rhs) &&
lhs.bufferId == rhs.bufferId && lhs.frameNumber == rhs.frameNumber;
}
// Defining PrintTo helps with Google Tests.
static inline void PrintTo(const LayerFE::ClientCompositionTargetSettings& settings,
::std::ostream* os) {
*os << "ClientCompositionTargetSettings{";
*os << "\n .clip = \n";
PrintTo(settings.clip, os);
*os << "\n .needsFiltering = " << settings.needsFiltering;
*os << "\n .isSecure = " << settings.isSecure;
*os << "\n .isProtected = " << settings.isProtected;
*os << "\n .viewport = ";
PrintTo(settings.viewport, os);
*os << "\n .dataspace = ";
PrintTo(settings.dataspace, os);
*os << "\n .realContentIsVisible = " << settings.realContentIsVisible;
*os << "\n .clearContent = " << settings.clearContent;
*os << "\n .blurSetting = " << settings.blurSetting;
*os << "\n}";
}
static inline void PrintTo(const LayerFE::LayerSettings& settings, ::std::ostream* os) {
*os << "LayerFE::LayerSettings{";
PrintTo(static_cast<const renderengine::LayerSettings&>(settings), os);
*os << "\n .bufferId = " << settings.bufferId;
*os << "\n .frameNumber = " << settings.frameNumber;
*os << "\n}";
}
} // namespace compositionengine
} // namespace android
|