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

Commit 62dc1344 authored by Courtney Goeltzenleuchter's avatar Courtney Goeltzenleuchter Committed by Android (Google) Code Review
Browse files

Merge changes I9da985a7,I2bd642aa,I9358b3c9,I9d3c60b1 into oc-dev

* changes:
  Add test for FP16 surface support
  Dump info about wide-color
  Add wide-color support to SurfaceFlinger
  Add debug string functions for graphics.h enums
parents 67443627 f29f2879
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright 2017 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 <system/graphics.h>

#include <string>

std::string decodeStandard(android_dataspace dataspace);
std::string decodeTransfer(android_dataspace dataspace);
std::string decodeRange(android_dataspace dataspace);
std::string dataspaceDetails(android_dataspace dataspace);
std::string decodeColorMode(android_color_mode colormode);
+5 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ cc_library_shared {

    srcs: [
        "ColorSpace.cpp",
        "DebugUtils.cpp",
        "Fence.cpp",
        "FenceTime.cpp",
        "FrameStats.cpp",
@@ -66,6 +67,8 @@ cc_library_shared {
    shared_libs: [
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.mapper@2.0",
        "android.hardware.configstore@1.0",
        "libbase",
        "libnativeloader",
        "libcutils",
        "libhardware",
@@ -76,6 +79,8 @@ cc_library_shared {
        "liblog",
    ],

    header_libs: ["android.hardware.configstore-utils"],

    static_libs: [
        "libarect",
        "libgrallocusage",

libs/ui/DebugUtils.cpp

0 → 100644
+187 −0
Original line number Diff line number Diff line
/*
 * Copyright 2017 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.
 */

#include <ui/DebugUtils.h>

#include <android-base/stringprintf.h>
#include <string>

std::string decodeStandard(android_dataspace dataspace) {
    const uint32_t dataspaceSelect = (dataspace & HAL_DATASPACE_STANDARD_MASK);
    switch (dataspaceSelect) {
        case HAL_DATASPACE_STANDARD_BT709:
            return std::string("BT709");

        case HAL_DATASPACE_STANDARD_BT601_625:
            return std::string("BT601_625");

        case HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED:
            return std::string("BT601_625_UNADJUSTED");

        case HAL_DATASPACE_STANDARD_BT601_525:
            return std::string("BT601_525");

        case HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED:
            return std::string("BT601_525_UNADJUSTED");

        case HAL_DATASPACE_STANDARD_BT2020:
            return std::string("BT2020");

        case HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE:
            return std::string("BT2020 (constant luminance)");

        case HAL_DATASPACE_STANDARD_BT470M:
            return std::string("BT470M");

        case HAL_DATASPACE_STANDARD_FILM:
            return std::string("FILM");

        case HAL_DATASPACE_STANDARD_DCI_P3:
            return std::string("DCI-P3");

        case HAL_DATASPACE_STANDARD_ADOBE_RGB:
            return std::string("AdobeRGB");

        case 0:
            switch (dataspace & 0xffff) {
                case HAL_DATASPACE_JFIF:
                    return std::string("(deprecated) JFIF (BT601_625, SMPTE_170M Full range)");

                case HAL_DATASPACE_BT601_625:
                    return std::string("(deprecated) BT601_625 (BT601_625, SMPTE_170M Limited "
                                       "range)");

                case HAL_DATASPACE_BT601_525:
                    return std::string("(deprecated) BT601_525 (BT601_525, SMPTE_170M Limited "
                                       "range)");

                case HAL_DATASPACE_SRGB_LINEAR:
                    return std::string("(deprecated) SRGB Linear Full range");

                case HAL_DATASPACE_SRGB:
                    return std::string("(deprecated) sRGB");

                case HAL_DATASPACE_V0_BT709:
                    return std::string("(deprecated) BT709 (BT709, SMPTE_170M Limited range)");

                case HAL_DATASPACE_ARBITRARY:
                    return std::string("ARBITRARY");

                case HAL_DATASPACE_UNKNOWN:
                // Fallthrough
                default:
                    return android::base::StringPrintf("Unknown deprecated dataspace code %d",
                                                       dataspaceSelect);
            }
    }

    return android::base::StringPrintf("Unknown dataspace code %d", dataspaceSelect);
}

std::string decodeTransfer(android_dataspace dataspace) {
    const uint32_t dataspaceTransfer = (dataspace & HAL_DATASPACE_TRANSFER_MASK);
    switch (dataspaceTransfer) {
        case HAL_DATASPACE_TRANSFER_UNSPECIFIED:
            return std::string("Unspecified");

        case HAL_DATASPACE_TRANSFER_LINEAR:
            return std::string("Linear");

        case HAL_DATASPACE_TRANSFER_SRGB:
            return std::string("sRGB");

        case HAL_DATASPACE_TRANSFER_SMPTE_170M:
            return std::string("SMPTE_170M");

        case HAL_DATASPACE_TRANSFER_GAMMA2_2:
            return std::string("gamma 2.2");

        case HAL_DATASPACE_TRANSFER_GAMMA2_6:
            return std::string("gamma 2.6");

        case HAL_DATASPACE_TRANSFER_GAMMA2_8:
            return std::string("gamma 2.8");

        case HAL_DATASPACE_TRANSFER_ST2084:
            return std::string("SMPTE 2084");

        case HAL_DATASPACE_TRANSFER_HLG:
            return std::string("STD-B67");
    }

    return android::base::StringPrintf("Unknown dataspace transfer %d", dataspaceTransfer);
}

std::string decodeRange(android_dataspace dataspace) {
    const uint32_t dataspaceRange = (dataspace & HAL_DATASPACE_RANGE_MASK);
    switch (dataspaceRange) {
        case HAL_DATASPACE_RANGE_UNSPECIFIED:
            return std::string("Range Unspecified");

        case HAL_DATASPACE_RANGE_FULL:
            return std::string("Full range");

        case HAL_DATASPACE_RANGE_LIMITED:
            return std::string("Limited range");

        case HAL_DATASPACE_RANGE_EXTENDED:
            return std::string("Extended range");
    }

    return android::base::StringPrintf("Unknown dataspace range %d", dataspaceRange);
}

std::string dataspaceDetails(android_dataspace dataspace) {
    return android::base::StringPrintf("%s %s %s", decodeStandard(dataspace).c_str(),
                                       decodeTransfer(dataspace).c_str(),
                                       decodeRange(dataspace).c_str());
}

std::string decodeColorMode(android_color_mode colorMode) {
    switch (colorMode) {
        case HAL_COLOR_MODE_NATIVE:
            return std::string("HAL_COLOR_MODE_NATIVE");

        case HAL_COLOR_MODE_STANDARD_BT601_625:
            return std::string("HAL_COLOR_MODE_BT601_625");

        case HAL_COLOR_MODE_STANDARD_BT601_625_UNADJUSTED:
            return std::string("HAL_COLOR_MODE_BT601_625_UNADJUSTED");

        case HAL_COLOR_MODE_STANDARD_BT601_525:
            return std::string("HAL_COLOR_MODE_BT601_525");

        case HAL_COLOR_MODE_STANDARD_BT601_525_UNADJUSTED:
            return std::string("HAL_COLOR_MODE_BT601_525_UNADJUSTED");

        case HAL_COLOR_MODE_STANDARD_BT709:
            return std::string("HAL_COLOR_MODE_BT709");

        case HAL_COLOR_MODE_DCI_P3:
            return std::string("HAL_COLOR_MODE_DCI_P3");

        case HAL_COLOR_MODE_SRGB:
            return std::string("HAL_COLOR_MODE_SRGB");

        case HAL_COLOR_MODE_ADOBE_RGB:
            return std::string("HAL_COLOR_MODE_ADOBE_RGB");

        case HAL_COLOR_MODE_DISPLAY_P3:
            return std::string("HAL_COLOR_MODE_DISPLAY_P3");
    }

    return android::base::StringPrintf("Unknown color mode %d", colorMode);
}
+7 −0
Original line number Diff line number Diff line
@@ -11,13 +11,20 @@ LOCAL_SRC_FILES := \
    egl_cache_test.cpp \
    EGL_test.cpp \

LOCAL_HEADER_LIBRARIES := \
    android.hardware.configstore-utils

LOCAL_SHARED_LIBRARIES := \
	android.hardware.configstore@1.0 \
	libEGL \
	libcutils \
	libbinder \
	libhidlbase \
	libhidltransport \
	libutils \
	libgui \
	libbase \
	liblog \

LOCAL_C_INCLUDES := \
    bionic/libc/private \
+94 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

#include <gtest/gtest.h>

#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>

#include <configstore/Utils.h>
#include <utils/String8.h>

#include <EGL/egl.h>
@@ -25,10 +28,31 @@
#include <gui/IGraphicBufferConsumer.h>
#include <gui/BufferQueue.h>

#define PIXEL_FORMAT_FLOAT "EGL_EXT_pixel_format_float"

bool hasEglPixelFormatFloat() {
    EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    const char* exts = eglQueryString(dpy, EGL_EXTENSIONS);
    size_t cropExtLen = strlen(PIXEL_FORMAT_FLOAT);
    size_t extsLen = strlen(exts);
    bool equal = !strcmp(PIXEL_FORMAT_FLOAT, exts);
    bool atStart = !strncmp(PIXEL_FORMAT_FLOAT " ", exts, cropExtLen + 1);
    bool atEnd = (cropExtLen + 1) < extsLen &&
            !strcmp(" " PIXEL_FORMAT_FLOAT, exts + extsLen - (cropExtLen + 1));
    bool inMiddle = strstr(exts, " " PIXEL_FORMAT_FLOAT " ");
    return equal || atStart || atEnd || inMiddle;
}

namespace android {

#define EGL_UNSIGNED_TRUE static_cast<EGLBoolean>(EGL_TRUE)

// retrieve wide-color setting from configstore
using namespace android::hardware::configstore;

static bool hasWideColorDisplay =
        getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(false);

class EGLTest : public ::testing::Test {
protected:
    EGLDisplay mEglDisplay;
@@ -169,5 +193,75 @@ TEST_F(EGLTest, EGLConfigRGBA8888First) {
    EXPECT_GE(components[3], 8);
}

TEST_F(EGLTest, EGLConfigFP16) {
    EGLint numConfigs;
    EGLConfig config;
    EGLBoolean success;

    if (!hasWideColorDisplay) {
        // skip this test if device does not have wide-color display
        return;
    }

    ASSERT_TRUE(hasEglPixelFormatFloat());

    EGLint attrs[] = {EGL_SURFACE_TYPE,
                      EGL_WINDOW_BIT,
                      EGL_RENDERABLE_TYPE,
                      EGL_OPENGL_ES2_BIT,
                      EGL_RED_SIZE,
                      16,
                      EGL_GREEN_SIZE,
                      16,
                      EGL_BLUE_SIZE,
                      16,
                      EGL_ALPHA_SIZE,
                      16,
                      EGL_COLOR_COMPONENT_TYPE_EXT,
                      EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT,
                      EGL_NONE};
    success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
    ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
    ASSERT_EQ(1, numConfigs);

    EGLint components[4];

    success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
    ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
    ASSERT_EQ(EGL_SUCCESS, eglGetError());
    success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
    ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
    ASSERT_EQ(EGL_SUCCESS, eglGetError());
    success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
    ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
    ASSERT_EQ(EGL_SUCCESS, eglGetError());
    success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]);
    ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
    ASSERT_EQ(EGL_SUCCESS, eglGetError());

    EXPECT_GE(components[0], 16);
    EXPECT_GE(components[1], 16);
    EXPECT_GE(components[2], 16);
    EXPECT_GE(components[3], 16);

    struct DummyConsumer : public BnConsumerListener {
        void onFrameAvailable(const BufferItem& /* item */) override {}
        void onBuffersReleased() override {}
        void onSidebandStreamChanged() override {}
    };

    // Create a EGLSurface
    sp<IGraphicBufferProducer> producer;
    sp<IGraphicBufferConsumer> consumer;
    BufferQueue::createBufferQueue(&producer, &consumer);
    consumer->consumerConnect(new DummyConsumer, false);
    sp<Surface> mSTC = new Surface(producer);
    sp<ANativeWindow> mANW = mSTC;

    EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, mANW.get(), NULL);
    ASSERT_EQ(EGL_SUCCESS, eglGetError());
    ASSERT_NE(EGL_NO_SURFACE, eglSurface);

    EXPECT_TRUE(eglDestroySurface(mEglDisplay, eglSurface));
}
}
Loading