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_
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"
26 class ChromotingJniInstance
;
27 class ChromotingJniRuntime
;
30 // FrameConsumer implementation that draws onto a JNI direct byte buffer.
31 class JniFrameConsumer
: public FrameConsumer
{
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
;
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