#include "gpu/ipc/service/command_buffer_stub.h"
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/hash/hash.h"
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/memory/unsafe_shared_memory_region.h"
#include "base/no_destructor.h"
#include "base/observer_list.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "base/values.h"
#include "build/build_config.h"
#include "gpu/command_buffer/common/constants.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "gpu/command_buffer/service/decoder_context.h"
#include "gpu/command_buffer/service/gpu_command_buffer_memory_tracker.h"
#include "gpu/command_buffer/service/logger.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/command_buffer/service/query_manager.h"
#include "gpu/command_buffer/service/scheduler.h"
#include "gpu/command_buffer/service/scheduler_task_runner.h"
#include "gpu/command_buffer/service/service_utils.h"
#include "gpu/command_buffer/service/sync_point_manager.h"
#include "gpu/config/gpu_crash_keys.h"
#include "gpu/ipc/service/gpu_channel.h"
#include "gpu/ipc/service/gpu_channel_manager.h"
#include "gpu/ipc/service/gpu_channel_manager_delegate.h"
#include "gpu/ipc/service/gpu_watchdog_thread.h"
#include "gpu/ipc/service/image_transport_surface.h"
#include "ipc/ipc_mojo_bootstrap.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_switches.h"
#include "ui/gl/init/gl_factory.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/win_util.h"
#endif
namespace gpu {
struct WaitForCommandState { … };
namespace {
const int64_t kHandleMoreWorkPeriodMs = …;
const int64_t kHandleMoreWorkPeriodBusyMs = …;
const int64_t kMaxTimeSinceIdleMs = …;
class DevToolsChannelData : public base::trace_event::ConvertableToTraceFormat { … };
std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
DevToolsChannelData::CreateForChannel(GpuChannel* channel) { … }
}
CommandBufferStub::CommandBufferStub(
GpuChannel* channel,
const mojom::CreateCommandBufferParams& init_params,
CommandBufferId command_buffer_id,
SequenceId sequence_id,
int32_t stream_id,
int32_t route_id)
: … { … }
CommandBufferStub::~CommandBufferStub() { … }
void CommandBufferStub::ExecuteDeferredRequest(
mojom::DeferredCommandBufferRequestParams& params) { … }
bool CommandBufferStub::IsScheduled() { … }
void CommandBufferStub::PollWork() { … }
void CommandBufferStub::PerformWork() { … }
bool CommandBufferStub::HasUnprocessedCommands() { … }
void CommandBufferStub::ScheduleDelayedWork(base::TimeDelta delay) { … }
bool CommandBufferStub::MakeCurrent() { … }
void CommandBufferStub::CreateCacheUse(
std::optional<gles2::ProgramCache::ScopedCacheUse>& cache_use) { … }
void CommandBufferStub::Destroy() { … }
void CommandBufferStub::SetGetBuffer(int32_t shm_id) { … }
CommandBufferServiceClient::CommandBatchProcessedResult
CommandBufferStub::OnCommandBatchProcessed() { … }
void CommandBufferStub::OnParseError() { … }
void CommandBufferStub::WaitForTokenInRange(int32_t start,
int32_t end,
WaitForStateCallback callback) { … }
void CommandBufferStub::WaitForGetOffsetInRange(uint32_t set_get_buffer_count,
int32_t start,
int32_t end,
WaitForStateCallback callback) { … }
void CommandBufferStub::CheckCompleteWaits() { … }
void CommandBufferStub::OnAsyncFlush(
int32_t put_offset,
uint32_t flush_id,
const std::vector<SyncToken>& sync_token_fences) { … }
void CommandBufferStub::RegisterTransferBuffer(
int32_t id,
base::UnsafeSharedMemoryRegion transfer_buffer) { … }
void CommandBufferStub::CreateGpuFenceFromHandle(uint32_t id,
gfx::GpuFenceHandle handle) { … }
void CommandBufferStub::GetGpuFenceHandle(uint32_t id,
GetGpuFenceHandleCallback callback) { … }
void CommandBufferStub::OnDestroyTransferBuffer(int32_t id) { … }
void CommandBufferStub::ReportState() { … }
void CommandBufferStub::SignalSyncToken(const SyncToken& sync_token,
uint32_t id) { … }
void CommandBufferStub::OnSignalAck(uint32_t id) { … }
void CommandBufferStub::SignalQuery(uint32_t query_id, uint32_t id) { … }
void CommandBufferStub::OnFenceSyncRelease(uint64_t release) { … }
void CommandBufferStub::OnDescheduleUntilFinished() { … }
void CommandBufferStub::OnRescheduleAfterFinished() { … }
void CommandBufferStub::ScheduleGrContextCleanup() { … }
void CommandBufferStub::HandleReturnData(base::span<const uint8_t> data) { … }
bool CommandBufferStub::ShouldYield() { … }
void CommandBufferStub::OnConsoleMessage(int32_t id,
const std::string& message) { … }
void CommandBufferStub::CacheBlob(gpu::GpuDiskCacheType type,
const std::string& key,
const std::string& shader) { … }
void CommandBufferStub::AddDestructionObserver(DestructionObserver* observer) { … }
void CommandBufferStub::RemoveDestructionObserver(
DestructionObserver* observer) { … }
std::unique_ptr<MemoryTracker> CommandBufferStub::CreateMemoryTracker() const { … }
void CommandBufferStub::SetMemoryTrackerFactoryForTesting(
MemoryTrackerFactory factory) { … }
void CommandBufferStub::BindEndpoints(
mojo::PendingAssociatedReceiver<mojom::CommandBuffer> receiver,
mojo::PendingAssociatedRemote<mojom::CommandBufferClient> client,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) { … }
MemoryTracker* CommandBufferStub::GetMemoryTracker() const { … }
scoped_refptr<Buffer> CommandBufferStub::GetTransferBuffer(int32_t id) { … }
void CommandBufferStub::RegisterTransferBufferForTest(
int32_t id,
scoped_refptr<Buffer> buffer) { … }
void CommandBufferStub::CheckContextLost() { … }
void CommandBufferStub::UpdateActiveUrl() { … }
void CommandBufferStub::MarkContextLost() { … }
CommandBufferStub::MemoryTrackerFactory
CommandBufferStub::GetMemoryTrackerFactory() { … }
CommandBufferStub::MemoryTrackerFactory
CommandBufferStub::SetOrGetMemoryTrackerFactory(MemoryTrackerFactory factory) { … }
CommandBufferStub::ScopedContextOperation::ScopedContextOperation(
CommandBufferStub& stub)
: … { … }
CommandBufferStub::ScopedContextOperation::~ScopedContextOperation() { … }
}