With the overlay path moving back to passing AcceleratedWidgets, move the implementation back into the surface factory.

This is https://codereview.chromium.org/445163003/ plus unittest fixes.
[email protected]
NOTRY=true

Review URL: https://codereview.chromium.org/452163002

Cr-Commit-Position: refs/heads/master@{#288738}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288738 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ui/ozone/platform/dri/dri_surface.cc b/ui/ozone/platform/dri/dri_surface.cc
index 57740a30..d0d4f56 100644
--- a/ui/ozone/platform/dri/dri_surface.cc
+++ b/ui/ozone/platform/dri/dri_surface.cc
@@ -71,11 +71,10 @@
   if (!controller_)
     return;
 
-  std::vector<OverlayPlane> planes(
-      1, OverlayPlane(buffers_[front_buffer_ ^ 1]));
+  controller_->QueueOverlayPlane(OverlayPlane(buffers_[front_buffer_ ^ 1]));
 
   UpdateNativeSurface(damage);
-  controller_->SchedulePageFlip(planes);
+  controller_->SchedulePageFlip();
   controller_->WaitForPageFlipEvent();
 
   // Update our front buffer pointer.
diff --git a/ui/ozone/platform/dri/gbm_surface.cc b/ui/ozone/platform/dri/gbm_surface.cc
index c776d6b3..86ff174c 100644
--- a/ui/ozone/platform/dri/gbm_surface.cc
+++ b/ui/ozone/platform/dri/gbm_surface.cc
@@ -135,7 +135,7 @@
   }
 
   // The primary buffer is a special case.
-  queued_planes_.push_back(OverlayPlane(primary));
+  controller_->QueueOverlayPlane(OverlayPlane(primary));
 
   if (!GbmSurfaceless::OnSwapBuffers())
     return false;
diff --git a/ui/ozone/platform/dri/gbm_surface_factory.cc b/ui/ozone/platform/dri/gbm_surface_factory.cc
index 7e5dc34..6f1d1833 100644
--- a/ui/ozone/platform/dri/gbm_surface_factory.cc
+++ b/ui/ozone/platform/dri/gbm_surface_factory.cc
@@ -123,6 +123,30 @@
   return scoped_refptr<GbmPixmap>(new GbmPixmap(buffer));
 }
 
+bool GbmSurfaceFactory::ScheduleOverlayPlane(
+    gfx::AcceleratedWidget widget,
+    int plane_z_order,
+    gfx::OverlayTransform plane_transform,
+    scoped_refptr<NativePixmap> buffer,
+    const gfx::Rect& display_bounds,
+    const gfx::RectF& crop_rect) {
+  scoped_refptr<GbmPixmap> pixmap = static_cast<GbmPixmap*>(buffer.get());
+  if (!pixmap) {
+    LOG(ERROR) << "ScheduleOverlayPlane passed NULL buffer.";
+    return false;
+  }
+  base::WeakPtr<HardwareDisplayController> hdc =
+      screen_manager_->GetDisplayController(widget);
+  if (!hdc)
+    return true;
+  hdc->QueueOverlayPlane(OverlayPlane(pixmap->buffer(),
+                                      plane_z_order,
+                                      plane_transform,
+                                      display_bounds,
+                                      crop_rect));
+  return true;
+}
+
 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() {
   return allow_surfaceless_;
 }
diff --git a/ui/ozone/platform/dri/gbm_surface_factory.h b/ui/ozone/platform/dri/gbm_surface_factory.h
index a8a0c4c..b1ed46e 100644
--- a/ui/ozone/platform/dri/gbm_surface_factory.h
+++ b/ui/ozone/platform/dri/gbm_surface_factory.h
@@ -32,6 +32,12 @@
   virtual scoped_refptr<ui::NativePixmap> CreateNativePixmap(
       gfx::Size size,
       BufferFormat format) OVERRIDE;
+  virtual bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+                                    int plane_z_order,
+                                    gfx::OverlayTransform plane_transform,
+                                    scoped_refptr<NativePixmap> buffer,
+                                    const gfx::Rect& display_bounds,
+                                    const gfx::RectF& crop_rect) OVERRIDE;
   virtual bool CanShowPrimaryPlaneAsOverlay() OVERRIDE;
 
  private:
diff --git a/ui/ozone/platform/dri/gbm_surfaceless.cc b/ui/ozone/platform/dri/gbm_surfaceless.cc
index 6eef2bd..50deeda 100644
--- a/ui/ozone/platform/dri/gbm_surfaceless.cc
+++ b/ui/ozone/platform/dri/gbm_surfaceless.cc
@@ -29,10 +29,7 @@
   if (!controller_)
     return true;
 
