chromium/media/gpu/chromeos/BUILD.gn

# Copyright 2019 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/chromeos/ui_mode.gni")
import("//gpu/vulkan/features.gni")
import("//media/gpu/args.gni")
import("//testing/test.gni")
import("//third_party/protobuf/proto_library.gni")

# V4L2 and VAAPI for video acceleration should not be enabled simultaneously.
assert(!(use_v4l2_codec && use_vaapi))

assert(use_v4l2_codec || use_vaapi)

# V4L2 or Vaapi imply the OS is Linux or ChromeOS
assert(is_linux || is_chromeos)

# This target can depend on targets in //media/gpu/{v4l2,vaapi}.
source_set("chromeos") {
  # TODO(crbug.com/1006266): consider using |use_chromeos_video_acceleration|.
  defines = [ "MEDIA_GPU_IMPLEMENTATION" ]
  sources = [
    "image_processor_factory.cc",
    "oop_video_decoder.cc",
    "video_decoder_pipeline.cc",
  ]

  public_deps = [ ":common" ]

  deps = [
    "//base",
    "//build/config/linux/libdrm",
    "//media",
    "//media/gpu:buffer_validation",
    "//media/gpu:buildflags",
    "//media/gpu:command_buffer_helper",
    "//media/gpu:common",
    "//media/mojo/common:common",
  ]

  if (use_vaapi) {
    deps += [
      "//media/gpu/vaapi",
      "//media/gpu/vaapi:common",
    ]
  }

  if (use_v4l2_codec) {
    deps += [ "//media/gpu/v4l2" ]
  }

  if (is_chromeos) {
    deps +=
        [ "//chromeos/components/cdm_factory_daemon:cdm_factory_daemon_gpu" ]
  }
}

# This target can be depended by targets in //media/gpu/{v4l2,vaapi}.
source_set("common") {
  defines = [ "MEDIA_GPU_IMPLEMENTATION" ]
  sources = [
    "chromeos_status.h",
    "dmabuf_video_frame_pool.cc",
    "dmabuf_video_frame_pool.h",
    "frame_resource_converter.cc",
    "frame_resource_converter.h",
    "gl_image_processor_backend.cc",
    "gl_image_processor_backend.h",
    "gpu_buffer_layout.cc",
    "gpu_buffer_layout.h",
    "image_processor.cc",
    "image_processor.h",
    "image_processor_backend.cc",
    "image_processor_backend.h",
    "image_processor_factory.h",
    "image_processor_with_pool.cc",
    "image_processor_with_pool.h",
    "libyuv_image_processor_backend.cc",
    "libyuv_image_processor_backend.h",
    "mailbox_frame_registry.cc",
    "mailbox_frame_registry.h",
    "mailbox_video_frame_converter.cc",
    "mailbox_video_frame_converter.h",
    "native_pixmap_frame_resource.cc",
    "native_pixmap_frame_resource.h",
    "oop_video_decoder.h",
    "platform_video_frame_pool.cc",
    "platform_video_frame_pool.h",
    "registered_mailbox_frame_converter.cc",
    "registered_mailbox_frame_converter.h",
    "shaders/shaders.h",
    "vd_video_decode_accelerator.cc",
    "vd_video_decode_accelerator.h",
    "vda_video_frame_pool.cc",
    "vda_video_frame_pool.h",
    "video_decoder_pipeline.h",
  ]

  # TODO(crbug.com/40652235): Merge :fourcc to :common.
  public_deps = [
    ":fourcc",
    ":video_frame_resource",
    ":video_frame_utils",
    "//gpu/ipc/service",
    "//media/mojo/mojom/stable:stable_video_decoder",
    "//ui/ozone",
  ]

  deps = [
    ":fourcc",
    "//base",
    "//build:chromeos_buildflags",
    "//build/config/linux/libdrm",
    "//gpu/ipc/common:common",
    "//media",
    "//media/gpu:buffer_validation",
    "//media/gpu:buildflags",
    "//media/gpu:command_buffer_helper",
    "//media/gpu:common",
    "//media/gpu:video_frame_mapper_common",
    "//third_party/libyuv",
    "//ui/gfx:buffer_types",
    "//ui/gfx:gfx_switches",
    "//ui/gfx:memory_buffer",
    "//ui/gfx/geometry",
    "//ui/gfx/linux:drm",
    "//ui/gfx/linux:gbm",
    "//ui/gl",
  ]

  if (enable_vulkan) {
    sources += [
      "vulkan_overlay_adaptor.cc",
      "vulkan_overlay_adaptor.h",
    ]
    deps += [
      "//gpu/command_buffer/service:gles2",
      "//gpu/vulkan/init:init",
    ]
  }

  if (is_chromeos) {
    sources += [
      "decoder_buffer_transcryptor.cc",
      "decoder_buffer_transcryptor.h",
    ]
    deps += [
      ":cdm-oemcrypto-proto",
      "//chromeos/components/cdm_factory_daemon:cdm_factory_daemon_gpu",
    ]
  }
}

