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

Side by Side Diff: mojo/services/surfaces/surfaces_impl.cc

Issue 771043002: Move surfaces service implementation to //services (Closed) Base URL: git@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 "mojo/services/surfaces/surfaces_impl.h"
6
7 #include "base/debug/trace_event.h"
8 #include "cc/output/compositor_frame.h"
9 #include "cc/resources/returned_resource.h"
10 #include "cc/surfaces/display.h"
11 #include "cc/surfaces/surface_id_allocator.h"
12 #include "mojo/cc/context_provider_mojo.h"
13 #include "mojo/cc/direct_output_surface.h"
14 #include "mojo/converters/geometry/geometry_type_converters.h"
15 #include "mojo/converters/surfaces/surfaces_type_converters.h"
16
17 namespace mojo {
18 namespace {
19 void CallCallback(const Closure& callback) {
20 callback.Run();
21 }
22 }
23
24 SurfacesImpl::SurfacesImpl(cc::SurfaceManager* manager,
25 uint32_t id_namespace,
26 Client* client,
27 SurfacePtr* surface)
28 : manager_(manager),
29 factory_(manager, this),
30 id_namespace_(id_namespace),
31 client_(client),
32 binding_(this, surface) {
33 }
34
35 SurfacesImpl::~SurfacesImpl() {
36 client_->OnDisplayBeingDestroyed(display_.get());
37 factory_.DestroyAll();
38 }
39
40 void SurfacesImpl::CreateSurface(SurfaceIdPtr id, SizePtr size) {
41 cc::SurfaceId cc_id = id.To<cc::SurfaceId>();
42 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) {
43 // Bad message, do something bad to the caller?
44 NOTREACHED();
45 return;
46 }
47 factory_.Create(id.To<cc::SurfaceId>(), size.To<gfx::Size>());
48 }
49
50 void SurfacesImpl::SubmitFrame(SurfaceIdPtr id,
51 FramePtr frame_ptr,
52 const Closure& callback) {
53 TRACE_EVENT0("mojo", "SurfacesImpl::SubmitFrame");
54 cc::SurfaceId cc_id = id.To<cc::SurfaceId>();
55 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) {
56 // Bad message, do something bad to the caller?
57 LOG(FATAL) << "Received frame for id " << cc_id.id << " namespace "
58 << cc::SurfaceIdAllocator::NamespaceForId(cc_id)
59 << " should be namespace " << id_namespace_;
60 return;
61 }
62 factory_.SubmitFrame(id.To<cc::SurfaceId>(),
63 frame_ptr.To<scoped_ptr<cc::CompositorFrame>>(),
64 base::Bind(&CallCallback, callback));
65 client_->FrameSubmitted();
66 }
67
68 void SurfacesImpl::DestroySurface(SurfaceIdPtr id) {
69 cc::SurfaceId cc_id = id.To<cc::SurfaceId>();
70 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) {
71 // Bad message, do something bad to the caller?
72 NOTREACHED();
73 return;
74 }
75 factory_.Destroy(id.To<cc::SurfaceId>());
76 }
77
78 void SurfacesImpl::CreateGLES2BoundSurface(
79 CommandBufferPtr gles2_client,
80 SurfaceIdPtr id,
81 SizePtr size,
82 InterfaceRequest<ViewportParameterListener> listener_request) {
83 command_buffer_handle_ = gles2_client.PassMessagePipe();
84
85 cc::SurfaceId cc_id = id.To<cc::SurfaceId>();
86 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) {
87 // Bad message, do something bad to the caller?
88 LOG(FATAL) << "Received request for id " << cc_id.id << " namespace "
89 << cc::SurfaceIdAllocator::NamespaceForId(cc_id)
90 << " should be namespace " << id_namespace_;
91 return;
92 }
93 if (!display_) {
94 cc::RendererSettings settings;
95 display_.reset(new cc::Display(this, manager_, nullptr, nullptr, settings));
96 client_->SetDisplay(display_.get());
97 display_->Initialize(make_scoped_ptr(new DirectOutputSurface(
98 new ContextProviderMojo(command_buffer_handle_.Pass()))));
99 }
100 factory_.Create(cc_id, size.To<gfx::Size>());
101 display_->Resize(cc_id, size.To<gfx::Size>(), 1.f);
102 parameter_listeners_.AddBinding(this, listener_request.Pass());
103 }
104
105 void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) {
106 Array<ReturnedResourcePtr> ret(resources.size());
107 for (size_t i = 0; i < resources.size(); ++i) {
108 ret[i] = ReturnedResource::From(resources[i]);
109 }
110 binding_.client()->ReturnResources(ret.Pass());
111 }
112
113 void SurfacesImpl::DisplayDamaged() {
114 }
115
116 void SurfacesImpl::DidSwapBuffers() {
117 }
118
119 void SurfacesImpl::DidSwapBuffersComplete() {
120 }
121
122 void SurfacesImpl::CommitVSyncParameters(base::TimeTicks timebase,
123 base::TimeDelta interval) {
124 }
125
126 void SurfacesImpl::OutputSurfaceLost() {
127 }
128
129 void SurfacesImpl::SetMemoryPolicy(const cc::ManagedMemoryPolicy& policy) {
130 }
131
132 void SurfacesImpl::OnVSyncParametersUpdated(int64_t timebase,
133 int64_t interval) {
134 client_->OnVSyncParametersUpdated(
135 base::TimeTicks::FromInternalValue(timebase),
136 base::TimeDelta::FromInternalValue(interval));
137 }
138
139 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/surfaces/surfaces_impl.h ('k') | mojo/services/surfaces/surfaces_service_application.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698