# 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("//flutter/impeller/tools/impeller.gni")

if (impeller_enable_compute) {
  impeller_shaders("compute_shaders") {
    name = "compute"
    enable_opengles = false

    if (impeller_enable_vulkan) {
      vulkan_language_version = 130
    }

    if (is_ios) {
      metal_version = "2.4"
    } else if (is_mac) {
      metal_version = "2.1"
    }

    shaders = [
      "stroke.comp",
      "path_polyline.comp",
      "prefix_sum_test.comp",
      "threadgroup_sizing_test.comp",
    ]
  }

  impeller_component("compute_tessellation_unittests") {
    testonly = true
    sources = [ "compute_subgroup_unittests.cc" ]

    deps = [
      ":compute_shaders",
      ":renderer",
      "../display_list:skia_conversions",
      "../entity",
      "../fixtures",
      "../playground:playground_test",
      "//flutter/testing:testing_lib",
    ]
  }
}

impeller_component("renderer") {
  sources = [
    "blit_command.cc",
    "blit_command.h",
    "blit_pass.cc",
    "blit_pass.h",
    "capabilities.cc",
    "capabilities.h",
    "command.cc",
    "command.h",
    "command_buffer.cc",
    "command_buffer.h",
    "compute_command.cc",
    "compute_command.h",
    "compute_pass.cc",
    "compute_pass.h",
    "compute_pipeline_builder.cc",
    "compute_pipeline_builder.h",
    "compute_pipeline_descriptor.cc",
    "compute_pipeline_descriptor.h",
    "context.cc",
    "context.h",
    "pipeline.cc",
    "pipeline.h",
    "pipeline_builder.cc",
    "pipeline_builder.h",
    "pipeline_descriptor.cc",
    "pipeline_descriptor.h",
    "pipeline_library.cc",
    "pipeline_library.h",
    "pool.h",
    "render_pass.cc",
    "render_pass.h",
    "render_target.cc",
    "render_target.h",
    "renderer.cc",
    "renderer.h",
    "sampler_library.cc",
    "sampler_library.h",
    "shader_function.cc",
    "shader_function.h",
    "shader_key.cc",
    "shader_key.h",
    "shader_library.cc",
    "shader_library.h",
    "snapshot.cc",
    "snapshot.h",
    "surface.cc",
    "surface.h",
    "vertex_buffer_builder.cc",
    "vertex_buffer_builder.h",
    "vertex_descriptor.cc",
    "vertex_descriptor.h",
  ]

  public_deps = [
    "../base",
    "../core",
    "../geometry",
    "../image",
    "../runtime_stage",
    "../tessellator",
  ]

  if (impeller_enable_compute) {
    sources += [
      "compute_tessellator.cc",
      "compute_tessellator.h",
    ]
    public_deps += [ ":compute_shaders" ]
  }

  deps = [ "//flutter/fml" ]
}

impeller_component("renderer_unittests") {
  testonly = true

  sources = [
    "capabilities_unittests.cc",
    "device_buffer_unittests.cc",
    "host_buffer_unittests.cc",
    "pipeline_descriptor_unittests.cc",
    "pool_unittests.cc",
    "renderer_unittests.cc",
  ]

  deps = [
    ":renderer",
    "../fixtures",
    "../playground:playground_test",
    "//flutter/testing:testing_lib",
  ]

  if (impeller_enable_compute) {
    sources += [ "compute_unittests.cc" ]
  }
}

test_fixtures("renderer_dart_fixtures") {
  dart_main = "../fixtures/dart_tests.dart"

  fixtures = [
    "../fixtures/bay_bridge.jpg",
    "../fixtures/boston.jpg",
  ]
}

impeller_component("renderer_dart_unittests") {
  testonly = true

  sources = [ "renderer_dart_unittests.cc" ]

  deps = [
    ":renderer",
    ":renderer_dart_fixtures",
    "../fixtures:shader_fixtures",
    "../playground:playground_test",
    "//flutter/lib/gpu",
    "//flutter/runtime:runtime",
    "//flutter/testing:fixture_test",
    "//flutter/testing:testing",
  ]
}
