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

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, 10 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
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
14 namespace surfaces {
15 namespace {
16 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) {
17 callback.Run();
18 }
19 }
20
21 DisplayImpl::DisplayImpl(
22 cc::SurfaceManager* manager,
23 cc::SurfaceId cc_id,
24 Client* client,
25 mojo::ContextProviderPtr context_provider,
26 mojo::ViewportParameterListenerPtr viewport_parameter_listener,
27 mojo::ResourceReturnerPtr returner,
28 mojo::InterfaceRequest<mojo::Display> display_request)
29 : manager_(manager),
30 factory_(manager, this),
31 cc_id_(cc_id),
32 client_(client),
33 context_provider_(context_provider.Pass()),
34 returner_(returner.Pass()),
35 binding_(this, display_request.Pass()) {
36 context_provider_->Create(nullptr, base::Bind(&DisplayImpl::OnContextCreated,
37 base::Unretained(this)));
38 }
39
40 void DisplayImpl::OnContextCreated(mojo::CommandBufferPtr gles2_client) {
41 if (!display_) {
42 cc::RendererSettings settings;
43 display_.reset(new cc::Display(this, manager_, nullptr, nullptr, settings));
44 client_->SetDisplay(display_.get());
45 display_->Initialize(make_scoped_ptr(new mojo::DirectOutputSurface(
46 new mojo::ContextProviderMojo(gles2_client.PassMessagePipe()))));
47 }
48 factory_.Create(cc_id_);
49 display_->SetSurfaceId(cc_id_, 1.f);
50 if (pending_frame_)
51 Draw();
52 // parameter_listeners_.AddBinding(this, listener_request.Pass());
53 }
54
55 DisplayImpl::~DisplayImpl() {
56 client_->OnDisplayBeingDestroyed(display_.get());
57 }
58
59 void DisplayImpl::SubmitFrame(mojo::FramePtr frame,
60 const SubmitFrameCallback& callback) {
61 DCHECK(pending_callback_.is_null());
62 pending_frame_ = frame.Pass();
63 pending_callback_ = callback;
64 if (display_)
65 Draw();
66 }
67
68 void DisplayImpl::Draw() {
69 gfx::Size frame_size =
70 pending_frame_->passes[0]->output_rect.To<gfx::Rect>().size();
71 display_->Resize(frame_size);
72 factory_.SubmitFrame(cc_id_,
73 pending_frame_.To<scoped_ptr<cc::CompositorFrame>>(),
74 base::Bind(&CallCallback, pending_callback_));
75 client_->FrameSubmitted();
76 pending_callback_.reset();
77 }
78
79 void DisplayImpl::DisplayDamaged() {
80 }
81
82 void DisplayImpl::DidSwapBuffers() {
83 }
84
85 void DisplayImpl::DidSwapBuffersComplete() {
86 }
87
88 void DisplayImpl::CommitVSyncParameters(base::TimeTicks timebase,
89 base::TimeDelta interval) {
90 }
91
92 void DisplayImpl::OutputSurfaceLost() {
93 }
94
95 void DisplayImpl::SetMemoryPolicy(const cc::ManagedMemoryPolicy& policy) {
96 }
97
98 void DisplayImpl::OnVSyncParametersUpdated(int64_t timebase, int64_t interval) {
99 client_->OnVSyncParametersUpdated(
100 base::TimeTicks::FromInternalValue(timebase),
101 base::TimeDelta::FromInternalValue(interval));
102 }
103
104 void DisplayImpl::ReturnResources(const cc::ReturnedResourceArray& resources) {
105 if (resources.empty())
106 return;
107 DCHECK(returner_);
108
109 mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size());
110 for (size_t i = 0; i < resources.size(); ++i) {
111 ret[i] = mojo::ReturnedResource::From(resources[i]);
112 }
113 returner_->ReturnResources(ret.Pass());
114 }
115
116 } // namespace surfaces
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698