Commit 4adf9909 authored by Jonathan Backer's avatar Jonathan Backer Committed by Commit Bot

Lose context if we cannot make current

We maintain the invariant that context is current when
ScheduleGrContextCleanup is called. We mark the context
as lost if we fail MakeCurrent in PurgeGrCache.

Change-Id: Ie901056816b23d0076586f8e3bd4794c9e4e2c73
Reviewed-on: https://chromium-review.googlesource.com/c/1354120Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Commit-Queue: Jonathan Backer <backer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611900}
parent e787f908
...@@ -21,6 +21,7 @@ GrCacheController::~GrCacheController() = default; ...@@ -21,6 +21,7 @@ GrCacheController::~GrCacheController() = default;
void GrCacheController::ScheduleGrContextCleanup() { void GrCacheController::ScheduleGrContextCleanup() {
DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(context_state_->context->IsCurrent(nullptr));
if (!context_state_->gr_context) if (!context_state_->gr_context)
return; return;
...@@ -34,7 +35,6 @@ void GrCacheController::ScheduleGrContextCleanup() { ...@@ -34,7 +35,6 @@ void GrCacheController::ScheduleGrContextCleanup() {
// a long while even if it is under budget. Below we set a call back to // a long while even if it is under budget. Below we set a call back to
// purge all possible GrContext resources if the context itself is not being // purge all possible GrContext resources if the context itself is not being
// used. // used.
context_state_->context->MakeCurrent(context_state_->surface.get());
context_state_->gr_context->performDeferredCleanup( context_state_->gr_context->performDeferredCleanup(
std::chrono::seconds(kOldResourceCleanupDelaySeconds)); std::chrono::seconds(kOldResourceCleanupDelaySeconds));
...@@ -50,6 +50,17 @@ void GrCacheController::ScheduleGrContextCleanup() { ...@@ -50,6 +50,17 @@ void GrCacheController::ScheduleGrContextCleanup() {
void GrCacheController::PurgeGrCache(uint64_t idle_id) { void GrCacheController::PurgeGrCache(uint64_t idle_id) {
purge_gr_cache_cb_.Cancel(); purge_gr_cache_cb_.Cancel();
if (context_state_->context_lost)
return;
// Skip unnecessary MakeCurrent to improve
// performance. https://crbug.com/457431
if (!context_state_->context->IsCurrent(nullptr) &&
!context_state_->context->MakeCurrent(context_state_->surface.get())) {
context_state_->context_lost = true;
return;
}
// If the idle id changed, the context was used after this callback was // If the idle id changed, the context was used after this callback was
// posted. Schedule another one. // posted. Schedule another one.
if (idle_id != current_idle_id_) { if (idle_id != current_idle_id_) {
...@@ -57,7 +68,6 @@ void GrCacheController::PurgeGrCache(uint64_t idle_id) { ...@@ -57,7 +68,6 @@ void GrCacheController::PurgeGrCache(uint64_t idle_id) {
return; return;
} }
context_state_->context->MakeCurrent(context_state_->surface.get());
context_state_->gr_context->freeGpuResources(); context_state_->gr_context->freeGpuResources();
} }
......
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