Bug 1048721 - Implement WebGL2Sync. r=jgilbert

This commit is contained in:
Dan Glastonbury 2014-06-18 14:25:53 +10:00
parent 57f2d0718c
commit 483e253e65
4 changed files with 105 additions and 17 deletions

View File

@ -4,7 +4,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WebGL2Context.h" #include "WebGL2Context.h"
#include "GLContext.h" #include "GLContext.h"
#include "WebGLSync.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; using namespace mozilla::dom;
@ -15,38 +17,117 @@ using namespace mozilla::dom;
already_AddRefed<WebGLSync> already_AddRefed<WebGLSync>
WebGL2Context::FenceSync(GLenum condition, GLbitfield flags) WebGL2Context::FenceSync(GLenum condition, GLbitfield flags)
{ {
MOZ_CRASH("Not Implemented."); if (IsContextLost())
return nullptr; return nullptr;
if (condition != LOCAL_GL_SYNC_GPU_COMMANDS_COMPLETE) {
ErrorInvalidEnum("fenceSync: condition must be SYNC_GPU_COMMANDS_COMPLETE");
return nullptr;
}
if (flags != 0) {
ErrorInvalidValue("fenceSync: flags must be 0");
return nullptr;
}
MakeContextCurrent();
nsRefPtr<WebGLSync> globj = new WebGLSync(this, condition, flags);
return globj.forget();
} }
bool bool
WebGL2Context::IsSync(WebGLSync* sync) WebGL2Context::IsSync(WebGLSync* sync)
{ {
MOZ_CRASH("Not Implemented."); if (IsContextLost())
return false; return false;
return ValidateObjectAllowDeleted("isSync", sync) && !sync->IsDeleted();
} }
void void
WebGL2Context::DeleteSync(WebGLSync* sync) WebGL2Context::DeleteSync(WebGLSync* sync)
{ {
MOZ_CRASH("Not Implemented."); if (IsContextLost())
return;
if (!ValidateObjectAllowDeletedOrNull("deleteSync", sync))
return;
if (!sync || sync->IsDeleted())
return;
sync->RequestDelete();
} }
GLenum GLenum
WebGL2Context::ClientWaitSync(WebGLSync* sync, GLbitfield flags, GLuint64 timeout) WebGL2Context::ClientWaitSync(WebGLSync* sync, GLbitfield flags, GLuint64 timeout)
{ {
MOZ_CRASH("Not Implemented."); if (IsContextLost())
return LOCAL_GL_FALSE; return LOCAL_GL_WAIT_FAILED;
if (!sync || sync->IsDeleted()) {
ErrorInvalidValue("clientWaitSync: sync is not a sync object.");
return LOCAL_GL_WAIT_FAILED;
}
if (flags != 0 && flags != LOCAL_GL_SYNC_FLUSH_COMMANDS_BIT) {
ErrorInvalidValue("clientWaitSync: flag must be SYNC_FLUSH_COMMANDS_BIT or 0");
return LOCAL_GL_WAIT_FAILED;
}
MakeContextCurrent();
return gl->fClientWaitSync(sync->mGLName, flags, timeout);
} }
void void
WebGL2Context::WaitSync(WebGLSync* sync, GLbitfield flags, GLuint64 timeout) WebGL2Context::WaitSync(WebGLSync* sync, GLbitfield flags, GLuint64 timeout)
{ {
MOZ_CRASH("Not Implemented."); if (IsContextLost())
return;
if (!sync || sync->IsDeleted()) {
ErrorInvalidValue("waitSync: sync is not a sync object.");
return;
}
if (flags != 0) {
ErrorInvalidValue("waitSync: flags must be 0");
return;
}
if (timeout != LOCAL_GL_TIMEOUT_IGNORED) {
ErrorInvalidValue("waitSync: timeout must be TIMEOUT_IGNORED");
return;
}
MakeContextCurrent();
gl->fWaitSync(sync->mGLName, flags, timeout);
} }
void void
WebGL2Context::GetSyncParameter(JSContext*, WebGLSync* sync, GLenum pname, JS::MutableHandleValue retval) WebGL2Context::GetSyncParameter(JSContext*, WebGLSync* sync, GLenum pname, JS::MutableHandleValue retval)
{ {
MOZ_CRASH("Not Implemented."); if (IsContextLost())
return;
if (!sync || sync->IsDeleted()) {
ErrorInvalidValue("getSyncParameter: sync is not a sync object.");
return;
}
retval.set(JS::NullValue());
GLint result = 0;
switch (pname) {
case LOCAL_GL_OBJECT_TYPE:
case LOCAL_GL_SYNC_STATUS:
case LOCAL_GL_SYNC_CONDITION:
case LOCAL_GL_SYNC_FLAGS:
MakeContextCurrent();
gl->fGetSynciv(sync->mGLName, pname, 1, nullptr, &result);
retval.set(JS::Int32Value(result));
break;
}
ErrorInvalidEnum("getSyncParameter: Invalid pname 0x%04x", pname);
} }

View File

@ -1591,6 +1591,7 @@ public:
friend class WebGLBuffer; friend class WebGLBuffer;
friend class WebGLSampler; friend class WebGLSampler;
friend class WebGLShader; friend class WebGLShader;
friend class WebGLSync;
friend class WebGLTransformFeedback; friend class WebGLTransformFeedback;
friend class WebGLUniformLocation; friend class WebGLUniformLocation;
friend class WebGLVertexArray; friend class WebGLVertexArray;

View File

@ -9,26 +9,30 @@
namespace mozilla { namespace mozilla {
WebGLSync::WebGLSync(WebGLContext* webgl): WebGLSync::WebGLSync(WebGLContext* webgl, GLenum condition, GLbitfield flags)
WebGLContextBoundObject(webgl) : WebGLContextBoundObject(webgl)
{ {
MOZ_CRASH("Not Implemented."); mGLName = mContext->gl->fFenceSync(condition, flags);
} }
WebGLSync::~WebGLSync() WebGLSync::~WebGLSync()
{} {
DeleteOnce();
}
void void
WebGLSync::Delete() WebGLSync::Delete()
{ {
MOZ_CRASH("Not Implemented."); mContext->MakeContextCurrent();
mContext->gl->fDeleteSync(mGLName);
mGLName = 0;
LinkedListElement<WebGLSync>::remove();
} }
WebGLContext* WebGLContext*
WebGLSync::GetParentObject() const WebGLSync::GetParentObject() const
{ {
MOZ_CRASH("Not Implemented."); return Context();
return nullptr;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------

View File

@ -21,7 +21,7 @@ class WebGLSync final
friend class WebGL2Context; friend class WebGL2Context;
public: public:
explicit WebGLSync(WebGLContext* webgl); WebGLSync(WebGLContext* webgl, GLenum condition, GLbitfield flags);
void Delete(); void Delete();
WebGLContext* GetParentObject() const; WebGLContext* GetParentObject() const;
@ -33,6 +33,8 @@ public:
private: private:
~WebGLSync(); ~WebGLSync();
GLsync mGLName;
}; };
} // namespace mozilla } // namespace mozilla