forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpu_task_scheduler_helper.h
114 lines (94 loc) · 4.6 KB
/
gpu_task_scheduler_helper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// 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.
#ifndef GPU_IPC_GPU_TASK_SCHEDULER_HELPER_H_
#define GPU_IPC_GPU_TASK_SCHEDULER_HELPER_H_
#include <vector>
#include "base/callback.h"
#include "base/memory/raw_ptr.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "gpu/command_buffer/service/sequence_id.h"
#include "gpu/ipc/gl_in_process_context_export.h"
namespace base {
class TimeTicks;
}
namespace viz {
class VizProcessContextProvider;
class DisplayCompositorMemoryAndTaskController;
}
namespace gpu {
class CommandBufferTaskExecutor;
class CommandBufferHelper;
class GLInProcessContext;
class SingleTaskSequence;
class InProcessCommandBuffer;
// This class is a wrapper around a |gpu::SingleTaskSequence|. When we have
// SkiaRenderer enabled, this should behave exactly like a
// |gpu::SingleTaskSequence|. When we have GLRenderer with CommandBuffer, we
// need to initialize this class with a |CommandBufferHelper|. This is because
// when this class is used outside of actual CommandBuffer, we would need to
// make sure the order of post tasks still corresponds to the order that tasks
// are posted to the CommandBuffer.
// This class is per display compositor. When this is used with command buffer,
// it is created on VizProcessContextProvider. When this is used with
// SkiaRenderer, it is created on SkiaOutputSurfaceImpl. Each user of this class
// would hold a reference.
class GL_IN_PROCESS_CONTEXT_EXPORT GpuTaskSchedulerHelper {
public:
// This constructor is only used for SkiaOutputSurface.
explicit GpuTaskSchedulerHelper(
std::unique_ptr<SingleTaskSequence> task_sequence);
// This constructor is used for command buffer GLOutputSurface.
explicit GpuTaskSchedulerHelper(
CommandBufferTaskExecutor* command_buffer_task_executor);
GpuTaskSchedulerHelper(const GpuTaskSchedulerHelper&) = delete;
GpuTaskSchedulerHelper& operator=(const GpuTaskSchedulerHelper&) = delete;
~GpuTaskSchedulerHelper();
// This function sets up the |command_buffer_helper| which flushes the command
// buffer when a user outside of the command buffer shares the same
// GpuTaskSchedulerHelper. This is only needed for sharing with the command
// buffer, thus no need to be called when using SkiaRenderer.
void Initialize(CommandBufferHelper* command_buffer_helper);
using ReportingCallback =
base::OnceCallback<void(base::TimeTicks task_ready)>;
// This is called outside of CommandBuffer and would need to flush the command
// buffer if the CommandBufferHelper is present. CommandBuffer is a friend of
// this class and gets a direct pointer to the internal
// |gpu::SingleTaskSequence|.
void ScheduleGpuTask(base::OnceClosure task,
std::vector<SyncToken> sync_tokens,
ReportingCallback report_callback = ReportingCallback());
// This is only called with SkiaOutputSurface, no need to flush command buffer
// here.
void ScheduleOrRetainGpuTask(base::OnceClosure task,
std::vector<SyncToken> sync_tokens);
// This is only called with SkiaOutputSurface.
SequenceId GetSequenceId();
private:
// If |using_command_buffer_| is true, we are using this class with
// GLOutputSurface. Otherwise we are using this class with
// SkiaOutputSurface.
bool using_command_buffer_;
friend class gpu::GLInProcessContext;
friend class gpu::InProcessCommandBuffer;
friend class viz::VizProcessContextProvider;
friend class viz::DisplayCompositorMemoryAndTaskController;
// Only used for inside CommandBuffer implementation.
SingleTaskSequence* GetTaskSequence() const;
// This |task_sequence_| handles task scheduling.
const std::unique_ptr<SingleTaskSequence> task_sequence_;
// When this class is used with the command buffer, this bool indicates
// whether we have initialized the |command_buffer_helper_|. The command
// buffer requires the |task_sequence_| in order to initialize on gpu thread,
// but the |command_buffer_helper_| is created after initialization of the
// command buffer.
bool initialized_;
// In the case where the TaskSequence is shared between command buffer and
// other users, |command_buffer_helper_| is used to flush the command buffer
// before posting tasks from a different user. This gives the command buffer a
// chance to post any pending tasks and maintains the ordering between command
// buffer and other user tasks.
raw_ptr<CommandBufferHelper> command_buffer_helper_ = nullptr;
};
} // namespace gpu
#endif // GPU_IPC_GPU_TASK_SCHEDULER_HELPER_H_