Commit b78ae9e3 authored by yuweih's avatar yuweih Committed by Commit bot

[Remoting Android] Separate the display core from JniGlDisplayHandler

This CL separates the core that lives entirely on the display thread from
JniGlDisplayHandler so that the thread model can be clearer.

BUG=646116

Review-Url: https://codereview.chromium.org/2389463002
Cr-Commit-Position: refs/heads/master@{#422988}
parent aa23d5d0
......@@ -48,8 +48,10 @@ void JniClient::ConnectToHost(const std::string& username,
const std::string& capabilities,
const std::string& flags) {
DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
DCHECK(!display_handler_);
DCHECK(!session_);
DCHECK(!secret_fetcher_);
display_handler_.reset(new JniGlDisplayHandler(runtime_, java_client_));
secret_fetcher_.reset(new JniPairingSecretFetcher(runtime_, GetWeakPtr(),
host_id));
session_.reset(new ChromotingJniInstance(
......@@ -72,11 +74,7 @@ void JniClient::DisconnectFromHost() {
runtime_->network_task_runner()->DeleteSoon(FROM_HERE,
secret_fetcher_.release());
}
if (display_handler_) {
display_handler_->Invalidate();
runtime_->display_task_runner()->DeleteSoon(FROM_HERE,
display_handler_.release());
}
display_handler_.reset();
}
void JniClient::OnConnectionState(protocol::ConnectionToHost::State state,
......@@ -161,8 +159,6 @@ void JniClient::Connect(
const base::android::JavaParamRef<jstring>& pairSecret,
const base::android::JavaParamRef<jstring>& capabilities,
const base::android::JavaParamRef<jstring>& flags) {
display_handler_.reset(new JniGlDisplayHandler(runtime_));
display_handler_->Initialize(java_client_);
ConnectToHost(ConvertJavaStringToUTF8(env, username),
ConvertJavaStringToUTF8(env, authToken),
ConvertJavaStringToUTF8(env, hostJid),
......
......@@ -13,6 +13,7 @@
#include "base/memory/weak_ptr.h"
#include "remoting/client/gl_renderer.h"
#include "remoting/client/gl_renderer_delegate.h"
#include "remoting/client/queued_task_poster.h"
#include "remoting/protocol/cursor_shape_stub.h"
namespace remoting {
......@@ -24,28 +25,15 @@ class VideoRenderer;
class ChromotingJniRuntime;
class DualBufferFrameConsumer;
class EglThreadContext;
class QueuedTaskPoster;
// Handles OpenGL display operations. Draws desktop and cursor on the OpenGL
// surface.
// JNI functions should all be called on the UI thread. user must call
// Initialize() after the handler is constructed and Invalidate() before the
// handler is destructed. The destructor must be called on the display thread.
// Please see GlDisplay.java for documentations.
// TODO(yuweih): Separate display thread logic into a core class.
class JniGlDisplayHandler : public protocol::CursorShapeStub,
public GlRendererDelegate {
// surface. The handler should be used and destroyed on the UI thread. It also
// has a core that works on the display thread.
class JniGlDisplayHandler {
public:
JniGlDisplayHandler(ChromotingJniRuntime* runtime);
// Destructor must be called on the display thread.
~JniGlDisplayHandler() override;
// Must be called exactly once on the UI thread before using the handler.
void Initialize(const base::android::JavaRef<jobject>& java_client);
// Must be called on the UI thread before calling the destructor.
void Invalidate();
JniGlDisplayHandler(ChromotingJniRuntime* runtime,
const base::android::JavaRef<jobject>& java_client);
~JniGlDisplayHandler();
std::unique_ptr<protocol::CursorShapeStub> CreateCursorShapeStub();
std::unique_ptr<protocol::VideoRenderer> CreateVideoRenderer();
......@@ -91,47 +79,21 @@ class JniGlDisplayHandler : public protocol::CursorShapeStub,
float diameter);
private:
// Queues a task. All queued tasks will be posted to the display thread after
// the current task is finished.
// Do nothing if |ui_task_poster_| has already been released.
void PostSequentialTaskOnDisplayThread(const base::Closure& task);
// GlRendererDelegate interface.
bool CanRenderFrame() override;
void OnFrameRendered() override;
void OnSizeChanged(int width, int height) override;
// CursorShapeStub interface.
void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override;
static void NotifyRenderDoneOnUiThread(
base::android::ScopedJavaGlobalRef<jobject> java_display);
class Core;
void SurfaceCreatedOnDisplayThread(
base::android::ScopedJavaGlobalRef<jobject> surface);
void SurfaceDestroyedOnDisplayThread();
static void ChangeCanvasSizeOnUiThread(
base::android::ScopedJavaGlobalRef<jobject> java_display,
int width,
int height);
// Callbacks from the core.
void OnRenderDone();
void OnCanvasSizeChanged(int width, int height);
ChromotingJniRuntime* runtime_;
base::android::ScopedJavaGlobalRef<jobject> java_display_;
std::unique_ptr<EglThreadContext> egl_context_;
base::WeakPtr<DualBufferFrameConsumer> frame_consumer_;
QueuedTaskPoster ui_task_poster_;
// |renderer_| must be deleted earlier than |egl_context_|.
GlRenderer renderer_;
std::unique_ptr<Core> core_;
std::unique_ptr<QueuedTaskPoster> ui_task_poster_;
base::android::ScopedJavaGlobalRef<jobject> java_display_;
// Used on display thread.
base::WeakPtr<JniGlDisplayHandler> weak_ptr_;
// Used on UI thread.
base::WeakPtrFactory<JniGlDisplayHandler> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(JniGlDisplayHandler);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment