| OLD | NEW |
| 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 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override; | 41 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override; |
| 42 | 42 |
| 43 // GlRendererDelegate interface. | 43 // GlRendererDelegate interface. |
| 44 bool CanRenderFrame() override; | 44 bool CanRenderFrame() override; |
| 45 void OnFrameRendered() override; | 45 void OnFrameRendered() override; |
| 46 void OnSizeChanged(int width, int height) override; | 46 void OnSizeChanged(int width, int height) override; |
| 47 | 47 |
| 48 void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame, | 48 void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame, |
| 49 const base::Closure& done); | 49 const base::Closure& done); |
| 50 void Stop(); | 50 void Stop(); |
| 51 void SurfaceCreated(GLKView* view); |
| 51 void SurfaceChanged(int width, int height); | 52 void SurfaceChanged(int width, int height); |
| 52 std::unique_ptr<protocol::FrameConsumer> GrabFrameConsumer(); | 53 std::unique_ptr<protocol::FrameConsumer> GrabFrameConsumer(); |
| 53 EAGLContext* GetEAGLContext(); | 54 EAGLContext* GetEAGLContext(); |
| 54 base::WeakPtr<Core> GetWeakPtr(); | 55 base::WeakPtr<Core> GetWeakPtr(); |
| 55 | 56 |
| 56 private: | 57 private: |
| 57 remoting::ChromotingClientRuntime* runtime_; | 58 remoting::ChromotingClientRuntime* runtime_; |
| 58 | 59 |
| 59 // Will be std::move'd when GrabFrameConsumer() is called. | 60 // Will be std::move'd when GrabFrameConsumer() is called. |
| 60 std::unique_ptr<DualBufferFrameConsumer> owned_frame_consumer_; | 61 std::unique_ptr<DualBufferFrameConsumer> owned_frame_consumer_; |
| 61 base::WeakPtr<DualBufferFrameConsumer> frame_consumer_; | 62 base::WeakPtr<DualBufferFrameConsumer> frame_consumer_; |
| 62 | 63 |
| 64 GLKView* gl_view_; |
| 63 EAGLContext* eagl_context_; | 65 EAGLContext* eagl_context_; |
| 64 std::unique_ptr<GlRenderer> renderer_; | 66 std::unique_ptr<GlRenderer> renderer_; |
| 65 // GlDemoScreen *demo_screen_; | 67 // GlDemoScreen *demo_screen_; |
| 66 | 68 |
| 67 // Used on display thread. | 69 // Used on display thread. |
| 68 base::WeakPtr<Core> weak_ptr_; | 70 base::WeakPtr<Core> weak_ptr_; |
| 69 base::WeakPtrFactory<Core> weak_factory_; | 71 base::WeakPtrFactory<Core> weak_factory_; |
| 70 | 72 |
| 71 DISALLOW_COPY_AND_ASSIGN(Core); | 73 DISALLOW_COPY_AND_ASSIGN(Core); |
| 72 }; | 74 }; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 101 // fall back to ES2 if needed. | 103 // fall back to ES2 if needed. |
| 102 eagl_context_ = | 104 eagl_context_ = |
| 103 [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; | 105 [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; |
| 104 [EAGLContext setCurrentContext:eagl_context_]; | 106 [EAGLContext setCurrentContext:eagl_context_]; |
| 105 } | 107 } |
| 106 | 108 |
| 107 renderer_ = remoting::GlRenderer::CreateGlRendererWithDesktop(); | 109 renderer_ = remoting::GlRenderer::CreateGlRendererWithDesktop(); |
| 108 | 110 |
| 109 // renderer_.RequestCanvasSize(); | 111 // renderer_.RequestCanvasSize(); |
| 110 | 112 |
| 111 renderer_->OnSurfaceCreated( | |
| 112 base::MakeUnique<GlCanvas>(static_cast<int>([eagl_context_ API]))); | |
| 113 | |
| 114 SurfaceChanged(1024, 640); // TODO(nicholss): Where does this data comefrom? | |
| 115 | |
| 116 // TODO(nicholss): This are wrong values but it lets us get something on the | |
| 117 // screen. | |
| 118 std::array<float, 9> matrix = {{1, 0, 0, | |
| 119 0, 1, 0, | |
| 120 0, 0, 1}}; | |
| 121 | |
| 122 renderer_->OnPixelTransformationChanged(matrix); | |
| 123 | |
| 124 // demo_screen_ = new GlDemoScreen(); | 113 // demo_screen_ = new GlDemoScreen(); |
| 125 // renderer_->AddDrawable(demo_screen_->GetWeakPtr()); | 114 // renderer_->AddDrawable(demo_screen_->GetWeakPtr()); |
| 126 renderer_->SetDelegate(weak_ptr_); | 115 renderer_->SetDelegate(weak_ptr_); |
| 127 } | 116 } |
| 128 | 117 |
| 129 void Core::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) { | 118 void Core::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) { |
| 130 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); | 119 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| 131 renderer_->OnCursorShapeChanged(cursor_shape); | 120 renderer_->OnCursorShapeChanged(cursor_shape); |
| 132 } | 121 } |
| 133 | 122 |
| 134 bool Core::CanRenderFrame() { | 123 bool Core::CanRenderFrame() { |
| 135 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); | 124 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| 136 return eagl_context_ != NULL; | 125 return gl_view_ != NULL && eagl_context_ != NULL; |
| 137 } | 126 } |
| 138 | 127 |
| 139 std::unique_ptr<protocol::FrameConsumer> Core::GrabFrameConsumer() { | 128 std::unique_ptr<protocol::FrameConsumer> Core::GrabFrameConsumer() { |
| 140 DCHECK(owned_frame_consumer_) << "The frame consumer is already grabbed."; | 129 DCHECK(owned_frame_consumer_) << "The frame consumer is already grabbed."; |
| 141 return std::move(owned_frame_consumer_); | 130 return std::move(owned_frame_consumer_); |
| 142 } | 131 } |
| 143 | 132 |
| 144 void Core::OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame, | 133 void Core::OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame, |
| 145 const base::Closure& done) { | 134 const base::Closure& done) { |
| 146 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); | 135 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| 147 renderer_->OnFrameReceived(std::move(frame), done); | 136 renderer_->OnFrameReceived(std::move(frame), done); |
| 148 } | 137 } |
| 149 | 138 |
| 150 void Core::OnFrameRendered() { | 139 void Core::OnFrameRendered() { |
| 151 // Nothing to do. | 140 [gl_view_ setNeedsDisplay]; |
| 152 } | 141 } |
| 153 | 142 |
| 154 void Core::OnSizeChanged(int width, int height) { | 143 void Core::OnSizeChanged(int width, int height) { |
| 155 // Nothing to do. | 144 // Nothing to do. |
| 156 } | 145 } |
| 157 | 146 |
| 158 void Core::Stop() { | 147 void Core::Stop() { |
| 159 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); | 148 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| 160 | 149 |
| 161 eagl_context_ = nil; | 150 eagl_context_ = nil; |
| 162 // demo_screen_ = nil; | 151 // demo_screen_ = nil; |
| 163 } | 152 } |
| 164 | 153 |
| 154 void Core::SurfaceCreated(GLKView* view) { |
| 155 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| 156 gl_view_ = view; |
| 157 |
| 158 renderer_->OnSurfaceCreated( |
| 159 base::MakeUnique<GlCanvas>(static_cast<int>([eagl_context_ API]))); |
| 160 |
| 161 runtime_->network_task_runner()->PostTask( |
| 162 FROM_HERE, base::Bind(&DualBufferFrameConsumer::RequestFullDesktopFrame, |
| 163 frame_consumer_)); |
| 164 } |
| 165 |
| 165 void Core::SurfaceChanged(int width, int height) { | 166 void Core::SurfaceChanged(int width, int height) { |
| 166 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); | 167 DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| 167 renderer_->OnSurfaceChanged(width, height); | 168 renderer_->OnSurfaceChanged(width, height); |
| 169 |
| 170 // TODO(nicholss): This are wrong values but it lets us get something on the |
| 171 // screen. |
| 172 std::array<float, 9> matrix = {{1, 0, 0, // Row 1 |
| 173 0, 1, 0, // Row 2 |
| 174 0, 0, 1}}; |
| 175 |
| 176 renderer_->OnPixelTransformationChanged(matrix); |
| 168 } | 177 } |
| 169 | 178 |
| 170 EAGLContext* Core::GetEAGLContext() { | 179 EAGLContext* Core::GetEAGLContext() { |
| 171 return eagl_context_; | 180 return eagl_context_; |
| 172 } | 181 } |
| 173 | 182 |
| 174 base::WeakPtr<remoting::GlDisplayHandler::Core> Core::GetWeakPtr() { | 183 base::WeakPtr<remoting::GlDisplayHandler::Core> Core::GetWeakPtr() { |
| 175 return weak_ptr_; | 184 return weak_ptr_; |
| 176 } | 185 } |
| 177 | 186 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 219 |
| 211 - (std::unique_ptr<remoting::protocol::CursorShapeStub>)CreateCursorShapeStub { | 220 - (std::unique_ptr<remoting::protocol::CursorShapeStub>)CreateCursorShapeStub { |
| 212 return base::MakeUnique<remoting::CursorShapeStubProxy>( | 221 return base::MakeUnique<remoting::CursorShapeStubProxy>( |
| 213 _core->GetWeakPtr(), _runtime->display_task_runner()); | 222 _core->GetWeakPtr(), _runtime->display_task_runner()); |
| 214 } | 223 } |
| 215 | 224 |
| 216 - (EAGLContext*)GetEAGLContext { | 225 - (EAGLContext*)GetEAGLContext { |
| 217 return _core->GetEAGLContext(); | 226 return _core->GetEAGLContext(); |
| 218 } | 227 } |
| 219 | 228 |
| 229 - (void)onSurfaceCreated:(GLKView*)view { |
| 230 _runtime->display_task_runner()->PostTask( |
| 231 FROM_HERE, base::Bind(&remoting::GlDisplayHandler::Core::SurfaceCreated, |
| 232 _core->GetWeakPtr(), view)); |
| 233 } |
| 234 |
| 235 - (void)onSurfaceChanged:(const CGRect&)frame { |
| 236 _runtime->display_task_runner()->PostTask( |
| 237 FROM_HERE, |
| 238 base::Bind(&remoting::GlDisplayHandler::Core::SurfaceChanged, |
| 239 _core->GetWeakPtr(), frame.size.width, frame.size.height)); |
| 240 } |
| 241 |
| 220 // TODO(nicholss): Remove this function, it is not used in the final impl, | 242 // TODO(nicholss): Remove this function, it is not used in the final impl, |
| 221 // or it should call RequestRender. | 243 // or it should call RequestRender. |
| 222 - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect { | 244 - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect { |
| 223 if (_core) { | 245 if (_core) { |
| 224 _runtime->display_task_runner()->PostTask( | 246 _runtime->display_task_runner()->PostTask( |
| 225 FROM_HERE, | 247 FROM_HERE, |
| 226 base::Bind(&remoting::GlDisplayHandler::Core::SurfaceChanged, | 248 base::Bind(&remoting::GlDisplayHandler::Core::SurfaceChanged, |
| 227 _core->GetWeakPtr(), rect.size.width, rect.size.height)); | 249 _core->GetWeakPtr(), rect.size.width, rect.size.height)); |
| 228 } | 250 } |
| 229 } | 251 } |
| 230 | 252 |
| 231 @end | 253 @end |
| OLD | NEW |