chromium/gpu/BUILD.gn

# Copyright 2014 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/cronet/config.gni")
import("//build/config/ui.gni")
import("//gpu/vulkan/features.gni")
import("//skia/features.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")
import("//third_party/angle/gni/angle.gni")
import("//third_party/protobuf/proto_library.gni")
import("//ui/gl/features.gni")

if (is_android) {
  # Pull in enable_chrome_android_internal.
  import("//build/config/android/config.gni")
}

config("gpu_implementation") {
  defines = [ "GPU_IMPLEMENTATION" ]
  configs = [ "//build/config/compiler:wexit_time_destructors" ]
}

config("gpu_gles2_implementation") {
  defines = [ "GPU_GLES2_IMPLEMENTATION" ]
  configs = [ "//build/config/compiler:wexit_time_destructors" ]
}

config("gpu_util_implementation") {
  defines = [ "GPU_UTIL_IMPLEMENTATION" ]
  configs = [ "//build/config/compiler:wexit_time_destructors" ]
}

config("raster_implementation") {
  defines = [ "RASTER_IMPLEMENTATION" ]
  configs = [ "//build/config/compiler:wexit_time_destructors" ]
}

config("webgpu_implementation") {
  defines = [ "WEBGPU_IMPLEMENTATION" ]
  configs = [ "//build/config/compiler:wexit_time_destructors" ]
}

component("gpu") {
  public_deps = [
    "//gpu/command_buffer/client:client_sources",
    "//gpu/command_buffer/common:common_sources",
    "//gpu/command_buffer/service:service_sources",
    "//gpu/config:config_sources",
    "//gpu/ipc/client:ipc_client_sources",
    "//gpu/ipc/common:ipc_common_sources",
  ]
}

component("gles2") {
  public_deps = [
    "//gpu/command_buffer/client:gles2_cmd_helper_sources",
    "//gpu/command_buffer/common:gles2_sources",
    "//gpu/command_buffer/common:raster_sources",
    "//gpu/command_buffer/service:gles2_sources",
  ]
}

component("raster") {
  public_deps = [ "//gpu/command_buffer/client:raster_sources" ]
}

component("mailbox") {
  defines = [ "IS_GPU_MAILBOX_IMPL" ]
  public_deps = [ "//gpu/command_buffer/common:mailbox_sources" ]
}

component("webgpu") {
  public_deps = [ "//gpu/command_buffer/client:webgpu_sources" ]
}

static_library("test_support") {
  testonly = true
  sources = [
    "command_buffer/client/client_test_helper.cc",
    "command_buffer/client/client_test_helper.h",
    "command_buffer/client/gles2_interface_stub.cc",
    "command_buffer/client/gles2_interface_stub.h",
    "command_buffer/client/gles2_interface_stub_autogen.h",
    "command_buffer/client/gles2_interface_stub_impl_autogen.h",
    "command_buffer/client/test_gpu_memory_buffer_manager.cc",
    "command_buffer/client/test_gpu_memory_buffer_manager.h",
    "command_buffer/client/test_shared_image_interface.cc",
    "command_buffer/client/test_shared_image_interface.h",
    "command_buffer/client/webgpu_interface_stub.cc",
    "command_buffer/client/webgpu_interface_stub.h",
    "command_buffer/client/webgpu_interface_stub_autogen.h",
    "command_buffer/client/webgpu_interface_stub_impl_autogen.h",
    "command_buffer/service/copy_texture_chromium_mock.cc",
    "command_buffer/service/copy_texture_chromium_mock.h",
    "command_buffer/service/error_state_mock.cc",
    "command_buffer/service/error_state_mock.h",
    "command_buffer/service/gles2_cmd_decoder_mock.cc",
    "command_buffer/service/gles2_cmd_decoder_mock.h",
    "command_buffer/service/mocks.cc",
    "command_buffer/service/mocks.h",
    "command_buffer/service/shared_image/test_image_backing.cc",
    "command_buffer/service/shared_image/test_image_backing.h",
    "command_buffer/service/test_helper.cc",
    "command_buffer/service/test_helper.h",
    "command_buffer/service/test_memory_tracker.cc",
    "command_buffer/service/test_memory_tracker.h",
    "ipc/raster_in_process_context.cc",
    "ipc/raster_in_process_context.h",
    "ipc/service/gpu_memory_buffer_factory_test_template.h",
    "ipc/webgpu_in_process_context.cc",
    "ipc/webgpu_in_process_context.h",
  ]

  public_deps = [
    ":gles2",
    ":gpu",
    ":webgpu",
    "//gpu/command_buffer/client:gles2_interface",
    "//gpu/command_buffer/client:webgpu_interface",
    "//gpu/ipc:gpu_thread_holder",
    "//third_party/dawn/include/dawn:cpp_headers",
    "//third_party/dawn/src/dawn:proc",
  ]
  deps = [
    "//base/test:test_support",
    "//gpu/command_buffer/client:raster",
    "//gpu/command_buffer/common",
    "//gpu/ipc:gl_in_process_context",
    "//gpu/ipc/common",
    "//gpu/ipc/service",
    "//gpu/skia_bindings:skia_bindings",
    "//testing/gmock",
    "//testing/gtest",
    "//ui/gfx:test_support",
    "//ui/gl:gl_unittest_utils",
    "//ui/gl:test_support",
  ]

  if (is_fuchsia) {
    deps += [
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sysmem2:fuchsia.sysmem2_hlcpp",
      "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
    ]
  }
  if (use_static_angle) {
    deps += [ "//third_party/angle:translator" ]
  } else {
    deps += [ "//third_party/angle:translator_gl_d3d_only" ]
  }
}

