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

Unified Diff: services/ui/public/cpp/gpu/mojo_gpu_memory_buffer_manager.cc

Issue 2516943002: mus-gpu: Fix a couple of issues with MojoGpuMemoryBufferManager. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « services/ui/public/cpp/gpu/mojo_gpu_memory_buffer_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/public/cpp/gpu/mojo_gpu_memory_buffer_manager.cc
diff --git a/services/ui/public/cpp/gpu/mojo_gpu_memory_buffer_manager.cc b/services/ui/public/cpp/gpu/mojo_gpu_memory_buffer_manager.cc
index 28a94ae4d70e18c8d7a530e0d309db994a287bfe..8f58c96746776ea052d27543b0eae62e3bece6c6 100644
--- a/services/ui/public/cpp/gpu/mojo_gpu_memory_buffer_manager.cc
+++ b/services/ui/public/cpp/gpu/mojo_gpu_memory_buffer_manager.cc
@@ -16,6 +16,8 @@
#include "services/ui/public/interfaces/constants.mojom.h"
#include "ui/gfx/buffer_format_util.h"
+using DestructionCallback = base::Callback<void(const gpu::SyncToken& sync)>;
+
namespace ui {
namespace {
@@ -27,19 +29,25 @@ void OnGpuMemoryBufferAllocated(gfx::GpuMemoryBufferHandle* ret_handle,
wait->Signal();
}
+void NotifyDestructionOnCorrectThread(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ const DestructionCallback& callback,
+ const gpu::SyncToken& sync_token) {
+ task_runner->PostTask(FROM_HERE, base::Bind(callback, sync_token));
+}
+
} // namespace
MojoGpuMemoryBufferManager::MojoGpuMemoryBufferManager(
- service_manager::Connector* connector)
- : thread_("GpuMemoryThread"),
- connector_(connector->Clone()),
- weak_ptr_factory_(this) {
+ mojom::GpuServicePtr gpu_service)
+ : thread_("GpuMemoryThread"), weak_ptr_factory_(this) {
CHECK(thread_.Start());
- // The thread is owned by this object. Which means the test will not run if
+ // The thread is owned by this object. Which means the task will not run if
// the object has been destroyed. So Unretained() is safe.
thread_.task_runner()->PostTask(
FROM_HERE, base::Bind(&MojoGpuMemoryBufferManager::InitThread,
- base::Unretained(this)));
+ base::Unretained(this),
+ base::Passed(gpu_service.PassInterface())));
}
MojoGpuMemoryBufferManager::~MojoGpuMemoryBufferManager() {
@@ -49,11 +57,14 @@ MojoGpuMemoryBufferManager::~MojoGpuMemoryBufferManager() {
thread_.Stop();
}
-void MojoGpuMemoryBufferManager::InitThread() {
- connector_->ConnectToInterface(ui::mojom::kServiceName, &gpu_service_);
+void MojoGpuMemoryBufferManager::InitThread(
+ mojo::InterfacePtrInfo<mojom::GpuService> gpu_service_info) {
+ gpu_service_.Bind(std::move(gpu_service_info));
+ weak_ptr_ = weak_ptr_factory_.GetWeakPtr();
}
void MojoGpuMemoryBufferManager::TearDownThread() {
+ weak_ptr_factory_.InvalidateWeakPtrs();
gpu_service_.reset();
}
@@ -106,11 +117,15 @@ MojoGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
wait.Wait();
if (gmb_handle.is_null())
return nullptr;
+
+ DestructionCallback callback =
+ base::Bind(&MojoGpuMemoryBufferManager::DeletedGpuMemoryBuffer, weak_ptr_,
+ gmb_handle.id);
std::unique_ptr<gpu::GpuMemoryBufferImpl> buffer(
gpu::GpuMemoryBufferImpl::CreateFromHandle(
gmb_handle, size, format, usage,
- base::Bind(&MojoGpuMemoryBufferManager::DeletedGpuMemoryBuffer,
- weak_ptr_factory_.GetWeakPtr(), gmb_handle.id)));
+ base::Bind(&NotifyDestructionOnCorrectThread, thread_.task_runner(),
+ callback)));
if (!buffer) {
DeletedGpuMemoryBuffer(gmb_handle.id, gpu::SyncToken());
return nullptr;
« no previous file with comments | « services/ui/public/cpp/gpu/mojo_gpu_memory_buffer_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698