Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / gl / gl_context.cc
index dc3a3e8..e358069 100644 (file)
@@ -26,6 +26,32 @@ base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky
     current_real_context_ = LAZY_INSTANCE_INITIALIZER;
 }  // namespace
 
+GLContext::ScopedReleaseCurrent::ScopedReleaseCurrent() : canceled_(false) {}
+
+GLContext::ScopedReleaseCurrent::~ScopedReleaseCurrent() {
+  if (!canceled_ && GetCurrent()) {
+    GetCurrent()->ReleaseCurrent(NULL);
+  }
+}
+
+void GLContext::ScopedReleaseCurrent::Cancel() {
+  canceled_ = true;
+}
+
+GLContext::FlushEvent::FlushEvent() {
+}
+
+GLContext::FlushEvent::~FlushEvent() {
+}
+
+void GLContext::FlushEvent::Signal() {
+  flag_.Set();
+}
+
+bool GLContext::FlushEvent::IsSignaled() {
+  return flag_.IsSet();
+}
+
 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) {
   if (!share_group_.get())
     share_group_ = new GLShareGroup;
@@ -40,6 +66,13 @@ GLContext::~GLContext() {
   }
 }
 
+scoped_refptr<GLContext::FlushEvent> GLContext::SignalFlush() {
+  DCHECK(IsCurrent(NULL));
+  scoped_refptr<FlushEvent> flush_event = new FlushEvent();
+  flush_events_.push_back(flush_event);
+  return flush_event;
+}
+
 bool GLContext::GetTotalGpuMemory(size_t* bytes) {
   DCHECK(bytes);
   *bytes = 0;
@@ -49,6 +82,10 @@ bool GLContext::GetTotalGpuMemory(size_t* bytes) {
 void GLContext::SetSafeToForceGpuSwitch() {
 }
 
+bool GLContext::ForceGpuSwitchIfNeeded() {
+  return true;
+}
+
 void GLContext::SetUnbindFboOnMakeCurrent() {
   NOTIMPLEMENTED();
 }
@@ -66,6 +103,13 @@ std::string GLContext::GetGLVersion() {
   return std::string(version ? version : "");
 }
 
+std::string GLContext::GetGLRenderer() {
+  DCHECK(IsCurrent(NULL));
+  const char *renderer =
+      reinterpret_cast<const char*>(glGetString(GL_RENDERER));
+  return std::string(renderer ? renderer : "");
+}
+
 bool GLContext::HasExtension(const char* name) {
   std::string extensions = GetExtensions();
   extensions += " ";
@@ -79,8 +123,9 @@ bool GLContext::HasExtension(const char* name) {
 const GLVersionInfo* GLContext::GetVersionInfo() {
   if(!version_info_) {
     std::string version = GetGLVersion();
+    std::string renderer = GetGLRenderer();
     version_info_ = scoped_ptr<GLVersionInfo>(
-        new GLVersionInfo(version.c_str()));
+        new GLVersionInfo(version.c_str(), renderer.c_str()));
   }
   return version_info_.get();
 }
@@ -117,6 +162,12 @@ GLContext* GLContext::GetRealCurrent() {
 void GLContext::SetCurrent(GLSurface* surface) {
   current_context_.Pointer()->Set(surface ? this : NULL);
   GLSurface::SetCurrent(surface);
+  // Leave the real GL api current so that unit tests work correctly.
+  // TODO(sievers): Remove this, but needs all gpu_unittest classes
+  // to create and make current a context.
+  if (!surface && GetGLImplementation() != kGLImplementationMockGL) {
+    SetGLApiToNoContext();
+  }
 }
 
 GLStateRestorer* GLContext::GetGLStateRestorer() {
@@ -152,6 +203,8 @@ void GLContext::SetupForVirtualization() {
 bool GLContext::MakeVirtuallyCurrent(
     GLContext* virtual_context, GLSurface* surface) {
   DCHECK(virtual_gl_api_);
+  if (!ForceGpuSwitchIfNeeded())
+    return false;
   return virtual_gl_api_->MakeCurrent(virtual_context, surface);
 }
 
@@ -164,6 +217,12 @@ void GLContext::SetRealGLApi() {
   SetGLToRealGLApi();
 }
 
+void GLContext::OnFlush() {
+  for (size_t n = 0; n < flush_events_.size(); n++)
+    flush_events_[n]->Signal();
+  flush_events_.clear();
+}
+
 GLContextReal::GLContextReal(GLShareGroup* share_group)
     : GLContext(share_group) {}