Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / browser / compositor / browser_compositor_view_private_mac.mm
index 90c8340..913b4b0 100644 (file)
 #include "base/lazy_instance.h"
 #include "base/message_loop/message_loop.h"
 #include "content/browser/compositor/gpu_process_transport_factory.h"
-#include "content/browser/renderer_host/compositing_iosurface_context_mac.h"
-#include "content/browser/renderer_host/compositing_iosurface_mac.h"
+#include "content/browser/compositor/io_surface_layer_mac.h"
+#include "content/browser/compositor/software_layer_mac.h"
 #include "content/browser/renderer_host/dip_util.h"
 #include "content/browser/renderer_host/render_widget_resize_helper.h"
-#include "content/browser/renderer_host/software_layer_mac.h"
 #include "content/common/gpu/surface_handle_types_mac.h"
 #include "content/public/browser/context_factory.h"
 #include "ui/base/cocoa/animation_utils.h"
@@ -61,6 +60,7 @@ BrowserCompositorViewMacInternal::BrowserCompositorViewMacInternal()
       native_widget_,
       content::GetContextFactory(),
       RenderWidgetResizeHelper::Get()->task_runner()));
+  compositor_->SetVisible(false);
 }
 
 BrowserCompositorViewMacInternal::~BrowserCompositorViewMacInternal() {
@@ -81,6 +81,7 @@ void BrowserCompositorViewMacInternal::SetClient(
   DCHECK(background_layer);
   [flipped_layer_ setBounds:[background_layer bounds]];
   [background_layer addSublayer:flipped_layer_];
+  compositor_->SetVisible(true);
 }
 
 void BrowserCompositorViewMacInternal::ResetClient() {
@@ -98,6 +99,7 @@ void BrowserCompositorViewMacInternal::ResetClient() {
   accelerated_output_surface_id_ = 0;
   last_swap_size_dip_ = gfx::Size();
 
+  compositor_->SetVisible(false);
   compositor_->SetScaleAndSize(1.0, gfx::Size(0, 0));
   compositor_->SetRootLayer(NULL);
   client_ = NULL;
@@ -110,7 +112,7 @@ bool BrowserCompositorViewMacInternal::HasFrameOfSize(
 
 int BrowserCompositorViewMacInternal::GetRendererID() const {
   if (io_surface_layer_)
-    return [io_surface_layer_ iosurface]->GetRendererID();
+    return [io_surface_layer_ rendererID];
   return 0;
 }
 
@@ -134,7 +136,7 @@ void BrowserCompositorViewMacInternal::GotAcceleratedFrame(
 
   // If there is no client and therefore no superview to draw into, early-out.
   if (!client_) {
-    AcceleratedLayerDidDrawFrame();
+    IOSurfaceLayerDidDrawFrame();
     return;
   }
 
@@ -180,7 +182,7 @@ void BrowserCompositorViewMacInternal::GotAcceleratedCAContextFrame(
 
   // Acknowledge the frame to unblock the compositor immediately (the GPU
   // process will do any required throttling).
-  AcceleratedLayerDidDrawFrame();
+  IOSurfaceLayerDidDrawFrame();
 
   // If this replacing a same-type layer, remove it now that the new layer is
   // in the hierarchy.
@@ -198,7 +200,7 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
     float scale_factor) {
   // In the layer is replaced, keep the old one around until after the new one
   // is installed to avoid flashes.
-  base::scoped_nsobject<CompositingIOSurfaceLayer> old_io_surface_layer =
+  base::scoped_nsobject<IOSurfaceLayer> old_io_surface_layer =
       io_surface_layer_;
 
   // Create or re-create an IOSurface layer if needed. If there already exists
@@ -206,35 +208,26 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
   // layer.
   bool needs_new_layer =
       !io_surface_layer_ ||
-      [io_surface_layer_ context]->HasBeenPoisoned() ||
-      [io_surface_layer_ iosurface]->scale_factor() != scale_factor;
+      [io_surface_layer_ hasBeenPoisoned] ||
+      [io_surface_layer_ scaleFactor] != scale_factor;
   if (needs_new_layer) {
-    scoped_refptr<content::CompositingIOSurfaceMac> iosurface =
-        content::CompositingIOSurfaceMac::Create();
-    if (!iosurface) {
-      LOG(ERROR) << "Failed to create CompositingIOSurfaceMac";
-    } else {
-      io_surface_layer_.reset([[CompositingIOSurfaceLayer alloc]
-          initWithIOSurface:iosurface
-            withScaleFactor:scale_factor
-                 withClient:this]);
-      if (io_surface_layer_)
-        [flipped_layer_ addSublayer:io_surface_layer_];
-      else
-        LOG(ERROR) << "Failed to create CompositingIOSurfaceLayer";
-    }
+    io_surface_layer_.reset(
+        [[IOSurfaceLayer alloc] initWithClient:this
+                               withScaleFactor:scale_factor]);
+    if (io_surface_layer_)
+      [flipped_layer_ addSublayer:io_surface_layer_];
+    else
+      LOG(ERROR) << "Failed to create IOSurfaceLayer";
   }
 
   // Open the provided IOSurface.
   if (io_surface_layer_) {
-    bool result = true;
-    gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
-        [io_surface_layer_ context]->cgl_context());
-    result = [io_surface_layer_ iosurface]->SetIOSurfaceWithContextCurrent(
-        [io_surface_layer_ context], io_surface_id, pixel_size, scale_factor);
+    bool result = [io_surface_layer_ gotFrameWithIOSurface:io_surface_id
+                                             withPixelSize:pixel_size
+                                           withScaleFactor:scale_factor];
     if (!result) {
       DestroyIOSurfaceLayer(io_surface_layer_);
-      LOG(ERROR) << "Failed open IOSurface in CompositingIOSurfaceLayer";
+      LOG(ERROR) << "Failed open IOSurface in IOSurfaceLayer";
     }
   }
 
@@ -242,8 +235,8 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
   // This frame will appear blank, the compositor will try to create another,
   // and maybe that will go better.
   if (!io_surface_layer_) {
-    LOG(ERROR) << "CompositingIOSurfaceLayer is nil, tab will be blank";
-    AcceleratedLayerHitError();
+    LOG(ERROR) << "IOSurfaceLayer is nil, tab will be blank";
+    IOSurfaceLayerHitError();
   }
 
   // Make the CALayer draw and set its size appropriately.
@@ -313,7 +306,7 @@ void BrowserCompositorViewMacInternal::DestroyCAContextLayer(
 }
 
 void BrowserCompositorViewMacInternal::DestroyIOSurfaceLayer(
-    base::scoped_nsobject<CompositingIOSurfaceLayer> io_surface_layer) {
+    base::scoped_nsobject<IOSurfaceLayer> io_surface_layer) {
   if (!io_surface_layer)
     return;
   [io_surface_layer resetClient];
@@ -329,7 +322,7 @@ void BrowserCompositorViewMacInternal::DestroySoftwareLayer() {
   software_layer_.reset();
 }
 
-bool BrowserCompositorViewMacInternal::AcceleratedLayerShouldAckImmediately()
+bool BrowserCompositorViewMacInternal::IOSurfaceLayerShouldAckImmediately()
     const {
   // If there is no client then the accelerated layer is not in the hierarchy
   // and will never draw.
@@ -338,7 +331,7 @@ bool BrowserCompositorViewMacInternal::AcceleratedLayerShouldAckImmediately()
   return client_->BrowserCompositorViewShouldAckImmediately();
 }
 
-void BrowserCompositorViewMacInternal::AcceleratedLayerDidDrawFrame() {
+void BrowserCompositorViewMacInternal::IOSurfaceLayerDidDrawFrame() {
   if (accelerated_output_surface_id_) {
     content::ImageTransportFactory::GetInstance()->OnSurfaceDisplayed(
         accelerated_output_surface_id_);
@@ -351,14 +344,13 @@ void BrowserCompositorViewMacInternal::AcceleratedLayerDidDrawFrame() {
   accelerated_latency_info_.clear();
 }
 
-void BrowserCompositorViewMacInternal::AcceleratedLayerHitError() {
+void BrowserCompositorViewMacInternal::IOSurfaceLayerHitError() {
   // Perform all acks that would have been done if the frame had succeeded, to
   // un-block the compositor and renderer.
-  AcceleratedLayerDidDrawFrame();
+  IOSurfaceLayerDidDrawFrame();
 
   // Poison the context being used and request a mulligan.
-  if (io_surface_layer_)
-    [io_surface_layer_ context]->PoisonContextAndSharegroup();
+  [io_surface_layer_ poisonContextAndSharegroup];
   compositor_->ScheduleFullRedraw();
 }