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"
12 #include "content/browser/compositor/onscreen_display_client.h"
16 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface(
17 cc::SurfaceManager
* surface_manager
,
18 cc::SurfaceIdAllocator
* allocator
,
19 const scoped_refptr
<cc::ContextProvider
>& context_provider
)
20 : cc::OutputSurface(context_provider
,
21 scoped_ptr
<cc::SoftwareOutputDevice
>()),
22 display_client_(NULL
),
23 surface_manager_(surface_manager
),
24 factory_(surface_manager
, this),
25 allocator_(allocator
) {
26 capabilities_
.delegated_rendering
= true;
27 capabilities_
.max_frames_pending
= 1;
30 SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() {
32 if (!surface_id_
.is_null()) {
33 factory_
.Destroy(surface_id_
);
37 void SurfaceDisplayOutputSurface::ReceivedVSyncParameters(
38 base::TimeTicks timebase
,
39 base::TimeDelta interval
) {
40 CommitVSyncParameters(timebase
, interval
);
43 void SurfaceDisplayOutputSurface::SwapBuffers(cc::CompositorFrame
* frame
) {
44 gfx::Size frame_size
=
45 frame
->delegated_frame_data
->render_pass_list
.back()->output_rect
.size();
46 if (frame_size
!= display_size_
) {
47 if (!surface_id_
.is_null()) {
48 factory_
.Destroy(surface_id_
);
50 surface_id_
= allocator_
->GenerateId();
51 factory_
.Create(surface_id_
, frame_size
);
52 display_size_
= frame_size
;
54 display_client_
->display()->Resize(
55 surface_id_
, frame_size
, frame
->metadata
.device_scale_factor
);
57 scoped_ptr
<cc::CompositorFrame
> frame_copy(new cc::CompositorFrame());
58 frame
->AssignTo(frame_copy
.get());
62 base::Bind(&SurfaceDisplayOutputSurface::SwapBuffersComplete
,
63 base::Unretained(this)));
65 client_
->DidSwapBuffers();
68 bool SurfaceDisplayOutputSurface::BindToClient(
69 cc::OutputSurfaceClient
* client
) {
71 DCHECK(display_client_
);
73 // Avoid initializing GL context here, as this should be sharing the
75 return display_client_
->Initialize();
78 void SurfaceDisplayOutputSurface::ReturnResources(
79 const cc::ReturnedResourceArray
& resources
) {
80 cc::CompositorFrameAck ack
;
81 ack
.resources
= resources
;
83 client_
->ReclaimResources(&ack
);
86 void SurfaceDisplayOutputSurface::SwapBuffersComplete() {
87 client_
->DidSwapBuffersComplete();
90 } // namespace content