[M120 Migration][WebRTC] Fix build error after Tbm feature enabled 27/309827/3 submit/tizen/20240417.160015
authorpeng.yin <peng8.yin@samsung.com>
Mon, 15 Apr 2024 02:33:10 +0000 (10:33 +0800)
committerpeng.yin <peng8.yin@samsung.com>
Wed, 17 Apr 2024 09:54:54 +0000 (17:54 +0800)
fix build error after Tbm macro enable, and add some type dependencies
from the `[WebRTC] Make VideoCalls work in multiprocess architecture`
patch set.

Change-Id: If80246597a2e63be171fa0b528360e546f0bf856
Signed-off-by: peng.yin <peng8.yin@samsung.com>
24 files changed:
media/base/video_frame.cc
media/mojo/mojom/BUILD.gn
media/mojo/mojom/renderer_extensions.mojom
third_party/blink/public/web/modules/mediastream/webmediaplayer_ms.h
third_party/blink/renderer/modules/mediastream/webmediaplayer_ms.cc
tizen_src/chromium_impl/content/browser/media/tizen_renderer_impl.cc
tizen_src/chromium_impl/content/browser/media/tizen_renderer_impl.h
tizen_src/chromium_impl/content/renderer/media/tizen/media_player_renderer_client.cc
tizen_src/chromium_impl/content/renderer/media/tizen/media_player_renderer_client.h
tizen_src/chromium_impl/media/blink/renderer/tizen_esplusplayer_renderer.cc
tizen_src/chromium_impl/media/blink/renderer/tizen_esplusplayer_renderer.h
tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle.h
tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.cc [new file with mode: 0644]
tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.h [new file with mode: 0644]
tizen_src/chromium_impl/ui/gfx/tbm_surface.cc [new file with mode: 0644]
tizen_src/chromium_impl/ui/gfx/tbm_surface.h [new file with mode: 0644]
tizen_src/chromium_impl/ui/gfx/tbm_utils.cc [new file with mode: 0644]
tizen_src/chromium_impl/ui/gfx/tbm_utils.h [new file with mode: 0644]
tizen_src/chromium_impl/ui/ui_efl.gni
ui/gfx/gpu_memory_buffer.h
ui/gfx/mojom/BUILD.gn
ui/gfx/mojom/buffer_types.mojom
ui/gfx/mojom/buffer_types_mojom_traits.cc
ui/gfx/mojom/buffer_types_mojom_traits.h

index 87d60b3..17023de 100644 (file)
 #include "ui/gfx/mac/io_surface.h"
 #endif
 #if defined(TIZEN_TBM_SUPPORT)
-#include "base/threading/thread_task_runner_handle.h"
 #include "base/trace_event/trace_event.h"
 #include "gpu/GLES2/gl2extchromium.h"
 #include "gpu/command_buffer/client/gles2_interface.h"
