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") {
"command_buffer_driver_manager.h",
"command_buffer_impl.cc",
"command_buffer_impl.h",
"command_buffer_impl_observer.h",
"command_buffer_local.cc",
"command_buffer_local.h",
"command_buffer_local_client.h",
......
......@@ -8,7 +8,6 @@
#include "base/macros.h"
#include "base/message_loop/message_loop.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/gpu_state.h"
#include "gpu/command_buffer/service/sync_point_manager.h"
......@@ -53,7 +52,7 @@ class CommandBufferImpl::CommandBufferDriverClientImpl
CommandBufferImpl::CommandBufferImpl(
mojo::InterfaceRequest<mus::mojom::CommandBuffer> request,
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.
gpu_state_->control_task_runner()->PostTask(
FROM_HERE,
......@@ -63,23 +62,21 @@ CommandBufferImpl::CommandBufferImpl(
void CommandBufferImpl::DidLoseContext(uint32_t reason) {
driver_->set_client(nullptr);
loss_observer_->DidLoseContext(reason);
client_->Destroyed(reason, gpu::error::kLostContext);
}
CommandBufferImpl::~CommandBufferImpl() {
if (observer_)
observer_->OnCommandBufferImplDestroyed();
}
void CommandBufferImpl::Initialize(
mus::mojom::CommandBufferLostContextObserverPtr loss_observer,
mus::mojom::CommandBufferClientPtr client,
mojo::ScopedSharedBufferHandle shared_state,
mojo::Array<int32_t> attribs,
const mojom::CommandBuffer::InitializeCallback& callback) {
gpu_state_->command_buffer_task_runner()->task_runner()->PostTask(
FROM_HERE,
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::Bind(&RunInitializeCallback, callback)));
}
......@@ -146,6 +143,37 @@ void CommandBufferImpl::DestroyImage(int32_t 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(
mojo::InterfaceRequest<mus::mojom::CommandBuffer> request) {
binding_.reset(
......@@ -154,7 +182,7 @@ void CommandBufferImpl::BindToRequest(
}
void CommandBufferImpl::InitializeOnGpuThread(
mojom::CommandBufferLostContextObserverPtr loss_observer,
mojom::CommandBufferClientPtr client,
mojo::ScopedSharedBufferHandle shared_state,
mojo::Array<int32_t> attribs,
const base::Callback<
......@@ -164,7 +192,7 @@ void CommandBufferImpl::InitializeOnGpuThread(
gpu::CommandBufferNamespace::MOJO, ++g_next_command_buffer_id,
gfx::kNullAcceleratedWidget, gpu_state_));
driver_->set_client(make_scoped_ptr(new CommandBufferDriverClientImpl(this)));
loss_observer_ = mojo::MakeProxy(loss_observer.PassInterface());
client_ = mojo::MakeProxy(client.PassInterface());
bool result =
driver_->Initialize(std::move(shared_state), std::move(attribs));
mojom::CommandBufferInitializeResultPtr initialize_result;
......
......@@ -18,7 +18,6 @@
namespace mus {
class CommandBufferDriver;
class CommandBufferImplObserver;
class GpuState;
// This class listens to the CommandBuffer message pipe on a low-latency thread
......@@ -31,17 +30,13 @@ class CommandBufferImpl : public mojom::CommandBuffer {
scoped_refptr<GpuState> gpu_state);
void DidLoseContext(uint32_t reason);
void set_observer(CommandBufferImplObserver* observer) {
observer_ = observer;
}
private:
class CommandBufferDriverClientImpl;
~CommandBufferImpl() override;
// mojom::CommandBuffer:
void Initialize(
mojom::CommandBufferLostContextObserverPtr loss_observer,
mojom::CommandBufferClientPtr client,
mojo::ScopedSharedBufferHandle shared_state,
mojo::Array<int32_t> attribs,
const mojom::CommandBuffer::InitializeCallback& callback) override;
......@@ -61,10 +56,26 @@ class CommandBufferImpl : public mojom::CommandBuffer {
int32_t format,
int32_t internal_format) 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.
void InitializeOnGpuThread(
mojom::CommandBufferLostContextObserverPtr loss_observer,
mojom::CommandBufferClientPtr client,
mojo::ScopedSharedBufferHandle shared_state,
mojo::Array<int32_t> attribs,
const base::Callback<
......@@ -95,8 +106,7 @@ class CommandBufferImpl : public mojom::CommandBuffer {
scoped_refptr<GpuState> gpu_state_;
scoped_ptr<CommandBufferDriver> driver_;
scoped_ptr<mojo::Binding<CommandBuffer>> binding_;
CommandBufferImplObserver* observer_;
mojom::CommandBufferLostContextObserverPtr loss_observer_;
mojom::CommandBufferClientPtr client_;
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;
import "gpu/command_buffer/common/capabilities.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";
struct CommandBufferInitializeResult {
......@@ -14,16 +16,24 @@ struct CommandBufferInitializeResult {
gpu.mojom.Capabilities capabilities;
};
interface CommandBufferLostContextObserver {
DidLoseContext(int32 context_lost_reason);
interface CommandBufferClient {
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 {
// Initialize attempts to initialize the command buffer.
// 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.
Initialize(CommandBufferLostContextObserver lost_observer,
Initialize(CommandBufferClient client,
handle<shared_buffer> shared_state,
array<int32> attribs) => (CommandBufferInitializeResult? result);
SetGetBuffer(int32 buffer);
......@@ -32,7 +42,6 @@ interface CommandBuffer {
RegisterTransferBuffer(
int32 id, handle<shared_buffer> transfer_buffer, uint32 size);
DestroyTransferBuffer(int32 id);
CreateImage(int32 id,
handle memory_handle,
int32 type,
......@@ -40,4 +49,13 @@ interface CommandBuffer {
int32 format,
int32 internal_format);
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(
mojo::ScopedMessagePipeHandle command_buffer_handle)
: delegate_(delegate),
attribs_(attribs),
observer_binding_(this),
client_binding_(this),
command_buffer_id_(0),
shared_state_(NULL),
last_put_offset_(-1),
......@@ -84,7 +84,7 @@ CommandBufferClientImpl::CommandBufferClientImpl(
std::move(command_buffer_handle), 0u),
async_waiter);
command_buffer_.set_connection_error_handler(
[this]() { DidLoseContext(gpu::error::kUnknown); });
[this]() { Destroyed(gpu::error::kUnknown, gpu::error::kLostContext); });
}
CommandBufferClientImpl::~CommandBufferClientImpl() {}
......@@ -102,12 +102,12 @@ bool CommandBufferClientImpl::Initialize() {
shared_state()->Initialize();
mus::mojom::CommandBufferLostContextObserverPtr observer_ptr;
observer_binding_.Bind(GetProxy(&observer_ptr), async_waiter_);
mus::mojom::CommandBufferClientPtr client_ptr;
client_binding_.Bind(GetProxy(&client_ptr), async_waiter_);
mus::mojom::CommandBufferInitializeResultPtr initialize_result;
command_buffer_->Initialize(
std::move(observer_ptr), std::move(duped),
std::move(client_ptr), std::move(duped),
mojo::Array<int32_t>::From(attribs_),
base::Bind(&InitializeCallback, &initialize_result));
......@@ -285,13 +285,27 @@ void CommandBufferClientImpl::SignalQuery(uint32_t query,
NOTIMPLEMENTED();
}
void CommandBufferClientImpl::DidLoseContext(int32_t lost_reason) {
last_state_.error = gpu::error::kLostContext;
void CommandBufferClientImpl::Destroyed(int32_t lost_reason, int32_t error) {
last_state_.context_lost_reason =
static_cast<gpu::error::ContextLostReason>(lost_reason);
last_state_.error = static_cast<gpu::error::Error>(error);
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() {
if (last_state_.error == gpu::error::kNoError)
shared_state()->Read(&last_state_);
......@@ -307,7 +321,7 @@ void CommandBufferClientImpl::MakeProgressAndUpdateState() {
if (!command_buffer_.WaitForIncomingResponse()) {
VLOG(1) << "Channel encountered error while waiting for command buffer.";
// TODO(piman): is it ok for this to re-enter?
DidLoseContext(gpu::error::kUnknown);
Destroyed(gpu::error::kUnknown, gpu::error::kLostContext);
return;
}
......
......@@ -33,7 +33,7 @@ class CommandBufferDelegate {
};
class CommandBufferClientImpl
: public mus::mojom::CommandBufferLostContextObserver,
: public mus::mojom::CommandBufferClient,
public gpu::CommandBuffer,
public gpu::GpuControl {
public:
......@@ -84,8 +84,12 @@ class CommandBufferClientImpl
bool CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) override;
private:
// mus::mojom::CommandBufferLostContextObserver implementation:
void DidLoseContext(int32_t lost_reason) override;
// mus::mojom::CommandBufferClient implementation:
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 MakeProgressAndUpdateState();
......@@ -94,7 +98,7 @@ class CommandBufferClientImpl
CommandBufferDelegate* delegate_;
std::vector<int32_t> attribs_;
mojo::Binding<mus::mojom::CommandBufferLostContextObserver> observer_binding_;
mojo::Binding<mus::mojom::CommandBufferClient> client_binding_;
mus::mojom::CommandBufferPtr command_buffer_;
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