gl_virtual_contexts_ext_window_rectangles_unittest.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Copyright (c) 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <GLES2/gl2.h>
  5. #include <GLES2/gl2ext.h>
  6. #include <GLES3/gl3.h>
  7. #include <stdint.h>
  8. #include "gpu/command_buffer/tests/gl_manager.h"
  9. #include "gpu/command_buffer/tests/gl_test_utils.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. namespace gpu {
  12. // A collection of tests that exercise the GL_EXT_srgb extension.
  13. class GLVirtualContextsEXTWindowRectanglesTest : public testing::Test {
  14. protected:
  15. void SetUp() override {
  16. GLManager::Options options;
  17. options.context_type = CONTEXT_TYPE_OPENGLES3;
  18. gl_real_shared_.Initialize(options);
  19. if (!IsApplicable())
  20. return;
  21. options.virtual_manager = &gl_real_shared_;
  22. gl1_.Initialize(options);
  23. gl2_.Initialize(options);
  24. }
  25. void TearDown() override {
  26. if (IsApplicable()) {
  27. gl1_.Destroy();
  28. gl2_.Destroy();
  29. }
  30. gl_real_shared_.Destroy();
  31. }
  32. bool IsApplicable() const {
  33. // Not applicable for devices not supporting OpenGLES3.
  34. if (!gl_real_shared_.IsInitialized()) {
  35. return false;
  36. }
  37. bool have_ext = GLTestHelper::HasExtension("GL_EXT_window_rectangles");
  38. return have_ext;
  39. }
  40. GLManager gl_real_shared_;
  41. GLManager gl1_;
  42. GLManager gl2_;
  43. };
  44. TEST_F(GLVirtualContextsEXTWindowRectanglesTest, Basic) {
  45. if (!IsApplicable()) {
  46. return;
  47. }
  48. // Context 1: Set window rectangles state.
  49. gl1_.MakeCurrent();
  50. {
  51. GLint box[12] = {};
  52. for (int i = 0; i < 12; ++i) {
  53. box[i] = i;
  54. }
  55. glWindowRectanglesEXT(GL_INCLUSIVE_EXT, 3, box);
  56. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  57. }
  58. // Context 2: Make sure it still has the default state.
  59. gl2_.MakeCurrent();
  60. {
  61. GLint max = -1;
  62. {
  63. glGetIntegerv(GL_MAX_WINDOW_RECTANGLES_EXT, &max);
  64. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  65. EXPECT_GE(max, 4);
  66. }
  67. {
  68. int mode = -1;
  69. glGetIntegerv(GL_WINDOW_RECTANGLE_MODE_EXT, &mode);
  70. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  71. EXPECT_EQ(GL_EXCLUSIVE_EXT, mode);
  72. }
  73. {
  74. GLint num = -1;
  75. glGetIntegerv(GL_NUM_WINDOW_RECTANGLES_EXT, &num);
  76. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  77. EXPECT_EQ(0, num);
  78. }
  79. for (int i = 0; i < max; ++i) {
  80. GLint rect[4] = {-1, -1, -1, -1};
  81. glGetIntegeri_v(GL_WINDOW_RECTANGLE_EXT, i, rect);
  82. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  83. EXPECT_EQ(0, rect[0]);
  84. EXPECT_EQ(0, rect[1]);
  85. EXPECT_EQ(0, rect[2]);
  86. EXPECT_EQ(0, rect[3]);
  87. }
  88. }
  89. // Context 1: Make sure it still has the state it set.
  90. gl1_.MakeCurrent();
  91. {
  92. {
  93. int mode = -1;
  94. glGetIntegerv(GL_WINDOW_RECTANGLE_MODE_EXT, &mode);
  95. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  96. EXPECT_EQ(GL_INCLUSIVE_EXT, mode);
  97. }
  98. {
  99. GLint num = -1;
  100. glGetIntegerv(GL_NUM_WINDOW_RECTANGLES_EXT, &num);
  101. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  102. EXPECT_EQ(3, num);
  103. }
  104. for (int i = 0; i < 3; ++i) {
  105. GLint rect[4] = {-1, -1, -1, -1};
  106. glGetIntegeri_v(GL_WINDOW_RECTANGLE_EXT, i, rect);
  107. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  108. EXPECT_EQ(4 * i + 0, rect[0]);
  109. EXPECT_EQ(4 * i + 1, rect[1]);
  110. EXPECT_EQ(4 * i + 2, rect[2]);
  111. EXPECT_EQ(4 * i + 3, rect[3]);
  112. }
  113. }
  114. }
  115. } // namespace gpu