Chromium Code Reviews| 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 #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/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "cc/input/input_handler.h" | 20 #include "cc/input/input_handler.h" |
| 21 #include "cc/layers/layer.h" | 21 #include "cc/layers/layer.h" |
| 22 #include "cc/output/compositor_frame.h" | 22 #include "cc/output/compositor_frame.h" |
| 23 #include "cc/output/context_provider.h" | 23 #include "cc/output/context_provider.h" |
| 24 #include "cc/output/output_surface.h" | 24 #include "cc/output/output_surface.h" |
| 25 #include "cc/resources/scoped_ui_resource.h" | |
| 26 #include "cc/resources/ui_resource_bitmap.h" | |
| 25 #include "cc/trees/layer_tree_host.h" | 27 #include "cc/trees/layer_tree_host.h" |
| 26 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 28 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 27 #include "content/browser/gpu/gpu_surface_tracker.h" | 29 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 28 #include "content/common/gpu/client/command_buffer_proxy_impl.h" | 30 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
| 29 #include "content/common/gpu/client/context_provider_command_buffer.h" | 31 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 30 #include "content/common/gpu/client/gl_helper.h" | 32 #include "content/common/gpu/client/gl_helper.h" |
| 31 #include "content/common/gpu/client/gpu_channel_host.h" | 33 #include "content/common/gpu/client/gpu_channel_host.h" |
| 32 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 34 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 33 #include "content/common/gpu/gpu_process_launch_causes.h" | 35 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 34 #include "content/public/browser/android/compositor_client.h" | 36 #include "content/public/browser/android/compositor_client.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 ANativeWindow_release(window); | 228 ANativeWindow_release(window); |
| 227 { | 229 { |
| 228 base::AutoLock lock(g_surface_map_lock.Get()); | 230 base::AutoLock lock(g_surface_map_lock.Get()); |
| 229 g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface)); | 231 g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface)); |
| 230 } | 232 } |
| 231 } | 233 } |
| 232 } | 234 } |
| 233 | 235 |
| 234 void CompositorImpl::SetVisible(bool visible) { | 236 void CompositorImpl::SetVisible(bool visible) { |
| 235 if (!visible) { | 237 if (!visible) { |
| 238 for(UIResourceMap::iterator iter = ui_resource_map_.begin(); | |
| 239 iter != ui_resource_map_.end(); | |
| 240 iter++) { | |
| 241 scoped_ptr<cc::ScopedUIResource> resource(iter->second); | |
| 242 } | |
| 243 ui_resource_map_.clear(); | |
| 236 host_.reset(); | 244 host_.reset(); |
| 237 } else if (!host_) { | 245 } else if (!host_) { |
| 238 cc::LayerTreeSettings settings; | 246 cc::LayerTreeSettings settings; |
| 239 settings.compositor_name = "BrowserCompositor"; | 247 settings.compositor_name = "BrowserCompositor"; |
| 240 settings.refresh_rate = 60.0; | 248 settings.refresh_rate = 60.0; |
| 241 settings.impl_side_painting = false; | 249 settings.impl_side_painting = false; |
| 242 settings.allow_antialiasing = false; | 250 settings.allow_antialiasing = false; |
| 243 settings.calculate_top_controls_position = false; | 251 settings.calculate_top_controls_position = false; |
| 244 settings.top_controls_height = 0.f; | 252 settings.top_controls_height = 0.f; |
| 245 settings.use_memory_management = false; | 253 settings.use_memory_management = false; |
| 246 settings.highp_threshold_min = 2048; | 254 settings.highp_threshold_min = 2048; |
| 247 | 255 |
| 248 // Do not clear the framebuffer when rendering into external GL contexts | 256 // Do not clear the framebuffer when rendering into external GL contexts |
| 249 // like Android View System's. | 257 // like Android View System's. |
| 250 if (UsesDirectGL()) | 258 if (UsesDirectGL()) |
| 251 settings.should_clear_root_render_pass = false; | 259 settings.should_clear_root_render_pass = false; |
| 252 | 260 |
| 253 scoped_refptr<base::SingleThreadTaskRunner> impl_thread_task_runner = | 261 scoped_refptr<base::SingleThreadTaskRunner> impl_thread_task_runner = |
| 254 g_impl_thread ? g_impl_thread->message_loop()->message_loop_proxy() | 262 g_impl_thread ? g_impl_thread->message_loop()->message_loop_proxy() |
| 255 : NULL; | 263 : NULL; |
| 256 | 264 |
| 257 host_ = cc::LayerTreeHost::Create(this, settings, impl_thread_task_runner); | 265 host_ = cc::LayerTreeHost::Create(this, settings, impl_thread_task_runner); |
| 258 host_->SetRootLayer(root_layer_); | 266 host_->SetRootLayer(root_layer_); |
| 259 | 267 |
| 260 host_->SetVisible(true); | 268 host_->SetVisible(true); |
| 261 host_->SetLayerTreeHostClientReady(); | 269 host_->SetLayerTreeHostClientReady(); |
| 262 host_->SetViewportSize(size_); | 270 host_->SetViewportSize(size_); |
| 263 host_->set_has_transparent_background(has_transparent_background_); | 271 host_->set_has_transparent_background(has_transparent_background_); |
| 272 // Need to recreate the UI resources because a new LTH has been created. | |
|
danakj
2013/08/27 15:42:48
LTH -> LayerTreeHost
powei
2013/08/27 22:39:28
Done.
| |
| 273 client_->DidLoseUIResources(); | |
| 264 } | 274 } |
| 265 } | 275 } |
| 266 | 276 |
| 267 void CompositorImpl::setDeviceScaleFactor(float factor) { | 277 void CompositorImpl::setDeviceScaleFactor(float factor) { |
| 268 if (host_) | 278 if (host_) |
| 269 host_->SetDeviceScaleFactor(factor); | 279 host_->SetDeviceScaleFactor(factor); |
| 270 } | 280 } |
| 271 | 281 |
| 272 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { | 282 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { |
| 273 if (size_ == size) | 283 if (size_ == size) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 285 host_->set_has_transparent_background(flag); | 295 host_->set_has_transparent_background(flag); |
| 286 } | 296 } |
| 287 | 297 |
| 288 bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) { | 298 bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) { |
| 289 if (host_) | 299 if (host_) |
| 290 return host_->CompositeAndReadback(pixels, rect); | 300 return host_->CompositeAndReadback(pixels, rect); |
| 291 else | 301 else |
| 292 return false; | 302 return false; |
| 293 } | 303 } |
| 294 | 304 |
| 305 cc::UIResourceId CompositorImpl::GenerateUIResource( | |
| 306 scoped_refptr<cc::UIResourceBitmap> bitmap) { | |
| 307 if (!host_) | |
| 308 return 0; | |
| 309 scoped_ptr<cc::ScopedUIResource> ui_resource = | |
| 310 cc::ScopedUIResource::Create(host_.get(), bitmap); | |
| 311 cc::UIResourceId id = ui_resource->id(); | |
| 312 ui_resource_map_[id] = ui_resource.release(); | |
| 313 return id; | |
| 314 } | |
| 315 | |
| 316 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { | |
| 317 UIResourceMap::iterator iter = ui_resource_map_.find(resource_id); | |
| 318 if (iter != ui_resource_map_.end()) { | |
| 319 scoped_ptr<cc::ScopedUIResource> resource(iter->second); | |
| 320 ui_resource_map_.erase(resource_id); | |
| 321 } | |
| 322 } | |
| 323 | |
| 295 WebKit::WebGLId CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) { | 324 WebKit::WebGLId CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) { |
| 296 unsigned int texture_id = BuildBasicTexture(); | 325 unsigned int texture_id = BuildBasicTexture(); |
| 297 WebKit::WebGraphicsContext3D* context = | 326 WebKit::WebGraphicsContext3D* context = |
| 298 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | 327 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); |
| 299 if (texture_id == 0 || context->isContextLost() || | 328 if (texture_id == 0 || context->isContextLost() || |
| 300 !context->makeContextCurrent()) | 329 !context->makeContextCurrent()) |
| 301 return 0; | 330 return 0; |
| 302 WebKit::WebGLId format = GetGLFormatForBitmap(bitmap); | 331 WebKit::WebGLId format = GetGLFormatForBitmap(bitmap); |
| 303 WebKit::WebGLId type = GetGLTypeForBitmap(bitmap); | 332 WebKit::WebGLId type = GetGLTypeForBitmap(bitmap); |
| 304 | 333 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 553 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
| 525 return GL_UNSIGNED_BYTE; | 554 return GL_UNSIGNED_BYTE; |
| 526 break; | 555 break; |
| 527 case ANDROID_BITMAP_FORMAT_RGB_565: | 556 case ANDROID_BITMAP_FORMAT_RGB_565: |
| 528 default: | 557 default: |
| 529 return GL_UNSIGNED_SHORT_5_6_5; | 558 return GL_UNSIGNED_SHORT_5_6_5; |
| 530 } | 559 } |
| 531 } | 560 } |
| 532 | 561 |
| 533 } // namespace content | 562 } // namespace content |
| OLD | NEW |