-  bool success = controller_->SchedulePageFlip(queued_planes_);
-  queued_planes_.clear();
-  // Even on failure we may have scheduled some planes. Allow the controller to
-  // wait for the events for the scheduled planes.
+  bool success = controller_->SchedulePageFlip();
   controller_->WaitForPageFlipEvent();
 
   return success;
@@ -42,25 +39,4 @@
   return scoped_ptr<gfx::VSyncProvider>(new DriVSyncProvider(controller_));
 }
 
-bool GbmSurfaceless::ScheduleOverlayPlane(
-    int plane_z_order,
-    gfx::OverlayTransform plane_transform,
-    scoped_refptr<ui::NativePixmap> buffer,
-    const gfx::Rect& display_bounds,
-    const gfx::RectF& crop_rect) {
-  scoped_refptr<GbmPixmap> pixmap =
-      static_cast<GbmPixmap*>(buffer.get());
-  if (!pixmap) {
-    LOG(ERROR) << "ScheduleOverlayPlane passed NULL buffer.";
-    return false;
-  }
-
-  queued_planes_.push_back(OverlayPlane(pixmap->buffer(),
-                                        plane_z_order,
-                                        plane_transform,
-                                        display_bounds,
-                                        crop_rect));
-  return true;
-}
-
 }  // namespace ui
diff --git a/ui/ozone/platform/dri/gbm_surfaceless.h b/ui/ozone/platform/dri/gbm_surfaceless.h
index df7afe2..7949b18 100644
--- a/ui/ozone/platform/dri/gbm_surfaceless.h
+++ b/ui/ozone/platform/dri/gbm_surfaceless.h
@@ -30,15 +30,8 @@
   virtual bool ResizeNativeWindow(const gfx::Size& viewport_size) OVERRIDE;
   virtual bool OnSwapBuffers() OVERRIDE;
   virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE;
-  virtual bool ScheduleOverlayPlane(int plane_z_order,
-                                    gfx::OverlayTransform plane_transform,
-                                    scoped_refptr<ui::NativePixmap> buffer,
-                                    const gfx::Rect& display_bounds,
-                                    const gfx::RectF& crop_rect) OVERRIDE;
-
  protected:
   base::WeakPtr<HardwareDisplayController> controller_;
-  OverlayPlaneList queued_planes_;
 
   DISALLOW_COPY_AND_ASSIGN(GbmSurfaceless);
 };
diff --git a/ui/ozone/platform/dri/hardware_display_controller.cc b/ui/ozone/platform/dri/hardware_display_controller.cc
index a0c9d28e..342b4502 100644
--- a/ui/ozone/platform/dri/hardware_display_controller.cc
+++ b/ui/ozone/platform/dri/hardware_display_controller.cc
@@ -111,6 +111,7 @@
 
 bool HardwareDisplayController::Enable() {
   TRACE_EVENT0("dri", "HDC::Enable");
+  DCHECK(!current_planes_.empty());
   OverlayPlane primary = GetPrimaryPlane(current_planes_);
   DCHECK(primary.buffer);
   pending_page_flips_ = 0;
@@ -130,18 +131,20 @@
   }
 }
 
