chromium/media/gpu/vaapi/BUILD.gn

# Copyright 2018 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("//build/config/features.gni")
import("//build/config/ui.gni")
import("//media/gpu/args.gni")
import("//media/media_options.gni")
import("//testing/test.gni")
import("//tools/generate_stubs/rules.gni")

assert(is_linux || is_chromeos)
assert(use_vaapi)

# Ensure Ozone is the default configuration.
assert(use_ozone)

generate_stubs("libva_stubs") {
  extra_header = "va_stub_header.fragment"
  sigs = [ "va.sigs" ]
  if (is_chromeos_ash) {
    sigs += [ "va_prot.sigs" ]
  }
  sigs += [ "va_drm.sigs" ]

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

source_set("vaapi") {
  defines = [ "MEDIA_GPU_IMPLEMENTATION" ]
  sources = [
    "av1_vaapi_video_decoder_delegate.cc",
    "av1_vaapi_video_decoder_delegate.h",
    "av1_vaapi_video_encoder_delegate.cc",
    "av1_vaapi_video_encoder_delegate.h",
    "h264_vaapi_video_decoder_delegate.cc",
    "h264_vaapi_video_decoder_delegate.h",
    "h264_vaapi_video_encoder_delegate.cc",
    "h264_vaapi_video_encoder_delegate.h",
    "vaapi_decode_surface_handler.h",
    "vaapi_dmabuf_video_frame_mapper.cc",
    "vaapi_dmabuf_video_frame_mapper.h",
    "vaapi_image_decode_accelerator_worker.cc",
    "vaapi_image_decode_accelerator_worker.h",
    "vaapi_image_decoder.cc",
    "vaapi_image_decoder.h",
    "vaapi_image_processor_backend.cc",
    "vaapi_image_processor_backend.h",
    "vaapi_jpeg_decoder.cc",
    "vaapi_jpeg_decoder.h",
    "vaapi_jpeg_encoder.cc",
    "vaapi_jpeg_encoder.h",
    "vaapi_video_decoder.cc",
    "vaapi_video_decoder.h",
    "vaapi_video_decoder_delegate.cc",
    "vaapi_video_decoder_delegate.h",
    "vaapi_video_encode_accelerator.cc",
    "vaapi_video_encode_accelerator.h",
    "vaapi_video_encoder_delegate.cc",
    "vaapi_video_encoder_delegate.h",
    "vaapi_webp_decoder.cc",
    "vaapi_webp_decoder.h",
    "vp8_vaapi_video_decoder_delegate.cc",
    "vp8_vaapi_video_decoder_delegate.h",
    "vp8_vaapi_video_encoder_delegate.cc",
    "vp8_vaapi_video_encoder_delegate.h",
    "vp9_vaapi_video_decoder_delegate.cc",
    "vp9_vaapi_video_decoder_delegate.h",
    "vp9_vaapi_video_encoder_delegate.cc",
    "vp9_vaapi_video_encoder_delegate.h",
  ]
  if (enable_hevc_parser_and_hw_decoder) {
    sources += [
      "h265_vaapi_video_decoder_delegate.cc",
      "h265_vaapi_video_decoder_delegate.h",
    ]
  }

  configs += [ "//build/config/linux/libva" ]

  deps = [
    ":common",
    ":vaapi_status",
    "//base",
    "//build:chromeos_buildflags",
    "//gpu/command_buffer/service:gles2",
    "//gpu/config",
    "//gpu/ipc/common",
    "//gpu/ipc/service",
    "//media/gpu:common",
    "//media/gpu:video_frame_mapper_common",
    "//media/gpu/chromeos:common",
    "//mojo/public/cpp/bindings",
    "//third_party/libaom:libaomrc",
    "//third_party/libvpx:libvpxrc",
    "//third_party/libyuv",
    "//ui/gfx",
    "//ui/gfx/geometry",
  ]

  public_deps = [
    "//media",
    "//skia",
  ]

  if (is_chromeos_ash) {
    sources += [
      "vaapi_jpeg_encode_accelerator.cc",
      "vaapi_jpeg_encode_accelerator.h",
      "vaapi_mjpeg_decode_accelerator.cc",
      "vaapi_mjpeg_decode_accelerator.h",
    ]

    deps += [
      "//chromeos/components/cdm_factory_daemon:cdm_factory_daemon_gpu",
      "//components/chromeos_camera:jpeg_encode_accelerator",
      "//components/chromeos_camera:mjpeg_decode_accelerator",
    ]
  }
}

# The vaapi status functionality is in its own source set so that it can be
# depended on without pulling the //media/gpu/vaapi:vaapi target.
source_set("vaapi_status") {
  sources = [ "vaapi_status.h" ]

  visibility = [
    ":vaapi",
    "//media/mojo/mojom/stable:*",
  ]

  deps = [ "//media" ]
}

source_set("common") {
  defines = [ "MEDIA_GPU_IMPLEMENTATION" ]
  sources = [
    "vaapi_common.cc",
    "vaapi_common.h",
    "vaapi_utils.cc",
    "vaapi_utils.h",
    "vaapi_wrapper.cc",
    "vaapi_wrapper.h",
  ]
  public_deps = [
    "//base",
    "//build/config/linux/libdrm",
    "//gpu",
    "//media",
    "//media/gpu:common",
    "//media/gpu/chromeos:fourcc",
    "//ui/gfx/geometry",
  ]
  deps = [
    ":libva_stubs",
    "//build:chromeos_buildflags",
    "//media/gpu/chromeos:video_frame_resource",
    "//third_party/libyuv",
    "//ui/base:features",
    "//ui/gfx:memory_buffer",
    "//ui/gfx/linux:drm",
  ]

  configs += [ "//build/config/linux/libva" ]
}

source_set("vaapi_test_utils") {
  testonly = true
  sources = [
    "test_utils.cc",
    "test_utils.h",
  ]
  deps = [
    ":common",
    "//base",
    "//testing/gtest",
    "//third_party/libyuv:libyuv",
  ]
  if (is_chromeos_ash) {
    deps += [ "//media/gpu/test:local_gpu_memory_buffer_manager" ]
  }
  public_deps = [ "//ui/gfx/geometry" ]
}

source_set("unit_test") {
  testonly = true
  sources = [
    "h264_vaapi_video_encoder_delegate_unittest.cc",
    "vaapi_image_decode_accelerator_worker_unittest.cc",
    "vaapi_video_encode_accelerator_unittest.cc",
    "vaapi_wrapper_unittest.cc",
    "vp9_vaapi_video_encoder_delegate_unittest.cc",
  ]
  deps = [
    ":common",
    ":vaapi",
    "//base",
    "//base/test:test_support",
    "//gpu:test_support",
    "//gpu/ipc/service",
    "//media:test_support",
    "//media/gpu:common",
    "//mojo/core/embedder",
    "//testing/gmock",
    "//testing/gtest",
    "//third_party/libvpx:libvpxrc",
    "//ui/gfx:memory_buffer",
    "//ui/gfx:test_support",
    "//ui/gfx/geometry",
  ]
  if (is_chromeos_ash) {
    sources += [ "vaapi_video_decoder_unittest.cc" ]
    deps +=
        [ "//chromeos/components/cdm_factory_daemon:cdm_factory_daemon_gpu" ]
  }
}

source_set("vaapi_image_decoder_test_common") {
  testonly = true
  sources = [
    "vaapi_image_decoder_test_common.cc",
    "vaapi_image_decoder_test_common.h",
  ]
  deps = [
    ":vaapi",
    ":vaapi_test_utils",
    "//base",
    "//media:test_support",
    "//testing/gtest",
  ]
}

# TODO(crbug.com/40115082): remove is_chromeos.
if (is_chromeos_ash) {
  source_set("jpeg_decoder_unit_test") {
    testonly = true
    sources = [ "vaapi_jpeg_decoder_unittest.cc" ]
    deps = [
      ":common",
      ":vaapi",
      ":vaapi_image_decoder_test_common",
      ":vaapi_test_utils",
      "//base",
      "//media/gpu/test:local_gpu_memory_buffer_manager",
      "//testing/gtest",
      "//third_party/libyuv:libyuv",
      "//ui/gfx:memory_buffer",
      "//ui/gfx/codec",
      "//ui/gfx/geometry",
    ]
  }

  source_set("webp_decoder_unit_test") {
    testonly = true
    sources = [ "vaapi_webp_decoder_unittest.cc" ]
    deps = [
      ":common",
      ":vaapi",
      ":vaapi_image_decoder_test_common",
      ":vaapi_test_utils",
      "//base",
      "//media/gpu/test:local_gpu_memory_buffer_manager",
      "//testing/gtest",
      "//third_party/libwebp",
      "//ui/gfx:memory_buffer",
      "//ui/gfx/geometry",
    ]
  }
}

source_set("vaapi_utils_unittest") {
  testonly = true
  sources = [ "vaapi_utils_unittest.cc" ]
  deps = [
    ":common",
    "//base",
    "//base/test:test_support",
    "//testing/gtest",
    "//ui/gfx/geometry",
  ]
}

test("vaapi_unittest") {
  sources = [ "vaapi_unittest.cc" ]
  deps = [
    ":common",
    ":vaapi_utils_unittest",
    "//base",
    "//base/test:test_support",
    "//build:chromeos_buildflags",
    "//gpu",
    "//media/gpu/test:helpers",
    "//testing/gtest",
    "//third_party/minigbm",
    "//ui/gfx/linux:gbm",
  ]

  # TODO(andrescj): the Chrome bots run vaapi_unittest with the fake driver, but
  # the ChromeOS tests rely on a real driver. Therefore, we shouldn't need this
  # unconditional data_deps. Instead, we should try to re-structure things so
  # that ChromeOS can build the vaapi_unittest without building the fake driver.
  data_deps = [ "//media/gpu/vaapi/test/fake_libva_driver:fake_drv_video" ]

  # TODO(crbug.com/40115082): remove is_chromeos.
  if (is_chromeos_ash) {
    deps += [
      ":jpeg_decoder_unit_test",
      ":webp_decoder_unit_test",
    ]
  }
}

group("vaapi_fuzzers") {
  testonly = true
  public_deps =
      [ "//media/gpu/vaapi/fuzzers/jpeg_decoder:vaapi_jpeg_decoder_fuzzertest" ]
}

executable("decode_test") {
  testonly = true
  sources = [
    "test/av1_decoder.cc",
    "test/av1_decoder.h",
    "test/decode.cc",
    "test/h264_decoder.cc",
    "test/h264_decoder.h",
    "test/h264_dpb.cc",
    "test/h264_dpb.h",
    "test/h264_vaapi_wrapper.cc",
    "test/h264_vaapi_wrapper.h",
    "test/macros.h",
    "test/scoped_va_config.cc",
    "test/scoped_va_config.h",
    "test/scoped_va_context.cc",
    "test/scoped_va_context.h",
    "test/shared_va_surface.cc",
    "test/shared_va_surface.h",
    "test/vaapi_device.cc",
    "test/vaapi_device.h",
    "test/video_decoder.cc",
    "test/video_decoder.h",
    "test/vp8_decoder.cc",
    "test/vp8_decoder.h",
    "test/vp9_decoder.cc",
    "test/vp9_decoder.h",
  ]

  if (enable_platform_hevc) {
    sources += [
      "test/h265_decoder.cc",
      "test/h265_decoder.h",
      "test/h265_dpb.cc",
      "test/h265_dpb.h",
      "test/h265_vaapi_wrapper.cc",
      "test/h265_vaapi_wrapper.h",
    ]
  }

  deps = [
    ":libva_stubs",
    "//base",
    "//build/config/linux/libdrm",
    "//media",
    "//media:test_support",
    "//media/gpu:common",
    "//third_party/libgav1:libgav1_parser",
    "//third_party/libyuv",
    "//ui/gfx/codec:codec",
    "//ui/gfx/geometry",
  ]
}