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

import("//build/config/ui.gni")
import("//mojo/public/tools/bindings/mojom.gni")

group("common") {
  if (is_component_build) {
    public_deps = [
      "//gpu",
    ]
  } else {
    public_deps = [
      ":ipc_common_sources",
    ]
  }
}

group("command_buffer_traits") {
  if (is_component_build) {
    public_deps = [
      "//gpu",
    ]
  } else {
    public_deps = [
      ":command_buffer_traits_sources",
    ]
  }
}

group("gpu_preferences_util") {
  if (is_component_build) {
    public_deps = [
      "//gpu:gpu_util",
    ]
  } else {
    public_deps = [
      ":gpu_preferences_util_sources",
    ]
  }
}

source_set("command_buffer_traits_sources") {
  # External code should depend on this via
  # //gpu/ipc/common:command_buffer_traits above rather than depending on this
  # directly or the component build will break.
  visibility = [ "//gpu/*" ]

  sources = [
    "gpu_command_buffer_traits.cc",
    "gpu_command_buffer_traits.h",
    "gpu_command_buffer_traits_multi.h",
  ]

  configs += [
    "//gpu:gpu_implementation",
    "//third_party/khronos:khronos_headers",
  ]

  public_deps = [
    "//gpu/command_buffer/common:common_sources",
    "//ipc",
  ]

  deps = [
    "//base",
    "//gpu/command_buffer/common:gles2_utils",
    "//ui/gfx/ipc",
    "//ui/gfx/ipc/geometry",
  ]
}

source_set("ipc_common_sources") {
  # External code should depend on this via //gpu/ipc/common above rather than
  # depending on this directly or the component build will break.
  visibility = [ "//gpu/*" ]

  sources = [
    "flush_params.cc",
    "flush_params.h",
    "gpu_memory_buffer_support.cc",
    "gpu_memory_buffer_support.h",
    "gpu_message_generator.cc",
    "gpu_message_generator.h",
    "gpu_messages.h",
    "gpu_param_traits.cc",
    "gpu_param_traits.h",
    "gpu_param_traits_macros.h",
    "memory_stats.cc",
    "memory_stats.h",
  ]

  configs += [
    "//gpu:gpu_implementation",
    "//third_party/khronos:khronos_headers",
  ]

  public_deps = [
    ":command_buffer_traits_sources",
    ":surface_handle_type",
    "//gpu/command_buffer/common:gles2_utils",
    "//ipc",
  ]

  deps = [
    "//base",
    "//gpu/command_buffer/common:common_sources",
    "//gpu/config:config_sources",
    "//ui/base",
    "//ui/gfx/ipc",
    "//ui/gfx/ipc/geometry",
    "//ui/gl",
    "//url/ipc:url_ipc",
  ]

  if (is_android) {
    sources += [
      "android/scoped_surface_request_conduit.cc",
      "android/scoped_surface_request_conduit.h",
    ]
  }

  if (is_mac || is_android) {
    sources += [
      "gpu_surface_lookup.cc",
      "gpu_surface_lookup.h",
      "gpu_surface_tracker.cc",
      "gpu_surface_tracker.h",
    ]
  }

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

# Depend on this to use surface_handle.h without pulling in all of gpu ipc.
source_set("surface_handle_type") {
  public = [
    "surface_handle.h",
  ]

  public_deps = [
    "//ui/gfx:native_widget_types",
  ]
}

mojom("interfaces") {
  sources = [
    "capabilities.mojom",
    "dx_diag_node.mojom",
    "gpu_feature_info.mojom",
    "gpu_info.mojom",
    "gpu_preferences.mojom",
    "mailbox.mojom",
    "mailbox_holder.mojom",
    "memory_stats.mojom",
    "surface_handle.mojom",
    "sync_token.mojom",
  ]

  public_deps = [
    "//mojo/common:common_custom_types",
    "//ui/gfx/geometry/mojo",
  ]
}

mojom("test_interfaces") {
  testonly = true
  sources = [
    "traits_test_service.mojom",
  ]

  public_deps = [
    ":interfaces",
  ]
}

source_set("struct_traits") {
  sources = [
    "mailbox_holder_struct_traits.h",
    "mailbox_struct_traits.h",
    "memory_stats_struct_traits.h",
    "surface_handle_struct_traits.h",
    "sync_token_struct_traits.h",
  ]
  deps = [
    ":interfaces_shared_cpp_sources",
    ":surface_handle_type",
    "//gpu/command_buffer/common",
    "//gpu/ipc/common",
    "//mojo/public/cpp/bindings:bindings",
  ]
}

source_set("gpu_preferences_util_sources") {
  # External code should depend on this via //gpu/ipc/gpu_preferences_util
  # above rather than depending on this directly or the component build will
  # break.
  visibility = [ "//gpu/*" ]
  sources = [
    "gpu_preferences_util.cc",
    "gpu_preferences_util.h",
  ]
  configs += [ "//gpu:gpu_util_implementation" ]
  deps = [
    ":interfaces",
  ]
}