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