Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / remoting / client / jni / jni_frame_consumer.h
blob3368a98ff9210e6486f5137a38f8a7c691fcd555
1 // Copyright 2013 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.
5 #ifndef REMOTING_CLIENT_JNI_JNI_FRAME_CONSUMER_H_
6 #define REMOTING_CLIENT_JNI_JNI_FRAME_CONSUMER_H_
8 #include <list>
10 #include "base/android/scoped_java_ref.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "remoting/client/frame_consumer.h"
15 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
17 namespace gfx {
18 class JavaBitmap;
19 } // namespace gfx
21 namespace webrtc {
22 class DesktopFrame;
23 } // namespace webrtc
25 namespace remoting {
26 class ChromotingJniInstance;
27 class ChromotingJniRuntime;
28 class FrameProducer;
30 // FrameConsumer implementation that draws onto a JNI direct byte buffer.
31 class JniFrameConsumer : public FrameConsumer {
32 public:
33 // The instance does not take ownership of |jni_runtime|.
34 explicit JniFrameConsumer(ChromotingJniRuntime* jni_runtime,
35 scoped_refptr<ChromotingJniInstance> jni_instance);
37 virtual ~JniFrameConsumer();
39 // This must be called once before the producer's source size is set.
40 void set_frame_producer(FrameProducer* producer);
42 // FrameConsumer implementation.
43 virtual void ApplyBuffer(const webrtc::DesktopSize& view_size,
44 const webrtc::DesktopRect& clip_area,
45 webrtc::DesktopFrame* buffer,
46 const webrtc::DesktopRegion& region,
47 const webrtc::DesktopRegion& shape) override;
48 virtual void ReturnBuffer(webrtc::DesktopFrame* buffer) override;
49 virtual void SetSourceSize(const webrtc::DesktopSize& source_size,
50 const webrtc::DesktopVector& dpi) override;
51 virtual PixelFormat GetPixelFormat() override;
53 private:
54 // Allocates a new buffer of |source_size|, informs Java about it, and tells
55 // the producer to draw onto it.
56 void AllocateBuffer(const webrtc::DesktopSize& source_size);
58 // Frees a frame buffer previously allocated by AllocateBuffer.
59 void FreeBuffer(webrtc::DesktopFrame* buffer);
61 // Variables are to be used from the display thread.
63 // Used to obtain task runner references and make calls to Java methods.
64 ChromotingJniRuntime* jni_runtime_;
66 // Used to record statistics.
67 scoped_refptr<ChromotingJniInstance> jni_instance_;
69 FrameProducer* frame_producer_;
70 webrtc::DesktopRect clip_area_;
72 // List of allocated image buffers.
73 std::list<webrtc::DesktopFrame*> buffers_;
75 // This global reference is required, instead of a local reference, so it
76 // remains valid for the lifetime of |bitmap_| - gfx::JavaBitmap does not
77 // create its own global reference internally. And this global ref must be
78 // destroyed (released) after |bitmap_| is destroyed.
79 base::android::ScopedJavaGlobalRef<jobject> bitmap_global_ref_;
81 // Reference to the frame bitmap that is passed to Java when the frame is
82 // allocated. This provides easy access to the underlying pixels.
83 scoped_ptr<gfx::JavaBitmap> bitmap_;
85 DISALLOW_COPY_AND_ASSIGN(JniFrameConsumer);
88 } // namespace remoting
90 #endif