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

Commit e271df94 authored by Valerie Hau's avatar Valerie Hau
Browse files

Transaction_test refactoring continued

Minor refactor

Bug: 140128949
Test: build, boot, SurfaceFlinger_test
Change-Id: Ibeed4b4feb102d8ee6cf57c2deabb53f41177f0a
parent 1ba4b251
Loading
Loading
Loading
Loading
+102 −83

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ public:

    void expectColor(const Rect& rect, const Color& color, uint8_t tolerance = 0) {
        ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat());
        expectBufferColor(mOutBuffer, mPixels, rect, color, tolerance);
        TransactionUtils::expectBufferColor(mOutBuffer, mPixels, rect, color, tolerance);
    }

    void expectBorder(const Rect& rect, const Color& color, uint8_t tolerance = 0) {
+99 −104
Original line number Diff line number Diff line
@@ -16,13 +16,7 @@

#pragma once

//#include <algorithm>
#include <chrono>
//#include <cinttypes>
//#include <functional>
//#include <limits>
//#include <ostream>
//#include <thread>
#include <gtest/gtest.h>

#include <android/native_window.h>
@@ -39,22 +33,23 @@
#include <ui/Rect.h>

#include "ColorUtils.h"
//#include <sys/types.h>
//#include <unistd.h>

namespace android {

namespace {

using namespace std::chrono_literals;
using Transaction = SurfaceComposerClient::Transaction;

std::ostream& operator<<(std::ostream& os, const Color& color) {
    os << int(color.r) << ", " << int(color.g) << ", " << int(color.b) << ", " << int(color.a);
    return os;
}

class TransactionUtils {
public:
    // Fill a region with the specified color.
void fillANativeWindowBufferColor(const ANativeWindow_Buffer& buffer, const Rect& rect,
    static void fillANativeWindowBufferColor(const ANativeWindow_Buffer& buffer, const Rect& rect,
                                             const Color& color) {
        Rect r(0, 0, buffer.width, buffer.height);
        if (!r.intersect(rect, &r)) {
@@ -65,8 +60,8 @@ void fillANativeWindowBufferColor(const ANativeWindow_Buffer& buffer, const Rect
        int32_t height = r.bottom - r.top;

        for (int32_t row = 0; row < height; row++) {
        uint8_t* dst =
                static_cast<uint8_t*>(buffer.bits) + (buffer.stride * (r.top + row) + r.left) * 4;
            uint8_t* dst = static_cast<uint8_t*>(buffer.bits) +
                    (buffer.stride * (r.top + row) + r.left) * 4;
            for (int32_t column = 0; column < width; column++) {
                dst[0] = color.r;
                dst[1] = color.g;
@@ -78,7 +73,8 @@ void fillANativeWindowBufferColor(const ANativeWindow_Buffer& buffer, const Rect
    }

    // Fill a region with the specified color.
void fillGraphicBufferColor(const sp<GraphicBuffer>& buffer, const Rect& rect, const Color& color) {
    static void fillGraphicBufferColor(const sp<GraphicBuffer>& buffer, const Rect& rect,
                                       const Color& color) {
        Rect r(0, 0, buffer->width, buffer->height);
        if (!r.intersect(rect, &r)) {
            return;
@@ -105,8 +101,8 @@ void fillGraphicBufferColor(const sp<GraphicBuffer>& buffer, const Rect& rect, c
    }

    // Check if a region has the specified color.
void expectBufferColor(const sp<GraphicBuffer>& outBuffer, uint8_t* pixels, const Rect& rect,
                       const Color& color, uint8_t tolerance) {
    static void expectBufferColor(const sp<GraphicBuffer>& outBuffer, uint8_t* pixels,
                                  const Rect& rect, const Color& color, uint8_t tolerance) {
        int32_t x = rect.left;
        int32_t y = rect.top;
        int32_t width = rect.right - rect.left;
@@ -140,8 +136,6 @@ void expectBufferColor(const sp<GraphicBuffer>& outBuffer, uint8_t* pixels, cons
        }
    }

using Transaction = SurfaceComposerClient::Transaction;

    // Fill an RGBA_8888 formatted surface with a single color.
    static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, uint8_t r, uint8_t g, uint8_t b,
                                 bool unlock = true) {
@@ -163,6 +157,7 @@ static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, uint8_t r, uint8_t g,
            ASSERT_EQ(NO_ERROR, s->unlockAndPost());
        }
    }
};

enum class RenderPath { SCREENSHOT, VIRTUAL_DISPLAY };