Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1022)

Unified Diff: services/fake_surfaces/fake_surfaces_service_application.cc

Issue 1537803002: Revert "Delete the Surfaces service." (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/fake_surfaces/fake_surfaces_service_application.h ('k') | services/surfaces/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/fake_surfaces/fake_surfaces_service_application.cc
diff --git a/services/fake_surfaces/fake_surfaces_service_application.cc b/services/fake_surfaces/fake_surfaces_service_application.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4eb25c3d75b985e3130e2ff890766a50f0840cc6
--- /dev/null
+++ b/services/fake_surfaces/fake_surfaces_service_application.cc
@@ -0,0 +1,151 @@
+// 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.
+
+#include "services/fake_surfaces/fake_surfaces_service_application.h"
+
+#include "mojo/application/application_runner_chromium.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
+#include "mojo/services/surfaces/interfaces/surfaces.mojom.h"
+
+using mojo::ApplicationConnection;
+using mojo::Display;
+using mojo::DisplayFactory;
+using mojo::InterfaceRequest;
+using mojo::ResourceReturnerPtr;
+using mojo::StrongBinding;
+using mojo::Surface;
+
+namespace fake_surfaces {
+
+namespace {
+void ReturnAll(const mojo::Array<mojo::TransferableResourcePtr>& resources,
+ mojo::ResourceReturner* returner) {
+ mojo::Array<mojo::ReturnedResourcePtr> returned;
+ returned.resize(resources.size());
+ for (size_t i = 0; i < resources.size(); ++i) {
+ auto ret = mojo::ReturnedResource::New();
+ ret->id = resources[i]->id;
+ ret->sync_point = 0u;
+ ret->count = 1;
+ ret->lost = false;
+ returned[i] = ret.Pass();
+ }
+ returner->ReturnResources(returned.Pass());
+}
+
+} // namespace
+
+class FakeDisplayImpl : public Display {
+ public:
+ FakeDisplayImpl(ResourceReturnerPtr returner,
+ InterfaceRequest<Display> request)
+ : returner_(returner.Pass()), binding_(this, request.Pass()) {}
+ ~FakeDisplayImpl() override {}
+
+ private:
+ // Display implementation
+ void SubmitFrame(mojo::FramePtr frame,
+ const SubmitFrameCallback& callback) override {
+ callback.Run();
+ if (frame->resources.size() == 0u || !returner_)
+ return;
+ ReturnAll(frame->resources, returner_.get());
+ }
+
+ ResourceReturnerPtr returner_;
+ StrongBinding<Display> binding_;
+};
+
+class FakeDisplayFactoryImpl : public DisplayFactory {
+ public:
+ explicit FakeDisplayFactoryImpl(InterfaceRequest<DisplayFactory> request)
+ : binding_(this, request.Pass()) {}
+ ~FakeDisplayFactoryImpl() override {}
+
+ private:
+ // DisplayFactory implementation.
+ void Create(mojo::ContextProviderPtr context_provider,
+ ResourceReturnerPtr returner,
+ InterfaceRequest<Display> request) override {
+ new FakeDisplayImpl(returner.Pass(), request.Pass());
+ }
+
+ StrongBinding<DisplayFactory> binding_;
+};
+
+class FakeSurfaceImpl : public Surface {
+ public:
+ FakeSurfaceImpl(uint32_t id_namespace, InterfaceRequest<Surface> request)
+ : id_namespace_(id_namespace), binding_(this, request.Pass()) {}
+ ~FakeSurfaceImpl() override {}
+
+ // Surface implementation.
+ void GetIdNamespace(
+ const Surface::GetIdNamespaceCallback& callback) override {
+ callback.Run(id_namespace_);
+ }
+
+ void SetResourceReturner(ResourceReturnerPtr returner) override {
+ returner_ = returner.Pass();
+ }
+
+ void CreateSurface(uint32_t local_id) override {}
+
+ void SubmitFrame(uint32_t local_id,
+ mojo::FramePtr frame,
+ const SubmitFrameCallback& callback) override {
+ callback.Run();
+ if (frame->resources.size() == 0u || !returner_)
+ return;
+ ReturnAll(frame->resources, returner_.get());
+ }
+
+ void DestroySurface(uint32_t local_id) override {}
+
+ private:
+ const uint32_t id_namespace_;
+ ResourceReturnerPtr returner_;
+ StrongBinding<Surface> binding_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeSurfaceImpl);
+};
+
+FakeSurfacesServiceApplication::FakeSurfacesServiceApplication()
+ : next_id_namespace_(1u) {
+}
+
+FakeSurfacesServiceApplication::~FakeSurfacesServiceApplication() {
+}
+
+void FakeSurfacesServiceApplication::Initialize(mojo::ApplicationImpl* app) {
+ tracing_.Initialize(app);
+}
+
+bool FakeSurfacesServiceApplication::ConfigureIncomingConnection(
+ ApplicationConnection* connection) {
+ connection->AddService<DisplayFactory>(this);
+ connection->AddService<Surface>(this);
+ return true;
+}
+
+void FakeSurfacesServiceApplication::Create(
+ ApplicationConnection* connection,
+ InterfaceRequest<DisplayFactory> request) {
+ new FakeDisplayFactoryImpl(request.Pass());
+}
+
+void FakeSurfacesServiceApplication::Create(ApplicationConnection* connection,
+ InterfaceRequest<Surface> request) {
+ new FakeSurfaceImpl(next_id_namespace_++, request.Pass());
+}
+
+} // namespace fake_surfaces
+
+MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ApplicationRunnerChromium runner(
+ new fake_surfaces::FakeSurfacesServiceApplication);
+ return runner.Run(application_request);
+}
« no previous file with comments | « services/fake_surfaces/fake_surfaces_service_application.h ('k') | services/surfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698