# Copyright 2013 The Flutter 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/fuchsia/sdk.gni")
import("//flutter/common/config.gni")
import("//flutter/impeller/tools/impeller.gni")
import("//flutter/testing/testing.gni")

config("display_list_config") {
  defines = []

  if (impeller_enable_3d) {
    defines += [ "IMPELLER_ENABLE_3D" ]
  }
}

source_set("display_list") {
  sources = [
    "benchmarking/dl_complexity.cc",
    "benchmarking/dl_complexity.h",
    "benchmarking/dl_complexity_gl.cc",
    "benchmarking/dl_complexity_gl.h",
    "benchmarking/dl_complexity_metal.cc",
    "benchmarking/dl_complexity_metal.h",
    "display_list.cc",
    "display_list.h",
    "dl_attributes.h",
    "dl_blend_mode.cc",
    "dl_blend_mode.h",
    "dl_builder.cc",
    "dl_builder.h",
    "dl_canvas.cc",
    "dl_canvas.h",
    "dl_color.h",
    "dl_op_flags.cc",
    "dl_op_flags.h",
    "dl_op_receiver.cc",
    "dl_op_receiver.h",
    "dl_op_records.cc",
    "dl_op_records.h",
    "dl_paint.cc",
    "dl_paint.h",
    "dl_sampling_options.h",
    "dl_tile_mode.h",
    "dl_vertices.cc",
    "dl_vertices.h",
    "effects/dl_color_filter.cc",
    "effects/dl_color_filter.h",
    "effects/dl_color_source.cc",
    "effects/dl_color_source.h",
    "effects/dl_image_filter.cc",
    "effects/dl_image_filter.h",
    "effects/dl_mask_filter.cc",
    "effects/dl_mask_filter.h",
    "effects/dl_path_effect.cc",
    "effects/dl_path_effect.h",
    "effects/dl_runtime_effect.cc",
    "effects/dl_runtime_effect.h",
    "geometry/dl_region.cc",
    "geometry/dl_region.h",
    "geometry/dl_rtree.cc",
    "geometry/dl_rtree.h",
    "image/dl_image.cc",
    "image/dl_image.h",
    "image/dl_image_skia.cc",
    "image/dl_image_skia.h",
    "skia/dl_sk_canvas.cc",
    "skia/dl_sk_canvas.h",
    "skia/dl_sk_conversions.cc",
    "skia/dl_sk_conversions.h",
    "skia/dl_sk_dispatcher.cc",
    "skia/dl_sk_dispatcher.h",
    "skia/dl_sk_paint_dispatcher.cc",
    "skia/dl_sk_paint_dispatcher.h",
    "skia/dl_sk_types.h",
    "utils/dl_bounds_accumulator.cc",
    "utils/dl_bounds_accumulator.h",
    "utils/dl_matrix_clip_tracker.cc",
    "utils/dl_matrix_clip_tracker.h",
    "utils/dl_receiver_utils.cc",
    "utils/dl_receiver_utils.h",
  ]

  public_configs = [ ":display_list_config" ]

  public_deps = [
    "//flutter/fml",
    "//flutter/impeller/runtime_stage",
    "//third_party/skia",
  ]

  if (!defined(defines)) {
    defines = []
  }
}

