# Copyright 2023 Google LLC
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("../../gn/skia.gni")
import("../../third_party/dawn/args.gni")

config("public_config") {
  defines = []
  include_dirs = [ "." ]
}

skia_component("window") {
  check_includes = false
  testonly = true  # For access to gpu_tool_utils. TODO: clean up
  public_configs = [ ":public_config" ]
  public = [
    "DisplayParams.h",
    "WindowContext.h",
  ]
  sources = [
    "DisplayParams.h",
    "RasterWindowContext.h",
    "WindowContext.cpp",
    "WindowContext.h",
  ]

  libs = []
  frameworks = []

  if (is_android) {
    sources += [
      "android/RasterWindowContext_android.cpp",
      "android/WindowContextFactory_android.h",
    ]
    libs += [ "android" ]
  } else if (is_linux) {
    sources += [
      "unix/RasterWindowContext_unix.cpp",
      "unix/RasterWindowContext_unix.h",
      "unix/XlibWindowInfo.h",
    ]
    libs += [ "X11" ]
  } else if (is_win) {
    sources += [
      "win/RasterWindowContext_win.cpp",
      "win/WindowContextFactory_win.h",
    ]
  } else if (is_mac) {
    sources += [ "mac/MacWindowInfo.h" ]
    frameworks += [
      "QuartzCore.framework",
      "Cocoa.framework",
      "Foundation.framework",
    ]
  } else if (is_ios) {
    sources += [ "ios/WindowContextFactory_ios.h" ]
    frameworks += [ "QuartzCore.framework" ]
  }

  if (skia_use_gl) {
    sources += [
      "GLWindowContext.cpp",
      "GLWindowContext.h",
    ]
    if (skia_use_angle) {
      sources += [ "ANGLEWindowContext.cpp" ]
    }
    if (is_android) {
      sources += [ "android/GLWindowContext_android.cpp" ]
    } else if (is_linux) {
      sources += [
        "unix/GaneshGLWindowContext_unix.cpp",
        "unix/GaneshGLWindowContext_unix.h",
      ]
      libs += [ "GL" ]
    } else if (is_win) {
      sources += [ "win/GLWindowContext_win.cpp" ]
      if (skia_use_angle) {
        sources += [ "win/ANGLEWindowContext_win.cpp" ]
      }
    } else if (is_mac) {
      sources += [
        # The Mac Raster implementation has a GL dependency
        "mac/GaneshGLWindowContext_mac.h",
        "mac/GaneshGLWindowContext_mac.mm",
        "mac/MacWindowGLUtils.h",
        "mac/RasterWindowContext_mac.h",
        "mac/RasterWindowContext_mac.mm",
      ]
      if (skia_use_angle) {
        sources += [
          "mac/GaneshANGLEWindowContext_mac.h",
          "mac/GaneshANGLEWindowContext_mac.mm",
          "mac/MacWindowGLUtils.h",
        ]
      }
    } else if (is_ios) {
      sources += [
        "ios/GLWindowContext_ios.mm",
        "ios/RasterWindowContext_ios.mm",
      ]
    }
  }

  if (skia_use_vulkan) {
    if (skia_enable_ganesh) {
      sources += [
        "VulkanWindowContext.cpp",
        "VulkanWindowContext.h",
      ]
    }
    if (skia_enable_graphite) {
      sources += [
        "GraphiteNativeVulkanWindowContext.cpp",
        "GraphiteNativeVulkanWindowContext.h",
      ]
    }
    if (is_android) {
      sources += [ "android/VulkanWindowContext_android.cpp" ]
      if (skia_enable_graphite) {
        sources += [ "android/GraphiteVulkanWindowContext_android.cpp" ]
      }
    } else if (is_linux) {
      sources += [
        "unix/GaneshVulkanWindowContext_unix.cpp",
        "unix/GaneshVulkanWindowContext_unix.h",
      ]
      if (skia_enable_graphite) {
        sources += [
          "unix/GraphiteNativeVulkanWindowContext_unix.cpp",
          "unix/GraphiteNativeVulkanWindowContext_unix.h",
        ]
      }
      libs += [ "X11-xcb" ]
    } else if (is_win) {
      sources += [ "win/VulkanWindowContext_win.cpp" ]
      if (skia_enable_graphite) {
        sources += [ "win/GraphiteVulkanWindowContext_win.cpp" ]
      }
    }
  }

  if (skia_use_metal) {
    if (skia_enable_ganesh) {
      sources += [
        "MetalWindowContext.h",
        "MetalWindowContext.mm",
      ]
    }
    if (skia_enable_graphite) {
      sources += [
        "GraphiteNativeMetalWindowContext.h",
        "GraphiteNativeMetalWindowContext.mm",
      ]
    }
    if (is_mac) {
      if (skia_enable_ganesh) {
        sources += [
          "mac/GaneshMetalWindowContext_mac.h",
          "mac/GaneshMetalWindowContext_mac.mm",
        ]
      }
      if (skia_enable_graphite) {
        sources += [
          "mac/GraphiteNativeMetalWindowContext_mac.h",
          "mac/GraphiteNativeMetalWindowContext_mac.mm",
        ]
      }
    } else if (is_ios) {
      if (skia_enable_ganesh) {
        sources += [ "ios/MetalWindowContext_ios.mm" ]
      }
      if (skia_enable_graphite) {
        sources += [ "ios/GraphiteMetalWindowContext_ios.mm" ]
      }
    }
  }

  if (skia_use_direct3d) {
    sources += [ "win/D3D12WindowContext_win.cpp" ]
  }

  if (skia_use_dawn) {
    if (skia_enable_graphite) {
      sources += [
        "GraphiteDawnWindowContext.cpp",
        "GraphiteDawnWindowContext.h",
      ]
    }
    if (is_linux) {
      if (skia_enable_graphite) {
        sources += [
          "unix/GraphiteDawnXlibWindowContext_unix.cpp",
          "unix/GraphiteDawnXlibWindowContext_unix.h",
        ]
      }
      if (dawn_enable_vulkan) {
        defines = [ "VK_USE_PLATFORM_XCB_KHR" ]
        libs += [ "X11-xcb" ]
      }
    } else if (is_win) {
      if (dawn_enable_d3d12 || dawn_enable_d3d11 || dawn_enable_vulkan) {
        if (skia_enable_graphite) {
          sources += [ "win/GraphiteDawnWindowContext_win.cpp" ]
        }
      }
    } else if (is_mac) {
      if (dawn_enable_metal) {
        if (skia_enable_graphite) {
          sources += [
            "mac/GraphiteDawnMetalWindowContext_mac.h",
            "mac/GraphiteDawnMetalWindowContext_mac.mm",
          ]
        }
      }
    } else if (is_android) {
      if (skia_enable_graphite) {
        sources += [ "android/GraphiteDawnWindowContext_android.cpp" ]
      }
    }
  }

  configs = [ "../../:skia_private" ]
  deps = [ "../..:skia" ]

  if (skia_enable_ganesh || skia_enable_graphite) {
    deps += [ "../..:gpu_tool_utils" ]
  }

  if (skia_use_gl && skia_use_angle) {
    deps += [ "//third_party/angle2" ]
  }
}
