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

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: 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
23 namespace {
24
25 struct GlobalState {
26 base::android::ScopedJavaGlobalRef<jobject> jobj_;
27 scoped_ptr<content::Compositor> compositor_;
28 scoped_ptr<WebKit::WebLayer> root_layer_;
29 };
30
31 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER;
32
33 content::Compositor* GetCompositor() {
34 return g_global_state.Get().compositor_.get();
35 }
36
37 static void SurfacePresented(
38 const content::DrawDelegate::SurfacePresentedCallback& callback,
39 uint32 sync_point) {
40 callback.Run(sync_point);
41 }
42
43 static void SurfaceUpdated(
44 uint64 texture,
45 content::RenderWidgetHostView* view,
46 const content::DrawDelegate::SurfacePresentedCallback& callback) {
47 GetCompositor()->OnSurfaceUpdated(base::Bind(
48 &SurfacePresented, callback));
49 }
50
51 } // anonymous namespace
52
53 namespace chrome {
54
55 // Register native methods
56 bool RegisterTabManager(JNIEnv* env) {
57 return RegisterNativesImpl(env);
58 }
59
60 static void Init(JNIEnv* env, jclass clazz, jobject obj) {
61 g_global_state.Get().jobj_.Reset(env, obj);
62 content::DrawDelegate::GetInstance()->SetUpdateCallback(
63 base::Bind(&SurfaceUpdated));
64 }
65
66 static void SurfaceCreated(
67 JNIEnv* env, jclass clazz, jobject jsurface) {
68 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface);
69 if (!native_window)
70 return;
71
72 if (!GetCompositor()) {
73 content::Compositor::Initialize();
74 g_global_state.Get().compositor_.reset(content::Compositor::Create());
75 DCHECK(!g_global_state.Get().root_layer_.get());
76 g_global_state.Get().root_layer_.reset(WebKit::WebLayer::create());
77 }
78 GetCompositor()->SetWindowSurface(native_window);
79 ANativeWindow_release(native_window);
80 GetCompositor()->SetRootLayer(g_global_state.Get().root_layer_.get());
81 }
82
83 static void SurfaceDestroyed(JNIEnv* env, jclass clazz) {
84 GetCompositor()->SetWindowSurface(NULL);
85 }
86
87 static void SurfaceSetSize(
88 JNIEnv* env, jclass clazz, jint width, jint height) {
89 gfx::Size size = gfx::Size(width, height);
90 content::DrawDelegate::GetInstance()->SetBounds(size);
91 GetCompositor()->SetWindowBounds(size);
92 }
93
94 static void ShowTab(
95 JNIEnv* env, jclass clazz, jint jtab) {
96 TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab);
97 DCHECK(tab);
98 WebKit::WebLayer* layer = tab->tab_layer();
99 DCHECK(layer);
100 g_global_state.Get().root_layer_->addChild(layer);
101 }
102
103 static void HideTab(
104 JNIEnv* env, jclass clazz, jint jtab) {
105 TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab);
106 DCHECK(tab);
107 WebKit::WebLayer* layer = tab->tab_layer();
108 DCHECK(layer);
109 layer->removeFromParent();
110 }
111
112 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698