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

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

Issue 940293003: Add a Display and ContextProvider concept to mojom, use to recreate (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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 | « services/surfaces/display_impl.h ('k') | 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 "services/surfaces/display_impl.h"
6
7 #include "cc/output/compositor_frame.h"
8 #include "cc/surfaces/display.h"
9 #include "mojo/cc/context_provider_mojo.h"
10 #include "mojo/cc/direct_output_surface.h"
11 #include "mojo/converters/geometry/geometry_type_converters.h"
12 #include "mojo/converters/surfaces/surfaces_type_converters.h"
13 #include "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 // TODO: Listen to lost context events and request a new one from
50 // |context_provider_|.
51 display_->Initialize(make_scoped_ptr(new mojo::DirectOutputSurface(
52 new mojo::ContextProviderMojo(gles2_client.PassMessagePipe()))));
53
54 factory_.Create(cc_id_);
55 display_->SetSurfaceId(cc_id_, 1.f);
56 if (pending_frame_)
57 Draw();
58 }
59
60 DisplayImpl::~DisplayImpl() {
61 if (display_) {
62 factory_.Destroy(cc_id_);
63 scheduler_->RemoveDisplay(display_.get());
64 }
65 }
66
67 void DisplayImpl::SubmitFrame(mojo::FramePtr frame,
68 const SubmitFrameCallback& callback) {
69 DCHECK(pending_callback_.is_null());
70 pending_frame_ = frame.Pass();
71 pending_callback_ = callback;
72 if (display_)
73 Draw();
74 }
75
76 void DisplayImpl::Draw() {
77 gfx::Size frame_size =
78 pending_frame_->passes[0]->output_rect.To<gfx::Rect>().size();
79 display_->Resize(frame_size);
80 factory_.SubmitFrame(cc_id_,
81 pending_frame_.To<scoped_ptr<cc::CompositorFrame>>(),
82 base::Bind(&CallCallback, pending_callback_));
83 scheduler_->SetNeedsDraw();
84 pending_callback_.reset();
85 }
86
87 void DisplayImpl::DisplayDamaged() {
88 }
89
90 void DisplayImpl::DidSwapBuffers() {
91 }
92
93 void DisplayImpl::DidSwapBuffersComplete() {
94 }
95
96 void DisplayImpl::CommitVSyncParameters(base::TimeTicks timebase,
97 base::TimeDelta interval) {
98 }
99
100 void DisplayImpl::OutputSurfaceLost() {
101 }
102
103 void DisplayImpl::SetMemoryPolicy(const cc::ManagedMemoryPolicy& policy) {
104 }
105
106 void DisplayImpl::OnVSyncParametersUpdated(int64_t timebase, int64_t interval) {
107 scheduler_->OnVSyncParametersUpdated(
108 base::TimeTicks::FromInternalValue(timebase),
109 base::TimeDelta::FromInternalValue(interval));
110 }
111
112 void DisplayImpl::ReturnResources(const cc::ReturnedResourceArray& resources) {
113 if (resources.empty())
114 return;
115 DCHECK(returner_);
116
117 mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size());
118 for (size_t i = 0; i < resources.size(); ++i) {
119 ret[i] = mojo::ReturnedResource::From(resources[i]);
120 }
121 returner_->ReturnResources(ret.Pass());
122 }
123
124 } // namespace surfaces
OLDNEW
« no previous file with comments | « services/surfaces/display_impl.h ('k') | services/surfaces/surfaces_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698