Commit 021565ba authored by Mohsen Izadi's avatar Mohsen Izadi Committed by Commit Bot

Allow HostGpuMemoryBufferManager to add connection error handler for GpuService

Whenever HostGpuMemoryBufferManager tries to get the GpuService instance
using GpuServiceProvider callback, it also sends a callback to be used
as the connection error handler for the GpuService. The code is also
updated such that the provider callback is called only when GpuService
has changed and the return value is cached.

BUG=733482

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: I7f30dc4fd63fe079a02f6c2484ac14c75da3c36a
Reviewed-on: https://chromium-review.googlesource.com/1161211
Commit-Queue: Mohsen Izadi <mohsen@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582089}
parent 901d58a2
...@@ -56,27 +56,6 @@ HostGpuMemoryBufferManager::~HostGpuMemoryBufferManager() { ...@@ -56,27 +56,6 @@ HostGpuMemoryBufferManager::~HostGpuMemoryBufferManager() {
DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(task_runner_->BelongsToCurrentThread());
} }
void HostGpuMemoryBufferManager::GpuServiceShutDown() {
DCHECK(task_runner_->BelongsToCurrentThread());
gpu_service_version_++;
// Drop allocated buffers.
allocated_buffers_.clear();
// Retry requesting pending buffer allocations.
auto pending_buffers = std::move(pending_buffers_);
pending_buffers_.clear();
for (auto& client_pair : pending_buffers) {
for (auto& buffer_pair : client_pair.second) {
auto& buffer = buffer_pair.second;
AllocateGpuMemoryBuffer(
buffer_pair.first, client_pair.first, buffer.size, buffer.format,
buffer.usage, buffer.surface_handle, std::move(buffer.callback));
}
}
}
void HostGpuMemoryBufferManager::DestroyGpuMemoryBuffer( void HostGpuMemoryBufferManager::DestroyGpuMemoryBuffer(
gfx::GpuMemoryBufferId id, gfx::GpuMemoryBufferId id,
int client_id, int client_id,
...@@ -91,7 +70,7 @@ void HostGpuMemoryBufferManager::DestroyGpuMemoryBuffer( ...@@ -91,7 +70,7 @@ void HostGpuMemoryBufferManager::DestroyGpuMemoryBuffer(
return; return;
DCHECK_NE(gfx::EMPTY_BUFFER, buffer_iter->second.type); DCHECK_NE(gfx::EMPTY_BUFFER, buffer_iter->second.type);
if (buffer_iter->second.type != gfx::SHARED_MEMORY_BUFFER) { if (buffer_iter->second.type != gfx::SHARED_MEMORY_BUFFER) {
auto* gpu_service = gpu_service_provider_.Run(); auto* gpu_service = GetGpuService();
DCHECK(gpu_service); DCHECK(gpu_service);
gpu_service->DestroyGpuMemoryBuffer(id, client_id, sync_token); gpu_service->DestroyGpuMemoryBuffer(id, client_id, sync_token);
} }
...@@ -107,7 +86,7 @@ void HostGpuMemoryBufferManager::DestroyAllGpuMemoryBufferForClient( ...@@ -107,7 +86,7 @@ void HostGpuMemoryBufferManager::DestroyAllGpuMemoryBufferForClient(
for (const auto& pair : buffers) { for (const auto& pair : buffers) {
DCHECK_NE(gfx::EMPTY_BUFFER, pair.second.type); DCHECK_NE(gfx::EMPTY_BUFFER, pair.second.type);
if (pair.second.type != gfx::SHARED_MEMORY_BUFFER) { if (pair.second.type != gfx::SHARED_MEMORY_BUFFER) {
auto* gpu_service = gpu_service_provider_.Run(); auto* gpu_service = GetGpuService();
DCHECK(gpu_service); DCHECK(gpu_service);
gpu_service->DestroyGpuMemoryBuffer(pair.first, client_id, gpu_service->DestroyGpuMemoryBuffer(pair.first, client_id,
gpu::SyncToken()); gpu::SyncToken());
...@@ -140,7 +119,7 @@ void HostGpuMemoryBufferManager::AllocateGpuMemoryBuffer( ...@@ -140,7 +119,7 @@ void HostGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
const bool is_native = native_configurations_.find(std::make_pair( const bool is_native = native_configurations_.find(std::make_pair(
format, usage)) != native_configurations_.end(); format, usage)) != native_configurations_.end();
if (is_native) { if (is_native) {
if (auto* gpu_service = gpu_service_provider_.Run()) { if (auto* gpu_service = GetGpuService()) {
PendingBufferInfo buffer_info; PendingBufferInfo buffer_info;
buffer_info.size = size; buffer_info.size = size;
buffer_info.format = format; buffer_info.format = format;
...@@ -271,6 +250,39 @@ bool HostGpuMemoryBufferManager::OnMemoryDump( ...@@ -271,6 +250,39 @@ bool HostGpuMemoryBufferManager::OnMemoryDump(
return true; return true;
} }
mojom::GpuService* HostGpuMemoryBufferManager::GetGpuService() {
DCHECK(task_runner_->BelongsToCurrentThread());
if (gpu_service_)
return gpu_service_;
gpu_service_ = gpu_service_provider_.Run(base::BindOnce(
&HostGpuMemoryBufferManager::OnConnectionError, weak_ptr_));
return gpu_service_;
}
void HostGpuMemoryBufferManager::OnConnectionError() {
DCHECK(task_runner_->BelongsToCurrentThread());
gpu_service_ = nullptr;
gpu_service_version_++;
// Drop allocated buffers.
allocated_buffers_.clear();
// Retry requesting pending buffer allocations.
auto pending_buffers = std::move(pending_buffers_);
pending_buffers_.clear();
for (auto& client_pair : pending_buffers) {
for (auto& buffer_pair : client_pair.second) {
auto& buffer = buffer_pair.second;
AllocateGpuMemoryBuffer(
buffer_pair.first, client_pair.first, buffer.size, buffer.format,
buffer.usage, buffer.surface_handle, std::move(buffer.callback));
}
}
}
uint64_t HostGpuMemoryBufferManager::ClientIdToTracingId(int client_id) const { uint64_t HostGpuMemoryBufferManager::ClientIdToTracingId(int client_id) const {
if (client_id == client_id_) { if (client_id == client_id_) {
return base::trace_event::MemoryDumpManager::GetInstance() return base::trace_event::MemoryDumpManager::GetInstance()
...@@ -298,7 +310,7 @@ void HostGpuMemoryBufferManager::OnGpuMemoryBufferAllocated( ...@@ -298,7 +310,7 @@ void HostGpuMemoryBufferManager::OnGpuMemoryBufferAllocated(
// The client has been destroyed since the allocation request was made. The // The client has been destroyed since the allocation request was made. The
// callback is already called with null handle. // callback is already called with null handle.
if (!handle.is_null() && !stale) { if (!handle.is_null() && !stale) {
auto* gpu_service = gpu_service_provider_.Run(); auto* gpu_service = GetGpuService();
DCHECK(gpu_service); DCHECK(gpu_service);
gpu_service->DestroyGpuMemoryBuffer(handle.id, client_id, gpu_service->DestroyGpuMemoryBuffer(handle.id, client_id,
gpu::SyncToken()); gpu::SyncToken());
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "base/callback_forward.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
...@@ -34,8 +35,11 @@ class VIZ_HOST_EXPORT HostGpuMemoryBufferManager ...@@ -34,8 +35,11 @@ class VIZ_HOST_EXPORT HostGpuMemoryBufferManager
public: public:
// Callback used to get the current instance of GpuService. The callback // Callback used to get the current instance of GpuService. The callback
// should retry launching GPU service if it is not already running, or return // should retry launching GPU service if it is not already running, or return
// nullptr if it is impossible. // nullptr if it is impossible. |connection_error_handler| will be called when
using GpuServiceProvider = base::RepeatingCallback<mojom::GpuService*(void)>; // the GpuService is shut down. The return value will be cached until the GPU
// service is shut down.
using GpuServiceProvider = base::RepeatingCallback<mojom::GpuService*(
base::OnceClosure connection_error_handler)>;
// All function of HostGpuMemoryBufferManager must be called the thread // All function of HostGpuMemoryBufferManager must be called the thread
// associated with |task_runner|, other than the constructor and the // associated with |task_runner|, other than the constructor and the
...@@ -48,11 +52,6 @@ class VIZ_HOST_EXPORT HostGpuMemoryBufferManager ...@@ -48,11 +52,6 @@ class VIZ_HOST_EXPORT HostGpuMemoryBufferManager
scoped_refptr<base::SingleThreadTaskRunner> task_runner); scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~HostGpuMemoryBufferManager() override; ~HostGpuMemoryBufferManager() override;
// This is called whenever GPU service is shut down (e.g. GPU process
// crashes). It will invalidate any allocated memory buffer and retry
// allocation requests for pending memory buffers.
void GpuServiceShutDown();
void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
int client_id, int client_id,
const gpu::SyncToken& sync_token); const gpu::SyncToken& sync_token);
...@@ -111,6 +110,13 @@ class VIZ_HOST_EXPORT HostGpuMemoryBufferManager ...@@ -111,6 +110,13 @@ class VIZ_HOST_EXPORT HostGpuMemoryBufferManager
AllocatedBufferInfo, AllocatedBufferInfo,
BASE_HASH_NAMESPACE::hash<gfx::GpuMemoryBufferId>>; BASE_HASH_NAMESPACE::hash<gfx::GpuMemoryBufferId>>;
mojom::GpuService* GetGpuService();
// This is called whenever GPU service is shut down (e.g. GPU process
// crashes). It will invalidate any allocated memory buffer and retry
// allocation requests for pending memory buffers.
void OnConnectionError();
uint64_t ClientIdToTracingId(int client_id) const; uint64_t ClientIdToTracingId(int client_id) const;
void OnGpuMemoryBufferAllocated(int gpu_service_version, void OnGpuMemoryBufferAllocated(int gpu_service_version,
int client_id, int client_id,
...@@ -118,6 +124,7 @@ class VIZ_HOST_EXPORT HostGpuMemoryBufferManager ...@@ -118,6 +124,7 @@ class VIZ_HOST_EXPORT HostGpuMemoryBufferManager
gfx::GpuMemoryBufferHandle handle); gfx::GpuMemoryBufferHandle handle);
GpuServiceProvider gpu_service_provider_; GpuServiceProvider gpu_service_provider_;
mojom::GpuService* gpu_service_ = nullptr;
// This is incremented every time GPU service is shut down in order check // This is incremented every time GPU service is shut down in order check
// whether a buffer is allocated by the most current GPU service or not. // whether a buffer is allocated by the most current GPU service or not.
......
...@@ -26,7 +26,8 @@ class TestGpuService : public mojom::GpuService { ...@@ -26,7 +26,8 @@ class TestGpuService : public mojom::GpuService {
HostGpuMemoryBufferManager::GpuServiceProvider CreateProvider() { HostGpuMemoryBufferManager::GpuServiceProvider CreateProvider() {
return base::BindRepeating( return base::BindRepeating(
[](mojom::GpuService* gpu_service) { return gpu_service; }, [](mojom::GpuService* gpu_service,
base::OnceClosure connection_error_handler) { return gpu_service; },
base::Unretained(this)); base::Unretained(this));
} }
......
...@@ -86,7 +86,10 @@ DefaultGpuHost::DefaultGpuHost( ...@@ -86,7 +86,10 @@ DefaultGpuHost::DefaultGpuHost(
gpu_memory_buffer_manager_ = gpu_memory_buffer_manager_ =
std::make_unique<viz::HostGpuMemoryBufferManager>( std::make_unique<viz::HostGpuMemoryBufferManager>(
base::BindRepeating( base::BindRepeating(
[](viz::mojom::GpuService* gpu_service) { return gpu_service; }, [](viz::mojom::GpuService* gpu_service,
base::OnceClosure connection_error_handler) {
return gpu_service;
},
gpu_service_.get()), gpu_service_.get()),
next_client_id_++, std::make_unique<gpu::GpuMemoryBufferSupport>(), next_client_id_++, std::make_unique<gpu::GpuMemoryBufferSupport>(),
main_thread_task_runner_); main_thread_task_runner_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment