Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f41d4af5 authored by Angel Aguayo's avatar Angel Aguayo Committed by Android (Google) Code Review
Browse files

Merge "Changed ProjectionSpace struct to a class with getters Bug:186475872...

Merge "Changed ProjectionSpace struct to a class with getters Bug:186475872 Test: atest ProjectionSpaceTest"
parents 829c1976 b084e0c8
Loading
Loading
Loading
Loading
+47 −32
Original line number Diff line number Diff line
@@ -28,51 +28,36 @@ namespace compositionengine {

// Geometrical space to which content is projected.
// For example, this can be the layer space or the physical display space.
struct ProjectionSpace {
class ProjectionSpace {
public:
    ProjectionSpace() = default;
    ProjectionSpace(ui::Size size, Rect content)
          : bounds(std::move(size)), content(std::move(content)) {}

    // Bounds of this space. Always starts at (0,0).
    Rect bounds;

    // Rect onto which content is projected.
    Rect content;

    // The orientation of this space. This value is meaningful only in relation to the rotation
    // of another projection space and it's used to determine the rotating transformation when
    // mapping between the two.
    // As a convention when using this struct orientation = 0 for the "oriented*" projection
    // spaces. For example when the display is rotated 90 degress counterclockwise, the orientation
    // of the display space will become 90, while  the orientation of the layer stack space will
    // remain the same.
    ui::Rotation orientation = ui::ROTATION_0;
    ProjectionSpace(ui::Size size, Rect content) : mBounds(size), mContent(std::move(content)) {}

    // Returns a transform which maps this.content into destination.content
    // and also rotates according to this.orientation and destination.orientation
    ui::Transform getTransform(const ProjectionSpace& destination) const {
        ui::Rotation rotation = destination.orientation - orientation;
        ui::Rotation rotation = destination.getOrientation() - mOrientation;

        // Compute a transformation which rotates the destination in a way it has the same
        // orientation as us.
        const uint32_t inverseRotationFlags = ui::Transform::toRotationFlags(-rotation);
        ui::Transform inverseRotatingTransform;
        inverseRotatingTransform.set(inverseRotationFlags, destination.bounds.width(),
                                     destination.bounds.height());
        inverseRotatingTransform.set(inverseRotationFlags, destination.getBounds().width,
                                     destination.getBounds().height);
        // The destination content rotated so it has the same orientation as us.
        Rect orientedDestContent = inverseRotatingTransform.transform(destination.content);
        Rect orientedDestContent = inverseRotatingTransform.transform(destination.getContent());

        // Compute translation from the source content to (0, 0).
        const float sourceX = content.left;
        const float sourceY = content.top;
        const float sourceX = mContent.left;
        const float sourceY = mContent.top;
        ui::Transform sourceTranslation;
        sourceTranslation.set(-sourceX, -sourceY);

        // Compute scaling transform which maps source content to destination content, assuming
        // they are both at (0, 0).
        ui::Transform scale;
        const float scaleX = static_cast<float>(orientedDestContent.width()) / content.width();
        const float scaleY = static_cast<float>(orientedDestContent.height()) / content.height();
        const float scaleX = static_cast<float>(orientedDestContent.width()) / mContent.width();
        const float scaleY = static_cast<float>(orientedDestContent.height()) / mContent.height();
        scale.set(scaleX, 0, 0, scaleY);

        // Compute translation from (0, 0) to the orientated destination content.
@@ -83,8 +68,8 @@ struct ProjectionSpace {

        // Compute rotation transform.
        const uint32_t orientationFlags = ui::Transform::toRotationFlags(rotation);
        auto orientedDestWidth = destination.bounds.width();
        auto orientedDestHeight = destination.bounds.height();
        auto orientedDestWidth = destination.getBounds().width;
        auto orientedDestHeight = destination.getBounds().height;
        if (rotation == ui::ROTATION_90 || rotation == ui::ROTATION_270) {
            std::swap(orientedDestWidth, orientedDestHeight);
        }
@@ -98,9 +83,39 @@ struct ProjectionSpace {
    }

    bool operator==(const ProjectionSpace& other) const {
        return bounds == other.bounds && content == other.content &&
                orientation == other.orientation;
        return mBounds == other.mBounds && mContent == other.mContent &&
                mOrientation == other.mOrientation;
    }

    void setBounds(ui::Size newBounds) { mBounds = std::move(newBounds); }

    void setContent(Rect newContent) { mContent = std::move(newContent); }

    void setOrientation(ui::Rotation newOrientation) { mOrientation = newOrientation; }

    Rect getBoundsAsRect() const { return Rect(mBounds.getWidth(), mBounds.getHeight()); }

    const ui::Size& getBounds() const { return mBounds; }

    const Rect& getContent() const { return mContent; }

    ui::Rotation getOrientation() const { return mOrientation; }

private:
    // Bounds of this space. Always starts at (0,0).
    ui::Size mBounds = ui::Size();

    // Rect onto which content is projected.
    Rect mContent = Rect();

    // The orientation of this space. This value is meaningful only in relation to the rotation
    // of another projection space and it's used to determine the rotating transformation when
    // mapping between the two.
    // As a convention when using this struct orientation = 0 for the "oriented*" projection
    // spaces. For example when the display is rotated 90 degress counterclockwise, the orientation
    // of the display space will become 90, while  the orientation of the layer stack space will
    // remain the same.
    ui::Rotation mOrientation = ui::ROTATION_0;
};

} // namespace compositionengine
@@ -108,8 +123,8 @@ struct ProjectionSpace {
inline std::string to_string(const android::compositionengine::ProjectionSpace& space) {
    return android::base::
            StringPrintf("ProjectionSpace(bounds = %s, content = %s, orientation = %s)",
                         to_string(space.bounds).c_str(), to_string(space.content).c_str(),
                         toCString(space.orientation));
                         to_string(space.getBoundsAsRect()).c_str(),
                         to_string(space.getContent()).c_str(), toCString(space.getOrientation()));
}

// Defining PrintTo helps with Google Tests.
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ void Display::setConfiguration(const compositionengine::DisplayCreationArgs& arg
    mId = args.id;
    mPowerAdvisor = args.powerAdvisor;
    editState().isSecure = args.isSecure;
    editState().displaySpace.bounds = Rect(args.pixels);
    editState().displaySpace.setBounds(args.pixels);
    setName(args.name);
}

+33 −31
Original line number Diff line number Diff line
@@ -156,38 +156,40 @@ void Output::setProjection(ui::Rotation orientation, const Rect& layerStackSpace
                           const Rect& orientedDisplaySpaceRect) {
    auto& outputState = editState();

    outputState.displaySpace.orientation = orientation;
    LOG_FATAL_IF(outputState.displaySpace.bounds == Rect::INVALID_RECT,
    outputState.displaySpace.setOrientation(orientation);
    LOG_FATAL_IF(outputState.displaySpace.getBoundsAsRect() == Rect::INVALID_RECT,
                 "The display bounds are unknown.");

    // Compute orientedDisplaySpace
    ui::Size orientedSize = outputState.displaySpace.bounds.getSize();
    ui::Size orientedSize = outputState.displaySpace.getBounds();
    if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) {
        std::swap(orientedSize.width, orientedSize.height);
    }
    outputState.orientedDisplaySpace.bounds = Rect(orientedSize);
    outputState.orientedDisplaySpace.content = orientedDisplaySpaceRect;
    outputState.orientedDisplaySpace.setBounds(orientedSize);
    outputState.orientedDisplaySpace.setContent(orientedDisplaySpaceRect);

    // Compute displaySpace.content
    const uint32_t transformOrientationFlags = ui::Transform::toRotationFlags(orientation);
    ui::Transform rotation;
    if (transformOrientationFlags != ui::Transform::ROT_INVALID) {
        const auto displaySize = outputState.displaySpace.bounds;
        const auto displaySize = outputState.displaySpace.getBoundsAsRect();
        rotation.set(transformOrientationFlags, displaySize.width(), displaySize.height());
    }
    outputState.displaySpace.content = rotation.transform(orientedDisplaySpaceRect);
    outputState.displaySpace.setContent(rotation.transform(orientedDisplaySpaceRect));

    // Compute framebufferSpace
    outputState.framebufferSpace.orientation = orientation;
    LOG_FATAL_IF(outputState.framebufferSpace.bounds == Rect::INVALID_RECT,
    outputState.framebufferSpace.setOrientation(orientation);
    LOG_FATAL_IF(outputState.framebufferSpace.getBoundsAsRect() == Rect::INVALID_RECT,
                 "The framebuffer bounds are unknown.");
    const auto scale =
            getScale(outputState.displaySpace.bounds, outputState.framebufferSpace.bounds);
    outputState.framebufferSpace.content = outputState.displaySpace.content.scale(scale.x, scale.y);
    const auto scale = getScale(outputState.displaySpace.getBoundsAsRect(),
                                outputState.framebufferSpace.getBoundsAsRect());
    outputState.framebufferSpace.setContent(
            outputState.displaySpace.getContent().scale(scale.x, scale.y));

    // Compute layerStackSpace
    outputState.layerStackSpace.content = layerStackSpaceRect;
    outputState.layerStackSpace.bounds = layerStackSpaceRect;
    outputState.layerStackSpace.setContent(layerStackSpaceRect);
    outputState.layerStackSpace.setBounds(
            ui::Size(layerStackSpaceRect.getWidth(), layerStackSpaceRect.getHeight()));

    outputState.transform = outputState.layerStackSpace.getTransform(outputState.displaySpace);
    outputState.needsFiltering = outputState.transform.needsBilinearFiltering();
@@ -200,21 +202,21 @@ void Output::setDisplaySize(const ui::Size& size) {
    auto& state = editState();

    // Update framebuffer space
    const Rect newBounds(size);
    state.framebufferSpace.bounds = newBounds;
    const ui::Size newBounds(size);
    state.framebufferSpace.setBounds(newBounds);

    // Update display space
    state.displaySpace.bounds = newBounds;
    state.displaySpace.setBounds(newBounds);
    state.transform = state.layerStackSpace.getTransform(state.displaySpace);

    // Update oriented display space
    const auto orientation = state.displaySpace.orientation;
    const auto orientation = state.displaySpace.getOrientation();
    ui::Size orientedSize = size;
    if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) {
        std::swap(orientedSize.width, orientedSize.height);
    }
    const Rect newOrientedBounds(orientedSize);
    state.orientedDisplaySpace.bounds = newOrientedBounds;
    const ui::Size newOrientedBounds(orientedSize);
    state.orientedDisplaySpace.setBounds(newOrientedBounds);

    if (mPlanner) {
        mPlanner->setDisplaySize(size);
@@ -349,7 +351,7 @@ compositionengine::RenderSurface* Output::getRenderSurface() const {
void Output::setRenderSurface(std::unique_ptr<compositionengine::RenderSurface> surface) {
    mRenderSurface = std::move(surface);
    const auto size = mRenderSurface->getSize();
    editState().framebufferSpace.bounds = Rect(size);
    editState().framebufferSpace.setBounds(size);
    if (mPlanner) {
        mPlanner->setDisplaySize(size);
    }
@@ -370,7 +372,7 @@ void Output::setRenderSurfaceForTest(std::unique_ptr<compositionengine::RenderSu

Region Output::getDirtyRegion() const {
    const auto& outputState = getState();
    return outputState.dirtyRegion.intersect(outputState.layerStackSpace.content);
    return outputState.dirtyRegion.intersect(outputState.layerStackSpace.getContent());
}

bool Output::includesLayer(ui::LayerFilter filter) const {
@@ -450,7 +452,7 @@ void Output::rebuildLayerStacks(const compositionengine::CompositionRefreshArgs&

    // Compute the resulting coverage for this output, and store it for later
    const ui::Transform& tr = outputState.transform;
    Region undefinedRegion{outputState.displaySpace.bounds};
    Region undefinedRegion{outputState.displaySpace.getBoundsAsRect()};
    undefinedRegion.subtractSelf(tr.transform(coverage.aboveOpaqueLayers));

    outputState.undefinedRegion = undefinedRegion;
@@ -647,7 +649,7 @@ void Output::ensureOutputLayerIfVisible(sp<compositionengine::LayerFE>& layerFE,
    // TODO(b/121291683): Why does this not use visibleRegion? (see outputSpaceVisibleRegion below)
    const auto& outputState = getState();
    Region drawRegion(outputState.transform.transform(visibleNonTransparentRegion));
    drawRegion.andSelf(outputState.displaySpace.bounds);
    drawRegion.andSelf(outputState.displaySpace.getBoundsAsRect());
    if (drawRegion.isEmpty()) {
        return;
    }
@@ -665,7 +667,7 @@ void Output::ensureOutputLayerIfVisible(sp<compositionengine::LayerFE>& layerFE,
    outputLayerState.visibleNonTransparentRegion = visibleNonTransparentRegion;
    outputLayerState.coveredRegion = coveredRegion;
    outputLayerState.outputSpaceVisibleRegion = outputState.transform.transform(
            visibleNonShadowRegion.intersect(outputState.layerStackSpace.content));
            visibleNonShadowRegion.intersect(outputState.layerStackSpace.getContent()));
    outputLayerState.shadowRegion = shadowRegion;
}

@@ -1041,10 +1043,10 @@ std::optional<base::unique_fd> Output::composeSurfaces(
    ALOGV("hasClientComposition");

    renderengine::DisplaySettings clientCompositionDisplay;
    clientCompositionDisplay.physicalDisplay = outputState.framebufferSpace.content;
    clientCompositionDisplay.clip = outputState.layerStackSpace.content;
    clientCompositionDisplay.physicalDisplay = outputState.framebufferSpace.getContent();
    clientCompositionDisplay.clip = outputState.layerStackSpace.getContent();
    clientCompositionDisplay.orientation =
            ui::Transform::toRotationFlags(outputState.displaySpace.orientation);
            ui::Transform::toRotationFlags(outputState.displaySpace.getOrientation());
    clientCompositionDisplay.outputDataspace = mDisplayColorProfile->hasWideColorGamut()
            ? outputState.dataspace
            : ui::Dataspace::UNKNOWN;
@@ -1138,7 +1140,7 @@ std::vector<LayerFE::LayerSettings> Output::generateClientCompositionRequests(
    ALOGV("Rendering client layers");

    const auto& outputState = getState();
    const Region viewportRegion(outputState.layerStackSpace.content);
    const Region viewportRegion(outputState.layerStackSpace.getContent());
    bool firstLayer = true;

    bool disableBlurs = false;
@@ -1201,7 +1203,7 @@ std::vector<LayerFE::LayerSettings> Output::generateClientCompositionRequests(
                                               outputState.needsFiltering,
                                       .isSecure = outputState.isSecure,
                                       .supportsProtectedContent = supportsProtectedContent,
                                       .viewport = outputState.layerStackSpace.content,
                                       .viewport = outputState.layerStackSpace.getContent(),
                                       .dataspace = outputDataspace,
                                       .realContentIsVisible = realContentIsVisible,
                                       .clearContent = !clientComposition,
@@ -1308,7 +1310,7 @@ void Output::renderCachedSets(const CompositionRefreshArgs& refreshArgs) {

void Output::dirtyEntireOutput() {
    auto& outputState = editState();
    outputState.dirtyRegion.set(outputState.displaySpace.bounds);
    outputState.dirtyRegion.set(outputState.displaySpace.getBoundsAsRect());
}

void Output::chooseCompositionStrategy() {
+5 −5
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ Rect OutputLayer::calculateInitialCrop() const {
    FloatRect activeCropFloat =
            reduce(layerState.geomLayerBounds, layerState.transparentRegionHint);

    const Rect& viewport = getOutput().getState().layerStackSpace.content;
    const Rect& viewport = getOutput().getState().layerStackSpace.getContent();
    const ui::Transform& layerTransform = layerState.geomLayerTransform;
    const ui::Transform& inverseLayerTransform = layerState.geomInverseLayerTransform;
    // Transform to screen space.
@@ -136,7 +136,7 @@ FloatRect OutputLayer::calculateOutputSourceCrop() const {
         * buffer
         */
        uint32_t invTransformOrient =
                ui::Transform::toRotationFlags(outputState.displaySpace.orientation);
                ui::Transform::toRotationFlags(outputState.displaySpace.getOrientation());
        // calculate the inverse transform
        if (invTransformOrient & HAL_TRANSFORM_ROT_90) {
            invTransformOrient ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
@@ -192,7 +192,7 @@ Rect OutputLayer::calculateOutputDisplayFrame() const {
    Rect activeCrop = layerState.geomCrop;
    if (!activeCrop.isEmpty() && bufferSize.isValid()) {
        activeCrop = layerTransform.transform(activeCrop);
        if (!activeCrop.intersect(outputState.layerStackSpace.content, &activeCrop)) {
        if (!activeCrop.intersect(outputState.layerStackSpace.getContent(), &activeCrop)) {
            activeCrop.clear();
        }
        activeCrop = inverseLayerTransform.transform(activeCrop, true);
@@ -228,7 +228,7 @@ Rect OutputLayer::calculateOutputDisplayFrame() const {
        geomLayerBounds.bottom += outset;
    }
    Rect frame{layerTransform.transform(reduce(geomLayerBounds, activeTransparentRegion))};
    if (!frame.intersect(outputState.layerStackSpace.content, &frame)) {
    if (!frame.intersect(outputState.layerStackSpace.getContent(), &frame)) {
        frame.clear();
    }
    const ui::Transform displayTransform{outputState.transform};
@@ -628,7 +628,7 @@ void OutputLayer::writeCursorPositionToHWC() const {
    const auto& outputState = getOutput().getState();

    Rect frame = layerFEState->cursorFrame;
    frame.intersect(outputState.layerStackSpace.content, &frame);
    frame.intersect(outputState.layerStackSpace.getContent(), &frame);
    Rect position = outputState.transform.transform(frame);

    if (auto error = hwcLayer->setCursorPosition(position.left, position.top);
+4 −4
Original line number Diff line number Diff line
@@ -159,13 +159,13 @@ void CachedSet::updateAge(std::chrono::steady_clock::time_point now) {
void CachedSet::render(renderengine::RenderEngine& renderEngine, TexturePool& texturePool,
                       const OutputCompositionState& outputState) {
    ATRACE_CALL();
    const Rect& viewport = outputState.layerStackSpace.content;
    const Rect& viewport = outputState.layerStackSpace.getContent();
    const ui::Dataspace& outputDataspace = outputState.dataspace;
    const ui::Transform::RotationFlags orientation =
            ui::Transform::toRotationFlags(outputState.framebufferSpace.orientation);
            ui::Transform::toRotationFlags(outputState.framebufferSpace.getOrientation());

    renderengine::DisplaySettings displaySettings{
            .physicalDisplay = outputState.framebufferSpace.content,
            .physicalDisplay = outputState.framebufferSpace.getContent(),
            .clip = viewport,
            .outputDataspace = outputDataspace,
            .orientation = orientation,
@@ -282,7 +282,7 @@ void CachedSet::render(renderengine::RenderEngine& renderEngine, TexturePool& te
        mOutputSpace = outputState.framebufferSpace;
        mTexture = texture;
        mTexture->setReadyFence(mDrawFence);
        mOutputSpace.orientation = outputState.framebufferSpace.orientation;
        mOutputSpace.setOrientation(outputState.framebufferSpace.getOrientation());
        mOutputDataspace = outputDataspace;
        mOrientation = orientation;
        mSkipCount = 0;
Loading