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

Commit 96fca0a0 authored by Alec Mouri's avatar Alec Mouri Committed by Automerger Merge Worker
Browse files

Merge "Remove DisplaySettings::globalTransform" into rvc-dev am: 4afbe7c7 am: fb6c28b0

Change-Id: I580862d08f7ae84d81d37e9bdd4372a4b77e1665
parents fab2171a fb6c28b0
Loading
Loading
Loading
Loading
+49 −18
Original line number Original line Diff line number Diff line
@@ -793,35 +793,66 @@ void GLESRenderEngine::handleRoundedCorners(const DisplaySettings& display,
    // top rectangle and the bottom rectangle, and turn off blending for the middle rectangle.
    // top rectangle and the bottom rectangle, and turn off blending for the middle rectangle.
    FloatRect bounds = layer.geometry.roundedCornersCrop;
    FloatRect bounds = layer.geometry.roundedCornersCrop;


    // Firstly, we need to convert the coordination from layer native coordination space to
    // Explicitly compute the transform from the clip rectangle to the physical
    // device coordination space.
    // display. Normally, this is done in glViewport but we explicitly compute
    // TODO(143929254): Verify that this transformation is correct
    // it here so that we can get the scissor bounds correct.
    const auto transformMatrix = display.globalTransform * layer.geometry.positionTransform;
    const Rect& source = display.clip;
    const vec4 leftTopCoordinate(bounds.left, bounds.top, 1.0, 1.0);
    const Rect& destination = display.physicalDisplay;
    const vec4 rightBottomCoordinate(bounds.right, bounds.bottom, 1.0, 1.0);
    // Here we compute the following transform:
    const vec4 leftTopCoordinateInBuffer = transformMatrix * leftTopCoordinate;
    // 1. Translate the top left corner of the source clip to (0, 0)
    const vec4 rightBottomCoordinateInBuffer = transformMatrix * rightBottomCoordinate;
    // 2. Rotate the clip rectangle about the origin in accordance with the
    bounds = FloatRect(leftTopCoordinateInBuffer[0], leftTopCoordinateInBuffer[1],
    // orientation flag
                       rightBottomCoordinateInBuffer[0], rightBottomCoordinateInBuffer[1]);
    // 3. Translate the top left corner back to the origin.

    // 4. Scale the clip rectangle to the destination rectangle dimensions
    // Secondly, if the display is rotated, we need to undo the rotation on coordination and
    // 5. Translate the top left corner to the destination rectangle's top left
    // align the (left, top) and (right, bottom) coordination with the device coordination
    // corner.
    // space.
    const mat4 translateSource = mat4::translate(vec4(-source.left, -source.top, 0, 1));
    mat4 rotation;
    int displacementX = 0;
    int displacementY = 0;
    float destinationWidth = static_cast<float>(destination.getWidth());
    float destinationHeight = static_cast<float>(destination.getHeight());
    float sourceWidth = static_cast<float>(source.getWidth());
    float sourceHeight = static_cast<float>(source.getHeight());
    const float rot90InRadians = 2.0f * static_cast<float>(M_PI) / 4.0f;
    switch (display.orientation) {
    switch (display.orientation) {
        case ui::Transform::ROT_90:
        case ui::Transform::ROT_90:
            std::swap(bounds.left, bounds.right);
            rotation = mat4::rotate(rot90InRadians, vec3(0, 0, 1));
            displacementX = source.getHeight();
            std::swap(sourceHeight, sourceWidth);
            break;
            break;
        case ui::Transform::ROT_180:
        case ui::Transform::ROT_180:
            std::swap(bounds.left, bounds.right);
            rotation = mat4::rotate(rot90InRadians * 2.0f, vec3(0, 0, 1));
            std::swap(bounds.top, bounds.bottom);
            displacementY = source.getHeight();
            displacementX = source.getWidth();
            break;
            break;
        case ui::Transform::ROT_270:
        case ui::Transform::ROT_270:
            std::swap(bounds.top, bounds.bottom);
            rotation = mat4::rotate(rot90InRadians * 3.0f, vec3(0, 0, 1));
            displacementY = source.getWidth();
            std::swap(sourceHeight, sourceWidth);
            break;
            break;
        default:
        default:
            break;
            break;
    }
    }


    const mat4 intermediateTranslation = mat4::translate(vec4(displacementX, displacementY, 0, 1));
    const mat4 scale = mat4::scale(
            vec4(destinationWidth / sourceWidth, destinationHeight / sourceHeight, 1, 1));
    const mat4 translateDestination =
            mat4::translate(vec4(destination.left, destination.top, 0, 1));
    const mat4 globalTransform =
            translateDestination * scale * intermediateTranslation * rotation * translateSource;

    const mat4 transformMatrix = globalTransform * layer.geometry.positionTransform;
    const vec4 leftTopCoordinate(bounds.left, bounds.top, 1.0, 1.0);
    const vec4 rightBottomCoordinate(bounds.right, bounds.bottom, 1.0, 1.0);
    const vec4 leftTopCoordinateInBuffer = transformMatrix * leftTopCoordinate;
    const vec4 rightBottomCoordinateInBuffer = transformMatrix * rightBottomCoordinate;
    bounds = FloatRect(std::min(leftTopCoordinateInBuffer[0], rightBottomCoordinateInBuffer[0]),
                       std::min(leftTopCoordinateInBuffer[1], rightBottomCoordinateInBuffer[1]),
                       std::max(leftTopCoordinateInBuffer[0], rightBottomCoordinateInBuffer[0]),
                       std::max(leftTopCoordinateInBuffer[1], rightBottomCoordinateInBuffer[1]));

    // Finally, we cut the layer into 3 parts, with top and bottom parts having rounded corners
    // Finally, we cut the layer into 3 parts, with top and bottom parts having rounded corners
    // and the middle part without rounded corners.
    // and the middle part without rounded corners.
    const int32_t radius = ceil(layer.geometry.roundedCornersRadius);
    const int32_t radius = ceil(layer.geometry.roundedCornersRadius);
+2 −16
Original line number Original line Diff line number Diff line
@@ -40,16 +40,6 @@ struct DisplaySettings {
    // z=1.
    // z=1.
    Rect clip = Rect::INVALID_RECT;
    Rect clip = Rect::INVALID_RECT;


    // Global transform to apply to all layers.
    // The global transform is assumed to automatically apply when projecting
    // the clip rectangle onto the physical display; however, this should be
    // explicitly provided to perform CPU-side optimizations such as computing
    // scissor rectangles for rounded corners which require transformation to
    // the phsical display space.
    //
    // This transform is also assumed to include the orientation flag below.
    mat4 globalTransform = mat4();

    // Maximum luminance pulled from the display's HDR capabilities.
    // Maximum luminance pulled from the display's HDR capabilities.
    float maxLuminance = 1.0f;
    float maxLuminance = 1.0f;


@@ -62,9 +52,7 @@ struct DisplaySettings {
    mat4 colorTransform = mat4();
    mat4 colorTransform = mat4();


    // Region that will be cleared to (0, 0, 0, 1) prior to rendering.
    // Region that will be cleared to (0, 0, 0, 1) prior to rendering.
    // RenderEngine will transform the clearRegion passed in here, by
    // This is specified in layer-stack space.
    // globalTransform, so that it will be in the same coordinate space as the
    // rendered layers.
    Region clearRegion = Region::INVALID_REGION;
    Region clearRegion = Region::INVALID_REGION;


    // An additional orientation flag to be applied after clipping the output.
    // An additional orientation flag to be applied after clipping the output.
@@ -76,8 +64,7 @@ struct DisplaySettings {


static inline bool operator==(const DisplaySettings& lhs, const DisplaySettings& rhs) {
static inline bool operator==(const DisplaySettings& lhs, const DisplaySettings& rhs) {
    return lhs.physicalDisplay == rhs.physicalDisplay && lhs.clip == rhs.clip &&
    return lhs.physicalDisplay == rhs.physicalDisplay && lhs.clip == rhs.clip &&
            lhs.globalTransform == rhs.globalTransform && lhs.maxLuminance == rhs.maxLuminance &&
            lhs.maxLuminance == rhs.maxLuminance && lhs.outputDataspace == rhs.outputDataspace &&
            lhs.outputDataspace == rhs.outputDataspace &&
            lhs.colorTransform == rhs.colorTransform &&
            lhs.colorTransform == rhs.colorTransform &&
            lhs.clearRegion.hasSameRects(rhs.clearRegion) && lhs.orientation == rhs.orientation;
            lhs.clearRegion.hasSameRects(rhs.clearRegion) && lhs.orientation == rhs.orientation;
}
}
@@ -89,7 +76,6 @@ static inline void PrintTo(const DisplaySettings& settings, ::std::ostream* os)
    PrintTo(settings.physicalDisplay, os);
    PrintTo(settings.physicalDisplay, os);
    *os << "\n    .clip = ";
    *os << "\n    .clip = ";
    PrintTo(settings.clip, os);
    PrintTo(settings.clip, os);
    *os << "\n    .globalTransform = " << settings.globalTransform;
    *os << "\n    .maxLuminance = " << settings.maxLuminance;
    *os << "\n    .maxLuminance = " << settings.maxLuminance;
    *os << "\n    .outputDataspace = ";
    *os << "\n    .outputDataspace = ";
    PrintTo(settings.outputDataspace, os);
    PrintTo(settings.outputDataspace, os);
+0 −1
Original line number Original line Diff line number Diff line
@@ -924,7 +924,6 @@ void RenderEngineTest::clearLeftRegion() {
    settings.physicalDisplay = fullscreenRect();
    settings.physicalDisplay = fullscreenRect();
    // Here logical space is 4x4
    // Here logical space is 4x4
    settings.clip = Rect(4, 4);
    settings.clip = Rect(4, 4);
    settings.globalTransform = mat4::scale(vec4(2, 4, 0, 1));
    settings.clearRegion = Region(Rect(2, 4));
    settings.clearRegion = Region(Rect(2, 4));
    std::vector<const renderengine::LayerSettings*> layers;
    std::vector<const renderengine::LayerSettings*> layers;
    // dummy layer, without bounds should not render anything
    // dummy layer, without bounds should not render anything
+0 −1
Original line number Original line Diff line number Diff line
@@ -829,7 +829,6 @@ std::optional<base::unique_fd> Output::composeSurfaces(
    renderengine::DisplaySettings clientCompositionDisplay;
    renderengine::DisplaySettings clientCompositionDisplay;
    clientCompositionDisplay.physicalDisplay = outputState.destinationClip;
    clientCompositionDisplay.physicalDisplay = outputState.destinationClip;
    clientCompositionDisplay.clip = outputState.sourceClip;
    clientCompositionDisplay.clip = outputState.sourceClip;
    clientCompositionDisplay.globalTransform = outputState.transform.asMatrix4();
    clientCompositionDisplay.orientation = outputState.orientation;
    clientCompositionDisplay.orientation = outputState.orientation;
    clientCompositionDisplay.outputDataspace = mDisplayColorProfile->hasWideColorGamut()
    clientCompositionDisplay.outputDataspace = mDisplayColorProfile->hasWideColorGamut()
            ? outputState.dataspace
            ? outputState.dataspace
+8 −11
Original line number Original line Diff line number Diff line
@@ -3100,9 +3100,8 @@ TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrMixedComposi
            .andIfUsesHdr(true)
            .andIfUsesHdr(true)
            .andIfSkipColorTransform(false)
            .andIfSkipColorTransform(false)
            .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
            .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
                                            mat4(), kDefaultMaxLuminance, kDefaultOutputDataspace,
                                            kDefaultMaxLuminance, kDefaultOutputDataspace, mat4(),
                                            mat4(), Region::INVALID_REGION,
                                            Region::INVALID_REGION, kDefaultOutputOrientation})
                                            kDefaultOutputOrientation})
            .execute()
            .execute()
            .expectAFenceWasReturned();
            .expectAFenceWasReturned();
}
}
@@ -3112,9 +3111,8 @@ TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrMixedComp
            .andIfUsesHdr(false)
            .andIfUsesHdr(false)
            .andIfSkipColorTransform(false)
            .andIfSkipColorTransform(false)
            .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
            .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
                                            mat4(), kDefaultMaxLuminance, kDefaultOutputDataspace,
                                            kDefaultMaxLuminance, kDefaultOutputDataspace, mat4(),
                                            mat4(), Region::INVALID_REGION,
                                            Region::INVALID_REGION, kDefaultOutputOrientation})
                                            kDefaultOutputOrientation})
            .execute()
            .execute()
            .expectAFenceWasReturned();
            .expectAFenceWasReturned();
}
}
@@ -3124,7 +3122,7 @@ TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrOnlyClientCo
            .andIfUsesHdr(true)
            .andIfUsesHdr(true)
            .andIfSkipColorTransform(false)
            .andIfSkipColorTransform(false)
            .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
            .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
                                            mat4(), kDefaultMaxLuminance, kDefaultOutputDataspace,
                                            kDefaultMaxLuminance, kDefaultOutputDataspace,
                                            kDefaultColorTransformMat, Region::INVALID_REGION,
                                            kDefaultColorTransformMat, Region::INVALID_REGION,
                                            kDefaultOutputOrientation})
                                            kDefaultOutputOrientation})
            .execute()
            .execute()
