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 "content/browser/compositor/surface_display_output_surface.h"
7 #include "cc/output/compositor_frame.h"
8 #include "cc/output/compositor_frame_ack.h"
9 #include "cc/surfaces/display.h"
10 #include "cc/surfaces/surface.h"
11 #include "cc/surfaces/surface_manager.h"
15 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface(
16 cc::SurfaceManager
* surface_manager
,
17 uint32_t surface_id_namespace
,
18 const scoped_refptr
<cc::ContextProvider
>& context_provider
)
19 : cc::OutputSurface(context_provider
,
20 scoped_ptr
<cc::SoftwareOutputDevice
>()),
22 surface_manager_(surface_manager
),
23 factory_(surface_manager
, this),
24 allocator_(surface_id_namespace
) {
25 capabilities_
.delegated_rendering
= true;
26 capabilities_
.max_frames_pending
= 1;
29 SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() {
31 if (!surface_id_
.is_null()) {
32 factory_
.Destroy(surface_id_
);
36 void SurfaceDisplayOutputSurface::SwapBuffers(cc::CompositorFrame
* frame
) {
37 gfx::Size frame_size
=
38 frame
->delegated_frame_data
->render_pass_list
.back()->output_rect
.size();
39 if (frame_size
!= display_size_
) {
40 if (!surface_id_
.is_null()) {
41 factory_
.Destroy(surface_id_
);
43 surface_id_
= allocator_
.GenerateId();
44 factory_
.Create(surface_id_
, frame_size
);
45 display_size_
= frame_size
;
46 display_
->Resize(surface_id_
, frame_size
);
49 scoped_ptr
<cc::CompositorFrame
> frame_copy(new cc::CompositorFrame());
50 frame
->AssignTo(frame_copy
.get());
54 base::Bind(&SurfaceDisplayOutputSurface::SwapBuffersComplete
,
55 base::Unretained(this)));
57 client_
->DidSwapBuffers();
60 void SurfaceDisplayOutputSurface::ReturnResources(
61 const cc::ReturnedResourceArray
& resources
) {
62 cc::CompositorFrameAck ack
;
63 ack
.resources
= resources
;
65 client_
->ReclaimResources(&ack
);
68 void SurfaceDisplayOutputSurface::SwapBuffersComplete() {
69 client_
->DidSwapBuffersComplete();
72 } // namespace content