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.
5 #include "mojo/services/surfaces/surfaces_impl.h"
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"
17 SurfacesImpl::SurfacesImpl(cc::SurfaceManager* manager,
18 uint32_t id_namespace,
21 factory_(manager, this),
22 id_namespace_(id_namespace),
26 SurfacesImpl::~SurfacesImpl() {
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?
36 factory_.Create(id.To<cc::SurfaceId>(), size.To<gfx::Size>());
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_;
48 factory_.SubmitFrame(id.To<cc::SurfaceId>(),
49 frame_ptr.To<scoped_ptr<cc::CompositorFrame> >(),
51 client_->FrameSubmitted();
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?
61 factory_.Destroy(id.To<cc::SurfaceId>());
64 void SurfacesImpl::CreateGLES2BoundSurface(CommandBufferPtr gles2_client,
67 command_buffer_handle_ = gles2_client.PassMessagePipe();
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_;
78 display_.reset(new cc::Display(this, manager_, NULL));
79 client_->SetDisplay(display_.get());
81 factory_.Create(cc_id, size.To<gfx::Size>());
82 display_->Resize(cc_id, size.To<gfx::Size>());
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]);
90 client()->ReturnResources(ret.Pass());
93 scoped_ptr<cc::OutputSurface> SurfacesImpl::CreateOutputSurface() {
94 return make_scoped_ptr(new cc::OutputSurface(
95 new ContextProviderMojo(command_buffer_handle_.Pass())));
98 void SurfacesImpl::DisplayDamaged() {
101 void SurfacesImpl::DidSwapBuffers() {
104 void SurfacesImpl::DidSwapBuffersComplete() {
107 void SurfacesImpl::CommitVSyncParameters(base::TimeTicks timebase,
108 base::TimeDelta interval) {