Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Unified Diff: gpu/command_buffer/service/in_process_command_buffer.cc

Issue 1864723003: Make lost context and error message callbacks on GpuControl go to client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: errorcallback: .get Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/service/in_process_command_buffer.cc
diff --git a/gpu/command_buffer/service/in_process_command_buffer.cc b/gpu/command_buffer/service/in_process_command_buffer.cc
index 27824398429933e1a0d14ac2ef2034f4577776fd..e0093f2b5e02b4d48c3270565aa90999b9a54130 100644
--- a/gpu/command_buffer/service/in_process_command_buffer.cc
+++ b/gpu/command_buffer/service/in_process_command_buffer.cc
@@ -22,6 +22,7 @@
#include "base/sequence_checker.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
+#include "gpu/command_buffer/client/gpu_control_client.h"
#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
#include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
#include "gpu/command_buffer/common/sync_token.h"
@@ -210,6 +211,8 @@ InProcessCommandBuffer::InProcessCommandBuffer(
const scoped_refptr<Service>& service)
: command_buffer_id_(
CommandBufferId::FromUnsafeValue(g_next_command_buffer_id.GetNext())),
+ gpu_control_client_(nullptr),
+ context_lost_(false),
delayed_work_pending_(false),
image_factory_(nullptr),
last_put_offset_(-1),
@@ -219,6 +222,7 @@ InProcessCommandBuffer::InProcessCommandBuffer(
flush_event_(false, false),
service_(GetInitialService(service)),
fence_sync_wait_event_(false, false),
+ client_thread_weak_ptr_factory_(this),
gpu_thread_weak_ptr_factory_(this) {
DCHECK(service_.get());
next_image_id_.GetNext();
@@ -245,7 +249,7 @@ bool InProcessCommandBuffer::MakeCurrent() {
return true;
}
-void InProcessCommandBuffer::PumpCommands() {
+void InProcessCommandBuffer::PumpCommandsOnGpuThread() {
CheckSequencedThread();
command_buffer_lock_.AssertAcquired();
@@ -255,13 +259,6 @@ void InProcessCommandBuffer::PumpCommands() {
executor_->PutChanged();
}
-bool InProcessCommandBuffer::GetBufferChanged(int32_t transfer_buffer_id) {
- CheckSequencedThread();
- command_buffer_lock_.AssertAcquired();
- command_buffer_->SetGetBuffer(transfer_buffer_id);
- return true;
-}
-
bool InProcessCommandBuffer::Initialize(
scoped_refptr<gfx::GLSurface> surface,
bool is_offscreen,
@@ -269,18 +266,19 @@ bool InProcessCommandBuffer::Initialize(
const gfx::Size& size,
const std::vector<int32_t>& attribs,
gfx::GpuPreference gpu_preference,
- const base::Closure& context_lost_callback,
InProcessCommandBuffer* share_group,
GpuMemoryBufferManager* gpu_memory_buffer_manager,
ImageFactory* image_factory) {
DCHECK(!share_group || service_.get() == share_group->service_.get());
- context_lost_callback_ = WrapCallback(context_lost_callback);
- if (surface.get()) {
+ if (surface) {
// GPU thread must be the same as client thread due to GLSurface not being
// thread safe.
sequence_checker_.reset(new base::SequenceChecker);
surface_ = surface;
+ } else {
+ origin_task_runner_ = base::ThreadTaskRunnerHandle::Get();
+ client_thread_weak_ptr_ = client_thread_weak_ptr_factory_.GetWeakPtr();
}
gpu::Capabilities capabilities;
@@ -328,9 +326,9 @@ bool InProcessCommandBuffer::InitializeOnGpuThread(
scoped_ptr<CommandBufferService> command_buffer(
new CommandBufferService(transfer_buffer_manager_.get()));
command_buffer->SetPutOffsetChangeCallback(base::Bind(
- &InProcessCommandBuffer::PumpCommands, gpu_thread_weak_ptr_));
+ &InProcessCommandBuffer::PumpCommandsOnGpuThread, gpu_thread_weak_ptr_));
command_buffer->SetParseErrorCallback(base::Bind(
- &InProcessCommandBuffer::OnContextLost, gpu_thread_weak_ptr_));
+ &InProcessCommandBuffer::OnContextLostOnGpuThread, gpu_thread_weak_ptr_));
if (!command_buffer->Initialize()) {
LOG(ERROR) << "Could not initialize command buffer.";
@@ -455,7 +453,7 @@ bool InProcessCommandBuffer::InitializeOnGpuThread(
void InProcessCommandBuffer::Destroy() {
CheckSequencedThread();
-
+ client_thread_weak_ptr_factory_.InvalidateWeakPtrs();
piman 2016/04/11 21:54:26 nit: reset gpu_control_client_
danakj 2016/04/11 22:27:32 Done.
base::WaitableEvent completion(true, false);
bool result = false;
base::Callback<bool(void)> destroy_task = base::Bind(
@@ -475,14 +473,14 @@ bool InProcessCommandBuffer::DestroyOnGpuThread() {
decoder_->Destroy(have_context);
decoder_.reset();
}
- context_ = NULL;
- surface_ = NULL;
- sync_point_client_ = NULL;
+ context_ = nullptr;
+ surface_ = nullptr;
+ sync_point_client_ = nullptr;
if (sync_point_order_data_) {
sync_point_order_data_->Destroy();
sync_point_order_data_ = nullptr;
}
- gl_share_group_ = NULL;
+ gl_share_group_ = nullptr;
#if defined(OS_ANDROID)
stream_texture_manager_.reset();
#endif
@@ -495,12 +493,22 @@ void InProcessCommandBuffer::CheckSequencedThread() {
sequence_checker_->CalledOnValidSequencedThread());
}
+void InProcessCommandBuffer::OnContextLostOnGpuThread() {
+ if (context_lost_)
piman 2016/04/11 21:54:26 Data race here - context_lost_ is modified on the
danakj 2016/04/11 22:27:32 OK I made it a DCHECK in OnContextLost().
+ return;
+ if (!origin_task_runner_ || origin_task_runner_->BelongsToCurrentThread())
+ return OnContextLost();
+ origin_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&InProcessCommandBuffer::OnContextLost,
+ client_thread_weak_ptr_));
+}
+
void InProcessCommandBuffer::OnContextLost() {
CheckSequencedThread();
- if (!context_lost_callback_.is_null()) {
- context_lost_callback_.Run();
- context_lost_callback_.Reset();
- }
+ DCHECK(gpu_control_client_);
piman 2016/04/11 21:54:26 Does the client *have* to provide one? Also, GLES2
danakj 2016/04/11 22:27:32 Hm... okay. Done for CommandBufferProxyImpl and mo
+ if (!context_lost_)
+ gpu_control_client_->OnGpuControlLostContext();
+ context_lost_ = true;
}
CommandBuffer::State InProcessCommandBuffer::GetStateFast() {
@@ -554,7 +562,7 @@ void InProcessCommandBuffer::FlushOnGpuThread(int32_t put_offset,
}
}
-void InProcessCommandBuffer::PerformDelayedWork() {
+void InProcessCommandBuffer::PerformDelayedWorkOnGpuThread() {
CheckSequencedThread();
delayed_work_pending_ = false;
base::AutoLock lock(command_buffer_lock_);
@@ -572,8 +580,9 @@ void InProcessCommandBuffer::ScheduleDelayedWorkOnGpuThread() {
if (delayed_work_pending_)
return;
delayed_work_pending_ = true;
- service_->ScheduleDelayedWork(base::Bind(
- &InProcessCommandBuffer::PerformDelayedWork, gpu_thread_weak_ptr_));
+ service_->ScheduleDelayedWork(
+ base::Bind(&InProcessCommandBuffer::PerformDelayedWorkOnGpuThread,
+ gpu_thread_weak_ptr_));
}
void InProcessCommandBuffer::Flush(int32_t put_offset) {
@@ -670,6 +679,10 @@ void InProcessCommandBuffer::DestroyTransferBufferOnGpuThread(int32_t id) {
command_buffer_->DestroyTransferBuffer(id);
}
+void InProcessCommandBuffer::SetGpuControlClient(GpuControlClient* client) {
+ gpu_control_client_ = client;
+}
+
gpu::Capabilities InProcessCommandBuffer::GetCapabilities() {
return capabilities_;
}

Powered by Google App Engine
This is Rietveld 408576698