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

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

Issue 11108004: Android Browser Compositor: Add ScheduleComposite() callback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 "chrome/android/testshell/tab_manager.h" 5 #include "chrome/android/testshell/tab_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h" 10 #include "base/android/scoped_java_ref.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "chrome/browser/android/tab_base_android_impl.h" 13 #include "chrome/browser/android/tab_base_android_impl.h"
14 #include "content/public/browser/android/compositor.h" 14 #include "content/public/browser/android/compositor.h"
15 #include "content/public/browser/android/draw_delegate.h" 15 #include "content/public/browser/android/draw_delegate.h"
16 #include "jni/TabManager_jni.h" 16 #include "jni/TabManager_jni.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h"
18 18
19 #include <android/native_window_jni.h> 19 #include <android/native_window_jni.h>
20 20
21 using base::android::ScopedJavaLocalRef; 21 using base::android::ScopedJavaLocalRef;
22 22
23 namespace { 23 namespace {
24 24
25 class CompositorClient : public content::Compositor::Client {
26 public:
27 virtual void ScheduleComposite() OVERRIDE;
28 };
29
25 struct GlobalState { 30 struct GlobalState {
26 scoped_ptr<content::Compositor> compositor; 31 scoped_ptr<content::Compositor> compositor;
27 scoped_ptr<WebKit::WebLayer> root_layer; 32 scoped_ptr<WebKit::WebLayer> root_layer;
33 CompositorClient client;
28 }; 34 };
29 35
30 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; 36 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER;
31 37
32 content::Compositor* GetCompositor() { 38 content::Compositor* GetCompositor() {
33 return g_global_state.Get().compositor.get(); 39 return g_global_state.Get().compositor.get();
34 } 40 }
35 41
36 static void SurfacePresented( 42 void CompositorClient::ScheduleComposite() {
37 const content::DrawDelegate::SurfacePresentedCallback& callback, 43 // Composite immediately
38 uint32 sync_point) { 44 if (GetCompositor())
39 callback.Run(sync_point); 45 GetCompositor()->Composite();
40 }
41
42 void DummyCallback(uint32) { }
43
44 static void SurfaceUpdated(
45 uint64 texture,
46 content::RenderWidgetHostView* view,
47 const content::DrawDelegate::SurfacePresentedCallback& callback) {
48 GetCompositor()->OnSurfaceUpdated(base::Bind(
49 &SurfacePresented, callback));
50 } 46 }
51 47
52 } // anonymous namespace 48 } // anonymous namespace
53 49
54 namespace chrome { 50 namespace chrome {
55 51
56 // Register native methods 52 // Register native methods
57 bool RegisterTabManager(JNIEnv* env) { 53 bool RegisterTabManager(JNIEnv* env) {
58 return RegisterNativesImpl(env); 54 return RegisterNativesImpl(env);
59 } 55 }
60 56
61 static void Init(JNIEnv* env, jclass clazz, jobject obj) { 57 static void Init(JNIEnv* env, jclass clazz, jobject obj) {
62 content::DrawDelegate::SurfaceUpdatedCallback cb = base::Bind(
63 &SurfaceUpdated);
64 content::DrawDelegate::GetInstance()->SetUpdateCallback(cb);
65 if (!GetCompositor()) { 58 if (!GetCompositor()) {
66 content::Compositor::Initialize(); 59 content::Compositor::Initialize();
67 g_global_state.Get().compositor.reset(content::Compositor::Create()); 60 g_global_state.Get().compositor.reset(content::Compositor::Create(
61 &g_global_state.Get().client));
68 DCHECK(!g_global_state.Get().root_layer.get()); 62 DCHECK(!g_global_state.Get().root_layer.get());
69 g_global_state.Get().root_layer.reset(WebKit::WebLayer::create()); 63 g_global_state.Get().root_layer.reset(WebKit::WebLayer::create());
70 } 64 }
71 } 65 }
72 66
73 static void SurfaceCreated(JNIEnv* env, jclass clazz, jobject jsurface) { 67 static void SurfaceCreated(JNIEnv* env, jclass clazz, jobject jsurface) {
74 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface); 68 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface);
75 if (native_window) { 69 if (native_window) {
76 GetCompositor()->SetWindowSurface(native_window); 70 GetCompositor()->SetWindowSurface(native_window);
77 ANativeWindow_release(native_window); 71 ANativeWindow_release(native_window);
(...skipping 10 matching lines...) Expand all
88 gfx::Size size = gfx::Size(width, height); 82 gfx::Size size = gfx::Size(width, height);
89 content::DrawDelegate::GetInstance()->SetBounds(size); 83 content::DrawDelegate::GetInstance()->SetBounds(size);
90 GetCompositor()->SetWindowBounds(size); 84 GetCompositor()->SetWindowBounds(size);
91 } 85 }
92 86
93 static void ShowTab(JNIEnv* env, jclass clazz, jint jtab) { 87 static void ShowTab(JNIEnv* env, jclass clazz, jint jtab) {
94 if (!GetCompositor()) 88 if (!GetCompositor())
95 return; 89 return;
96 TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab); 90 TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab);
97 g_global_state.Get().root_layer->addChild(tab->tab_layer()); 91 g_global_state.Get().root_layer->addChild(tab->tab_layer());
98 GetCompositor()->OnSurfaceUpdated(base::Bind(&DummyCallback));
99 } 92 }
100 93
101 static void HideTab(JNIEnv* env, jclass clazz, jint jtab) { 94 static void HideTab(JNIEnv* env, jclass clazz, jint jtab) {
102 if (!GetCompositor()) 95 if (!GetCompositor())
103 return; 96 return;
104 TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab); 97 TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab);
105 tab->tab_layer()->removeFromParent(); 98 tab->tab_layer()->removeFromParent();
106 } 99 }
107 100
108 } // namespace chrome 101 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | content/browser/android/draw_delegate_impl.h » ('j') | content/browser/renderer_host/compositor_impl_android.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698