flutter_flutter/compositor/surface_holder.h
James Robinson a88056c0b1 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
2015-01-14 10:25:31 -08:00

63 lines
1.6 KiB
C++

// Copyright 2014 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 SKY_COMPOSITOR_SURFACE_HOLDER_H_
#define SKY_COMPOSITOR_SURFACE_HOLDER_H_
#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "mojo/services/surfaces/public/interfaces/surface_id.mojom.h"
#include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h"
#include "mojo/services/surfaces/public/interfaces/surfaces_service.mojom.h"
#include "ui/gfx/geometry/rect.h"
namespace mojo {
class Shell;
}
namespace sky {
class SurfaceAllocator;
class SurfaceHolder : public mojo::SurfaceClient {
public:
class Client {
public:
virtual void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) = 0;
virtual void ReturnResources(
mojo::Array<mojo::ReturnedResourcePtr> resources) = 0;
protected:
virtual ~Client();
};
explicit SurfaceHolder(Client* client, mojo::Shell* shell);
~SurfaceHolder() override;
void SetSize(const gfx::Size& size);
void SubmitFrame(mojo::FramePtr frame, const base::Closure& callback);
private:
// mojo::SurfaceClient
void SetIdNamespace(uint32_t id_namespace) override;
void ReturnResources(
mojo::Array<mojo::ReturnedResourcePtr> resources) override;
void SetQualifiedId();
Client* client_;
gfx::Size size_;
uint32_t id_namespace_;
uint32_t local_id_;
mojo::SurfacePtr surface_;
base::WeakPtrFactory<SurfaceHolder> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(SurfaceHolder);
};
} // namespace sky
#endif // SKY_COMPOSITOR_SURFACE_HOLDER_H_