Chromium Code Reviews| Index: remoting/client/ios/display/gl_display_handler.mm |
| diff --git a/remoting/client/ios/display/gl_display_handler.mm b/remoting/client/ios/display/gl_display_handler.mm |
| index 414665fd09ea7a4713f8fa47f4ddf59fcce1ba20..d5636e80116bf1f5450d857ac7aa5159ef65c21a 100644 |
| --- a/remoting/client/ios/display/gl_display_handler.mm |
| +++ b/remoting/client/ios/display/gl_display_handler.mm |
| @@ -6,47 +6,50 @@ |
| #error "This file requires ARC support." |
| #endif |
| - |
| -#import <Foundation/Foundation.h> |
| -#import <GLKit/GLKit.h> |
| +#import "remoting/client/ios/display/gl_display_handler.h" |
| #import "remoting/client/display/sys_opengl.h" |
| #import "remoting/client/ios/display/gl_demo_screen.h" |
| -#import "remoting/client/ios/display/gl_display_handler.h" |
| +#include "base/bind.h" |
| #include "base/macros.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/memory/weak_ptr.h" |
| #include "remoting/client/chromoting_client.h" |
| +#include "remoting/client/chromoting_client_runtime.h" |
| +#include "remoting/client/cursor_shape_stub_proxy.h" |
| #include "remoting/client/display/gl_canvas.h" |
| #include "remoting/client/display/gl_renderer.h" |
| #include "remoting/client/display/gl_renderer_delegate.h" |
| #include "remoting/client/dual_buffer_frame_consumer.h" |
| -#include "remoting/client/ios/app_runtime.h" |
| #include "remoting/client/software_video_renderer.h" |
| namespace remoting { |
| namespace GlDisplayHandler { |
| // The core that lives on the display thread. |
| -class Core : public GlRendererDelegate { |
| +class Core : public protocol::CursorShapeStub, public GlRendererDelegate { |
| public: |
| - Core(remoting::ios::AppRuntime* runtime); |
| + Core(); |
| ~Core() override; |
| + // CursorShapeStub interface. |
| + void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override; |
| + |
| // GlRendererDelegate interface. |
| bool CanRenderFrame() override; |
| void OnFrameRendered() override; |
| void OnSizeChanged(int width, int height) override; |
| void Created(); |
| + void Stop(); |
| void SurfaceChanged(int width, int height); |
| std::unique_ptr<protocol::FrameConsumer> GrabFrameConsumer(); |
| base::WeakPtr<Core> GetWeakPtr(); |
| private: |
| // Will be std::move'd when GrabFrameConsumer() is called. |
| - remoting::ios::AppRuntime* runtime_; |
| + remoting::ChromotingClientRuntime* runtime_; |
| std::unique_ptr<DualBufferFrameConsumer> owned_frame_consumer_; |
| base::WeakPtr<DualBufferFrameConsumer> frame_consumer_; |
| @@ -61,8 +64,8 @@ class Core : public GlRendererDelegate { |
| DISALLOW_COPY_AND_ASSIGN(Core); |
| }; |
| -Core::Core(remoting::ios::AppRuntime* runtime) |
| - : runtime_(runtime), weak_factory_(this) { |
| +Core::Core() : weak_factory_(this) { |
| + runtime_ = ChromotingClientRuntime::GetInstance(); |
| weak_ptr_ = weak_factory_.GetWeakPtr(); |
| renderer_.SetDelegate(weak_ptr_); |
| owned_frame_consumer_.reset(new remoting::DualBufferFrameConsumer( |
| @@ -76,6 +79,11 @@ Core::Core(remoting::ios::AppRuntime* runtime) |
| Core::~Core() {} |
| +void Core::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) { |
| + DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| + renderer_.OnCursorShapeChanged(cursor_shape); |
| +} |
| + |
| bool Core::CanRenderFrame() { |
| DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| return eagl_context_ != NULL; |
| @@ -99,12 +107,25 @@ void Core::Created() { |
| DCHECK(!eagl_context_); |
| eagl_context_ = [EAGLContext currentContext]; |
| + if (!eagl_context_) { |
| + eagl_context_ = |
| + [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; |
| + [EAGLContext setCurrentContext:eagl_context_]; |
| + } |
| renderer_.RequestCanvasSize(); |
| renderer_.OnSurfaceCreated(base::MakeUnique<GlCanvas>( |
| static_cast<int>([eagl_context_ API]))); |
| } |
| +void Core::Stop() { |
| + DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| + |
| + eagl_context_ = nil; |
| + // demo_screen_ |
|
Yuwei
2017/04/08 02:42:37
What are these comments for?
nicholss
2017/04/10 16:17:09
Cruft leftover from playing with the demo. I will
|
| + // renderer_ = nil; |
| +} |
| + |
| void Core::SurfaceChanged(int width, int height) { |
| DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); |
| renderer_.OnSurfaceChanged(width, height); |
| @@ -119,7 +140,7 @@ base::WeakPtr<remoting::GlDisplayHandler::Core> Core::GetWeakPtr() { |
| @interface GlDisplayHandler () |
| @property(nonatomic) remoting::GlDisplayHandler::Core* core_; |
| -@property(nonatomic) remoting::ios::AppRuntime* runtime_; |
| +@property(nonatomic) remoting::ChromotingClientRuntime* runtime_; |
| @end |
| @implementation GlDisplayHandler |
| @@ -127,24 +148,35 @@ base::WeakPtr<remoting::GlDisplayHandler::Core> Core::GetWeakPtr() { |
| @synthesize core_ = _core_; |
| @synthesize runtime_ = _runtime_; |
| -- (id)initWithRuntime:(remoting::ios::AppRuntime*)runtime { |
| +- (id)initWithRuntime:(remoting::ChromotingClientRuntime*)runtime { |
| self.runtime_ = runtime; |
| return self; |
| } |
| - (void)created { |
| - _core_ = new remoting::GlDisplayHandler::Core(self.runtime_); |
| + _core_ = new remoting::GlDisplayHandler::Core(); |
| self.runtime_->display_task_runner()->PostTask( |
| FROM_HERE, base::Bind(&remoting::GlDisplayHandler::Core::Created, |
| self.core_->GetWeakPtr())); |
| } |
| +- (void)stop { |
| + self.runtime_->display_task_runner()->PostTask( |
| + FROM_HERE, base::Bind(&remoting::GlDisplayHandler::Core::Stop, |
| + self.core_->GetWeakPtr())); |
| +} |
| + |
| - (std::unique_ptr<remoting::protocol::VideoRenderer>)CreateVideoRenderer { |
| return base::MakeUnique<remoting::SoftwareVideoRenderer>( |
| _core_->GrabFrameConsumer()); |
| } |
| +- (std::unique_ptr<remoting::protocol::CursorShapeStub>)CreateCursorShapeStub { |
| + return base::MakeUnique<remoting::CursorShapeStubProxy>( |
| + _core_->GetWeakPtr(), self.runtime_->display_task_runner()); |
| +} |
| + |
| // In general, avoid expensive work in this function to maximize frame rate. |
| - (void)glkView:(GLKView*)view drawInRect:(CGRect)rect { |
| if (_core_) { |