| Index: remoting/client/jni/frame_consumer_impl.cc
|
| diff --git a/remoting/client/jni/frame_consumer_impl.cc b/remoting/client/jni/frame_consumer_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..30c54bae680a4f8f200dcd7568a3ab53bfd3e5d5
|
| --- /dev/null
|
| +++ b/remoting/client/jni/frame_consumer_impl.cc
|
| @@ -0,0 +1,85 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "remoting/client/jni/frame_consumer_impl.h"
|
| +
|
| +#include "base/android/jni_android.h"
|
| +#include "base/logging.h"
|
| +#include "media/base/yuv_convert.h"
|
| +#include "remoting/client/frame_producer.h"
|
| +#include "remoting/client/jni/chromoting_jni.h"
|
| +#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
|
| +
|
| +namespace {
|
| +
|
| +class DirectDesktopFrame : public webrtc::BasicDesktopFrame {
|
| + public:
|
| + DirectDesktopFrame(int width, int height);
|
| +
|
| + jobject buffer() const {
|
| + return buffer_;
|
| + }
|
| +
|
| + private:
|
| + jobject buffer_;
|
| +};
|
| +
|
| +DirectDesktopFrame::DirectDesktopFrame(int width, int height)
|
| + : webrtc::BasicDesktopFrame(webrtc::DesktopSize(width, height)) {
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + buffer_ = env->NewDirectByteBuffer(data(), stride()*height);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +namespace remoting {
|
| +
|
| +FrameConsumerImpl::FrameConsumerImpl()
|
| + : frame_producer_(NULL),
|
| + buffer_(NULL) {
|
| + media::InitializeCPUSpecificYUVConversions();
|
| +}
|
| +
|
| +FrameConsumerImpl::~FrameConsumerImpl() {
|
| + ReturnBuffer(buffer_);
|
| +}
|
| +
|
| +void FrameConsumerImpl::set_frame_producer(FrameProducer* producer) {
|
| + frame_producer_ = producer;
|
| +}
|
| +
|
| +void FrameConsumerImpl::ApplyBuffer(const SkISize& view_size,
|
| + const SkIRect& clip_area,
|
| + webrtc::DesktopFrame* buffer,
|
| + const SkRegion& region) {
|
| + ChromotingJni::GetInstance()->RedrawCanvas();
|
| + // Give |frame_producer_| back the same buffer so that |buffer| and |buffer_|
|
| + // are always the same exact pointer.
|
| + frame_producer_->DrawBuffer(buffer);
|
| +}
|
| +
|
| +void FrameConsumerImpl::ReturnBuffer(webrtc::DesktopFrame* buffer) {
|
| + delete buffer;
|
| + // |buffer_| is the same pointer as |buffer|, so we just invalidated it.
|
| + buffer_ = NULL;
|
| +}
|
| +
|
| +void FrameConsumerImpl::SetSourceSize(const SkISize& source_size,
|
| + const SkIPoint& dpi) {
|
| + view_size_ = source_size;
|
| + clip_area_ = SkIRect::MakeSize(source_size);
|
| + frame_producer_->SetOutputSizeAndClip(view_size_, clip_area_);
|
| +
|
| + if (!buffer_)
|
| + buffer_ = new DirectDesktopFrame(source_size.width(),
|
| + source_size.height());
|
| +
|
| + ChromotingJni::GetInstance()->UpdateImageBuffer(
|
| + source_size.width(),
|
| + source_size.height(),
|
| + static_cast<DirectDesktopFrame*>(buffer_)->buffer());
|
| + frame_producer_->DrawBuffer(buffer_);
|
| +}
|
| +
|
| +} // namespace remoting
|
|
|