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

Side by Side Diff: mojo/services/surfaces/display_impl.cc

Issue 1049993002: Get mojo_shell building inside chromium checkout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit Created 5 years, 8 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 | « mojo/services/surfaces/display_impl.h ('k') | mojo/services/surfaces/surfaces_impl.h » ('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 "mojo/services/surfaces/display_impl.h"
6
7 #include "cc/output/compositor_frame.h"
8 #include "cc/surfaces/display.h"
9 #include "mojo/converters/geometry/geometry_type_converters.h"
10 #include "mojo/converters/surfaces/surfaces_type_converters.h"
11 #include "mojo/services/surfaces/context_provider_mojo.h"
12 #include "mojo/services/surfaces/surfaces_output_surface.h"
13 #include "mojo/services/surfaces/surfaces_scheduler.h"
14
15 namespace surfaces {
16 namespace {
17 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) {
18 callback.Run();
19 }
20 }
21
22 DisplayImpl::DisplayImpl(cc::SurfaceManager* manager,
23 cc::SurfaceId cc_id,
24 SurfacesScheduler* scheduler,
25 mojo::ContextProviderPtr context_provider,
26 mojo::ResourceReturnerPtr returner,
27 mojo::InterfaceRequest<mojo::Display> display_request)
28 : manager_(manager),
29 factory_(manager, this),
30 cc_id_(cc_id),
31 scheduler_(scheduler),
32 context_provider_(context_provider.Pass()),
33 returner_(returner.Pass()),
34 viewport_param_binding_(this),
35 display_binding_(this, display_request.Pass()) {
36 mojo::ViewportParameterListenerPtr viewport_parameter_listener;
37 viewport_param_binding_.Bind(GetProxy(&viewport_parameter_listener));
38 context_provider_->Create(
39 viewport_parameter_listener.Pass(),
40 base::Bind(&DisplayImpl::OnContextCreated, base::Unretained(this)));
41 }
42
43 void DisplayImpl::OnContextCreated(mojo::CommandBufferPtr gles2_client) {
44 DCHECK(!display_);
45
46 cc::RendererSettings settings;
47 display_.reset(new cc::Display(this, manager_, nullptr, nullptr, settings));
48 scheduler_->AddDisplay(display_.get());
49 display_->Initialize(make_scoped_ptr(new mojo::DirectOutputSurface(
50 new mojo::ContextProviderMojo(gles2_client.PassMessagePipe()))));
51
52 factory_.Create(cc_id_);
53 display_->SetSurfaceId(cc_id_, 1.f);
54 if (pending_frame_)
55 Draw();
56 }
57
58 DisplayImpl::~DisplayImpl() {
59 if (display_) {
60 factory_.Destroy(cc_id_);
61 scheduler_->RemoveDisplay(display_.get());
62 }
63 }
64
65 void DisplayImpl::SubmitFrame(mojo::FramePtr frame,
66 const SubmitFrameCallback& callback) {
67 DCHECK(pending_callback_.is_null());
68 pending_frame_ = frame.Pass();
69 pending_callback_ = callback;
70 if (display_)
71 Draw();
72 }
73
74 void DisplayImpl::Draw() {
75 gfx::Size frame_size =
76 pending_frame_->passes[0]->output_rect.To<gfx::Rect>().size();
77 display_->Resize(frame_size);
78 factory_.SubmitFrame(cc_id_,
79 pending_frame_.To<scoped_ptr<cc::CompositorFrame>>(),
80 base::Bind(&CallCallback, pending_callback_));
81 scheduler_->SetNeedsDraw();
82 pending_callback_.reset();
83 }
84
85 void DisplayImpl::DisplayDamaged() {
86 }
87
88 void DisplayImpl::DidSwapBuffers() {
89 }
90
91 void DisplayImpl::DidSwapBuffersComplete() {
92 }
93
94 void DisplayImpl::CommitVSyncParameters(base::TimeTicks timebase,
95 base::TimeDelta interval) {
96 }
97
98 void DisplayImpl::OutputSurfaceLost() {
99 // If our OutputSurface is lost we can't draw until we get a new one. For now,
100 // destroy the display and create a new one when our ContextProvider provides
101 // a new one.
102 // TODO: This is more violent than necessary - we could simply remove this
103 // display from the scheduler's set and pass a new context in to the
104 // OutputSurface. It should be able to reinitialize properly.
105 scheduler_->RemoveDisplay(display_.get());
106 display_.reset();
107 factory_.Destroy(cc_id_);
108 viewport_param_binding_.Close();
109 mojo::ViewportParameterListenerPtr viewport_parameter_listener;
110 viewport_param_binding_.Bind(GetProxy(&viewport_parameter_listener));
111 context_provider_->Create(
112 viewport_parameter_listener.Pass(),
113 base::Bind(&DisplayImpl::OnContextCreated, base::Unretained(this)));
114 }
115
116 void DisplayImpl::SetMemoryPolicy(const cc::ManagedMemoryPolicy& policy) {
117 }
118
119 void DisplayImpl::OnVSyncParametersUpdated(int64_t timebase, int64_t interval) {
120 scheduler_->OnVSyncParametersUpdated(
121 base::TimeTicks::FromInternalValue(timebase),
122 base::TimeDelta::FromInternalValue(interval));
123 }
124
125 void DisplayImpl::ReturnResources(const cc::ReturnedResourceArray& resources) {
126 if (resources.empty())
127 return;
128 DCHECK(returner_);
129
130 mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size());
131 for (size_t i = 0; i < resources.size(); ++i) {
132 ret[i] = mojo::ReturnedResource::From(resources[i]);
133 }
134 returner_->ReturnResources(ret.Pass());
135 }
136
137 } // namespace surfaces
OLDNEW
« no previous file with comments | « mojo/services/surfaces/display_impl.h ('k') | mojo/services/surfaces/surfaces_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698