chromium/gpu/webgpu/callback.h

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_WEBGPU_CALLBACK_H_
#define GPU_WEBGPU_CALLBACK_H_

#include <memory>

#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/types/is_instantiation.h"

namespace gpu::webgpu {

// WGPUCallback<Callback> is a heap-allocated version of
// base::OnceCallback or base::RepeatingCallback.
// It is allocated on the heap so that it can be reinterpret_cast to/from
// void* and passed to WGPU C callbacks.
//
// Example:
//   WGPUOnceCallback<F>* callback =
//     BindWGPUOnceCallback(func, arg1);
//
//   // |someWGPUFunction| expects callback function with arguments:
//   //    Args... args, void* userdata.
//   // When it is called, it will forward to func(arg1, args...).
//   GetProcs().someWGPUFunction(
//     callback->UnboundCallback(), callback->AsUserdata());
template <typename Callback>
class WGPUCallbackBase;

template <typename Callback>
class WGPUOnceCallback;

template <typename Callback>
class WGPURepeatingCallback;

WGPUCallbackBase<BaseCallbackTemplate<R (Args...)>>;

WGPUOnceCallback<R (Args...)>;

WGPURepeatingCallback<R (Args...)>;

template <typename CallbackType>
  requires base::is_instantiation<base::OnceCallback, CallbackType>
auto MakeWGPUOnceCallback(CallbackType&& cb) {}

template <typename FunctionType, typename... BoundParameters>
  requires(!base::internal::kIsWeakMethod<
           base::internal::FunctorTraits<FunctionType,
                                         BoundParameters...>::is_method,
           BoundParameters...>)
auto BindWGPUOnceCallback(FunctionType&& function,
                          BoundParameters&&... bound_parameters) {}

template <typename CallbackType>
  requires base::is_instantiation<base::RepeatingCallback, CallbackType>
auto MakeWGPURepeatingCallback(CallbackType&& cb) {}

template <typename FunctionType, typename... BoundParameters>
auto BindWGPURepeatingCallback(FunctionType&& function,
                               BoundParameters&&... bound_parameters) {}

}  // namespace gpu::webgpu

#endif  // GPU_WEBGPU_CALLBACK_H_