if (!is_android && !is_fuchsia && !is_chromeos_ash && !is_ios) {
  proto_library("gl_lpm_fuzzer_proto") {
    sources = [ "command_buffer/tests/lpm/gl_lpm_fuzzer.proto" ]

    use_protobuf_full = true
    deps = [ "//third_party/protobuf:protobuf_full" ]
  }

  static_library("gl_lpm_shader_to_string") {
    sources = [
      "command_buffer/tests/lpm/gl_lpm_shader_to_string.cc",
      "command_buffer/tests/lpm/gl_lpm_shader_to_string.h",
    ]

    deps = [
      ":gl_lpm_fuzzer_proto",
      "//base:base",
    ]
  }

  test("gl_lpm_shader_to_string_unittest") {
    sources = [ "command_buffer/tests/lpm/gl_lpm_shader_to_string_unittest.cc" ]

    deps = [
      ":gl_lpm_shader_to_string",
      "//base/test:run_all_unittests",
      "//testing/gtest",
      "//third_party/protobuf:protobuf_full",
    ]
  }

  fuzzer_test("gl_lpm_fuzzer") {
    sources = [
      "command_buffer/tests/gl_manager.cc",
      "command_buffer/tests/gl_manager.h",
      "command_buffer/tests/gl_test_utils.cc",
      "command_buffer/tests/gl_test_utils.h",
      "command_buffer/tests/lpm/gl_lpm_fuzzer.cc",
    ]

    defines = [ "GL_GLEXT_PROTOTYPES" ]

    if (is_mac) {
      frameworks = [ "IOSurface.framework" ]
    }

    deps = [
      ":gl_lpm_fuzzer_proto",
      ":gl_lpm_shader_to_string",
      ":gles2",
      ":test_support",
      "//gpu/command_buffer/client:gles2_c_lib",
      "//gpu/command_buffer/client:gles2_implementation",
      "//gpu/command_buffer/common:gles2_utils",
      "//gpu/ipc:gl_in_process_context",
      "//gpu/ipc/service:service",
      "//testing/gtest:gtest",
      "//third_party/libprotobuf-mutator",
      "//ui/gfx:gfx",
      "//ui/gl:gl",
      "//ui/gl/init:init",
    ]

    if (use_ozone) {
      deps += [ "//ui/ozone" ]
    }
  }
}