# Although fourcc is platform-agnostic; however, it is restricted by the above
# assert(use_v4l2_codec || use_vaapi).
source_set("fourcc") {
  defines = [ "MEDIA_GPU_IMPLEMENTATION" ]
  sources = [
    "fourcc.cc",
    "fourcc.h",
  ]

  deps = [
    "//base",
    "//media",
    "//media/gpu:buildflags",
    "//media/gpu:common",
  ]
}

# This needs to be separate from :common since it is depended on by
# //media/gpu:video_frame_mapper_common.
source_set("video_frame_resource") {
  sources = [
    "frame_resource.cc",
    "frame_resource.h",
    "video_frame_resource.cc",
    "video_frame_resource.h",
  ]

  deps = [
    ":video_frame_utils",
    "//base",
    "//media",
  ]
}

source_set("video_frame_utils") {
  defines = [ "MEDIA_GPU_IMPLEMENTATION" ]
  sources = [
    "chromeos_compressed_gpu_memory_buffer_video_frame_utils.cc",
    "chromeos_compressed_gpu_memory_buffer_video_frame_utils.h",
    "platform_video_frame_utils.cc",
    "platform_video_frame_utils.h",
  ]

  deps = [
    "//base",
    "//build/config/linux/libdrm",
    "//gpu/ipc/common:common",
    "//media",
    "//media/gpu:buffer_validation",
    "//media/gpu:common",
    "//ui/gfx:buffer_types",
    "//ui/gfx:gfx_switches",
    "//ui/gfx:memory_buffer",
    "//ui/gfx/linux:drm",
    "//ui/gfx/linux:gbm",
  ]
}

source_set("video_frame_mapper") {
  defines = [ "MEDIA_GPU_IMPLEMENTATION" ]
  sources = [
    "generic_dmabuf_video_frame_mapper.cc",
    "generic_dmabuf_video_frame_mapper.h",
    "gpu_memory_buffer_video_frame_mapper.cc",
    "gpu_memory_buffer_video_frame_mapper.h",
  ]

  deps = [
    ":common",
    "//base",
    "//media",
    "//media/gpu:command_buffer_helper",
    "//media/gpu:common",
    "//media/gpu:video_frame_mapper_common",
  ]
}

if (is_chromeos) {
  proto_library("cdm-oemcrypto-proto") {
    sources = [
      "//third_party/cros_system_api/dbus/cdm_oemcrypto/secure_buffer.proto",
    ]
    proto_out_dir = "media/gpu/chromeos"
  }
}

source_set(
    "chromeos_compressed_gpu_memory_buffer_video_frame_utils_test_support") {
  testonly = true
  sources = [
    "fake_chromeos_intel_compressed_gpu_memory_buffer.cc",
    "fake_chromeos_intel_compressed_gpu_memory_buffer.h",
  ]
  deps = [
    ":common",
    "//base",
    "//build/config/linux/libdrm",
    "//ui/gfx",
  ]
}

