| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gl/gl_fence_nv.h" | 5 #include "ui/gl/gl_fence_nv.h" |
| 6 | 6 |
| 7 #include "ui/gl/gl_bindings.h" | 7 #include "ui/gl/gl_bindings.h" |
| 8 #include "ui/gl/gl_context.h" | |
| 9 | 8 |
| 10 namespace gfx { | 9 namespace gfx { |
| 11 | 10 |
| 12 GLFenceNV::GLFenceNV(bool flush) { | 11 GLFenceNV::GLFenceNV() { |
| 13 // What if either of these GL calls fails? TestFenceNV will return true. | 12 // What if either of these GL calls fails? TestFenceNV will return true. |
| 14 // See spec: | 13 // See spec: |
| 15 // http://www.opengl.org/registry/specs/NV/fence.txt | 14 // http://www.opengl.org/registry/specs/NV/fence.txt |
| 16 // | 15 // |
| 17 // What should happen if TestFenceNV is called for a name before SetFenceNV | 16 // What should happen if TestFenceNV is called for a name before SetFenceNV |
| 18 // is called? | 17 // is called? |
| 19 // We generate an INVALID_OPERATION error, and return TRUE. | 18 // We generate an INVALID_OPERATION error, and return TRUE. |
| 20 // This follows the semantics for texture object names before | 19 // This follows the semantics for texture object names before |
| 21 // they are bound, in that they acquire their state upon binding. | 20 // they are bound, in that they acquire their state upon binding. |
| 22 // We will arbitrarily return TRUE for consistency. | 21 // We will arbitrarily return TRUE for consistency. |
| 23 glGenFencesNV(1, &fence_); | 22 glGenFencesNV(1, &fence_); |
| 24 glSetFenceNV(fence_, GL_ALL_COMPLETED_NV); | 23 glSetFenceNV(fence_, GL_ALL_COMPLETED_NV); |
| 25 DCHECK(glIsFenceNV(fence_)); | 24 DCHECK(glIsFenceNV(fence_)); |
| 26 if (flush) { | 25 glFlush(); |
| 27 glFlush(); | |
| 28 } else { | |
| 29 flush_event_ = GLContext::GetCurrent()->SignalFlush(); | |
| 30 } | |
| 31 } | 26 } |
| 32 | 27 |
| 33 bool GLFenceNV::HasCompleted() { | 28 bool GLFenceNV::HasCompleted() { |
| 34 DCHECK(glIsFenceNV(fence_)); | 29 DCHECK(glIsFenceNV(fence_)); |
| 35 return !!glTestFenceNV(fence_); | 30 return !!glTestFenceNV(fence_); |
| 36 } | 31 } |
| 37 | 32 |
| 38 void GLFenceNV::ClientWait() { | 33 void GLFenceNV::ClientWait() { |
| 39 DCHECK(glIsFenceNV(fence_)); | 34 DCHECK(glIsFenceNV(fence_)); |
| 40 if (!flush_event_.get() || flush_event_->IsSignaled()) { | 35 glFinishFenceNV(fence_); |
| 41 glFinishFenceNV(fence_); | |
| 42 } else { | |
| 43 LOG(ERROR) << "Trying to wait for uncommitted fence. Skipping..."; | |
| 44 } | |
| 45 } | 36 } |
| 46 | 37 |
| 47 void GLFenceNV::ServerWait() { | 38 void GLFenceNV::ServerWait() { |
| 48 DCHECK(glIsFenceNV(fence_)); | 39 DCHECK(glIsFenceNV(fence_)); |
| 49 ClientWait(); | 40 ClientWait(); |
| 50 } | 41 } |
| 51 | 42 |
| 52 GLFenceNV::~GLFenceNV() { | 43 GLFenceNV::~GLFenceNV() { |
| 53 DCHECK(glIsFenceNV(fence_)); | 44 DCHECK(glIsFenceNV(fence_)); |
| 54 glDeleteFencesNV(1, &fence_); | 45 glDeleteFencesNV(1, &fence_); |
| 55 } | 46 } |
| 56 | 47 |
| 57 } // namespace gfx | 48 } // namespace gfx |
| OLD | NEW |