Commit dbac2c6a authored by penghuang's avatar penghuang Committed by Commit bot

mus: Modify mojo command buffer to match current chrome gpu ipc.

We are implementing an ipc layer for GPU command buffer, so the command
buffer should not know the underneath ipc (see CL). To achive this goal,
we need modify mojo command buffer interface to match the current chrome
gpu ipc.

CL https://codereview.chromium.org/1656433002/

BUG=None

Review URL: https://codereview.chromium.org/1686543004

Cr-Commit-Position: refs/heads/master@{#374714}
parent 1b53af4a
...@@ -17,7 +17,6 @@ source_set("gles2") { ...@@ -17,7 +17,6 @@ source_set("gles2") {
"command_buffer_driver_manager.h", "command_buffer_driver_manager.h",
"command_buffer_impl.cc", "command_buffer_impl.cc",
"command_buffer_impl.h", "command_buffer_impl.h",
"command_buffer_impl_observer.h",
"command_buffer_local.cc", "command_buffer_local.cc",
"command_buffer_local.h", "command_buffer_local.h",
"command_buffer_local_client.h", "command_buffer_local_client.h",
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "components/mus/gles2/command_buffer_driver.h" #include "components/mus/gles2/command_buffer_driver.h"
#include "components/mus/gles2/command_buffer_impl_observer.h"
#include "components/mus/gles2/command_buffer_type_conversions.h" #include "components/mus/gles2/command_buffer_type_conversions.h"
#include "components/mus/gles2/gpu_state.h" #include "components/mus/gles2/gpu_state.h"
#include "gpu/command_buffer/service/sync_point_manager.h" #include "gpu/command_buffer/service/sync_point_manager.h"
...@@ -53,7 +52,7 @@ class CommandBufferImpl::CommandBufferDriverClientImpl ...@@ -53,7 +52,7 @@ class CommandBufferImpl::CommandBufferDriverClientImpl
CommandBufferImpl::CommandBufferImpl( CommandBufferImpl::CommandBufferImpl(
mojo::InterfaceRequest<mus::mojom::CommandBuffer> request, mojo::InterfaceRequest<mus::mojom::CommandBuffer> request,
scoped_refptr<GpuState> gpu_state) scoped_refptr<GpuState> gpu_state)
: gpu_state_(gpu_state), observer_(nullptr) { : gpu_state_(gpu_state) {
// Bind |CommandBufferImpl| to the |request| in the GPU control thread. // Bind |CommandBufferImpl| to the |request| in the GPU control thread.
gpu_state_->control_task_runner()->PostTask( gpu_state_->control_task_runner()->PostTask(
FROM_HERE, FROM_HERE,
...@@ -63,23 +62,21 @@ CommandBufferImpl::CommandBufferImpl( ...@@ -63,23 +62,21 @@ CommandBufferImpl::CommandBufferImpl(
void CommandBufferImpl::DidLoseContext(uint32_t reason) { void CommandBufferImpl::DidLoseContext(uint32_t reason) {
driver_->set_client(nullptr); driver_->set_client(nullptr);
loss_observer_->DidLoseContext(reason); client_->Destroyed(reason, gpu::error::kLostContext);
} }
CommandBufferImpl::~CommandBufferImpl() { CommandBufferImpl::~CommandBufferImpl() {
if (observer_)
observer_->OnCommandBufferImplDestroyed();
} }
void CommandBufferImpl::Initialize( void CommandBufferImpl::Initialize(
mus::mojom::CommandBufferLostContextObserverPtr loss_observer, mus::mojom::CommandBufferClientPtr client,
mojo::ScopedSharedBufferHandle shared_state, mojo::ScopedSharedBufferHandle shared_state,
mojo::Array<int32_t> attribs, mojo::Array<int32_t> attribs,
const mojom::CommandBuffer::InitializeCallback& callback) { const mojom::CommandBuffer::InitializeCallback& callback) {
gpu_state_->command_buffer_task_runner()->task_runner()->PostTask( gpu_state_->command_buffer_task_runner()->task_runner()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&CommandBufferImpl::InitializeOnGpuThread, base::Bind(&CommandBufferImpl::InitializeOnGpuThread,
base::Unretained(this), base::Passed(&loss_observer), base::Unretained(this), base::Passed(&client),
base::Passed(&shared_state), base::Passed(&attribs), base::Passed(&shared_state), base::Passed(&attribs),
base::Bind(&RunInitializeCallback, callback))); base::Bind(&RunInitializeCallback, callback)));
} }
...@@ -146,6 +143,37 @@ void CommandBufferImpl::DestroyImage(int32_t id) { ...@@ -146,6 +143,37 @@ void CommandBufferImpl::DestroyImage(int32_t id) {
base::Unretained(this), id)); base::Unretained(this), id));
} }
void CommandBufferImpl::CreateStreamTexture(
uint32_t client_texture_id,
const mojom::CommandBuffer::CreateStreamTextureCallback& callback) {
NOTIMPLEMENTED();
}
void CommandBufferImpl::ProduceFrontBuffer(const gpu::Mailbox& mailbox) {
NOTIMPLEMENTED();
}
void CommandBufferImpl::SignalQuery(uint32_t query, uint32_t signal_id) {
NOTIMPLEMENTED();
}
void CommandBufferImpl::SignalSyncToken(const gpu::SyncToken& sync_token,
uint32_t signal_id) {
NOTIMPLEMENTED();
}
void CommandBufferImpl::WaitForGetOffsetInRange(
int32_t start, int32_t end,
const mojom::CommandBuffer::WaitForGetOffsetInRangeCallback& callback) {
NOTIMPLEMENTED();
}
void CommandBufferImpl::WaitForTokenInRange(
int32_t start, int32_t end,
const mojom::CommandBuffer::WaitForGetOffsetInRangeCallback& callback) {
NOTIMPLEMENTED();
}
void CommandBufferImpl::BindToRequest( void CommandBufferImpl::BindToRequest(
mojo::InterfaceRequest<mus::mojom::CommandBuffer> request) { mojo::InterfaceRequest<mus::mojom::CommandBuffer> request) {
binding_.reset( binding_.reset(
...@@ -154,7 +182,7 @@ void CommandBufferImpl::BindToRequest( ...@@ -154,7 +182,7 @@ void CommandBufferImpl::BindToRequest(
} }
void CommandBufferImpl::InitializeOnGpuThread( void CommandBufferImpl::InitializeOnGpuThread(
mojom::CommandBufferLostContextObserverPtr loss_observer, mojom::CommandBufferClientPtr client,
mojo::ScopedSharedBufferHandle shared_state, mojo::ScopedSharedBufferHandle shared_state,
mojo::Array<int32_t> attribs, mojo::Array<int32_t> attribs,
const base::Callback< const base::Callback<
...@@ -164,7 +192,7 @@ void CommandBufferImpl::InitializeOnGpuThread( ...@@ -164,7 +192,7 @@ void CommandBufferImpl::InitializeOnGpuThread(
gpu::CommandBufferNamespace::MOJO, ++g_next_command_buffer_id, gpu::CommandBufferNamespace::MOJO, ++g_next_command_buffer_id,
gfx::kNullAcceleratedWidget, gpu_state_)); gfx::kNullAcceleratedWidget, gpu_state_));
driver_->set_client(make_scoped_ptr(new CommandBufferDriverClientImpl(this))); driver_->set_client(make_scoped_ptr(new CommandBufferDriverClientImpl(this)));
loss_observer_ = mojo::MakeProxy(loss_observer.PassInterface()); client_ = mojo::MakeProxy(client.PassInterface());
bool result = bool result =
driver_->Initialize(std::move(shared_state), std::move(attribs)); driver_->Initialize(std::move(shared_state), std::move(attribs));
mojom::CommandBufferInitializeResultPtr initialize_result; mojom::CommandBufferInitializeResultPtr initialize_result;
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
namespace mus { namespace mus {
class CommandBufferDriver; class CommandBufferDriver;
class CommandBufferImplObserver;
class GpuState; class GpuState;
// This class listens to the CommandBuffer message pipe on a low-latency thread // This class listens to the CommandBuffer message pipe on a low-latency thread
...@@ -31,17 +30,13 @@ class CommandBufferImpl : public mojom::CommandBuffer { ...@@ -31,17 +30,13 @@ class CommandBufferImpl : public mojom::CommandBuffer {
scoped_refptr<GpuState> gpu_state); scoped_refptr<GpuState> gpu_state);
void DidLoseContext(uint32_t reason); void DidLoseContext(uint32_t reason);
void set_observer(CommandBufferImplObserver* observer) {
observer_ = observer;
}
private: private:
class CommandBufferDriverClientImpl; class CommandBufferDriverClientImpl;
~CommandBufferImpl() override; ~CommandBufferImpl() override;
// mojom::CommandBuffer: // mojom::CommandBuffer:
void Initialize( void Initialize(
mojom::CommandBufferLostContextObserverPtr loss_observer, mojom::CommandBufferClientPtr client,
mojo::ScopedSharedBufferHandle shared_state, mojo::ScopedSharedBufferHandle shared_state,
mojo::Array<int32_t> attribs, mojo::Array<int32_t> attribs,
const mojom::CommandBuffer::InitializeCallback& callback) override; const mojom::CommandBuffer::InitializeCallback& callback) override;
...@@ -61,10 +56,26 @@ class CommandBufferImpl : public mojom::CommandBuffer { ...@@ -61,10 +56,26 @@ class CommandBufferImpl : public mojom::CommandBuffer {
int32_t format, int32_t format,
int32_t internal_format) override; int32_t internal_format) override;
void DestroyImage(int32_t id) override; void DestroyImage(int32_t id) override;
void CreateStreamTexture(
uint32_t client_texture_id,
const mojom::CommandBuffer::CreateStreamTextureCallback& callback
) override;
void ProduceFrontBuffer(const gpu::Mailbox& mailbox) override;
void SignalQuery(uint32_t query, uint32_t signal_id) override;
void SignalSyncToken(const gpu::SyncToken& sync_token,
uint32_t signal_id) override;
void WaitForGetOffsetInRange(
int32_t start, int32_t end,
const mojom::CommandBuffer::WaitForGetOffsetInRangeCallback& callback
) override;
void WaitForTokenInRange(
int32_t start, int32_t end,
const mojom::CommandBuffer::WaitForGetOffsetInRangeCallback& callback
) override;
// All helper functions are called in the GPU therad. // All helper functions are called in the GPU therad.
void InitializeOnGpuThread( void InitializeOnGpuThread(
mojom::CommandBufferLostContextObserverPtr loss_observer, mojom::CommandBufferClientPtr client,
mojo::ScopedSharedBufferHandle shared_state, mojo::ScopedSharedBufferHandle shared_state,
mojo::Array<int32_t> attribs, mojo::Array<int32_t> attribs,
const base::Callback< const base::Callback<
...@@ -95,8 +106,7 @@ class CommandBufferImpl : public mojom::CommandBuffer { ...@@ -95,8 +106,7 @@ class CommandBufferImpl : public mojom::CommandBuffer {
scoped_refptr<GpuState> gpu_state_; scoped_refptr<GpuState> gpu_state_;
scoped_ptr<CommandBufferDriver> driver_; scoped_ptr<CommandBufferDriver> driver_;
scoped_ptr<mojo::Binding<CommandBuffer>> binding_; scoped_ptr<mojo::Binding<CommandBuffer>> binding_;
CommandBufferImplObserver* observer_; mojom::CommandBufferClientPtr client_;
mojom::CommandBufferLostContextObserverPtr loss_observer_;
DISALLOW_COPY_AND_ASSIGN(CommandBufferImpl); DISALLOW_COPY_AND_ASSIGN(CommandBufferImpl);
}; };
......
// Copyright 2015 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.
#ifndef COMPONENTS_GLES2_COMMAND_BUFFER_IMPL_OBSERVER_H_
#define COMPONENTS_GLES2_COMMAND_BUFFER_IMPL_OBSERVER_H_
namespace mus {
class CommandBufferImplObserver {
public:
virtual void OnCommandBufferImplDestroyed() = 0;
protected:
~CommandBufferImplObserver() {}
};
} // namespace mus
#endif // COMPONENTS_GLES2_COMMAND_BUFFER_IMPL_OBSERVER_H_
...@@ -6,6 +6,8 @@ module mus.mojom; ...@@ -6,6 +6,8 @@ module mus.mojom;
import "gpu/command_buffer/common/capabilities.mojom"; import "gpu/command_buffer/common/capabilities.mojom";
import "gpu/command_buffer/common/command_buffer.mojom"; import "gpu/command_buffer/common/command_buffer.mojom";
import "gpu/command_buffer/common/mailbox.mojom";
import "gpu/command_buffer/common/sync_token.mojom";
import "ui/mojo/geometry/geometry.mojom"; import "ui/mojo/geometry/geometry.mojom";
struct CommandBufferInitializeResult { struct CommandBufferInitializeResult {
...@@ -14,16 +16,24 @@ struct CommandBufferInitializeResult { ...@@ -14,16 +16,24 @@ struct CommandBufferInitializeResult {
gpu.mojom.Capabilities capabilities; gpu.mojom.Capabilities capabilities;
}; };
interface CommandBufferLostContextObserver { interface CommandBufferClient {
DidLoseContext(int32 context_lost_reason); Destroyed(int32 context_lost_reason,
int32 error);
SignalAck(uint32 id);
// TODO(penghuang): support latency_info and use gfx::SwapResult for result.
SwapBuffersCompleted(/* array<ui.mojom.LatencyInfo> latency_info, */
int32 result);
UpdateState(gpu.mojom.CommandBufferState state);
// TODO(penghuang): use base::TimeTicks & base::TimeDelta.
UpdateVSyncParameters(int64 timebase, int64 interval);
}; };
interface CommandBuffer { interface CommandBuffer {
// Initialize attempts to initialize the command buffer. // Initialize attempts to initialize the command buffer.
// If the context is lost after creation the LostContext method on the // If the context is lost after creation the LostContext method on the
// CommandBufferLostContextObserver's will be called then this pipe will be // CommandBufferClient's will be called then this pipe will be
// closed. // closed.
Initialize(CommandBufferLostContextObserver lost_observer, Initialize(CommandBufferClient client,
handle<shared_buffer> shared_state, handle<shared_buffer> shared_state,
array<int32> attribs) => (CommandBufferInitializeResult? result); array<int32> attribs) => (CommandBufferInitializeResult? result);
SetGetBuffer(int32 buffer); SetGetBuffer(int32 buffer);
...@@ -32,7 +42,6 @@ interface CommandBuffer { ...@@ -32,7 +42,6 @@ interface CommandBuffer {
RegisterTransferBuffer( RegisterTransferBuffer(
int32 id, handle<shared_buffer> transfer_buffer, uint32 size); int32 id, handle<shared_buffer> transfer_buffer, uint32 size);
DestroyTransferBuffer(int32 id); DestroyTransferBuffer(int32 id);
CreateImage(int32 id, CreateImage(int32 id,
handle memory_handle, handle memory_handle,
int32 type, int32 type,
...@@ -40,4 +49,13 @@ interface CommandBuffer { ...@@ -40,4 +49,13 @@ interface CommandBuffer {
int32 format, int32 format,
int32 internal_format); int32 internal_format);
DestroyImage(int32 id); DestroyImage(int32 id);
CreateStreamTexture(uint32 client_texture_id)
=> (int32 stream_id, bool succeeded);
ProduceFrontBuffer(gpu.mojom.Mailbox mailbox);
SignalQuery(uint32 query, uint32 signal_id);
SignalSyncToken(gpu.mojom.SyncToken sync_token, uint32 signal_id);
WaitForGetOffsetInRange(int32 start, int32 end)
=> (gpu.mojom.CommandBufferState state);
WaitForTokenInRange(int32 start, int32 end)
=> (gpu.mojom.CommandBufferState state);
}; };
...@@ -71,7 +71,7 @@ CommandBufferClientImpl::CommandBufferClientImpl( ...@@ -71,7 +71,7 @@ CommandBufferClientImpl::CommandBufferClientImpl(
mojo::ScopedMessagePipeHandle command_buffer_handle) mojo::ScopedMessagePipeHandle command_buffer_handle)
: delegate_(delegate), : delegate_(delegate),
attribs_(attribs), attribs_(attribs),
observer_binding_(this), client_binding_(this),
command_buffer_id_(0), command_buffer_id_(0),
shared_state_(NULL), shared_state_(NULL),
last_put_offset_(-1), last_put_offset_(-1),
...@@ -84,7 +84,7 @@ CommandBufferClientImpl::CommandBufferClientImpl( ...@@ -84,7 +84,7 @@ CommandBufferClientImpl::CommandBufferClientImpl(
std::move(command_buffer_handle), 0u), std::move(command_buffer_handle), 0u),
async_waiter); async_waiter);
command_buffer_.set_connection_error_handler( command_buffer_.set_connection_error_handler(
[this]() { DidLoseContext(gpu::error::kUnknown); }); [this]() { Destroyed(gpu::error::kUnknown, gpu::error::kLostContext); });
} }
CommandBufferClientImpl::~CommandBufferClientImpl() {} CommandBufferClientImpl::~CommandBufferClientImpl() {}
...@@ -102,12 +102,12 @@ bool CommandBufferClientImpl::Initialize() { ...@@ -102,12 +102,12 @@ bool CommandBufferClientImpl::Initialize() {
shared_state()->Initialize(); shared_state()->Initialize();
mus::mojom::CommandBufferLostContextObserverPtr observer_ptr; mus::mojom::CommandBufferClientPtr client_ptr;
observer_binding_.Bind(GetProxy(&observer_ptr), async_waiter_); client_binding_.Bind(GetProxy(&client_ptr), async_waiter_);
mus::mojom::CommandBufferInitializeResultPtr initialize_result; mus::mojom::CommandBufferInitializeResultPtr initialize_result;
command_buffer_->Initialize( command_buffer_->Initialize(
std::move(observer_ptr), std::move(duped), std::move(client_ptr), std::move(duped),
mojo::Array<int32_t>::From(attribs_), mojo::Array<int32_t>::From(attribs_),
base::Bind(&InitializeCallback, &initialize_result)); base::Bind(&InitializeCallback, &initialize_result));
...@@ -285,13 +285,27 @@ void CommandBufferClientImpl::SignalQuery(uint32_t query, ...@@ -285,13 +285,27 @@ void CommandBufferClientImpl::SignalQuery(uint32_t query,
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
void CommandBufferClientImpl::DidLoseContext(int32_t lost_reason) { void CommandBufferClientImpl::Destroyed(int32_t lost_reason, int32_t error) {
last_state_.error = gpu::error::kLostContext;
last_state_.context_lost_reason = last_state_.context_lost_reason =
static_cast<gpu::error::ContextLostReason>(lost_reason); static_cast<gpu::error::ContextLostReason>(lost_reason);
last_state_.error = static_cast<gpu::error::Error>(error);
delegate_->ContextLost(); delegate_->ContextLost();
} }
void CommandBufferClientImpl::SignalAck(uint32_t id) {
}
void CommandBufferClientImpl::SwapBuffersCompleted(int32_t result) {
}
void CommandBufferClientImpl::UpdateState(
const gpu::CommandBuffer::State& state) {
}
void CommandBufferClientImpl::UpdateVSyncParameters(int64_t timebase,
int64_t interval) {
}
void CommandBufferClientImpl::TryUpdateState() { void CommandBufferClientImpl::TryUpdateState() {
if (last_state_.error == gpu::error::kNoError) if (last_state_.error == gpu::error::kNoError)
shared_state()->Read(&last_state_); shared_state()->Read(&last_state_);
...@@ -307,7 +321,7 @@ void CommandBufferClientImpl::MakeProgressAndUpdateState() { ...@@ -307,7 +321,7 @@ void CommandBufferClientImpl::MakeProgressAndUpdateState() {
if (!command_buffer_.WaitForIncomingResponse()) { if (!command_buffer_.WaitForIncomingResponse()) {
VLOG(1) << "Channel encountered error while waiting for command buffer."; VLOG(1) << "Channel encountered error while waiting for command buffer.";
// TODO(piman): is it ok for this to re-enter? // TODO(piman): is it ok for this to re-enter?
DidLoseContext(gpu::error::kUnknown); Destroyed(gpu::error::kUnknown, gpu::error::kLostContext);
return; return;
} }
......
...@@ -33,7 +33,7 @@ class CommandBufferDelegate { ...@@ -33,7 +33,7 @@ class CommandBufferDelegate {
}; };
class CommandBufferClientImpl class CommandBufferClientImpl
: public mus::mojom::CommandBufferLostContextObserver, : public mus::mojom::CommandBufferClient,
public gpu::CommandBuffer, public gpu::CommandBuffer,
public gpu::GpuControl { public gpu::GpuControl {
public: public:
...@@ -84,8 +84,12 @@ class CommandBufferClientImpl ...@@ -84,8 +84,12 @@ class CommandBufferClientImpl
bool CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) override; bool CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) override;
private: private:
// mus::mojom::CommandBufferLostContextObserver implementation: // mus::mojom::CommandBufferClient implementation:
void DidLoseContext(int32_t lost_reason) override; void Destroyed(int32_t lost_reason, int32_t error) override;
void SignalAck(uint32_t id) override;
void SwapBuffersCompleted(int32_t result) override;
void UpdateState(const gpu::CommandBuffer::State& state) override;
void UpdateVSyncParameters(int64_t timebase, int64_t interval) override;
void TryUpdateState(); void TryUpdateState();
void MakeProgressAndUpdateState(); void MakeProgressAndUpdateState();
...@@ -94,7 +98,7 @@ class CommandBufferClientImpl ...@@ -94,7 +98,7 @@ class CommandBufferClientImpl
CommandBufferDelegate* delegate_; CommandBufferDelegate* delegate_;
std::vector<int32_t> attribs_; std::vector<int32_t> attribs_;
mojo::Binding<mus::mojom::CommandBufferLostContextObserver> observer_binding_; mojo::Binding<mus::mojom::CommandBufferClient> client_binding_;
mus::mojom::CommandBufferPtr command_buffer_; mus::mojom::CommandBufferPtr command_buffer_;
uint64_t command_buffer_id_; uint64_t command_buffer_id_;
......
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