source_set("unit_tests") {
  testonly = true
  deps = [
    ":chromeos_compressed_gpu_memory_buffer_video_frame_utils_test_support",
    ":common",
    "//base",
    "//base/test:test_support",
    "//build/config/linux/libdrm",
    "//gpu/ipc/service:service",
    "//media",
    "//media:test_support",
    "//media/gpu:buildflags",
    "//skia",
    "//testing/gmock",
    "//testing/gtest",
    "//ui/gfx:buffer_types",
    "//ui/gfx:memory_buffer",
    "//ui/gfx/geometry",
  ]
  sources = [
    "chromeos_compressed_gpu_memory_buffer_video_frame_utils_unittest.cc",
    "fourcc_unittests.cc",
    "mailbox_frame_registry_unittest.cc",
    "mailbox_video_frame_converter_unittest.cc",
    "native_pixmap_frame_resource_unittest.cc",
    "platform_video_frame_pool_unittest.cc",
    "platform_video_frame_utils_unittest.cc",
    "video_decoder_pipeline_unittest.cc",
    "video_frame_resource_unittest.cc",
  ]
  if (is_chromeos_ash) {
    deps +=
        [ "//chromeos/components/cdm_factory_daemon:cdm_factory_daemon_gpu" ]
  }
}

source_set("perf_test_utils") {
  testonly = true
  deps = [
    ":chromeos",
    "//base/test:test_support",
    "//media/gpu/test:video_test_environment",
    "//testing/gtest",
    "//testing/perf",
  ]
  sources = [
    "perf_test_util.cc",
    "perf_test_util.h",
  ]
}

test("image_processor_test") {
  sources = [ "image_processor_test.cc" ]
  deps = [
    ":chromeos",
    "//base/test:test_support",
    "//build:chromeos_buildflags",
    "//media:test_support",
    "//media/gpu:buildflags",
    "//media/gpu:video_frame_mapper_common",
    "//media/gpu/test:frame_file_writer",
    "//media/gpu/test:frame_validator",
    "//media/gpu/test:helpers",
    "//media/gpu/test:image_processor",
    "//media/gpu/test:video_test_environment",
    "//mojo/core/embedder",
    "//testing/gtest",
    "//third_party/libyuv",
    "//ui/gl",
    "//ui/gl:test_support",
  ]
  if (use_vaapi) {
    deps += [ "//media/gpu/vaapi:vaapi" ]
  }
  if (use_v4l2_codec) {
    deps += [ "//media/gpu/v4l2" ]
  }
  if (enable_vulkan) {
    deps += [ "//gpu/command_buffer/service:gles2" ]
  }
}

if (use_v4l2_codec) {
  test("image_processor_perf_test") {
    sources = [ "image_processor_perf_test.cc" ]
    deps = [
      ":chromeos",
      ":perf_test_utils",
      "//base/test:test_support",
      "//media:test_support",
      "//media/gpu:video_frame_mapper_common",
      "//media/gpu/test:helpers",
      "//media/gpu/test:video_test_environment",
      "//testing/gtest",
      "//testing/perf",
      "//third_party/libyuv",
      "//ui/gl",
      "//ui/gl:test_support",
    ]
    if (enable_vulkan) {
      deps += [ "//gpu/command_buffer/service:gles2" ]
    }
  }
}

if (use_v4l2_codec && enable_vulkan) {
  test("vulkan_overlay_adaptor_test") {
    sources = [ "vulkan_overlay_adaptor_test.cc" ]
    deps = [
      ":chromeos",
      ":perf_test_utils",
      "//base/test:test_support",
      "//gpu/command_buffer/service:gles2",
      "//media:test_support",
      "//media/gpu:video_frame_mapper_common",
      "//media/gpu/test:helpers",
      "//media/gpu/test:video_test_environment",
      "//testing/gtest",
      "//testing/perf",
      "//third_party/libyuv",
      "//ui/gl",
      "//ui/gl:test_support",
    ]
  }
}