Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: content/browser/android/content_view_render_view.cc

Issue 201583004: Add layerTreeBuildHelper to control layer tree in ContentViewRenderView (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved setting up layer tree to a helper class Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.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"
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 if (!native_build_helper)
Yaron 2014/04/10 01:26:09 Can you CHECK this? Why can this be 0?
Yusuf 2014/04/23 00:16:14 Done.
54 return;
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_ = layer_tree_build_helper_->GetLayerTree(content_view);
65 compositor_->SetRootLayer(content_view->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 InitCompositor(); 84 InitCompositor();
73 } 85 }
74 86
75 void ContentViewRenderView::SurfaceDestroyed(JNIEnv* env, jobject obj) { 87 void ContentViewRenderView::SurfaceDestroyed(JNIEnv* env, jobject obj) {
76 compositor_->SetSurface(NULL); 88 compositor_->SetSurface(NULL);
77 current_surface_format_ = 0; 89 current_surface_format_ = 0;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 132 }
121 133
122 void ContentViewRenderView::OnSwapBuffersCompleted() { 134 void ContentViewRenderView::OnSwapBuffersCompleted() {
123 JNIEnv* env = base::android::AttachCurrentThread(); 135 JNIEnv* env = base::android::AttachCurrentThread();
124 Java_ContentViewRenderView_onSwapBuffersCompleted(env, java_obj_.obj()); 136 Java_ContentViewRenderView_onSwapBuffersCompleted(env, java_obj_.obj());
125 } 137 }
126 138
127 void ContentViewRenderView::InitCompositor() { 139 void ContentViewRenderView::InitCompositor() {
128 if (!compositor_) 140 if (!compositor_)
129 compositor_.reset(Compositor::Create(this, root_window_)); 141 compositor_.reset(Compositor::Create(this, root_window_));
142 compositor_->SetRootLayer(root_layer_);
Yaron 2014/04/10 01:26:09 I think this should stay in SetCurrentContentView,
Yusuf 2014/04/23 00:16:14 Done.
130 } 143 }
131
132 } // namespace content 144 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698