Commit d4ef3682 authored by Aldo Culquicondor's avatar Aldo Culquicondor Committed by Commit Bot

VR: Remove UI wrappers in BrowserRenderer

These methods don't affect the BrowserRenderer. The task posting is done
in VrGLThread instead.

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:linux_vr;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: Ie43b046c71b7293d33316f4029f0fd7710c19869
Reviewed-on: https://chromium-review.googlesource.com/c/1258283
Commit-Queue: Aldo Culquicondor <acondor@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596219}
parent d6604509
...@@ -493,6 +493,43 @@ void VrGLThread::UpdateWebInputIndices(int selection_start, ...@@ -493,6 +493,43 @@ void VrGLThread::UpdateWebInputIndices(int selection_start,
composition_start, composition_end)); composition_start, composition_end));
} }
void VrGLThread::OnSwapContents(int new_content_id) {
task_runner()->PostTask(
FROM_HERE, base::BindRepeating(&BrowserUiInterface::OnSwapContents,
weak_browser_ui_, new_content_id));
}
void VrGLThread::SetDialogLocation(float x, float y) {
task_runner()->PostTask(
FROM_HERE, base::BindRepeating(&BrowserUiInterface::SetDialogLocation,
weak_browser_ui_, x, y));
}
void VrGLThread::SetDialogFloating(bool floating) {
task_runner()->PostTask(
FROM_HERE, base::BindRepeating(&BrowserUiInterface::SetDialogFloating,
weak_browser_ui_, floating));
}
void VrGLThread::ShowPlatformToast(const base::string16& text) {
task_runner()->PostTask(
FROM_HERE, base::BindRepeating(&BrowserUiInterface::ShowPlatformToast,
weak_browser_ui_, text));
}
void VrGLThread::CancelPlatformToast() {
task_runner()->PostTask(
FROM_HERE, base::BindRepeating(&BrowserUiInterface::CancelPlatformToast,
weak_browser_ui_));
}
void VrGLThread::OnContentBoundsChanged(int width, int height) {
task_runner()->PostTask(
FROM_HERE,
base::BindRepeating(&BrowserUiInterface::OnContentBoundsChanged,
weak_browser_ui_, width, height));
}
void VrGLThread::AddOrUpdateTab(int id, void VrGLThread::AddOrUpdateTab(int id,
bool incognito, bool incognito,
const base::string16& title) { const base::string16& title) {
......
...@@ -147,6 +147,12 @@ class VrGLThread : public base::android::JavaHandlerThread, ...@@ -147,6 +147,12 @@ class VrGLThread : public base::android::JavaHandlerThread,
int selection_end, int selection_end,
int composition_start, int composition_start,
int composition_end) override; int composition_end) override;
void OnSwapContents(int new_content_id) override;
void SetDialogLocation(float x, float y) override;
void SetDialogFloating(bool floating) override;
void ShowPlatformToast(const base::string16& text) override;
void CancelPlatformToast() override;
void OnContentBoundsChanged(int width, int height) override;
void AddOrUpdateTab(int id, void AddOrUpdateTab(int id,
bool incognito, bool incognito,
const base::string16& title) override; const base::string16& title) override;
......
...@@ -220,9 +220,7 @@ void VrShell::SwapContents(JNIEnv* env, ...@@ -220,9 +220,7 @@ void VrShell::SwapContents(JNIEnv* env,
const JavaParamRef<jobject>& obj, const JavaParamRef<jobject>& obj,
const JavaParamRef<jobject>& tab) { const JavaParamRef<jobject>& tab) {
content_id_++; content_id_++;
PostToGlThread(FROM_HERE, gl_thread_->OnSwapContents(content_id_);
base::BindOnce(&BrowserRenderer::OnSwapContents,
gl_thread_->GetBrowserRenderer(), content_id_));
TabAndroid* active_tab = TabAndroid* active_tab =
tab.is_null() tab.is_null()
? nullptr ? nullptr
...@@ -673,17 +671,13 @@ void VrShell::SetDialogLocation(JNIEnv* env, ...@@ -673,17 +671,13 @@ void VrShell::SetDialogLocation(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
float x, float x,
float y) { float y) {
PostToGlThread(FROM_HERE, gl_thread_->SetDialogLocation(x, y);
base::BindOnce(&BrowserRenderer::SetDialogLocation,
gl_thread_->GetBrowserRenderer(), x, y));
} }
void VrShell::SetDialogFloating(JNIEnv* env, void VrShell::SetDialogFloating(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
bool floating) { bool floating) {
PostToGlThread(FROM_HERE, gl_thread_->SetDialogFloating(floating);
base::BindOnce(&BrowserRenderer::SetDialogFloating,
gl_thread_->GetBrowserRenderer(), floating));
} }
void VrShell::ShowToast(JNIEnv* env, void VrShell::ShowToast(JNIEnv* env,
...@@ -691,15 +685,12 @@ void VrShell::ShowToast(JNIEnv* env, ...@@ -691,15 +685,12 @@ void VrShell::ShowToast(JNIEnv* env,
jstring jtext) { jstring jtext) {
base::string16 text; base::string16 text;
base::android::ConvertJavaStringToUTF16(env, jtext, &text); base::android::ConvertJavaStringToUTF16(env, jtext, &text);
PostToGlThread(FROM_HERE, gl_thread_->ShowPlatformToast(text);
base::BindOnce(&BrowserRenderer::ShowToast,
gl_thread_->GetBrowserRenderer(), text));
} }
void VrShell::CancelToast(JNIEnv* env, void VrShell::CancelToast(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) { const base::android::JavaParamRef<jobject>& obj) {
PostToGlThread(FROM_HERE, base::BindOnce(&BrowserRenderer::CancelToast, gl_thread_->CancelPlatformToast();
gl_thread_->GetBrowserRenderer()));
} }
void VrShell::ConnectPresentingService( void VrShell::ConnectPresentingService(
...@@ -952,10 +943,7 @@ void VrShell::OnContentScreenBoundsChanged(const gfx::SizeF& bounds) { ...@@ -952,10 +943,7 @@ void VrShell::OnContentScreenBoundsChanged(const gfx::SizeF& bounds) {
Java_VrShell_setContentCssSize(env, j_vr_shell_, window_size.width(), Java_VrShell_setContentCssSize(env, j_vr_shell_, window_size.width(),
window_size.height(), dpr); window_size.height(), dpr);
PostToGlThread(FROM_HERE, gl_thread_->OnContentBoundsChanged(window_size.width(), window_size.height());
base::BindOnce(&BrowserRenderer::ContentBoundsChanged,
gl_thread_->GetBrowserRenderer(),
window_size.width(), window_size.height()));
} }
void VrShell::SetVoiceSearchActive(bool active) { void VrShell::SetVoiceSearchActive(bool active) {
......
...@@ -158,10 +158,6 @@ void BrowserRenderer::SetWebXrMode(bool enabled) { ...@@ -158,10 +158,6 @@ void BrowserRenderer::SetWebXrMode(bool enabled) {
scheduler_delegate_->SetWebXrMode(enabled); scheduler_delegate_->SetWebXrMode(enabled);
} }
void BrowserRenderer::OnSwapContents(int new_content_id) {
ui_->OnSwapContents(new_content_id);
}
void BrowserRenderer::EnableAlertDialog(PlatformInputHandler* input_handler, void BrowserRenderer::EnableAlertDialog(PlatformInputHandler* input_handler,
float width, float width,
float height) { float height) {
...@@ -206,31 +202,10 @@ void BrowserRenderer::SetAlertDialogSize(float width, float height) { ...@@ -206,31 +202,10 @@ void BrowserRenderer::SetAlertDialogSize(float width, float height) {
} }
} }
void BrowserRenderer::SetDialogLocation(float x, float y) {
ui_->SetDialogLocation(x, y);
}
void BrowserRenderer::SetDialogFloating(bool floating) {
ui_->SetDialogFloating(floating);
}
void BrowserRenderer::ShowToast(const base::string16& text) {
ui_->ShowPlatformToast(text);
}
void BrowserRenderer::CancelToast() {
ui_->CancelPlatformToast();
}
void BrowserRenderer::ResumeContentRendering() { void BrowserRenderer::ResumeContentRendering() {
graphics_delegate_->ResumeContentRendering(); graphics_delegate_->ResumeContentRendering();
} }
void BrowserRenderer::ContentBoundsChanged(int width, int height) {
TRACE_EVENT0("gpu", __func__);
ui_->OnContentBoundsChanged(width, height);
}
void BrowserRenderer::BufferBoundsChanged( void BrowserRenderer::BufferBoundsChanged(
const gfx::Size& content_buffer_size, const gfx::Size& content_buffer_size,
const gfx::Size& overlay_buffer_size) { const gfx::Size& overlay_buffer_size) {
......
...@@ -58,18 +58,12 @@ class VR_EXPORT BrowserRenderer : public SchedulerBrowserRendererInterface { ...@@ -58,18 +58,12 @@ class VR_EXPORT BrowserRenderer : public SchedulerBrowserRendererInterface {
void OnExitPresent(); void OnExitPresent();
void OnTriggerEvent(bool pressed); void OnTriggerEvent(bool pressed);
void SetWebXrMode(bool enabled); void SetWebXrMode(bool enabled);
void OnSwapContents(int new_content_id);
void EnableAlertDialog(PlatformInputHandler* input_handler, void EnableAlertDialog(PlatformInputHandler* input_handler,
float width, float width,
float height); float height);
void DisableAlertDialog(); void DisableAlertDialog();
void SetAlertDialogSize(float width, float height); void SetAlertDialogSize(float width, float height);
void SetDialogLocation(float x, float y);
void SetDialogFloating(bool floating);
void ShowToast(const base::string16& text);
void CancelToast();
void ResumeContentRendering(); void ResumeContentRendering();
void ContentBoundsChanged(int width, int height);
void BufferBoundsChanged(const gfx::Size& content_buffer_size, void BufferBoundsChanged(const gfx::Size& content_buffer_size,
const gfx::Size& overlay_buffer_size); const gfx::Size& overlay_buffer_size);
......
...@@ -34,20 +34,12 @@ class MockUi : public UiInterface { ...@@ -34,20 +34,12 @@ class MockUi : public UiInterface {
void(GlTextureLocation, unsigned int, unsigned int, unsigned int)); void(GlTextureLocation, unsigned int, unsigned int, unsigned int));
MOCK_METHOD4(SetAlertDialogEnabled, MOCK_METHOD4(SetAlertDialogEnabled,
void(bool, PlatformUiInputDelegate*, float, float)); void(bool, PlatformUiInputDelegate*, float, float));
MOCK_METHOD2(SetAlertDialogSize, void(float, float));
MOCK_METHOD4(SetContentOverlayAlertDialogEnabled, MOCK_METHOD4(SetContentOverlayAlertDialogEnabled,
void(bool, PlatformUiInputDelegate*, float, float)); void(bool, PlatformUiInputDelegate*, float, float));
MOCK_METHOD2(SetDialogLocation, void(float, float));
MOCK_METHOD2(SetContentOverlayAlertDialogSize, void(float, float));
MOCK_METHOD1(SetDialogFloating, void(bool));
MOCK_METHOD1(ShowPlatformToast, void(const base::string16&));
MOCK_METHOD0(CancelPlatformToast, void());
MOCK_METHOD0(OnPause, void()); MOCK_METHOD0(OnPause, void());
void OnControllerUpdated(const ControllerModel&, void OnControllerUpdated(const ControllerModel&,
const ReticleModel&) override {} const ReticleModel&) override {}
void OnProjMatrixChanged(const gfx::Transform&) override {} void OnProjMatrixChanged(const gfx::Transform&) override {}
MOCK_METHOD1(OnSwapContents, void(int));
MOCK_METHOD2(OnContentBoundsChanged, void(int, int));
MOCK_METHOD0(AcceptDoffPromptForTesting, void()); MOCK_METHOD0(AcceptDoffPromptForTesting, void());
MOCK_METHOD2(GetTargetPointForTesting, MOCK_METHOD2(GetTargetPointForTesting,
gfx::Point3F(UserFriendlyElementName, gfx::Point3F(UserFriendlyElementName,
......
...@@ -24,6 +24,8 @@ struct OmniboxSuggestions; ...@@ -24,6 +24,8 @@ struct OmniboxSuggestions;
struct ToolbarState; struct ToolbarState;
// The browser communicates state changes to the VR UI via this interface. // The browser communicates state changes to the VR UI via this interface.
// A GL thread would also implement this interface to provide a convenient way
// to call these methods from the main thread.
class VR_EXPORT BrowserUiInterface { class VR_EXPORT BrowserUiInterface {
public: public:
virtual ~BrowserUiInterface() {} virtual ~BrowserUiInterface() {}
...@@ -57,6 +59,12 @@ class VR_EXPORT BrowserUiInterface { ...@@ -57,6 +59,12 @@ class VR_EXPORT BrowserUiInterface {
int selection_end, int selection_end,
int composition_start, int composition_start,
int composition_end) = 0; int composition_end) = 0;
virtual void OnSwapContents(int new_content_id) = 0;
virtual void SetDialogLocation(float x, float y) = 0;
virtual void SetDialogFloating(bool floating) = 0;
virtual void ShowPlatformToast(const base::string16& text) = 0;
virtual void CancelPlatformToast() = 0;
virtual void OnContentBoundsChanged(int width, int height) = 0;
virtual void AddOrUpdateTab(int id, virtual void AddOrUpdateTab(int id,
bool incognito, bool incognito,
const base::string16& title) = 0; const base::string16& title) = 0;
......
...@@ -46,6 +46,12 @@ class MockBrowserUiInterface : public BrowserUiInterface { ...@@ -46,6 +46,12 @@ class MockBrowserUiInterface : public BrowserUiInterface {
MOCK_METHOD1(SetOverlayTextureEmpty, void(bool)); MOCK_METHOD1(SetOverlayTextureEmpty, void(bool));
MOCK_METHOD1(ShowSoftInput, void(bool)); MOCK_METHOD1(ShowSoftInput, void(bool));
MOCK_METHOD4(UpdateWebInputIndices, void(int, int, int, int)); MOCK_METHOD4(UpdateWebInputIndices, void(int, int, int, int));
MOCK_METHOD1(OnSwapContents, void(int));
MOCK_METHOD2(SetDialogLocation, void(float, float));
MOCK_METHOD1(SetDialogFloating, void(bool));
MOCK_METHOD1(ShowPlatformToast, void(const base::string16&));
MOCK_METHOD0(CancelPlatformToast, void());
MOCK_METHOD2(OnContentBoundsChanged, void(int, int));
MOCK_METHOD3(AddOrUpdateTab, MOCK_METHOD3(AddOrUpdateTab,
void(int id, bool incognito, const base::string16& title)); void(int id, bool incognito, const base::string16& title));
MOCK_METHOD2(RemoveTab, void(int id, bool incognito)); MOCK_METHOD2(RemoveTab, void(int id, bool incognito));
......
...@@ -228,9 +228,9 @@ void VrTestContext::HandleInput(ui::Event* event) { ...@@ -228,9 +228,9 @@ void VrTestContext::HandleInput(ui::Event* event) {
break; break;
case ui::DomCode::US_A: case ui::DomCode::US_A:
if (model_->platform_toast) { if (model_->platform_toast) {
ui_->CancelPlatformToast(); browser_ui->CancelPlatformToast();
} else { } else {
ui_->ShowPlatformToast(base::UTF8ToUTF16("Downloading")); browser_ui->ShowPlatformToast(base::UTF8ToUTF16("Downloading"));
} }
break; break;
case ui::DomCode::US_H: case ui::DomCode::US_H:
......
...@@ -137,9 +137,6 @@ class VR_UI_EXPORT Ui : public UiInterface, ...@@ -137,9 +137,6 @@ class VR_UI_EXPORT Ui : public UiInterface,
PlatformUiInputDelegate* delegate, PlatformUiInputDelegate* delegate,
float width_percentage, float width_percentage,
float height_percentage) override; float height_percentage) override;
void SetAlertDialogSize(float width, float height) override;
void SetContentOverlayAlertDialogSize(float width_percentage,
float height_percentage) override;
void SetDialogLocation(float x, float y) override; void SetDialogLocation(float x, float y) override;
void SetDialogFloating(bool floating) override; void SetDialogFloating(bool floating) override;
void ShowPlatformToast(const base::string16& text) override; void ShowPlatformToast(const base::string16& text) override;
...@@ -198,6 +195,9 @@ class VR_UI_EXPORT Ui : public UiInterface, ...@@ -198,6 +195,9 @@ class VR_UI_EXPORT Ui : public UiInterface,
void OnKeyboardHidden() override; void OnKeyboardHidden() override;
private: private:
void SetAlertDialogSize(float width, float height);
void SetContentOverlayAlertDialogSize(float width_percentage,
float height_percentage);
void RequestFocus(int element_id); void RequestFocus(int element_id);
void RequestUnfocus(int element_id); void RequestUnfocus(int element_id);
void OnMenuButtonClicked(); void OnMenuButtonClicked();
......
...@@ -62,19 +62,10 @@ class UiInterface { ...@@ -62,19 +62,10 @@ class UiInterface {
PlatformUiInputDelegate* delegate, PlatformUiInputDelegate* delegate,
float width_percentage, float width_percentage,
float height_percentage) = 0; float height_percentage) = 0;
virtual void SetAlertDialogSize(float width, float height) = 0;
virtual void SetContentOverlayAlertDialogSize(float width_percentage,
float height_percentage) = 0;
virtual void SetDialogLocation(float x, float y) = 0;
virtual void SetDialogFloating(bool floating) = 0;
virtual void ShowPlatformToast(const base::string16& text) = 0;
virtual void CancelPlatformToast() = 0;
virtual void OnPause() = 0; virtual void OnPause() = 0;
virtual void OnControllerUpdated(const ControllerModel& controller_model, virtual void OnControllerUpdated(const ControllerModel& controller_model,
const ReticleModel& reticle_model) = 0; const ReticleModel& reticle_model) = 0;
virtual void OnProjMatrixChanged(const gfx::Transform& proj_matrix) = 0; virtual void OnProjMatrixChanged(const gfx::Transform& proj_matrix) = 0;
virtual void OnSwapContents(int new_content_id) = 0;
virtual void OnContentBoundsChanged(int width, int height) = 0;
virtual void AcceptDoffPromptForTesting() = 0; virtual void AcceptDoffPromptForTesting() = 0;
virtual gfx::Point3F GetTargetPointForTesting( virtual gfx::Point3F GetTargetPointForTesting(
UserFriendlyElementName element_name, UserFriendlyElementName element_name,
......
...@@ -150,23 +150,24 @@ TEST_F(UiTest, WebVrToastTransience) { ...@@ -150,23 +150,24 @@ TEST_F(UiTest, WebVrToastTransience) {
TEST_F(UiTest, PlatformToast) { TEST_F(UiTest, PlatformToast) {
CreateScene(kNotInWebVr); CreateScene(kNotInWebVr);
EXPECT_FALSE(IsVisible(kPlatformToast)); EXPECT_FALSE(IsVisible(kPlatformToast));
auto browser_ui = ui_->GetBrowserUiWeakPtr();
// show and hide toast after a timeout. // show and hide toast after a timeout.
ui_->ShowPlatformToast(base::UTF8ToUTF16("Downloading")); browser_ui->ShowPlatformToast(base::UTF8ToUTF16("Downloading"));
EXPECT_TRUE(IsVisible(kPlatformToast)); EXPECT_TRUE(IsVisible(kPlatformToast));
EXPECT_TRUE(RunForSeconds(kToastTimeoutSeconds + kSmallDelaySeconds)); EXPECT_TRUE(RunForSeconds(kToastTimeoutSeconds + kSmallDelaySeconds));
EXPECT_FALSE(IsVisible(kPlatformToast)); EXPECT_FALSE(IsVisible(kPlatformToast));
// toast can be cancelled. // toast can be cancelled.
ui_->ShowPlatformToast(base::UTF8ToUTF16("Downloading")); browser_ui->ShowPlatformToast(base::UTF8ToUTF16("Downloading"));
EXPECT_TRUE(IsVisible(kPlatformToast)); EXPECT_TRUE(IsVisible(kPlatformToast));
ui_->CancelPlatformToast(); browser_ui->CancelPlatformToast();
EXPECT_FALSE(IsVisible(kPlatformToast)); EXPECT_FALSE(IsVisible(kPlatformToast));
// toast can refresh visible timeout. // toast can refresh visible timeout.
ui_->ShowPlatformToast(base::UTF8ToUTF16("Downloading")); browser_ui->ShowPlatformToast(base::UTF8ToUTF16("Downloading"));
EXPECT_TRUE(RunForSeconds(kSmallDelaySeconds)); EXPECT_TRUE(RunForSeconds(kSmallDelaySeconds));
ui_->ShowPlatformToast(base::UTF8ToUTF16("Downloading")); browser_ui->ShowPlatformToast(base::UTF8ToUTF16("Downloading"));
EXPECT_TRUE(RunForSeconds(kToastTimeoutSeconds - kSmallDelaySeconds)); EXPECT_TRUE(RunForSeconds(kToastTimeoutSeconds - kSmallDelaySeconds));
EXPECT_TRUE(IsVisible(kPlatformToast)); EXPECT_TRUE(IsVisible(kPlatformToast));
EXPECT_TRUE(RunForSeconds(kToastTimeoutSeconds + kSmallDelaySeconds)); EXPECT_TRUE(RunForSeconds(kToastTimeoutSeconds + kSmallDelaySeconds));
......
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