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 factory_(surface_manager
, this),
24 allocator_(allocator
) {
25 factory_
.set_needs_sync_points(false);
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;
30 // Display and SurfaceDisplayOutputSurface share a GL context, so sync
31 // points aren't needed when passing resources between them.
32 capabilities_
.delegated_sync_points_required
= false;
35 SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() {
37 if (!surface_id_
.is_null()) {
38 factory_
.Destroy(surface_id_
);
42 void SurfaceDisplayOutputSurface::ReceivedVSyncParameters(
43 base::TimeTicks timebase
,
44 base::TimeDelta interval
) {
45 CommitVSyncParameters(timebase
, interval
);
48 void SurfaceDisplayOutputSurface::SwapBuffers(CompositorFrame
* frame
) {
49 gfx::Size frame_size
=
50 frame
->delegated_frame_data
->render_pass_list
.back()->output_rect
.size();
51 if (frame_size
.IsEmpty() || frame_size
!= display_size_
) {
52 if (!surface_id_
.is_null()) {
53 factory_
.Destroy(surface_id_
);
55 surface_id_
= allocator_
->GenerateId();
56 factory_
.Create(surface_id_
);
57 display_size_
= frame_size
;
59 display_client_
->display()->SetSurfaceId(surface_id_
,
60 frame
->metadata
.device_scale_factor
);
62 client_
->DidSwapBuffers();
64 scoped_ptr
<CompositorFrame
> frame_copy(new CompositorFrame());
65 frame
->AssignTo(frame_copy
.get());
67 surface_id_
, frame_copy
.Pass(),
68 base::Bind(&SurfaceDisplayOutputSurface::SwapBuffersComplete
,
69 base::Unretained(this)));
72 bool SurfaceDisplayOutputSurface::BindToClient(OutputSurfaceClient
* client
) {
74 DCHECK(display_client_
);
76 // Avoid initializing GL context here, as this should be sharing the
78 return display_client_
->Initialize();
81 void SurfaceDisplayOutputSurface::ForceReclaimResources() {
82 if (!surface_id_
.is_null())
83 factory_
.SubmitFrame(surface_id_
, nullptr, SurfaceFactory::DrawCallback());
86 void SurfaceDisplayOutputSurface::ReturnResources(
87 const ReturnedResourceArray
& resources
) {
88 CompositorFrameAck ack
;
89 ack
.resources
= resources
;
91 client_
->ReclaimResources(&ack
);
94 void SurfaceDisplayOutputSurface::SwapBuffersComplete(SurfaceDrawStatus drawn
) {
95 if (client_
&& !display_client_
->output_surface_lost())
96 client_
->DidSwapBuffersComplete();