summaryrefslogtreecommitdiffstats
path: root/components/mus/public/cpp/lib/window_surface.cc
blob: 746d31c0140fde424ff67f56a7cd00c8efdc3583 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 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/window_surface.h"

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

namespace mus {

// static
scoped_ptr<WindowSurface> WindowSurface::Create(
    scoped_ptr<WindowSurfaceBinding>* surface_binding) {
  mojom::SurfacePtr surface;
  mojom::SurfaceClientPtr surface_client;
  mojo::InterfaceRequest<mojom::SurfaceClient> surface_client_request =
      GetProxy(&surface_client);

  surface_binding->reset(new WindowSurfaceBinding(
      GetProxy(&surface), surface_client.PassInterface()));
  return make_scoped_ptr(new WindowSurface(surface.PassInterface(),
                                           std::move(surface_client_request)));
}

WindowSurface::~WindowSurface() {}

void WindowSurface::BindToThread() {
  DCHECK(!thread_checker_);
  thread_checker_.reset(new base::ThreadChecker());
  surface_.Bind(std::move(surface_info_));
  client_binding_.reset(new mojo::Binding<mojom::SurfaceClient>(
      this, std::move(client_request_)));
}

void WindowSurface::SubmitCompositorFrame(mojom::CompositorFramePtr frame,
                                          const mojo::Closure& callback) {
  DCHECK(thread_checker_);
  DCHECK(thread_checker_->CalledOnValidThread());
  if (!surface_)
    return;
  surface_->SubmitCompositorFrame(std::move(frame), callback);
}

WindowSurface::WindowSurface(
    mojo::InterfacePtrInfo<mojom::Surface> surface_info,
    mojo::InterfaceRequest<mojom::SurfaceClient> client_request)
    : client_(nullptr),
      surface_info_(std::move(surface_info)),
      client_request_(std::move(client_request)) {}

void WindowSurface::ReturnResources(
    mojo::Array<mojom::ReturnedResourcePtr> resources) {
  DCHECK(thread_checker_);
  DCHECK(thread_checker_->CalledOnValidThread());
  if (!client_)
    return;
  client_->OnResourcesReturned(this, std::move(resources));
}

WindowSurfaceBinding::~WindowSurfaceBinding() {}

WindowSurfaceBinding::WindowSurfaceBinding(
    mojo::InterfaceRequest<mojom::Surface> surface_request,
    mojo::InterfacePtrInfo<mojom::SurfaceClient> surface_client)
    : surface_request_(std::move(surface_request)),
      surface_client_(std::move(surface_client)) {}

}  // namespace mus