File: gl_virtual_contexts_ext_window_rectangles_unittest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (136 lines) | stat: -rw-r--r-- 3,550 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES3/gl3.h>
#include <stdint.h>

#include <array>

#include "gpu/command_buffer/tests/gl_manager.h"
#include "gpu/command_buffer/tests/gl_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace gpu {

// A collection of tests that exercise the GL_EXT_srgb extension.
class GLVirtualContextsEXTWindowRectanglesTest : public testing::Test {
 protected:
  void SetUp() override {
    GLManager::Options options;
    options.context_type = CONTEXT_TYPE_OPENGLES3;
    gl_real_shared_.Initialize(options);

    if (!IsApplicable())
      return;

    options.virtual_manager = &gl_real_shared_;
    gl1_.Initialize(options);
    gl2_.Initialize(options);
  }

  void TearDown() override {
    if (IsApplicable()) {
      gl1_.Destroy();
      gl2_.Destroy();
    }
    gl_real_shared_.Destroy();
  }

  bool IsApplicable() const {
    // Not applicable for devices not supporting OpenGLES3.
    if (!gl_real_shared_.IsInitialized()) {
      return false;
    }

    bool have_ext = GLTestHelper::HasExtension("GL_EXT_window_rectangles");
    return have_ext;
  }

  GLManager gl_real_shared_;
  GLManager gl1_;
  GLManager gl2_;
};

TEST_F(GLVirtualContextsEXTWindowRectanglesTest, Basic) {
  if (!IsApplicable()) {
    return;
  }

  // Context 1: Set window rectangles state.
  gl1_.MakeCurrent();
  {
    std::array<GLint, 12> box = {};
    for (int i = 0; i < 12; ++i) {
      box[i] = i;
    }
    glWindowRectanglesEXT(GL_INCLUSIVE_EXT, 3, box.data());
    EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  }

  // Context 2: Make sure it still has the default state.
  gl2_.MakeCurrent();
  {
    GLint max = -1;
    {
      glGetIntegerv(GL_MAX_WINDOW_RECTANGLES_EXT, &max);
      EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
      EXPECT_GE(max, 4);
    }

    {
      int mode = -1;
      glGetIntegerv(GL_WINDOW_RECTANGLE_MODE_EXT, &mode);
      EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
      EXPECT_EQ(GL_EXCLUSIVE_EXT, mode);
    }
    {
      GLint num = -1;
      glGetIntegerv(GL_NUM_WINDOW_RECTANGLES_EXT, &num);
      EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
      EXPECT_EQ(0, num);
    }

    for (int i = 0; i < max; ++i) {
      GLint rect[4] = {-1, -1, -1, -1};
      glGetIntegeri_v(GL_WINDOW_RECTANGLE_EXT, i, rect);
      EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
      EXPECT_EQ(0, rect[0]);
      EXPECT_EQ(0, rect[1]);
      EXPECT_EQ(0, rect[2]);
      EXPECT_EQ(0, rect[3]);
    }
  }

  // Context 1: Make sure it still has the state it set.
  gl1_.MakeCurrent();
  {
    {
      int mode = -1;
      glGetIntegerv(GL_WINDOW_RECTANGLE_MODE_EXT, &mode);
      EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
      EXPECT_EQ(GL_INCLUSIVE_EXT, mode);
    }
    {
      GLint num = -1;
      glGetIntegerv(GL_NUM_WINDOW_RECTANGLES_EXT, &num);
      EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
      EXPECT_EQ(3, num);
    }

    for (int i = 0; i < 3; ++i) {
      GLint rect[4] = {-1, -1, -1, -1};
      glGetIntegeri_v(GL_WINDOW_RECTANGLE_EXT, i, rect);
      EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
      EXPECT_EQ(4 * i + 0, rect[0]);
      EXPECT_EQ(4 * i + 1, rect[1]);
      EXPECT_EQ(4 * i + 2, rect[2]);
      EXPECT_EQ(4 * i + 3, rect[3]);
    }
  }
}

}  // namespace gpu