blob: 0b94fdb3ef812998db1d70d916f413630b940b10 [file]
/*
* 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 <cstdint>
#include <android/gui/BorderSettings.h>
#include <android/gui/BoxShadowSettings.h>
#include <android/gui/CachingHint.h>
#include <android/gui/ISystemContentPriorityConstants.h>
#include <common/LayerFilter.h>
#include <gui/DisplayLuts.h>
#include <gui/HdrMetadata.h>
#include <include/private/SkHdrMetadata.h>
#include <math/mat4.h>
#include <ui/BlurRegion.h>
#include <ui/FloatRect.h>
#include <ui/LayerStack.h>
#include <ui/PictureProfileHandle.h>
#include <ui/Rect.h>
#include <ui/Region.h>
#include <ui/ShadowSettings.h>
#include <ui/Transform.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 <gui/BufferQueue.h>
#include <ui/EdgeExtensionEffect.h>
#include <ui/GraphicBuffer.h>
#include <ui/GraphicTypes.h>
#include <ui/StretchEffect.h>
#include "DisplayHardware/Hal.h"
#include "Tracking/Trackers.h"
#include <aidl/android/hardware/graphics/composer3/Composition.h>
// TODO(b/129481165): remove the #pragma below and fix conversion issues
#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
namespace android::compositionengine {
namespace hal = android::hardware::graphics::composer::hal;
// More complex metadata for this layer
struct GenericLayerMetadataEntry {
// True if the metadata may affect the composed result.
// See setLayerGenericMetadata in IComposerClient.hal
bool mandatory;
// Byte blob or parcel
std::vector<uint8_t> value;
std::string dumpAsString() const;
struct Hasher {
size_t operator()(const GenericLayerMetadataEntry& entry) const {
size_t hash = 0;
for (const auto value : entry.value) {
hashCombineSingleHashed(hash, value);
}
return hash;
}
};
};
inline bool operator==(const GenericLayerMetadataEntry& lhs, const GenericLayerMetadataEntry& rhs) {
return lhs.mandatory == rhs.mandatory && lhs.value == rhs.value;
}
// Defining PrintTo helps with Google Tests.
inline void PrintTo(const GenericLayerMetadataEntry& v, ::std::ostream* os) {
*os << v.dumpAsString();
}
using GenericLayerMetadataMap = std::unordered_map<std::string, GenericLayerMetadataEntry>;
class UnboundedSupportFloatRect {
public:
UnboundedSupportFloatRect() : mIsUnbounded(true) {}
explicit UnboundedSupportFloatRect(const FloatRect& rect) : mValue(rect), mIsUnbounded(false) {}
bool isUnbounded() const { return mIsUnbounded.get(); }
FloatRect toFloatRect() const {
return mIsUnbounded.get() ? mUnboundedValue.get() : mValue.get();
}
void setValue(const FloatRect& rect) {
mValue = rect;
mIsUnbounded = false;
}
void setUnboundedValue(const FloatRect& unboundedValue) {
mIsUnbounded = true;
mUnboundedValue = unboundedValue;
}
std::string toString() const {
if (isUnbounded()) {
return "unbounded";
}
return toFloatRect().toString();
}
// Allow UnboundedSupportFloatRect to be used where FloatRect is expected.
//
// Example:
//
// void floatRectConsumer(const FloatRect& rect);
// UnboundedSupportFloatRect unboundedSupportFloatRect;
// floatRectConsumer(unboundedSupportFloatRect)
operator FloatRect() const {
return toFloatRect();
}
// Allow UnboundedSupportFloatRect to be assigned from FloatRect.
//
// Example:
//
// UnboundedSupportFloatRect unbounded = floatRect;
UnboundedSupportFloatRect& operator=(const FloatRect& rect) {
setValue(rect);
return *this;
}
UnboundedSupportFloatRect intersect(const UnboundedSupportFloatRect& other) const {
FloatRect intersectedRect = toFloatRect().intersect(other.toFloatRect());
if (isUnbounded() && other.isUnbounded()) {
UnboundedSupportFloatRect result;
result.setUnboundedValue(intersectedRect);
return result;
} else {
return UnboundedSupportFloatRect(intersectedRect);
}
}
UnboundedSupportFloatRect intersect(const FloatRect& other) const {
return UnboundedSupportFloatRect(toFloatRect().intersect(other));
}
private:
TrackedPrimitive<FloatRect, TrackedField::kBounds> mValue;
TrackedPrimitive<FloatRect, TrackedField::kBounds> mUnboundedValue{kDefaultUnboundedRect};
TrackedPrimitive<bool, TrackedField::kBounds> mIsUnbounded{true};
static constexpr FloatRect kDefaultUnboundedRect = {-50000.f, -50000.f, 50000.f, 50000.f};
};
/*
* Used by LayerFE::getCompositionState
* Note that fields that affect HW composer state may need to be mirrored into
* android::compositionengine::impl::planner::LayerState
*/
struct LayerFECompositionState {
// If set to true, forces client composition on all output layers until
// the next geometry change.
bool forceClientComposition{false};
// TODO(b/121291683): Reorganize and rename the contents of this structure
/*
* Visibility state
*/
// The filter that determines which outputs include this layer
TrackedLayerFilter<TrackedField::kLayerStack> outputFilter;
// If false, this layer should not be considered visible
bool isVisible{true};
// True if the layer is completely opaque
bool isOpaque{true};
// If true, invalidates the entire visible region
TrackedPrimitive<bool, TrackedField::kInvalidate> contentDirty{false};
// The alpha value for this layer
float alpha{1.f};
// Background blur in pixels
TrackedPrimitive<int, TrackedField::kBackgroundBlurRadius> backgroundBlurRadius{0};
// Background blur content scale factor, between 0.0 and 1.0
float backgroundBlurScale{1.0f};
// If true, the layer is sampling the background (e.g. for post-processing)
bool isTextureSamplingBehind{false};
// The transform from layer local coordinates to composition coordinates
TrackedTransform<TrackedField::kPosition, TrackedField::kTransform> geomLayerTransform;
// The inverse of the layer transform
ui::Transform geomInverseLayerTransform;
// The hint from the layer producer as to what portion of the layer is
// transparent.
Region transparentRegionHint;
virtual Region getOpaqueRegion() const;
// The blend mode for this layer
hal::BlendMode blendMode{hal::BlendMode::INVALID};
// The bounds of the layer in layer local coordinates
UnboundedSupportFloatRect geomLayerBounds;
// The crop to apply to the layer in layer local coordinates
UnboundedSupportFloatRect geomLayerCrop;
ShadowSettings shadowSettings;
// The settings to configure the outline of a layer.
gui::BorderSettings borderSettings;
// The settings to configure box shadows of a layer.
gui::BoxShadowSettings boxShadowSettings;
// List of regions that require blur
std::vector<BlurRegion> blurRegions;
StretchEffect stretchEffect;
EdgeExtensionEffect edgeExtensionEffect;
/*
* Geometry state
*/
bool isSecure{false};
bool geomUsesSourceCrop{false};
bool geomBufferUsesDisplayInverseTransform{false};
uint32_t geomBufferTransform{0};
Rect geomBufferSize;
Rect geomContentCrop;
FloatRect geomCrop;
GenericLayerMetadataMap metadata;
/*
* Per-frame content
*/
// The type of composition for this layer
aidl::android::hardware::graphics::composer3::Composition compositionType{
aidl::android::hardware::graphics::composer3::Composition::INVALID};
// The buffer and related state
sp<GraphicBuffer> buffer;
sp<Fence> acquireFence = Fence::NO_FENCE;
TrackedRegion<TrackedField::kDamageRegion> surfaceDamage;
uint64_t frameNumber = 0;
// Most recent frameId for the RenderCommandBuffer path when using
// compositor side rendering. Mostly passed through here as a way to
// check diffs when caching.
uint64_t renderCommandBufferFrameId = 0;
// The handle to use for a sideband stream for this layer
sp<NativeHandle> sidebandStream;
// If true, this sideband layer has a frame update
bool sidebandStreamHasFrame{false};
// The color for this layer
TrackedColor<TrackedField::kColor> color;
/*
* Per-frame presentation state
*/
// If true, this layer will use the dataspace chosen for the output and
// ignore the dataspace value just below
bool isColorspaceAgnostic{false};
// The dataspace for this layer
TrackedPrimitive<ui::Dataspace, TrackedField::kDataspace> dataspace{ui::Dataspace::UNKNOWN};
// The metadata for this layer
HdrMetadata hdrMetadata;
// The color transform
TrackedPrimitive<mat4, TrackedField::kColorTransform> colorTransform;
bool colorTransformIsIdentity{true};
// True if the layer has protected content
TrackedPrimitive<bool, TrackedField::kIsProtected> hasProtectedContent{false};
/*
* Cursor state
*/
// The output-independent frame for the cursor
Rect cursorFrame;
// framerate of the layer as measured by LayerHistory
float fps;
// The dimming flag
bool dimmingEnabled{true};
float currentHdrSdrRatio = 1.f;
float desiredHdrSdrRatio = 0.f;
std::optional<skhdr::AdaptiveGlobalToneMap> agtm;
// A picture profile handle refers to a PictureProfile configured on the display, which is a
// set of parameters that configures the picture processing hardware that is used to enhance
// the quality of buffer contents.
PictureProfileHandle pictureProfileHandle{PictureProfileHandle::NONE};
// A layer's priority in terms of limited picture processing pipeline utilization.
int64_t pictureProfilePriority;
gui::CachingHint cachingHint = gui::CachingHint::Enabled;
int32_t systemContentPriority = gui::ISystemContentPriorityConstants::Unset;
std::shared_ptr<gui::DisplayLuts> luts;
uint64_t permissions = 0;
virtual ~LayerFECompositionState();
// Debugging
virtual void dump(std::string& out) const;
FloatRect outsetRectForShadow(const FloatRect& input) const {
FloatRect output = input;
// RenderEngine currently blurs shadows to smooth out edges, so outset by
// 2x the length instead of 1x to compensate
float outset = shadowSettings.length * 2;
// Stroke antialiasing should never add more than 2 pixels.
if (borderSettings.strokeWidth > 0) {
outset = std::max(outset, borderSettings.strokeWidth + 2);
}
output.left -= outset;
output.top -= outset;
output.right += outset;
output.bottom += outset;
for (const gui::BoxShadowSettings::BoxShadowParams& boxShadow :
boxShadowSettings.boxShadows) {
float radius = convertBlurSigmaToKernelRadius(
convertBlurUserRadiusToSigma(boxShadow.blurRadius)) +
boxShadow.spreadRadius;
float shadowLeft = input.left + boxShadow.offsetX - radius;
float shadowTop = input.top + boxShadow.offsetY - radius;
float shadowRight = input.right + boxShadow.offsetX + radius;
float shadowBottom = input.bottom + boxShadow.offsetY + radius;
output.left = std::min(shadowLeft, output.left);
output.top = std::min(shadowTop, output.top);
output.right = std::max(shadowRight, output.right);
output.bottom = std::max(shadowBottom, output.bottom);
}
return output;
}
};
} // namespace android::compositionengine