| 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" | |
| 11 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 14 #include "remoting/client/frame_consumer.h" | 13 #include "remoting/client/frame_consumer.h" |
| 15 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 14 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
| 16 | 15 |
| 17 namespace gfx { | 16 namespace remoting { |
| 18 class JavaBitmap; | |
| 19 } // namespace gfx | |
| 20 | 17 |
| 21 namespace webrtc { | |
| 22 class DesktopFrame; | |
| 23 } // namespace webrtc | |
| 24 | |
| 25 namespace remoting { | |
| 26 class ChromotingJniInstance; | |
| 27 class ChromotingJniRuntime; | 18 class ChromotingJniRuntime; |
| 28 class FrameProducer; | |
| 29 | 19 |
| 30 // FrameConsumer implementation that draws onto a JNI direct byte buffer. | 20 // FrameConsumer implementation that draws onto a JNI direct byte buffer. |
| 31 class JniFrameConsumer : public FrameConsumer { | 21 class JniFrameConsumer : public FrameConsumer { |
| 32 public: | 22 public: |
| 33 // The instance does not take ownership of |jni_runtime|. | 23 // Does not take ownership of |jni_runtime|. |
| 34 explicit JniFrameConsumer(ChromotingJniRuntime* jni_runtime, | 24 explicit JniFrameConsumer(ChromotingJniRuntime* jni_runtime); |
| 35 scoped_refptr<ChromotingJniInstance> jni_instance); | |
| 36 | 25 |
| 37 ~JniFrameConsumer() override; | 26 ~JniFrameConsumer() override; |
| 38 | 27 |
| 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. | 28 // FrameConsumer implementation. |
| 43 void ApplyBuffer(const webrtc::DesktopSize& view_size, | 29 scoped_ptr<webrtc::DesktopFrame> AllocateFrame( |
| 44 const webrtc::DesktopRect& clip_area, | 30 const webrtc::DesktopSize& size) override; |
| 45 webrtc::DesktopFrame* buffer, | 31 void DrawFrame(scoped_ptr<webrtc::DesktopFrame> frame, |
| 46 const webrtc::DesktopRegion& region, | 32 const base::Closure& done) override; |
| 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; | 33 PixelFormat GetPixelFormat() override; |
| 52 | 34 |
| 53 private: | 35 private: |
| 54 // Allocates a new buffer of |source_size|, informs Java about it, and tells | 36 class Renderer; |
| 55 // the producer to draw onto it. | |
| 56 void AllocateBuffer(const webrtc::DesktopSize& source_size); | |
| 57 | 37 |
| 58 // Frees a frame buffer previously allocated by AllocateBuffer. | 38 void OnFrameRendered(const base::Closure& done); |
| 59 void FreeBuffer(webrtc::DesktopFrame* buffer); | |
| 60 | |
| 61 // Variables are to be used from the display thread. | |
| 62 | 39 |
| 63 // Used to obtain task runner references and make calls to Java methods. | 40 // Used to obtain task runner references and make calls to Java methods. |
| 64 ChromotingJniRuntime* jni_runtime_; | 41 ChromotingJniRuntime* jni_runtime_; |
| 65 | 42 |
| 66 // Used to record statistics. | 43 // Renderer object used to render the frames on the display thread. |
| 67 scoped_refptr<ChromotingJniInstance> jni_instance_; | 44 scoped_ptr<Renderer> renderer_; |
| 68 | 45 |
| 69 FrameProducer* frame_producer_; | 46 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 | 47 |
| 85 DISALLOW_COPY_AND_ASSIGN(JniFrameConsumer); | 48 DISALLOW_COPY_AND_ASSIGN(JniFrameConsumer); |
| 86 }; | 49 }; |
| 87 | 50 |
| 88 } // namespace remoting | 51 } // namespace remoting |
| 89 | 52 |
| 90 #endif | 53 #endif |
| OLD | NEW |