test("gl_tests") {
  use_xvfb = use_xvfb_in_this_config

  sources = [
    "command_buffer/service/gles2_external_framebuffer_unittest.cc",
    "command_buffer/service/shared_image/egl_image_backing_factory_unittest.cc",
    "command_buffer/service/shared_image/gl_texture_image_backing_factory_unittest.cc",
    "command_buffer/service/shared_image/shared_image_factory_unittest.cc",
    "command_buffer/service/shared_image/shared_image_manager_unittest.cc",
    "command_buffer/service/shared_image/shared_image_representation_unittest.cc",
    "command_buffer/service/shared_image/shared_image_test_base.cc",
    "command_buffer/service/shared_image/shared_image_test_base.h",
    "command_buffer/service/shared_image/test_utils.cc",
    "command_buffer/service/shared_image/test_utils.h",
    "command_buffer/service/shared_image/wrapped_sk_image_backing_factory_unittest.cc",
    "command_buffer/tests/compressed_texture_test.cc",
    "command_buffer/tests/es3_misc_functions_unittest.cc",
    "command_buffer/tests/gl_angle_shader_pixel_local_storage_unittest.cc",
    "command_buffer/tests/gl_bgra_mipmap_unittest.cc",
    "command_buffer/tests/gl_bind_uniform_location_unittest.cc",
    "command_buffer/tests/gl_chromium_framebuffer_multisample_unittest.cc",
    "command_buffer/tests/gl_clear_framebuffer_unittest.cc",
    "command_buffer/tests/gl_copy_texture_CHROMIUM_unittest.cc",
    "command_buffer/tests/gl_cube_map_texture_unittest.cc",
    "command_buffer/tests/gl_depth_texture_unittest.cc",
    "command_buffer/tests/gl_deschedule_unittest.cc",
    "command_buffer/tests/gl_discardable_textures_unittest.cc",
    "command_buffer/tests/gl_dynamic_config_unittest.cc",
    "command_buffer/tests/gl_ext_blend_func_extended_unittest.cc",
    "command_buffer/tests/gl_ext_multisample_compatibility_unittest.cc",
    "command_buffer/tests/gl_ext_srgb_unittest.cc",
    "command_buffer/tests/gl_ext_window_rectangles_unittest.cc",
    "command_buffer/tests/gl_gpu_memory_buffer_unittest.cc",
    "command_buffer/tests/gl_helper_unittest.cc",
    "command_buffer/tests/gl_lose_context_chromium_unittest.cc",
    "command_buffer/tests/gl_manager.cc",
    "command_buffer/tests/gl_manager.h",
    "command_buffer/tests/gl_map_buffer_range_unittest.cc",
    "command_buffer/tests/gl_object_bindings_unittest.cc",
    "command_buffer/tests/gl_offscreen_surface_unittest.cc",
    "command_buffer/tests/gl_oob_attrib_unittest.cc",
    "command_buffer/tests/gl_pointcoord_unittest.cc",
    "command_buffer/tests/gl_program_unittest.cc",
    "command_buffer/tests/gl_query_unittest.cc",
    "command_buffer/tests/gl_readback_unittest.cc",
    "command_buffer/tests/gl_request_extension_unittest.cc",
    "command_buffer/tests/gl_set_aggressively_free_resources_unittest.cc",
    "command_buffer/tests/gl_shared_resources_unittest.cc",
    "command_buffer/tests/gl_stream_draw_unittest.cc",
    "command_buffer/tests/gl_test_setup_helper.cc",
    "command_buffer/tests/gl_test_setup_helper.h",
    "command_buffer/tests/gl_test_utils.cc",
    "command_buffer/tests/gl_test_utils.h",
    "command_buffer/tests/gl_tests_main.cc",
    "command_buffer/tests/gl_texture_storage_unittest.cc",
    "command_buffer/tests/gl_unallocated_texture_unittest.cc",
    "command_buffer/tests/gl_unittest.cc",
    "command_buffer/tests/gl_virtual_contexts_ext_window_rectangles_unittest.cc",
    "command_buffer/tests/gl_virtual_contexts_unittest.cc",
    "command_buffer/tests/gl_webgl_multi_draw_test.cc",
    "command_buffer/tests/occlusion_query_unittest.cc",
    "config/gpu_info_collector_gl_test.cc",
    "ipc/client/gpu_context_tests.h",
    "ipc/client/gpu_in_process_context_tests.cc",
    "ipc/client/raster_in_process_context_tests.cc",
  ]

  if (is_android) {
    sources += [ "command_buffer/tests/gl_unittests_android.cc" ]
  }

  # Simply loading the Vulkan driver leaks crbug.com/1134681
  if (use_dawn && !is_lsan) {
    sources += [
      "command_buffer/service/webgpu_decoder_unittest.cc",
      "command_buffer/tests/shared_image_gl_backing_produce_dawn_unittest.cc",
      "command_buffer/tests/webgpu_mailbox_unittest.cc",
      "command_buffer/tests/webgpu_test.cc",
      "command_buffer/tests/webgpu_test.h",
    ]
  }

  defines = [ "GL_GLEXT_PROTOTYPES" ]

  deps = [
    ":gles2",
    ":gpu",
    ":test_support",
    "//base",
    "//base/test:test_support",
    "//cc:test_support",
    "//cc/paint",
    "//components/viz/test:test_support",
    "//gpu/command_buffer/client:gles2_c_lib",
    "//gpu/command_buffer/client:gles2_implementation",
    "//gpu/command_buffer/client:raster",
    "//gpu/command_buffer/client:webgpu",
    "//gpu/command_buffer/common:gles2_utils",
    "//gpu/ipc:gl_in_process_context",
    "//gpu/ipc/host",
    "//gpu/ipc/service",
    "//gpu/vulkan:buildflags",
    "//gpu/webgpu:common",
    "//mojo/core/embedder",
    "//testing/gmock",
    "//testing/gtest",
    "//third_party/libyuv",
    "//ui/gfx",
    "//ui/gfx:test_support",
    "//ui/gfx/geometry",
    "//ui/gl",
    "//ui/gl:test_support",
    "//ui/gl/init",
  ]

  if (use_static_angle) {
    deps += [ "//third_party/angle:translator" ]
  } else {
    deps += [ "//third_party/angle:translator_gl_d3d_only" ]
  }

  if (use_ozone) {
    deps += [ "//ui/ozone" ]
    sources += [ "command_buffer/service/shared_image/ozone_image_backing_factory_unittest.cc" ]
  }

  if (enable_vulkan) {
    deps += [ "//gpu/vulkan/init:init" ]
  }

  libs = []

  if (is_android) {
    libs += [ "android" ]
    deps += [ "//ui/android:ui_java" ]
    sources += [ "command_buffer/service/shared_image/ahardwarebuffer_image_backing_factory_unittest.cc" ]
  } else if (is_apple) {
    frameworks = [ "IOSurface.framework" ]
    sources += [ "command_buffer/service/shared_image/iosurface_image_backing_factory_unittest.cc" ]
  } else if (is_win) {
    deps += [
      "//ui/platform_window",
      "//ui/platform_window:platform_impls",
    ]
    sources += [
      "command_buffer/service/dxgi_shared_handle_manager_unittest.cc",
      "command_buffer/service/shared_image/d3d_image_backing_factory_unittest.cc",
      "command_buffer/service/shared_image/dcomp_image_backing_factory_unittest.cc",
    ]
  } else if (is_linux) {
    # Simply loading the Vulkan driver leaks crbug.com/1134681
    # CFI error in third_party/vulkan_memory_allocator crbug.com/1139916
    if (enable_vulkan && !is_lsan && !is_cfi) {
      sources += [ "command_buffer/service/shared_image/external_vk_image_backing_factory_unittest.cc" ]
    }
  }

  # Simply loading the Vulkan driver leaks crbug.com/1134681
  if (is_linux && !is_lsan) {
    sources += [ "command_buffer/service/shared_image/angle_vulkan_image_backing_factory_unittest.cc" ]
  }

  if (use_dawn || skia_use_dawn) {
    deps += [
      "//third_party/dawn/src/dawn:cpp",
      "//third_party/dawn/src/dawn:proc",
      "//third_party/dawn/src/dawn/native",
    ]

    sources += [
      "command_buffer/service/shared_image/dawn_image_representation_unittest_common.cc",
      "command_buffer/service/shared_image/dawn_image_representation_unittest_common.h",
    ]
  }

  data_deps = [ "//testing/buildbot/filters:gl_tests_filters" ]

  if (is_android && enable_chrome_android_internal) {
    data_deps += [ "//clank/build/bot/filters:gl_tests_filters" ]
  }

  if (is_chromeos) {
    deps += [ "//ui/gfx/linux:gbm" ]
  }
}

