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

Side by Side Diff: chrome/android/testshell/tab_manager.cc

Issue 10968003: Add rendering support to the TestShell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased on top of test apk changes. Created 8 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/android/testshell/tab_manager.h"
6
7 #include "base/logging.h"
8 #include "base/android/jni_android.h"
9 #include "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h"
11 #include "base/bind.h"
12 #include "base/lazy_instance.h"
13 #include "chrome/browser/android/tab_base_android_impl.h"
14 #include "content/public/browser/android/compositor.h"
15 #include "content/public/browser/android/draw_delegate.h"
16 #include "jni/TabManager_jni.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h"
18
19 #include <android/native_window_jni.h>
20
21 using base::android::ScopedJavaLocalRef;
22 using content::Compositor;
23 using content::DrawDelegate;
24
25 namespace {
26
27 struct GlobalState {
28 base::android::ScopedJavaGlobalRef<jobject> jobj_;
Jay Civelli 2012/09/24 22:43:08 No "_" for struct members, it should be: base::an
David Trainor- moved to gerrit 2012/09/24 23:39:57 Done.
29 scoped_ptr<content::Compositor> compositor_;
Jay Civelli 2012/09/24 22:43:08 Nit: no need for fully qualified name, you are "us
David Trainor- moved to gerrit 2012/09/24 23:39:57 Done.
30 scoped_ptr<WebKit::WebLayer> root_layer_;
31 };
32
33 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER;
34
35 content::Compositor* GetCompositor() {
36 return g_global_state.Get().compositor_.get();
37 }
38
39 static void SurfacePresented(
40 const content::DrawDelegate::SurfacePresentedCallback& callback,
41 uint32 sync_point) {
42 callback.Run(sync_point);
43 }
44
45 void DummyCallback(uint32) { }
46
47 static void SurfaceUpdated(
48 uint64 texture,
49 content::RenderWidgetHostView* view,
50 const content::DrawDelegate::SurfacePresentedCallback& callback) {
51 GetCompositor()->OnSurfaceUpdated(base::Bind(
52 &SurfacePresented, callback));
53 }
54
55 } // anonymous namespace
56
57 namespace chrome {
58
59 // Register native methods
60 bool RegisterTabManager(JNIEnv* env) {
61 return RegisterNativesImpl(env);
62 }
63
64 static void Init(JNIEnv* env, jclass clazz, jobject obj) {
65 g_global_state.Get().jobj_.Reset(
Jay Civelli 2012/09/24 22:43:08 I don't understand why we need a GlobalRef on that
David Trainor- moved to gerrit 2012/09/24 23:39:57 After refactoring I think I don't need this at all
66 base::android::ScopedJavaLocalRef<jobject>(env, obj));
Jay Civelli 2012/09/24 22:43:08 Nit: no need for the full qualified name, you are
David Trainor- moved to gerrit 2012/09/24 23:39:57 Done.
67 content::DrawDelegate::SurfaceUpdatedCallback cb = base::Bind(
68 &SurfaceUpdated);
69 content::DrawDelegate::GetInstance()->SetUpdateCallback(cb);
70 if (!GetCompositor()) {
71 Compositor::Initialize();
72 g_global_state.Get().compositor_.reset(Compositor::Create());
73 DCHECK(!g_global_state.Get().root_layer_.get());
74 g_global_state.Get().root_layer_.reset(WebKit::WebLayer::create());
75 }
76 }
77
78 static void SurfaceCreated(
79 JNIEnv* env, jclass clazz, jobject jsurface) {
Jay Civelli 2012/09/24 22:43:08 Doesn't that fit on the prev line?
David Trainor- moved to gerrit 2012/09/24 23:39:57 Done.
80 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface);
81 if (native_window) {
82 GetCompositor()->SetWindowSurface(native_window);
83 ANativeWindow_release(native_window);
84 GetCompositor()->SetRootLayer(g_global_state.Get().root_layer_.get());
85 }
86 }
87
88 static void SurfaceDestroyed(JNIEnv* env, jclass clazz) {
89 GetCompositor()->SetWindowSurface(NULL);
90 }
91
92 static void SurfaceSetSize(
93 JNIEnv* env, jclass clazz, jint width, jint height) {
94 gfx::Size size = gfx::Size(width, height);
95 content::DrawDelegate::GetInstance()->SetBounds(size);
96 GetCompositor()->SetWindowBounds(size);
97 }
98
99 static void ShowTab(
100 JNIEnv* env, jclass clazz, jint jtab) {
Jay Civelli 2012/09/24 22:43:08 Nit: Should fit on previous line, right?
David Trainor- moved to gerrit 2012/09/24 23:39:57 Done.
101 if (!GetCompositor()) return;
Jay Civelli 2012/09/24 22:43:08 C++ style code says return should be on next line.
David Trainor- moved to gerrit 2012/09/24 23:39:57 Done.
102 TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab);
103 g_global_state.Get().root_layer_->addChild(tab->tab_layer());
104 GetCompositor()->OnSurfaceUpdated(base::Bind(&DummyCallback));
105 }
106
107 static void HideTab(
108 JNIEnv* env, jclass clazz, jint jtab) {
Jay Civelli 2012/09/24 22:43:08 Nit: Would fit on prev line.
David Trainor- moved to gerrit 2012/09/24 23:39:57 Done.
109 if (!GetCompositor()) return;
110 TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab);
111 tab->tab_layer()->removeFromParent();
112 }
113
114 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698