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 "cc/surfaces/surface_display_output_surface.h"
8 #include "cc/output/compositor_frame.h"
9 #include "cc/output/compositor_frame_ack.h"
10 #include "cc/surfaces/display.h"
11 #include "cc/surfaces/onscreen_display_client.h"
12 #include "cc/surfaces/surface.h"
13 #include "cc/surfaces/surface_manager.h"
17 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface(
18 SurfaceManager
* surface_manager
,
19 SurfaceIdAllocator
* allocator
,
20 const scoped_refptr
<ContextProvider
>& context_provider
)
21 : OutputSurface(context_provider
),
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;
28 capabilities_
.adjust_deadline_for_parent
= true;
29 capabilities_
.can_force_reclaim_resources
= true;
32 SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() {
34 if (!surface_id_
.is_null()) {
35 factory_
.Destroy(surface_id_
);
39 void SurfaceDisplayOutputSurface::ReceivedVSyncParameters(
40 base::TimeTicks timebase
,
41 base::TimeDelta interval
) {
42 CommitVSyncParameters(timebase
, interval
);
45 void SurfaceDisplayOutputSurface::SwapBuffers(CompositorFrame
* frame
) {
46 gfx::Size frame_size
=
47 frame
->delegated_frame_data
->render_pass_list
.back()->output_rect
.size();
48 if (frame_size
.IsEmpty() || frame_size
!= display_size_
) {
49 if (!surface_id_
.is_null()) {
50 factory_
.Destroy(surface_id_
);
52 surface_id_
= allocator_
->GenerateId();
53 factory_
.Create(surface_id_
);
54 display_size_
= frame_size
;
56 display_client_
->display()->SetSurfaceId(surface_id_
,
57 frame
->metadata
.device_scale_factor
);
59 scoped_ptr
<CompositorFrame
> frame_copy(new CompositorFrame());
60 frame
->AssignTo(frame_copy
.get());
62 surface_id_
, frame_copy
.Pass(),
63 base::Bind(&SurfaceDisplayOutputSurface::SwapBuffersComplete
,
64 base::Unretained(this)));
66 client_
->DidSwapBuffers();
69 bool SurfaceDisplayOutputSurface::BindToClient(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::ForceReclaimResources() {
79 if (!surface_id_
.is_null()) {
80 scoped_ptr
<CompositorFrame
> empty_frame(new CompositorFrame());
81 empty_frame
->delegated_frame_data
.reset(new DelegatedFrameData
);
82 factory_
.SubmitFrame(surface_id_
, empty_frame
.Pass(),
83 SurfaceFactory::DrawCallback());
87 void SurfaceDisplayOutputSurface::ReturnResources(
88 const ReturnedResourceArray
& resources
) {
89 CompositorFrameAck ack
;
90 ack
.resources
= resources
;
92 client_
->ReclaimResources(&ack
);
95 void SurfaceDisplayOutputSurface::SwapBuffersComplete(SurfaceDrawStatus drawn
) {
96 if (client_
&& !display_client_
->output_surface_lost())
97 client_
->DidSwapBuffersComplete();