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

Side by Side Diff: remoting/ios/display/gl_display_handler.mm

Issue 2879743002: [CRD iOS] Hook the touch input feedback (Closed)
Patch Set: Use the ui task poster Created 3 years, 7 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #if !defined(__has_feature) || !__has_feature(objc_arc) 5 #if !defined(__has_feature) || !__has_feature(objc_arc)
6 #error "This file requires ARC support." 6 #error "This file requires ARC support."
7 #endif 7 #endif
8 8
9 #include <array> 9 #include <array>
10 10
11 #import "remoting/ios/display/gl_display_handler.h" 11 #import "remoting/ios/display/gl_display_handler.h"
12 12
13 #import "base/mac/bind_objc_block.h" 13 #import "base/mac/bind_objc_block.h"
14 #import "remoting/client/display/sys_opengl.h" 14 #import "remoting/client/display/sys_opengl.h"
15 #import "remoting/ios/display/gl_demo_screen.h" 15 #import "remoting/ios/display/gl_demo_screen.h"
16 16
17 #include "base/bind.h" 17 #include "base/bind.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
21 #include "remoting/client/chromoting_client_runtime.h" 21 #include "remoting/client/chromoting_client_runtime.h"
22 #include "remoting/client/cursor_shape_stub_proxy.h" 22 #include "remoting/client/cursor_shape_stub_proxy.h"
23 #include "remoting/client/display/gl_canvas.h" 23 #include "remoting/client/display/gl_canvas.h"
24 #include "remoting/client/display/gl_renderer.h" 24 #include "remoting/client/display/gl_renderer.h"
25 #include "remoting/client/display/gl_renderer_delegate.h" 25 #include "remoting/client/display/gl_renderer_delegate.h"
26 #include "remoting/client/dual_buffer_frame_consumer.h" 26 #include "remoting/client/dual_buffer_frame_consumer.h"
27 #include "remoting/client/queued_task_poster.h" 27 #include "remoting/client/render_stub_proxy.h"
28 #include "remoting/client/software_video_renderer.h" 28 #include "remoting/client/software_video_renderer.h"
29 #include "remoting/client/view_matrix.h"
29 30
30 namespace remoting { 31 namespace remoting {
31 namespace GlDisplayHandler { 32 namespace GlDisplayHandler {
32 33
33 // The core that lives on the display thread. 34 // The core that lives on the display thread.
34 class Core : public protocol::CursorShapeStub, public GlRendererDelegate { 35 class Core : public protocol::CursorShapeStub,
36 public RenderStub,
37 public GlRendererDelegate {
35 public: 38 public:
36 Core(); 39 Core();
37 ~Core() override; 40 ~Core() override;
38 41
39 void Initialize(); 42 void Initialize();
40 43
41 void SetHandlerDelegate(id<GlDisplayHandlerDelegate> delegate); 44 void SetHandlerDelegate(id<GlDisplayHandlerDelegate> delegate);
42 45
43 // CursorShapeStub interface. 46 // CursorShapeStub interface.
44 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override; 47 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override;
45 48
46 // GlRendererDelegate interface. 49 // GlRendererDelegate interface.
47 bool CanRenderFrame() override; 50 bool CanRenderFrame() override;
48 void OnFrameRendered() override; 51 void OnFrameRendered() override;
49 void OnSizeChanged(int width, int height) override; 52 void OnSizeChanged(int width, int height) override;
50 53
51 void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame, 54 void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame,
52 const base::Closure& done); 55 const base::Closure& done);
53 void Stop(); 56 void Stop();
54 void SurfaceCreated(GLKView* view); 57 void SurfaceCreated(GLKView* view);
55 void SurfaceChanged(int width, int height); 58 void SurfaceChanged(int width, int height);
56 void SetTransformation(const remoting::ViewMatrix& matrix); 59
60 // RenderStub interface.
61 void SetTransformation(const remoting::ViewMatrix& matrix) override;
62 void SetCursorPosition(float x, float y) override;
63 void SetCursorVisibility(bool visible) override;
64 void StartInputFeedback(float x, float y, float diameter) override;
65
57 std::unique_ptr<protocol::FrameConsumer> GrabFrameConsumer(); 66 std::unique_ptr<protocol::FrameConsumer> GrabFrameConsumer();
58 EAGLContext* GetEAGLContext(); 67 EAGLContext* GetEAGLContext();
59 base::WeakPtr<Core> GetWeakPtr(); 68 base::WeakPtr<Core> GetWeakPtr();
60 69
61 private: 70 private:
62 remoting::ChromotingClientRuntime* runtime_; 71 remoting::ChromotingClientRuntime* runtime_;
63 72
64 // Will be std::move'd when GrabFrameConsumer() is called. 73 // Will be std::move'd when GrabFrameConsumer() is called.
65 std::unique_ptr<DualBufferFrameConsumer> owned_frame_consumer_; 74 std::unique_ptr<DualBufferFrameConsumer> owned_frame_consumer_;
66 base::WeakPtr<DualBufferFrameConsumer> frame_consumer_; 75 base::WeakPtr<DualBufferFrameConsumer> frame_consumer_;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 void Core::SurfaceChanged(int width, int height) { 197 void Core::SurfaceChanged(int width, int height) {
189 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); 198 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
190 renderer_->OnSurfaceChanged(width, height); 199 renderer_->OnSurfaceChanged(width, height);
191 } 200 }
192 201
193 void Core::SetTransformation(const remoting::ViewMatrix& matrix) { 202 void Core::SetTransformation(const remoting::ViewMatrix& matrix) {
194 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); 203 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
195 renderer_->OnPixelTransformationChanged(matrix.ToMatrixArray()); 204 renderer_->OnPixelTransformationChanged(matrix.ToMatrixArray());
196 } 205 }
197 206
207 void Core::SetCursorPosition(float x, float y) {
208 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
209 renderer_->OnCursorMoved(x, y);
210 }
211
212 void Core::SetCursorVisibility(bool visible) {
213 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
214 renderer_->OnCursorVisibilityChanged(visible);
215 }
216 void Core::StartInputFeedback(float x, float y, float diameter) {
217 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
218 renderer_->OnCursorInputFeedback(x, y, diameter);
219 }
220
198 EAGLContext* Core::GetEAGLContext() { 221 EAGLContext* Core::GetEAGLContext() {
199 return eagl_context_; 222 return eagl_context_;
200 } 223 }
201 224
202 base::WeakPtr<remoting::GlDisplayHandler::Core> Core::GetWeakPtr() { 225 base::WeakPtr<remoting::GlDisplayHandler::Core> Core::GetWeakPtr() {
203 return weak_ptr_; 226 return weak_ptr_;
204 } 227 }
205 228
206 } // namespace GlDisplayHandler 229 } // namespace GlDisplayHandler
207 } // namespace remoting 230 } // namespace remoting
208 231
209 @interface GlDisplayHandler () { 232 @interface GlDisplayHandler () {
210 std::unique_ptr<remoting::GlDisplayHandler::Core> _core; 233 std::unique_ptr<remoting::GlDisplayHandler::Core> _core;
211 remoting::ChromotingClientRuntime* _runtime; 234 remoting::ChromotingClientRuntime* _runtime;
212 std::unique_ptr<remoting::QueuedTaskPoster> _uiTaskPoster;
213 } 235 }
214 @end 236 @end
215 237
216 @implementation GlDisplayHandler 238 @implementation GlDisplayHandler
217 239
218 - (id)init { 240 - (id)init {
219 self = [super init]; 241 self = [super init];
220 if (self) { 242 if (self) {
221 _runtime = remoting::ChromotingClientRuntime::GetInstance(); 243 _runtime = remoting::ChromotingClientRuntime::GetInstance();
222 _core.reset(new remoting::GlDisplayHandler::Core()); 244 _core.reset(new remoting::GlDisplayHandler::Core());
223 _uiTaskPoster.reset(
224 new remoting::QueuedTaskPoster(_runtime->display_task_runner()));
225 } 245 }
226 return self; 246 return self;
227 } 247 }
228 248
229 - (void)dealloc { 249 - (void)dealloc {
230 _runtime->display_task_runner()->DeleteSoon(FROM_HERE, _core.release()); 250 _runtime->display_task_runner()->DeleteSoon(FROM_HERE, _core.release());
231 } 251 }
232 252
233 #pragma mark - Public 253 #pragma mark - Public
234 254
235 - (void)stop { 255 - (void)stop {
236 _runtime->display_task_runner()->PostTask( 256 _runtime->display_task_runner()->PostTask(
237 FROM_HERE, 257 FROM_HERE,
238 base::Bind(&remoting::GlDisplayHandler::Core::Stop, _core->GetWeakPtr())); 258 base::Bind(&remoting::GlDisplayHandler::Core::Stop, _core->GetWeakPtr()));
239 } 259 }
240 260
261 - (std::unique_ptr<remoting::RenderStub>)CreateRenderStub {
262 return base::MakeUnique<remoting::RenderStubProxy>(
263 _core->GetWeakPtr(), _runtime->display_task_runner());
264 }
265
241 - (std::unique_ptr<remoting::protocol::VideoRenderer>)CreateVideoRenderer { 266 - (std::unique_ptr<remoting::protocol::VideoRenderer>)CreateVideoRenderer {
242 return base::MakeUnique<remoting::SoftwareVideoRenderer>( 267 return base::MakeUnique<remoting::SoftwareVideoRenderer>(
243 _core->GrabFrameConsumer()); 268 _core->GrabFrameConsumer());
244 } 269 }
245 270
246 - (std::unique_ptr<remoting::protocol::CursorShapeStub>)CreateCursorShapeStub { 271 - (std::unique_ptr<remoting::protocol::CursorShapeStub>)CreateCursorShapeStub {
247 return base::MakeUnique<remoting::CursorShapeStubProxy>( 272 return base::MakeUnique<remoting::CursorShapeStubProxy>(
248 _core->GetWeakPtr(), _runtime->display_task_runner()); 273 _core->GetWeakPtr(), _runtime->display_task_runner());
249 } 274 }
250 275
251 - (EAGLContext*)GetEAGLContext { 276 - (EAGLContext*)GetEAGLContext {
252 return _core->GetEAGLContext(); 277 return _core->GetEAGLContext();
253 } 278 }
254 279
255 - (void)onSurfaceCreated:(GLKView*)view { 280 - (void)onSurfaceCreated:(GLKView*)view {
256 _runtime->display_task_runner()->PostTask( 281 _runtime->display_task_runner()->PostTask(
257 FROM_HERE, base::Bind(&remoting::GlDisplayHandler::Core::SurfaceCreated, 282 FROM_HERE, base::Bind(&remoting::GlDisplayHandler::Core::SurfaceCreated,
258 _core->GetWeakPtr(), view)); 283 _core->GetWeakPtr(), view));
259 } 284 }
260 285
261 - (void)onSurfaceChanged:(const CGRect&)frame { 286 - (void)onSurfaceChanged:(const CGRect&)frame {
262 _runtime->display_task_runner()->PostTask( 287 _runtime->display_task_runner()->PostTask(
263 FROM_HERE, 288 FROM_HERE,
264 base::Bind(&remoting::GlDisplayHandler::Core::SurfaceChanged, 289 base::Bind(&remoting::GlDisplayHandler::Core::SurfaceChanged,
265 _core->GetWeakPtr(), frame.size.width, frame.size.height)); 290 _core->GetWeakPtr(), frame.size.width, frame.size.height));
266 } 291 }
267 292
268 - (void)onPixelTransformationChanged:(const remoting::ViewMatrix&)matrix {
269 _uiTaskPoster->AddTask(
270 base::Bind(&remoting::GlDisplayHandler::Core::SetTransformation,
271 _core->GetWeakPtr(), matrix));
272 }
273
274 #pragma mark - Properties 293 #pragma mark - Properties
275 294
276 - (void)setDelegate:(id<GlDisplayHandlerDelegate>)delegate { 295 - (void)setDelegate:(id<GlDisplayHandlerDelegate>)delegate {
277 _runtime->display_task_runner()->PostTask( 296 _runtime->display_task_runner()->PostTask(
278 FROM_HERE, 297 FROM_HERE,
279 base::Bind(&remoting::GlDisplayHandler::Core::SetHandlerDelegate, 298 base::Bind(&remoting::GlDisplayHandler::Core::SetHandlerDelegate,
280 _core->GetWeakPtr(), delegate)); 299 _core->GetWeakPtr(), delegate));
281 } 300 }
282 301
283 - (id<GlDisplayHandlerDelegate>)delegate { 302 - (id<GlDisplayHandlerDelegate>)delegate {
284 // Implementation is still required for UNAVAILABLE_ATTRIBUTE. 303 // Implementation is still required for UNAVAILABLE_ATTRIBUTE.
285 NOTREACHED(); 304 NOTREACHED();
286 return nil; 305 return nil;
287 } 306 }
288 307
289 @end 308 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698