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

Commit 439b6096 authored by Alec Mouri's avatar Alec Mouri
Browse files

Remove coordinate swapping in region sampling

Captured screens for region sampling were originally rendered
upside-down, which required swapping coordinates to sample from the
correct area in the output buffer. Since then, several fixes to the
screenshot path have landed, which treat screen orientation
consistently, so the captured images are no longer upside-down. But,
the coordinate swapping was never removed. Remove it now, as sampling
during landscape is now broken.

Bug: 133849373
Bug: 241967077
Test: Split screen in landscape with settings app in dark mode,
calculator in light mode, and trigger back gestures

Change-Id: I52c65032d33d01a4407dc1b30215e7edac6eb1ea
parent eebf7c3b
Loading
Loading
Loading
Loading
+4 −15
Original line number Diff line number Diff line
@@ -203,25 +203,14 @@ float sampleArea(const uint32_t* data, int32_t width, int32_t height, int32_t st
        return 0.0f;
    }

    // (b/133849373) ROT_90 screencap images produced upside down
    auto area = sample_area;
    if (orientation & ui::Transform::ROT_90) {
        area.top = height - area.top;
        area.bottom = height - area.bottom;
        std::swap(area.top, area.bottom);

        area.left = width - area.left;
        area.right = width - area.right;
        std::swap(area.left, area.right);
    }

    const uint32_t pixelCount = (area.bottom - area.top) * (area.right - area.left);
    const uint32_t pixelCount =
            (sample_area.bottom - sample_area.top) * (sample_area.right - sample_area.left);
    uint32_t accumulatedLuma = 0;

    // Calculates luma with approximation of Rec. 709 primaries
    for (int32_t row = area.top; row < area.bottom; ++row) {
    for (int32_t row = sample_area.top; row < sample_area.bottom; ++row) {
        const uint32_t* rowBase = data + row * stride;
        for (int32_t column = area.left; column < area.right; ++column) {
        for (int32_t column = sample_area.left; column < sample_area.right; ++column) {
            uint32_t pixel = rowBase[column];
            const uint32_t r = pixel & 0xFF;
            const uint32_t g = (pixel >> 8) & 0xFF;
+0 −34
Original line number Diff line number Diff line
@@ -106,40 +106,6 @@ TEST_F(RegionSamplingTest, bounds_checking) {
                testing::Eq(0.0));
}

// workaround for b/133849373
TEST_F(RegionSamplingTest, orientation_90) {
    std::generate(buffer.begin(), buffer.end(),
                  [n = 0]() mutable { return (n++ > (kStride * kHeight >> 1)) ? kBlack : kWhite; });

    Rect tl_region{0, 0, 4, 4};
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_0,
                           tl_region),
                testing::Eq(1.0));
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_180,
                           tl_region),
                testing::Eq(1.0));
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_90,
                           tl_region),
                testing::Eq(0.0));
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_270,
                           tl_region),
                testing::Eq(0.0));

    Rect br_region{kWidth - 4, kHeight - 4, kWidth, kHeight};
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_0,
                           br_region),
                testing::Eq(0.0));
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_180,
                           br_region),
                testing::Eq(0.0));
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_90,
                           br_region),
                testing::Eq(1.0));
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_270,
                           br_region),
                testing::Eq(1.0));
}

} // namespace android

// TODO(b/129481165): remove the #pragma below and fix conversion issues