# Copyright (C) 2025 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/config/components/ets_frontend/ets2abc_config.gni")
import("//build/ohos.gni")
import("//foundation/graphic/graphic_2d/graphic_config.gni")

## Build effectKit_ani.so

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

config("graphic_ani_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",
  ]

  defines = [ "EGL_EGLEXT_PROTOTYPES" ]
}

ohos_shared_library("effectKit_ani") {
  shlib_type = "ani"
  branch_protector_ret = "pac_ret"

  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_vcall_icall_only = true
    debug = false
  }

  include_dirs = [
    "./include",
    "$graphic_2d_root/interfaces/kits/napi/graphic/effect_kit/include",
    "$graphic_2d_root/rosen/modules/effect/effectChain/include",
    "$graphic_2d_root/rosen/modules/effect/egl/include",
    "$graphic_2d_root/rosen/modules/effect/color_picker/include",
    "$graphic_2d_root/rosen/modules/effect/skia_effectChain/include",
    "$graphic_2d_root/utils/color_manager/export",
  ]

  public_configs = []

  configs = [ ":graphic_ani_effect_kit_config" ]

  sources = [
    "./src/ani_effect_kit_module.cpp",
    "./src/ani_filter.cpp",
    "./src/ani_color_picker.cpp",
    "./src/ani_effect_kit_utils.cpp",
    "$graphic_2d_root/interfaces/kits/napi/graphic/effect_kit/src/color_picker_napi.cpp",
    "$graphic_2d_root/interfaces/kits/napi/graphic/effect_kit/src/effect_kit_napi_utils.cpp",
    "$graphic_2d_root/interfaces/kits/napi/graphic/effect_kit/src/filter_napi.cpp",
  ]

  deps = [
    "$graphic_2d_root/frameworks/opengl_wrapper:EGL",
    "$graphic_2d_root/interfaces/kits/napi/graphic/effect_kit:effectkit",
    "$graphic_2d_root/rosen/modules/effect/color_picker:color_picker",
    "$graphic_2d_root/rosen/modules/effect/skia_effectChain:skeffectchain",
    "$graphic_2d_root/rosen/modules/2d_graphics:2d_graphics",
  ]

  external_deps = [
    "c_utils:utils",
    "graphic_surface:surface",
    "graphics_effect:graphics_effect_core",
    "hilog:libhilog",
    "image_framework:image",
    "image_framework:image_taihe",
    "napi:ace_napi",
    "runtime_core:ani",
    "runtime_core:ani_helpers",
    "runtime_core:libarkruntime",
  ]

  if (defined(arkgraphic2d_api_metrics) && arkgraphic2d_api_metrics) {
    external_deps += [ "api_metrics:histogrammanager" ]
    defines = [ "HISTOGRAM_MANAGEMENT_ENABLE=1" ]
  }

  part_name = "graphic_2d"
  subsystem_name = "graphic"
  output_extension = "so"
}

## Build effectKit_ani.so

generate_static_abc("effectKit") {
  base_url = "./ets"
  files = [ "./ets/@ohos.effectKit.ets" ]
  is_boot_abc = "True"
  device_dst_file = "/system/framework/effectKit.abc"
}

generate_static_abc("effectKit_entry") {
  base_url = "./ets"
  files = [ "./ets/effectKit_entry.ets" ]
  is_boot_abc = "True"
  device_dst_file = "/system/framework/effectKit_entry.abc"
}

ohos_prebuilt_etc("effectKit_etc") {
  source = "$target_out_dir/effectKit.abc"
  module_install_dir = "framework"
  part_name = "graphic_2d"
  subsystem_name = "graphic"
  deps = [ ":effectKit" ]
}