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/output_surface_client.h"
10 #include "mojo/converters/geometry/geometry_type_converters.h"
11 #include "mojo/converters/surfaces/surfaces_type_converters.h"
15 OutputSurfaceMojo::OutputSurfaceMojo(
16 OutputSurfaceMojoClient
* client
,
17 const scoped_refptr
<cc::ContextProvider
>& context_provider
,
19 : cc::OutputSurface(context_provider
),
20 output_surface_mojo_client_(client
),
21 surface_(surface
.Pass()),
24 capabilities_
.delegated_rendering
= true;
25 capabilities_
.max_frames_pending
= 1;
28 OutputSurfaceMojo::~OutputSurfaceMojo() {
31 void OutputSurfaceMojo::SetIdNamespace(uint32_t id_namespace
) {
32 id_namespace_
= id_namespace
;
34 cc::SurfaceId
qualified_id(static_cast<uint64_t>(id_namespace_
) << 32 |
36 output_surface_mojo_client_
->DidCreateSurface(qualified_id
);
40 bool OutputSurfaceMojo::BindToClient(cc::OutputSurfaceClient
* client
) {
41 surface_
->GetIdNamespace(
42 base::Bind(&OutputSurfaceMojo::SetIdNamespace
, base::Unretained(this)));
43 return cc::OutputSurface::BindToClient(client
);
46 void OutputSurfaceMojo::SwapBuffers(cc::CompositorFrame
* frame
) {
47 gfx::Size frame_size
=
48 frame
->delegated_frame_data
->render_pass_list
.back()->output_rect
.size();
49 if (frame_size
!= surface_size_
) {
50 if (local_id_
!= 0u) {
51 surface_
->DestroySurface(local_id_
);
54 surface_
->CreateSurface(local_id_
);
56 cc::SurfaceId
qualified_id(static_cast<uint64_t>(id_namespace_
) << 32 |
58 output_surface_mojo_client_
->DidCreateSurface(qualified_id
);
60 surface_size_
= frame_size
;
63 surface_
->SubmitFrame(local_id_
, Frame::From(*frame
), mojo::Closure());
65 client_
->DidSwapBuffers();
66 client_
->DidSwapBuffersComplete();