# Copyright 2017 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("//services/service_manager/public/cpp/service.gni")
import("//services/service_manager/public/service_manifest.gni")
import("//testing/test.gni")

source_set("lib") {
  sources = [
    "barcode_detection_impl.h",
    "face_detection_provider_impl.h",
    "shape_detection_service.cc",
    "shape_detection_service.h",
    "text_detection_impl.h",
  ]

  if (is_mac) {
    sources += [
      "barcode_detection_impl_mac.h",
      "barcode_detection_impl_mac.mm",
      "detection_utils_mac.h",
      "detection_utils_mac.mm",
      "face_detection_impl_mac.h",
      "face_detection_impl_mac.mm",
      "text_detection_impl_mac.h",
      "text_detection_impl_mac.mm",
    ]
    libs = [ "QuartzCore.framework" ]
  } else if (is_win) {
    sources -= [ "face_detection_provider_impl.h" ]
    sources += [
      "barcode_detection_impl.cc",
      "detection_utils_win.h",
      "face_detection_impl_win.cc",
      "face_detection_impl_win.h",
      "face_detection_provider_win.cc",
      "face_detection_provider_win.h",
      "text_detection_impl.cc",
    ]
  } else {
    sources += [
      "barcode_detection_impl.cc",
      "face_detection_provider_impl.cc",
      "text_detection_impl.cc",
    ]
  }

  deps = [
    "//mojo/public/cpp/bindings",
    "//ui/gfx",
    "//ui/gfx/geometry",
  ]

  public_deps = [
    "//base",
    "//media/capture",
    "//services/service_manager/public/cpp",
    "//services/shape_detection/public/interfaces",
  ]

  if (is_android) {
    deps += [ ":shape_detection_jni_headers" ]
  }
}

if (is_android) {
  generate_jni("shape_detection_jni_headers") {
    sources = [
      "android/java/src/org/chromium/shape_detection/InterfaceRegistrar.java",
    ]
    jni_package = "shape_detection"
  }

  android_library("shape_detection_java") {
    java_files = [
      "android/java/src/org/chromium/shape_detection/BarcodeDetectionImpl.java",
      "android/java/src/org/chromium/shape_detection/FaceDetectionImpl.java",
      "android/java/src/org/chromium/shape_detection/FaceDetectionImplGmsCore.java",
      "android/java/src/org/chromium/shape_detection/FaceDetectionProviderImpl.java",
      "android/java/src/org/chromium/shape_detection/InterfaceRegistrar.java",
      "android/java/src/org/chromium/shape_detection/BitmapUtils.java",
      "android/java/src/org/chromium/shape_detection/TextDetectionImpl.java",
    ]

    deps = [
      "$google_play_services_package:google_play_services_base_java",
      "$google_play_services_package:google_play_services_basement_java",
      "$google_play_services_package:google_play_services_vision_common_java",
      "$google_play_services_package:google_play_services_vision_java",
      "//base:base_java",
      "//mojo/android:system_java",
      "//mojo/public/java:bindings_java",
      "//mojo/public/java:system_java",
      "//services/service_manager/public/interfaces:interfaces_java",
      "//services/service_manager/public/java:service_manager_java",
      "//services/shape_detection/public/interfaces:interfaces_java",
      "//skia/public/interfaces:interfaces_java",
      "//ui/gfx/geometry/mojo:mojo_java",
    ]
  }
}

service_manifest("manifest") {
  name = "shape_detection"
  source = "manifest.json"
}

source_set("tests") {
  testonly = true
  sources = []
  if (is_mac) {
    sources += [
      "barcode_detection_impl_mac_unittest.mm",
      "face_detection_impl_mac_unittest.mm",
      "text_detection_impl_mac_unittest.mm",
    ]

    libs = [
      "CoreFoundation.framework",
      "CoreGraphics.framework",
      "QuartzCore.framework",
    ]
  } else if (is_win) {
    sources += [ "face_detection_impl_win_unittest.cc" ]
  }

  deps = [
    ":lib",
    "//base",
    "//base/test:test_support",
    "//skia",
    "//testing/gmock",
    "//testing/gtest",
    "//ui/gfx",
    "//ui/gl",
  ]
  data = [
    "//services/test/data/mona_lisa.jpg",
  ]
}