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