Chromium Code Reviews| Index: gpu/command_buffer/service/gles2_cmd_decoder.cc |
| diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| index 6934e8bc58baacbe074b94a54cc01b6e8f939737..78d8fb1cc5f19540a195d5f84c6925175753ce9e 100644 |
| --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| @@ -926,6 +926,7 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient { |
| const volatile GLint* rects); |
| // Callback for async SwapBuffers. |
| + void FinishAsyncSwapBuffers(gfx::SwapResult result); |
| void FinishSwapBuffers(gfx::SwapResult result); |
| void DoCommitOverlayPlanes(); |
| @@ -2371,6 +2372,8 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient { |
| bool supports_swap_buffers_with_bounds_; |
| bool supports_commit_overlay_planes_; |
| bool supports_async_swap_; |
| + uint32_t next_async_swap_id_ = 1; |
| + uint32_t pending_swaps_ = 0; |
| bool supports_dc_layers_ = false; |
| // These flags are used to override the state of the shared feature_info_ |
| @@ -11884,10 +11887,14 @@ error::Error GLES2DecoderImpl::HandlePostSubBufferCHROMIUM( |
| ClearScheduleDCLayerState(); |
| if (supports_async_swap_) { |
| - TRACE_EVENT_ASYNC_BEGIN0("cc", "GLES2DecoderImpl::AsyncSwapBuffers", this); |
| + DCHECK_LT(pending_swaps_, 2u); |
| + uint32_t async_swap_id = next_async_swap_id_++; |
| + ++pending_swaps_; |
| + TRACE_EVENT_ASYNC_BEGIN0("gpu", "AsyncSwapBuffers", async_swap_id); |
| + |
| surface_->PostSubBufferAsync( |
| c.x, c.y, c.width, c.height, |
| - base::Bind(&GLES2DecoderImpl::FinishSwapBuffers, |
| + base::Bind(&GLES2DecoderImpl::FinishAsyncSwapBuffers, |
| base::AsWeakPtr(this))); |
| } else { |
| FinishSwapBuffers(surface_->PostSubBuffer(c.x, c.y, c.width, c.height)); |
| @@ -15505,9 +15512,13 @@ void GLES2DecoderImpl::DoSwapBuffers() { |
| glFlush(); |
| } |
| } else if (supports_async_swap_) { |
| - TRACE_EVENT_ASYNC_BEGIN0("cc", "GLES2DecoderImpl::AsyncSwapBuffers", this); |
| - surface_->SwapBuffersAsync(base::Bind(&GLES2DecoderImpl::FinishSwapBuffers, |
| - base::AsWeakPtr(this))); |
| + DCHECK_LT(pending_swaps_, 2u); |
| + uint32_t async_swap_id = next_async_swap_id_++; |
| + ++pending_swaps_; |
| + TRACE_EVENT_ASYNC_BEGIN0("gpu", "AsyncSwapBuffers", async_swap_id); |
| + |
| + surface_->SwapBuffersAsync(base::Bind( |
| + &GLES2DecoderImpl::FinishAsyncSwapBuffers, base::AsWeakPtr(this))); |
| } else { |
| FinishSwapBuffers(surface_->SwapBuffers()); |
| } |
| @@ -15517,6 +15528,15 @@ void GLES2DecoderImpl::DoSwapBuffers() { |
| ExitCommandProcessingEarly(); |
| } |
| +void GLES2DecoderImpl::FinishAsyncSwapBuffers(gfx::SwapResult result) { |
| + DCHECK(pending_swaps_); |
|
reveman
2017/03/27 14:21:22
nit: DCHECK_NE(pending_swaps_, 0u)
Daniele Castagna
2017/03/27 16:11:10
Changed to DCHECK_NE(0u, pending_swaps_).
|
| + uint32_t async_swap_id = next_async_swap_id_ - pending_swaps_; |
| + --pending_swaps_; |
| + TRACE_EVENT_ASYNC_END0("gpu", "AsyncSwapBuffers", async_swap_id); |
| + |
| + FinishSwapBuffers(result); |
| +} |
| + |
| void GLES2DecoderImpl::FinishSwapBuffers(gfx::SwapResult result) { |
| if (result == gfx::SwapResult::SWAP_FAILED) { |
| LOG(ERROR) << "Context lost because SwapBuffers failed."; |
| @@ -15531,10 +15551,6 @@ void GLES2DecoderImpl::FinishSwapBuffers(gfx::SwapResult result) { |
| // known values. |
| backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; |
| } |
| - |
| - if (supports_async_swap_) { |
| - TRACE_EVENT_ASYNC_END0("cc", "GLES2DecoderImpl::AsyncSwapBuffers", this); |
| - } |
| } |
| void GLES2DecoderImpl::DoCommitOverlayPlanes() { |