From ff733b3f39098600fd5461dd71778e249cd7d78c Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Fri, 24 Sep 2021 16:46:36 -0400 Subject: [PATCH] Graphite: add MtlGpu. Bug: skia:12466 Change-Id: I51dc73a213e672578767b41c01c487c942465964 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/452722 Commit-Queue: Jim Van Verth Reviewed-by: Robert Phillips --- BUILD.gn | 12 +++++++++ experimental/graphite/src/mtl/MtlGpu.h | 36 +++++++++++++++++++++++++ experimental/graphite/src/mtl/MtlGpu.mm | 29 ++++++++++++++++++++ gn/graphite.gni | 5 ++++ 4 files changed, 82 insertions(+) create mode 100644 experimental/graphite/src/mtl/MtlGpu.h create mode 100644 experimental/graphite/src/mtl/MtlGpu.mm diff --git a/BUILD.gn b/BUILD.gn index 1c9765cb26..99a66dd9bb 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1026,10 +1026,22 @@ optional("ndk_images") { } optional("graphite") { + libs = [] + frameworks = [] + enabled = skia_enable_graphite public_defines = [ "SK_GRAPHITE_ENABLED" ] public = skia_graphite_public sources = skia_graphite_sources + if (skia_use_metal) { + public_defines += [ "SK_METAL" ] + sources += skia_graphite_mtl_sources + if (skia_enable_metal_debug_info) { + public_defines += [ "SK_ENABLE_MTL_DEBUG_INFO" ] + } + frameworks += [ "Metal.framework" ] + frameworks += [ "Foundation.framework" ] + } } optional("pdf") { diff --git a/experimental/graphite/src/mtl/MtlGpu.h b/experimental/graphite/src/mtl/MtlGpu.h new file mode 100644 index 0000000000..6ef99a5371 --- /dev/null +++ b/experimental/graphite/src/mtl/MtlGpu.h @@ -0,0 +1,36 @@ +/* + * Copyright 2021 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef skgpu_MtlGpu_DEFINED +#define skgpu_MtlGpu_DEFINED + +#include "experimental/graphite/src/Gpu.h" + +#include "include/gpu/mtl/GrMtlBackendContext.h" +#include "include/ports/SkCFObject.h" + +#import + +namespace skgpu::mtl { + +class Gpu final : public skgpu::Gpu { +public: + static sk_sp Make(const GrMtlBackendContext&); + ~Gpu() override; + + id device() const { return fDevice.get(); } + +private: + Gpu(sk_cfp>, sk_cfp>); + + sk_cfp> fDevice; + sk_cfp> fQueue; +}; + +} // namespace skgpu::mtl + +#endif // skgpu_MtlGpu_DEFINED diff --git a/experimental/graphite/src/mtl/MtlGpu.mm b/experimental/graphite/src/mtl/MtlGpu.mm new file mode 100644 index 0000000000..82f79dd775 --- /dev/null +++ b/experimental/graphite/src/mtl/MtlGpu.mm @@ -0,0 +1,29 @@ +/* + * Copyright 2021 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "experimental/graphite/src/mtl/MtlGpu.h" + +#include "experimental/graphite/src/Caps.h" + +namespace skgpu::mtl { + +sk_sp Gpu::Make(const GrMtlBackendContext& context) { + sk_cfp> device = sk_ret_cfp((id)(context.fDevice.get())); + sk_cfp> queue = sk_ret_cfp((id)(context.fQueue.get())); + + return sk_sp(new Gpu(std::move(device), std::move(queue))); +} + +Gpu::Gpu(sk_cfp> device, sk_cfp> queue) + : fDevice(std::move(device)) + , fQueue(std::move(queue)) { +} + +Gpu::~Gpu() { +} + +} // namespace skgpu::mtl diff --git a/gn/graphite.gni b/gn/graphite.gni index 55c0157210..a88c529552 100644 --- a/gn/graphite.gni +++ b/gn/graphite.gni @@ -37,3 +37,8 @@ skia_graphite_sources = [ "$_src/Task.cpp", "$_src/Task.h", ] + +skia_graphite_mtl_sources = [ + "$_src/mtl/MtlGpu.h", + "$_src/mtl/MtlGpu.mm", +]