Index: chrome/browser/android/vr_shell/vr_shell.cc |
diff --git a/chrome/browser/android/vr_shell/vr_shell.cc b/chrome/browser/android/vr_shell/vr_shell.cc |
index cbc58091fe6421241007f0f10fd073949453836f..c7b7dea0aee0833f32c407d84579fab0e238904c 100644 |
--- a/chrome/browser/android/vr_shell/vr_shell.cc |
+++ b/chrome/browser/android/vr_shell/vr_shell.cc |
@@ -10,6 +10,39 @@ |
#include "ui/gl/gl_bindings.h" |
#include "ui/gl/init/gl_factory.h" |
+#include "base/android/build_info.h" |
+#include "base/android/jni_android.h" |
+#include "base/bind.h" |
+#include "base/command_line.h" |
+#include "base/id_map.h" |
+#include "base/rand_util.h" |
+#include "base/trace_event/trace_event.h" |
+#include "cc/layers/layer.h" |
+#include "cc/layers/layer_collections.h" |
+#include "cc/layers/solid_color_layer.h" |
+#include "cc/layers/texture_layer.h" |
+#include "chrome/browser/android/compositor/layer/toolbar_layer.h" |
+#include "chrome/browser/android/compositor/layer_title_cache.h" |
+#include "chrome/browser/android/compositor/scene_layer/scene_layer.h" |
+#include "content/public/browser/android/compositor.h" |
+#include "content/public/browser/android/content_view_core.h" |
+#include "content/public/browser/child_process_data.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/common/process_type.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
+#include "ui/android/resources/resource_manager.h" |
+#include "ui/android/resources/ui_resource_provider.h" |
+#include "ui/android/window_android.h" |
+ |
+#include "ui/gfx/android/java_bitmap.h" |
+ |
+#include "ui/android/delegated_frame_host_android.h" |
+#include "content/browser/renderer_host/render_widget_host_view_android.h" |
+#include "cc/layers/surface_layer.h" |
+ |
+#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/render_widget_host.h" |
+ |
namespace vr_shell { |
namespace { |
@@ -56,8 +89,22 @@ void ContentRect::Translate(float x, float y, float z) { |
transfrom_to_world.m[2][3] += z; |
} |
-VrShell::VrShell(JNIEnv* env, jobject obj) { |
+VrShell::VrShell(JNIEnv* env, |
+ jobject obj, |
+ jboolean low_mem_device, |
+ ui::WindowAndroid* window_android) |
+ : root_layer_(cc::SolidColorLayer::Create()), |
+ current_surface_format_(0), |
+ content_width_(0), |
+ content_height_(0), |
+ weak_factory_(this) { |
+ content::BrowserChildProcessObserver::Add(this); |
j_vr_shell_.Reset(env, obj); |
+ compositor_.reset(content::Compositor::Create(this, window_android)); |
+ compositor_->setDeviceScaleFactor(1.0f); |
+ |
+ root_layer_->SetIsDrawable(true); |
+ root_layer_->SetBackgroundColor(SK_ColorRED); |
} |
void VrShell::Destroy(JNIEnv* env, |
@@ -69,7 +116,13 @@ bool RegisterVrShell(JNIEnv* env) { |
return RegisterNativesImpl(env); |
} |
-VrShell::~VrShell() {} |
+VrShell::~VrShell() { |
+ content::BrowserChildProcessObserver::Remove(this); |
+ |
+ // Explicitly reset these scoped_ptrs here because otherwise we callbacks will |
+ // try to access member variables during destruction. |
+ compositor_.reset(NULL); |
+} |
void VrShell::GvrInit(JNIEnv* env, |
const base::android::JavaParamRef<jobject>& obj, |
@@ -97,6 +150,11 @@ void VrShell::InitializeGl(JNIEnv* env, |
new gvr::BufferViewport(gvr_api_->CreateBufferViewport())); |
} |
+void VrShell::AddContentLayer() { |
+ LOG(ERROR) << "bshe add content layer"; |
+ // root_layer_->AddChild(rwhva->delegated_frame_host()->CopySurfaceLayer()); |
+} |
+ |
void VrShell::DrawFrame(JNIEnv* env, |
const base::android::JavaParamRef<jobject>& obj) { |
buffer_viewport_list_->SetToRecommendedBufferViewports(); |
@@ -105,6 +163,16 @@ void VrShell::DrawFrame(JNIEnv* env, |
target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; |
head_pose_ = gvr_api_->GetHeadPoseInStartSpace(target_time); |
+ // Quick hack to get valid SurfaceLayer. |
+ // if (root_layer_->children().size() == 0 && |
+ // rwhva && |
+ // rwhva->HasValidFrame()) { |
+ // content::BrowserThread::PostTask( |
+ // content::BrowserThread::UI, |
+ // FROM_HERE, |
+ // base::Bind(&VrShell::AddContentLayer, base::Unretained(this))); |
+ // } |
+ // |
// Content area positioning. |
content_rect_->SetIdentity(); |
content_rect_->Translate(kContentRectPositionDefault.x, |
@@ -143,6 +211,82 @@ void VrShell::DrawFrame(JNIEnv* env, |
frame.Submit(*buffer_viewport_list_, head_pose_); |
} |
+void VrShell::UpdateLayerTreeHost() {} |
+ |
+void VrShell::OnSwapBuffersCompleted(int pending_swap_buffers) {} |
+ |
+void VrShell::OnWebContentsReady( |
+ JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& object, |
+ const base::android::JavaParamRef<jobject>& jweb_contents) { |
+ content::WebContents* content = |
+ content::WebContents::FromJavaWebContents(jweb_contents); |
+ LOG(ERROR) << "bshe " |
+ << "====on Web Contents loading===" << content->IsLoading(); |
+ ui::ViewAndroid* view_android = content->GetNativeView(); |
+ view_android->GetLayer()->SetBackgroundColor(SK_ColorTRANSPARENT); |
+ view_android->GetLayer()->RemoveFromParent(); |
+ view_android->GetLayer()->SetOpacity(1.0); |
+ view_android->GetLayer()->SetIsDrawable(true); |
+ view_android->GetLayer()->SetHideLayerAndSubtree(false); |
+ LOG(ERROR) << "bshe " |
+ << "====width===" << content_width_; |
+ view_android->GetLayer()->SetBounds( |
+ gfx::Size(content_width_, content_height_)); |
+ content->GetRenderWidgetHostView()->Show(); |
+ root_layer_->AddChild(view_android->GetLayer()); |
+ content::RenderWidgetHost* rwh2 = |
+ content->GetRenderWidgetHostView()->GetRenderWidgetHost(); |
+ rwh2->WasResized(); |
+ compositor_->SetNeedsComposite(); |
+} |
+ |
+void VrShell::SurfaceCreated( |
+ JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& object) { |
+ compositor_->SetRootLayer(root_layer_); |
+ current_surface_format_ = 0; |
+} |
+ |
+void VrShell::SurfaceDestroyed( |
+ JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& object) { |
+ compositor_->SetSurface(NULL); |
+ current_surface_format_ = 0; |
+} |
+ |
+void VrShell::SurfaceChanged( |
+ JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& object, |
+ jint format, |
+ jint width, |
+ jint height, |
+ const base::android::JavaParamRef<jobject>& surface) { |
+ DCHECK(surface); |
+ if (current_surface_format_ != format) { |
+ current_surface_format_ = format; |
+ compositor_->SetSurface(surface); |
+ } |
+ gfx::Size size = gfx::Size(width, height); |
+ compositor_->SetWindowBounds(size); |
+ content_width_ = size.width(); |
+ content_height_ = size.height(); |
+ LOG(ERROR) << "bshe" << "======size=======" << size.ToString(); |
+ root_layer_->SetBounds(gfx::Size(content_width_, content_height_)); |
+} |
+ |
+ui::UIResourceProvider* VrShell::GetUIResourceProvider() { |
+ if (!compositor_) |
+ return NULL; |
+ return &compositor_->GetUIResourceProvider(); |
+} |
+ |
+void VrShell::SetNeedsComposite( |
+ JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& object) { |
+ compositor_->SetNeedsComposite(); |
+} |
+ |
void VrShell::DrawEye(const gvr::Mat4f& view_matrix, |
const gvr::BufferViewport& params) { |
gvr::Recti pixel_rect = |
@@ -172,6 +316,23 @@ void VrShell::DrawContentRect() { |
content_rect_->content_texture_handle, content_rect_combined_matrix); |
} |
+void VrShell::BrowserChildProcessHostDisconnected( |
+ const content::ChildProcessData& data) { |
+ LOG(WARNING) << "Child process disconnected (type=" << data.process_type |
+ << ") pid=" << data.handle << ")"; |
+ if (base::android::BuildInfo::GetInstance()->sdk_int() <= |
+ base::android::SDK_VERSION_JELLY_BEAN_MR2 && |
+ data.process_type == content::PROCESS_TYPE_GPU) { |
+ compositor_->SetSurface(nullptr); |
+ } |
+} |
+ |
+void VrShell::BrowserChildProcessCrashed(const content::ChildProcessData& data, |
+ int exit_code) { |
+ // The Android TERMINATION_STATUS_OOM_PROTECTED hack causes us to never go |
+ // through here but through BrowserChildProcessHostDisconnected() instead. |
+} |
+ |
void VrShell::OnPause(JNIEnv* env, |
const base::android::JavaParamRef<jobject>& obj) { |
if (gvr_api_ == nullptr) |
@@ -190,9 +351,16 @@ void VrShell::OnResume(JNIEnv* env, |
// ---------------------------------------------------------------------------- |
// Native JNI methods |
// ---------------------------------------------------------------------------- |
+jlong Init(JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& obj, |
+ jboolean low_mem_device, |
+ jlong native_window_android) { |
+ ui::WindowAndroid* window_android = |
+ // ui::WindowAndroid::createForTesting(); |
+ reinterpret_cast<ui::WindowAndroid*>(native_window_android); |
+ |
+ VrShell* vrShell = new VrShell(env, obj, low_mem_device, window_android); |
-jlong Init(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj) { |
- VrShell* vrShell = new VrShell(env, obj); |
return reinterpret_cast<intptr_t>(vrShell); |
} |