Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/browser/android/content_view_render_view.h" | 5 #include "content/browser/android/content_view_render_view.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "cc/layers/layer.h" | 14 #include "cc/layers/layer.h" |
| 15 #include "content/browser/android/content_view_core_impl.h" | 15 #include "content/browser/android/content_view_core_impl.h" |
| 16 #include "content/browser/android/layer_tree_build_helper_impl.h" | |
| 16 #include "content/public/browser/android/compositor.h" | 17 #include "content/public/browser/android/compositor.h" |
| 17 #include "content/public/browser/android/content_view_layer_renderer.h" | 18 #include "content/public/browser/android/content_view_layer_renderer.h" |
| 19 #include "content/public/browser/android/layer_tree_build_helper.h" | |
| 18 #include "jni/ContentViewRenderView_jni.h" | 20 #include "jni/ContentViewRenderView_jni.h" |
| 19 #include "ui/gfx/android/java_bitmap.h" | 21 #include "ui/gfx/android/java_bitmap.h" |
| 20 #include "ui/gfx/size.h" | 22 #include "ui/gfx/size.h" |
| 21 | 23 |
| 22 #include <android/bitmap.h> | 24 #include <android/bitmap.h> |
| 23 #include <android/native_window_jni.h> | 25 #include <android/native_window_jni.h> |
| 24 | 26 |
| 25 using base::android::ScopedJavaLocalRef; | 27 using base::android::ScopedJavaLocalRef; |
| 26 | 28 |
| 27 namespace content { | 29 namespace content { |
| 28 | 30 |
| 29 // static | 31 // static |
| 30 bool ContentViewRenderView::RegisterContentViewRenderView(JNIEnv* env) { | 32 bool ContentViewRenderView::RegisterContentViewRenderView(JNIEnv* env) { |
| 31 return RegisterNativesImpl(env); | 33 return RegisterNativesImpl(env); |
| 32 } | 34 } |
| 33 | 35 |
| 34 ContentViewRenderView::ContentViewRenderView(JNIEnv* env, | 36 ContentViewRenderView::ContentViewRenderView(JNIEnv* env, |
| 35 jobject obj, | 37 jobject obj, |
| 36 gfx::NativeWindow root_window) | 38 gfx::NativeWindow root_window) |
| 37 : buffers_swapped_during_composite_(false), | 39 : buffers_swapped_during_composite_(false), |
| 40 layer_tree_build_helper_(new LayerTreeBuildHelperImpl()), | |
|
Yaron
2014/04/24 19:47:11
This is problematic. You're leaking this original
Yusuf
2014/04/28 23:18:46
Moved the ownership to content_view_render_view.
| |
| 38 root_window_(root_window), | 41 root_window_(root_window), |
| 39 current_surface_format_(0) { | 42 current_surface_format_(0) { |
| 40 java_obj_.Reset(env, obj); | 43 java_obj_.Reset(env, obj); |
| 41 } | 44 } |
| 42 | 45 |
| 43 ContentViewRenderView::~ContentViewRenderView() { | 46 ContentViewRenderView::~ContentViewRenderView() { |
| 44 } | 47 } |
| 45 | 48 |
| 49 void ContentViewRenderView::SetLayerTreeBuildHelper(JNIEnv* env, | |
| 50 jobject obj, | |
| 51 jlong native_build_helper) { | |
| 52 CHECK(native_build_helper); | |
| 53 | |
| 54 LayerTreeBuildHelper* build_helper = | |
| 55 reinterpret_cast<LayerTreeBuildHelper*>(native_build_helper); | |
| 56 layer_tree_build_helper_ = build_helper; | |
| 57 } | |
| 46 // static | 58 // static |
| 47 static jlong Init(JNIEnv* env, jobject obj, jlong native_root_window) { | 59 static jlong Init(JNIEnv* env, |
| 60 jobject obj, | |
| 61 jlong native_root_window) { | |
| 48 gfx::NativeWindow root_window = | 62 gfx::NativeWindow root_window = |
| 49 reinterpret_cast<gfx::NativeWindow>(native_root_window); | 63 reinterpret_cast<gfx::NativeWindow>(native_root_window); |
| 50 ContentViewRenderView* content_view_render_view = | 64 ContentViewRenderView* content_view_render_view = |
| 51 new ContentViewRenderView(env, obj, root_window); | 65 new ContentViewRenderView(env, obj, root_window); |
| 52 return reinterpret_cast<intptr_t>(content_view_render_view); | 66 return reinterpret_cast<intptr_t>(content_view_render_view); |
| 53 } | 67 } |
| 54 | 68 |
| 55 void ContentViewRenderView::Destroy(JNIEnv* env, jobject obj) { | 69 void ContentViewRenderView::Destroy(JNIEnv* env, jobject obj) { |
| 56 delete this; | 70 delete this; |
| 57 } | 71 } |
| 58 | 72 |
| 59 void ContentViewRenderView::SetCurrentContentViewCore( | 73 void ContentViewRenderView::SetCurrentContentViewCore( |
| 60 JNIEnv* env, jobject obj, jlong native_content_view_core) { | 74 JNIEnv* env, jobject obj, jlong native_content_view_core) { |
| 61 InitCompositor(); | 75 InitCompositor(); |
| 62 ContentViewCoreImpl* content_view_core = | 76 ContentViewCoreImpl* content_view_core = |
| 63 reinterpret_cast<ContentViewCoreImpl*>(native_content_view_core); | 77 reinterpret_cast<ContentViewCoreImpl*>(native_content_view_core); |
| 64 if (content_view_core) | 78 compositor_->SetRootLayer( |
| 65 compositor_->SetRootLayer(content_view_core->GetLayer()); | 79 layer_tree_build_helper_->GetLayerTree(content_view_core->GetLayer())); |
| 66 else | |
| 67 compositor_->SetRootLayer(cc::Layer::Create()); | |
| 68 } | 80 } |
| 69 | 81 |
| 70 void ContentViewRenderView::SurfaceCreated( | 82 void ContentViewRenderView::SurfaceCreated( |
| 71 JNIEnv* env, jobject obj) { | 83 JNIEnv* env, jobject obj) { |
| 72 current_surface_format_ = 0; | 84 current_surface_format_ = 0; |
| 73 InitCompositor(); | 85 InitCompositor(); |
| 74 } | 86 } |
| 75 | 87 |
| 76 void ContentViewRenderView::SurfaceDestroyed(JNIEnv* env, jobject obj) { | 88 void ContentViewRenderView::SurfaceDestroyed(JNIEnv* env, jobject obj) { |
| 77 compositor_->SetSurface(NULL); | 89 compositor_->SetSurface(NULL); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 | 134 |
| 123 void ContentViewRenderView::OnSwapBuffersCompleted() { | 135 void ContentViewRenderView::OnSwapBuffersCompleted() { |
| 124 JNIEnv* env = base::android::AttachCurrentThread(); | 136 JNIEnv* env = base::android::AttachCurrentThread(); |
| 125 Java_ContentViewRenderView_onSwapBuffersCompleted(env, java_obj_.obj()); | 137 Java_ContentViewRenderView_onSwapBuffersCompleted(env, java_obj_.obj()); |
| 126 } | 138 } |
| 127 | 139 |
| 128 void ContentViewRenderView::InitCompositor() { | 140 void ContentViewRenderView::InitCompositor() { |
| 129 if (!compositor_) | 141 if (!compositor_) |
| 130 compositor_.reset(Compositor::Create(this, root_window_)); | 142 compositor_.reset(Compositor::Create(this, root_window_)); |
| 131 } | 143 } |
| 132 | |
| 133 } // namespace content | 144 } // namespace content |
| OLD | NEW |