summaryrefslogtreecommitdiffstats
path: root/components/mus/public/cpp/lib/view_surface.cc
blob: bdd5c329b080f93f9a1a044cf8f98f683c2e5fc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/mus/public/cpp/view_surface.h"

#include "components/mus/public/cpp/view_surface_client.h"
#include "mojo/converters/surfaces/surfaces_type_converters.h"

namespace mojo {

ViewSurface::~ViewSurface() {}

void ViewSurface::BindToThread() {
  DCHECK(!bound_to_thread_);
  bound_to_thread_ = true;
  surface_.Bind(surface_info_.Pass());
  client_binding_.Bind(client_request_.Pass());
}

void ViewSurface::SubmitCompositorFrame(mojo::CompositorFramePtr frame) {
  DCHECK(bound_to_thread_);
  if (!surface_)
    return;
  surface_->SubmitCompositorFrame(frame.Pass(), mojo::Closure());
}

ViewSurface::ViewSurface(
    mojo::InterfacePtrInfo<mojo::Surface> surface_info,
    mojo::InterfaceRequest<mojo::SurfaceClient> client_request)
    : client_(nullptr),
      surface_info_(surface_info.Pass()),
      client_request_(client_request.Pass()),
      client_binding_(this),
      bound_to_thread_(false) {}

void ViewSurface::ReturnResources(
    mojo::Array<mojo::ReturnedResourcePtr> resources) {
  if (!client_)
    return;
  client_->OnResourcesReturned(this, resources.Pass());
}

}  // namespace mojo