test("gpu_unittests") {
  use_xvfb = use_xvfb_in_this_config

  sources = [
    "command_buffer/client/buffer_tracker_unittest.cc",
    "command_buffer/client/client_discardable_manager_unittest.cc",
    "command_buffer/client/client_shared_image_unittest.cc",
    "command_buffer/client/cmd_buffer_helper_test.cc",
    "command_buffer/client/command_buffer_direct_locked.cc",
    "command_buffer/client/command_buffer_direct_locked.h",
    "command_buffer/client/fenced_allocator_test.cc",
    "command_buffer/client/gles2_implementation_unittest.cc",
    "command_buffer/client/gles2_implementation_unittest_autogen.h",
    "command_buffer/client/mapped_memory_unittest.cc",
    "command_buffer/client/mock_transfer_buffer.cc",
    "command_buffer/client/mock_transfer_buffer.h",
    "command_buffer/client/program_info_manager_unittest.cc",
    "command_buffer/client/query_tracker_unittest.cc",
    "command_buffer/client/raster_implementation_gles_unittest.cc",
    "command_buffer/client/raster_implementation_unittest.cc",
    "command_buffer/client/raster_implementation_unittest_autogen.h",
    "command_buffer/client/ring_buffer_test.cc",
    "command_buffer/client/shared_image_pool_unittest.cc",
    "command_buffer/client/transfer_buffer_cmd_copy_helpers_unittest.cc",
    "command_buffer/client/transfer_buffer_unittest.cc",
    "command_buffer/client/vertex_array_object_manager_unittest.cc",
    "command_buffer/client/webgpu_implementation_unittest.cc",
    "command_buffer/client/webgpu_implementation_unittest_autogen.h",
    "command_buffer/common/buffer_unittest.cc",
    "command_buffer/common/command_buffer_shared_test.cc",
    "command_buffer/common/debug_marker_manager_unittest.cc",
    "command_buffer/common/discardable_handle_unittest.cc",
    "command_buffer/common/gles2_cmd_format_test.cc",
    "command_buffer/common/gles2_cmd_format_test_autogen.h",
    "command_buffer/common/gles2_cmd_utils_unittest.cc",
    "command_buffer/common/id_allocator_test.cc",
    "command_buffer/common/raster_cmd_format_test.cc",
    "command_buffer/common/raster_cmd_format_test_autogen.h",
    "command_buffer/common/shared_image_usage_unittest.cc",
    "command_buffer/common/shm_count_unittest.cc",
    "command_buffer/common/unittest_main.cc",
    "command_buffer/common/webgpu_cmd_format_test.cc",
    "command_buffer/common/webgpu_cmd_format_test_autogen.h",
    "command_buffer/service/buffer_manager_unittest.cc",
    "command_buffer/service/client_service_map_unittest.cc",
    "command_buffer/service/command_buffer_service_unittest.cc",
    "command_buffer/service/common_decoder_unittest.cc",
    "command_buffer/service/context_group_unittest.cc",
    "command_buffer/service/context_state_test_helpers.cc",
    "command_buffer/service/context_state_test_helpers.h",
    "command_buffer/service/context_state_test_helpers_autogen.h",
    "command_buffer/service/context_state_unittest.cc",
    "command_buffer/service/feature_info_unittest.cc",
    "command_buffer/service/framebuffer_manager_unittest.cc",
    "command_buffer/service/gl_context_mock.cc",
    "command_buffer/service/gl_context_mock.h",
    "command_buffer/service/gl_context_virtual_unittest.cc",
    "command_buffer/service/gl_surface_mock.cc",
    "command_buffer/service/gl_surface_mock.h",
    "command_buffer/service/gles2_cmd_decoder_unittest_base.cc",
    "command_buffer/service/gles2_cmd_decoder_unittest_base.h",
    "command_buffer/service/gpu_service_test.cc",
    "command_buffer/service/gpu_service_test.h",
    "command_buffer/service/gpu_tracer_unittest.cc",
    "command_buffer/service/gr_cache_controller_unittest.cc",
    "command_buffer/service/gr_shader_cache_unittest.cc",
    "command_buffer/service/id_manager_unittest.cc",
    "command_buffer/service/indexed_buffer_binding_host_unittest.cc",
    "command_buffer/service/memory_program_cache_unittest.cc",
    "command_buffer/service/multi_draw_manager_unittest.cc",
    "command_buffer/service/passthrough_program_cache_unittest.cc",
    "command_buffer/service/program_cache_unittest.cc",
    "command_buffer/service/program_manager_unittest.cc",
    "command_buffer/service/query_manager_unittest.cc",
    "command_buffer/service/raster_decoder_unittest.cc",
    "command_buffer/service/raster_decoder_unittest_1.cc",
    "command_buffer/service/raster_decoder_unittest_base.cc",
    "command_buffer/service/raster_decoder_unittest_base.h",
    "command_buffer/service/raster_decoder_unittest_context_lost.cc",
    "command_buffer/service/renderbuffer_manager_unittest.cc",
    "command_buffer/service/retaining_one_shot_timer_holder_unittest.cc",
    "command_buffer/service/scheduler_dfs_unittest.cc",
    "command_buffer/service/scheduler_unittest.cc",
    "command_buffer/service/service_discardable_manager_unittest.cc",
    "command_buffer/service/service_transfer_cache_unittest.cc",
    "command_buffer/service/shader_manager_unittest.cc",
    "command_buffer/service/shader_translator_cache_unittest.cc",
    "command_buffer/service/shader_translator_unittest.cc",
    "command_buffer/service/shared_context_state_unittest.cc",
    "command_buffer/service/shared_image/compound_image_backing_unittest.cc",
    "command_buffer/service/shared_image/gl_repack_utils_unittest.cc",
    "command_buffer/service/shared_memory_region_wrapper_unittest.cc",
    "command_buffer/service/sync_point_manager_unittest.cc",
    "command_buffer/service/task_graph_unittest.cc",
    "command_buffer/service/texture_manager_unittest.cc",
    "command_buffer/service/transfer_buffer_manager_unittest.cc",
    "command_buffer/service/transform_feedback_manager_unittest.cc",
    "command_buffer/service/vertex_array_manager_unittest.cc",
    "command_buffer/service/vertex_attrib_manager_unittest.cc",
    "config/gpu_blocklist_unittest.cc",
    "config/gpu_control_list_entry_unittest.cc",
    "config/gpu_control_list_testing_arrays_and_structs_autogen.h",
    "config/gpu_control_list_testing_autogen.cc",
    "config/gpu_control_list_testing_autogen.h",
    "config/gpu_control_list_testing_data.h",
    "config/gpu_control_list_testing_entry_enums_autogen.h",
    "config/gpu_control_list_testing_exceptions_autogen.h",
    "config/gpu_control_list_unittest.cc",
    "config/gpu_control_list_version_unittest.cc",
    "config/gpu_driver_bug_list_unittest.cc",
    "config/gpu_info_collector_unittest.cc",
    "config/gpu_info_unittest.cc",
    "config/gpu_preferences_unittest.cc",
    "config/gpu_test_config_unittest.cc",
    "config/gpu_test_expectations_parser_unittest.cc",
    "config/gpu_util_unittest.cc",
    "ipc/client/command_buffer_proxy_impl_unittest.cc",
    "ipc/client/image_decode_accelerator_proxy_unittest.cc",
    "ipc/common/gpu_memory_buffer_impl_shared_memory_unittest.cc",
    "ipc/common/gpu_memory_buffer_impl_test_template.h",
    "ipc/common/mojom_traits_unittest.cc",
    "ipc/host/gpu_disk_cache_unittest.cc",
    "ipc/service/gpu_channel_test_common.cc",
    "ipc/service/gpu_channel_test_common.h",
    "ipc/service/gpu_watchdog_thread_unittest.cc",
  ]

  if (enable_validating_command_decoder) {
    sources += [
      "command_buffer/service/gles2_cmd_decoder_unittest.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest.h",
      "command_buffer/service/gles2_cmd_decoder_unittest_1.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h",
      "command_buffer/service/gles2_cmd_decoder_unittest_2.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest_2_autogen.h",
      "command_buffer/service/gles2_cmd_decoder_unittest_3.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest_3_autogen.h",
      "command_buffer/service/gles2_cmd_decoder_unittest_4.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest_4_autogen.h",
      "command_buffer/service/gles2_cmd_decoder_unittest_attribs.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest_buffers.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest_context_lost.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest_context_state.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest_drawing.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest_extensions.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest_framebuffers.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest_programs.cc",
      "command_buffer/service/gles2_cmd_decoder_unittest_textures.cc",
    ]
  }

  if (is_chromeos_ash) {
    # Image decode acceleration with hardware is only supported in Chrome OS.
    # The intention is to run this test in the linux-chromeos build.
    sources += [ "ipc/service/image_decode_accelerator_stub_unittest.cc" ]
  }

  if (is_apple) {
    sources += [
      "ipc/common/gpu_memory_buffer_impl_io_surface_unittest.cc",
      "ipc/service/gpu_memory_buffer_factory_io_surface_unittest.cc",
    ]
  }

  if (is_linux || is_chromeos || use_ozone) {
    sources += [
      "ipc/common/gpu_memory_buffer_impl_native_pixmap_unittest.cc",
      "ipc/service/gpu_memory_buffer_factory_native_pixmap_unittest.cc",
    ]
  }

  if (is_win) {
    sources += [
      "ipc/common/gpu_memory_buffer_impl_dxgi_unittest.cc",
      "ipc/service/gpu_memory_buffer_factory_dxgi_unittest.cc",
    ]
  }

  if (is_linux || is_chromeos || is_android) {
    sources += [ "command_buffer/service/gpu_fence_manager_unittest.cc" ]
  }

  if (is_mac) {
    sources += [ "ipc/service/built_in_shader_cache_unittest.cc" ]
  }

  # On official builds angle doesn't build null backend that is required for
  # unit tests. We don't check directly for angle_enable_null to avoid
  # accidental skipping all the tests if angle logic to build null backend will
  # change.
  if (!is_official_build) {
    assert(angle_enable_null)
    sources += [
      "command_buffer/service/gles2_cmd_decoder_passthrough_unittest_buffers.cc",
      "command_buffer/service/gles2_cmd_decoder_passthrough_unittest_commands.cc",
      "command_buffer/service/gles2_cmd_decoder_passthrough_unittest_discardable_textures.cc",
      "command_buffer/service/gles2_cmd_decoder_passthrough_unittest_drawing.cc",
      "command_buffer/service/gles2_cmd_decoder_passthrough_unittest_framebuffers.cc",
      "command_buffer/service/gles2_cmd_decoder_passthrough_unittest_textures.cc",
      "ipc/service/gpu_channel_unittest.cc",
    ]

    if (!is_ios) {
      # This test depends on the test trace processor which is not currently
      # a dependency on iOS. See //base/test:test_support.
      sources += [ "ipc/service/gpu_channel_manager_unittest.cc" ]
    }
  }

  if (use_dawn) {
    sources += [
      "command_buffer/service/dawn_caching_interface_unittest.cc",
      "config/webgpu_blocklist_unittest.cc",
    ]
  }

  configs += [ "//build/config:precompiled_headers" ]

  deps = [
    ":gles2",
    ":gpu",
    ":test_support",
    "//base",
    "//base/test:test_support",
    "//build:chromeos_buildflags",
    "//cc:test_support",
    "//cc/paint",
    "//components/viz/common:shared_image_format",
    "//components/viz/test:test_support",
    "//gpu/command_buffer/client:gles2_c_lib",
    "//gpu/command_buffer/client:gles2_implementation",
    "//gpu/command_buffer/client:raster",
    "//gpu/command_buffer/client:webgpu",
    "//gpu/command_buffer/common",
    "//gpu/command_buffer/common:gles2_utils",
    "//gpu/command_buffer/service",
    "//gpu/config",
    "//gpu/ipc:gl_in_process_context",
    "//gpu/ipc/client",
    "//gpu/ipc/common",
    "//gpu/ipc/common:test_interfaces",
    "//gpu/ipc/common:test_support",
    "//gpu/ipc/host",
    "//gpu/ipc/service",
    "//mojo/core/embedder",
    "//mojo/public/cpp/bindings",
    "//mojo/public/cpp/test_support:test_utils",
    "//net:test_support",
    "//skia",
    "//testing/gmock",
    "//testing/gtest",
    "//third_party/angle:includes",
    "//third_party/re2",
    "//ui/gfx",
    "//ui/gfx:test_support",
    "//ui/gfx/geometry",
    "//ui/gl",
    "//ui/gl:gl_unittest_utils",
    "//ui/gl:test_support",
    "//url",
  ]

  if (use_static_angle) {
    deps += [ "//third_party/angle:translator" ]
  } else {
    deps += [ "//third_party/angle:translator_gl_d3d_only" ]
  }

  if (is_android) {
    deps += [
      "//ui/android:ui_java",
      "//ui/gl:gl_jni_headers",
    ]
  }

  if (use_dawn) {
    deps += [
      "//gpu/config:webgpu_blocklist_impl",
      "//net:test_support",
      "//third_party/dawn/src/dawn:cpp",
      "//third_party/dawn/src/dawn:proc",
      "//third_party/dawn/src/dawn/native",
    ]
  }

  if (use_ozone) {
    deps += [ "//ui/ozone" ]
  }

  if (is_ios) {
    bundle_deps =
        [ "//testing/buildbot/filters:gpu_unittests_filters_bundle_data" ]
  }
}