-bool HardwareDisplayController::SchedulePageFlip(
-    const OverlayPlaneList& overlays) {
-  DCHECK_LE(1u, overlays.size());
+void HardwareDisplayController::QueueOverlayPlane(const OverlayPlane& plane) {
+  pending_planes_.push_back(plane);
+}
+
+bool HardwareDisplayController::SchedulePageFlip() {
+  DCHECK(!pending_planes_.empty());
   DCHECK_EQ(0u, pending_page_flips_);
 
-  pending_planes_ = overlays;
   bool status = true;
   for (size_t i = 0; i < crtc_states_.size(); ++i) {
     if (crtc_states_[i]->is_disabled())
       continue;
 
-    status &= SchedulePageFlipOnCrtc(overlays, crtc_states_[i]);
+    status &= SchedulePageFlipOnCrtc(pending_planes_, crtc_states_[i]);
   }
 
   return status;
diff --git a/ui/ozone/platform/dri/hardware_display_controller.h b/ui/ozone/platform/dri/hardware_display_controller.h
index 394faee59..9c6bb12 100644
--- a/ui/ozone/platform/dri/hardware_display_controller.h
+++ b/ui/ozone/platform/dri/hardware_display_controller.h
@@ -120,6 +120,8 @@
   // Disables the CRTC.
   void Disable();
 
+  void QueueOverlayPlane(const OverlayPlane& plane);
+
   // Schedules the |overlays|' framebuffers to be displayed on the next vsync
   // event. The event will be posted on the graphics card file descriptor |fd_|
   // and it can be read and processed by |drmHandleEvent|. That function can
@@ -136,7 +138,7 @@
   // called again before the page flip occurrs.
   //
   // Returns true if the page flip was successfully registered, false otherwise.
-  bool SchedulePageFlip(const OverlayPlaneList& overlays);
+  bool SchedulePageFlip();
 
   // TODO(dnicoara) This should be on the MessageLoop when Ozone can have
   // BeginFrame can be triggered explicitly by Ozone.
diff --git a/ui/ozone/platform/dri/hardware_display_controller_unittest.cc b/ui/ozone/platform/dri/hardware_display_controller_unittest.cc
index ae4d6f8..998ccca 100644
--- a/ui/ozone/platform/dri/hardware_display_controller_unittest.cc
+++ b/ui/ozone/platform/dri/hardware_display_controller_unittest.cc
@@ -88,8 +88,8 @@
 
   ui::OverlayPlane plane2(scoped_refptr<ui::ScanoutBuffer>(
       new MockScanoutBuffer(kDefaultModeSize)));
-  EXPECT_TRUE(controller_->SchedulePageFlip(
-      std::vector<ui::OverlayPlane>(1, plane2)));
+  controller_->QueueOverlayPlane(plane2);
+  EXPECT_TRUE(controller_->SchedulePageFlip());
   controller_->WaitForPageFlipEvent();
   EXPECT_TRUE(plane1.buffer->HasOneRef());
   EXPECT_FALSE(plane2.buffer->HasOneRef());
@@ -117,8 +117,8 @@
 
   ui::OverlayPlane plane2(scoped_refptr<ui::ScanoutBuffer>(
       new MockScanoutBuffer(kDefaultModeSize)));
-  EXPECT_FALSE(controller_->SchedulePageFlip(
-      std::vector<ui::OverlayPlane>(1, plane2)));
+  controller_->QueueOverlayPlane(plane2);
+  EXPECT_FALSE(controller_->SchedulePageFlip());
   EXPECT_FALSE(plane1.buffer->HasOneRef());
   EXPECT_FALSE(plane2.buffer->HasOneRef());
 
@@ -135,14 +135,14 @@
   controller_->Disable();
   ui::OverlayPlane plane2(scoped_refptr<ui::ScanoutBuffer>(
       new MockScanoutBuffer(kDefaultModeSize)));
-  EXPECT_TRUE(controller_->SchedulePageFlip(
-      std::vector<ui::OverlayPlane>(1, plane2)));
+  controller_->QueueOverlayPlane(plane2);
+  EXPECT_TRUE(controller_->SchedulePageFlip());
   controller_->WaitForPageFlipEvent();
   EXPECT_EQ(0, drm_->get_page_flip_call_count());
 
   EXPECT_TRUE(controller_->Modeset(plane1, kDefaultMode));
-  EXPECT_TRUE(controller_->SchedulePageFlip(
-      std::vector<ui::OverlayPlane>(1, plane2)));
+  controller_->QueueOverlayPlane(plane2);
+  EXPECT_TRUE(controller_->SchedulePageFlip());
   controller_->WaitForPageFlipEvent();
   EXPECT_EQ(1, drm_->get_page_flip_call_count());
 }
@@ -160,11 +160,10 @@
 
   EXPECT_TRUE(controller_->Modeset(plane1, kDefaultMode));
 
-  std::vector<ui::OverlayPlane> overlays;
-  overlays.push_back(plane1);
-  overlays.push_back(plane2);
+  controller_->QueueOverlayPlane(plane1);
+  controller_->QueueOverlayPlane(plane2);
 
-  EXPECT_TRUE(controller_->SchedulePageFlip(overlays));
+  EXPECT_TRUE(controller_->SchedulePageFlip());
   controller_->WaitForPageFlipEvent();
   EXPECT_EQ(1, drm_->get_page_flip_call_count());
   EXPECT_EQ(1, drm_->get_overlay_flip_call_count());
@@ -182,7 +181,7 @@
 
   ui::OverlayPlane plane2(scoped_refptr<ui::ScanoutBuffer>(
       new MockScanoutBuffer(kDefaultModeSize)));
-  EXPECT_TRUE(controller_->SchedulePageFlip(
-      std::vector<ui::OverlayPlane>(1, plane2)));
+  controller_->QueueOverlayPlane(plane2);
+  EXPECT_TRUE(controller_->SchedulePageFlip());
   EXPECT_EQ(2, drm_->get_page_flip_call_count());
 }
