| 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/gl_helper.h" | 31 #include "content/common/gpu/client/gl_helper.h" |
| 30 #include "content/common/gpu/client/gpu_channel_host.h" | 32 #include "content/common/gpu/client/gpu_channel_host.h" |
| 31 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 33 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 32 #include "content/common/gpu/gpu_process_launch_causes.h" | 34 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 33 #include "content/public/browser/android/compositor_client.h" | 35 #include "content/public/browser/android/compositor_client.h" |
| 34 #include "content/public/common/content_switches.h" | 36 #include "content/public/common/content_switches.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 ANativeWindow_release(window); | 222 ANativeWindow_release(window); |
| 221 { | 223 { |
| 222 base::AutoLock lock(g_surface_map_lock.Get()); | 224 base::AutoLock lock(g_surface_map_lock.Get()); |
| 223 g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface)); | 225 g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface)); |
| 224 } | 226 } |
| 225 } | 227 } |
| 226 } | 228 } |
| 227 | 229 |
| 228 void CompositorImpl::SetVisible(bool visible) { | 230 void CompositorImpl::SetVisible(bool visible) { |
| 229 if (!visible) { | 231 if (!visible) { |
| 232 for(UIResourceMap::iterator iter = ui_resource_map_.begin(); |
| 233 iter != ui_resource_map_.end(); |
| 234 iter++) { |
| 235 scoped_ptr<cc::ScopedUIResource> resource(iter->second); |
| 236 } |
| 237 ui_resource_map_.clear(); |
| 230 host_.reset(); | 238 host_.reset(); |
| 231 } else if (!host_) { | 239 } else if (!host_) { |
| 232 cc::LayerTreeSettings settings; | 240 cc::LayerTreeSettings settings; |
| 233 settings.compositor_name = "BrowserCompositor"; | 241 settings.compositor_name = "BrowserCompositor"; |
| 234 settings.refresh_rate = 60.0; | 242 settings.refresh_rate = 60.0; |
| 235 settings.impl_side_painting = false; | 243 settings.impl_side_painting = false; |
| 236 settings.allow_antialiasing = false; | 244 settings.allow_antialiasing = false; |
| 237 settings.calculate_top_controls_position = false; | 245 settings.calculate_top_controls_position = false; |
| 238 settings.top_controls_height = 0.f; | 246 settings.top_controls_height = 0.f; |
| 239 settings.use_memory_management = false; | 247 settings.use_memory_management = false; |
| 240 settings.highp_threshold_min = 2048; | 248 settings.highp_threshold_min = 2048; |
| 241 | 249 |
| 242 // Do not clear the framebuffer when rendering into external GL contexts | 250 // Do not clear the framebuffer when rendering into external GL contexts |
| 243 // like Android View System's. | 251 // like Android View System's. |
| 244 if (UsesDirectGL()) | 252 if (UsesDirectGL()) |
| 245 settings.should_clear_root_render_pass = false; | 253 settings.should_clear_root_render_pass = false; |
| 246 | 254 |
| 247 scoped_refptr<base::SingleThreadTaskRunner> impl_thread_task_runner = | 255 scoped_refptr<base::SingleThreadTaskRunner> impl_thread_task_runner = |
| 248 g_impl_thread ? g_impl_thread->message_loop()->message_loop_proxy() | 256 g_impl_thread ? g_impl_thread->message_loop()->message_loop_proxy() |
| 249 : NULL; | 257 : NULL; |
| 250 | 258 |
| 251 host_ = cc::LayerTreeHost::Create(this, settings, impl_thread_task_runner); | 259 host_ = cc::LayerTreeHost::Create(this, settings, impl_thread_task_runner); |
| 252 host_->SetRootLayer(root_layer_); | 260 host_->SetRootLayer(root_layer_); |
| 253 | 261 |
| 254 host_->SetVisible(true); | 262 host_->SetVisible(true); |
| 255 host_->SetLayerTreeHostClientReady(); | 263 host_->SetLayerTreeHostClientReady(); |
| 256 host_->SetViewportSize(size_); | 264 host_->SetViewportSize(size_); |
| 257 host_->set_has_transparent_background(has_transparent_background_); | 265 host_->set_has_transparent_background(has_transparent_background_); |
| 266 // Need to recreate the UI resources because a new LTH has been created. |
| 267 client_->DidLoseUIResources(); |
| 258 } | 268 } |
| 259 } | 269 } |
| 260 | 270 |
| 261 void CompositorImpl::setDeviceScaleFactor(float factor) { | 271 void CompositorImpl::setDeviceScaleFactor(float factor) { |
| 262 if (host_) | 272 if (host_) |
| 263 host_->SetDeviceScaleFactor(factor); | 273 host_->SetDeviceScaleFactor(factor); |
| 264 } | 274 } |
| 265 | 275 |
| 266 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { | 276 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { |
| 267 if (size_ == size) | 277 if (size_ == size) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 279 host_->set_has_transparent_background(flag); | 289 host_->set_has_transparent_background(flag); |
| 280 } | 290 } |
| 281 | 291 |
| 282 bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) { | 292 bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) { |
| 283 if (host_) | 293 if (host_) |
| 284 return host_->CompositeAndReadback(pixels, rect); | 294 return host_->CompositeAndReadback(pixels, rect); |
| 285 else | 295 else |
| 286 return false; | 296 return false; |
| 287 } | 297 } |
| 288 | 298 |
| 299 cc::UIResourceId CompositorImpl::GenerateUIResource(gfx::JavaBitmap& bitmap) { |
| 300 if (!host_) |
| 301 return 0; |
| 302 |
| 303 void* src_pixels = bitmap.pixels(); |
| 304 gfx::Size size = bitmap.size(); |
| 305 uint8_t* dst_pixels = new uint8_t[size.GetArea() * 4]; |
| 306 memcpy(dst_pixels, src_pixels, size.GetArea() * 4); |
| 307 scoped_ptr<cc::ScopedUIResource> ui_resource = cc::ScopedUIResource::Create( |
| 308 host_.get(), |
| 309 cc::UIResourceBitmap::Create( |
| 310 dst_pixels, cc::UIResourceBitmap::RGBA8, size)); |
| 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 |
| 289 WebKit::WebGLId CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) { | 324 WebKit::WebGLId CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) { |
| 290 unsigned int texture_id = BuildBasicTexture(); | 325 unsigned int texture_id = BuildBasicTexture(); |
| 291 WebKit::WebGraphicsContext3D* context = | 326 WebKit::WebGraphicsContext3D* context = |
| 292 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | 327 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); |
| 293 if (texture_id == 0 || context->isContextLost() || | 328 if (texture_id == 0 || context->isContextLost() || |
| 294 !context->makeContextCurrent()) | 329 !context->makeContextCurrent()) |
| 295 return 0; | 330 return 0; |
| 296 WebKit::WebGLId format = GetGLFormatForBitmap(bitmap); | 331 WebKit::WebGLId format = GetGLFormatForBitmap(bitmap); |
| 297 WebKit::WebGLId type = GetGLTypeForBitmap(bitmap); | 332 WebKit::WebGLId type = GetGLTypeForBitmap(bitmap); |
| 298 | 333 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 532 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
| 498 return GL_UNSIGNED_BYTE; | 533 return GL_UNSIGNED_BYTE; |
| 499 break; | 534 break; |
| 500 case ANDROID_BITMAP_FORMAT_RGB_565: | 535 case ANDROID_BITMAP_FORMAT_RGB_565: |
| 501 default: | 536 default: |
| 502 return GL_UNSIGNED_SHORT_5_6_5; | 537 return GL_UNSIGNED_SHORT_5_6_5; |
| 503 } | 538 } |
| 504 } | 539 } |
| 505 | 540 |
| 506 } // namespace content | 541 } // namespace content |
| OLD | NEW |