gl_offscreen_surface_unittest.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright (c) 2018 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 <GLES2/gl2extchromium.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. // Test that an offscreen surface with zero size initializes correctly
  13. TEST(OffscreenSurfaceTest, ZeroInitialSize) {
  14. GLManager::Options options;
  15. options.size = gfx::Size(0, 0);
  16. options.context_type = CONTEXT_TYPE_OPENGLES2;
  17. GLManager gl;
  18. gl.Initialize(options);
  19. ASSERT_TRUE(gl.IsInitialized());
  20. gl.Destroy();
  21. }
  22. // Test that an offscreen surface can be resized to zero
  23. TEST(OffscreenSurfaceTest, ResizeToZero) {
  24. GLManager::Options options;
  25. options.size = gfx::Size(4, 4);
  26. options.context_type = CONTEXT_TYPE_OPENGLES2;
  27. GLManager gl;
  28. gl.Initialize(options);
  29. ASSERT_TRUE(gl.IsInitialized());
  30. gl.MakeCurrent();
  31. // If losing the context will cause the process to exit, do not perform this
  32. // test as it will cause all subsequent tests to not run.
  33. if (gl.workarounds().exit_on_context_lost) {
  34. gl.Destroy();
  35. return;
  36. }
  37. // Generates context loss and fails the test if the resize fails.
  38. gfx::ColorSpace color_space = gfx::ColorSpace::CreateSRGB();
  39. glResizeCHROMIUM(0, 0, 1.0f, color_space.AsGLColorSpace(), GL_TRUE);
  40. gl.Destroy();
  41. }
  42. // Resize to a number between maximum int and uint
  43. TEST(OffscreenSurfaceTest, ResizeOverflow) {
  44. GLManager::Options options;
  45. options.size = gfx::Size(4, 4);
  46. options.context_type = CONTEXT_TYPE_OPENGLES2;
  47. options.context_lost_allowed = true;
  48. GLManager gl;
  49. gl.Initialize(options);
  50. ASSERT_TRUE(gl.IsInitialized());
  51. gl.MakeCurrent();
  52. // If losing the context will cause the process to exit, do not perform this
  53. // test as it will cause all subsequent tests to not run.
  54. if (gl.workarounds().exit_on_context_lost) {
  55. gl.Destroy();
  56. return;
  57. }
  58. // Context loss is allowed trying to resize to such a huge value but make sure
  59. // that no asserts or undefined behavior is triggered
  60. static const GLuint kLargeSize =
  61. static_cast<GLuint>(std::numeric_limits<int>::max()) + 10;
  62. gfx::ColorSpace color_space = gfx::ColorSpace::CreateSRGB();
  63. glResizeCHROMIUM(kLargeSize, 1, 1.0f, color_space.AsGLColorSpace(), GL_TRUE);
  64. gl.Destroy();
  65. }
  66. } // namespace gpu