summaryrefslogtreecommitdiffstats
path: root/remoting/client/jni/jni_frame_consumer.h
blob: 14155a15379d9c2f1d0cc2eeb31f92e6f4cd83cf (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
// Copyright 2013 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.

#ifndef REMOTING_CLIENT_JNI_JNI_FRAME_CONSUMER_H_
#define REMOTING_CLIENT_JNI_JNI_FRAME_CONSUMER_H_

#include "remoting/client/frame_consumer.h"

#include "base/compiler_specific.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"

namespace webrtc {
class DesktopFrame;
}  // namespace webrtc

namespace remoting {
class ChromotingJniRuntime;
class FrameProducer;

// FrameConsumer implementation that draws onto a JNI direct byte buffer.
class JniFrameConsumer : public FrameConsumer {
 public:
  // The instance does not take ownership of |jni_runtime|.
  explicit JniFrameConsumer(ChromotingJniRuntime* jni_runtime);

  virtual ~JniFrameConsumer();

  // This must be called once before the producer's source size is set.
  void set_frame_producer(FrameProducer* producer);

  // FrameConsumer implementation.
  virtual void ApplyBuffer(const webrtc::DesktopSize& view_size,
                           const webrtc::DesktopRect& clip_area,
                           webrtc::DesktopFrame* buffer,
                           const webrtc::DesktopRegion& region) OVERRIDE;
  virtual void ReturnBuffer(webrtc::DesktopFrame* buffer) OVERRIDE;
  virtual void SetSourceSize(const webrtc::DesktopSize& source_size,
                             const webrtc::DesktopVector& dpi) OVERRIDE;

 private:
  // Variables are to be used from the display thread.

  // Used to obtain task runner references and make calls to Java methods.
  ChromotingJniRuntime* jni_runtime_;

  // Whether we're currently in the constructor, and should deallocate the
  // buffer instead of passing it back to the producer.
  bool in_dtor_;

  FrameProducer* frame_producer_;
  webrtc::DesktopSize view_size_;
  webrtc::DesktopRect clip_area_;

  // If |provide_buffer_|, allocates a new buffer of |view_size_|, informs
  // Java about it, and tells the producer to draw onto it. Otherwise, no-op.
  void AllocateBuffer();

  DISALLOW_COPY_AND_ASSIGN(JniFrameConsumer);
};

}  // namespace remoting

#endif