Commit 5f348030 authored by sohan's avatar sohan Committed by Commit Bot

cc: HUD handle context lost in Gpu raster.

This returns the resource id in case the HUD canvas
is invalid, because of context loss while SkSurface
creation. The resource is subsequently evicted from
quad list.

BUG=736127
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

patch from issue 2961633002 at patchset 160001 (http://crrev.com/2961633002#ps160001)

Change-Id: I8d04dfed24ec9cd7e2b520d20988b7a70efcacc3
Reviewed-on: https://chromium-review.googlesource.com/571821Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Reviewed-by: default avatarVladimir Levin <vmpstr@chromium.org>
Reviewed-by: default avatarSohan Jyoti Ghosh <sohan.jyoti@huawei.com>
Commit-Queue: Sohan Jyoti Ghosh <sohan.jyoti@huawei.com>
Cr-Commit-Position: refs/heads/master@{#488827}
parent a58a1f01
......@@ -77,8 +77,7 @@ HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl,
internal_contents_scale_(1.f),
fps_graph_(60.0, 80.0),
paint_time_graph_(16.0, 48.0),
fade_step_(0) {
}
fade_step_(0) {}
HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {}
......@@ -161,7 +160,8 @@ void HeadsUpDisplayLayerImpl::AppendQuads(
void HeadsUpDisplayLayerImpl::UpdateHudTexture(
DrawMode draw_mode,
ResourceProvider* resource_provider,
viz::ContextProvider* context_provider) {
viz::ContextProvider* context_provider,
const RenderPassList& list) {
if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id())
return;
......@@ -180,6 +180,10 @@ void HeadsUpDisplayLayerImpl::UpdateHudTexture(
ResourceProvider::ScopedSkSurfaceProvider scoped_surface(
context_provider, &lock, using_worker_context, use_distance_field_text,
can_use_lcd_text, msaa_sample_count);
if (!scoped_surface.sk_surface()) {
EvictHudQuad(list);
return;
}
SkCanvas* gpu_raster_canvas = scoped_surface.sk_surface()->getCanvas();
TRACE_EVENT_END0("cc", "CreateHudCanvas");
......@@ -822,6 +826,25 @@ void HeadsUpDisplayLayerImpl::DrawDebugRects(
}
}
void HeadsUpDisplayLayerImpl::EvictHudQuad(const RenderPassList& list) {
ResourceId evict_resource_id = resources_.back()->id();
// This iterates over the render pass list of quads to evict the hud quad
// appended during render pass preparation. We need this eviction when we
// have a context loss during SkSurface creation in UpdateHudTexture, and
// we early out without updating the Hud contents.
for (const auto& render_pass : list) {
for (auto it = render_pass->quad_list.begin();
it != render_pass->quad_list.end(); ++it) {
for (ResourceId resource_id : it->resources) {
if (resource_id == evict_resource_id) {
render_pass->quad_list.EraseAndInvalidateAllPointers(it);
return;
}
}
}
}
}
const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const {
return "cc::HeadsUpDisplayLayerImpl";
}
......
......@@ -45,7 +45,8 @@ class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl {
AppendQuadsData* append_quads_data) override;
void UpdateHudTexture(DrawMode draw_mode,
ResourceProvider* resource_provider,
viz::ContextProvider* context_provider);
viz::ContextProvider* context_provider,
const RenderPassList& list);
void ReleaseResources() override;
......@@ -55,6 +56,9 @@ class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl {
void SetHUDTypeface(sk_sp<SkTypeface> typeface);
// This evicts hud quad appended during render pass preparation.
void EvictHudQuad(const RenderPassList& list);
// LayerImpl overrides.
void PushPropertiesTo(LayerImpl* layer) override;
......
......@@ -25,12 +25,15 @@ void CheckDrawLayer(HeadsUpDisplayLayerImpl* layer,
bool will_draw = layer->WillDraw(draw_mode, resource_provider);
if (will_draw)
layer->AppendQuads(render_pass.get(), &data);
layer->UpdateHudTexture(draw_mode, resource_provider, context_provider);
RenderPassList pass_list;
pass_list.push_back(std::move(render_pass));
layer->UpdateHudTexture(draw_mode, resource_provider, context_provider,
pass_list);
if (will_draw)
layer->DidDraw(resource_provider);
size_t expected_quad_list_size = will_draw ? 1 : 0;
EXPECT_EQ(expected_quad_list_size, render_pass->quad_list.size());
EXPECT_EQ(expected_quad_list_size, pass_list.back()->quad_list.size());
EXPECT_EQ(0u, data.num_missing_tiles);
EXPECT_EQ(0u, data.num_incomplete_tiles);
}
......
......@@ -1726,7 +1726,7 @@ bool LayerTreeHostImpl::DrawLayers(FrameData* frame) {
TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture");
active_tree_->hud_layer()->UpdateHudTexture(
draw_mode, resource_provider_.get(),
layer_tree_frame_sink_->context_provider());
layer_tree_frame_sink_->context_provider(), frame->render_passes);
}
CompositorFrameMetadata metadata = MakeCompositorFrameMetadata();
......
......@@ -1003,6 +1003,11 @@ class LayerTreeHostContextTestDontUseLostResources
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame,
DrawResult draw_result) override {
if (host_impl->active_tree()->source_frame_number() == 2) {
// Lose the context after draw on the second commit. This will cause
// a third commit to recover.
context3d_->set_times_bind_texture_succeeds(0);
}
return draw_result;
}
......@@ -1018,13 +1023,6 @@ class LayerTreeHostContextTestDontUseLostResources
void DidCommitAndDrawFrame() override {
ASSERT_TRUE(layer_tree_host()->hud_layer());
if (layer_tree_host()->SourceFrameNumber() == 2) {
// Lose the context after draw on the second commit. This will cause
// a third commit to recover.
context3d_->set_times_bind_texture_succeeds(0);
}
// End the test once we know the 3nd frame drew.
if (layer_tree_host()->SourceFrameNumber() < 5) {
layer_tree_host()->root_layer()->SetNeedsDisplay();
......
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