diff --git a/ui/ozone/platform/egltest/ozone_platform_egltest.cc b/ui/ozone/platform/egltest/ozone_platform_egltest.cc
index 467cec5..57d3549 100644
--- a/ui/ozone/platform/egltest/ozone_platform_egltest.cc
+++ b/ui/ozone/platform/egltest/ozone_platform_egltest.cc
@@ -180,14 +180,6 @@
     return scoped_ptr<gfx::VSyncProvider>();
   }
 
-  virtual bool ScheduleOverlayPlane(int plane_z_order,
-                                    gfx::OverlayTransform plane_transform,
-                                    scoped_refptr<ui::NativePixmap> buffer,
-                                    const gfx::Rect& display_bounds,
-                                    const gfx::RectF& crop_rect) OVERRIDE {
-    return false;
-  }
-
  private:
   LibeglplatformShimLoader* eglplatform_shim_;
   intptr_t native_window_;
diff --git a/ui/ozone/public/surface_factory_ozone.cc b/ui/ozone/public/surface_factory_ozone.cc
index dac23f5..e6fd1a3 100644
--- a/ui/ozone/public/surface_factory_ozone.cc
+++ b/ui/ozone/public/surface_factory_ozone.cc
@@ -63,6 +63,16 @@
   return NULL;
 }
 
+bool SurfaceFactoryOzone::ScheduleOverlayPlane(
+    gfx::AcceleratedWidget widget,
+    int plane_z_order,
+    gfx::OverlayTransform plane_transform,
+    scoped_refptr<NativePixmap> buffer,
+    const gfx::Rect& display_bounds,
+    const gfx::RectF& crop_rect) {
+  return false;
+}
+
 bool SurfaceFactoryOzone::CanShowPrimaryPlaneAsOverlay() {
   return false;
 }
diff --git a/ui/ozone/public/surface_factory_ozone.h b/ui/ozone/public/surface_factory_ozone.h
index 08b9774..1ab18b8 100644
--- a/ui/ozone/public/surface_factory_ozone.h
+++ b/ui/ozone/public/surface_factory_ozone.h
@@ -119,6 +119,24 @@
       gfx::Size size,
       BufferFormat format);
 
+  // Sets the overlay plane to switch to at the next page flip.
+  // |w| specifies the screen to display this overlay plane on.
+  // |plane_z_order| specifies the stacking order of the plane relative to the
+  // main framebuffer located at index 0.
+  // |plane_transform| specifies how the buffer is to be transformed during.
+  // composition.
+  // |buffer| to be presented by the overlay.
+  // |display_bounds| specify where it is supposed to be on the screen.
+  // |crop_rect| specifies the region within the buffer to be placed
+  // inside |display_bounds|. This is specified in texture coordinates, in the
+  // range of [0,1].
+  virtual bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+                                    int plane_z_order,
+                                    gfx::OverlayTransform plane_transform,
+                                    scoped_refptr<NativePixmap> buffer,
+                                    const gfx::Rect& display_bounds,
+                                    const gfx::RectF& crop_rect);
+
   // Returns true if overlays can be shown at z-index 0, replacing the main
   // surface. Combined with surfaceless extensions, it allows for an
   // overlay-only mode.
diff --git a/ui/ozone/public/surface_ozone_egl.h b/ui/ozone/public/surface_ozone_egl.h
index e2c182eb..4f38f06b 100644
--- a/ui/ozone/public/surface_ozone_egl.h
+++ b/ui/ozone/public/surface_ozone_egl.h
@@ -44,22 +44,6 @@
   // outside of the sandbox, they must have been completed in
   // InitializeHardware. Returns an empty scoped_ptr on error.
   virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() = 0;
-
-  // Sets the overlay plane to switch to at the next page flip.
-  // |plane_z_order| specifies the stacking order of the plane relative to the
-  // main framebuffer located at index 0.
-  // |plane_transform| specifies how the buffer is to be transformed during.
-  // composition.
-  // |buffer| to be presented by the overlay.
-  // |display_bounds| specify where it is supposed to be on the screen.
-  // |crop_rect| specifies the region within the buffer to be placed
-  // inside |display_bounds|. This is specified in texture coordinates, in the
-  // range of [0,1].
-  virtual bool ScheduleOverlayPlane(int plane_z_order,
-                                    gfx::OverlayTransform plane_transform,
-                                    scoped_refptr<NativePixmap> buffer,
-                                    const gfx::Rect& display_bounds,
-                                    const gfx::RectF& crop_rect) = 0;
 };
 
 }  // namespace ui