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

Unified Diff: services/fake_surfaces/fake_surfaces_service_application.cc

Issue 804693002: Add fake implementation of Surfaces service for sky tests (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 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') | sky/tests/resources/mocha.sky » ('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..a74d4d99b7419108c8fd611c4c4c329a58ca4f36
--- /dev/null
+++ b/services/fake_surfaces/fake_surfaces_service_application.cc
@@ -0,0 +1,114 @@
+// 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/common/tracing_impl.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h"
+
+using mojo::InterfaceRequest;
+
+namespace fake_surfaces {
+
+class FakeSurfaceImpl : public mojo::Surface {
+ public:
+ FakeSurfaceImpl(uint32_t id_namespace, mojo::SurfacePtr* ptr)
+ : binding_(this, ptr) {}
+ ~FakeSurfaceImpl() override {}
+
+ // mojo::Surface implementation.
+ void CreateSurface(mojo::SurfaceIdPtr id, mojo::SizePtr size) override {}
+
+ void SubmitFrame(mojo::SurfaceIdPtr id,
+ mojo::FramePtr frame,
+ const mojo::Closure& callback) override {
+ callback.Run();
+ if (frame->resources.size() == 0u)
+ return;
+ mojo::Array<mojo::ReturnedResourcePtr> returned;
+ returned.resize(frame->resources.size());
+ for (size_t i = 0; i < frame->resources.size(); ++i) {
+ auto ret = mojo::ReturnedResource::New();
+ ret->id = frame->resources[i]->id;
+ ret->sync_point = 0u;
+ ret->count = 1;
+ ret->lost = false;
+ returned[i] = ret.Pass();
+ }
+ binding_.client()->ReturnResources(returned.Pass());
+ }
+
+ void DestroySurface(mojo::SurfaceIdPtr id) override {}
+
+ void CreateGLES2BoundSurface(
+ mojo::CommandBufferPtr gles2_client,
+ mojo::SurfaceIdPtr id,
+ mojo::SizePtr size,
+ mojo::InterfaceRequest<mojo::ViewportParameterListener> listener_request)
+ override {
+ }
+
+ private:
+ mojo::StrongBinding<mojo::Surface> binding_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeSurfaceImpl);
+};
+
+class FakeSurfacesServiceImpl : public mojo::SurfacesService {
+ public:
+ FakeSurfacesServiceImpl(uint32_t* id_namespace,
+ InterfaceRequest<mojo::SurfacesService> request)
+ : binding_(this, request.Pass()), next_id_namespace_(id_namespace) {}
+ ~FakeSurfacesServiceImpl() override {}
+
+ // mojo::SurfacesService implementation.
+ void CreateSurfaceConnection(
+ const mojo::Callback<void(mojo::SurfacePtr, uint32_t)>& callback)
+ override {
+ mojo::SurfacePtr surface;
+ uint32_t id_namespace = (*next_id_namespace_)++;
+ new FakeSurfaceImpl(id_namespace, &surface);
+ callback.Run(surface.Pass(), id_namespace);
+ }
+
+ private:
+ mojo::StrongBinding<mojo::SurfacesService> binding_;
+ uint32_t* next_id_namespace_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeSurfacesServiceImpl);
+};
+
+FakeSurfacesServiceApplication::FakeSurfacesServiceApplication()
+ : next_id_namespace_(1u) {
+}
+
+FakeSurfacesServiceApplication::~FakeSurfacesServiceApplication() {
+}
+
+void FakeSurfacesServiceApplication::Initialize(mojo::ApplicationImpl* app) {
+ mojo::TracingImpl::Create(app);
+}
+
+bool FakeSurfacesServiceApplication::ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) {
+ connection->AddService(this);
+ return true;
+}
+
+void FakeSurfacesServiceApplication::Create(
+ mojo::ApplicationConnection* connection,
+ InterfaceRequest<mojo::SurfacesService> request) {
+ new FakeSurfacesServiceImpl(&next_id_namespace_, request.Pass());
+}
+
+} // namespace fake_surfaces
+
+MojoResult MojoMain(MojoHandle shell_handle) {
+ mojo::ApplicationRunnerChromium runner(
+ new fake_surfaces::FakeSurfacesServiceApplication);
+ return runner.Run(shell_handle);
+}
« no previous file with comments | « services/fake_surfaces/fake_surfaces_service_application.h ('k') | sky/tests/resources/mocha.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698