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