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 15 matching lines...) Expand all Loading... |
39 namespace { | 43 namespace { |
40 | 44 |
41 static bool g_initialized = false; | 45 static bool g_initialized = false; |
42 static webkit_glue::WebThreadImpl* g_impl_thread = NULL; | 46 static webkit_glue::WebThreadImpl* g_impl_thread = NULL; |
43 static bool g_use_direct_gl = false; | 47 static bool g_use_direct_gl = false; |
44 | 48 |
45 } // anonymous namespace | 49 } // anonymous namespace |
46 | 50 |
47 namespace content { | 51 namespace content { |
48 | 52 |
| 53 typedef std::map<int, base::android::ScopedJavaGlobalRef<jobject> > |
| 54 SurfaceMap; |
| 55 static base::LazyInstance<SurfaceMap> |
| 56 g_surface_map = LAZY_INSTANCE_INITIALIZER; |
| 57 static base::LazyInstance<base::Lock> g_surface_map_lock; |
| 58 |
49 // static | 59 // static |
50 Compositor* Compositor::Create(Client* client) { | 60 Compositor* Compositor::Create(Client* client) { |
51 return client ? new CompositorImpl(client) : NULL; | 61 return client ? new CompositorImpl(client) : NULL; |
52 } | 62 } |
53 | 63 |
54 // static | 64 // static |
55 void Compositor::Initialize() { | 65 void Compositor::Initialize() { |
56 DCHECK(!CompositorImpl::IsInitialized()); | 66 DCHECK(!CompositorImpl::IsInitialized()); |
57 g_initialized = true; | 67 g_initialized = true; |
58 } | 68 } |
(...skipping 16 matching lines...) Expand all Loading... |
75 // static | 85 // static |
76 bool CompositorImpl::IsThreadingEnabled() { | 86 bool CompositorImpl::IsThreadingEnabled() { |
77 return g_impl_thread; | 87 return g_impl_thread; |
78 } | 88 } |
79 | 89 |
80 // static | 90 // static |
81 bool CompositorImpl::UsesDirectGL() { | 91 bool CompositorImpl::UsesDirectGL() { |
82 return g_use_direct_gl; | 92 return g_use_direct_gl; |
83 } | 93 } |
84 | 94 |
| 95 // static |
| 96 jobject CompositorImpl::GetSurface(int surface_id) { |
| 97 base::AutoLock lock(g_surface_map_lock.Get()); |
| 98 SurfaceMap* surfaces = g_surface_map.Pointer(); |
| 99 SurfaceMap::iterator it = surfaces->find(surface_id); |
| 100 jobject jsurface = it == surfaces->end() ? NULL : it->second.obj(); |
| 101 |
| 102 LOG_IF(WARNING, !jsurface) << "No surface for surface id " << surface_id; |
| 103 return jsurface; |
| 104 } |
| 105 |
85 CompositorImpl::CompositorImpl(Compositor::Client* client) | 106 CompositorImpl::CompositorImpl(Compositor::Client* client) |
86 : root_layer_(cc::Layer::create()), | 107 : root_layer_(cc::Layer::create()), |
87 has_transparent_background_(false), | 108 has_transparent_background_(false), |
88 window_(NULL), | 109 window_(NULL), |
89 surface_id_(0), | 110 surface_id_(0), |
90 client_(client), | 111 client_(client), |
91 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 112 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
92 DCHECK(client); | 113 DCHECK(client); |
93 } | 114 } |
94 | 115 |
(...skipping 25 matching lines...) Expand all Loading... |
120 window_ = window; | 141 window_ = window; |
121 ANativeWindow_acquire(window); | 142 ANativeWindow_acquire(window); |
122 surface_id_ = tracker->AddSurfaceForNativeWidget(window); | 143 surface_id_ = tracker->AddSurfaceForNativeWidget(window); |
123 tracker->SetSurfaceHandle( | 144 tracker->SetSurfaceHandle( |
124 surface_id_, | 145 surface_id_, |
125 gfx::GLSurfaceHandle(gfx::kNullPluginWindow, gfx::NATIVE_DIRECT)); | 146 gfx::GLSurfaceHandle(gfx::kNullPluginWindow, gfx::NATIVE_DIRECT)); |
126 SetVisible(true); | 147 SetVisible(true); |
127 } | 148 } |
128 } | 149 } |
129 | 150 |
| 151 void CompositorImpl::SetSurface(jobject surface) { |
| 152 JNIEnv* env = base::android::AttachCurrentThread(); |
| 153 base::android::ScopedJavaLocalRef<jobject> j_surface(env, surface); |
| 154 if (surface) { |
| 155 ANativeWindow* window = ANativeWindow_fromSurface(env, surface); |
| 156 SetWindowSurface(window); |
| 157 ANativeWindow_release(window); |
| 158 { |
| 159 base::AutoLock lock(g_surface_map_lock.Get()); |
| 160 g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface)); |
| 161 } |
| 162 } else { |
| 163 { |
| 164 base::AutoLock lock(g_surface_map_lock.Get()); |
| 165 g_surface_map.Get().erase(surface_id_); |
| 166 } |
| 167 SetWindowSurface(NULL); |
| 168 } |
| 169 } |
| 170 |
130 void CompositorImpl::SetVisible(bool visible) { | 171 void CompositorImpl::SetVisible(bool visible) { |
131 if (!visible) { | 172 if (!visible) { |
132 host_.reset(); | 173 host_.reset(); |
133 } else if (!host_.get()) { | 174 } else if (!host_.get()) { |
134 cc::LayerTreeSettings settings; | 175 cc::LayerTreeSettings settings; |
135 settings.refreshRate = 60.0; | 176 settings.refreshRate = 60.0; |
136 settings.implSidePainting = false; | 177 settings.implSidePainting = false; |
137 settings.calculateTopControlsPosition = false; | 178 settings.calculateTopControlsPosition = false; |
138 settings.topControlsHeight = 0.f; | 179 settings.topControlsHeight = 0.f; |
139 settings.useMemoryManagement = false; | 180 settings.useMemoryManagement = false; |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 459 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
419 return GL_UNSIGNED_BYTE; | 460 return GL_UNSIGNED_BYTE; |
420 break; | 461 break; |
421 case ANDROID_BITMAP_FORMAT_RGB_565: | 462 case ANDROID_BITMAP_FORMAT_RGB_565: |
422 default: | 463 default: |
423 return GL_UNSIGNED_SHORT_5_6_5; | 464 return GL_UNSIGNED_SHORT_5_6_5; |
424 } | 465 } |
425 } | 466 } |
426 | 467 |
427 } // namespace content | 468 } // namespace content |
OLD | NEW |