test("gpu_perftests") {
  sources = [
    "perftests/measurements.cc",
    "perftests/measurements.h",
    "perftests/run_all_tests.cc",
    "perftests/texture_upload_perftest.cc",
  ]

  deps = [
    ":gpu",
    "//base",
    "//base/test:test_support",
    "//gpu/command_buffer/client:gles2_implementation",
    "//testing/gmock",
    "//testing/gtest",
    "//testing/perf",
    "//ui/gfx/geometry",
    "//ui/gl",
    "//ui/gl/init",
  ]

  if (use_ozone) {
    deps += [
      "//ui/base:features",
      "//ui/ozone",
    ]
  }

  data_deps = [
    # Needed for isolate script to execute.
    "//testing:run_perf_test",
    "//third_party/angle:includes",
  ]

  # This target should not require the Chrome executable to run.
  assert_no_deps = [ "//chrome" ]
}

test("command_buffer_perftests") {
  sources = [
    "command_buffer/tests/decoder_perftest.cc",
    "perftests/run_all_tests.cc",
  ]

  deps = [
    ":gpu",
    "//base",
    "//base/test:test_support",
    "//gpu/command_buffer/client:gles2_cmd_helper",
    "//gpu/command_buffer/client:gles2_implementation",
    "//gpu/command_buffer/service:gles2",
    "//testing/gtest",
    "//testing/perf",
    "//ui/gfx/geometry",
    "//ui/gl",
    "//ui/gl/init",
  ]

  if (use_ozone) {
    deps += [
      "//ui/base:features",
      "//ui/ozone",
    ]
  }

  data_deps = [
    # Needed for isolate script to execute.
    "//testing:run_perf_test",
  ]

  # This target should not require the Chrome executable to run.
  assert_no_deps = [ "//chrome" ]
}

