[TTVD] Allow injecting custom OutputSurface into OutputSurfaceProxy 93/315593/2
authorJakub Gajownik <j.gajownik2@samsung.com>
Tue, 5 Nov 2024 14:11:56 +0000 (15:11 +0100)
committerBot Blink <blinkbot@samsung.com>
Tue, 3 Dec 2024 12:43:07 +0000 (12:43 +0000)
Remove direct dependency on OutputSurfaceImpl from
OutputSurfaceProxy class as now it's hard to implement
any testing for it. There is no functionally change,
just the ability to inject custom derived class was added.

Bug: https://jira-eu.sec.samsung.net/browse/VDGAME-618
Change-Id: Ia8e0deb4bb46d3953513a38a98df0fe4bc6addce
Signed-off-by: Jakub Gajownik <j.gajownik2@samsung.com>
tizen_src/chromium_impl/ui/ozone/platform/efl/output_surface_impl.h
tizen_src/chromium_impl/ui/ozone/platform/efl/output_surface_proxy.cc
tizen_src/chromium_impl/ui/ozone/platform/efl/output_surface_proxy.h
tizen_src/chromium_impl/ui/ozone/platform/efl/output_surface_state.cc

index f109eab8528a8bc885af3460c091b9c7bd3cce7b..47aa3f0122681b5b166aa8b87e3c58cf8b277704 100644 (file)
@@ -24,17 +24,28 @@ struct Geometry {
   gfx::Rect picture;
 };
 
+class OutputSurfaceScaler : public OutputSurface {
+ public:
+  OutputSurfaceScaler() = default;
+  virtual ~OutputSurfaceScaler() = default;
+
+  virtual bool Initialize(Plane plane) = 0;
+  virtual gfx::VideoOutputMode PrepareToRender(base::UnguessableToken,
+                                               bool) = 0;
+  virtual void SetBelowParent() = 0;
+};
+
 // Real implementation of surface that actually does rendering
 // to scaler and holds platform resources.
-class OutputSurfaceImpl : public OutputSurface {
+class OutputSurfaceImpl : public OutputSurfaceScaler {
  public:
   OutputSurfaceImpl(int device_id,
                     const RenderingWorkarounds& rendering_workarounds);
   ~OutputSurfaceImpl() override;
 
-  bool Initialize(Plane plane);
+  bool Initialize(Plane plane) override;
 
-  gfx::VideoOutputMode PrepareToRender(base::UnguessableToken, bool);
+  gfx::VideoOutputMode PrepareToRender(base::UnguessableToken, bool) override;
 
   // Might be called on different thread than creation and initialization
   // was done. It's also common scenario that each decoder has it's own
@@ -43,7 +54,7 @@ class OutputSurfaceImpl : public OutputSurface {
               gfx::Size,
               gfx::OverlayRenderData) override;
 
-  void SetBelowParent();
+  void SetBelowParent() override;
 
  private:
   void EnableSeqMode(bool enabled);
index 978079cd51b75054a3520aa38672c613518cd604..f216ed657f1eca0aaf952e5d654d8c976aac840f 100644 (file)
@@ -36,9 +36,13 @@ constexpr const base::TimeDelta kStateUpdatingDelay = base::Milliseconds(10);
 }  // namespace
 
 OutputSurfaceProxy::OutputSurfaceProxy(
-    const RenderingWorkarounds& rendering_workarounds)
+    const RenderingWorkarounds& rendering_workarounds,
+    base::RepeatingCallback<std::unique_ptr<OutputSurfaceScaler>(
+        int device_id,
+        const RenderingWorkarounds& rendering_workarounds)> create_surface_cb)
     : worker_thread_("output_surface_worker"),