-#include "media/base/bind_to_current_loop.h"
 #endif
 
 namespace media {
index 84f8d98..562bd29 100644 (file)
@@ -137,6 +137,10 @@ mojom("mojom") {
     enabled_features += [ "is_tizen_tv" ]
   }
 
+  if (tizen_tbm_support) {
+    enabled_features += [ "tizen_tbm_support" ]
+  }
+
   shared_typemaps = [
     {
       types = [
index b4a775c..9b77848 100644 (file)
@@ -77,7 +77,7 @@ interface MediaPlayerRendererClientExtension {
 
   [EnableIf=tizen_tbm_support]
   OnNewTbmFrameAvailable(uint32 playerId,
-                         gfx.mojom.TbmBufferHandle tbm_buffer_handle,
+                         gfx.mojom.TbmBufferHandleInterProcess tbm_buffer_handle,
                          mojo_base.mojom.TimeDelta timestamp);
 
   [EnableIf=is_tizen_tv]
@@ -101,7 +101,7 @@ interface MediaPlayerRendererExtension {
       => (mojo_base.mojom.UnguessableToken request_token);
 
   [EnableIf=tizen_tbm_support]
-  OnTbmBufferExhausted(gfx.mojom.TbmBufferHandle tbm_buffer_handle);
+  OnMediaPacketExhausted(uint64 media_packet);
 
   [EnableIf=is_tizen_tv]
   EnableTbmBufferCallback(bool enabled);
index 1ef98e0..8ac53e4 100644 (file)
 #include "third_party/blink/public/platform/web_media_player.h"
 #include "third_party/blink/public/platform/web_surface_layer_bridge.h"
 
+#if BUILDFLAG(IS_TIZEN_TV) && defined(TIZEN_TBM_SUPPORT)
+#include "base/synchronization/waitable_event.h"
+#endif
+
 namespace media {
 class GpuMemoryBufferVideoFramePool;
 class MediaLog;
@@ -210,6 +214,12 @@ class BLINK_MODULES_EXPORT WebMediaPlayerMS
   void RegisterFrameSinkHierarchy() override;
   void UnregisterFrameSinkHierarchy() override;
 
+#if BUILDFLAG(IS_TIZEN_TV) && defined(TIZEN_TBM_SUPPORT) && \
+    defined(TIZEN_MULTIMEDIA)
+  void OnRequestVideoDecodedBufferComplete(bool success);
+  void SendVideoDecodedBufferRequest();
+#endif
+
  private:
   friend class WebMediaPlayerMSTest;
 
@@ -262,6 +272,9 @@ class BLINK_MODULES_EXPORT WebMediaPlayerMS
   media::PipelineStatistics GetPipelineStatistics();
 
   absl::optional<media::mojom::MediaStreamType> GetMediaStreamType();
+#if BUILDFLAG(IS_TIZEN_TV) && defined(TIZEN_TBM_SUPPORT)
+  void PaintDecodedVideoFrame(scoped_refptr<media::VideoFrame> decoded_frame);
+#endif
 
   std::unique_ptr<MediaStreamInternalFrameWrapper> internal_frame_;
 
@@ -350,6 +363,13 @@ class BLINK_MODULES_EXPORT WebMediaPlayerMS
 
   std::unique_ptr<WebVideoFrameSubmitter> submitter_;
 
+#if BUILDFLAG(IS_TIZEN_TV) && defined(TIZEN_TBM_SUPPORT)
+  // save last time requested decoded frame
+  scoped_refptr<media::VideoFrame> decoded_video_frame_;
+  base::WaitableEvent request_frame_waiter_;
+  base::Lock request_frame_lock_;
+#endif
+
   // Whether the use of a surface layer instead of a video layer is enabled.
   bool use_surface_layer_ = false;
 
index df4bebd..a15ccaf 100644 (file)
@@ -176,6 +176,10 @@ class WebMediaPlayerMS::FrameDeliverer {
  public:
   using RepaintCB = WTF::CrossThreadRepeatingFunction<
       void(scoped_refptr<media::VideoFrame> frame, bool is_copy)>;
+#if BUILDFLAG(IS_TIZEN_TV) && defined(TIZEN_TBM_SUPPORT)
+  using RequestCB = WTF::CrossThreadRepeatingFunction<void(
+      scoped_refptr<media::VideoFrame> frame)>;
+#endif
   FrameDeliverer(const base::WeakPtr<WebMediaPlayerMS>& player,
                  RepaintCB enqueue_frame_cb,
                  scoped_refptr<base::SequencedTaskRunner> media_task_runner,
@@ -1798,4 +1802,23 @@ void WebMediaPlayerMS::UnregisterFrameSinkHierarchy() {
     bridge_->UnregisterFrameSinkHierarchy();
 }
 
+#if BUILDFLAG(IS_TIZEN_TV) && defined(TIZEN_TBM_SUPPORT) && \
+    defined(TIZEN_MULTIMEDIA)
+void WebMediaPlayerMS::OnRequestVideoDecodedBufferComplete(bool success) {
+  if (!success) {
+    LOG(ERROR) << "SendVideoDecodedBufferRequest failed, wait 22ms "
+                  "and try again";
+  }
+}
+
+void WebMediaPlayerMS::SendVideoDecodedBufferRequest() {
+  LOG(INFO) << __func__;
+  media::TizenEsPlusPlayerRendererManager::GetInstance()
+      .SendVideoDecodedBufferRequest(
+          player_id_,
+          base::BindOnce(&WebMediaPlayerMS::OnRequestVideoDecodedBufferComplete,
+                         base::Unretained(this)));
+}
+#endif
+
 }  // namespace blink
index b0a19d4..756db67 100644 (file)
@@ -25,6 +25,7 @@
 #include "tizen_src/chromium_impl/content/browser/media/media_player_renderer_web_contents_observer.h"
 #include "tizen_src/chromium_impl/media/filters/media_player_registry.h"
 #include "tizen_src/chromium_impl/media/filters/media_player_tizen.h"
+#include "tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.h"
 
 #if defined(TIZEN_VIDEO_HOLE)
 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
@@ -892,13 +893,12 @@ void TizenRendererImpl::OnRequestSuspend(bool resource_conflicted) {
 void TizenRendererImpl::OnNewTbmFrameAvailable(uint32_t player_id,
                                                gfx::TbmBufferHandle tbm_handle,
                                                base::TimeDelta timestamp) {
-  client_extension_->OnNewTbmFrameAvailable(player_id, tbm_handle, timestamp);
+  client_extension_->OnNewTbmFrameAvailable(
+      player_id, gfx::ToTbmBufferHandleInterProcess(tbm_handle), timestamp);
 }
 
-void TizenRendererImpl::OnTbmBufferExhausted(
-    const gfx::TbmBufferHandle& tbm_handle) {
-  media_player_->DestroyMediaPacket(
-      reinterpret_cast<void*>(tbm_handle.media_packet));
+void TizenRendererImpl::OnMediaPacketExhausted(uint64_t media_packet) {
+  media_player_->DestroyMediaPacket(reinterpret_cast<void*>(media_packet));
 }
 #else
 void TizenRendererImpl::OnNewFrameAvailable(
index bac5ad6..51b6f76 100644 (file)
@@ -26,6 +26,8 @@
 #include "third_party/abseil-cpp/absl/types/optional.h"
 #include "third_party/blink/public/platform/web_media_player.h"
 #include "tizen_src/chromium_impl/media/filters/media_player_tizen_client.h"
+#include "tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle.h"
+#include "tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.h"
 #include "ui/gfx/geometry/size.h"
 
 namespace base {
@@ -149,7 +151,7 @@ class CONTENT_EXPORT TizenRendererImpl
   void OnNewTbmFrameAvailable(uint32_t player_id,
                               gfx::TbmBufferHandle tbm_handle,
                               base::TimeDelta timestamp) override;
-  void OnTbmBufferExhausted(const gfx::TbmBufferHandle& tbm_handle) override;
+  void OnMediaPacketExhausted(uint64_t media_packet) override;
 #else
   void OnNewFrameAvailable(uint32_t playerId,
                            base::UnsafeSharedMemoryRegion frame,
index 7c8729e..8c1463f 100644 (file)
@@ -8,6 +8,8 @@
 
 #include "base/functional/bind.h"
 #include "third_party/libyuv/include/libyuv/convert.h"
+#include "ui/gfx/tbm_buffer_handle.h"
+#include "ui/gfx/tbm_buffer_handle_inter_process.h"
 
 namespace content {
 
@@ -225,32 +227,36 @@ void MediaPlayerRendererClient::OnBufferUpdate(base::TimeDelta time) {
 }
 
 #if defined(TIZEN_TBM_SUPPORT)
-void MediaPlayerRendererClient::OnTbmBufferExhausted(
+void MediaPlayerRendererClient::OnMediaPacketExhausted(
     media::VideoFrame* video_frame,
-    void* media_packet,
-    int player_id) {
+    uintptr_t media_packet) {
   // In this case, media packet will be released in destructor of |GLImageEGL|.
   if (video_frame->GetTbmTexture())
     return;
 
-  gfx::TbmBufferHandle tbm_handle;
-  tbm_handle.media_packet = reinterpret_cast<uintptr_t>(media_packet);
-  tbm_handle.player_id = player_id;
-  renderer_extension_remote_->OnTbmBufferExhausted(tbm_handle);
+  renderer_extension_remote_->OnMediaPacketExhausted(media_packet);
 }
 
 void MediaPlayerRendererClient::OnNewTbmFrameAvailable(
     uint32_t playerId,
-    const gfx::TbmBufferHandle& tbm_buffer_handle,
+    gfx::TbmBufferHandleInterProcess tbm_buffer_handle_inter_process,
     base::TimeDelta timestamp) {
+  auto [tbm_buffer_handle, tbm_surface_release_cb_runner] =
+      gfx::ToTbmBufferHandle(tbm_buffer_handle_inter_process);
   gfx::Size size(tbm_buffer_handle.width, tbm_buffer_handle.height);
+
   scoped_refptr<media::VideoFrame> video_frame =
       media::VideoFrame::WrapTBMSurface(size, timestamp, tbm_buffer_handle);
+  if (!video_frame) {
+    LOG(ERROR) << "Failed to wrap TBM surface";
+    return;
+  }
+
+  video_frame->AddDestructionObserver(tbm_surface_release_cb_runner.Release());
   video_frame->AddDestructionObserver(base::BindOnce(
-      &MediaPlayerRendererClient::OnTbmBufferExhausted,
+      &MediaPlayerRendererClient::OnMediaPacketExhausted,
       weak_factory_.GetWeakPtr(), base::Unretained(video_frame.get()),
-      const_cast<void*>((const void*)tbm_buffer_handle.media_packet),
-      tbm_buffer_handle.player_id));
+      reinterpret_cast<uintptr_t>(tbm_buffer_handle.media_packet)));
 
 #if defined(TIZEN_VIDEO_HOLE) && !BUILDFLAG(IS_TIZEN_TV)
   if (!is_video_hole_ || (is_video_hole_ && !is_fullscreen_))
index 884695e..8746d37 100644 (file)
@@ -24,7 +24,7 @@
 #include "mojo/public/cpp/bindings/remote.h"
 
 #if defined(TIZEN_TBM_SUPPORT)
-#include "tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle.h"
+#include "tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.h"
 #endif
 
 namespace content {
@@ -86,12 +86,12 @@ class CONTENT_EXPORT MediaPlayerRendererClient
                            uint32_t width,
                            uint32_t height) override;
 #if defined(TIZEN_TBM_SUPPORT)
-  void OnNewTbmFrameAvailable(uint32_t playerId,
-                              const gfx::TbmBufferHandle& tbm_buffer_handle,
-                              base::TimeDelta timestamp) override;
-  void OnTbmBufferExhausted(media::VideoFrame* video_frame,
-                            void* media_packet,
-                            int player_id);
+  void OnNewTbmFrameAvailable(
+      uint32_t playerId,
+      gfx::TbmBufferHandleInterProcess tbm_buffer_handle_inter_process,
+      base::TimeDelta timestamp) override;
+  void OnMediaPacketExhausted(media::VideoFrame* video_frame,
+                              uintptr_t media_packet);
 #endif
 
  private:
index 306588d..2a2c943 100644 (file)
@@ -16,7 +16,7 @@
 #include "content/renderer/media/media_interface_factory.h"
 #include "media/base/video_codecs.h"
 #include "media/renderers/video_overlay_factory.h"
-// #include "ui/gfx/tbm_buffer_handle_inter_process.h"
+#include "ui/gfx/tbm_buffer_handle_inter_process.h"
 
 #if defined(ENABLE_AUTO_ZOOM)
 #include "media/mojo/mojom/ai_zoom_settings.mojom.h"
@@ -113,6 +113,15 @@ TizenEsPlusPlayerRendererManager::GetTizenEsPlusPlayerRenderer(int id) {
   return renderer;
 }
 
+void TizenEsPlusPlayerRendererManager::SendVideoDecodedBufferRequest(
+    int id,
+    RequestVideoDecodedBufferCB cb) {
+  base::AutoLock lk(lock_);
+  auto renderer = GetTizenEsPlusPlayerRenderer(id);
+  if (renderer)
+    renderer->SendVideoDecodedBufferRequest(std::move(cb));
+}
+
 void TizenEsPlusPlayerRendererManager::OnVideoSinkGeometryChange(
     int id,
     const gfx::RectF& rect,
@@ -717,9 +726,10 @@ void TizenEsPlusPlayerRenderer::OnNewTbmFrameAvailable(
   // Webrtc TBM from esplayer will be destroyed from
   // video frame DestructionObserver
   frame->SetTbmDestroyType(gfx::kDestroyTbmByVideoFrame);
-  frame->AddDestructionObserver(BindToCurrentLoop(base::BindOnce(
-      &TizenEsPlusPlayerRenderer::ReleaseMediaPacket, GetWeakPtr(),
-      reinterpret_cast<uintptr_t>(tbm_buffer_handle.media_packet))));
+  frame->AddDestructionObserver(
+      base::BindPostTaskToCurrentDefault(base::BindOnce(
+          &TizenEsPlusPlayerRenderer::ReleaseMediaPacket, GetWeakPtr(),
+          reinterpret_cast<uintptr_t>(tbm_buffer_handle.media_packet))));
   frame->metadata().MergeMetadataFrom(GetMetaData(timestamp));
   if (frame_cb_) {
     frame_cb_.Run(std::move(frame), timestamp + base::TimeTicks());
@@ -880,4 +890,17 @@ TizenEsPlusPlayerRenderer::StreamResource::GetAllStreams() {
   return v;
 }
 
+void TizenEsPlusPlayerRenderer::SendVideoDecodedBufferRequest(
+    RequestVideoDecodedBufferCB cb) {
+  if (!worker_task_runner_->BelongsToCurrentThread()) {
+    worker_task_runner_->PostTask(
+        FROM_HERE,
+        base::BindOnce(
+            &TizenEsPlusPlayerRenderer::SendVideoDecodedBufferRequest,
+            GetWeakPtr(), std::move(cb)));
+    return;
+  }
+  mojo_renderer_->RequestVideoDecodedBuffer(std::move(cb));
+}
+
 }  // namespace media
index 8addc02..85879da 100644 (file)
@@ -47,6 +47,7 @@ using FrameCb = base::RepeatingCallback<void(scoped_refptr<media::VideoFrame>,
 using InitCb = base::OnceCallback<void(bool)>;
 using SelectedResource = std::pair<HardwareResouceType /* scaler */,
                                    HardwareResouceType /* decoder */>;
+using RequestVideoDecodedBufferCB = base::OnceCallback<void(bool)>;
 
 class TizenEsPlusPlayerRenderer;
 
@@ -70,6 +71,7 @@ class TizenEsPlusPlayerRendererManager {
                                  const gfx::RectF& rect,
                                  media::VideoRotation rotation);
   void OnZOrderChanged(int broadcast_id, const std::vector<int>& video_ids);
+  void SendVideoDecodedBufferRequest(int id, RequestVideoDecodedBufferCB cb);
 
  private:
   friend class base::NoDestructor<TizenEsPlusPlayerRendererManager>;
@@ -178,12 +180,12 @@ class TizenEsPlusPlayerRenderer final
   void SetAiZoomSettings(const media::TizenAiZoomSettings& settings);
 #endif  // defined(ENABLE_AUTO_ZOOM)
   void SetPlayerVideoAbove(int32_t other_id);
-  void OnVideoSinkGeometryChange(const gfx::RectF& rect,
-                                 media::VideoRotation rotation);
-
   const SelectedResource& selected_resource() const {
     return selected_resource_;
   }
+  void OnVideoSinkGeometryChange(const gfx::RectF& rect,
+                                 media::VideoRotation rotation);
+  void SendVideoDecodedBufferRequest(RequestVideoDecodedBufferCB cb);
 
   base::WeakPtr<TizenEsPlusPlayerRenderer> GetWeakPtr();
 
index ea7dab6..7144f54 100644 (file)
@@ -35,10 +35,12 @@ struct GFX_EXPORT TbmBufferHandle {
   TbmDestroyType tbm_destroy_type = kDestroyTbmByEgl;
   int32_t player_id = 0;
   int32_t key_num = 0;
-  int32_t key[4];
-  int32_t strides[4];
+  int32_t key[4] = {0};
+  int32_t strides[4] = {0};
   int32_t width = 0;
   int32_t height = 0;
+  uint64_t pts = 0;
+  uint64_t duration = 0;
 #endif
 };
 
diff --git a/tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.cc b/tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.cc
new file mode 100644 (file)
index 0000000..8a71513
--- /dev/null
@@ -0,0 +1,204 @@
+// Copyright 2022 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.h"
+
+#include <memory>
+
+#include "base/functional/callback_helpers.h"
+#include "base/logging.h"
+#include "ui/gfx/tbm_buffer_handle.h"
+
+#if defined(TIZEN_TBM_SUPPORT)
+#include "tizen_src/chromium_impl/ui/gfx/tbm_utils.h"
+#endif
+
+namespace gfx {
+
+#if defined(TIZEN_TBM_SUPPORT)
+std::vector<base::ScopedFD> GetBufferObjectFdsFromSurface(
+    tbm_surface_h tbm_surface) {
+  if (!tbm_surface) {
+    LOG(WARNING) << "Provided TBM Surface is null";
+    return {};
+  }
+
+  std::vector<base::ScopedFD> result{};
+
+  size_t tbm_bos_count = tbm_surface_internal_get_num_bos(tbm_surface);
+  result.reserve(tbm_bos_count);
+
+  for (auto i = 0u; i < tbm_bos_count; ++i) {
+    // tbm_surface_internal_get_bo does not increase reference count for tbm_bo
+    auto tbm_bo = tbm_surface_internal_get_bo(tbm_surface, i);
+    if (!tbm_bo) {
+      LOG(WARNING) << "Failed to get tbm_bo from tbm_surface_h";
+      return {};
+    }
+    result.emplace_back(tbm_bo_export_fd(tbm_bo));
+  }
+
+  return result;
+}
+
+TbmSurfaceParameters GetTbmParamsFromSurface(tbm_surface_h tbm_surface) {
+  if (!tbm_surface) {
+    LOG(WARNING) << "Provided TBM Surface is null";
+    return {};
+  }
+
+  tbm_surface_info_s tbm_si{};
+  auto ret = tbm_surface_get_info(tbm_surface, &tbm_si);
+  if (ret != TBM_SURFACE_ERROR_NONE) {
+    LOG(WARNING)
+        << "Failed to get tbm_surface_info_s from tbm_surface_h, result = "
+        << ret;
+    return {};
+  }
+
+  std::vector<TbmSurfacePlaneParameters> result_params;
+  result_params.reserve(tbm_si.num_planes);
+
+  for (uint32_t i = 0; i < tbm_si.num_planes; ++i) {
+    result_params.emplace_back(
+        TbmSurfacePlaneParameters{.offset = tbm_si.planes[i].offset,
+                                  .size = tbm_si.planes[i].size,
+                                  .stride = tbm_si.planes[i].stride});
+  }
+
+  return {tbm_si.format,
+          std::move(result_params),
+          {static_cast<int32_t>(tbm_si.width),
+           static_cast<int32_t>(tbm_si.height)}};
+}
+#endif  // defined(TIZEN_TBM_SUPPORT)
+
+TbmBufferHandleInterProcess ToTbmBufferHandleInterProcess(
+    const TbmBufferHandle& tbm_buffer) {
+  TbmBufferHandleInterProcess tbm_buffer_ip;
+
+#if defined(TIZEN_TBM_SUPPORT)
+  if (!tbm_buffer.tbm_surface) {
+    LOG(WARNING) << "Provided TBM Surface is null";
+    return {};
+  }
+
+  auto buffer_mgr = TbmBufMgrType(tbm_bufmgr_init(-1));
+
+  if (!buffer_mgr) {
+    LOG(WARNING) << "TBM buffer manager was not created successfully";
+    return {};
+  }
+
+  auto tbm_surface = reinterpret_cast<tbm_surface_h>(tbm_buffer.tbm_surface);
+
+  tbm_buffer_ip.fds = GetBufferObjectFdsFromSurface(tbm_surface);
+  if (tbm_buffer_ip.fds.empty()) {
+    LOG(WARNING) << "Failed to get buffer object FDs from tbm surface";
+    return {};
+  }
+
+  auto tbm_params = GetTbmParamsFromSurface(tbm_surface);
+  if (!tbm_params.IsValid()) {
+    LOG(WARNING) << "Failed to get TBM parameters from tbm surface";
+    return {};
+  }
+  tbm_buffer_ip.tbm_format = tbm_params.format;
+  tbm_buffer_ip.planes = std::move(tbm_params.planes);
+
+  tbm_buffer_ip.media_packet = tbm_buffer.media_packet;
+  tbm_buffer_ip.player_id = tbm_buffer.player_id;
+  tbm_buffer_ip.width = tbm_buffer.width;
+  tbm_buffer_ip.height = tbm_buffer.height;
+  tbm_buffer_ip.tbm_destroy_type = tbm_buffer.tbm_destroy_type;
+  tbm_buffer_ip.pts = tbm_buffer.pts;
+  tbm_buffer_ip.duration = tbm_buffer.duration;
+#endif  // defined(TIZEN_TBM_SUPPORT)
+
+  return tbm_buffer_ip;
+}
+
+std::pair<TbmBufferHandle, TbmSurfaceReleaseCbRunner> ToTbmBufferHandle(
+    const TbmBufferHandleInterProcess& tbm_buffer_ip) {
+  std::pair<TbmBufferHandle, TbmSurfaceReleaseCbRunner> out_pair;
+
+#if defined(TIZEN_TBM_SUPPORT)
+  TbmBufferHandle tbm_buffer;
+  auto buffer_mgr = TbmBufMgrType(tbm_bufmgr_init(-1));
+
+  if (!buffer_mgr) {
+    LOG(WARNING) << "TBM buffer manager was not created successfully";
+    return out_pair;
+  }
+
+  tbm_buffer.media_packet = tbm_buffer_ip.media_packet;
+  tbm_buffer.player_id = tbm_buffer_ip.player_id;
+
+  tbm_buffer.key_num = tbm_buffer_ip.fds.size();
+
+  std::vector<TbmBOType> bos;
+  std::vector<tbm_bo> bos_raw;
+  bos.reserve(tbm_buffer_ip.fds.size());
+  bos_raw.reserve(tbm_buffer_ip.fds.size());
+
+  for (uint32_t i = 0; i < tbm_buffer_ip.fds.size(); ++i) {
+    bos.emplace_back(
+        tbm_bo_import_fd(buffer_mgr.get(), tbm_buffer_ip.fds[i].get()));
+
+    if (!bos.back()) {
+      LOG(WARNING) << "Failed to import tbm_bo from fd";
+      return out_pair;
+    }
+
+    bos_raw.emplace_back(bos.back().get());
+    tbm_buffer.key[i] = tbm_bo_export(bos_raw.back());
+  }
+
+  TbmSurfaceReleaseCbRunner release_cb;
+  {
+    tbm_surface_info_s tbm_si{};
+    tbm_si.bpp = tbm_surface_internal_get_bpp(tbm_buffer_ip.tbm_format);
+    tbm_si.num_planes = tbm_buffer_ip.planes.size();
+    tbm_si.format = tbm_buffer_ip.tbm_format;
+    tbm_si.width = tbm_buffer_ip.width;
+    tbm_si.height = tbm_buffer_ip.height;
+    for (uint32_t i = 0; i < tbm_buffer_ip.planes.size(); ++i) {
+      tbm_si.planes[i].offset = tbm_buffer_ip.planes[i].offset;
+      tbm_si.planes[i].size = tbm_buffer_ip.planes[i].size;
+      tbm_si.planes[i].stride = tbm_buffer_ip.planes[i].stride;
+      tbm_si.size += tbm_si.planes[i].size;
+
+      tbm_buffer.strides[i] = tbm_buffer_ip.planes[i].stride;
+    }
+
+    auto tbm_surface = tbm_surface_internal_create_with_bos(
+        &tbm_si, bos_raw.data(), bos_raw.size());
+
+    if (!tbm_surface) {
+      LOG(WARNING) << "Failed to create tbm_surface_h from provided tbm_bo's";
+      return out_pair;
+    }
+
+    tbm_buffer.tbm_surface =
+        reinterpret_cast<decltype(tbm_buffer.tbm_surface)>(tbm_surface);
+
+    release_cb = base::ScopedClosureRunner{base::BindOnce(
+        [](tbm_surface_h tbm_surface) { tbm_surface_destroy(tbm_surface); },
+        tbm_surface)};
+  }
+
+  tbm_buffer.width = tbm_buffer_ip.width;
+  tbm_buffer.height = tbm_buffer_ip.height;
+
+  tbm_buffer.tbm_destroy_type = tbm_buffer_ip.tbm_destroy_type;
+  tbm_buffer.pts = tbm_buffer_ip.pts;
+  tbm_buffer.duration = tbm_buffer_ip.duration;
+
+  out_pair = std::make_pair(std::move(tbm_buffer), std::move(release_cb));
+#endif  // defined(TIZEN_TBM_SUPPORT)
+
+  return out_pair;
+}
+
+}  // namespace gfx
\ No newline at end of file
diff --git a/tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.h b/tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.h
new file mode 100644 (file)
index 0000000..3c02b35
--- /dev/null
@@ -0,0 +1,74 @@
+// Copyright 2022 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_GFX_TBM_BUFFER_HANDLE_INTER_PROCESS_H
+#define UI_GFX_TBM_BUFFER_HANDLE_INTER_PROCESS_H
+
+#include <utility>
+
+#include "base/functional/callback_forward.h"
+#include "base/functional/callback_helpers.h"
+#include "ui/gfx/geometry/size.h"
+#include "ui/gfx/gfx_export.h"
+#include "ui/gfx/tbm_buffer_handle.h"
+
+#if defined(TIZEN_TBM_SUPPORT)
+#include <array>
+
+#include <tbm_bufmgr.h>
+#include <tbm_surface.h>
+#include <tbm_surface_internal.h>
+#include "mojo/public/cpp/platform/platform_handle.h"
+#endif
+
+namespace gfx {
+
+#if defined(TIZEN_TBM_SUPPORT)
+struct GFX_EXPORT TbmSurfacePlaneParameters {
+  uint32_t offset{0};
+  uint32_t size{0};
+  uint32_t stride{0};
+};
+
+struct GFX_EXPORT TbmSurfaceParameters {
+  tbm_format format{0};
+  std::vector<TbmSurfacePlaneParameters> planes;
+  Size size;
+
+  bool IsValid() const { return format && !planes.empty() && !size.IsEmpty(); }
+};
+#endif  // defined(TIZEN_TBM_SUPPORT)
+
+struct GFX_EXPORT TbmBufferHandleInterProcess {
+#if defined(TIZEN_TBM_SUPPORT)
+  size_t media_packet{0};
+  int32_t player_id{-1};
+  TbmDestroyType tbm_destroy_type{kDestroyTbmByEgl};
+  std::vector<base::ScopedFD> fds{};
+  int32_t tbm_format{-1};
+  std::vector<TbmSurfacePlaneParameters> planes;
+  int32_t width{-1};
+  int32_t height{-1};
+  uint64_t pts{0};
+  uint64_t duration{0};
+#endif  // defined(TIZEN_TBM_SUPPORT)
+};
+
+#if defined(TIZEN_TBM_SUPPORT)
+std::vector<base::ScopedFD> GetBufferObjectFdsFromSurface(
+    tbm_surface_h tbm_surface);
+
+TbmSurfaceParameters GetTbmParamsFromSurface(tbm_surface_h tbm_surface);
+#endif  // defined(TIZEN_TBM_SUPPORT)
+
+TbmBufferHandleInterProcess ToTbmBufferHandleInterProcess(
+    const TbmBufferHandle&);
+
+using TbmSurfaceReleaseCbRunner = base::ScopedClosureRunner;
+std::pair<TbmBufferHandle, TbmSurfaceReleaseCbRunner> ToTbmBufferHandle(
+    const TbmBufferHandleInterProcess&);
+
+}  // namespace gfx
+
+#endif  // UI_GFX_TBM_BUFFER_HANDLE_INTER_PROCESS_H
diff --git a/tizen_src/chromium_impl/ui/gfx/tbm_surface.cc b/tizen_src/chromium_impl/ui/gfx/tbm_surface.cc
new file mode 100644 (file)
index 0000000..8fe009b
--- /dev/null
@@ -0,0 +1,77 @@
+// Copyright 2022 Samsung Electronics Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/tbm_surface.h"
+
+#include <tbm_bo.h>
+#include <tbm_bufmgr.h>
+#include <tbm_surface.h>
+#include <tbm_surface_internal.h>
+
+#include "base/logging.h"
+
+namespace gfx {
+
+std::unique_ptr<TbmSurface> TbmSurface::ImportTbmSurface(
+    const NativePixmapHandle& native_pixmap_handle,
+    const gfx::Size& picture_size) {
+  // Currently this class supports only NV12 TBMs.
+  constexpr static const size_t kNV12Planes = 2;
+  if (native_pixmap_handle.planes.size() != kNV12Planes) {
+    LOG(ERROR) << "Invalid pixmap handle, expected 2 planes, got: "
+               << native_pixmap_handle.planes.size();
+    return nullptr;
+  }
+
+  tbm_surface_info_s tbmsi{};
+  tbmsi.bpp = tbm_surface_internal_get_bpp(TBM_FORMAT_NV12);
+  tbmsi.num_planes = tbm_surface_internal_get_num_planes(TBM_FORMAT_NV12);
+  tbmsi.format = TBM_FORMAT_NV12;
+  tbmsi.width = picture_size.width();
+  tbmsi.height = picture_size.height();
+
+  auto buf_mgr = TbmBufMgrType(tbm_bufmgr_init(-1));
+  if (!buf_mgr) {
+    LOG(ERROR) << "Cannot create buffer manager";
+    return nullptr;
+  }
+
+  std::vector<TbmBOType> bos;
+  std::vector<tbm_bo> bos_raw;
+  bos.reserve(native_pixmap_handle.planes.size());
+  bos_raw.reserve(native_pixmap_handle.planes.size());
+
+  for (size_t i = 0; i < native_pixmap_handle.planes.size(); ++i) {
+    if (!native_pixmap_handle.planes[i].fd.is_valid()) {
+      LOG(ERROR) << "Invalid FD, cannot import";
+      return nullptr;
+    }
+    bos.emplace_back(tbm_bo_import_fd(buf_mgr.get(),
+                                      native_pixmap_handle.planes[i].fd.get()));
+    bos_raw.emplace_back(bos.back().get());
+    // TBM surface must contain different buffer objects.
+    if (i > 0 && bos[i].get() == bos[i - 1].get()) {
+      return nullptr;
+    }
+
+    tbmsi.planes[i].offset = native_pixmap_handle.planes[i].offset;
+    tbmsi.planes[i].size = native_pixmap_handle.planes[i].size;
+    tbmsi.planes[i].stride = native_pixmap_handle.planes[i].stride;
+    tbmsi.size += tbmsi.planes[i].size;
+  }
+
+  auto surface = TbmSurfaceType(tbm_surface_internal_create_with_bos(
+      &tbmsi, bos_raw.data(), bos_raw.size()));
+
+  if (!surface) {
+    LOG(ERROR) << "Cannot create surface";
+    return nullptr;
+  }
+  return std::make_unique<TbmSurface>(std::move(buf_mgr), std::move(surface));
+}
+
+TbmSurface::TbmSurface(TbmBufMgrType buf_mgr, TbmSurfaceType handle)
+    : buf_mgr_(std::move(buf_mgr)), handle_(std::move(handle)) {}
+
+}  // namespace gfx
diff --git a/tizen_src/chromium_impl/ui/gfx/tbm_surface.h b/tizen_src/chromium_impl/ui/gfx/tbm_surface.h
new file mode 100644 (file)
index 0000000..d47c854
--- /dev/null
@@ -0,0 +1,39 @@
+// Copyright 2022 Samsung Electronics Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TIZEN_SRC_CHROMIUM_IMPL_UI_GFX_TBM_SURFACE_H_
+#define TIZEN_SRC_CHROMIUM_IMPL_UI_GFX_TBM_SURFACE_H_
+
+#include <memory>
+
+#include "tizen_src/chromium_impl/ui/gfx/tbm_utils.h"
+#include "ui/gfx/geometry/size.h"
+#include "ui/gfx/native_pixmap_handle.h"
+
+namespace gfx {
+
+class TbmSurface {
+ public:
+  static std::unique_ptr<TbmSurface> ImportTbmSurface(
+      const NativePixmapHandle& native_pixmap_handle,
+      const gfx::Size& picture_size);
+
+  tbm_surface_h operator*() const { return handle_.get(); }
+
+ private:
+  // GCC compiler requires namespace specification for `Tbm*` wrappers,
+  // otherwise compile error is being reported.
+  friend std::unique_ptr<TbmSurface> std::make_unique<TbmSurface>(
+      gfx::TbmBufMgrType&&,
+      gfx::TbmSurfaceType&&);
+
+  TbmSurface(TbmBufMgrType buf_mgr, TbmSurfaceType handle);
+
+  TbmBufMgrType buf_mgr_;
+  TbmSurfaceType handle_;
+};
+
+}  // namespace gfx
+
+#endif  // TIZEN_SRC_CHROMIUM_IMPL_UI_GFX_TBM_SURFACE_H_
diff --git a/tizen_src/chromium_impl/ui/gfx/tbm_utils.cc b/tizen_src/chromium_impl/ui/gfx/tbm_utils.cc
new file mode 100644 (file)
index 0000000..a6aa16a
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2024 Samsung Electronics Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "tizen_src/chromium_impl/ui/gfx/tbm_utils.h"
+
+#include <tbm_bo.h>
+#include <tbm_bufmgr.h>
+#include <tbm_surface.h>
+#include <tbm_surface_internal.h>
+
+namespace gfx {
+
+void TbmBODeleter::operator()(tbm_bo bo) {
+  tbm_bo_unref(bo);
+}
+
+void TbmSurfaceDeleter::operator()(tbm_surface_h surface) {
+  tbm_surface_internal_destroy(surface);
+}
+
+void TbmBufMgrDeleter::operator()(tbm_bufmgr bufmgr) {
+  tbm_bufmgr_deinit(bufmgr);
+}
+
+}  // namespace gfx
\ No newline at end of file
diff --git a/tizen_src/chromium_impl/ui/gfx/tbm_utils.h b/tizen_src/chromium_impl/ui/gfx/tbm_utils.h
new file mode 100644 (file)
index 0000000..da4f747
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright 2024 Samsung Electronics Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TIZEN_SRC_CHROMIUM_IMPL_UI_GFX_TBM_UTILS_H_
+#define TIZEN_SRC_CHROMIUM_IMPL_UI_GFX_TBM_UTILS_H_
+
+#include <memory>
+
+#include <tbm_type.h>
+#include <tbm_type_common.h>
+
+namespace gfx {
+
+struct TbmBODeleter {
+  void operator()(tbm_bo bo);
+};
+
+struct TbmSurfaceDeleter {
+  void operator()(tbm_surface_h surface);
+};
+
+struct TbmBufMgrDeleter {
+  void operator()(tbm_bufmgr bufmgr);
+};
+
+using TbmBOType =
+    std::unique_ptr<std::remove_pointer<tbm_bo>::type, TbmBODeleter>;
+
+using TbmSurfaceType = std::unique_ptr<std::remove_pointer<tbm_surface_h>::type,
+                                       TbmSurfaceDeleter>;
+
+using TbmBufMgrType =
+    std::unique_ptr<std::remove_pointer<tbm_bufmgr>::type, TbmBufMgrDeleter>;
+}  // namespace gfx
+
+#endif  // TIZEN_SRC_CHROMIUM_IMPL_UI_GFX_TBM_UTILS_H_
index 7e08db0..6a55e27 100644 (file)
@@ -63,8 +63,24 @@ external_ui_gfx_sources = [
   "//tizen_src/chromium_impl/ui/display/device_display_info_efl.h",
   "//tizen_src/chromium_impl/ui/display/device_display_info_observer_efl.h",
   "//tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle.h",
+  "//tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.cc",
+  "//tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.h",
 ]
 
+if (tizen_product_tv) {
+  external_ui_gfx_sources += [
+    "//tizen_src/chromium_impl/ui/gfx/tbm_surface.cc",
+    "//tizen_src/chromium_impl/ui/gfx/tbm_surface.h",
+  ]
+}
+
+if (tizen_tbm_support) {
+  external_ui_gfx_sources += [
+    "//tizen_src/chromium_impl/ui/gfx/tbm_utils.cc",
+    "//tizen_src/chromium_impl/ui/gfx/tbm_utils.h",
+  ]
+}
+
 # For //ui/gfx/x target
 external_ui_gfx_x11_sources =
     [ "//tizen_src/chromium_impl/ui/gfx/x/x11_types_override.cc" ]
index 56272bb..ab4239a 100644 (file)
@@ -28,7 +28,7 @@
 #endif
 
 #if defined(TIZEN_TBM_SUPPORT)
-#include "ui/gfx/tbm_buffer_handle.h"
+#include "ui/gfx/tbm_buffer_handle_inter_process.h"
 #endif
 
 namespace base {
@@ -90,15 +90,7 @@ struct GFX_EXPORT GpuMemoryBufferHandle {
   base::android::ScopedHardwareBufferHandle android_hardware_buffer;
 #endif
 #if defined(TIZEN_TBM_SUPPORT)
-  size_t tbm_surface{0};
-  size_t media_packet{0};
-  TbmDestroyType tbm_destroy_type = kDestroyTbmByEgl;
-  int32_t player_id = 0;
-  int32_t key_num = 0;
-  int32_t key[4];
-  int32_t strides[4];
-  int32_t width = 0;
-  int32_t height = 0;
+  TbmBufferHandleInterProcess tbm_buffer_handle_ip;
 #endif
 };
 
index bbfb870..4a6fdd4 100644 (file)
@@ -96,8 +96,9 @@ mojom("mojom") {
           cpp = "::gfx::GpuMemoryBufferType"
         },
         {
-          mojom = "gfx.mojom.TbmBufferHandle"
-          cpp = "::gfx::TbmBufferHandle"
+          mojom = "gfx.mojom.TbmBufferHandleInterProcess"
+          cpp = "::gfx::TbmBufferHandleInterProcess"
+          move_only = true
         },
       ]
 
index 88c3c04..486051b 100644 (file)
@@ -76,25 +76,38 @@ struct GpuMemoryBufferHandle {
   uint32 stride;
 
   [EnableIf=tizen_tbm_support]
-  uint64 tbm_surface;
+  TbmBufferHandleInterProcess tbm_buffer_handle_ip;
 
+  GpuMemoryBufferPlatformHandle? platform_handle;
+};
+
+// gfx::TbmBufferPlaneParameters
+[EnableIf=tizen_tbm_support]
+struct TbmSurfacePlaneParameters {
+  uint32 offset;
+  uint32 size;
+  uint32 stride;
+};
+
+// gfx::TbmBufferHandleInterProcess
+struct TbmBufferHandleInterProcess {
   [EnableIf=tizen_tbm_support]
   uint64 media_packet;
 
   [EnableIf=tizen_tbm_support]
-  TbmDestroyType tbm_destroy_type;
+  int32 player_id;
 
   [EnableIf=tizen_tbm_support]
-  int32 player_id;
+  TbmDestroyType tbm_destroy_type;
 
   [EnableIf=tizen_tbm_support]
-  int32 key_num;
+  array<handle<platform>> fds;
 
   [EnableIf=tizen_tbm_support]
-  array<int32, 4> key;
+  int32 tbm_format;
 
   [EnableIf=tizen_tbm_support]
-  array<int32, 4> strides;
+  array<TbmSurfacePlaneParameters> planes;
 
   [EnableIf=tizen_tbm_support]
   int32 width;
@@ -102,35 +115,9 @@ struct GpuMemoryBufferHandle {
   [EnableIf=tizen_tbm_support]
   int32 height;
 
-  GpuMemoryBufferPlatformHandle? platform_handle;
-};
-
-// gfx::TbmBufferHandle
-struct TbmBufferHandle {
-  [EnableIf=tizen_tbm_support]
-  uint32 tbm_surface;
-
   [EnableIf=tizen_tbm_support]
-  uint32 media_packet;
+  uint64 pts;
 
   [EnableIf=tizen_tbm_support]
-  TbmDestroyType tbm_destroy_type;
-
-  [EnableIf=tizen_tbm_support]
-  int32 player_id;
-
-  [EnableIf=tizen_tbm_support]
-  int32 key_num;
-
-  [EnableIf=tizen_tbm_support]
-  array<int32, 4> key;
-
-  [EnableIf=tizen_tbm_support]
-  array<int32, 4> strides;
-
-  [EnableIf=tizen_tbm_support]
-  int32 width;
-
-  [EnableIf=tizen_tbm_support]
-  int32 height;
+  uint64 duration;
 };
index d990b94..f1117c3 100644 (file)
@@ -4,7 +4,12 @@
 
 #include "ui/gfx/mojom/buffer_types_mojom_traits.h"
 
+#include <algorithm>
+#include <iterator>
+
 #include "build/build_config.h"
+#include "mojo/public/cpp/platform/platform_handle.h"
+#include "ui/gfx/tbm_buffer_handle_inter_process.h"
 
 #if BUILDFLAG(IS_ANDROID)
 #include "base/android/scoped_hardware_buffer_handle.h"
@@ -99,20 +104,11 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
   out->offset = data.offset();
   out->stride = data.stride();
 #if defined(TIZEN_TBM_SUPPORT)
-  out->tbm_surface = data.tbm_surface();
-  out->media_packet = data.media_packet();
-  out->player_id = data.player_id();
-  out->key_num = data.key_num();
-  out->width = data.width();
-  out->height = data.height();
-  data.ReadTbmDestroyType(&out->tbm_destroy_type);
-  base::span<int32_t> key(out->key);
-  if (!data.ReadKey(&key))
+  gfx::TbmBufferHandleInterProcess tbm_buffer_handle_ip;
+  if (!data.ReadTbmBufferHandleIp(&tbm_buffer_handle_ip))
     return false;
 
-  base::span<int32_t> strides(out->strides);
-  if (!data.ReadStrides(&strides))
-    return false;
+  out->tbm_buffer_handle_ip = std::move(tbm_buffer_handle_ip);
 #endif
   gfx::mojom::GpuMemoryBufferPlatformHandlePtr platform_handle;
   if (!data.ReadPlatformHandle(&platform_handle)) {
@@ -184,53 +180,72 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
 }
 
 #if defined(TIZEN_TBM_SUPPORT)
-// static
-base::span<const int32_t> StructTraits<
-    gfx::mojom::GpuMemoryBufferHandleDataView,
-    gfx::GpuMemoryBufferHandle>::key(const gfx::GpuMemoryBufferHandle& input) {
-  return input.key;
+bool StructTraits<gfx::mojom::TbmSurfacePlaneParametersDataView,
+                  gfx::TbmSurfacePlaneParameters>::
+    Read(gfx::mojom::TbmSurfacePlaneParametersDataView data,
+         gfx::TbmSurfacePlaneParameters* out) {
+  out->offset = data.offset();
+  out->size = data.size();
+  out->stride = data.stride();
+
+  return true;
 }
 
-// static
-base::span<const int32_t> StructTraits<
-    gfx::mojom::GpuMemoryBufferHandleDataView,
-    gfx::GpuMemoryBufferHandle>::strides(const gfx::GpuMemoryBufferHandle&
-                                             input) {
-  return input.strides;
+std::vector<mojo::PlatformHandle> StructTraits<
+    gfx::mojom::TbmBufferHandleInterProcessDataView,
+    gfx::TbmBufferHandleInterProcess>::fds(gfx::TbmBufferHandleInterProcess&
+                                               input) {
+  std::vector<mojo::PlatformHandle> platform_handles;
+  platform_handles.reserve(input.fds.size());
+  std::transform(std::make_move_iterator(input.fds.begin()),
+                 std::make_move_iterator(input.fds.end()),
+                 std::back_inserter(platform_handles), [](base::ScopedFD&& fd) {
+                   return mojo::PlatformHandle(std::move(fd));
+                 });
+  return platform_handles;
+}
+
+std::vector<gfx::TbmSurfacePlaneParameters> StructTraits<
+    gfx::mojom::TbmBufferHandleInterProcessDataView,
+    gfx::TbmBufferHandleInterProcess>::planes(gfx::TbmBufferHandleInterProcess&
+                                                  input) {
+  return std::move(input.planes);
 }
 
-bool StructTraits<gfx::mojom::TbmBufferHandleDataView, gfx::TbmBufferHandle>::
-    Read(gfx::mojom::TbmBufferHandleDataView data, gfx::TbmBufferHandle* out) {
-  out->tbm_surface = data.tbm_surface();
+bool StructTraits<gfx::mojom::TbmBufferHandleInterProcessDataView,
+                  gfx::TbmBufferHandleInterProcess>::
+    Read(gfx::mojom::TbmBufferHandleInterProcessDataView data,
+         gfx::TbmBufferHandleInterProcess* out) {
   out->media_packet = data.media_packet();
   out->player_id = data.player_id();
-  out->key_num = data.key_num();
-  out->width = data.width();
-  out->height = data.height();
-  data.ReadTbmDestroyType(&out->tbm_destroy_type);
-  base::span<int32_t> key(out->key);
-  if (!data.ReadKey(&key))
+
+  if (!data.ReadTbmDestroyType(&out->tbm_destroy_type))
     return false;
 
-  base::span<int32_t> strides(out->strides);
-  if (!data.ReadStrides(&strides))
+  std::vector<mojo::PlatformHandle> fds;
+  if (!data.ReadFds(&fds))
     return false;
-  return true;
-}
 
-// static
-base::span<const int32_t>
-StructTraits<gfx::mojom::TbmBufferHandleDataView, gfx::TbmBufferHandle>::key(
-    const gfx::TbmBufferHandle& input) {
-  return input.key;
-}
+  out->fds.clear();
+  out->fds.reserve(fds.size());
+  std::transform(fds.begin(), fds.end(), std::back_inserter(out->fds),
+                 [](mojo::PlatformHandle& handle) { return handle.TakeFD(); });
 
-// static
-base::span<const int32_t>
-StructTraits<gfx::mojom::TbmBufferHandleDataView,
-             gfx::TbmBufferHandle>::strides(const gfx::TbmBufferHandle& input) {
-  return input.strides;
+  out->tbm_format = data.tbm_format();
+
+  std::vector<gfx::TbmSurfacePlaneParameters> planes;
+  if (!data.ReadPlanes(&planes))
+    return false;
+
+  out->planes = std::move(planes);
+  out->width = data.width();
+  out->height = data.height();
+  out->pts = data.pts();
+  out->duration = data.duration();
+
+  return true;
 }
-#endif
+
+#endif  // defined(TIZEN_TBM_SUPPORT)
 
 }  // namespace mojo
index 2146030..d875abf 100644 (file)
@@ -5,19 +5,20 @@
 #ifndef UI_GFX_MOJOM_BUFFER_TYPES_MOJOM_TRAITS_H_
 #define UI_GFX_MOJOM_BUFFER_TYPES_MOJOM_TRAITS_H_
 
-
 #include "base/component_export.h"
 #include "base/notreached.h"
 #include "build/build_config.h"
 #include "mojo/public/cpp/bindings/enum_traits.h"
 #include "mojo/public/cpp/bindings/struct_traits.h"
+#include "mojo/public/cpp/platform/platform_handle.h"
 #include "ui/gfx/buffer_types.h"
 #include "ui/gfx/gpu_memory_buffer.h"
 #include "ui/gfx/mojom/buffer_types.mojom-shared.h"
 #include "ui/gfx/mojom/native_handle_types.mojom.h"
+#include "ui/gfx/tbm_buffer_handle_inter_process.h"
 
 #if defined(TIZEN_TBM_SUPPORT)
-#include "tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle.h"
+#include "tizen_src/chromium_impl/ui/gfx/tbm_buffer_handle_inter_process.h"
 #endif
 
 namespace mojo {
@@ -243,32 +244,9 @@ struct COMPONENT_EXPORT(GFX_SHARED_MOJOM_TRAITS)
     return handle.stride;
   }
 #if defined(TIZEN_TBM_SUPPORT)
-  static size_t tbm_surface(const gfx::GpuMemoryBufferHandle& handle) {
-    return handle.tbm_surface;
-  }
-  static size_t media_packet(const gfx::GpuMemoryBufferHandle& handle) {
-    return handle.media_packet;
-  }
-  static int32_t player_id(const gfx::GpuMemoryBufferHandle& handle) {
-    return handle.player_id;
-  }
-
-  static int32_t key_num(const gfx::GpuMemoryBufferHandle& handle) {
-    return handle.key_num;
-  }
-  static base::span<const int32_t> key(const gfx::GpuMemoryBufferHandle& input);
-  static base::span<const int32_t> strides(
-      const gfx::GpuMemoryBufferHandle& input);
-
-  static int32_t width(const gfx::GpuMemoryBufferHandle& handle) {
-    return handle.width;
-  }
-  static int32_t height(const gfx::GpuMemoryBufferHandle& handle) {
-    return handle.height;
-  }
-  static gfx::TbmDestroyType tbm_destroy_type(
-      const gfx::GpuMemoryBufferHandle& handle) {
-    return handle.tbm_destroy_type;
+  static gfx::TbmBufferHandleInterProcess tbm_buffer_handle_ip(
+      gfx::GpuMemoryBufferHandle& handle) {
+    return std::move(handle.tbm_buffer_handle_ip);
   }
 #endif
   static mojo::StructPtr<gfx::mojom::GpuMemoryBufferPlatformHandle>
@@ -281,35 +259,56 @@ struct COMPONENT_EXPORT(GFX_SHARED_MOJOM_TRAITS)
 #if defined(TIZEN_TBM_SUPPORT)
 template <>
 struct COMPONENT_EXPORT(GFX_SHARED_MOJOM_TRAITS)
-    StructTraits<gfx::mojom::TbmBufferHandleDataView, gfx::TbmBufferHandle> {
-  static uint32_t tbm_surface(const gfx::TbmBufferHandle& handle) {
-    return handle.tbm_surface;
+    StructTraits<gfx::mojom::TbmSurfacePlaneParametersDataView,
+                 gfx::TbmSurfacePlaneParameters> {
+  static uint32_t offset(const gfx::TbmSurfacePlaneParameters& handle) {
+    return handle.offset;
   }
-  static uint32_t media_packet(const gfx::TbmBufferHandle& handle) {
+  static uint32_t size(const gfx::TbmSurfacePlaneParameters& handle) {
+    return handle.size;
+  }
+  static uint32_t stride(const gfx::TbmSurfacePlaneParameters& handle) {
+    return handle.stride;
+  }
+  static bool Read(gfx::mojom::TbmSurfacePlaneParametersDataView data,
+                   gfx::TbmSurfacePlaneParameters* handle);
+};
+
+template <>
+struct COMPONENT_EXPORT(GFX_SHARED_MOJOM_TRAITS)
+    StructTraits<gfx::mojom::TbmBufferHandleInterProcessDataView,
+                 gfx::TbmBufferHandleInterProcess> {
+  static size_t media_packet(const gfx::TbmBufferHandleInterProcess& handle) {
     return handle.media_packet;
   }
-  static int32_t player_id(const gfx::TbmBufferHandle& handle) {
+  static int32_t player_id(const gfx::TbmBufferHandleInterProcess& handle) {
     return handle.player_id;
   }
-
-  static int32_t key_num(const gfx::TbmBufferHandle& handle) {
-    return handle.key_num;
+  static gfx::TbmDestroyType tbm_destroy_type(
+      const gfx::TbmBufferHandleInterProcess& handle) {
+    return handle.tbm_destroy_type;
   }
-  static base::span<const int32_t> key(const gfx::TbmBufferHandle& input);
-  static base::span<const int32_t> strides(const gfx::TbmBufferHandle& input);
-
-  static int32_t width(const gfx::TbmBufferHandle& handle) {
+  static std::vector<mojo::PlatformHandle> fds(
+      gfx::TbmBufferHandleInterProcess& input);
+  static int32_t tbm_format(const gfx::TbmBufferHandleInterProcess& handle) {
+    return handle.tbm_format;
+  }
+  static std::vector<gfx::TbmSurfacePlaneParameters> planes(
+      gfx::TbmBufferHandleInterProcess& input);
+  static int32_t width(const gfx::TbmBufferHandleInterProcess& handle) {
     return handle.width;
   }
-  static int32_t height(const gfx::TbmBufferHandle& handle) {
+  static int32_t height(const gfx::TbmBufferHandleInterProcess& handle) {
     return handle.height;
   }
-  static gfx::TbmDestroyType tbm_destroy_type(
-      const gfx::TbmBufferHandle& handle) {
-    return handle.tbm_destroy_type;
+  static uint64_t pts(const gfx::TbmBufferHandleInterProcess& handle) {
+    return handle.pts;
+  }
+  static uint64_t duration(const gfx::TbmBufferHandleInterProcess& handle) {
+    return handle.duration;
   }
-  static bool Read(gfx::mojom::TbmBufferHandleDataView data,
-                   gfx::TbmBufferHandle* handle);
+  static bool Read(gfx::mojom::TbmBufferHandleInterProcessDataView data,
+                   gfx::TbmBufferHandleInterProcess* handle);
 };
 
 template <>