chromium/third_party/angle/src/tests/egl_tests/EGLPreRotationTest.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.
//
// EGLPreRotationTest:
//   Tests pertaining to Android pre-rotation.
//

#include <gtest/gtest.h>

#include <vector>

#include "common/Color.h"
#include "common/platform.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "util/EGLWindow.h"
#include "util/OSWindow.h"
#include "util/Timer.h"
#include "util/test_utils.h"

usingnamespaceangle;

namespace
{

EGLPreRotationSurfaceTestParams;

std::string PrintToStringParamName(
    const ::testing::TestParamInfo<EGLPreRotationSurfaceTestParams> &info)
{}

// A class to test various Android pre-rotation cases.  In order to make it easier to debug test
// failures, the initial window size is 256x256, and each pixel will have a unique and predictable
// value.  The red channel will increment with the x axis, and the green channel will increment
// with the y axis.  The four corners will have the following values:
//
// Where                 GLES Render &  ReadPixels coords       Color    (in Hex)
// Lower-left,  which is (-1.0,-1.0) & (  0,   0) in GLES will be black  (0x00, 0x00, 0x00, 0xFF)
// Lower-right, which is ( 1.0,-1.0) & (256,   0) in GLES will be red    (0xFF, 0x00, 0x00, 0xFF)
// Upper-left,  which is (-1.0, 1.0) & (  0, 256) in GLES will be green  (0x00, 0xFF, 0x00, 0xFF)
// Upper-right, which is ( 1.0, 1.0) & (256, 256) in GLES will be yellow (0xFF, 0xFF, 0x00, 0xFF)
class EGLPreRotationSurfaceTest : public ANGLETest<EGLPreRotationSurfaceTestParams>
{};

// Provide a predictable pattern for testing pre-rotation
TEST_P(EGLPreRotationSurfaceTest, OrientedWindowWithDraw)
{}

// Use dFdx() and dFdy() and still provide a predictable pattern for testing pre-rotation
// In this case, the color values will be the following: (dFdx(v_data.x), dFdy(v_data.y), 0, 1).
// To help make this meaningful for pre-rotation, the derivatives will vary in the four corners of
// the window:
//
//  +------------+------------+      +--------+--------+
//  | (  0, 219) | (239, 249) |      | Green  | Yellow |
//  +------------+------------+  OR  +--------+--------+
//  | (  0,   0) | (229,   0) |      | Black  |  Red   |
//  +------------+------------+      +--------+--------+
TEST_P(EGLPreRotationSurfaceTest, OrientedWindowWithDerivativeDraw)
{}

// Android-specific test that changes a window's rotation, which requires ContextVk::syncState() to
// handle the new rotation
TEST_P(EGLPreRotationSurfaceTest, ChangeRotationWithDraw)
{}

// A slight variation of EGLPreRotationSurfaceTest, where the initial window size is 400x300, yet
// the drawing is still 256x256.  In addition, gl_FragCoord is used in a "clever" way, as the color
// of the 256x256 drawing area, which reproduces an interesting pre-rotation case from the
// following dEQP tests:
//
// - dEQP.GLES31/functional_texture_multisample_samples_*_sample_position
//
// This will test the rotation of gl_FragCoord, as well as the viewport, scissor, and rendering
// area calculations, especially when the Android device is rotated.
class EGLPreRotationLargeSurfaceTest : public EGLPreRotationSurfaceTest
{};

// Provide a predictable pattern for testing pre-rotation
TEST_P(EGLPreRotationLargeSurfaceTest, OrientedWindowWithFragCoordDraw)
{}

// Pre-rotation tests for glBlitFramebuffer.  A slight variation of EGLPreRotationLargeSurfaceTest,
// where the initial window size is still 400x300, and the drawing is still 256x256.  In addition,
// glBlitFramebuffer is tested in a variety of ways.  Separate tests are used to make debugging
// simpler, but they all share common setup.  These tests reproduce interesting pre-rotation cases
// from dEQP tests such as the following:
//
// - dEQP.GLES3/functional_fbo_blit_default_framebuffer_*
// - dEQP.GLES3/functional_fbo_invalidate_*
constexpr GLuint kCoordMidWayShort       =;
constexpr GLuint kCoordMidWayLong        =;
constexpr GLColor kColorMidWayShortShort =;
constexpr GLColor kColorMidWayShortLong  =;
constexpr GLColor kColorMidWayLongShort  =;
constexpr GLColor kColorMidWayLongLong   =;
// When scaling horizontally, the "black" and "green" colors have a 1 in the red component
constexpr GLColor kColorScaleHorizBlack =;
constexpr GLColor kColorScaleHorizGreen =;
// When scaling vertically, the "black" and "red" colors have a 1 in the green component
constexpr GLColor kColorScaleVertBlack =;
constexpr GLColor kColorScaleVertRed   =;

class EGLPreRotationBlitFramebufferTest : public EGLPreRotationLargeSurfaceTest
{};

// Draw a predictable pattern (for testing pre-rotation) into an FBO, and then use glBlitFramebuffer
// to blit that pattern into various places within the 400x300 window
TEST_P(EGLPreRotationBlitFramebufferTest, BasicBlitFramebuffer)
{}

// Blit the ms0 stencil buffer to the default framebuffer with rotation on android.
TEST_P(EGLPreRotationBlitFramebufferTest, BlitStencilWithRotation)
{}

// Blit the multisample stencil buffer to the default framebuffer with rotation on android.
TEST_P(EGLPreRotationBlitFramebufferTest, BlitMultisampleStencilWithRotation)
{}

// Blit stencil to default framebuffer with flip and prerotation.
TEST_P(EGLPreRotationBlitFramebufferTest, BlitStencilWithFlip)
{}

// Blit color buffer to default framebuffer with Y-flip/X-flip.
TEST_P(EGLPreRotationBlitFramebufferTest, BlitColorToDefault)
{}

// Blit color buffer from default framebuffer with Y-flip/X-flip.
TEST_P(EGLPreRotationBlitFramebufferTest, BlitColorFromDefault)
{}

// Blit multisample color buffer to resolved framebuffer.
TEST_P(EGLPreRotationBlitFramebufferTest, BlitMultisampleColorToResolved)
{}

// Blit color buffer to default framebuffer with linear filter.
TEST_P(EGLPreRotationBlitFramebufferTest, BlitColorWithLinearFilter)
{}

// Draw a predictable pattern (for testing pre-rotation) into an FBO, and then use glBlitFramebuffer
// to blit the left and right halves of that pattern into various places within the 400x300 window
TEST_P(EGLPreRotationBlitFramebufferTest, LeftAndRightBlitFramebuffer)
{}

// Draw a predictable pattern (for testing pre-rotation) into an FBO, and then use glBlitFramebuffer
// to blit the top and bottom halves of that pattern into various places within the 400x300 window
TEST_P(EGLPreRotationBlitFramebufferTest, TopAndBottomBlitFramebuffer)
{}

// Draw a predictable pattern (for testing pre-rotation) into an FBO, and then use glBlitFramebuffer
// to blit that pattern into various places within the 400x300 window, but being scaled to one-half
// size
TEST_P(EGLPreRotationBlitFramebufferTest, ScaledBlitFramebuffer)
{}

// Draw a predictable pattern (for testing pre-rotation) into a 256x256 portion of the 400x300
// window, and then use glBlitFramebuffer to blit that pattern into an FBO
TEST_P(EGLPreRotationBlitFramebufferTest, FboDestBlitFramebuffer)
{}

// Draw a predictable pattern (for testing pre-rotation) into a 256x256 portion of the 400x300
// window, and then use glBlitFramebuffer to blit that pattern into an FBO, but with coordinates
// that are partially out-of-bounds of the source
TEST_P(EGLPreRotationBlitFramebufferTest, FboDestOutOfBoundsSourceBlitFramebuffer)
{}

// Draw a predictable pattern (for testing pre-rotation) into a 256x256 portion of the 400x300
// window, and then use glBlitFramebuffer to blit that pattern into an FBO, but with coordinates
// that are partially out-of-bounds of the source, and cause a "stretch" to occur
TEST_P(EGLPreRotationBlitFramebufferTest, FboDestOutOfBoundsSourceWithStretchBlitFramebuffer)
{}

// Draw a predictable pattern (for testing pre-rotation) into a 256x256 portion of the 400x300
// window, and then use glBlitFramebuffer to blit that pattern into an FBO, but with source and FBO
// coordinates that are partially out-of-bounds of the source
TEST_P(EGLPreRotationBlitFramebufferTest, FboDestOutOfBoundsSourceAndDestBlitFramebuffer)
{}

class EGLPreRotationInterpolateAtOffsetTest : public EGLPreRotationSurfaceTest
{};

// Draw with interpolateAtOffset() builtin function to pre-rotated default FBO
TEST_P(EGLPreRotationInterpolateAtOffsetTest, InterpolateAtOffsetWithDefaultFBO)
{}

// Draw with interpolateAtOffset() builtin function to pre-rotated custom FBO
TEST_P(EGLPreRotationInterpolateAtOffsetTest, InterpolateAtOffsetWithCustomFBO)
{}

}  // anonymous namespace

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST();
ANGLE_INSTANTIATE_TEST_COMBINE_1();

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST();
ANGLE_INSTANTIATE_TEST_COMBINE_1();

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST();
ANGLE_INSTANTIATE_TEST_COMBINE_1();

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST();
ANGLE_INSTANTIATE_TEST_COMBINE_1();