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.
5 #include "ui/gl/gl_fence_nv.h"
7 #include "ui/gl/gl_bindings.h"
8 #include "ui/gl/gl_context.h"
12 GLFenceNV::GLFenceNV(bool flush
) {
13 // What if either of these GL calls fails? TestFenceNV will return true.
15 // http://www.opengl.org/registry/specs/NV/fence.txt
17 // What should happen if TestFenceNV is called for a name before SetFenceNV
19 // We generate an INVALID_OPERATION error, and return TRUE.
20 // This follows the semantics for texture object names before
21 // they are bound, in that they acquire their state upon binding.
22 // We will arbitrarily return TRUE for consistency.
23 glGenFencesNV(1, &fence_
);
24 glSetFenceNV(fence_
, GL_ALL_COMPLETED_NV
);
25 DCHECK(glIsFenceNV(fence_
));
29 flush_event_
= GLContext::GetCurrent()->SignalFlush();
33 bool GLFenceNV::HasCompleted() {
34 DCHECK(glIsFenceNV(fence_
));
35 return !!glTestFenceNV(fence_
);
38 void GLFenceNV::ClientWait() {
39 DCHECK(glIsFenceNV(fence_
));
40 if (!flush_event_
.get() || flush_event_
->IsSignaled()) {
41 glFinishFenceNV(fence_
);
43 LOG(ERROR
) << "Trying to wait for uncommitted fence. Skipping...";
47 void GLFenceNV::ServerWait() {
48 DCHECK(glIsFenceNV(fence_
));
52 GLFenceNV::~GLFenceNV() {
53 DCHECK(glIsFenceNV(fence_
));
54 glDeleteFencesNV(1, &fence_
);