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

Commit 32cbe28e authored by Lloyd Pique's avatar Lloyd Pique
Browse files

SF: Move state out of DisplayDevice to a new Output class

CompositionEngine::Output holds the composition state of an output. A
CompositionEngine::Display is an output, so it derives from it.

The state is removed from DisplayDevice, with some (temporary) accessors
left behind as there are more changes coming.

The composition related code in SurfaceFlinger is adjusted to however
use the output state.

Test: atest libsurfaceflinger_unittest libcompositionengine_test
Bug: 121291683
Change-Id: Idae2d3d96315538d006b27b56e0a8b566ce0e3b8
parent 45a165a5
Loading
Loading
Loading
Loading
+35 −31
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include <math.h>

#include <android-base/stringprintf.h>
#include <cutils/compiler.h>
#include <ui/Region.h>
#include <ui/Transform.h>
@@ -380,44 +381,47 @@ bool Transform::preserveRects() const
    return (getOrientation() & ROT_INVALID) ? false : true;
}

void Transform::dump(const char* name) const
{
    type(); // updates the type
void Transform::dump(std::string& out, const char* name) const {
    using android::base::StringAppendF;

    type(); // Ensure the information in mType is up to date

    String8 flags, type;
    const mat33& m(mMatrix);
    uint32_t orient = mType >> 8;
    const uint32_t type = mType;
    const uint32_t orient = type >> 8;

    StringAppendF(&out, "%s 0x%08x (", name, orient);

    if (orient & ROT_INVALID) {
        flags.append("ROT_INVALID ");
        out.append("ROT_INVALID ");
    } else {
        if (orient & ROT_90) {
            flags.append("ROT_90 ");
            out.append("ROT_90 ");
        } else {
            flags.append("ROT_0 ");
        }
        if (orient&FLIP_V)
            flags.append("FLIP_V ");
        if (orient&FLIP_H)
            flags.append("FLIP_H ");
    }

    if (!(mType&(SCALE|ROTATE|TRANSLATE)))
        type.append("IDENTITY ");
    if (mType&SCALE)
        type.append("SCALE ");
    if (mType&ROTATE)
        type.append("ROTATE ");
    if (mType&TRANSLATE)
        type.append("TRANSLATE ");

    ALOGD("%s 0x%08x (%s, %s)", name, mType, flags.string(), type.string());
    ALOGD("%.4f  %.4f  %.4f", static_cast<double>(m[0][0]), static_cast<double>(m[1][0]),
          static_cast<double>(m[2][0]));
    ALOGD("%.4f  %.4f  %.4f", static_cast<double>(m[0][1]), static_cast<double>(m[1][1]),
          static_cast<double>(m[2][1]));
    ALOGD("%.4f  %.4f  %.4f", static_cast<double>(m[0][2]), static_cast<double>(m[1][2]),
          static_cast<double>(m[2][2]));
            out.append("ROT_0 ");
        }
        if (orient & FLIP_V) out.append("FLIP_V ");
        if (orient & FLIP_H) out.append("FLIP_H ");
    }

    StringAppendF(&out, ") 0x%02x (", type);

    if (!(type & (SCALE | ROTATE | TRANSLATE))) out.append("IDENTITY ");
    if (type & SCALE) out.append("SCALE ");
    if (type & ROTATE) out.append("ROTATE ");
    if (type & TRANSLATE) out.append("TRANSLATE ");

    out.append(")\n");

    for (size_t i = 0; i < 3; i++) {
        StringAppendF(&out, "    %.4f  %.4f  %.4f\n", static_cast<double>(mMatrix[0][i]),
                      static_cast<double>(mMatrix[1][i]), static_cast<double>(mMatrix[2][i]));
    }
}

void Transform::dump(const char* name) const {
    std::string out;
    dump(out, name);
    ALOGD("%s", out.c_str());
}

}  // namespace ui
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include <stdint.h>
#include <sys/types.h>
#include <string>

#include <hardware/hardware.h>
#include <math/vec2.h>
@@ -90,6 +91,7 @@ public:
    Transform inverse() const;

    // for debugging
    void dump(std::string& result, const char* name) const;
    void dump(const char* name) const;

