1 // Copyright 2015 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 "components/mus/surfaces/top_level_display_client.h"
7 #include "cc/output/compositor_frame.h"
8 #include "cc/surfaces/display.h"
9 #include "cc/surfaces/surface.h"
10 #include "components/mus/gles2/gpu_state.h"
11 #include "components/mus/surfaces/surfaces_context_provider.h"
12 #include "components/mus/surfaces/surfaces_output_surface.h"
13 #include "components/mus/surfaces/surfaces_scheduler.h"
14 #include "components/mus/surfaces/surfaces_state.h"
18 void CallCallback(const base::Closure
& callback
, cc::SurfaceDrawStatus status
) {
23 TopLevelDisplayClient::TopLevelDisplayClient(
24 gfx::AcceleratedWidget widget
,
25 const scoped_refptr
<GpuState
>& gpu_state
,
26 const scoped_refptr
<SurfacesState
>& surfaces_state
)
27 : surfaces_state_(surfaces_state
),
28 factory_(surfaces_state
->manager(), this),
29 cc_id_(static_cast<uint64_t>(surfaces_state
->next_id_namespace()) << 32) {
30 factory_
.Create(cc_id_
);
32 display_
.reset(new cc::Display(this, surfaces_state_
->manager(), nullptr,
33 nullptr, cc::RendererSettings()));
34 surfaces_state_
->scheduler()->AddDisplay(display_
.get());
36 // TODO(brianderson): Reconcile with SurfacesScheduler crbug.com/476676
37 cc::DisplayScheduler
* null_display_scheduler
= nullptr;
39 make_scoped_ptr(new DirectOutputSurface(
40 new SurfacesContextProvider(this, widget
, gpu_state
))),
41 null_display_scheduler
);
43 display_
->Resize(last_submitted_frame_size_
);
45 // TODO(fsamuel): Plumb the proper device scale factor.
46 display_
->SetSurfaceId(cc_id_
, 1.f
/* device_scale_factor */);
49 TopLevelDisplayClient::~TopLevelDisplayClient() {
50 factory_
.Destroy(cc_id_
);
51 surfaces_state_
->scheduler()->RemoveDisplay(display_
.get());
52 // By deleting the object after display_ is reset, OutputSurfaceLost can
53 // know not to do anything (which would result in double delete).
54 delete display_
.release();
57 void TopLevelDisplayClient::SubmitCompositorFrame(
58 scoped_ptr
<cc::CompositorFrame
> frame
,
59 const base::Closure
& callback
) {
60 pending_frame_
= frame
.Pass();
62 last_submitted_frame_size_
=
63 pending_frame_
->delegated_frame_data
->render_pass_list
.back()
65 display_
->Resize(last_submitted_frame_size_
);
66 factory_
.SubmitCompositorFrame(cc_id_
, pending_frame_
.Pass(),
67 base::Bind(&CallCallback
, callback
));
68 surfaces_state_
->scheduler()->SetNeedsDraw();
71 const cc::CompositorFrame
*
72 TopLevelDisplayClient::GetLastCompositorFrame() const {
73 cc::Surface
* surface
= surfaces_state_
->manager()->GetSurfaceForId(cc_id_
);
76 return surface
->GetEligibleFrame();
79 void TopLevelDisplayClient::CommitVSyncParameters(base::TimeTicks timebase
,
80 base::TimeDelta interval
) {}
82 void TopLevelDisplayClient::OutputSurfaceLost() {
83 if (!display_
) // Shutdown case
86 // If our OutputSurface is lost we can't draw until we get a new one. For now,
87 // destroy the display and create a new one when our ContextProvider provides
89 // TODO: This is more violent than necessary - we could simply remove this
90 // display from the scheduler's set and pass a new context in to the
91 // OutputSurface. It should be able to reinitialize properly.
92 surfaces_state_
->scheduler()->RemoveDisplay(display_
.get());
96 void TopLevelDisplayClient::SetMemoryPolicy(
97 const cc::ManagedMemoryPolicy
& policy
) {}
99 void TopLevelDisplayClient::OnVSyncParametersUpdated(int64_t timebase
,
101 surfaces_state_
->scheduler()->OnVSyncParametersUpdated(
102 base::TimeTicks::FromInternalValue(timebase
),
103 base::TimeDelta::FromInternalValue(interval
));
106 void TopLevelDisplayClient::ReturnResources(
107 const cc::ReturnedResourceArray
& resources
) {
108 // TODO(fsamuel): Implement this.