OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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/gfx/gl/gl_fence.h" | |
6 | |
7 #include "base/compiler_specific.h" | |
8 #include "ui/gfx/gl/gl_bindings.h" | |
9 #include "ui/gfx/gl/gl_context.h" | |
10 | |
11 namespace { | |
12 | |
13 class GLFenceNVFence: public gfx::GLFence { | |
14 public: | |
15 GLFenceNVFence() { | |
16 // What if either of these GL calls fails? TestFenceNV will return true. | |
17 // See spec: | |
18 // http://www.opengl.org/registry/specs/NV/fence.txt | |
19 // | |
20 // What should happen if TestFenceNV is called for a name before SetFenceNV | |
21 // is called? | |
22 // We generate an INVALID_OPERATION error, and return TRUE. | |
23 // This follows the semantics for texture object names before | |
24 // they are bound, in that they acquire their state upon binding. | |
25 // We will arbitrarily return TRUE for consistency. | |
26 glGenFencesNV(1, &fence_); | |
27 glSetFenceNV(fence_, GL_ALL_COMPLETED_NV); | |
28 glFlush(); | |
29 } | |
30 | |
31 virtual bool HasCompleted() OVERRIDE { | |
32 return IsContextLost() || glTestFenceNV(fence_); | |
33 } | |
34 | |
35 private: | |
36 ~GLFenceNVFence() { | |
37 glDeleteFencesNV(1, &fence_); | |
38 } | |
39 | |
40 GLuint fence_; | |
41 }; | |
42 | |
43 class GLFenceARBSync: public gfx::GLFence { | |
44 public: | |
45 GLFenceARBSync() { | |
46 sync_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); | |
47 glFlush(); | |
48 } | |
49 | |
50 virtual bool HasCompleted() OVERRIDE { | |
51 // Handle the case where FenceSync failed. | |
52 if (!sync_ || IsContextLost()) | |
53 return true; | |
54 | |
55 GLsizei length = 0; | |
56 GLsizei value = 0; | |
57 glGetSynciv(sync_, | |
58 GL_SYNC_STATUS, | |
59 1, // bufSize | |
60 &length, | |
61 &value); | |
62 return length == 1 && value == GL_SIGNALED; | |
63 } | |
64 | |
65 private: | |
66 ~GLFenceARBSync() { | |
67 glDeleteSync(sync_); | |
68 } | |
69 | |
70 GLsync sync_; | |
71 }; | |
72 | |
73 } // namespace | |
74 | |
75 namespace gfx { | |
76 | |
77 GLFence::GLFence() { | |
78 } | |
79 | |
80 GLFence::~GLFence() { | |
81 } | |
82 | |
83 // static | |
84 GLFence* GLFence::Create() { | |
85 if (gfx::g_GL_NV_fence) { | |
86 return new GLFenceNVFence(); | |
87 } else if (gfx::g_GL_ARB_sync) { | |
88 return new GLFenceARBSync(); | |
89 } else { | |
90 return NULL; | |
91 } | |
92 } | |
93 | |
94 // static | |
95 bool GLFence::IsContextLost() { | |
96 if (!gfx::g_GL_ARB_robustness) | |
97 return false; | |
98 | |
99 if (!gfx::GLContext::GetCurrent() || | |
100 !gfx::GLContext::GetCurrent()-> | |
101 WasAllocatedUsingARBRobustness()) | |
102 return false; | |
103 | |
104 GLenum status = glGetGraphicsResetStatusARB(); | |
105 return status != GL_NO_ERROR; | |
106 } | |
107 | |
108 } // namespace gfx | |
OLD | NEW |