Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / aura / bench / bench_main.cc
index ff0d32d..f2eadee 100644 (file)
@@ -33,6 +33,7 @@
 #include "ui/gfx/canvas.h"
 #include "ui/gfx/rect.h"
 #include "ui/gfx/skia_util.h"
+#include "ui/gfx/x/x11_connection.h"
 #include "ui/gl/gl_surface.h"
 
 #ifndef GL_GLEXT_PROTOTYPES
 #endif
 #include "third_party/khronos/GLES2/gl2ext.h"
 
-#if defined(USE_X11)
-#include "base/message_loop/message_pump_x11.h"
-#endif
-
 using base::TimeTicks;
 using ui::Compositor;
 using ui::Layer;
@@ -138,36 +135,15 @@ class BenchCompositorObserver : public ui::CompositorObserver {
   DISALLOW_COPY_AND_ASSIGN(BenchCompositorObserver);
 };
 
-class WebGLTexture : public ui::Texture {
- public:
-  WebGLTexture(gpu::gles2::GLES2Interface* gl, const gfx::Size& size)
-      : ui::Texture(false, size, 1.0f),
-        gl_(gl),
-        texture_id_(0u) {
-    gl->GenTextures(1, &texture_id_);
-    gl->BindTexture(GL_TEXTURE_2D, texture_id_);
-    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-    gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(),
-                   0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-  }
-
-  virtual unsigned int PrepareTexture() OVERRIDE {
-    return texture_id_;
-  }
-
- private:
-  virtual ~WebGLTexture() {
-    gl_->DeleteTextures(1, &texture_id_);
-  }
-
-  gpu::gles2::GLES2Interface* gl_;
-  GLuint texture_id_;
-
-  DISALLOW_COPY_AND_ASSIGN(WebGLTexture);
-};
+void ReturnMailbox(scoped_refptr<cc::ContextProvider> context_provider,
+                   GLuint texture,
+                   GLuint sync_point,
+                   bool is_lost) {
+  gpu::gles2::GLES2Interface* gl = context_provider->ContextGL();
+  gl->WaitSyncPointCHROMIUM(sync_point);
+  gl->DeleteTextures(1, &texture);
+  gl->ShallowFlushCHROMIUM();
+}
 
 // A benchmark that adds a texture layer that is updated every frame.
 class WebGLBench : public BenchCompositorObserver {
@@ -177,7 +153,6 @@ class WebGLBench : public BenchCompositorObserver {
         parent_(parent),
         webgl_(ui::LAYER_TEXTURED),
         compositor_(compositor),
-        texture_(),
         fbo_(0),
         do_draw_(true) {
     CommandLine* command_line = CommandLine::ForCurrentProcess();
@@ -205,23 +180,47 @@ class WebGLBench : public BenchCompositorObserver {
     context_provider_ =
         ui::ContextFactory::GetInstance()->SharedMainThreadContextProvider();
     gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
-    texture_ = new WebGLTexture(gl, bounds.size());
+    GLuint texture = 0;
+    gl->GenTextures(1, &texture);
+    gl->BindTexture(GL_TEXTURE_2D, texture);
+    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+    gl->TexImage2D(GL_TEXTURE_2D,
+                   0,
+                   GL_RGBA,
+                   width,
+                   height,
+                   0,
+                   GL_RGBA,
+                   GL_UNSIGNED_BYTE,
+                   NULL);
+    gpu::Mailbox mailbox;
+    gl->GenMailboxCHROMIUM(mailbox.name);
+    gl->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
+
     gl->GenFramebuffers(1, &fbo_);
-    compositor->AddObserver(this);
-    webgl_.SetExternalTexture(texture_.get());
     gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
     gl->FramebufferTexture2D(
-        GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
-        GL_TEXTURE_2D, texture_->PrepareTexture(), 0);
+        GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
     gl->ClearColor(0.f, 1.f, 0.f, 1.f);
     gl->Clear(GL_COLOR_BUFFER_BIT);
     gl->Flush();
+
+    GLuint sync_point = gl->InsertSyncPointCHROMIUM();
+    webgl_.SetTextureMailbox(
+        cc::TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point),
+        cc::SingleReleaseCallback::Create(
+            base::Bind(ReturnMailbox, context_provider_, texture)),
+        bounds.size());
+    compositor->AddObserver(this);
   }
 
   virtual ~WebGLBench() {
-    context_provider_->ContextGL()->DeleteFramebuffers(1, &fbo_);
     webgl_.SetShowPaintedContent();
-    texture_ = NULL;
+    gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
+    gl->DeleteFramebuffers(1, &fbo_);
     compositor_->RemoveObserver(this);
   }
 
@@ -232,7 +231,6 @@ class WebGLBench : public BenchCompositorObserver {
       gl->Clear(GL_COLOR_BUFFER_BIT);
       gl->Flush();
     }
-    webgl_.SetExternalTexture(texture_.get());
     webgl_.SchedulePaint(gfx::Rect(webgl_.bounds().size()));
     compositor_->ScheduleDraw();
   }
@@ -242,7 +240,6 @@ class WebGLBench : public BenchCompositorObserver {
   Layer webgl_;
   Compositor* compositor_;
   scoped_refptr<cc::ContextProvider> context_provider_;
-  scoped_refptr<WebGLTexture> texture_;
 
   // The FBO that is used to render to the texture.
   unsigned int fbo_;
@@ -294,7 +291,7 @@ int main(int argc, char** argv) {
 #if defined(USE_X11)
   // This demo uses InProcessContextFactory which uses X on a separate Gpu
   // thread.
-  XInitThreads();
+  gfx::InitializeThreadedX11();
 #endif
 
   gfx::GLSurface::InitializeOneOff();
@@ -307,7 +304,7 @@ int main(int argc, char** argv) {
   base::i18n::InitializeICU();
 
   base::MessageLoopForUI message_loop;
-  aura::Env::CreateInstance();
+  aura::Env::CreateInstance(true);
   scoped_ptr<aura::TestScreen> test_screen(
       aura::TestScreen::CreateFullscreen());
   gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());