gl_fence_nv.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2014 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 "ui/gl/gl_fence_nv.h"
  5. #include "ui/gl/gl_bindings.h"
  6. namespace gl {
  7. GLFenceNV::GLFenceNV() {
  8. // What if either of these GL calls fails? TestFenceNV will return true.
  9. // See spec:
  10. // http://www.opengl.org/registry/specs/NV/fence.txt
  11. //
  12. // What should happen if TestFenceNV is called for a name before SetFenceNV
  13. // is called?
  14. // We generate an INVALID_OPERATION error, and return TRUE.
  15. // This follows the semantics for texture object names before
  16. // they are bound, in that they acquire their state upon binding.
  17. // We will arbitrarily return TRUE for consistency.
  18. glGenFencesNV(1, &fence_);
  19. ResetState();
  20. }
  21. bool GLFenceNV::ResetSupported() {
  22. return true;
  23. }
  24. void GLFenceNV::ResetState() {
  25. glSetFenceNV(fence_, GL_ALL_COMPLETED_NV);
  26. DCHECK(glIsFenceNV(fence_));
  27. glFlush();
  28. }
  29. bool GLFenceNV::HasCompleted() {
  30. DCHECK(glIsFenceNV(fence_));
  31. return !!glTestFenceNV(fence_);
  32. }
  33. void GLFenceNV::ClientWait() {
  34. DCHECK(glIsFenceNV(fence_));
  35. glFinishFenceNV(fence_);
  36. }
  37. void GLFenceNV::ServerWait() {
  38. DCHECK(glIsFenceNV(fence_));
  39. ClientWait();
  40. }
  41. GLFenceNV::~GLFenceNV() {
  42. if (fence_) {
  43. DCHECK(glIsFenceNV(fence_));
  44. glDeleteFencesNV(1, &fence_);
  45. }
  46. }
  47. void GLFenceNV::Invalidate() {
  48. fence_ = 0;
  49. }
  50. } // namespace gl