if (enable_unittests) {
  test_fixtures("display_list_fixtures") {
    fixtures = []
  }

  executable("display_list_unittests") {
    testonly = true

    sources = [
      "benchmarking/dl_complexity_unittests.cc",
      "display_list_unittests.cc",
      "dl_color_unittests.cc",
      "dl_paint_unittests.cc",
      "dl_vertices_unittests.cc",
      "effects/dl_color_filter_unittests.cc",
      "effects/dl_color_source_unittests.cc",
      "effects/dl_image_filter_unittests.cc",
      "effects/dl_mask_filter_unittests.cc",
      "effects/dl_path_effect_unittests.cc",
      "geometry/dl_region_unittests.cc",
      "geometry/dl_rtree_unittests.cc",
      "skia/dl_sk_conversions_unittests.cc",
      "skia/dl_sk_paint_dispatcher_unittests.cc",
      "utils/dl_matrix_clip_tracker_unittests.cc",
    ]

    deps = [
      ":display_list",
      ":display_list_fixtures",
      "//flutter/display_list/testing:display_list_testing",
      "//flutter/testing",
    ]

    if (!defined(defines)) {
      defines = []
    }
    if (is_win) {
      # Required for M_PI and others.
      defines += [ "_USE_MATH_DEFINES" ]
    }

    # This is needed for //third_party/googletest for linking zircon symbols.
    if (is_fuchsia) {
      libs =
          [ "${fuchsia_sdk_path}/arch/${target_cpu}/sysroot/lib/libzircon.so" ]
    }
  }

  executable("display_list_rendertests") {
    testonly = true

    sources = [ "testing/dl_rendering_unittests.cc" ]

    deps = [
      ":display_list",
      ":display_list_fixtures",
      "//flutter/common/graphics",
      "//flutter/display_list/testing:display_list_surface_provider",
      "//flutter/display_list/testing:display_list_testing",
      "//flutter/testing",
    ]

    if (!defined(defines)) {
      defines = []
    }
    if (is_win) {
      # Required for M_PI and others.
      defines += [ "_USE_MATH_DEFINES" ]
    }

    # This is needed for //third_party/googletest for linking zircon symbols.
    if (is_fuchsia) {
      libs =
          [ "${fuchsia_sdk_path}/arch/${target_cpu}/sysroot/lib/libzircon.so" ]
    }
  }

  executable("display_list_builder_benchmarks") {
    testonly = true

    sources = [ "benchmarking/dl_builder_benchmarks.cc" ]

    deps = [
      ":display_list",
      ":display_list_fixtures",
      "//flutter/benchmarking",
      "//flutter/display_list/testing:display_list_testing",
      "//flutter/testing:testing_lib",
    ]
  }

  executable("display_list_region_benchmarks") {
    testonly = true

    sources = [ "benchmarking/dl_region_benchmarks.cc" ]

    deps = [
      ":display_list_fixtures",
      "//flutter/benchmarking",
      "//flutter/testing:testing_lib",
    ]
  }
}

fixtures_location("display_list_benchmarks_fixtures") {
  assets_dir = "$target_gen_dir/"
}

source_set("display_list_benchmarks_source") {
  testonly = true

  sources = [
    "benchmarking/dl_benchmarks.cc",
    "benchmarking/dl_benchmarks.h",
  ]

  deps = [
    ":display_list",
    ":display_list_benchmarks_fixtures",
    "//flutter/benchmarking",
    "//flutter/common/graphics",
    "//flutter/display_list/testing:display_list_surface_provider",
    "//flutter/fml",
    "//flutter/testing:skia",
    "//flutter/testing:testing_lib",
    "//third_party/dart/runtime:libdart_jit",  # for tracing
    "//third_party/skia",
  ]
}

executable("display_list_benchmarks") {
  testonly = true

  deps = [ ":display_list_benchmarks_source" ]
}

if (is_ios) {
  shared_library("ios_display_list_benchmarks") {
    testonly = true
    visibility = [ ":*" ]

    configs -= [
      "//build/config/gcc:symbol_visibility_hidden",
      "//build/config:symbol_visibility_hidden",
    ]
    configs += [ "//flutter/benchmarking:benchmark_library_config" ]
    cflags = [
      "-fobjc-arc",
      "-mios-simulator-version-min=$ios_testing_deployment_target",
    ]
    ldflags =
        [ "-Wl,-install_name,@rpath/libios_display_list_benchmarks.dylib" ]
    deps = [
      ":display_list_benchmarks_source",
      "//flutter/benchmarking:benchmarking_library",
    ]
  }
}
