diff options
author | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-29 17:47:01 +0000 |
---|---|---|
committer | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-29 17:47:01 +0000 |
commit | 890e8966414165e59418b7886778cbd16cc194ac (patch) | |
tree | 3e0de593dd21b86879bd09d228a090f8af105564 /gpu | |
parent | 32fcb896c5d34a483c3adbdec90badbddd54d7d8 (diff) | |
download | chromium_src-890e8966414165e59418b7886778cbd16cc194ac.zip chromium_src-890e8966414165e59418b7886778cbd16cc194ac.tar.gz chromium_src-890e8966414165e59418b7886778cbd16cc194ac.tar.bz2 |
Implement proper synchronization between HW video decode IPC and CommandBuffer.
This is done by inserting tokens into the command-buffer stream
when synchronization is needed, and adding a
last-read/last-written token pair to each IPC message. This
allowed me to remove the bogus FinishGL() calls from the gles2
sample pepper plugin.
As part of this CL, the return value for VideoDecodeAccelerator::{Decode,Flush,Abort} changed from bool to void. These are all async methods so errors ought to be signaled using callbacks.
BUG=none
TEST=gles2 works, no crashes; trybots
Review URL: http://codereview.chromium.org/7260008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90971 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/common/command_buffer.cc | 31 | ||||
-rw-r--r-- | gpu/command_buffer/common/command_buffer.h | 21 | ||||
-rw-r--r-- | gpu/command_buffer/service/gpu_scheduler.cc | 8 | ||||
-rw-r--r-- | gpu/command_buffer/service/gpu_scheduler.h | 6 | ||||
-rw-r--r-- | gpu/gpu.gyp | 1 |
5 files changed, 67 insertions, 0 deletions
diff --git a/gpu/command_buffer/common/command_buffer.cc b/gpu/command_buffer/common/command_buffer.cc new file mode 100644 index 0000000..5a12ed1 --- /dev/null +++ b/gpu/command_buffer/common/command_buffer.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "../common/command_buffer.h" +#include "../common/logging.h" + +namespace gpu { + +ReadWriteTokens::ReadWriteTokens() + : last_token_read(-1), last_token_written(-1) { +} + +ReadWriteTokens::ReadWriteTokens(int32 read, int32 written) + : last_token_read(read), last_token_written(written) { +} + +bool ReadWriteTokens::InRange(int32 token) const { + int32 min = last_token_read; + int32 max = last_token_written; + GPU_DCHECK_GE(min, 0); + GPU_DCHECK_GE(max, 0); + if (min <= max) { + // token should be in [min .. max) + return (token >= min) && (token < max); + } + // token should be in [0 .. max) or [min .. wrap token) + return (token >= min) || (token < max); +} + +} // namespace gpu diff --git a/gpu/command_buffer/common/command_buffer.h b/gpu/command_buffer/common/command_buffer.h index d438f72..d5fb24d 100644 --- a/gpu/command_buffer/common/command_buffer.h +++ b/gpu/command_buffer/common/command_buffer.h @@ -123,6 +123,27 @@ class CommandBuffer { DISALLOW_COPY_AND_ASSIGN(CommandBuffer); }; +// Synchronizing other mechanisms (such as IPC) with the CommandBuffer requires +// inserting (writing) a token into the buffer and knowing what the last token +// read at that point was. ReadWriteTokens is a convenience struct for passing +// these pairs around. Expected usage is to compare a current token to +// [last_token_read,last_token_written). +class ReadWriteTokens { + public: + ReadWriteTokens(int32 read, int32 written); + // Required to support pickling. Use by anything else will DCHECK in InRange. + ReadWriteTokens(); + + // Return true iff |value| is in the range described by |tokens|, accounting + // for (up to) one wrap-around. + bool InRange(int32 token) const; + + // These want to be private (and const) but can't in order to support + // pickling. + int32 last_token_read; + int32 last_token_written; +}; + } // namespace gpu #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ diff --git a/gpu/command_buffer/service/gpu_scheduler.cc b/gpu/command_buffer/service/gpu_scheduler.cc index a67fd3a..1ff60d4 100644 --- a/gpu/command_buffer/service/gpu_scheduler.cc +++ b/gpu/command_buffer/service/gpu_scheduler.cc @@ -273,6 +273,8 @@ Buffer GpuScheduler::GetSharedMemoryBuffer(int32 shm_id) { void GpuScheduler::set_token(int32 token) { command_buffer_->SetToken(token); + if (!set_token_callback_.is_null()) + set_token_callback_.Run(token); } bool GpuScheduler::SetGetOffset(int32 offset) { @@ -311,6 +313,12 @@ void GpuScheduler::SetCommandProcessedCallback( command_processed_callback_.reset(callback); } +void GpuScheduler::SetTokenCallback( + const base::Callback<void(int32)>& callback) { + DCHECK(set_token_callback_.is_null()); + set_token_callback_ = callback; +} + void GpuScheduler::ScheduleProcessCommands() { MessageLoop::current()->PostTask( FROM_HERE, diff --git a/gpu/command_buffer/service/gpu_scheduler.h b/gpu/command_buffer/service/gpu_scheduler.h index a5d10ae..eedae30 100644 --- a/gpu/command_buffer/service/gpu_scheduler.h +++ b/gpu/command_buffer/service/gpu_scheduler.h @@ -158,6 +158,11 @@ class GpuScheduler : public CommandBufferEngine { decoder_->SetLatchCallback(callback); } + // Sets a callback which is called when set_token() is called, and passes the + // just-set token to the callback. DCHECKs that no callback has previously + // been registered for this notification. + void SetTokenCallback(const base::Callback<void(int32)>& callback); + // Get the GLES2Decoder associated with this scheduler. gles2::GLES2Decoder* decoder() const { return decoder_.get(); } @@ -218,6 +223,7 @@ class GpuScheduler : public CommandBufferEngine { scoped_ptr<Callback1<gfx::Size>::Type> wrapped_resize_callback_; scoped_ptr<Callback0::Type> wrapped_swap_buffers_callback_; scoped_ptr<Callback0::Type> command_processed_callback_; + base::Callback<void(int32)> set_token_callback_; }; } // namespace gpu diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp index 6e4a2c3a0..d9f0efa 100644 --- a/gpu/gpu.gyp +++ b/gpu/gpu.gyp @@ -46,6 +46,7 @@ 'command_buffer/common/buffer.h', 'command_buffer/common/cmd_buffer_common.h', 'command_buffer/common/cmd_buffer_common.cc', + 'command_buffer/common/command_buffer.cc', 'command_buffer/common/command_buffer.h', 'command_buffer/common/constants.h', 'command_buffer/common/gles2_cmd_ids_autogen.h', |