# We allow validating command decoder fuzzer on linux for better coverage.
if (enable_validating_command_decoder || is_linux) {
  fuzzer_test("gpu_fuzzer") {
    sources = [ "command_buffer/tests/fuzzer_main.cc" ]

    deps = [
      ":gles2",
      ":gpu",
      "//base",
      "//base:i18n",
      "//ui/gfx/geometry",
      "//ui/gl",
      "//ui/gl:test_support",
    ]

    libfuzzer_options = [ "max_len=16384" ]

    if (use_ozone) {
      deps += [ "//ui/ozone" ]
    }
  }
}

fuzzer_test("gpu_angle_passthrough_fuzzer") {
  sources = [ "command_buffer/tests/fuzzer_main.cc" ]

  defines = [
    "GPU_FUZZER_USE_ANGLE",
    "GPU_FUZZER_USE_PASSTHROUGH_CMD_DECODER",
  ]

  deps = [
    ":gles2",
    ":gpu",
    "//base",
    "//ui/gfx/geometry",
    "//ui/gl",
    "//ui/gl:test_support",
  ]

  if (use_ozone) {
    deps += [ "//ui/ozone" ]
  }

  libfuzzer_options = [ "max_len=16384" ]
}

fuzzer_test("gpu_swangle_passthrough_fuzzer") {
  sources = [ "command_buffer/tests/fuzzer_main.cc" ]

  defines = [
    "GPU_FUZZER_USE_ANGLE",
    "GPU_FUZZER_USE_SWANGLE",
    "GPU_FUZZER_USE_PASSTHROUGH_CMD_DECODER",
  ]

  deps = [
    ":gles2",
    ":gpu",
    "//base",
    "//ui/gfx/geometry",
    "//ui/gl",
    "//ui/gl:test_support",
  ]

  if (use_ozone) {
    deps += [ "//ui/ozone" ]
  }

  libfuzzer_options = [ "max_len=16384" ]
}

