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

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: address piman's comments 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 "base/message_loop.h"
13 #include "chrome/browser/android/tab_base_android_impl.h" 14 #include "chrome/browser/android/tab_base_android_impl.h"
14 #include "content/public/browser/android/compositor.h" 15 #include "content/public/browser/android/compositor.h"
15 #include "content/public/browser/android/draw_delegate.h" 16 #include "content/public/browser/android/draw_delegate.h"
16 #include "jni/TabManager_jni.h" 17 #include "jni/TabManager_jni.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h"
18 19
19 #include <android/native_window_jni.h> 20 #include <android/native_window_jni.h>
20 21
21 using base::android::ScopedJavaLocalRef; 22 using base::android::ScopedJavaLocalRef;
22 23
23 namespace { 24 namespace {
24 25
26 class CompositorClient : public content::Compositor::Client {
27 public:
28 virtual void ScheduleComposite() OVERRIDE;
29 };
30
25 struct GlobalState { 31 struct GlobalState {
32 CompositorClient client;
26 scoped_ptr<content::Compositor> compositor; 33 scoped_ptr<content::Compositor> compositor;
27 scoped_ptr<WebKit::WebLayer> root_layer; 34 scoped_ptr<WebKit::WebLayer> root_layer;
28 }; 35 };
29 36
30 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; 37 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER;
31 38
32 content::Compositor* GetCompositor() { 39 content::Compositor* GetCompositor() {
33 return g_global_state.Get().compositor.get(); 40 return g_global_state.Get().compositor.get();
34 } 41 }
35 42
36 static void SurfacePresented( 43 bool g_scheduled_composite = false;
piman 2012/10/13 18:04:21 nit: should this be in the global state?
37 const content::DrawDelegate::SurfacePresentedCallback& callback, 44 void Composite() {
38 uint32 sync_point) { 45 g_scheduled_composite = false;
39 callback.Run(sync_point); 46 if (GetCompositor()) {
47 GetCompositor()->Composite();
48 }
40 } 49 }
41 50
42 void DummyCallback(uint32) { } 51 void CompositorClient::ScheduleComposite() {
43 52 if (!g_scheduled_composite) {
44 static void SurfaceUpdated( 53 g_scheduled_composite = true;
45 uint64 texture, 54 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&Composite));
46 content::RenderWidgetHostView* view, 55 }
47 const content::DrawDelegate::SurfacePresentedCallback& callback) {
48 GetCompositor()->OnSurfaceUpdated(base::Bind(
49 &SurfacePresented, callback));
50 } 56 }
51 57
52 } // anonymous namespace 58 } // anonymous namespace
53 59
54 namespace chrome { 60 namespace chrome {
55 61
56 // Register native methods 62 // Register native methods
57 bool RegisterTabManager(JNIEnv* env) { 63 bool RegisterTabManager(JNIEnv* env) {
58 return RegisterNativesImpl(env); 64 return RegisterNativesImpl(env);
59 } 65 }
60 66
61 static void Init(JNIEnv* env, jclass clazz, jobject obj) { 67 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()) { 68 if (!GetCompositor()) {
66 content::Compositor::Initialize(); 69 content::Compositor::Initialize();
67 g_global_state.Get().compositor.reset(content::Compositor::Create()); 70 g_global_state.Get().compositor.reset(content::Compositor::Create(
71 &g_global_state.Get().client));
68 DCHECK(!g_global_state.Get().root_layer.get()); 72 DCHECK(!g_global_state.Get().root_layer.get());
69 g_global_state.Get().root_layer.reset(WebKit::WebLayer::create()); 73 g_global_state.Get().root_layer.reset(WebKit::WebLayer::create());
70 } 74 }
71 } 75 }
72 76
73 static void SurfaceCreated(JNIEnv* env, jclass clazz, jobject jsurface) { 77 static void SurfaceCreated(JNIEnv* env, jclass clazz, jobject jsurface) {
74 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface); 78 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface);
75 if (native_window) { 79 if (native_window) {
76 GetCompositor()->SetWindowSurface(native_window); 80 GetCompositor()->SetWindowSurface(native_window);
77 ANativeWindow_release(native_window); 81 ANativeWindow_release(native_window);
(...skipping 10 matching lines...) Expand all
88 gfx::Size size = gfx::Size(width, height); 92 gfx::Size size = gfx::Size(width, height);
89 content::DrawDelegate::GetInstance()->SetBounds(size); 93 content::DrawDelegate::GetInstance()->SetBounds(size);
90 GetCompositor()->SetWindowBounds(size); 94 GetCompositor()->SetWindowBounds(size);
91 } 95 }
92 96
93 static void ShowTab(JNIEnv* env, jclass clazz, jint jtab) { 97 static void ShowTab(JNIEnv* env, jclass clazz, jint jtab) {
94 if (!GetCompositor()) 98 if (!GetCompositor())
95 return; 99 return;
96 TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab); 100 TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab);
97 g_global_state.Get().root_layer->addChild(tab->tab_layer()); 101 g_global_state.Get().root_layer->addChild(tab->tab_layer());
98 GetCompositor()->OnSurfaceUpdated(base::Bind(&DummyCallback));
99 } 102 }
100 103
101 static void HideTab(JNIEnv* env, jclass clazz, jint jtab) { 104 static void HideTab(JNIEnv* env, jclass clazz, jint jtab) {
102 if (!GetCompositor()) 105 if (!GetCompositor())
103 return; 106 return;
104 TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab); 107 TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab);
105 tab->tab_layer()->removeFromParent(); 108 tab->tab_layer()->removeFromParent();
106 } 109 }
107 110
108 } // namespace chrome 111 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | content/browser/android/draw_delegate_impl.h » ('j') | content/shell/android/shell_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698