Use local ids for Surfaces APIs that can only apply to local surfaces

Surfaces identifiers have a local and a namespace component. The
namespace is particular to a connection. The local component is up to
the endpoint of the connection to manage. In contexts where a surface
that may be from anywhere is referenced, a fully qualified ID with both
the local and namespace component is needed in order to be unambiguous.
In contexts that can only apply to local surfaces only the local id is
needed.

This updates the mojo.Surface APIs that can only refer to local IDs to
only take the local component. In particular creating, destroying, or
submitting a frame can only refer to surfaces created on that connection.
References to surfaces within a frame may refer to local or foreign
surfaces so they use fully qualified IDs.

This also skips the SurfacesService indirection since many applications
can perform useful operations on a mojo.Surface interface such as create
surfaces and submit frames without knowing their ID namespace. The
namespace component is needed only to pass fully qualified IDs to other
actors that may wish to reference the produced frame.

R=sky@chromium.org

Review URL: https://codereview.chromium.org/826423008
This commit is contained in:
James Robinson 2015-01-14 10:25:31 -08:00
parent f77fe8f15b
commit 3ab6eab14c
4 changed files with 27 additions and 47 deletions

View File

@ -16,7 +16,7 @@ namespace sky {
LayerHost::LayerHost(LayerHostClient* client) LayerHost::LayerHost(LayerHostClient* client)
: client_(client), : client_(client),
state_(kWaitingForSurfaceService), state_(kReadyForFrame),
frame_requested_(false), frame_requested_(false),
surface_holder_(this, client->GetShell()), surface_holder_(this, client->GetShell()),
gl_context_owner_(client->GetShell()), gl_context_owner_(client->GetShell()),
@ -46,13 +46,6 @@ void LayerHost::GetPixelsForTesting(std::vector<unsigned char>* pixels) {
return root_layer_->GetPixelsForTesting(pixels); return root_layer_->GetPixelsForTesting(pixels);
} }
void LayerHost::OnSurfaceConnectionCreated() {
DCHECK_EQ(state_, kWaitingForSurfaceService);
state_ = kReadyForFrame;
if (frame_requested_)
BeginFrameSoon();
}
void LayerHost::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { void LayerHost::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) {
client_->OnSurfaceIdAvailable(surface_id.Pass()); client_->OnSurfaceIdAvailable(surface_id.Pass());
} }

View File

@ -45,13 +45,11 @@ class LayerHost : public SurfaceHolder::Client {
private: private:
enum State { enum State {
kWaitingForSurfaceService,
kReadyForFrame, kReadyForFrame,
kWaitingForFrameAcknowldgement, kWaitingForFrameAcknowldgement,
}; };
// SurfaceHolder::Client // SurfaceHolder::Client
void OnSurfaceConnectionCreated() override;
void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) override; void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) override;
void ReturnResources( void ReturnResources(
mojo::Array<mojo::ReturnedResourcePtr> resources) override; mojo::Array<mojo::ReturnedResourcePtr> resources) override;

View File

