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

Side by Side Diff: content/browser/renderer_host/compositor_impl_android.cc

Issue 213493002: content: Add multi-proc surface texture support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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/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 #include <map>
10 10
11 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
12 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/containers/scoped_ptr_hash_map.h"
16 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
17 #include "base/logging.h" 16 #include "base/logging.h"
18 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
19 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
20 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
21 #include "base/threading/thread_checker.h" 20 #include "base/threading/thread_checker.h"
22 #include "cc/base/switches.h" 21 #include "cc/base/switches.h"
23 #include "cc/input/input_handler.h" 22 #include "cc/input/input_handler.h"
24 #include "cc/layers/layer.h" 23 #include "cc/layers/layer.h"
25 #include "cc/output/compositor_frame.h" 24 #include "cc/output/compositor_frame.h"
26 #include "cc/output/context_provider.h" 25 #include "cc/output/context_provider.h"
27 #include "cc/output/output_surface.h" 26 #include "cc/output/output_surface.h"
28 #include "cc/resources/scoped_ui_resource.h" 27 #include "cc/resources/scoped_ui_resource.h"
29 #include "cc/resources/ui_resource_bitmap.h" 28 #include "cc/resources/ui_resource_bitmap.h"
30 #include "cc/trees/layer_tree_host.h" 29 #include "cc/trees/layer_tree_host.h"
31 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 30 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
32 #include "content/browser/gpu/gpu_surface_tracker.h" 31 #include "content/browser/gpu/gpu_surface_tracker.h"
33 #include "content/common/gpu/client/command_buffer_proxy_impl.h" 32 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
34 #include "content/common/gpu/client/context_provider_command_buffer.h" 33 #include "content/common/gpu/client/context_provider_command_buffer.h"
35 #include "content/common/gpu/client/gl_helper.h" 34 #include "content/common/gpu/client/gl_helper.h"
36 #include "content/common/gpu/client/gpu_channel_host.h" 35 #include "content/common/gpu/client/gpu_channel_host.h"
37 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 36 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
38 #include "content/common/gpu/gpu_process_launch_causes.h" 37 #include "content/common/gpu/gpu_process_launch_causes.h"
39 #include "content/public/browser/android/compositor_client.h" 38 #include "content/public/browser/android/compositor_client.h"
39 #include "content/public/browser/browser_thread.h"
40 #include "gpu/command_buffer/client/gles2_interface.h" 40 #include "gpu/command_buffer/client/gles2_interface.h"
41 #include "third_party/khronos/GLES2/gl2.h" 41 #include "third_party/khronos/GLES2/gl2.h"
42 #include "third_party/khronos/GLES2/gl2ext.h" 42 #include "third_party/khronos/GLES2/gl2ext.h"
43 #include "third_party/skia/include/core/SkMallocPixelRef.h" 43 #include "third_party/skia/include/core/SkMallocPixelRef.h"
44 #include "ui/base/android/window_android.h" 44 #include "ui/base/android/window_android.h"
45 #include "ui/gfx/android/device_display_info.h" 45 #include "ui/gfx/android/device_display_info.h"
46 #include "ui/gfx/android/java_bitmap.h" 46 #include "ui/gfx/android/java_bitmap.h"
47 #include "ui/gfx/frame_time.h" 47 #include "ui/gfx/frame_time.h"
48 #include "ui/gl/android/scoped_java_surface.h" 48 #include "ui/gl/android/scoped_java_surface.h"
49 #include "ui/gl/android/surface_texture.h" 49 #include "ui/gl/android/surface_texture.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 protected: 130 protected:
131 TransientUIResource(cc::LayerTreeHost* host, 131 TransientUIResource(cc::LayerTreeHost* host,
132 const cc::UIResourceBitmap& bitmap) 132 const cc::UIResourceBitmap& bitmap)
133 : cc::ScopedUIResource(host, bitmap), retrieved_(false) {} 133 : cc::ScopedUIResource(host, bitmap), retrieved_(false) {}
134 134
135 private: 135 private:
136 bool retrieved_; 136 bool retrieved_;
137 }; 137 };
138 138
139 class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker { 139 class SurfaceTextureManager {
140 public: 140 public:
141 SurfaceTextureTrackerImpl() : next_surface_texture_id_(1) { 141 SurfaceTextureManager() : next_surface_texture_id_(1) {
142 thread_checker_.DetachFromThread(); 142 thread_checker_.DetachFromThread();
143 } 143 }
144 144
145 // Overridden from gfx::SurfaceTextureTracker: 145 int AddSurfaceTexture(base::ProcessHandle process_handle) {
146 virtual scoped_refptr<gfx::SurfaceTexture> AcquireSurfaceTexture(
147 int primary_id,
148 int secondary_id) OVERRIDE {
149 base::AutoLock lock(surface_textures_lock_);
150 scoped_ptr<SurfaceTextureInfo> info =
151 surface_textures_.take_and_erase(SurfaceTextureMapKey(
152 primary_id, static_cast<base::ProcessHandle>(secondary_id)));
153 return info ? info->surface_texture : NULL;
154 }
155
156 int AddSurfaceTexture(gfx::SurfaceTexture* surface_texture,
157 base::ProcessHandle process_handle) {
158 DCHECK(thread_checker_.CalledOnValidThread()); 146 DCHECK(thread_checker_.CalledOnValidThread());
159 int surface_texture_id = next_surface_texture_id_++; 147 int surface_texture_id = next_surface_texture_id_++;
160 if (next_surface_texture_id_ == INT_MAX) 148 if (next_surface_texture_id_ == INT_MAX)
161 next_surface_texture_id_ = 1; 149 next_surface_texture_id_ = 1;
162 150
163 base::AutoLock lock(surface_textures_lock_); 151 base::AutoLock lock(surface_textures_lock_);
164 SurfaceTextureMapKey key(surface_texture_id, process_handle); 152 SurfaceTextureMapKey key(surface_texture_id, process_handle);
165 DCHECK(surface_textures_.find(key) == surface_textures_.end()); 153 DCHECK(surface_textures_.find(key) == surface_textures_.end());
166 surface_textures_.set( 154 surface_textures_[key].Reset();
167 key, make_scoped_ptr(new SurfaceTextureInfo(surface_texture)));
168 return surface_texture_id; 155 return surface_texture_id;
169 } 156 }
170 157
171 void RemoveAllSurfaceTextures(base::ProcessHandle process_handle) { 158 void RemoveAllSurfaceTextures(base::ProcessHandle process_handle) {
172 DCHECK(thread_checker_.CalledOnValidThread()); 159 DCHECK(thread_checker_.CalledOnValidThread());
173 base::AutoLock lock(surface_textures_lock_); 160 base::AutoLock lock(surface_textures_lock_);
174 SurfaceTextureMap::iterator it = surface_textures_.begin(); 161 SurfaceTextureMap::iterator it = surface_textures_.begin();
175 while (it != surface_textures_.end()) { 162 while (it != surface_textures_.end()) {
176 if (it->first.second == process_handle) 163 if (it->first.second == process_handle)
177 surface_textures_.erase(it++); 164 surface_textures_.erase(it++);
178 else 165 else
179 ++it; 166 ++it;
180 } 167 }
181 } 168 }
182 169
183 jobject GetSurface(int surface_texture_id, 170 jobject GetSurface(int surface_texture_id,
184 base::ProcessHandle process_handle) const { 171 base::ProcessHandle process_handle) const {
185 base::AutoLock lock(surface_textures_lock_); 172 base::AutoLock lock(surface_textures_lock_);
186 SurfaceTextureMap::const_iterator it = surface_textures_.find( 173 SurfaceTextureMap::const_iterator it = surface_textures_.find(
187 SurfaceTextureMapKey(surface_texture_id, process_handle)); 174 SurfaceTextureMapKey(surface_texture_id, process_handle));
188 return it == surface_textures_.end() 175 return it == surface_textures_.end()
189 ? NULL 176 ? NULL
190 : it->second->surface.j_surface().obj(); 177 : it->second.obj();
191 } 178 }
192 179
193 private: 180 private:
194 struct SurfaceTextureInfo {
195 explicit SurfaceTextureInfo(gfx::SurfaceTexture* surface_texture)
196 : surface_texture(surface_texture), surface(surface_texture) {}
197
198 scoped_refptr<gfx::SurfaceTexture> surface_texture;
199 gfx::ScopedJavaSurface surface;
200 };
201
202 typedef std::pair<int, base::ProcessHandle> SurfaceTextureMapKey; 181 typedef std::pair<int, base::ProcessHandle> SurfaceTextureMapKey;
203 typedef base::ScopedPtrHashMap<SurfaceTextureMapKey, SurfaceTextureInfo> 182 typedef std::map<SurfaceTextureMapKey,
183 base::android::ScopedJavaGlobalRef<jobject> >
204 SurfaceTextureMap; 184 SurfaceTextureMap;
205 SurfaceTextureMap surface_textures_; 185 SurfaceTextureMap surface_textures_;
206 mutable base::Lock surface_textures_lock_; 186 mutable base::Lock surface_textures_lock_;
207 int next_surface_texture_id_; 187 int next_surface_texture_id_;
208 base::ThreadChecker thread_checker_; 188 base::ThreadChecker thread_checker_;
209 }; 189 };
210 base::LazyInstance<SurfaceTextureTrackerImpl> g_surface_texture_tracker = 190 base::LazyInstance<SurfaceTextureManager> g_surface_texture_manager =
211 LAZY_INSTANCE_INITIALIZER; 191 LAZY_INSTANCE_INITIALIZER;
212 192
213 static bool g_initialized = false; 193 static bool g_initialized = false;
214 194
215 } // anonymous namespace 195 } // anonymous namespace
216 196
217 namespace content { 197 namespace content {
218 198
219 typedef std::map<int, base::android::ScopedJavaGlobalRef<jobject> > 199 typedef std::map<int, base::android::ScopedJavaGlobalRef<jobject> >
220 SurfaceMap; 200 SurfaceMap;
221 static base::LazyInstance<SurfaceMap> 201 static base::LazyInstance<SurfaceMap>
222 g_surface_map = LAZY_INSTANCE_INITIALIZER; 202 g_surface_map = LAZY_INSTANCE_INITIALIZER;
223 static base::LazyInstance<base::Lock> g_surface_map_lock; 203 static base::LazyInstance<base::Lock> g_surface_map_lock;
224 204
225 // static 205 // static
226 Compositor* Compositor::Create(CompositorClient* client, 206 Compositor* Compositor::Create(CompositorClient* client,
227 gfx::NativeWindow root_window) { 207 gfx::NativeWindow root_window) {
228 return client ? new CompositorImpl(client, root_window) : NULL; 208 return client ? new CompositorImpl(client, root_window) : NULL;
229 } 209 }
230 210
231 // static 211 // static
232 void Compositor::Initialize() { 212 void Compositor::Initialize() {
233 DCHECK(!CompositorImpl::IsInitialized()); 213 DCHECK(!CompositorImpl::IsInitialized());
234 // SurfaceTextureTracker instance must be set before we create a GPU thread
235 // that could be using it to initialize GLImage instances.
236 gfx::SurfaceTextureTracker::InitInstance(g_surface_texture_tracker.Pointer());
237 g_initialized = true; 214 g_initialized = true;
238 } 215 }
239 216
240 // static 217 // static
241 bool CompositorImpl::IsInitialized() { 218 bool CompositorImpl::IsInitialized() {
242 return g_initialized; 219 return g_initialized;
243 } 220 }
244 221
245 // static 222 // static
246 jobject CompositorImpl::GetSurface(int surface_id) { 223 jobject CompositorImpl::GetSurface(int surface_id) {
247 base::AutoLock lock(g_surface_map_lock.Get()); 224 base::AutoLock lock(g_surface_map_lock.Get());
248 SurfaceMap* surfaces = g_surface_map.Pointer(); 225 SurfaceMap* surfaces = g_surface_map.Pointer();
249 SurfaceMap::iterator it = surfaces->find(surface_id); 226 SurfaceMap::iterator it = surfaces->find(surface_id);
250 jobject jsurface = it == surfaces->end() ? NULL : it->second.obj(); 227 jobject jsurface = it == surfaces->end() ? NULL : it->second.obj();
251 228
252 LOG_IF(WARNING, !jsurface) << "No surface for surface id " << surface_id; 229 LOG_IF(WARNING, !jsurface) << "No surface for surface id " << surface_id;
253 return jsurface; 230 return jsurface;
254 } 231 }
255 232
256 // static 233 // static
257 jobject CompositorImpl::GetSurfaceTextureSurface( 234 jobject CompositorImpl::GetSurfaceTextureSurface(
258 int surface_texture_id, 235 int surface_texture_id,
259 base::ProcessHandle process_handle) { 236 base::ProcessHandle process_handle) {
260 jobject jsurface = g_surface_texture_tracker.Pointer()->GetSurface( 237 jobject jsurface = g_surface_texture_manager.Pointer()->GetSurface(
261 surface_texture_id, process_handle); 238 surface_texture_id, process_handle);
262 239
263 LOG_IF(WARNING, !jsurface) << "No surface for surface texture id " 240 LOG_IF(WARNING, !jsurface) << "No surface for surface texture id "
264 << surface_texture_id; 241 << surface_texture_id;
265 return jsurface; 242 return jsurface;
266 } 243 }
267 244
268 // static 245 // static
269 int CompositorImpl::AllocateSurfaceTexture(base::ProcessHandle process_handle) { 246 void CompositorImpl::CreateSurfaceTexture(
270 const int kDummyTextureId = 0; 247 base::ProcessHandle process_handle,
271 scoped_refptr<gfx::SurfaceTexture> surface_texture = 248 const CreateSurfaceTextureCallback& callback) {
272 gfx::SurfaceTexture::Create(kDummyTextureId); 249 int surface_texture_id =
273 return g_surface_texture_tracker.Pointer()->AddSurfaceTexture( 250 g_surface_texture_manager.Pointer()->AddSurfaceTexture(process_handle);
274 surface_texture.get(), process_handle); 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
252 BrowserGpuChannelHostFactory* factory =
253 BrowserGpuChannelHostFactory::instance();
254 factory->CreateSurfaceTexture(
255 surface_texture_id,
256 process_handle,
257 base::Bind(&CompositorImpl::OnSurfaceTextureCreated,
258 surface_texture_id,
259 process_handle,
260 callback));
275 } 261 }
276 262
277 // static 263 // static
278 void CompositorImpl::DestroyAllSurfaceTextures( 264 void CompositorImpl::DestroyAllSurfaceTextures(
279 base::ProcessHandle process_handle) { 265 base::ProcessHandle process_handle) {
280 g_surface_texture_tracker.Pointer()->RemoveAllSurfaceTextures(process_handle); 266 g_surface_texture_manager.Pointer()->RemoveAllSurfaceTextures(process_handle);
267 }
268
269 // static
270 void CompositorImpl::OnSurfaceTextureCreated(
271 int surface_texture_id,
272 base::ProcessHandle process_handle,
273 const CreateSurfaceTextureCallback& callback) {
274 // TODO(reveman): Get surface texture surface from GPU service.
275 NOTIMPLEMENTED();
281 } 276 }
282 277
283 CompositorImpl::CompositorImpl(CompositorClient* client, 278 CompositorImpl::CompositorImpl(CompositorClient* client,
284 gfx::NativeWindow root_window) 279 gfx::NativeWindow root_window)
285 : root_layer_(cc::Layer::Create()), 280 : root_layer_(cc::Layer::Create()),
286 has_transparent_background_(false), 281 has_transparent_background_(false),
287 device_scale_factor_(1), 282 device_scale_factor_(1),
288 window_(NULL), 283 window_(NULL),
289 surface_id_(0), 284 surface_id_(0),
290 client_(client), 285 client_(client),
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 568
574 void CompositorImpl::DidCommit() { 569 void CompositorImpl::DidCommit() {
575 root_window_->OnCompositingDidCommit(); 570 root_window_->OnCompositingDidCommit();
576 } 571 }
577 572
578 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { 573 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) {
579 root_layer_->AddChild(layer); 574 root_layer_->AddChild(layer);
580 } 575 }
581 576
582 } // namespace content 577 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/compositor_impl_android.h ('k') | content/browser/renderer_host/render_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698