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 "cc/output/compositor_frame.h"
8 #include "cc/resources/returned_resource.h"
9 #include "cc/surfaces/display.h"
10 #include "cc/surfaces/surface_id_allocator.h"
11 #include "mojo/cc/context_provider_mojo.h"
12 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
13 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h"
14
15 namespace mojo {
16
SurfacesImpl(cc::SurfaceManager * manager,uint32_t id_namespace,Client * client)17 SurfacesImpl::SurfacesImpl(cc::SurfaceManager* manager,
18 uint32_t id_namespace,
19 Client* client)
20 : manager_(manager),
21 factory_(manager, this),
22 id_namespace_(id_namespace),
23 client_(client) {
24 }
25
~SurfacesImpl()26 SurfacesImpl::~SurfacesImpl() {
27 }
28
CreateSurface(SurfaceIdPtr id,mojo::SizePtr size)29 void SurfacesImpl::CreateSurface(SurfaceIdPtr id, mojo::SizePtr size) {
30 cc::SurfaceId cc_id = id.To<cc::SurfaceId>();
31 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) {
32 // Bad message, do something bad to the caller?
33 NOTREACHED();
34 return;
35 }
36 factory_.Create(id.To<cc::SurfaceId>(), size.To<gfx::Size>());
37 }
38
SubmitFrame(SurfaceIdPtr id,FramePtr frame_ptr)39 void SurfacesImpl::SubmitFrame(SurfaceIdPtr id, FramePtr frame_ptr) {
40 cc::SurfaceId cc_id = id.To<cc::SurfaceId>();
41 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) {
42 // Bad message, do something bad to the caller?
43 LOG(FATAL) << "Received frame for id " << cc_id.id << " namespace "
44 << cc::SurfaceIdAllocator::NamespaceForId(cc_id)
45 << " should be namespace " << id_namespace_;
46 return;
47 }
48 factory_.SubmitFrame(id.To<cc::SurfaceId>(),
49 frame_ptr.To<scoped_ptr<cc::CompositorFrame> >(),
50 base::Closure());
51 client_->FrameSubmitted();
52 }
53
DestroySurface(SurfaceIdPtr id)54 void SurfacesImpl::DestroySurface(SurfaceIdPtr id) {
55 cc::SurfaceId cc_id = id.To<cc::SurfaceId>();
56 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) {
57 // Bad message, do something bad to the caller?
58 NOTREACHED();
59 return;
60 }
61 factory_.Destroy(id.To<cc::SurfaceId>());
62 }
63
CreateGLES2BoundSurface(CommandBufferPtr gles2_client,SurfaceIdPtr id,mojo::SizePtr size)64 void SurfacesImpl::CreateGLES2BoundSurface(CommandBufferPtr gles2_client,
65 SurfaceIdPtr id,
66 mojo::SizePtr size) {
67 command_buffer_handle_ = gles2_client.PassMessagePipe();
68
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 LOG(FATAL) << "Received request for id " << cc_id.id << " namespace "
73 << cc::SurfaceIdAllocator::NamespaceForId(cc_id)
74 << " should be namespace " << id_namespace_;
75 return;
76 }
77 if (!display_) {
78 display_.reset(new cc::Display(this, manager_, NULL));
79 client_->SetDisplay(display_.get());
80 }
81 factory_.Create(cc_id, size.To<gfx::Size>());
82 display_->Resize(cc_id, size.To<gfx::Size>());
83 }
84
ReturnResources(const cc::ReturnedResourceArray & resources)85 void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) {
86 Array<ReturnedResourcePtr> ret(resources.size());
87 for (size_t i = 0; i < resources.size(); ++i) {
88 ret[i] = ReturnedResource::From(resources[i]);
89 }
90 client()->ReturnResources(ret.Pass());
91 }
92
CreateOutputSurface()93 scoped_ptr<cc::OutputSurface> SurfacesImpl::CreateOutputSurface() {
94 return make_scoped_ptr(new cc::OutputSurface(
95 new ContextProviderMojo(command_buffer_handle_.Pass())));
96 }
97
DisplayDamaged()98 void SurfacesImpl::DisplayDamaged() {
99 }
100
DidSwapBuffers()101 void SurfacesImpl::DidSwapBuffers() {
102 }
103
DidSwapBuffersComplete()104 void SurfacesImpl::DidSwapBuffersComplete() {
105 }
106
CommitVSyncParameters(base::TimeTicks timebase,base::TimeDelta interval)107 void SurfacesImpl::CommitVSyncParameters(base::TimeTicks timebase,
108 base::TimeDelta interval) {
109 }
110
111 } // namespace mojo
112