Commit 5975c12d authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

GetSharedContextState() return null if GrContext cannot be initialized

Looks like the crash in https://crbug.com/1086428 is because GrContext
is not initialized successfully, and then we are accessing the nullptr
GrContext, and then segment fault happens. Fix the problem by making
GetSharedContextState() return nullptr if GrContext cannot be
initialized.

Bug: 1086428
Change-Id: I288fc6832d6b0c838e16c119354e50db2ad2af80
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214912
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: default avatarJonathan Backer <backer@chromium.org>
Auto-Submit: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771851}
parent 82d399b0
......@@ -191,7 +191,7 @@ SharedContextState::~SharedContextState() {
this);
}
void SharedContextState::InitializeGrContext(
bool SharedContextState::InitializeGrContext(
const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
GrContextOptions::PersistentCache* cache,
......@@ -220,7 +220,7 @@ void SharedContextState::InitializeGrContext(
if (!interface) {
LOG(ERROR) << "OOP raster support disabled: GrGLInterface creation "
"failed.";
return;
return false;
}
if (activity_flags && cache) {
......@@ -255,12 +255,13 @@ void SharedContextState::InitializeGrContext(
}
if (!gr_context_) {
LOG(ERROR) << "OOP raster support disabled: GrContext creation "
"failed.";
} else {
gr_context_->setResourceCacheLimit(max_resource_cache_bytes);
LOG(ERROR) << "OOP raster support disabled: GrContext creation failed.";
return false;
}
gr_context_->setResourceCacheLimit(max_resource_cache_bytes);
transfer_cache_ = std::make_unique<ServiceTransferCache>(gpu_preferences);
return true;
}
bool SharedContextState::InitializeGL(
......
......@@ -68,7 +68,7 @@ class GPU_GLES2_EXPORT SharedContextState
base::WeakPtr<gpu::MemoryTracker::Observer> peak_memory_monitor =
nullptr);
void InitializeGrContext(const GpuPreferences& gpu_preferences,
bool InitializeGrContext(const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
GrContextOptions::PersistentCache* cache,
GpuProcessActivityFlags* activity_flags = nullptr,
......
......@@ -721,7 +721,7 @@ scoped_refptr<SharedContextState> GpuChannelManager::GetSharedContextState(
}
// TODO(penghuang): https://crbug.com/899735 Handle device lost for Vulkan.
shared_context_state_ = base::MakeRefCounted<SharedContextState>(
auto shared_context_state = base::MakeRefCounted<SharedContextState>(
std::move(share_group), std::move(surface), std::move(context),
use_virtualized_gl_contexts,
base::BindOnce(&GpuChannelManager::OnContextLost, base::Unretained(this),
......@@ -742,20 +742,25 @@ scoped_refptr<SharedContextState> GpuChannelManager::GetSharedContextState(
if (gpu_preferences_.gr_context_type == gpu::GrContextType::kGL) {
auto feature_info = base::MakeRefCounted<gles2::FeatureInfo>(
gpu_driver_bug_workarounds(), gpu_feature_info());
if (!shared_context_state_->InitializeGL(gpu_preferences_,
feature_info.get())) {
shared_context_state_ = nullptr;
if (!shared_context_state->InitializeGL(gpu_preferences_,
feature_info.get())) {
LOG(ERROR) << "ContextResult::kFatalFailure: Failed to Initialize GL "
"for SharedContextState";
*result = ContextResult::kFatalFailure;
return nullptr;
}
}
shared_context_state_->InitializeGrContext(
gpu_preferences_, gpu_driver_bug_workarounds_, gr_shader_cache(),
&activity_flags_, watchdog_);
if (!shared_context_state->InitializeGrContext(
gpu_preferences_, gpu_driver_bug_workarounds_, gr_shader_cache(),
&activity_flags_, watchdog_)) {
LOG(ERROR) << "ContextResult::kFatalFailure: Failed to Initialize"
"GrContext for SharedContextState";
*result = ContextResult::kFatalFailure;
return nullptr;
}
}
shared_context_state_ = std::move(shared_context_state);
gr_cache_controller_.emplace(shared_context_state_.get(), task_runner_);
*result = ContextResult::kSuccess;
......
......@@ -5,9 +5,11 @@
#include "gpu/ipc/service/gpu_channel_test_common.h"
#include "base/memory/unsafe_shared_memory_region.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_simple_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/memory_dump_manager.h"
#include "components/viz/common/features.h"
#include "gpu/command_buffer/common/activity_flags.h"
#include "gpu/command_buffer/service/scheduler.h"
#include "gpu/command_buffer/service/shared_image_manager.h"
......@@ -77,10 +79,14 @@ GpuChannelTestCommon::GpuChannelTestCommon(
channel_manager_delegate_(
new TestGpuChannelManagerDelegate(scheduler_.get())) {
// We need GL bindings to actually initialize command buffers.
if (use_stub_bindings)
if (use_stub_bindings) {
gl::GLSurfaceTestSupport::InitializeOneOffWithStubBindings();
else
// GrContext cannot be created with stub bindings.
scoped_feature_list_ = std::make_unique<base::test::ScopedFeatureList>();
scoped_feature_list_->InitAndDisableFeature(features::kUseSkiaRenderer);
} else {
gl::GLSurfaceTestSupport::InitializeOneOff();
}
GpuFeatureInfo feature_info;
feature_info.enabled_gpu_driver_bug_workarounds =
......
......@@ -15,9 +15,15 @@
namespace base {
class TestSimpleTaskRunner;
namespace test {
class ScopedFeatureList;
} // namespace test
namespace trace_event {
class MemoryDumpManager;
} // namespace trace_event
} // namespace base
namespace IPC {
......@@ -63,6 +69,7 @@ class GpuChannelTestCommon : public testing::Test {
std::unique_ptr<SharedImageManager> shared_image_manager_;
std::unique_ptr<Scheduler> scheduler_;
std::unique_ptr<TestGpuChannelManagerDelegate> channel_manager_delegate_;
std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_;
std::unique_ptr<GpuChannelManager> channel_manager_;
DISALLOW_COPY_AND_ASSIGN(GpuChannelTestCommon);
......
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