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> |
| 9 |
| 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" |
8 #include "remoting/client/frame_consumer.h" | 13 #include "remoting/client/frame_consumer.h" |
| 14 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
9 | 15 |
10 #include "base/compiler_specific.h" | 16 namespace gfx { |
11 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 17 class JavaBitmap; |
| 18 } // namespace gfx |
12 | 19 |
13 namespace webrtc { | 20 namespace webrtc { |
14 class DesktopFrame; | 21 class DesktopFrame; |
15 } // namespace webrtc | 22 } // namespace webrtc |
16 | 23 |
17 namespace remoting { | 24 namespace remoting { |
18 class ChromotingJniRuntime; | 25 class ChromotingJniRuntime; |
19 class FrameProducer; | 26 class FrameProducer; |
20 | 27 |
21 // FrameConsumer implementation that draws onto a JNI direct byte buffer. | 28 // FrameConsumer implementation that draws onto a JNI direct byte buffer. |
(...skipping 11 matching lines...) Expand all Loading... |
33 virtual void ApplyBuffer(const webrtc::DesktopSize& view_size, | 40 virtual void ApplyBuffer(const webrtc::DesktopSize& view_size, |
34 const webrtc::DesktopRect& clip_area, | 41 const webrtc::DesktopRect& clip_area, |
35 webrtc::DesktopFrame* buffer, | 42 webrtc::DesktopFrame* buffer, |
36 const webrtc::DesktopRegion& region) OVERRIDE; | 43 const webrtc::DesktopRegion& region) OVERRIDE; |
37 virtual void ReturnBuffer(webrtc::DesktopFrame* buffer) OVERRIDE; | 44 virtual void ReturnBuffer(webrtc::DesktopFrame* buffer) OVERRIDE; |
38 virtual void SetSourceSize(const webrtc::DesktopSize& source_size, | 45 virtual void SetSourceSize(const webrtc::DesktopSize& source_size, |
39 const webrtc::DesktopVector& dpi) OVERRIDE; | 46 const webrtc::DesktopVector& dpi) OVERRIDE; |
40 virtual PixelFormat GetPixelFormat() OVERRIDE; | 47 virtual PixelFormat GetPixelFormat() OVERRIDE; |
41 | 48 |
42 private: | 49 private: |
| 50 // Allocates a new buffer of |view_size_|, informs Java about it, and tells |
| 51 // the producer to draw onto it. |
| 52 void AllocateBuffer(); |
| 53 |
| 54 // Frees a frame buffer previously allocated by AllocateBuffer. |
| 55 void FreeBuffer(webrtc::DesktopFrame* buffer); |
| 56 |
43 // Variables are to be used from the display thread. | 57 // Variables are to be used from the display thread. |
44 | 58 |
45 // Used to obtain task runner references and make calls to Java methods. | 59 // Used to obtain task runner references and make calls to Java methods. |
46 ChromotingJniRuntime* jni_runtime_; | 60 ChromotingJniRuntime* jni_runtime_; |
47 | 61 |
48 // Whether we're currently in the constructor, and should deallocate the | |
49 // buffer instead of passing it back to the producer. | |
50 bool in_dtor_; | |
51 | |
52 FrameProducer* frame_producer_; | 62 FrameProducer* frame_producer_; |
53 webrtc::DesktopSize view_size_; | 63 webrtc::DesktopSize view_size_; |
54 webrtc::DesktopRect clip_area_; | 64 webrtc::DesktopRect clip_area_; |
55 | 65 |
56 // If |provide_buffer_|, allocates a new buffer of |view_size_|, informs | 66 // List of allocated image buffers. |
57 // Java about it, and tells the producer to draw onto it. Otherwise, no-op. | 67 std::list<webrtc::DesktopFrame*> buffers_; |
58 void AllocateBuffer(); | 68 |
| 69 // This global reference is required, instead of a local reference, so it |
| 70 // remains valid for the lifetime of |bitmap_| - gfx::JavaBitmap does not |
| 71 // create its own global reference internally. And this global ref must be |
| 72 // destroyed (released) after |bitmap_| is destroyed. |
| 73 base::android::ScopedJavaGlobalRef<jobject> bitmap_global_ref_; |
| 74 |
| 75 // Reference to the frame bitmap that is passed to Java when the frame is |
| 76 // allocated. This provides easy access to the underlying pixels. |
| 77 scoped_ptr<gfx::JavaBitmap> bitmap_; |
59 | 78 |
60 DISALLOW_COPY_AND_ASSIGN(JniFrameConsumer); | 79 DISALLOW_COPY_AND_ASSIGN(JniFrameConsumer); |
61 }; | 80 }; |
62 | 81 |
63 } // namespace remoting | 82 } // namespace remoting |
64 | 83 |
65 #endif | 84 #endif |
OLD | NEW |