if (is_linux || is_chromeos) {
  fuzzer_test("gpu_raster_fuzzer") {
    sources = [ "command_buffer/tests/fuzzer_main.cc" ]

    defines = [ "GPU_FUZZER_USE_RASTER_DECODER" ]

    deps = [
      ":gles2",
      ":gpu",
      "//base",
      "//ui/gfx/geometry",
      "//ui/gl",
      "//ui/gl:test_support",
    ]

    if (use_ozone) {
      deps += [ "//ui/ozone" ]
    }

    libfuzzer_options = [ "max_len=16384" ]
  }

  fuzzer_test("gpu_raster_passthrough_fuzzer") {
    sources = [ "command_buffer/tests/fuzzer_main.cc" ]

    defines = [
      "GPU_FUZZER_USE_ANGLE",
      "GPU_FUZZER_USE_RASTER_DECODER",
      "GPU_FUZZER_USE_PASSTHROUGH_CMD_DECODER",
    ]

    deps = [
      ":gles2",
      ":gpu",
      "//base",
      "//ui/gfx/geometry",
      "//ui/gl",
      "//ui/gl:test_support",
    ]

    if (use_ozone) {
      deps += [ "//ui/ozone" ]
    }

    libfuzzer_options = [ "max_len=16384" ]
  }

  fuzzer_test("gpu_raster_swangle_passthrough_fuzzer") {
    sources = [ "command_buffer/tests/fuzzer_main.cc" ]

    defines = [
      "GPU_FUZZER_USE_ANGLE",
      "GPU_FUZZER_USE_SWANGLE",
      "GPU_FUZZER_USE_PASSTHROUGH_CMD_DECODER",
      "GPU_FUZZER_USE_RASTER_DECODER",
    ]

    deps = [
      ":gles2",
      ":gpu",
      "//base",
      "//ui/gfx/geometry",
      "//ui/gl",
      "//ui/gl:test_support",
    ]

    if (use_ozone) {
      deps += [ "//ui/ozone" ]
    }

    libfuzzer_options = [ "max_len=16384" ]
  }
}

# Microbenchmark to measure performance of GLHelper code, for use in
# debugging, profiling, and optimizing.
test("gpu_benchmark") {
  sources = [ "command_buffer/tests/gl_helper_benchmark.cc" ]

  configs += [ "//build/config:precompiled_headers" ]

  if (!is_debug && (is_win || is_android)) {
    configs -= [ "//build/config/compiler:default_optimization" ]
    configs += [ "//build/config/compiler:optimize_max" ]
  }

  deps = [
    "//base",
    "//base/test:test_support",
    "//components/test:run_all_unittests",
    "//components/viz/common",
    "//components/viz/test:test_support",
    "//gpu/command_buffer/client",
    "//gpu/command_buffer/client:gles2_implementation",
    "//gpu/ipc:gl_in_process_context",
    "//gpu/ipc:gpu_thread_holder",
    "//skia",
    "//testing/gmock",
    "//testing/gtest",
    "//third_party/angle:includes",
    "//ui/gfx",
  ]
}