#include "services/video_effects/video_effects_processor_webgpu.h"
#include <memory>
#include <numbers>
#include "base/bit_cast.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/sequence_checker.h"
#include "base/strings/stringprintf.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/client_shared_image.h"
#include "gpu/command_buffer/client/context_support.h"
#include "gpu/command_buffer/client/raster_interface.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/client/webgpu_interface.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/ipc/client/client_shared_image_interface.h"
#include "gpu/webgpu/callback.h"
#include "media/base/media_switches.h"
#include "media/base/video_types.h"
#include "services/video_effects/public/mojom/video_effects_processor.mojom-shared.h"
#include "services/video_effects/public/mojom/video_effects_processor.mojom.h"
#include "services/viz/public/cpp/gpu/context_provider_command_buffer.h"
#include "third_party/dawn/include/dawn/dawn_proc.h"
#include "third_party/dawn/include/dawn/dawn_proc_table.h"
#include "third_party/dawn/include/dawn/webgpu.h"
#include "third_party/dawn/include/dawn/webgpu_cpp.h"
#include "third_party/dawn/include/dawn/webgpu_cpp_print.h"
#include "third_party/dawn/include/dawn/wire/WireClient.h"
namespace {
scoped_refptr<gpu::ClientSharedImage> CreateSharedImageRGBA(
gpu::SharedImageInterface* sii,
const media::mojom::VideoFrameInfo& frame_info,
gpu::SharedImageUsageSet gpu_usage) { … }
}
namespace video_effects {
struct Uniforms { … };
VideoEffectsProcessorWebGpu::VideoEffectsProcessorWebGpu(
scoped_refptr<viz::ContextProviderCommandBuffer> context_provider,
scoped_refptr<viz::RasterContextProvider> raster_interface_context_provider,
scoped_refptr<gpu::ClientSharedImageInterface> shared_image_interface,
base::OnceClosure on_unrecoverable_error)
: … { … }
VideoEffectsProcessorWebGpu::~VideoEffectsProcessorWebGpu() = default;
bool VideoEffectsProcessorWebGpu::Initialize() { … }
void VideoEffectsProcessorWebGpu::PostProcess(
media::mojom::VideoBufferHandlePtr input_frame_data,
media::mojom::VideoFrameInfoPtr input_frame_info,
media::mojom::VideoBufferHandlePtr result_frame_data,
media::VideoPixelFormat result_pixel_format,
mojom::VideoEffectsProcessor::PostProcessCallback post_process_cb) { … }
void VideoEffectsProcessorWebGpu::QueryDone(
GLuint query_id,
uint64_t trace_id,
media::mojom::VideoBufferHandlePtr input_frame_data,
media::mojom::VideoFrameInfoPtr input_frame_info,
media::mojom::VideoBufferHandlePtr result_frame_data,
media::VideoPixelFormat result_pixel_format,
mojom::VideoEffectsProcessor::PostProcessCallback post_process_cb) { … }
void VideoEffectsProcessorWebGpu::OnRequestAdapter(
wgpu::RequestAdapterStatus status,
wgpu::Adapter adapter,
char const* message) { … }
void VideoEffectsProcessorWebGpu::OnRequestDevice(
wgpu::RequestDeviceStatus status,
wgpu::Device device,
char const* message) { … }
wgpu::ComputePipeline VideoEffectsProcessorWebGpu::CreateComputePipeline() { … }
void VideoEffectsProcessorWebGpu::OnDeviceLost(WGPUDeviceLostReason reason,
char const* message) { … }
void VideoEffectsProcessorWebGpu::EnsureFlush() { … }
void VideoEffectsProcessorWebGpu::MaybeCallOnUnrecoverableError() { … }
void VideoEffectsProcessorWebGpu::ErrorCallback(WGPUErrorType type,
char const* message,
void* userdata) { … }
void VideoEffectsProcessorWebGpu::LoggingCallback(WGPULoggingType type,
char const* message,
void* userdata) { … }
}