| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_CLIENT_JNI_JNI_FRAME_CONSUMER_H_ | 5 #ifndef REMOTING_CLIENT_JNI_JNI_FRAME_CONSUMER_H_ |
| 6 #define REMOTING_CLIENT_JNI_JNI_FRAME_CONSUMER_H_ | 6 #define REMOTING_CLIENT_JNI_JNI_FRAME_CONSUMER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 14 #include "remoting/client/frame_consumer.h" | 15 #include "remoting/client/frame_consumer.h" |
| 15 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 16 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
| 16 | 17 |
| 17 namespace gfx { | 18 namespace gfx { |
| 18 class JavaBitmap; | 19 class JavaBitmap; |
| 19 } // namespace gfx | 20 } // namespace gfx |
| 20 | 21 |
| 21 namespace webrtc { | |
| 22 class DesktopFrame; | |
| 23 } // namespace webrtc | |
| 24 | |
| 25 namespace remoting { | 22 namespace remoting { |
| 26 class ChromotingJniInstance; | 23 class ChromotingJniInstance; |
| 27 class ChromotingJniRuntime; | 24 class ChromotingJniRuntime; |
| 28 class FrameProducer; | 25 class FrameProducer; |
| 29 | 26 |
| 30 // FrameConsumer implementation that draws onto a JNI direct byte buffer. | 27 // FrameConsumer implementation that draws onto a JNI direct byte buffer. |
| 31 class JniFrameConsumer : public FrameConsumer { | 28 class JniFrameConsumer : public FrameConsumer { |
| 32 public: | 29 public: |
| 33 // The instance does not take ownership of |jni_runtime|. | 30 // The instance does not take ownership of |jni_runtime|. |
| 34 explicit JniFrameConsumer(ChromotingJniRuntime* jni_runtime, | 31 explicit JniFrameConsumer(ChromotingJniRuntime* jni_runtime, |
| 35 scoped_refptr<ChromotingJniInstance> jni_instance); | 32 scoped_refptr<ChromotingJniInstance> jni_instance); |
| 36 | 33 |
| 37 ~JniFrameConsumer() override; | 34 ~JniFrameConsumer() override; |
| 38 | 35 |
| 39 // This must be called once before the producer's source size is set. | |
| 40 void set_frame_producer(FrameProducer* producer); | |
| 41 | |
| 42 // FrameConsumer implementation. | 36 // FrameConsumer implementation. |
| 43 void ApplyBuffer(const webrtc::DesktopSize& view_size, | 37 scoped_ptr<webrtc::DesktopFrame> AllocateFrame( |
| 44 const webrtc::DesktopRect& clip_area, | 38 const webrtc::DesktopSize& size) override; |
| 45 webrtc::DesktopFrame* buffer, | 39 void DrawFrame(scoped_ptr<webrtc::DesktopFrame> frame) override; |
| 46 const webrtc::DesktopRegion& region, | |
| 47 const webrtc::DesktopRegion* shape) override; | |
| 48 void ReturnBuffer(webrtc::DesktopFrame* buffer) override; | |
| 49 void SetSourceSize(const webrtc::DesktopSize& source_size, | |
| 50 const webrtc::DesktopVector& dpi) override; | |
| 51 PixelFormat GetPixelFormat() override; | 40 PixelFormat GetPixelFormat() override; |
| 52 | 41 |
| 53 private: | 42 private: |
| 54 // Allocates a new buffer of |source_size|, informs Java about it, and tells | 43 class Renderer; |
| 55 // the producer to draw onto it. | |
| 56 void AllocateBuffer(const webrtc::DesktopSize& source_size); | |
| 57 | 44 |
| 58 // Frees a frame buffer previously allocated by AllocateBuffer. | 45 void OnFrameRendered(const base::Closure& done); |
| 59 void FreeBuffer(webrtc::DesktopFrame* buffer); | |
| 60 | |
| 61 // Variables are to be used from the display thread. | |
| 62 | 46 |
| 63 // Used to obtain task runner references and make calls to Java methods. | 47 // Used to obtain task runner references and make calls to Java methods. |
| 64 ChromotingJniRuntime* jni_runtime_; | 48 ChromotingJniRuntime* jni_runtime_; |
| 65 | 49 |
| 66 // Used to record statistics. | 50 // Renderer object used to render the frames on the display thread. |
| 67 scoped_refptr<ChromotingJniInstance> jni_instance_; | 51 scoped_ptr<Renderer> renderer_; |
| 68 | 52 |
| 69 FrameProducer* frame_producer_; | 53 base::WeakPtrFactory<JniFrameConsumer> weak_factory_; |
| 70 webrtc::DesktopRect clip_area_; | |
| 71 | |
| 72 // List of allocated image buffers. | |
| 73 std::list<webrtc::DesktopFrame*> buffers_; | |
| 74 | |
| 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_; | |
| 80 | |
| 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_; | |
| 84 | 54 |
| 85 DISALLOW_COPY_AND_ASSIGN(JniFrameConsumer); | 55 DISALLOW_COPY_AND_ASSIGN(JniFrameConsumer); |
| 86 }; | 56 }; |
| 87 | 57 |
| 88 } // namespace remoting | 58 } // namespace remoting |
| 89 | 59 |
| 90 #endif | 60 #endif |
| OLD | NEW |