summaryrefslogtreecommitdiffstats
path: root/remoting/client/plugin/pepper_view_proxy.cc
blob: 3e4bb353b5c9ac1d14000436f5d092ca26ca4b9d (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Copyright (c) 2011 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 "remoting/client/plugin/pepper_view_proxy.h"

#include "base/message_loop.h"
#include "remoting/client/client_context.h"
#include "remoting/client/plugin/chromoting_instance.h"

namespace remoting {

PepperViewProxy::PepperViewProxy(ChromotingInstance* instance, PepperView* view,
                                 base::MessageLoopProxy* plugin_message_loop)
  : instance_(instance),
    view_(view),
    plugin_message_loop_(plugin_message_loop) {
}

PepperViewProxy::~PepperViewProxy() {
}

bool PepperViewProxy::Initialize() {
  // This method needs a return value so we can't post a task and process on
  // another thread so just return true since PepperView doesn't do anything
  // either.
  return true;
}

void PepperViewProxy::TearDown() {
  if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) {
    plugin_message_loop_->PostTask(
        FROM_HERE, NewRunnableMethod(this, &PepperViewProxy::TearDown));
    return;
  }

  if (view_)
    view_->TearDown();
}

void PepperViewProxy::Paint() {
  if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) {
    plugin_message_loop_->PostTask(
        FROM_HERE, NewRunnableMethod(this, &PepperViewProxy::Paint));
    return;
  }

  if (view_)
    view_->Paint();
}

void PepperViewProxy::SetSolidFill(uint32 color) {
  if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) {
    plugin_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
        this, &PepperViewProxy::SetSolidFill, color));
    return;
  }

  if (view_)
    view_->SetSolidFill(color);
}

void PepperViewProxy::UnsetSolidFill() {
  if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) {
    plugin_message_loop_->PostTask(
        FROM_HERE, NewRunnableMethod(this, &PepperViewProxy::UnsetSolidFill));
    return;
  }

  if (view_)
    view_->UnsetSolidFill();
}

void PepperViewProxy::SetConnectionState(ConnectionState state) {
  if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) {
    plugin_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
        this, &PepperViewProxy::SetConnectionState, state));
    return;
  }

  if (view_)
    view_->SetConnectionState(state);
}

void PepperViewProxy::UpdateLoginStatus(bool success, const std::string& info) {
  if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) {
    plugin_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
        this, &PepperViewProxy::UpdateLoginStatus, success, info));
    return;
  }

  if (view_)
    view_->UpdateLoginStatus(success, info);
}

double PepperViewProxy::GetHorizontalScaleRatio() const {
  // This method returns a value, so must run synchronously, so must be
  // called only on the pepper thread.
  DCHECK(plugin_message_loop_->BelongsToCurrentThread());

  if (view_)
    return view_->GetHorizontalScaleRatio();
  return 1.0;
}

double PepperViewProxy::GetVerticalScaleRatio() const {
  // This method returns a value, so must run synchronously, so must be
  // called only on the pepper thread.
  DCHECK(plugin_message_loop_->BelongsToCurrentThread());

  if (view_)
    return view_->GetVerticalScaleRatio();
  return 1.0;
}

void PepperViewProxy::AllocateFrame(
    media::VideoFrame::Format format,
    size_t width,
    size_t height,
    base::TimeDelta timestamp,
    base::TimeDelta duration,
    scoped_refptr<media::VideoFrame>* frame_out,
    Task* done) {
  if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) {
    plugin_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
        this, &PepperViewProxy::AllocateFrame, format, width,
        height, timestamp, duration, frame_out, done));
    return;
  }

  if (view_) {
    view_->AllocateFrame(format, width, height, timestamp, duration, frame_out,
                         done);
  }
}

void PepperViewProxy::ReleaseFrame(media::VideoFrame* frame) {
  if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) {
    plugin_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
        this, &PepperViewProxy::ReleaseFrame, make_scoped_refptr(frame)));
    return;
  }

  if (view_)
    view_->ReleaseFrame(frame);
}

void PepperViewProxy::OnPartialFrameOutput(media::VideoFrame* frame,
                                           UpdatedRects* rects,
                                           Task* done) {
  if (instance_ && !plugin_message_loop_->BelongsToCurrentThread()) {
    plugin_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
        this, &PepperViewProxy::OnPartialFrameOutput,
        make_scoped_refptr(frame), rects, done));
    return;
  }

  if (view_)
    view_->OnPartialFrameOutput(frame, rects, done);
}

void PepperViewProxy::Detach() {
  DCHECK(plugin_message_loop_->BelongsToCurrentThread());
  instance_ = NULL;
  view_ = NULL;
}

}  // namespace remoting