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