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/cc/output_surface_mojo.h"
8 #include "cc/output/compositor_frame.h"
9 #include "cc/output/compositor_frame_ack.h"
10 #include "cc/output/output_surface_client.h"
11 #include "components/view_manager/public/cpp/view_surface.h"
12 #include "mojo/converters/surfaces/surfaces_type_converters.h"
16 OutputSurfaceMojo::OutputSurfaceMojo(
17 const scoped_refptr
<cc::ContextProvider
>& context_provider
,
18 scoped_ptr
<mojo::ViewSurface
> surface
)
19 : cc::OutputSurface(context_provider
),
20 surface_(surface
.Pass()) {
21 capabilities_
.delegated_rendering
= true;
22 capabilities_
.max_frames_pending
= 1;
25 OutputSurfaceMojo::~OutputSurfaceMojo() {
28 bool OutputSurfaceMojo::BindToClient(cc::OutputSurfaceClient
* client
) {
29 surface_
->BindToThread();
30 surface_
->set_client(this);
31 return cc::OutputSurface::BindToClient(client
);
34 void OutputSurfaceMojo::SwapBuffers(cc::CompositorFrame
* frame
) {
35 // TODO(fsamuel, rjkroege): We should probably throttle compositor frames.
36 surface_
->SubmitCompositorFrame(mojo::CompositorFrame::From(*frame
));
38 client_
->DidSwapBuffers();
39 client_
->DidSwapBuffersComplete();
42 void OutputSurfaceMojo::OnResourcesReturned(
43 mojo::ViewSurface
* surface
,
44 mojo::Array
<mojo::ReturnedResourcePtr
> resources
) {
45 cc::CompositorFrameAck cfa
;
46 cfa
.resources
= resources
.To
<cc::ReturnedResourceArray
>();
47 ReclaimResources(&cfa
);