blob: 6546ed509a9ed1dc3354e213266b6fc24a4a5d21 [file] [log] [blame]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/gpu/browser_exposed_gpu_interfaces.h"
#include "base/memory/scoped_refptr.h"
#include "base/no_destructor.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/gpu/chrome_content_gpu_client.h"
#include "mojo/public/cpp/bindings/binder_map.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "components/arc/mojom/protected_buffer_manager.mojom.h"
#include "components/arc/mojom/video_decode_accelerator.mojom.h"
#include "components/arc/mojom/video_encode_accelerator.mojom.h"
#include "components/arc/mojom/video_protected_buffer_allocator.mojom.h"
#include "components/arc/video_accelerator/gpu_arc_video_decode_accelerator.h"
#include "components/arc/video_accelerator/gpu_arc_video_encode_accelerator.h"
#include "components/arc/video_accelerator/gpu_arc_video_protected_buffer_allocator.h"
#include "components/arc/video_accelerator/protected_buffer_manager.h"
#include "components/arc/video_accelerator/protected_buffer_manager_proxy.h"
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
namespace {
#if BUILDFLAG(IS_CHROMEOS_ASH)
void CreateArcVideoDecodeAccelerator(
ChromeContentGpuClient* client,
const gpu::GpuPreferences& gpu_preferences,
const gpu::GpuDriverBugWorkarounds& gpu_workarounds,
mojo::PendingReceiver<::arc::mojom::VideoDecodeAccelerator> receiver) {
mojo::MakeSelfOwnedReceiver(
std::make_unique<arc::GpuArcVideoDecodeAccelerator>(
gpu_preferences, gpu_workarounds,
client->GetProtectedBufferManager()),
std::move(receiver));
}
void CreateArcVideoEncodeAccelerator(
const gpu::GpuPreferences& gpu_preferences,
const gpu::GpuDriverBugWorkarounds& gpu_workarounds,
mojo::PendingReceiver<::arc::mojom::VideoEncodeAccelerator> receiver) {
mojo::MakeSelfOwnedReceiver(
std::make_unique<arc::GpuArcVideoEncodeAccelerator>(gpu_preferences,
gpu_workarounds),
std::move(receiver));
}
void CreateArcVideoProtectedBufferAllocator(
ChromeContentGpuClient* client,
mojo::PendingReceiver<::arc::mojom::VideoProtectedBufferAllocator>
receiver) {
auto gpu_arc_video_protected_buffer_allocator =
arc::GpuArcVideoProtectedBufferAllocator::Create(
client->GetProtectedBufferManager());
if (!gpu_arc_video_protected_buffer_allocator)
return;
mojo::MakeSelfOwnedReceiver(
std::move(gpu_arc_video_protected_buffer_allocator), std::move(receiver));
}
void CreateProtectedBufferManager(
ChromeContentGpuClient* client,
mojo::PendingReceiver<::arc::mojom::ProtectedBufferManager> receiver) {
mojo::MakeSelfOwnedReceiver(
std::make_unique<arc::GpuArcProtectedBufferManagerProxy>(
client->GetProtectedBufferManager()),
std::move(receiver));
}
#endif
} // namespace
void ExposeChromeGpuInterfacesToBrowser(
ChromeContentGpuClient* client,
const gpu::GpuPreferences& gpu_preferences,
const gpu::GpuDriverBugWorkarounds& gpu_workarounds,
mojo::BinderMap* binders) {
#if BUILDFLAG(IS_CHROMEOS_ASH)
binders->Add(base::BindRepeating(&CreateArcVideoDecodeAccelerator, client,
gpu_preferences, gpu_workarounds),
base::ThreadTaskRunnerHandle::Get());
binders->Add(base::BindRepeating(&CreateArcVideoEncodeAccelerator,
gpu_preferences, gpu_workarounds),
base::ThreadTaskRunnerHandle::Get());
binders->Add(
base::BindRepeating(&CreateArcVideoProtectedBufferAllocator, client),
base::ThreadTaskRunnerHandle::Get());
binders->Add(base::BindRepeating(&CreateProtectedBufferManager, client),
base::ThreadTaskRunnerHandle::Get());
#endif
}