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/public/browser/android/compositor.h" | 16 #include "content/public/browser/android/compositor.h" |
17 #include "content/public/browser/android/content_view_layer_renderer.h" | 17 #include "content/public/browser/android/content_view_layer_renderer.h" |
18 #include "content/public/browser/android/layer_tree_build_helper.h" | |
18 #include "jni/ContentViewRenderView_jni.h" | 19 #include "jni/ContentViewRenderView_jni.h" |
19 #include "ui/gfx/android/java_bitmap.h" | 20 #include "ui/gfx/android/java_bitmap.h" |
20 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
21 | 22 |
22 #include <android/bitmap.h> | 23 #include <android/bitmap.h> |
23 #include <android/native_window_jni.h> | 24 #include <android/native_window_jni.h> |
24 | 25 |
25 using base::android::ScopedJavaLocalRef; | 26 using base::android::ScopedJavaLocalRef; |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 | 29 |
29 // static | 30 // static |
30 bool ContentViewRenderView::RegisterContentViewRenderView(JNIEnv* env) { | 31 bool ContentViewRenderView::RegisterContentViewRenderView(JNIEnv* env) { |
31 return RegisterNativesImpl(env); | 32 return RegisterNativesImpl(env); |
32 } | 33 } |
33 | 34 |
34 ContentViewRenderView::ContentViewRenderView(JNIEnv* env, | 35 ContentViewRenderView::ContentViewRenderView(JNIEnv* env, |
35 jobject obj, | 36 jobject obj, |
36 gfx::NativeWindow root_window) | 37 gfx::NativeWindow root_window) |
37 : buffers_swapped_during_composite_(false), | 38 : buffers_swapped_during_composite_(false), |
39 root_layer_(cc::Layer::Create()), | |
40 layer_tree_build_helper_(new LayerTreeBuildHelper()), | |
38 root_window_(root_window), | 41 root_window_(root_window), |
39 current_surface_format_(0) { | 42 current_surface_format_(0) { |
43 root_layer_->SetIsDrawable(true); | |
40 java_obj_.Reset(env, obj); | 44 java_obj_.Reset(env, obj); |
41 } | 45 } |
42 | 46 |
43 ContentViewRenderView::~ContentViewRenderView() { | 47 ContentViewRenderView::~ContentViewRenderView() { |
44 } | 48 } |
45 | 49 |
50 void ContentViewRenderView::SetLayerTreeBuildHelper(JNIEnv* env, | |
51 jobject obj, | |
52 jlong native_build_helper) { | |
53 CHECK(native_build_helper); | |
54 | |
55 LayerTreeBuildHelper* build_helper = | |
56 reinterpret_cast<LayerTreeBuildHelper*>(native_build_helper); | |
57 layer_tree_build_helper_ = build_helper; | |
58 } | |
46 // static | 59 // static |
47 static jlong Init(JNIEnv* env, jobject obj, jlong native_root_window) { | 60 static jlong Init(JNIEnv* env, |
61 jobject obj, | |
62 jlong native_root_window) { | |
48 gfx::NativeWindow root_window = | 63 gfx::NativeWindow root_window = |
49 reinterpret_cast<gfx::NativeWindow>(native_root_window); | 64 reinterpret_cast<gfx::NativeWindow>(native_root_window); |
50 ContentViewRenderView* content_view_render_view = | 65 ContentViewRenderView* content_view_render_view = |
51 new ContentViewRenderView(env, obj, root_window); | 66 new ContentViewRenderView(env, obj, root_window); |
52 return reinterpret_cast<intptr_t>(content_view_render_view); | 67 return reinterpret_cast<intptr_t>(content_view_render_view); |
53 } | 68 } |
54 | 69 |
55 void ContentViewRenderView::Destroy(JNIEnv* env, jobject obj) { | 70 void ContentViewRenderView::Destroy(JNIEnv* env, jobject obj) { |
56 delete this; | 71 delete this; |
57 } | 72 } |
58 | 73 |
59 void ContentViewRenderView::SetCurrentContentView( | 74 void ContentViewRenderView::SetCurrentContentView( |
60 JNIEnv* env, jobject obj, jlong native_content_view) { | 75 JNIEnv* env, jobject obj, jlong native_content_view) { |
61 InitCompositor(); | 76 InitCompositor(); |
62 ContentViewCoreImpl* content_view = | 77 ContentViewCoreImpl* content_view = |
63 reinterpret_cast<ContentViewCoreImpl*>(native_content_view); | 78 reinterpret_cast<ContentViewCoreImpl*>(native_content_view); |
64 if (content_view) | 79 root_layer_ = |
Yaron
2014/04/23 20:57:46
Actually, do we need a ref? Isn't it sufficient to
Yusuf
2014/04/24 00:06:03
Done.
| |
65 compositor_->SetRootLayer(content_view->GetLayer()); | 80 layer_tree_build_helper_->GetLayerTree(content_view->GetLayer()); |
66 else | 81 compositor_->SetRootLayer(root_layer_); |
67 compositor_->SetRootLayer(cc::Layer::Create()); | |
68 } | 82 } |
69 | 83 |
70 void ContentViewRenderView::SurfaceCreated( | 84 void ContentViewRenderView::SurfaceCreated( |
71 JNIEnv* env, jobject obj) { | 85 JNIEnv* env, jobject obj) { |
72 InitCompositor(); | 86 InitCompositor(); |
73 } | 87 } |
74 | 88 |
75 void ContentViewRenderView::SurfaceDestroyed(JNIEnv* env, jobject obj) { | 89 void ContentViewRenderView::SurfaceDestroyed(JNIEnv* env, jobject obj) { |
76 compositor_->SetSurface(NULL); | 90 compositor_->SetSurface(NULL); |
77 current_surface_format_ = 0; | 91 current_surface_format_ = 0; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 | 135 |
122 void ContentViewRenderView::OnSwapBuffersCompleted() { | 136 void ContentViewRenderView::OnSwapBuffersCompleted() { |
123 JNIEnv* env = base::android::AttachCurrentThread(); | 137 JNIEnv* env = base::android::AttachCurrentThread(); |
124 Java_ContentViewRenderView_onSwapBuffersCompleted(env, java_obj_.obj()); | 138 Java_ContentViewRenderView_onSwapBuffersCompleted(env, java_obj_.obj()); |
125 } | 139 } |
126 | 140 |
127 void ContentViewRenderView::InitCompositor() { | 141 void ContentViewRenderView::InitCompositor() { |
128 if (!compositor_) | 142 if (!compositor_) |
129 compositor_.reset(Compositor::Create(this, root_window_)); | 143 compositor_.reset(Compositor::Create(this, root_window_)); |
130 } | 144 } |
131 | |
132 } // namespace content | 145 } // namespace content |
OLD | NEW |