-      rendering_workarounds_(rendering_workarounds) {}
+      rendering_workarounds_(rendering_workarounds),
+      create_surface_cb_(std::move(create_surface_cb)) {}
 
 OutputSurfaceProxy::~OutputSurfaceProxy() {
   TIZEN_MEDIA_LOG(INFO);
@@ -160,8 +164,7 @@ void OutputSurfaceProxy::InitializeOnWorker(
   // First one is explicitly checking for initialization.
   // TODO(vdwasm) |SetBelowParent| should be considered to move to worker thread
   //              if there are against that.
-  impl_ =
-      std::make_unique<OutputSurfaceImpl>(device_id, rendering_workarounds_);
+  impl_ = create_surface_cb_.Run(device_id, rendering_workarounds_);
 
   bool result = impl_->Initialize(plane_);
   if (!result) {
index fcbf5552438c110f1eda6c48a77dcfc8181ee3f4..30f7fbb25a3e9cdbba4843eec9488538eb802d5b 100644 (file)
@@ -24,7 +24,11 @@ class OutputSurfaceProxy
       public base::RefCountedThreadSafe<OutputSurfaceProxy> {
  public:
   explicit OutputSurfaceProxy(
-      const RenderingWorkarounds& rendering_workarounds);
+      const RenderingWorkarounds& rendering_workarounds,
+      base::RepeatingCallback<std::unique_ptr<OutputSurfaceScaler>(
+          int device_id,
+          const RenderingWorkarounds& rendering_workarounds)>
+          create_surface_cb);
 
   // Called on client (viz compositor/decoder) thread.
   bool Initialize(Plane plane, base::OnceCallback<void(Plane)> conflict_cb);
@@ -130,7 +134,7 @@ class OutputSurfaceProxy
   base::ConditionVariable initialization_done_{&lock_};
   // Implementation for accessing scaler, note it's not permitted
   // to call any method on this object without holding |scaler_token_|.
-  std::unique_ptr<OutputSurfaceImpl> impl_ GUARDED_BY(lock_);
+  std::unique_ptr<OutputSurfaceScaler> impl_ GUARDED_BY(lock_);
   base::OnceCallback<void(Plane)> conflict_cb_ GUARDED_BY(lock_);
   bool initialized_ GUARDED_BY(lock_) = false;
   int device_id_ GUARDED_BY(lock_) = 0;
@@ -143,6 +147,11 @@ class OutputSurfaceProxy
 
   const RenderingWorkarounds rendering_workarounds_;
 
+  base::RepeatingCallback<std::unique_ptr<OutputSurfaceScaler>(
+      int device_id,
+      const RenderingWorkarounds& rendering_workarounds)>
+      create_surface_cb_;
+
   base::WeakPtr<OutputSurfaceProxy> weak_this_on_worker_;
   base::WeakPtrFactory<OutputSurfaceProxy> weak_factory_on_worker_{this};
 };
index 782799fade226df7f50195d2b081b16847a31e17..f35cec2edcf8e6d30d14029dc4eba48cac1fd86c 100644 (file)
@@ -75,8 +75,15 @@ bool OutputSurfaceState::Allocate(
     base::OnceCallback<void(OutputSurface::Plane)> conflict_cb,
     const ui::RenderingWorkarounds& rendering_workarounds) {
   TIZEN_MEDIA_LOG(INFO) << "Allocate new surface: " << plane_;
-  auto temp_surface =
-      base::MakeRefCounted<ui::OutputSurfaceProxy>(rendering_workarounds);
+
+  auto create_surface_cb = base::BindRepeating(
+      [](int device_id, const RenderingWorkarounds& rendering_workarounds)
+          -> std::unique_ptr<OutputSurfaceScaler> {
+        return std::make_unique<OutputSurfaceImpl>(device_id,
+                                                   rendering_workarounds);
+      });
+  auto temp_surface = base::MakeRefCounted<ui::OutputSurfaceProxy>(
+      rendering_workarounds, std::move(create_surface_cb));
   if (!temp_surface->Initialize(plane_, std::move(conflict_cb))) {
     TIZEN_MEDIA_LOG(INFO) << "Failed to initialize surface: " << plane_;
     state_ = State::kError;