Edit

kc3-lang/angle/src/tests/test_utils/angle_test_platform.cpp

Branch :

  • Show log

    Commit

  • Author : Jamie Madill
    Date : 2020-03-15 17:28:43
    Hash : 5df2c9ea
    Message : Refactor ANGLE common test utils. This reduces code duplication by including a common set of sources in a single place. New test sets will be a bit easier to add. It also encapsulates the dependencies a bit better when we pull the test utils out of the test targets. Unblocks a follow-up CL that moves the trace perf test sources into their own file so we can re-enable optimizations in the main perf test target. New warnings popped up in a few of the files because of the new source set enabling more warnings. This CL also fixes all of those. Bug: angleproject:3630 Change-Id: Ic30cb30fb4288c4dbbbd29f9bdf04be51e8a6b30 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2103083 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Yuly Novikov <ynovikov@chromium.org>

  • src/tests/test_utils/angle_test_platform.cpp
  • //
    // Copyright 2020 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    
    #include "angle_test_platform.h"
    
    #include "common/platform.h"
    #include "gpu_info_util/SystemInfo.h"
    
    #if defined(ANGLE_PLATFORM_WINDOWS)
    #    include <VersionHelpers.h>
    #endif  // defined(ANGLE_PLATFORM_WINDOWS)
    
    using namespace angle;
    
    bool IsAdreno()
    {
        std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
        return (rendererString.find("Adreno") != std::string::npos);
    }
    
    bool IsD3D11()
    {
        std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
        return (rendererString.find("Direct3D11 vs_5_0") != std::string::npos);
    }
    
    bool IsD3D11_FL93()
    {
        std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
        return (rendererString.find("Direct3D11 vs_4_0_") != std::string::npos);
    }
    
    bool IsD3D9()
    {
        std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
        return (rendererString.find("Direct3D9") != std::string::npos);
    }
    
    bool IsD3DSM3()
    {
        return IsD3D9() || IsD3D11_FL93();
    }
    
    bool IsDesktopOpenGL()
    {
        return IsOpenGL() && !IsOpenGLES();
    }
    
    bool IsOpenGLES()
    {
        std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
        return (rendererString.find("OpenGL ES") != std::string::npos);
    }
    
    bool IsOpenGL()
    {
        std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
        return (rendererString.find("OpenGL") != std::string::npos);
    }
    
    bool IsNULL()
    {
        std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
        return (rendererString.find("NULL") != std::string::npos);
    }
    
    bool IsVulkan()
    {
        const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
        std::string rendererString(renderer);
        return (rendererString.find("Vulkan") != std::string::npos);
    }
    
    bool IsMetal()
    {
        const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
        std::string rendererString(renderer);
        return (rendererString.find("Metal") != std::string::npos);
    }
    
    bool IsD3D()
    {
        return IsD3D9() || IsD3D11();
    }
    
    bool IsDebug()
    {
    #if !defined(NDEBUG)
        return true;
    #else
        return false;
    #endif
    }
    
    bool IsRelease()
    {
        return !IsDebug();
    }
    
    bool EnsureGLExtensionEnabled(const std::string &extName)
    {
        if (IsGLExtensionEnabled("GL_ANGLE_request_extension") && IsGLExtensionRequestable(extName))
        {
            glRequestExtensionANGLE(extName.c_str());
        }
    
        return IsGLExtensionEnabled(extName);
    }
    
    bool IsEGLClientExtensionEnabled(const std::string &extName)
    {
        return CheckExtensionExists(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), extName);
    }
    
    bool IsEGLDeviceExtensionEnabled(EGLDeviceEXT device, const std::string &extName)
    {
        return CheckExtensionExists(eglQueryDeviceStringEXT(device, EGL_EXTENSIONS), extName);
    }
    
    bool IsEGLDisplayExtensionEnabled(EGLDisplay display, const std::string &extName)
    {
        return CheckExtensionExists(eglQueryString(display, EGL_EXTENSIONS), extName);
    }
    
    bool IsGLExtensionEnabled(const std::string &extName)
    {
        return CheckExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
                                    extName);
    }
    
    bool IsGLExtensionRequestable(const std::string &extName)
    {
        return CheckExtensionExists(
            reinterpret_cast<const char *>(glGetString(GL_REQUESTABLE_EXTENSIONS_ANGLE)), extName);
    }