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

80 lines
2.0 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_LAYER_HOST_H_
#define SKY_COMPOSITOR_LAYER_HOST_H_
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "mojo/gpu/gl_context_owner.h"
#include "mojo/skia/ganesh_context.h"
#include "sky/compositor/layer_host_client.h"
#include "sky/compositor/resource_manager.h"
#include "sky/compositor/surface_holder.h"
namespace sky {
class ResourceManager;
class Layer;
class LayerHostClient;
class LayerHost : public SurfaceHolder::Client {
public:
explicit LayerHost(LayerHostClient* client);
~LayerHost();
LayerHostClient* client() const { return client_; }
const base::WeakPtr<mojo::GLContext>& gl_context() const {
return gl_context_owner_.context();
}
mojo::GaneshContext* ganesh_context() const {
return const_cast<mojo::GaneshContext*>(&ganesh_context_);
}
ResourceManager* resource_manager() const {
return const_cast<ResourceManager*>(&resource_manager_);
}
void SetNeedsAnimate();
void SetRootLayer(scoped_refptr<Layer> layer);
void GetPixelsForTesting(std::vector<unsigned char>* pixels);
private:
enum State {
kReadyForFrame,
kWaitingForFrameAcknowldgement,
};
// SurfaceHolder::Client
void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) override;
void ReturnResources(
mojo::Array<mojo::ReturnedResourcePtr> resources) override;
void BeginFrameSoon();
void BeginFrame();
void Upload(Layer* layer);
void DidCompleteFrame();
LayerHostClient* client_;
State state_;
bool frame_requested_;
SurfaceHolder surface_holder_;
mojo::GLContextOwner gl_context_owner_;
mojo::GaneshContext ganesh_context_;
ResourceManager resource_manager_;
scoped_refptr<Layer> root_layer_;
base::WeakPtrFactory<LayerHost> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(LayerHost);
};
} // namespace sky
#endif // SKY_COMPOSITOR_LAYER_HOST_H_