OLD | NEW |
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/browser/renderer_host/compositor_impl_android.h" | 5 #include "content/browser/renderer_host/compositor_impl_android.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
| 9 #include <map> |
9 | 10 |
| 11 #include "base/android/jni_android.h" |
| 12 #include "base/android/scoped_java_ref.h" |
10 #include "base/bind.h" | 13 #include "base/bind.h" |
11 #include "base/command_line.h" | 14 #include "base/command_line.h" |
12 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/synchronization/lock.h" |
14 #include "cc/context_provider.h" | 18 #include "cc/context_provider.h" |
15 #include "cc/input_handler.h" | 19 #include "cc/input_handler.h" |
16 #include "cc/layer.h" | 20 #include "cc/layer.h" |
17 #include "cc/layer_tree_host.h" | 21 #include "cc/layer_tree_host.h" |
18 #include "cc/output_surface.h" | 22 #include "cc/output_surface.h" |
19 #include "cc/thread_impl.h" | 23 #include "cc/thread_impl.h" |
20 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 24 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
21 #include "content/browser/gpu/gpu_surface_tracker.h" | 25 #include "content/browser/gpu/gpu_surface_tracker.h" |
22 #include "content/browser/renderer_host/image_transport_factory_android.h" | 26 #include "content/browser/renderer_host/image_transport_factory_android.h" |
23 #include "content/common/gpu/client/gl_helper.h" | 27 #include "content/common/gpu/client/gl_helper.h" |
(...skipping 26 matching lines...) Expand all Loading... |
50 }; | 54 }; |
51 | 55 |
52 static bool g_initialized = false; | 56 static bool g_initialized = false; |
53 static webkit_glue::WebThreadImpl* g_impl_thread = NULL; | 57 static webkit_glue::WebThreadImpl* g_impl_thread = NULL; |
54 static bool g_use_direct_gl = false; | 58 static bool g_use_direct_gl = false; |
55 | 59 |
56 } // anonymous namespace | 60 } // anonymous namespace |
57 | 61 |
58 namespace content { | 62 namespace content { |
59 | 63 |
| 64 typedef std::map<int, base::android::ScopedJavaGlobalRef<jobject> > |
| 65 SurfaceMap; |
| 66 static base::LazyInstance<SurfaceMap> |
| 67 g_surface_map = LAZY_INSTANCE_INITIALIZER; |
| 68 static base::LazyInstance<base::Lock> g_surface_map_lock; |
| 69 |
60 // static | 70 // static |
61 Compositor* Compositor::Create(Client* client) { | 71 Compositor* Compositor::Create(Client* client) { |
62 return client ? new CompositorImpl(client) : NULL; | 72 return client ? new CompositorImpl(client) : NULL; |
63 } | 73 } |
64 | 74 |
65 // static | 75 // static |
66 void Compositor::Initialize() { | 76 void Compositor::Initialize() { |
67 DCHECK(!CompositorImpl::IsInitialized()); | 77 DCHECK(!CompositorImpl::IsInitialized()); |
68 g_initialized = true; | 78 g_initialized = true; |
69 } | 79 } |
(...skipping 16 matching lines...) Expand all Loading... |
86 // static | 96 // static |
87 bool CompositorImpl::IsThreadingEnabled() { | 97 bool CompositorImpl::IsThreadingEnabled() { |
88 return g_impl_thread; | 98 return g_impl_thread; |
89 } | 99 } |
90 | 100 |
91 // static | 101 // static |
92 bool CompositorImpl::UsesDirectGL() { | 102 bool CompositorImpl::UsesDirectGL() { |
93 return g_use_direct_gl; | 103 return g_use_direct_gl; |
94 } | 104 } |
95 | 105 |
| 106 // static |
| 107 jobject CompositorImpl::GetSurface(int surface_id) { |
| 108 base::AutoLock lock(g_surface_map_lock.Get()); |
| 109 SurfaceMap* surfaces = g_surface_map.Pointer(); |
| 110 SurfaceMap::iterator it = surfaces->find(surface_id); |
| 111 jobject jsurface = it == surfaces->end() ? NULL : it->second.obj(); |
| 112 |
| 113 LOG_IF(WARNING, !jsurface) << "No surface for surface id " << surface_id; |
| 114 return jsurface; |
| 115 } |
| 116 |
96 CompositorImpl::CompositorImpl(Compositor::Client* client) | 117 CompositorImpl::CompositorImpl(Compositor::Client* client) |
97 : root_layer_(cc::Layer::create()), | 118 : root_layer_(cc::Layer::create()), |
98 has_transparent_background_(false), | 119 has_transparent_background_(false), |
99 window_(NULL), | 120 window_(NULL), |
100 surface_id_(0), | 121 surface_id_(0), |
101 client_(client), | 122 client_(client), |
102 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 123 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
103 DCHECK(client); | 124 DCHECK(client); |
104 } | 125 } |
105 | 126 |
(...skipping 25 matching lines...) Expand all Loading... |
131 window_ = window; | 152 window_ = window; |
132 ANativeWindow_acquire(window); | 153 ANativeWindow_acquire(window); |
133 surface_id_ = tracker->AddSurfaceForNativeWidget(window); | 154 surface_id_ = tracker->AddSurfaceForNativeWidget(window); |
134 tracker->SetSurfaceHandle( | 155 tracker->SetSurfaceHandle( |
135 surface_id_, | 156 surface_id_, |
136 gfx::GLSurfaceHandle(gfx::kNullPluginWindow, gfx::NATIVE_DIRECT)); | 157 gfx::GLSurfaceHandle(gfx::kNullPluginWindow, gfx::NATIVE_DIRECT)); |
137 SetVisible(true); | 158 SetVisible(true); |
138 } | 159 } |
139 } | 160 } |
140 | 161 |
| 162 void CompositorImpl::SetSurface(jobject surface) { |
| 163 JNIEnv* env = base::android::AttachCurrentThread(); |
| 164 base::android::ScopedJavaLocalRef<jobject> j_surface(env, surface); |
| 165 if (surface) { |
| 166 ANativeWindow* window = ANativeWindow_fromSurface(env, surface); |
| 167 SetWindowSurface(window); |
| 168 ANativeWindow_release(window); |
| 169 { |
| 170 base::AutoLock lock(g_surface_map_lock.Get()); |
| 171 g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface)); |
| 172 } |
| 173 } else { |
| 174 { |
| 175 base::AutoLock lock(g_surface_map_lock.Get()); |
| 176 g_surface_map.Get().erase(surface_id_); |
| 177 } |
| 178 SetWindowSurface(NULL); |
| 179 } |
| 180 } |
| 181 |
141 void CompositorImpl::SetVisible(bool visible) { | 182 void CompositorImpl::SetVisible(bool visible) { |
142 if (!visible) { | 183 if (!visible) { |
143 host_.reset(); | 184 host_.reset(); |
144 } else if (!host_.get()) { | 185 } else if (!host_.get()) { |
145 cc::LayerTreeSettings settings; | 186 cc::LayerTreeSettings settings; |
146 settings.refreshRate = 60.0; | 187 settings.refreshRate = 60.0; |
147 settings.implSidePainting = false; | 188 settings.implSidePainting = false; |
148 settings.calculateTopControlsPosition = false; | 189 settings.calculateTopControlsPosition = false; |
149 settings.topControlsHeight = 0.f; | 190 settings.topControlsHeight = 0.f; |
150 settings.useMemoryManagement = false; | 191 settings.useMemoryManagement = false; |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 477 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
437 return GL_UNSIGNED_BYTE; | 478 return GL_UNSIGNED_BYTE; |
438 break; | 479 break; |
439 case ANDROID_BITMAP_FORMAT_RGB_565: | 480 case ANDROID_BITMAP_FORMAT_RGB_565: |
440 default: | 481 default: |
441 return GL_UNSIGNED_SHORT_5_6_5; | 482 return GL_UNSIGNED_SHORT_5_6_5; |
442 } | 483 } |
443 } | 484 } |
444 | 485 |
445 } // namespace content | 486 } // namespace content |
OLD | NEW |