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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "services/fake_surfaces/fake_surfaces_service_application.h"
6
7 #include "mojo/application/application_runner_chromium.h"
8 #include "mojo/common/tracing_impl.h"
9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h"
12
13 using mojo::InterfaceRequest;
14
15 namespace fake_surfaces {
16
17 class FakeSurfaceImpl : public mojo::Surface {
18 public:
19 FakeSurfaceImpl(uint32_t id_namespace, mojo::SurfacePtr* ptr)
20 : binding_(this, ptr) {}
21 ~FakeSurfaceImpl() override {}
22
23 // mojo::Surface implementation.
24 void CreateSurface(mojo::SurfaceIdPtr id, mojo::SizePtr size) override {}
25
26 void SubmitFrame(mojo::SurfaceIdPtr id,
27 mojo::FramePtr frame,
28 const mojo::Closure& callback) override {
29 callback.Run();
30 if (frame->resources.size() == 0u)
31 return;
32 mojo::Array<mojo::ReturnedResourcePtr> returned;
33 returned.resize(frame->resources.size());
34 for (size_t i = 0; i < frame->resources.size(); ++i) {
35 auto ret = mojo::ReturnedResource::New();
36 ret->id = frame->resources[i]->id;
37 ret->sync_point = 0u;
38 ret->count = 1;
39 ret->lost = false;
40 returned[i] = ret.Pass();
41 }
42 binding_.client()->ReturnResources(returned.Pass());
43 }
44
45 void DestroySurface(mojo::SurfaceIdPtr id) override {}
46
47 void CreateGLES2BoundSurface(
48 mojo::CommandBufferPtr gles2_client,
49 mojo::SurfaceIdPtr id,
50 mojo::SizePtr size,
51 mojo::InterfaceRequest<mojo::ViewportParameterListener> listener_request)
52 override {
53 }
54
55 private:
56 mojo::StrongBinding<mojo::Surface> binding_;
57
58 DISALLOW_COPY_AND_ASSIGN(FakeSurfaceImpl);
59 };
60
61 class FakeSurfacesServiceImpl : public mojo::SurfacesService {
62 public:
63 FakeSurfacesServiceImpl(uint32_t* id_namespace,
64 InterfaceRequest<mojo::SurfacesService> request)
65 : binding_(this, request.Pass()), next_id_namespace_(id_namespace) {}
66 ~FakeSurfacesServiceImpl() override {}
67
68 // mojo::SurfacesService implementation.
69 void CreateSurfaceConnection(
70 const mojo::Callback<void(mojo::SurfacePtr, uint32_t)>& callback)
71 override {
72 mojo::SurfacePtr surface;
73 uint32_t id_namespace = (*next_id_namespace_)++;
74 new FakeSurfaceImpl(id_namespace, &surface);
75 callback.Run(surface.Pass(), id_namespace);
76 }
77
78 private:
79 mojo::StrongBinding<mojo::SurfacesService> binding_;
80 uint32_t* next_id_namespace_;
81
82 DISALLOW_COPY_AND_ASSIGN(FakeSurfacesServiceImpl);
83 };
84
85 FakeSurfacesServiceApplication::FakeSurfacesServiceApplication()
86 : next_id_namespace_(1u) {
87 }
88
89 FakeSurfacesServiceApplication::~FakeSurfacesServiceApplication() {
90 }
91
92 void FakeSurfacesServiceApplication::Initialize(mojo::ApplicationImpl* app) {
93 mojo::TracingImpl::Create(app);
94 }
95
96 bool FakeSurfacesServiceApplication::ConfigureIncomingConnection(
97 mojo::ApplicationConnection* connection) {
98 connection->AddService(this);
99 return true;
100 }
101
102 void FakeSurfacesServiceApplication::Create(
103 mojo::ApplicationConnection* connection,
104 InterfaceRequest<mojo::SurfacesService> request) {
105 new FakeSurfacesServiceImpl(&next_id_namespace_, request.Pass());
106 }
107
108 } // namespace fake_surfaces
109
110 MojoResult MojoMain(MojoHandle shell_handle) {
111 mojo::ApplicationRunnerChromium runner(
112 new fake_surfaces::FakeSurfacesServiceApplication);
113 return runner.Run(shell_handle);
114 }
OLDNEW
« 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