Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: trunk/src/remoting/client/jni/jni_frame_consumer.cc

Issue 24217003: Revert 224101 "Remove dependency on Skia from chromoting client." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "remoting/client/jni/jni_frame_consumer.h" 5 #include "remoting/client/jni/jni_frame_consumer.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "remoting/client/frame_producer.h" 10 #include "remoting/client/frame_producer.h"
11 #include "remoting/client/jni/chromoting_jni_runtime.h" 11 #include "remoting/client/jni/chromoting_jni_runtime.h"
12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
13 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
14 13
15 namespace { 14 namespace {
16 15
17 // Allocates its buffer within a Java direct byte buffer, where it can be 16 // Allocates its buffer within a Java direct byte buffer, where it can be
18 // accessed by both native and managed code. 17 // accessed by both native and managed code.
19 class DirectDesktopFrame : public webrtc::BasicDesktopFrame { 18 class DirectDesktopFrame : public webrtc::BasicDesktopFrame {
20 public: 19 public:
21 DirectDesktopFrame(int width, int height); 20 DirectDesktopFrame(int width, int height);
22 21
23 virtual ~DirectDesktopFrame(); 22 virtual ~DirectDesktopFrame();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 base::WaitableEvent done_event(true, false); 55 base::WaitableEvent done_event(true, false);
57 frame_producer_->RequestReturnBuffers( 56 frame_producer_->RequestReturnBuffers(
58 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done_event))); 57 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done_event)));
59 done_event.Wait(); 58 done_event.Wait();
60 } 59 }
61 60
62 void JniFrameConsumer::set_frame_producer(FrameProducer* producer) { 61 void JniFrameConsumer::set_frame_producer(FrameProducer* producer) {
63 frame_producer_ = producer; 62 frame_producer_ = producer;
64 } 63 }
65 64
66 void JniFrameConsumer::ApplyBuffer(const webrtc::DesktopSize& view_size, 65 void JniFrameConsumer::ApplyBuffer(const SkISize& view_size,
67 const webrtc::DesktopRect& clip_area, 66 const SkIRect& clip_area,
68 webrtc::DesktopFrame* buffer, 67 webrtc::DesktopFrame* buffer,
69 const webrtc::DesktopRegion& region) { 68 const SkRegion& region) {
70 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread()); 69 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread());
71 70
72 scoped_ptr<webrtc::DesktopFrame> buffer_scoped(buffer); 71 scoped_ptr<webrtc::DesktopFrame> buffer_scoped(buffer);
73 jni_runtime_->RedrawCanvas(); 72 jni_runtime_->RedrawCanvas();
74 73
75 if (view_size.width() > view_size_.width() || 74 if (view_size.width() > view_size_.width() ||
76 view_size.height() > view_size_.height()) { 75 view_size.height() > view_size_.height()) {
77 LOG(INFO) << "Existing buffer is too small"; 76 LOG(INFO) << "Existing buffer is too small";
78 view_size_ = view_size; 77 view_size_ = view_size;
79 78
80 // Manually destroy the old buffer before allocating a new one to prevent 79 // Manually destroy the old buffer before allocating a new one to prevent
81 // our memory footprint from temporarily ballooning. 80 // our memory footprint from temporarily ballooning.
82 buffer_scoped.reset(); 81 buffer_scoped.reset();
83 AllocateBuffer(); 82 AllocateBuffer();
84 } 83 }
85 84
86 // Supply |frame_producer_| with a buffer to render the next frame into. 85 // Supply |frame_producer_| with a buffer to render the next frame into.
87 if (!in_dtor_) 86 if (!in_dtor_)
88 frame_producer_->DrawBuffer(buffer_scoped.release()); 87 frame_producer_->DrawBuffer(buffer_scoped.release());
89 } 88 }
90 89
91 void JniFrameConsumer::ReturnBuffer(webrtc::DesktopFrame* buffer) { 90 void JniFrameConsumer::ReturnBuffer(webrtc::DesktopFrame* buffer) {
92 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread()); 91 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread());
93 LOG(INFO) << "Returning image buffer"; 92 LOG(INFO) << "Returning image buffer";
94 delete buffer; 93 delete buffer;
95 } 94 }
96 95
97 void JniFrameConsumer::SetSourceSize(const webrtc::DesktopSize& source_size, 96 void JniFrameConsumer::SetSourceSize(const SkISize& source_size,
98 const webrtc::DesktopVector& dpi) { 97 const SkIPoint& dpi) {
99 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread()); 98 DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread());
100 99
101 // We currently render the desktop 1:1 and perform pan/zoom scaling 100 // We currently render the desktop 1:1 and perform pan/zoom scaling
102 // and cropping on the managed canvas. 101 // and cropping on the managed canvas.
103 view_size_ = source_size; 102 view_size_ = source_size;
104 clip_area_ = webrtc::DesktopRect::MakeSize(view_size_); 103 clip_area_ = SkIRect::MakeSize(view_size_);
105 frame_producer_->SetOutputSizeAndClip(view_size_, clip_area_); 104 frame_producer_->SetOutputSizeAndClip(view_size_, clip_area_);
106 105
107 // Unless being destructed, allocate buffer and start drawing frames onto it. 106 // Unless being destructed, allocate buffer and start drawing frames onto it.
108 frame_producer_->RequestReturnBuffers(base::Bind( 107 frame_producer_->RequestReturnBuffers(base::Bind(
109 &JniFrameConsumer::AllocateBuffer, base::Unretained(this))); 108 &JniFrameConsumer::AllocateBuffer, base::Unretained(this)));
110 } 109 }
111 110
112 void JniFrameConsumer::AllocateBuffer() { 111 void JniFrameConsumer::AllocateBuffer() {
113 // Only do anything if we're not being destructed. 112 // Only do anything if we're not being destructed.
114 if (!in_dtor_) { 113 if (!in_dtor_) {
115 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { 114 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) {
116 jni_runtime_->display_task_runner()->PostTask(FROM_HERE, 115 jni_runtime_->display_task_runner()->PostTask(FROM_HERE,
117 base::Bind(&JniFrameConsumer::AllocateBuffer, 116 base::Bind(&JniFrameConsumer::AllocateBuffer,
118 base::Unretained(this))); 117 base::Unretained(this)));
119 return; 118 return;
120 } 119 }
121 120
122 DirectDesktopFrame* buffer = new DirectDesktopFrame(view_size_.width(), 121 DirectDesktopFrame* buffer = new DirectDesktopFrame(view_size_.width(),
123 view_size_.height()); 122 view_size_.height());
124 123
125 // Update Java's reference to the buffer and record of its dimensions. 124 // Update Java's reference to the buffer and record of its dimensions.
126 jni_runtime_->UpdateImageBuffer(view_size_.width(), 125 jni_runtime_->UpdateImageBuffer(view_size_.width(),
127 view_size_.height(), 126 view_size_.height(),
128 buffer->buffer()); 127 buffer->buffer());
129 128
130 frame_producer_->DrawBuffer(buffer); 129 frame_producer_->DrawBuffer(buffer);
131 } 130 }
132 } 131 }
133 132
134 } // namespace remoting 133 } // namespace remoting
OLDNEW
« no previous file with comments | « trunk/src/remoting/client/jni/jni_frame_consumer.h ('k') | trunk/src/remoting/client/plugin/chromoting_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698