Commit b0bee3ff authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

gpu: Fix SharedContextState in InProcessCB

Nothing in production should rely on InProcessCommandBuffer creating its
own SharedContextState. If one is required, it must be obtained from the
task executor and thus shared with other contexts.

Just remove the code and fail init if SharedContextState is null when it
is required.

Change-Id: I7de905182c8127d17907caff4bfd005182037b15
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1970135Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726098}
parent c3ebb9a4
......@@ -682,18 +682,9 @@ gpu::ContextResult InProcessCommandBuffer::InitializeOnGpuThread(
if (params.attribs.enable_raster_interface &&
!params.attribs.enable_gles2_interface) {
gr_shader_cache_ = params.gr_shader_cache;
if (!context_state_) {
context_state_ = base::MakeRefCounted<SharedContextState>(
gl_share_group_, surface_, real_context,
use_virtualized_gl_context_, base::DoNothing(),
task_executor_->gpu_preferences().gr_context_type);
context_state_->InitializeGL(task_executor_->gpu_preferences(),
context_group_->feature_info());
context_state_->InitializeGrContext(workarounds, params.gr_shader_cache,
params.activity_flags);
}
if (!context_state_->MakeCurrent(nullptr, /*needs_gl=*/true)) {
if (!context_state_ ||
!context_state_->MakeCurrent(nullptr, /*needs_gl=*/true)) {
DestroyOnGpuThread();
LOG(ERROR) << "Failed to make context current.";
return ContextResult::kTransientFailure;
......
......@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "gpu/command_buffer/service/mailbox_manager_factory.h"
#include "gpu/command_buffer/service/scheduler.h"
#include "gpu/command_buffer/service/service_utils.h"
......@@ -17,6 +18,7 @@
#include "gpu/config/gpu_info_collector.h"
#include "gpu/config/gpu_util.h"
#include "gpu/ipc/gpu_in_process_thread_service.h"
#include "ui/gl/init/gl_factory.h"
namespace gpu {
......@@ -71,11 +73,40 @@ void InProcessGpuThreadHolder::InitializeOnGpuThread(
task_runner(), sync_point_manager_.get(), gpu_preferences_);
mailbox_manager_ = gles2::CreateMailboxManager(gpu_preferences_);
shared_image_manager_ = std::make_unique<SharedImageManager>();
share_group_ = new gl::GLShareGroup();
surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size());
gl::GLContextAttribs attribs = gles2::GenerateGLContextAttribs(
ContextCreationAttribs(), false /* use_passthrough_decoder */);
context_ =
gl::init::CreateGLContext(share_group_.get(), surface_.get(), attribs);
CHECK(context_->MakeCurrent(surface_.get()));
GpuDriverBugWorkarounds gpu_driver_bug_workarounds(
gpu_feature_info_.enabled_gpu_driver_bug_workarounds);
bool use_virtualized_gl_context_ = false;
#if defined(OS_MACOSX)
// Virtualize GpuPreference:::kLowPower contexts by default on OS X to prevent
// performance regressions when enabling FCM. https://crbug.com/180463
use_virtualized_gl_context_ = true;
#endif
use_virtualized_gl_context_ |=
gpu_driver_bug_workarounds.use_virtualized_gl_contexts;
context_state_ = base::MakeRefCounted<SharedContextState>(
share_group_, surface_, context_, use_virtualized_gl_context_,
base::DoNothing(), gpu_preferences_.gr_context_type);
auto feature_info = base::MakeRefCounted<gles2::FeatureInfo>(
gpu_driver_bug_workarounds, gpu_feature_info_);
context_state_->InitializeGL(gpu_preferences_, feature_info);
context_state_->InitializeGrContext(gpu_driver_bug_workarounds, nullptr);
task_executor_ = std::make_unique<GpuInProcessThreadService>(
task_runner(), scheduler_.get(), sync_point_manager_.get(),
mailbox_manager_.get(), nullptr, gl::GLSurfaceFormat(), gpu_feature_info_,
gpu_preferences_, shared_image_manager_.get(), nullptr,
base::BindRepeating([] { return scoped_refptr<SharedContextState>(); }));
base::BindRepeating(&InProcessGpuThreadHolder::GetSharedContextState,
base::Unretained(this)));
completion->Signal();
}
......@@ -85,6 +116,17 @@ void InProcessGpuThreadHolder::DeleteOnGpuThread() {
scheduler_.reset();
sync_point_manager_.reset();
shared_image_manager_.reset();
context_state_.reset();
context_.reset();
surface_.reset();
share_group_.reset();
}
scoped_refptr<SharedContextState>
InProcessGpuThreadHolder::GetSharedContextState() {
DCHECK(context_state_);
return context_state_;
}
} // namespace gpu
......@@ -11,6 +11,7 @@
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/threading/thread.h"
#include "gpu/command_buffer/service/shared_context_state.h"
#include "gpu/config/gpu_feature_info.h"
#include "gpu/config/gpu_preferences.h"
......@@ -46,10 +47,16 @@ class COMPONENT_EXPORT(GPU_THREAD_HOLDER) InProcessGpuThreadHolder
private:
void InitializeOnGpuThread(base::WaitableEvent* completion);
void DeleteOnGpuThread();
scoped_refptr<SharedContextState> GetSharedContextState();
GpuPreferences gpu_preferences_;
GpuFeatureInfo gpu_feature_info_;
scoped_refptr<gl::GLShareGroup> share_group_;
scoped_refptr<gl::GLSurface> surface_;
scoped_refptr<gl::GLContext> context_;
scoped_refptr<SharedContextState> context_state_;
std::unique_ptr<SyncPointManager> sync_point_manager_;
std::unique_ptr<Scheduler> scheduler_;
std::unique_ptr<MailboxManager> mailbox_manager_;
......
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