Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: components/surfaces/display_impl.cc

Issue 1150093003: Move GLES2, GPU & Surfaces into the ViewManager directory. This does not merge the applications, th… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/surfaces/display_impl.h ('k') | components/surfaces/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "components/surfaces/display_impl.h"
6
7 #include "cc/output/compositor_frame.h"
8 #include "cc/surfaces/display.h"
9 #include "components/surfaces/surfaces_context_provider.h"
10 #include "components/surfaces/surfaces_output_surface.h"
11 #include "components/surfaces/surfaces_scheduler.h"
12 #include "components/surfaces/surfaces_service_application.h"
13 #include "mojo/converters/geometry/geometry_type_converters.h"
14 #include "mojo/converters/surfaces/surfaces_type_converters.h"
15
16 namespace surfaces {
17 namespace {
18 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) {
19 callback.Run();
20 }
21 }
22
23 DisplayImpl::DisplayImpl(SurfacesServiceApplication* application,
24 cc::SurfaceManager* manager,
25 cc::SurfaceId cc_id,
26 SurfacesScheduler* scheduler,
27 mojo::ContextProviderPtr context_provider,
28 mojo::ResourceReturnerPtr returner,
29 mojo::InterfaceRequest<mojo::Display> display_request)
30 : application_(application),
31 manager_(manager),
32 factory_(manager, this),
33 cc_id_(cc_id),
34 scheduler_(scheduler),
35 context_provider_(context_provider.Pass()),
36 returner_(returner.Pass()),
37 viewport_param_binding_(this),
38 display_binding_(this, display_request.Pass()) {
39 application_->DisplayCreated(this);
40 mojo::ViewportParameterListenerPtr viewport_parameter_listener;
41 viewport_param_binding_.Bind(GetProxy(&viewport_parameter_listener));
42 context_provider_->Create(
43 viewport_parameter_listener.Pass(),
44 base::Bind(&DisplayImpl::OnContextCreated, base::Unretained(this)));
45 factory_.Create(cc_id_);
46 }
47
48 void DisplayImpl::OnContextCreated(mojo::CommandBufferPtr gles2_client) {
49 DCHECK(!display_);
50
51 cc::RendererSettings settings;
52 display_.reset(new cc::Display(this, manager_, nullptr, nullptr, settings));
53 scheduler_->AddDisplay(display_.get());
54 display_->Initialize(make_scoped_ptr(
55 new surfaces::DirectOutputSurface(new surfaces::SurfacesContextProvider(
56 gles2_client.PassInterface().PassHandle()))));
57 display_->Resize(last_submitted_frame_size_);
58
59 display_->SetSurfaceId(cc_id_, 1.f);
60 if (pending_frame_)
61 Draw();
62 }
63
64 DisplayImpl::~DisplayImpl() {
65 if (display_) {
66 factory_.Destroy(cc_id_);
67 scheduler_->RemoveDisplay(display_.get());
68 // By deleting the object after display_ is reset, OutputSurfaceLost can
69 // know not to do anything (which would result in double delete).
70 delete display_.release();
71 }
72 application_->DisplayDestroyed(this);
73 }
74
75 void DisplayImpl::SubmitFrame(mojo::FramePtr frame,
76 const SubmitFrameCallback& callback) {
77 DCHECK(pending_callback_.is_null());
78 pending_frame_ = frame.Pass();
79 pending_callback_ = callback;
80 if (display_)
81 Draw();
82 }
83
84 void DisplayImpl::Draw() {
85 gfx::Size frame_size =
86 pending_frame_->passes[0]->output_rect.To<gfx::Rect>().size();
87 last_submitted_frame_size_ = frame_size;
88 display_->Resize(frame_size);
89 factory_.SubmitFrame(cc_id_,
90 pending_frame_.To<scoped_ptr<cc::CompositorFrame>>(),
91 base::Bind(&CallCallback, pending_callback_));
92 pending_frame_.reset();
93 scheduler_->SetNeedsDraw();
94 pending_callback_.reset();
95 }
96
97 void DisplayImpl::DisplayDamaged() {
98 }
99
100 void DisplayImpl::DidSwapBuffers() {
101 }
102
103 void DisplayImpl::DidSwapBuffersComplete() {
104 }
105
106 void DisplayImpl::CommitVSyncParameters(base::TimeTicks timebase,
107 base::TimeDelta interval) {
108 }
109
110 void DisplayImpl::OutputSurfaceLost() {
111 if (!display_) // Shutdown case
112 return;
113
114 // If our OutputSurface is lost we can't draw until we get a new one. For now,
115 // destroy the display and create a new one when our ContextProvider provides
116 // a new one.
117 // TODO: This is more violent than necessary - we could simply remove this
118 // display from the scheduler's set and pass a new context in to the
119 // OutputSurface. It should be able to reinitialize properly.
120 scheduler_->RemoveDisplay(display_.get());
121 display_.reset();
122 viewport_param_binding_.Close();
123 mojo::ViewportParameterListenerPtr viewport_parameter_listener;
124 viewport_param_binding_.Bind(GetProxy(&viewport_parameter_listener));
125 context_provider_->Create(
126 viewport_parameter_listener.Pass(),
127 base::Bind(&DisplayImpl::OnContextCreated, base::Unretained(this)));
128 }
129
130 void DisplayImpl::SetMemoryPolicy(const cc::ManagedMemoryPolicy& policy) {
131 }
132
133 void DisplayImpl::OnVSyncParametersUpdated(int64_t timebase, int64_t interval) {
134 scheduler_->OnVSyncParametersUpdated(
135 base::TimeTicks::FromInternalValue(timebase),
136 base::TimeDelta::FromInternalValue(interval));
137 }
138
139 void DisplayImpl::ReturnResources(const cc::ReturnedResourceArray& resources) {
140 if (resources.empty())
141 return;
142 DCHECK(returner_);
143
144 mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size());
145 for (size_t i = 0; i < resources.size(); ++i) {
146 ret[i] = mojo::ReturnedResource::From(resources[i]);
147 }
148 returner_->ReturnResources(ret.Pass());
149 }
150
151 } // namespace surfaces
OLDNEW
« no previous file with comments | « components/surfaces/display_impl.h ('k') | components/surfaces/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698