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

Side by Side Diff: content/shell/android/shell_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 "content/shell/android/shell_manager.h" 5 #include "content/shell/android/shell_manager.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"
(...skipping 12 matching lines...) Expand all
23 #include "ui/gfx/size.h" 23 #include "ui/gfx/size.h"
24 24
25 #include <android/native_window_jni.h> 25 #include <android/native_window_jni.h>
26 26
27 using base::android::ScopedJavaLocalRef; 27 using base::android::ScopedJavaLocalRef;
28 using content::Compositor; 28 using content::Compositor;
29 using content::DrawDelegate; 29 using content::DrawDelegate;
30 30
31 namespace { 31 namespace {
32 32
33 class CompositorClient : public Compositor::Client {
34 public:
35 virtual void ScheduleComposite() OVERRIDE;
36 };
37
33 struct GlobalState { 38 struct GlobalState {
34 base::android::ScopedJavaGlobalRef<jobject> j_obj; 39 base::android::ScopedJavaGlobalRef<jobject> j_obj;
35 scoped_ptr<content::Compositor> compositor; 40 scoped_ptr<content::Compositor> compositor;
36 scoped_ptr<WebKit::WebLayer> root_layer; 41 scoped_ptr<WebKit::WebLayer> root_layer;
42 CompositorClient client;
piman 2012/10/12 20:53:06 On destruction, you will destroy client - which is
no sievers 2012/10/12 22:33:51 Done.
37 }; 43 };
38 44
39 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; 45 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER;
40 46
41 content::Compositor* GetCompositor() { 47 content::Compositor* GetCompositor() {
42 return g_global_state.Get().compositor.get(); 48 return g_global_state.Get().compositor.get();
43 } 49 }
44 50
45 static void SurfacePresented( 51 void CompositorClient::ScheduleComposite() {
46 const DrawDelegate::SurfacePresentedCallback& callback, 52 // Composite immediately
piman 2012/10/12 20:53:06 I'm pretty sure you don't want to do that. This me
no sievers 2012/10/12 22:33:51 Done.
47 uint32 sync_point) { 53 if (GetCompositor())
48 callback.Run(sync_point); 54 GetCompositor()->Composite();
49 }
50
51 static void SurfaceUpdated(
52 uint64 texture,
53 content::RenderWidgetHostView* view,
54 const DrawDelegate::SurfacePresentedCallback& callback) {
55 GetCompositor()->OnSurfaceUpdated(base::Bind(
56 &SurfacePresented, callback));
57 } 55 }
58 56
59 } // anonymous namespace 57 } // anonymous namespace
60 58
61 namespace content { 59 namespace content {
62 60
63 jobject CreateShellView() { 61 jobject CreateShellView() {
64 JNIEnv* env = base::android::AttachCurrentThread(); 62 JNIEnv* env = base::android::AttachCurrentThread();
65 if (!GetCompositor()) { 63 if (!GetCompositor()) {
66 Compositor::Initialize(); 64 Compositor::Initialize();
67 g_global_state.Get().compositor.reset(Compositor::Create()); 65 g_global_state.Get().compositor.reset(Compositor::Create(
66 &g_global_state.Get().client));
68 DCHECK(!g_global_state.Get().root_layer.get()); 67 DCHECK(!g_global_state.Get().root_layer.get());
69 g_global_state.Get().root_layer.reset(WebKit::WebLayer::create()); 68 g_global_state.Get().root_layer.reset(WebKit::WebLayer::create());
70 } 69 }
71 return Java_ShellManager_createShell( 70 return Java_ShellManager_createShell(
72 env, g_global_state.Get().j_obj.obj()).Release(); 71 env, g_global_state.Get().j_obj.obj()).Release();
73 } 72 }
74 73
75 // Register native methods 74 // Register native methods
76 bool RegisterShellManager(JNIEnv* env) { 75 bool RegisterShellManager(JNIEnv* env) {
77 return RegisterNativesImpl(env); 76 return RegisterNativesImpl(env);
78 } 77 }
79 78
80 static void Init(JNIEnv* env, jclass clazz, jobject obj) { 79 static void Init(JNIEnv* env, jclass clazz, jobject obj) {
81 g_global_state.Get().j_obj.Reset( 80 g_global_state.Get().j_obj.Reset(
82 base::android::ScopedJavaLocalRef<jobject>(env, obj)); 81 base::android::ScopedJavaLocalRef<jobject>(env, obj));
83 DrawDelegate::SurfaceUpdatedCallback cb = base::Bind(
84 &SurfaceUpdated);
85 DrawDelegate::GetInstance()->SetUpdateCallback(cb);
86 } 82 }
87 83
88 static void SurfaceCreated( 84 static void SurfaceCreated(
89 JNIEnv* env, jclass clazz, jobject jsurface) { 85 JNIEnv* env, jclass clazz, jobject jsurface) {
90 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface); 86 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface);
91 if (native_window) { 87 if (native_window) {
92 GetCompositor()->SetWindowSurface(native_window); 88 GetCompositor()->SetWindowSurface(native_window);
93 ANativeWindow_release(native_window); 89 ANativeWindow_release(native_window);
94 GetCompositor()->SetRootLayer(g_global_state.Get().root_layer.get()); 90 GetCompositor()->SetRootLayer(g_global_state.Get().root_layer.get());
95 } 91 }
(...skipping 25 matching lines...) Expand all
121 void ShellAttachLayer(WebKit::WebLayer* layer) { 117 void ShellAttachLayer(WebKit::WebLayer* layer) {
122 g_global_state.Get().root_layer->addChild(layer); 118 g_global_state.Get().root_layer->addChild(layer);
123 } 119 }
124 120
125 121
126 void ShellRemoveLayer(WebKit::WebLayer* layer) { 122 void ShellRemoveLayer(WebKit::WebLayer* layer) {
127 layer->removeFromParent(); 123 layer->removeFromParent();
128 } 124 }
129 125
130 } // namespace content 126 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698