Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / components / view_manager / surfaces / top_level_display_client.cc
blob251a3ebd4954ddc202fc1d3676143ae8e7f0a98b
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/view_manager/surfaces/top_level_display_client.h"
7 #include "cc/output/compositor_frame.h"
8 #include "cc/surfaces/display.h"
9 #include "components/view_manager/gles2/gpu_state.h"
10 #include "components/view_manager/surfaces/surfaces_context_provider.h"
11 #include "components/view_manager/surfaces/surfaces_output_surface.h"
12 #include "components/view_manager/surfaces/surfaces_scheduler.h"
13 #include "components/view_manager/surfaces/surfaces_state.h"
15 namespace surfaces {
16 namespace {
17 void CallCallback(const base::Closure& callback, cc::SurfaceDrawStatus status) {
18 callback.Run();
22 TopLevelDisplayClient::TopLevelDisplayClient(
23 gfx::AcceleratedWidget widget,
24 const scoped_refptr<gles2::GpuState>& gpu_state,
25 const scoped_refptr<SurfacesState>& surfaces_state)
26 : gpu_state_(gpu_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;
38 display_->Initialize(
39 make_scoped_ptr(new surfaces::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 void TopLevelDisplayClient::OnContextCreated() {
52 TopLevelDisplayClient::~TopLevelDisplayClient() {
53 if (display_) {
54 factory_.Destroy(cc_id_);
55 surfaces_state_->scheduler()->RemoveDisplay(display_.get());
56 // By deleting the object after display_ is reset, OutputSurfaceLost can
57 // know not to do anything (which would result in double delete).
58 delete display_.release();
62 void TopLevelDisplayClient::SubmitFrame(scoped_ptr<cc::CompositorFrame> frame,
63 const base::Closure& callback) {
64 DCHECK(pending_callback_.is_null());
65 pending_frame_ = frame.Pass();
66 pending_callback_ = callback;
67 if (display_)
68 Draw();
71 void TopLevelDisplayClient::Draw() {
72 gfx::Size frame_size =
73 pending_frame_->delegated_frame_data->render_pass_list.back()->
74 output_rect.size();
75 last_submitted_frame_size_ = frame_size;
76 display_->Resize(frame_size);
77 factory_.SubmitFrame(cc_id_,
78 pending_frame_.Pass(),
79 base::Bind(&CallCallback, pending_callback_));
80 surfaces_state_->scheduler()->SetNeedsDraw();
81 pending_callback_.Reset();
84 void TopLevelDisplayClient::CommitVSyncParameters(base::TimeTicks timebase,
85 base::TimeDelta interval) {
88 void TopLevelDisplayClient::OutputSurfaceLost() {
89 if (!display_) // Shutdown case
90 return;
92 // If our OutputSurface is lost we can't draw until we get a new one. For now,
93 // destroy the display and create a new one when our ContextProvider provides
94 // a new one.
95 // TODO: This is more violent than necessary - we could simply remove this
96 // display from the scheduler's set and pass a new context in to the
97 // OutputSurface. It should be able to reinitialize properly.
98 surfaces_state_->scheduler()->RemoveDisplay(display_.get());
99 display_.reset();
102 void TopLevelDisplayClient::SetMemoryPolicy(
103 const cc::ManagedMemoryPolicy& policy) {
106 void TopLevelDisplayClient::OnVSyncParametersUpdated(int64_t timebase,
107 int64_t interval) {
108 surfaces_state_->scheduler()->OnVSyncParametersUpdated(
109 base::TimeTicks::FromInternalValue(timebase),
110 base::TimeDelta::FromInternalValue(interval));
113 void TopLevelDisplayClient::ReturnResources(
114 const cc::ReturnedResourceArray& resources) {
115 // TODO(fsamuel): Implement this.
118 } // namespace surfaces