WebGL2ContextSync.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "WebGL2Context.h"
  6. #include "GLContext.h"
  7. #include "WebGLSync.h"
  8. namespace mozilla {
  9. // -------------------------------------------------------------------------
  10. // Sync objects
  11. already_AddRefed<WebGLSync>
  12. WebGL2Context::FenceSync(GLenum condition, GLbitfield flags)
  13. {
  14. if (IsContextLost())
  15. return nullptr;
  16. if (condition != LOCAL_GL_SYNC_GPU_COMMANDS_COMPLETE) {
  17. ErrorInvalidEnum("fenceSync: condition must be SYNC_GPU_COMMANDS_COMPLETE");
  18. return nullptr;
  19. }
  20. if (flags != 0) {
  21. ErrorInvalidValue("fenceSync: flags must be 0");
  22. return nullptr;
  23. }
  24. MakeContextCurrent();
  25. RefPtr<WebGLSync> globj = new WebGLSync(this, condition, flags);
  26. return globj.forget();
  27. }
  28. bool
  29. WebGL2Context::IsSync(const WebGLSync* sync)
  30. {
  31. if (!ValidateIsObject("isSync", sync))
  32. return false;
  33. return true;
  34. }
  35. void
  36. WebGL2Context::DeleteSync(WebGLSync* sync)
  37. {
  38. if (!ValidateDeleteObject("deleteSync", sync))
  39. return;
  40. sync->RequestDelete();
  41. }
  42. GLenum
  43. WebGL2Context::ClientWaitSync(const WebGLSync& sync, GLbitfield flags, GLuint64 timeout)
  44. {
  45. const char funcName[] = "clientWaitSync";
  46. if (IsContextLost())
  47. return LOCAL_GL_WAIT_FAILED;
  48. if (!ValidateObject(funcName, sync))
  49. return LOCAL_GL_WAIT_FAILED;
  50. if (flags != 0 && flags != LOCAL_GL_SYNC_FLUSH_COMMANDS_BIT) {
  51. ErrorInvalidValue("%s: `flags` must be SYNC_FLUSH_COMMANDS_BIT or 0.", funcName);
  52. return LOCAL_GL_WAIT_FAILED;
  53. }
  54. if (timeout > kMaxClientWaitSyncTimeoutNS) {
  55. ErrorInvalidOperation("%s: `timeout` must not exceed %s nanoseconds.", funcName,
  56. "MAX_CLIENT_WAIT_TIMEOUT_WEBGL");
  57. return LOCAL_GL_WAIT_FAILED;
  58. }
  59. MakeContextCurrent();
  60. return gl->fClientWaitSync(sync.mGLName, flags, timeout);
  61. }
  62. void
  63. WebGL2Context::WaitSync(const WebGLSync& sync, GLbitfield flags, GLint64 timeout)
  64. {
  65. const char funcName[] = "waitSync";
  66. if (IsContextLost())
  67. return;
  68. if (!ValidateObject(funcName, sync))
  69. return;
  70. if (flags != 0) {
  71. ErrorInvalidValue("%s: `flags` must be 0.", funcName);
  72. return;
  73. }
  74. if (timeout != -1) {
  75. ErrorInvalidValue("%s: `timeout` must be TIMEOUT_IGNORED.", funcName);
  76. return;
  77. }
  78. MakeContextCurrent();
  79. gl->fWaitSync(sync.mGLName, flags, LOCAL_GL_TIMEOUT_IGNORED);
  80. }
  81. void
  82. WebGL2Context::GetSyncParameter(JSContext*, const WebGLSync& sync, GLenum pname,
  83. JS::MutableHandleValue retval)
  84. {
  85. const char funcName[] = "getSyncParameter";
  86. retval.setNull();
  87. if (IsContextLost())
  88. return;
  89. if (!ValidateObject(funcName, sync))
  90. return;
  91. ////
  92. gl->MakeCurrent();
  93. GLint result = 0;
  94. switch (pname) {
  95. case LOCAL_GL_OBJECT_TYPE:
  96. case LOCAL_GL_SYNC_STATUS:
  97. case LOCAL_GL_SYNC_CONDITION:
  98. case LOCAL_GL_SYNC_FLAGS:
  99. gl->fGetSynciv(sync.mGLName, pname, 1, nullptr, &result);
  100. retval.set(JS::Int32Value(result));
  101. return;
  102. default:
  103. ErrorInvalidEnum("%s: Invalid pname 0x%04x", funcName, pname);
  104. return;
  105. }
  106. }
  107. } // namespace mozilla