# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build/ohos.gni")
import("//foundation/graphic/graphic_2d/graphic_config.gni")

## Build effect_kit.so

declare_args() {
  arkgraphic2d_api_metrics = true
}
if (defined(global_parts_info) &&
    !defined(global_parts_info.hiviewdfx_api_metrics)) {
  arkgraphic2d_api_metrics = false
}

config("graphic_napi_effect_kit_config") {
  visibility = [ ":*" ]

  cflags = [
    "-Wall",
    "-Werror",
    "-g3",
    "-Wno-pointer-arith",
    "-Wno-non-virtual-dtor",
    "-Wno-missing-field-initializers",
    "-Wno-c++11-narrowing",
    "-Wno-unused-but-set-variable",
  ]

  if(is_arkui_x && target_os == "ios") {
    cflags += ["-Wno-ignored-qualifiers",]
  }

  defines = [ "EGL_EGLEXT_PROTOTYPES" ]

  include_dirs = [
    "./include",
    "//foundation/graphic/graphic_2d/rosen/modules/effect/color_picker/include",
    "//foundation/graphic/graphic_2d/rosen/modules/effect/skia_effectChain/include",
    "//foundation/graphic/graphic_2d/utils/color_manager/export",
  ]
}

if (is_arkui_x) {
  ohos_source_set("effectkit") {
    configs = [ ":graphic_napi_effect_kit_config" ]
    include_dirs = [
      "//third_party/json/single_include/nlohmann",
      "//foundation/multimedia/image_framework/interfaces/kits/js/common/include",
      "//foundation/multimedia/image_framework/interfaces/innerkits/include",
      "//foundation/graphic/graphic_surface/interfaces/inner_api/common",
      "//foundation/graphic/graphics_effect/include",
      "//foundation/graphic/graphics_effect/include/core",
      "//foundation/graphic/graphics_effect/include/pipeline",
      "//foundation/graphic/graphics_effect/include/hps",
      "//foundation/graphic/graphics_effect/include/ext",
      "//foundation/graphic/graphics_effect/include/effect",
      "//foundation/graphic/graphics_effect/include/effect/filter",
      "//foundation/graphic/graphics_effect/include/effect/shader",
      "//foundation/graphic/graphics_effect/include/effect/mask",
      "//foundation/graphic/graphics_effect/include/effect/shape",
      "//foundation/graphic/graphics_effect/include/util",
    ]

    defines = ["CROSS_PLATFORM"]
    if(target_os == "ios") {
      defines += ["ROSEN_IOS"]
    }

    sources = [
      "./src/color_picker_napi.cpp",
      "./src/effect_kit_napi_utils.cpp",
      "./src/filter_napi.cpp",
      "./src/native_module_ohos_effect.cpp",
    ]

    deps = [
      "//foundation/graphic/graphic_2d/frameworks/opengl_wrapper:EGL",
      "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
      "//foundation/graphic/graphic_2d/rosen/modules/effect/color_picker:color_picker",
      "//foundation/graphic/graphic_2d/rosen/modules/effect/skia_effectChain:skeffectchain",
    ]

    if (current_os == "ios") {
      deps += [ "//plugins/libs/napi:napi_${target_os}" ]
    }

    cflags_cc = [ "-std=c++17" ]
    part_name = "graphic_2d"
    subsystem_name = "graphic"
  }
} else {
  ohos_shared_library("effectkit") {
    include_dirs =
        [ "//foundation/graphic/graphic_2d/rosen/modules/effect/egl/include" ]

    configs = [ ":graphic_napi_effect_kit_config" ]

    sources = [
      "./src/color_picker_napi.cpp",
      "./src/effect_kit_napi_utils.cpp",
      "./src/filter_napi.cpp",
      "./src/native_module_ohos_effect.cpp",
    ]

    deps = [
      "//foundation/graphic/graphic_2d/frameworks/opengl_wrapper:EGL",
      "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
      "//foundation/graphic/graphic_2d/rosen/modules/effect/color_picker:color_picker",
      "//foundation/graphic/graphic_2d/rosen/modules/effect/skia_effectChain:skeffectchain",
    ]

    external_deps = [
      "c_utils:utils",
      "graphics_effect:graphics_effect_core",
      "hilog:libhilog",
      "image_framework:image",
      "image_framework:image_native",
      "napi:ace_napi",
      "graphic_surface:surface",
    ]
    
    if (defined(arkgraphic2d_api_metrics) && arkgraphic2d_api_metrics) {
      external_deps += [ "api_metrics:histogrammanager" ]
      defines = [ "HISTOGRAM_MANAGEMENT_ENABLE=1" ]
    }

    cflags_cc = [ "-std=c++17" ]

    relative_install_dir = "module"
    part_name = "graphic_2d"
    subsystem_name = "graphic"
  }
}
## Build effect_kit.so