| 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_arb.h" | 5 #include "ui/gl/gl_fence_arb.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "ui/gl/gl_bindings.h" | 8 #include "ui/gl/gl_bindings.h" |
| 9 #include "ui/gl/gl_context.h" | |
| 10 | 9 |
| 11 namespace gfx { | 10 namespace gfx { |
| 12 | 11 |
| 13 namespace { | 12 namespace { |
| 14 | 13 |
| 15 std::string GetGLErrors() { | 14 std::string GetGLErrors() { |
| 16 // Clears and logs all current gl errors. | 15 // Clears and logs all current gl errors. |
| 17 std::string accumulated_errors; | 16 std::string accumulated_errors; |
| 18 GLenum error; | 17 GLenum error; |
| 19 while ((error = glGetError()) != GL_NO_ERROR) { | 18 while ((error = glGetError()) != GL_NO_ERROR) { |
| 20 accumulated_errors += base::StringPrintf("0x%x ", error); | 19 accumulated_errors += base::StringPrintf("0x%x ", error); |
| 21 } | 20 } |
| 22 return accumulated_errors; | 21 return accumulated_errors; |
| 23 } | 22 } |
| 24 | 23 |
| 25 } // namespace | 24 } // namespace |
| 26 | 25 |
| 27 GLFenceARB::GLFenceARB(bool flush) { | 26 GLFenceARB::GLFenceARB() { |
| 28 sync_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); | 27 sync_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); |
| 29 DCHECK_EQ(GL_TRUE, glIsSync(sync_)); | 28 DCHECK_EQ(GL_TRUE, glIsSync(sync_)); |
| 30 if (flush) { | 29 glFlush(); |
| 31 glFlush(); | |
| 32 } else { | |
| 33 flush_event_ = GLContext::GetCurrent()->SignalFlush(); | |
| 34 } | |
| 35 } | 30 } |
| 36 | 31 |
| 37 bool GLFenceARB::HasCompleted() { | 32 bool GLFenceARB::HasCompleted() { |
| 38 // Handle the case where FenceSync failed. | 33 // Handle the case where FenceSync failed. |
| 39 if (!sync_) | 34 if (!sync_) |
| 40 return true; | 35 return true; |
| 41 | 36 |
| 42 DCHECK_EQ(GL_TRUE, glIsSync(sync_)); | 37 DCHECK_EQ(GL_TRUE, glIsSync(sync_)); |
| 43 // We could potentially use glGetSynciv here, but it doesn't work | 38 // We could potentially use glGetSynciv here, but it doesn't work |
| 44 // on OSX 10.7 (always says the fence is not signaled yet). | 39 // on OSX 10.7 (always says the fence is not signaled yet). |
| 45 // glClientWaitSync works better, so let's use that instead. | 40 // glClientWaitSync works better, so let's use that instead. |
| 46 GLenum result = glClientWaitSync(sync_, 0, 0); | 41 GLenum result = glClientWaitSync(sync_, 0, 0); |
| 47 if (result == GL_WAIT_FAILED) { | 42 if (result == GL_WAIT_FAILED) { |
| 48 LOG(FATAL) << "Failed to wait for GLFence. error code:" << GetGLErrors(); | 43 LOG(FATAL) << "Failed to wait for GLFence. error code:" << GetGLErrors(); |
| 49 } | 44 } |
| 50 return result != GL_TIMEOUT_EXPIRED; | 45 return result != GL_TIMEOUT_EXPIRED; |
| 51 } | 46 } |
| 52 | 47 |
| 53 void GLFenceARB::ClientWait() { | 48 void GLFenceARB::ClientWait() { |
| 54 DCHECK_EQ(GL_TRUE, glIsSync(sync_)); | 49 DCHECK_EQ(GL_TRUE, glIsSync(sync_)); |
| 55 if (!flush_event_.get() || flush_event_->IsSignaled()) { | 50 GLenum result = |
| 56 GLenum result = | 51 glClientWaitSync(sync_, GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED); |
| 57 glClientWaitSync(sync_, GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED); | 52 DCHECK_NE(static_cast<GLenum>(GL_TIMEOUT_EXPIRED), result); |
| 58 DCHECK_NE(static_cast<GLenum>(GL_TIMEOUT_EXPIRED), result); | 53 if (result == GL_WAIT_FAILED) { |
| 59 if (result == GL_WAIT_FAILED) { | 54 LOG(FATAL) << "Failed to wait for GLFence. error code:" << GetGLErrors(); |
| 60 LOG(FATAL) << "Failed to wait for GLFence. error code:" << GetGLErrors(); | |
| 61 } | |
| 62 } else { | |
| 63 LOG(ERROR) << "Trying to wait for uncommitted fence. Skipping..."; | |
| 64 } | 55 } |
| 65 } | 56 } |
| 66 | 57 |
| 67 void GLFenceARB::ServerWait() { | 58 void GLFenceARB::ServerWait() { |
| 68 DCHECK_EQ(GL_TRUE, glIsSync(sync_)); | 59 DCHECK_EQ(GL_TRUE, glIsSync(sync_)); |
| 69 if (!flush_event_.get() || flush_event_->IsSignaled()) { | 60 glWaitSync(sync_, 0, GL_TIMEOUT_IGNORED); |
| 70 glWaitSync(sync_, 0, GL_TIMEOUT_IGNORED); | |
| 71 } else { | |
| 72 LOG(ERROR) << "Trying to wait for uncommitted fence. Skipping..."; | |
| 73 } | |
| 74 } | 61 } |
| 75 | 62 |
| 76 GLFenceARB::~GLFenceARB() { | 63 GLFenceARB::~GLFenceARB() { |
| 77 DCHECK_EQ(GL_TRUE, glIsSync(sync_)); | 64 DCHECK_EQ(GL_TRUE, glIsSync(sync_)); |
| 78 glDeleteSync(sync_); | 65 glDeleteSync(sync_); |
| 79 } | 66 } |
| 80 | 67 |
| 81 } // namespace gfx | 68 } // namespace gfx |
| OLD | NEW |