@@ -3136,7 +3134,7 @@ TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrOnlyClien
            .andIfUsesHdr(false)
            .andIfUsesHdr(false)
            .andIfSkipColorTransform(false)
            .andIfSkipColorTransform(false)
            .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
            .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
                                            mat4(), kDefaultMaxLuminance, kDefaultOutputDataspace,
                                            kDefaultMaxLuminance, kDefaultOutputDataspace,
                                            kDefaultColorTransformMat, Region::INVALID_REGION,
                                            kDefaultColorTransformMat, Region::INVALID_REGION,
                                            kDefaultOutputOrientation})
                                            kDefaultOutputOrientation})
            .execute()
            .execute()
@@ -3149,9 +3147,8 @@ TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,
            .andIfUsesHdr(true)
            .andIfUsesHdr(true)
            .andIfSkipColorTransform(true)
            .andIfSkipColorTransform(true)
            .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
            .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
                                            mat4(), kDefaultMaxLuminance, kDefaultOutputDataspace,
                                            kDefaultMaxLuminance, kDefaultOutputDataspace, mat4(),
                                            mat4(), Region::INVALID_REGION,
                                            Region::INVALID_REGION, kDefaultOutputOrientation})
                                            kDefaultOutputOrientation})
            .execute()
            .execute()
            .expectAFenceWasReturned();
            .expectAFenceWasReturned();
}
}
Loading