-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake_command_buffer_helper.cc
139 lines (118 loc) · 4.38 KB
/
fake_command_buffer_helper.cc
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright 2018 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 "media/gpu/fake_command_buffer_helper.h"
#include "base/logging.h"
namespace media {
FakeCommandBufferHelper::FakeCommandBufferHelper(
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: task_runner_(std::move(task_runner)) {
DVLOG(1) << __func__;
}
FakeCommandBufferHelper::~FakeCommandBufferHelper() {
DVLOG(1) << __func__;
}
void FakeCommandBufferHelper::StubLost() {
DVLOG(1) << __func__;
DCHECK(task_runner_->BelongsToCurrentThread());
// Keep a reference to |this| in case the destruction cb drops the last one.
scoped_refptr<CommandBufferHelper> thiz(this);
if (will_destroy_stub_cb_)
std::move(will_destroy_stub_cb_).Run(!is_context_lost_);
has_stub_ = false;
is_context_lost_ = true;
is_context_current_ = false;
waits_.clear();
}
void FakeCommandBufferHelper::ContextLost() {
DVLOG(1) << __func__;
DCHECK(task_runner_->BelongsToCurrentThread());
is_context_lost_ = true;
is_context_current_ = false;
}
void FakeCommandBufferHelper::CurrentContextLost() {
DVLOG(2) << __func__;
DCHECK(task_runner_->BelongsToCurrentThread());
is_context_current_ = false;
}
bool FakeCommandBufferHelper::HasTexture(GLuint service_id) {
DVLOG(4) << __func__ << "(" << service_id << ")";
DCHECK(task_runner_->BelongsToCurrentThread());
return service_ids_.count(service_id);
}
void FakeCommandBufferHelper::ReleaseSyncToken(gpu::SyncToken sync_token) {
DVLOG(3) << __func__;
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(waits_.count(sync_token));
task_runner_->PostTask(FROM_HERE, std::move(waits_[sync_token]));
waits_.erase(sync_token);
}
gl::GLContext* FakeCommandBufferHelper::GetGLContext() {
DVLOG(4) << __func__;
DCHECK(task_runner_->BelongsToCurrentThread());
return nullptr;
}
bool FakeCommandBufferHelper::MakeContextCurrent() {
DVLOG(3) << __func__;
DCHECK(task_runner_->BelongsToCurrentThread());
is_context_current_ = !is_context_lost_;
return is_context_current_;
}
bool FakeCommandBufferHelper::IsContextCurrent() const {
return is_context_current_;
}
GLuint FakeCommandBufferHelper::CreateTexture(GLenum target,
GLenum internal_format,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type) {
DVLOG(2) << __func__;
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(is_context_current_);
GLuint service_id = next_service_id_++;
service_ids_.insert(service_id);
return service_id;
}
void FakeCommandBufferHelper::DestroyTexture(GLuint service_id) {
DVLOG(2) << __func__ << "(" << service_id << ")";
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(is_context_current_);
DCHECK(service_ids_.count(service_id));
service_ids_.erase(service_id);
}
void FakeCommandBufferHelper::SetCleared(GLuint service_id) {
DVLOG(2) << __func__;
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(service_ids_.count(service_id));
}
bool FakeCommandBufferHelper::BindImage(GLuint service_id,
gl::GLImage* image,
bool client_managed) {
DVLOG(2) << __func__ << "(" << service_id << ")";
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(service_ids_.count(service_id));
return has_stub_;
}
gpu::Mailbox FakeCommandBufferHelper::CreateMailbox(GLuint service_id) {
DVLOG(2) << __func__ << "(" << service_id << ")";
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(service_ids_.count(service_id));
if (!has_stub_)
return gpu::Mailbox();
return gpu::Mailbox::Generate();
}
void FakeCommandBufferHelper::WaitForSyncToken(gpu::SyncToken sync_token,
base::OnceClosure done_cb) {
DVLOG(2) << __func__;
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(!waits_.count(sync_token));
if (has_stub_)
waits_.emplace(sync_token, std::move(done_cb));
}
void FakeCommandBufferHelper::SetWillDestroyStubCB(
WillDestroyStubCB will_destroy_stub_cb) {
DCHECK(!will_destroy_stub_cb_);
will_destroy_stub_cb_ = std::move(will_destroy_stub_cb);
}
} // namespace media