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

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
« no previous file with comments | « content/public/browser/android/draw_delegate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h"
13 #include "content/shell/shell.h" 14 #include "content/shell/shell.h"
14 #include "content/shell/shell_browser_context.h" 15 #include "content/shell/shell_browser_context.h"
15 #include "content/shell/shell_content_browser_client.h" 16 #include "content/shell/shell_content_browser_client.h"
16 #include "content/public/browser/android/compositor.h" 17 #include "content/public/browser/android/compositor.h"
17 #include "content/public/browser/android/draw_delegate.h" 18 #include "content/public/browser/android/draw_delegate.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 #include "content/shell/shell.h" 20 #include "content/shell/shell.h"
20 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
21 #include "jni/ShellManager_jni.h" 22 #include "jni/ShellManager_jni.h"
22 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" 23 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h"
23 #include "ui/gfx/size.h" 24 #include "ui/gfx/size.h"
24 25
25 #include <android/native_window_jni.h> 26 #include <android/native_window_jni.h>
26 27
27 using base::android::ScopedJavaLocalRef; 28 using base::android::ScopedJavaLocalRef;
28 using content::Compositor; 29 using content::Compositor;
29 using content::DrawDelegate; 30 using content::DrawDelegate;
30 31
31 namespace { 32 namespace {
32 33
34 class CompositorClient : public Compositor::Client {
35 public:
36 virtual void ScheduleComposite() OVERRIDE;
37 };
38
33 struct GlobalState { 39 struct GlobalState {
40 GlobalState()
41 : g_scheduled_composite(false) {}
34 base::android::ScopedJavaGlobalRef<jobject> j_obj; 42 base::android::ScopedJavaGlobalRef<jobject> j_obj;
43 CompositorClient client;
35 scoped_ptr<content::Compositor> compositor; 44 scoped_ptr<content::Compositor> compositor;
36 scoped_ptr<WebKit::WebLayer> root_layer; 45 scoped_ptr<WebKit::WebLayer> root_layer;
46 bool g_scheduled_composite;
37 }; 47 };
38 48
39 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; 49 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER;
40 50
41 content::Compositor* GetCompositor() { 51 content::Compositor* GetCompositor() {
42 return g_global_state.Get().compositor.get(); 52 return g_global_state.Get().compositor.get();
43 } 53 }
44 54
45 static void SurfacePresented( 55 void Composite() {
46 const DrawDelegate::SurfacePresentedCallback& callback, 56 g_global_state.Get().g_scheduled_composite = false;
47 uint32 sync_point) { 57 if (GetCompositor()) {
48 callback.Run(sync_point); 58 GetCompositor()->Composite();
59 }
49 } 60 }
50 61
51 static void SurfaceUpdated( 62 void CompositorClient::ScheduleComposite() {
52 uint64 texture, 63 if (!g_global_state.Get().g_scheduled_composite) {
53 content::RenderWidgetHostView* view, 64 g_global_state.Get().g_scheduled_composite = true;
54 const DrawDelegate::SurfacePresentedCallback& callback) { 65 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&Composite));
55 GetCompositor()->OnSurfaceUpdated(base::Bind( 66 }
56 &SurfacePresented, callback));
57 } 67 }
58 68
59 } // anonymous namespace 69 } // anonymous namespace
60 70
61 namespace content { 71 namespace content {
62 72
63 jobject CreateShellView() { 73 jobject CreateShellView() {
64 JNIEnv* env = base::android::AttachCurrentThread(); 74 JNIEnv* env = base::android::AttachCurrentThread();
65 if (!GetCompositor()) { 75 if (!GetCompositor()) {
66 Compositor::Initialize(); 76 Compositor::Initialize();
67 g_global_state.Get().compositor.reset(Compositor::Create()); 77 g_global_state.Get().compositor.reset(Compositor::Create(
78 &g_global_state.Get().client));
68 DCHECK(!g_global_state.Get().root_layer.get()); 79 DCHECK(!g_global_state.Get().root_layer.get());
69 g_global_state.Get().root_layer.reset(WebKit::WebLayer::create()); 80 g_global_state.Get().root_layer.reset(WebKit::WebLayer::create());
70 } 81 }
71 return Java_ShellManager_createShell( 82 return Java_ShellManager_createShell(
72 env, g_global_state.Get().j_obj.obj()).Release(); 83 env, g_global_state.Get().j_obj.obj()).Release();
73 } 84 }
74 85
75 // Register native methods 86 // Register native methods
76 bool RegisterShellManager(JNIEnv* env) { 87 bool RegisterShellManager(JNIEnv* env) {
77 return RegisterNativesImpl(env); 88 return RegisterNativesImpl(env);
78 } 89 }
79 90
80 static void Init(JNIEnv* env, jclass clazz, jobject obj) { 91 static void Init(JNIEnv* env, jclass clazz, jobject obj) {
81 g_global_state.Get().j_obj.Reset( 92 g_global_state.Get().j_obj.Reset(
82 base::android::ScopedJavaLocalRef<jobject>(env, obj)); 93 base::android::ScopedJavaLocalRef<jobject>(env, obj));
83 DrawDelegate::SurfaceUpdatedCallback cb = base::Bind(
84 &SurfaceUpdated);
85 DrawDelegate::GetInstance()->SetUpdateCallback(cb);
86 } 94 }
87 95
88 static void SurfaceCreated( 96 static void SurfaceCreated(
89 JNIEnv* env, jclass clazz, jobject jsurface) { 97 JNIEnv* env, jclass clazz, jobject jsurface) {
90 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface); 98 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface);
91 if (native_window) { 99 if (native_window) {
92 GetCompositor()->SetWindowSurface(native_window); 100 GetCompositor()->SetWindowSurface(native_window);
93 ANativeWindow_release(native_window); 101 ANativeWindow_release(native_window);
94 GetCompositor()->SetRootLayer(g_global_state.Get().root_layer.get()); 102 GetCompositor()->SetRootLayer(g_global_state.Get().root_layer.get());
95 } 103 }
(...skipping 25 matching lines...) Expand all
121 void ShellAttachLayer(WebKit::WebLayer* layer) { 129 void ShellAttachLayer(WebKit::WebLayer* layer) {
122 g_global_state.Get().root_layer->addChild(layer); 130 g_global_state.Get().root_layer->addChild(layer);
123 } 131 }
124 132
125 133
126 void ShellRemoveLayer(WebKit::WebLayer* layer) { 134 void ShellRemoveLayer(WebKit::WebLayer* layer) {
127 layer->removeFromParent(); 135 layer->removeFromParent();
128 } 136 }
129 137
130 } // namespace content 138 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/android/draw_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698