private:
+5 −0
Original line number Diff line number Diff line
@@ -36,6 +36,9 @@ cc_library {
    srcs: [
        "src/CompositionEngine.cpp",
        "src/Display.cpp",
        "src/DumpHelpers.cpp",
        "src/Output.cpp",
        "src/OutputCompositionState.cpp",
    ],
    local_include_dirs: ["include"],
    export_include_dirs: ["include"],
@@ -47,6 +50,7 @@ cc_library {
    srcs: [
        "mock/CompositionEngine.cpp",
        "mock/Display.cpp",
        "mock/Output.cpp",
    ],
    static_libs: [
        "libgtest",
@@ -64,6 +68,7 @@ cc_test {
    srcs: [
        "tests/CompositionEngineTest.cpp",
        "tests/DisplayTest.cpp",
        "tests/OutputTest.cpp",
        "tests/MockHWComposer.cpp",
    ],
    static_libs: [
+3 −1
Original line number Diff line number Diff line
@@ -21,13 +21,15 @@

#include "DisplayHardware/DisplayIdentification.h"

#include <compositionengine/Output.h>

namespace android::compositionengine {

/**
 * A display is a composition target which may be backed by a hardware composer
 * display device
 */
class Display {
class Display : public virtual Output {
public:
    // Gets the HWC DisplayId for the display if there is one
    virtual const std::optional<DisplayId>& getId() const = 0;
+97 −0
Original line number Diff line number Diff line
/*
 * 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 <string>

#include <math/mat4.h>
#include <ui/GraphicTypes.h>
#include <ui/Region.h>
#include <ui/Transform.h>

namespace android::compositionengine {

namespace impl {
struct OutputCompositionState;
} // namespace impl

/**
 * Encapsulates all the state involved with composing layers for an output
 */
class Output {
public:
    // Returns true if the output is valid. This is meant to be checked post-
    // construction and prior to use, as not everything is set up by the
    // constructor.
    virtual bool isValid() const = 0;

    // Enables (or disables) composition on this output
    virtual void setCompositionEnabled(bool) = 0;

    // Sets the projection state to use
    virtual void setProjection(const ui::Transform&, int32_t orientation, const Rect& frame,
                               const Rect& viewport, const Rect& scissor, bool needsFiltering) = 0;
    // Sets the bounds to use
    virtual void setBounds(const Rect&) = 0;

    // Sets the layer stack filter for this output. If singleLayerStack is true,
    // this output displays just the single layer stack specified by
    // singleLayerStackId. Otherwise all layer stacks will be visible on this
    // output.
    virtual void setLayerStackFilter(bool singleLayerStack, uint32_t singleLayerStackId) = 0;

    // Sets the color transform matrix to use
    virtual void setColorTransform(const mat4&) = 0;

    // Sets the output color mode
    virtual void setColorMode(ui::ColorMode, ui::Dataspace, ui::RenderIntent) = 0;

    // Outputs a string with a state dump
    virtual void dump(std::string&) const = 0;

    // Gets the debug name for the output
    virtual const std::string& getName() const = 0;

    // Sets a debug name for the output
    virtual void setName(const std::string&) = 0;

    using OutputCompositionState = compositionengine::impl::OutputCompositionState;

    // Gets the raw composition state data for the output
    // TODO(lpique): Make this protected once it is only internally called.
    virtual const OutputCompositionState& getState() const = 0;

    // Allows mutable access to the raw composition state data for the output.
    // This is meant to be used by the various functions that are part of the
    // composition process.
    // TODO(lpique): Make this protected once it is only internally called.
    virtual OutputCompositionState& editState() = 0;

    // Gets the physical space dirty region. If repaintEverything is true, this
    // will be the full display bounds. Internally the dirty region is stored in
    // logical (aka layer stack) space.
    virtual Region getPhysicalSpaceDirtyRegion(bool repaintEverything) const = 0;

    // Tests whether a given layerStackId belongs in this output
    virtual bool belongsInOutput(uint32_t layerStackId) const = 0;

protected:
    ~Output() = default;
};

} // namespace android::compositionengine
Loading