OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "remoting/client/jni/frame_consumer_impl.h" |
| 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/logging.h" |
| 9 #include "media/base/yuv_convert.h" |
| 10 #include "remoting/client/frame_producer.h" |
| 11 #include "remoting/client/jni/chromoting_jni.h" |
| 12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 class DirectDesktopFrame : public webrtc::BasicDesktopFrame { |
| 17 public: |
| 18 DirectDesktopFrame(int width, int height); |
| 19 |
| 20 jobject buffer() const { |
| 21 return buffer_; |
| 22 } |
| 23 |
| 24 private: |
| 25 jobject buffer_; |
| 26 }; |
| 27 |
| 28 DirectDesktopFrame::DirectDesktopFrame(int width, int height) |
| 29 : webrtc::BasicDesktopFrame(webrtc::DesktopSize(width, height)) { |
| 30 JNIEnv* env = base::android::AttachCurrentThread(); |
| 31 buffer_ = env->NewDirectByteBuffer(data(), stride()*height); |
| 32 } |
| 33 |
| 34 } // namespace |
| 35 |
| 36 namespace remoting { |
| 37 |
| 38 FrameConsumerImpl::FrameConsumerImpl() |
| 39 : frame_producer_(NULL), |
| 40 buffer_(NULL) { |
| 41 media::InitializeCPUSpecificYUVConversions(); |
| 42 } |
| 43 |
| 44 FrameConsumerImpl::~FrameConsumerImpl() { |
| 45 ReturnBuffer(buffer_); |
| 46 } |
| 47 |
| 48 void FrameConsumerImpl::set_frame_producer(FrameProducer* producer) { |
| 49 frame_producer_ = producer; |
| 50 } |
| 51 |
| 52 void FrameConsumerImpl::ApplyBuffer(const SkISize& view_size, |
| 53 const SkIRect& clip_area, |
| 54 webrtc::DesktopFrame* buffer, |
| 55 const SkRegion& region) { |
| 56 ChromotingJni::GetInstance()->RedrawCanvas(); |
| 57 // Give |frame_producer_| back the same buffer so that |buffer| and |buffer_| |
| 58 // are always the same exact pointer. |
| 59 frame_producer_->DrawBuffer(buffer); |
| 60 } |
| 61 |
| 62 void FrameConsumerImpl::ReturnBuffer(webrtc::DesktopFrame* buffer) { |
| 63 delete buffer; |
| 64 // |buffer_| is the same pointer as |buffer|, so we just invalidated it. |
| 65 buffer_ = NULL; |
| 66 } |
| 67 |
| 68 void FrameConsumerImpl::SetSourceSize(const SkISize& source_size, |
| 69 const SkIPoint& dpi) { |
| 70 view_size_ = source_size; |
| 71 clip_area_ = SkIRect::MakeSize(source_size); |
| 72 frame_producer_->SetOutputSizeAndClip(view_size_, clip_area_); |
| 73 |
| 74 if (!buffer_) |
| 75 buffer_ = new DirectDesktopFrame(source_size.width(), |
| 76 source_size.height()); |
| 77 |
| 78 ChromotingJni::GetInstance()->UpdateImageBuffer( |
| 79 source_size.width(), |
| 80 source_size.height(), |
| 81 static_cast<DirectDesktopFrame*>(buffer_)->buffer()); |
| 82 frame_producer_->DrawBuffer(buffer_); |
| 83 } |
| 84 |
| 85 } // namespace remoting |
OLD | NEW |