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

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

Issue 2825403004: Integrating with new rendering for CRD iOS. (Closed)
Patch Set: Adding remoting service changes to this CL, they are dependent. Created 3 years, 8 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>
10
9 #import "remoting/client/ios/display/gl_display_handler.h" 11 #import "remoting/client/ios/display/gl_display_handler.h"
10 12
13 #import "base/mac/bind_objc_block.h"
11 #import "remoting/client/display/sys_opengl.h" 14 #import "remoting/client/display/sys_opengl.h"
12 #import "remoting/client/ios/display/gl_demo_screen.h" 15 #import "remoting/client/ios/display/gl_demo_screen.h"
13 16
14 #include "base/bind.h" 17 #include "base/bind.h"
15 #include "base/macros.h" 18 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
17 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
18 #include "remoting/client/chromoting_client.h"
19 #include "remoting/client/chromoting_client_runtime.h" 21 #include "remoting/client/chromoting_client_runtime.h"
20 #include "remoting/client/cursor_shape_stub_proxy.h" 22 #include "remoting/client/cursor_shape_stub_proxy.h"
21 #include "remoting/client/display/gl_canvas.h" 23 #include "remoting/client/display/gl_canvas.h"
22 #include "remoting/client/display/gl_renderer.h" 24 #include "remoting/client/display/gl_renderer.h"
23 #include "remoting/client/display/gl_renderer_delegate.h" 25 #include "remoting/client/display/gl_renderer_delegate.h"
24 #include "remoting/client/dual_buffer_frame_consumer.h" 26 #include "remoting/client/dual_buffer_frame_consumer.h"
25 #include "remoting/client/software_video_renderer.h" 27 #include "remoting/client/software_video_renderer.h"
26 28
27 namespace remoting { 29 namespace remoting {
28 namespace GlDisplayHandler { 30 namespace GlDisplayHandler {
29 31
30 // The core that lives on the display thread. 32 // The core that lives on the display thread.
31 class Core : public protocol::CursorShapeStub, public GlRendererDelegate { 33 class Core : public protocol::CursorShapeStub, public GlRendererDelegate {
32 public: 34 public:
33 Core(); 35 Core();
34 ~Core() override; 36 ~Core() override;
35 37
38 void Initialize();
39
36 // CursorShapeStub interface. 40 // CursorShapeStub interface.
37 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override; 41 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override;
38 42
39 // GlRendererDelegate interface. 43 // GlRendererDelegate interface.
40 bool CanRenderFrame() override; 44 bool CanRenderFrame() override;
41 void OnFrameRendered() override; 45 void OnFrameRendered() override;
42 void OnSizeChanged(int width, int height) override; 46 void OnSizeChanged(int width, int height) override;
43 47
44 void Created(); 48 void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame,
49 const base::Closure& done);
45 void Stop(); 50 void Stop();
46 void SurfaceChanged(int width, int height); 51 void SurfaceChanged(int width, int height);
47 std::unique_ptr<protocol::FrameConsumer> GrabFrameConsumer(); 52 std::unique_ptr<protocol::FrameConsumer> GrabFrameConsumer();
53 EAGLContext* GetEAGLContext();
48 base::WeakPtr<Core> GetWeakPtr(); 54 base::WeakPtr<Core> GetWeakPtr();
49 55
50 private: 56 private:
57 remoting::ChromotingClientRuntime* runtime_;
58
51 // Will be std::move'd when GrabFrameConsumer() is called. 59 // Will be std::move'd when GrabFrameConsumer() is called.
52 remoting::ChromotingClientRuntime* runtime_;
53 std::unique_ptr<DualBufferFrameConsumer> owned_frame_consumer_; 60 std::unique_ptr<DualBufferFrameConsumer> owned_frame_consumer_;
61 base::WeakPtr<DualBufferFrameConsumer> frame_consumer_;
54 62
55 base::WeakPtr<DualBufferFrameConsumer> frame_consumer_;
56 EAGLContext* eagl_context_; 63 EAGLContext* eagl_context_;
57 GlRenderer renderer_; 64 std::unique_ptr<GlRenderer> renderer_;
58 GlDemoScreen demo_screen_; 65 // GlDemoScreen *demo_screen_;
Yuwei 2017/04/21 19:02:42 Looks like the whole GlDemoScreen class is not use
nicholss 2017/04/21 21:00:06 Yes just for debugging at the moment, not quite re
59 66
60 // Used on display thread. 67 // Used on display thread.
61 base::WeakPtr<Core> weak_ptr_; 68 base::WeakPtr<Core> weak_ptr_;
62 base::WeakPtrFactory<Core> weak_factory_; 69 base::WeakPtrFactory<Core> weak_factory_;
63 70
64 DISALLOW_COPY_AND_ASSIGN(Core); 71 DISALLOW_COPY_AND_ASSIGN(Core);
65 }; 72 };
66 73
67 Core::Core() : weak_factory_(this) { 74 Core::Core() : weak_factory_(this) {
68 runtime_ = ChromotingClientRuntime::GetInstance(); 75 runtime_ = ChromotingClientRuntime::GetInstance();
76 DCHECK(!runtime_->display_task_runner()->BelongsToCurrentThread());
77
69 weak_ptr_ = weak_factory_.GetWeakPtr(); 78 weak_ptr_ = weak_factory_.GetWeakPtr();
70 renderer_.SetDelegate(weak_ptr_); 79
80 runtime_->display_task_runner()->PostTask(
81 FROM_HERE, base::Bind(&Core::Initialize, base::Unretained(this)));
82
83 // Do not bind GlRenderer::OnFrameReceived. |renderer_| is not ready yet.
71 owned_frame_consumer_.reset(new remoting::DualBufferFrameConsumer( 84 owned_frame_consumer_.reset(new remoting::DualBufferFrameConsumer(
72 base::Bind(&remoting::GlRenderer::OnFrameReceived, 85 base::Bind(&Core::OnFrameReceived, weak_ptr_),
73 renderer_.GetWeakPtr()),
74 runtime_->display_task_runner(), 86 runtime_->display_task_runner(),
75 remoting::protocol::FrameConsumer::PixelFormat::FORMAT_RGBA)); 87 protocol::FrameConsumer::PixelFormat::FORMAT_RGBA));
76 frame_consumer_ = owned_frame_consumer_->GetWeakPtr(); 88 frame_consumer_ = owned_frame_consumer_->GetWeakPtr();
77 renderer_.AddDrawable(demo_screen_.GetWeakPtr());
78 } 89 }
79 90
80 Core::~Core() {} 91 Core::~Core() {}
Yuwei 2017/04/21 19:02:42 I think we should DCHECK it's being destructed on
nicholss 2017/04/21 21:00:06 Seems good to me.
81 92
93 void Core::Initialize() {
94 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
95
96 eagl_context_ = [EAGLContext currentContext];
97 if (!eagl_context_) {
98 // TODO(nicholss): For prod code, make sure to check for ES3 support and
99 // fall back to ES2 if needed.
100 eagl_context_ =
101 [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
102 [EAGLContext setCurrentContext:eagl_context_];
103 }
104
105 renderer_ = remoting::GlRenderer::CreateGlRendererWithDesktop();
106
107 // renderer_.RequestCanvasSize();
108
109 renderer_->OnSurfaceCreated(
110 base::MakeUnique<GlCanvas>(static_cast<int>([eagl_context_ API])));
111
112 SurfaceChanged(1024, 640); // TODO(nicholss): Where does this data comefrom?
113
114 // TODO(nicholss): This are wrong values but it lets us get something on the
115 // screen.
116 std::array<float, 9> matrix;
Yuwei 2017/04/21 18:28:59 Looks like it may not zero-initialize the matrix:
Yuwei 2017/04/21 19:02:42 *reader. The test I suggested above probably does
nicholss 2017/04/21 21:00:06 I had this before and it would not compile. I get
117 matrix[0] = 1;
118 matrix[4] = 1;
119 matrix[8] = 1;
120
121 renderer_->OnPixelTransformationChanged(matrix);
122
123 // demo_screen_ = new GlDemoScreen();
124 // renderer_->AddDrawable(demo_screen_->GetWeakPtr());
125 renderer_->SetDelegate(weak_ptr_);
126 }
127
82 void Core::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) { 128 void Core::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) {
83 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); 129 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
84 renderer_.OnCursorShapeChanged(cursor_shape); 130 renderer_->OnCursorShapeChanged(cursor_shape);
85 } 131 }
86 132
87 bool Core::CanRenderFrame() { 133 bool Core::CanRenderFrame() {
88 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); 134 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
89 return eagl_context_ != NULL; 135 return eagl_context_ != NULL;
90 } 136 }
91 137
92 std::unique_ptr<protocol::FrameConsumer> Core::GrabFrameConsumer() { 138 std::unique_ptr<protocol::FrameConsumer> Core::GrabFrameConsumer() {
93 DCHECK(owned_frame_consumer_) << "The frame consumer is already grabbed."; 139 DCHECK(owned_frame_consumer_) << "The frame consumer is already grabbed.";
94 return std::move(owned_frame_consumer_); 140 return std::move(owned_frame_consumer_);
95 } 141 }
96 142
143 void Core::OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame,
144 const base::Closure& done) {
145 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
146 renderer_->OnFrameReceived(std::move(frame), done);
147 }
148
97 void Core::OnFrameRendered() { 149 void Core::OnFrameRendered() {
98 // Nothing to do. 150 // Nothing to do.
99 } 151 }
100 152
101 void Core::OnSizeChanged(int width, int height) { 153 void Core::OnSizeChanged(int width, int height) {
102 // Nothing to do. 154 // Nothing to do.
103 } 155 }
104 156
105 void Core::Created() {
106 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
107 DCHECK(!eagl_context_);
108
109 eagl_context_ = [EAGLContext currentContext];
110 if (!eagl_context_) {
111 eagl_context_ =
112 [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
113 [EAGLContext setCurrentContext:eagl_context_];
114 }
115 renderer_.RequestCanvasSize();
116
117 renderer_.OnSurfaceCreated(base::MakeUnique<GlCanvas>(
118 static_cast<int>([eagl_context_ API])));
119 }
120
121 void Core::Stop() { 157 void Core::Stop() {
122 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); 158 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
123 159
124 eagl_context_ = nil; 160 eagl_context_ = nil;
125 // demo_screen_ 161 // demo_screen_ = nil;
126 // renderer_ = nil;
127 } 162 }
128 163
129 void Core::SurfaceChanged(int width, int height) { 164 void Core::SurfaceChanged(int width, int height) {
130 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); 165 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
131 renderer_.OnSurfaceChanged(width, height); 166 renderer_->OnSurfaceChanged(width, height);
167 }
168
169 EAGLContext* Core::GetEAGLContext() {
170 return eagl_context_;
132 } 171 }
133 172
134 base::WeakPtr<remoting::GlDisplayHandler::Core> Core::GetWeakPtr() { 173 base::WeakPtr<remoting::GlDisplayHandler::Core> Core::GetWeakPtr() {
135 return weak_ptr_; 174 return weak_ptr_;
136 } 175 }
137 176
138 } // namespace GlDisplayHandler 177 } // namespace GlDisplayHandler
139 } // namespace remoting 178 } // namespace remoting
140 179
141 @interface GlDisplayHandler () 180 @interface GlDisplayHandler () {
142 @property(nonatomic) remoting::GlDisplayHandler::Core* core_; 181 remoting::GlDisplayHandler::Core* _core;
143 @property(nonatomic) remoting::ChromotingClientRuntime* runtime_; 182 remoting::ChromotingClientRuntime* _runtime;
183 }
144 @end 184 @end
145 185
146 @implementation GlDisplayHandler 186 @implementation GlDisplayHandler
147 187
148 @synthesize core_ = _core_; 188 - (id)init {
149 @synthesize runtime_ = _runtime_; 189 self = [super init];
150 190 if (self) {
151 - (id)initWithRuntime:(remoting::ChromotingClientRuntime*)runtime { 191 _runtime = remoting::ChromotingClientRuntime::GetInstance();
152 self.runtime_ = runtime; 192 _core = new remoting::GlDisplayHandler::Core();
193 }
153 return self; 194 return self;
154 } 195 }
155 196
156 - (void)created { 197 #pragma mark - Public
157 _core_ = new remoting::GlDisplayHandler::Core();
158
159 self.runtime_->display_task_runner()->PostTask(
160 FROM_HERE, base::Bind(&remoting::GlDisplayHandler::Core::Created,
161 self.core_->GetWeakPtr()));
162 }
163 198
164 - (void)stop { 199 - (void)stop {
165 self.runtime_->display_task_runner()->PostTask( 200 _runtime->display_task_runner()->PostTask(
166 FROM_HERE, base::Bind(&remoting::GlDisplayHandler::Core::Stop, 201 FROM_HERE,
167 self.core_->GetWeakPtr())); 202 base::Bind(&remoting::GlDisplayHandler::Core::Stop, _core->GetWeakPtr()));
168 } 203 }
169 204
170 - (std::unique_ptr<remoting::protocol::VideoRenderer>)CreateVideoRenderer { 205 - (std::unique_ptr<remoting::protocol::VideoRenderer>)CreateVideoRenderer {
171 return base::MakeUnique<remoting::SoftwareVideoRenderer>( 206 return base::MakeUnique<remoting::SoftwareVideoRenderer>(
172 _core_->GrabFrameConsumer()); 207 _core->GrabFrameConsumer());
173 } 208 }
174 209
175 - (std::unique_ptr<remoting::protocol::CursorShapeStub>)CreateCursorShapeStub { 210 - (std::unique_ptr<remoting::protocol::CursorShapeStub>)CreateCursorShapeStub {
176 return base::MakeUnique<remoting::CursorShapeStubProxy>( 211 return base::MakeUnique<remoting::CursorShapeStubProxy>(
177 _core_->GetWeakPtr(), self.runtime_->display_task_runner()); 212 _core->GetWeakPtr(), _runtime->display_task_runner());
213 }
214
215 - (EAGLContext*)GetEAGLContext {
216 return _core->GetEAGLContext();
178 } 217 }
179 218
180 // In general, avoid expensive work in this function to maximize frame rate. 219 // In general, avoid expensive work in this function to maximize frame rate.
181 - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect { 220 - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect {
182 if (_core_) { 221 if (_core) {
183 _core_->SurfaceChanged(rect.size.width, rect.size.height); 222 _runtime->display_task_runner()->PostTask(
223 FROM_HERE,
224 base::Bind(&remoting::GlDisplayHandler::Core::SurfaceChanged,
225 _core->GetWeakPtr(), rect.size.width, rect.size.height));
226 // should be RequestRender
Yuwei 2017/04/21 19:02:42 The Android client is configured to draw (swap buf
nicholss 2017/04/21 21:00:06 This method is not used in the current implementat
184 } 227 }
185 } 228 }
186 229
187 @end 230 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698