@ -17,48 +17,50 @@ SurfaceHolder::Client::~Client() {
} }
SurfaceHolder::SurfaceHolder(Client* client, mojo::Shell* shell) SurfaceHolder::SurfaceHolder(Client* client, mojo::Shell* shell)
: client_(client), weak_factory_(this) { : client_(client), id_namespace_(0u), local_id_(0u), weak_factory_(this) {
mojo::ServiceProviderPtr service_provider; mojo::ServiceProviderPtr service_provider;
shell->ConnectToApplication("mojo:surfaces_service", shell->ConnectToApplication("mojo:surfaces_service",
mojo::GetProxy(&service_provider)); mojo::GetProxy(&service_provider));
mojo::ConnectToService(service_provider.get(), &surfaces_service_); mojo::ConnectToService(service_provider.get(), &surface_);
surface_.set_client(this);
surfaces_service_->CreateSurfaceConnection(base::Bind(
&SurfaceHolder::OnSurfaceConnectionCreated, weak_factory_.GetWeakPtr()));
} }
SurfaceHolder::~SurfaceHolder() { SurfaceHolder::~SurfaceHolder() {
if (surface_ && surface_id_) if (local_id_ != 0u)
surface_->DestroySurface(surface_id_.Clone()); surface_->DestroySurface(local_id_);
}
bool SurfaceHolder::IsReadyForFrame() const {
return surface_;
} }
void SurfaceHolder::SubmitFrame(mojo::FramePtr frame, void SurfaceHolder::SubmitFrame(mojo::FramePtr frame,
const base::Closure& callback) { const base::Closure& callback) {
surface_->SubmitFrame(surface_id_.Clone(), frame.Pass(), callback); surface_->SubmitFrame(local_id_, frame.Pass(), callback);
} }
void SurfaceHolder::SetSize(const gfx::Size& size) { void SurfaceHolder::SetSize(const gfx::Size& size) {
if (surface_id_ && size_ == size) if (local_id_ != 0u && size_ == size)
return; return;
if (surface_id_) { if (local_id_ != 0u)
surface_->DestroySurface(surface_id_.Clone()); surface_->DestroySurface(local_id_);
} else {
surface_id_ = mojo::SurfaceId::New();
}
surface_id_ = surface_allocator_->CreateSurfaceId(); local_id_++;
surface_->CreateSurface(surface_id_.Clone()); surface_->CreateSurface(local_id_);
size_ = size; size_ = size;
client_->OnSurfaceIdAvailable(surface_id_.Clone()); if (id_namespace_ != 0u)
SetQualifiedId();
}
void SurfaceHolder::SetQualifiedId() {
auto qualified_id = mojo::SurfaceId::New();
qualified_id->id_namespace = id_namespace_;
qualified_id->local = local_id_;
client_->OnSurfaceIdAvailable(qualified_id.Pass());
} }
void SurfaceHolder::SetIdNamespace(uint32_t id_namespace) { void SurfaceHolder::SetIdNamespace(uint32_t id_namespace) {
id_namespace_ = id_namespace;
if (local_id_ != 0u)
SetQualifiedId();
} }
void SurfaceHolder::ReturnResources( void SurfaceHolder::ReturnResources(
@ -69,12 +71,4 @@ void SurfaceHolder::ReturnResources(
client_->ReturnResources(resources.Pass()); client_->ReturnResources(resources.Pass());
} }
void SurfaceHolder::OnSurfaceConnectionCreated(mojo::SurfacePtr surface,
uint32_t id_namespace) {
surface_ = surface.Pass();
surface_.set_client(this);
surface_allocator_.reset(new SurfaceAllocator(id_namespace));
client_->OnSurfaceConnectionCreated();
}
} // namespace sky } // namespace sky

View File

@ -24,7 +24,6 @@ class SurfaceHolder : public mojo::SurfaceClient {
public: public:
class Client { class Client {
public: public:
virtual void OnSurfaceConnectionCreated() = 0;
virtual void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) = 0; virtual void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) = 0;
virtual void ReturnResources( virtual void ReturnResources(
mojo::Array<mojo::ReturnedResourcePtr> resources) = 0; mojo::Array<mojo::ReturnedResourcePtr> resources) = 0;
@ -36,8 +35,6 @@ class SurfaceHolder : public mojo::SurfaceClient {
explicit SurfaceHolder(Client* client, mojo::Shell* shell); explicit SurfaceHolder(Client* client, mojo::Shell* shell);
~SurfaceHolder() override; ~SurfaceHolder() override;
bool IsReadyForFrame() const;
void SetSize(const gfx::Size& size); void SetSize(const gfx::Size& size);
void SubmitFrame(mojo::FramePtr frame, const base::Closure& callback); void SubmitFrame(mojo::FramePtr frame, const base::Closure& callback);
@ -47,15 +44,13 @@ class SurfaceHolder : public mojo::SurfaceClient {
void ReturnResources( void ReturnResources(
mojo::Array<mojo::ReturnedResourcePtr> resources) override; mojo::Array<mojo::ReturnedResourcePtr> resources) override;
void OnSurfaceConnectionCreated(mojo::SurfacePtr surface, void SetQualifiedId();
uint32_t id_namespace);
Client* client_; Client* client_;
gfx::Size size_; gfx::Size size_;
scoped_ptr<SurfaceAllocator> surface_allocator_; uint32_t id_namespace_;
mojo::SurfacesServicePtr surfaces_service_; uint32_t local_id_;
mojo::SurfacePtr surface_; mojo::SurfacePtr surface_;
mojo::SurfaceIdPtr surface_id_;
base::WeakPtrFactory<SurfaceHolder> weak_factory_; base::WeakPtrFactory<SurfaceHolder> weak_factory_;