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/cc/output_surface_mojo.h" 6 7#include "cc/output/compositor_frame.h" 8#include "cc/output/output_surface_client.h" 9#include "mojo/services/public/cpp/geometry/geometry_type_converters.h" 10#include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" 11 12namespace mojo { 13 14OutputSurfaceMojo::OutputSurfaceMojo( 15 OutputSurfaceMojoClient* client, 16 const scoped_refptr<cc::ContextProvider>& context_provider, 17 SurfacePtr surface, 18 uint32_t id_namespace) 19 : cc::OutputSurface(context_provider), 20 output_surface_mojo_client_(client), 21 surface_(surface.Pass()), 22 id_allocator_(id_namespace) { 23 capabilities_.delegated_rendering = true; 24 capabilities_.max_frames_pending = 1; 25} 26 27OutputSurfaceMojo::~OutputSurfaceMojo() { 28} 29 30void OutputSurfaceMojo::ReturnResources(Array<ReturnedResourcePtr> resources) { 31} 32 33bool OutputSurfaceMojo::BindToClient(cc::OutputSurfaceClient* client) { 34 surface_.set_client(this); 35 return cc::OutputSurface::BindToClient(client); 36} 37 38void OutputSurfaceMojo::SwapBuffers(cc::CompositorFrame* frame) { 39 gfx::Size frame_size = 40 frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); 41 if (frame_size != surface_size_) { 42 if (!surface_id_.is_null()) { 43 surface_->DestroySurface(SurfaceId::From(surface_id_)); 44 } 45 surface_id_ = id_allocator_.GenerateId(); 46 surface_->CreateSurface(SurfaceId::From(surface_id_), 47 Size::From(frame_size)); 48 output_surface_mojo_client_->DidCreateSurface(surface_id_); 49 surface_size_ = frame_size; 50 } 51 52 surface_->SubmitFrame(SurfaceId::From(surface_id_), Frame::From(*frame)); 53 54 client_->DidSwapBuffers(); 55 client_->DidSwapBuffersComplete(); 56} 57 58} // namespace mojo 59