# Copyright (c) 2023 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/arkui/ace_engine/ace_config.gni")
import("//foundation/graphic/graphic_2d/graphic_config.gni")
import(
    "//foundation/graphic/graphic_2d/rosen/modules/render_service_base/config.gni")

config("composer_public_config") {
  include_dirs = [
    "//foundation/graphic/graphic_2d/rosen/include/common",
    "//drivers/peripheral/display/interfaces/include",
    "//foundation/graphic/graphic_2d/interfaces/inner_api/common",
    "//foundation/graphic/graphic_2d/rosen/modules/composer/hdi_backend/include",
    "//foundation/graphic/graphic_2d/rosen/modules/composer/vsync/include",
    "//foundation/graphic/graphic_2d/rosen/modules/render_service_base/src/platform/darwin",
    "//foundation/graphic/graphic_2d/interfaces/inner_api/composer",
    "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/src",
    "//foundation/appframework/graphic_2d/ios",
    "//foundation/graphic/graphic_surface/interfaces/inner_api/utils",
    "//foundation/graphic/graphic_surface/interfaces/inner_api/surface",
  ]
}

ohos_source_set("ios") {
  defines = rs_common_define

  sources = [
    "$rosen_root/modules/render_service_base/src/platform/ohos/rs_log.cpp",
    "render_context.mm",
    "rs_accessibility.cpp",
    "rs_ashmem_helper.cpp",
    "rs_frame_report.cpp",
    "rs_marshalling_helper.cpp",
    "rs_render_pipeline_client.cpp",
    "rs_render_service_client.mm",
    "rs_surface_frame_ios.cpp",
    "rs_surface_platform_texture_ios.mm",
    "rs_surface_texture_ios.mm",
    "rs_system_properties.cpp",
    "rs_vsync_client_ios.mm",
  ]

  include_dirs = [
    "//foundation/appframework/utils",
    "//foundation/graphic/graphic_2d/utils/log",
    "$rosen_root/modules/render_service_base/include",
    "$graphic_2d_root/rosen/modules/2d_graphics/src",
    "$graphic_2d_root/interfaces/inner_api/surface/",
    "$rosen_root/modules/2d_graphics/include",
    "$graphic_2d_root/utils/log",
    "$rosen_root/modules/2d_graphics/src/drawing/engine_adapter",
    "$rosen_root/modules/frame_report/include",
    "//foundation/graphic/graphic_surface/interfaces/inner_api",
    "//foundation/graphic/graphic_surface/interfaces/inner_api/surface",
    "//foundation/graphic/graphic_2d/rosen/modules/render_service_client/core",
  ]

  defines += [
    "MODULE_RSB",
    "ACE_ENABLE_GL",
    "RS_ENABLE_GL",
    "USE_SURFACE_TEXTURE",
  ]
  if (rs_enable_gpu) {
    defines += [ "USE_GPU" ]
    sources += [ "rs_surface_gpu.mm" ]
  }

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

  configs = [ "$rosen_root/modules/platform:eventhandler_config" ]

  public_configs = [ ":composer_public_config" ]

  deps = [
    "$rosen_root/modules/platform:hilog",
    "$rosen_root/modules/platform:image_native",
  ]
  frameworks = [
    "CoreMedia.framework",
    "CoreVideo.framework",
    "UIKit.framework",
    "OpenGLES.framework",
    "AudioToolbox.framework",
    "QuartzCore.framework",
  ]

  public_deps = [
    "$rosen_root/modules/platform:ace_skia",
    "$rosen_root/modules/platform:eventhandler",
    "$rosen_root/modules/platform:ipc_core",
    "$rosen_root/modules/platform:utils",
  ]

  if (defined(use_rosen_drawing) && use_rosen_drawing) {
    defines += [ "USE_ROSEN_DRAWING" ]
    public_deps += [ "$rosen_root/modules/2d_graphics:2d_graphics" ]
  }
  if (graphic_2d_feature_enable_vulkan) {
    defines += [ "RS_ENABLE_VK" ]
    include_dirs += [
      "//third_party/MoltenVK/MoltenVK/include/MoltenVK",
      "//foundation/appframework/graphic_2d/ios/vulkan",
    ]
    deps += [ "//third_party/MoltenVK:moltenvk_deps" ]
    sources += [
      "rs_vulkan_context.cpp",
      "vulkan/render_context_vk.mm",
      "vulkan/rs_surface_frame_ios_vulkan.cpp",
      "vulkan/rs_surface_swap_chain.mm",
      "vulkan/rs_surface_ios_vulkan.mm",
    ]
    frameworks += [
      "Metal.framework",
      "Foundation.framework",
      "IOSurface.framework",
    ]
  }
}