| 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/render_widget_host_view_android.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 6 | 6 |
| 7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "cc/layers/surface_layer.h" | 27 #include "cc/layers/surface_layer.h" |
| 28 #include "cc/output/compositor_frame.h" | 28 #include "cc/output/compositor_frame.h" |
| 29 #include "cc/output/copy_output_request.h" | 29 #include "cc/output/copy_output_request.h" |
| 30 #include "cc/output/copy_output_result.h" | 30 #include "cc/output/copy_output_result.h" |
| 31 #include "cc/output/latency_info_swap_promise.h" | 31 #include "cc/output/latency_info_swap_promise.h" |
| 32 #include "cc/resources/single_release_callback.h" | 32 #include "cc/resources/single_release_callback.h" |
| 33 #include "cc/surfaces/surface.h" | 33 #include "cc/surfaces/surface.h" |
| 34 #include "cc/surfaces/surface_hittest.h" | 34 #include "cc/surfaces/surface_hittest.h" |
| 35 #include "cc/surfaces/surface_manager.h" | 35 #include "cc/surfaces/surface_manager.h" |
| 36 #include "cc/trees/layer_tree_host.h" | 36 #include "cc/trees/layer_tree_host.h" |
| 37 #include "components/display_compositor/gl_helper.h" | 37 #include "components/viz/display_compositor/gl_helper.h" |
| 38 #include "content/browser/accessibility/browser_accessibility_manager_android.h" | 38 #include "content/browser/accessibility/browser_accessibility_manager_android.h" |
| 39 #include "content/browser/android/composited_touch_handle_drawable.h" | 39 #include "content/browser/android/composited_touch_handle_drawable.h" |
| 40 #include "content/browser/android/content_view_core_impl.h" | 40 #include "content/browser/android/content_view_core_impl.h" |
| 41 #include "content/browser/android/ime_adapter_android.h" | 41 #include "content/browser/android/ime_adapter_android.h" |
| 42 #include "content/browser/android/overscroll_controller_android.h" | 42 #include "content/browser/android/overscroll_controller_android.h" |
| 43 #include "content/browser/android/selection_popup_controller.h" | 43 #include "content/browser/android/selection_popup_controller.h" |
| 44 #include "content/browser/android/synchronous_compositor_host.h" | 44 #include "content/browser/android/synchronous_compositor_host.h" |
| 45 #include "content/browser/compositor/surface_utils.h" | 45 #include "content/browser/compositor/surface_utils.h" |
| 46 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 46 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
| 47 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 47 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 120 } |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 using base::android::ApplicationState; | 123 using base::android::ApplicationState; |
| 124 using base::android::ApplicationStatusListener; | 124 using base::android::ApplicationStatusListener; |
| 125 | 125 |
| 126 class GLHelperHolder { | 126 class GLHelperHolder { |
| 127 public: | 127 public: |
| 128 static GLHelperHolder* Create(); | 128 static GLHelperHolder* Create(); |
| 129 | 129 |
| 130 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); } | 130 viz::GLHelper* gl_helper() { return gl_helper_.get(); } |
| 131 bool IsLost() { | 131 bool IsLost() { |
| 132 if (!gl_helper_) | 132 if (!gl_helper_) |
| 133 return true; | 133 return true; |
| 134 return provider_->ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR; | 134 return provider_->ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR; |
| 135 } | 135 } |
| 136 | 136 |
| 137 void ReleaseIfPossible(); | 137 void ReleaseIfPossible(); |
| 138 | 138 |
| 139 private: | 139 private: |
| 140 GLHelperHolder(); | 140 GLHelperHolder(); |
| 141 void Initialize(); | 141 void Initialize(); |
| 142 void OnContextLost(); | 142 void OnContextLost(); |
| 143 void OnApplicationStatusChanged(ApplicationState new_state); | 143 void OnApplicationStatusChanged(ApplicationState new_state); |
| 144 | 144 |
| 145 scoped_refptr<ui::ContextProviderCommandBuffer> provider_; | 145 scoped_refptr<ui::ContextProviderCommandBuffer> provider_; |
| 146 std::unique_ptr<display_compositor::GLHelper> gl_helper_; | 146 std::unique_ptr<viz::GLHelper> gl_helper_; |
| 147 | 147 |
| 148 // Set to |false| if there are only stopped activities (or none). | 148 // Set to |false| if there are only stopped activities (or none). |
| 149 bool has_running_or_paused_activities_; | 149 bool has_running_or_paused_activities_; |
| 150 | 150 |
| 151 std::unique_ptr<ApplicationStatusListener> app_status_listener_; | 151 std::unique_ptr<ApplicationStatusListener> app_status_listener_; |
| 152 | 152 |
| 153 DISALLOW_COPY_AND_ASSIGN(GLHelperHolder); | 153 DISALLOW_COPY_AND_ASSIGN(GLHelperHolder); |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 GLHelperHolder::GLHelperHolder() | 156 GLHelperHolder::GLHelperHolder() |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 automatic_flushes, support_locking, limits, attributes, nullptr, | 207 automatic_flushes, support_locking, limits, attributes, nullptr, |
| 208 ui::command_buffer_metrics::BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT); | 208 ui::command_buffer_metrics::BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT); |
| 209 if (!provider_->BindToCurrentThread()) | 209 if (!provider_->BindToCurrentThread()) |
| 210 return; | 210 return; |
| 211 provider_->ContextGL()->TraceBeginCHROMIUM( | 211 provider_->ContextGL()->TraceBeginCHROMIUM( |
| 212 "gpu_toplevel", | 212 "gpu_toplevel", |
| 213 base::StringPrintf("CmdBufferImageTransportFactory-%p", provider_.get()) | 213 base::StringPrintf("CmdBufferImageTransportFactory-%p", provider_.get()) |
| 214 .c_str()); | 214 .c_str()); |
| 215 provider_->SetLostContextCallback( | 215 provider_->SetLostContextCallback( |
| 216 base::Bind(&GLHelperHolder::OnContextLost, base::Unretained(this))); | 216 base::Bind(&GLHelperHolder::OnContextLost, base::Unretained(this))); |
| 217 gl_helper_.reset(new display_compositor::GLHelper( | 217 gl_helper_.reset( |
| 218 provider_->ContextGL(), provider_->ContextSupport())); | 218 new viz::GLHelper(provider_->ContextGL(), provider_->ContextSupport())); |
| 219 | 219 |
| 220 // Unretained() is safe because |this| owns the following two callbacks. | 220 // Unretained() is safe because |this| owns the following two callbacks. |
| 221 app_status_listener_.reset(new ApplicationStatusListener(base::Bind( | 221 app_status_listener_.reset(new ApplicationStatusListener(base::Bind( |
| 222 &GLHelperHolder::OnApplicationStatusChanged, base::Unretained(this)))); | 222 &GLHelperHolder::OnApplicationStatusChanged, base::Unretained(this)))); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void GLHelperHolder::ReleaseIfPossible() { | 225 void GLHelperHolder::ReleaseIfPossible() { |
| 226 if (!has_running_or_paused_activities_ && !g_pending_readback_lock) { | 226 if (!has_running_or_paused_activities_ && !g_pending_readback_lock) { |
| 227 gl_helper_.reset(); | 227 gl_helper_.reset(); |
| 228 provider_ = nullptr; | 228 provider_ = nullptr; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 257 delete g_readback_helper_holder; | 257 delete g_readback_helper_holder; |
| 258 g_readback_helper_holder = nullptr; | 258 g_readback_helper_holder = nullptr; |
| 259 } | 259 } |
| 260 | 260 |
| 261 if (!g_readback_helper_holder) | 261 if (!g_readback_helper_holder) |
| 262 g_readback_helper_holder = GLHelperHolder::Create(); | 262 g_readback_helper_holder = GLHelperHolder::Create(); |
| 263 | 263 |
| 264 return g_readback_helper_holder; | 264 return g_readback_helper_holder; |
| 265 } | 265 } |
| 266 | 266 |
| 267 display_compositor::GLHelper* GetPostReadbackGLHelper() { | 267 viz::GLHelper* GetPostReadbackGLHelper() { |
| 268 bool create_if_necessary = true; | 268 bool create_if_necessary = true; |
| 269 return GetPostReadbackGLHelperHolder(create_if_necessary)->gl_helper(); | 269 return GetPostReadbackGLHelperHolder(create_if_necessary)->gl_helper(); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void ReleaseGLHelper() { | 272 void ReleaseGLHelper() { |
| 273 bool create_if_necessary = false; | 273 bool create_if_necessary = false; |
| 274 GLHelperHolder* holder = GetPostReadbackGLHelperHolder(create_if_necessary); | 274 GLHelperHolder* holder = GetPostReadbackGLHelperHolder(create_if_necessary); |
| 275 | 275 |
| 276 if (holder) { | 276 if (holder) { |
| 277 holder->ReleaseIfPossible(); | 277 holder->ReleaseIfPossible(); |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 void CopyFromCompositingSurfaceFinished( | 281 void CopyFromCompositingSurfaceFinished( |
| 282 const ReadbackRequestCallback& callback, | 282 const ReadbackRequestCallback& callback, |
| 283 std::unique_ptr<cc::SingleReleaseCallback> release_callback, | 283 std::unique_ptr<cc::SingleReleaseCallback> release_callback, |
| 284 std::unique_ptr<SkBitmap> bitmap, | 284 std::unique_ptr<SkBitmap> bitmap, |
| 285 const base::TimeTicks& start_time, | 285 const base::TimeTicks& start_time, |
| 286 scoped_refptr<PendingReadbackLock> readback_lock, | 286 scoped_refptr<PendingReadbackLock> readback_lock, |
| 287 bool result) { | 287 bool result) { |
| 288 TRACE_EVENT0( | 288 TRACE_EVENT0( |
| 289 "cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceFinished"); | 289 "cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceFinished"); |
| 290 gpu::SyncToken sync_token; | 290 gpu::SyncToken sync_token; |
| 291 if (result) { | 291 if (result) { |
| 292 display_compositor::GLHelper* gl_helper = GetPostReadbackGLHelper(); | 292 viz::GLHelper* gl_helper = GetPostReadbackGLHelper(); |
| 293 if (gl_helper) | 293 if (gl_helper) |
| 294 gl_helper->GenerateSyncToken(&sync_token); | 294 gl_helper->GenerateSyncToken(&sync_token); |
| 295 } | 295 } |
| 296 | 296 |
| 297 // PostTask() to make sure the |readback_lock| is released. Also do this | 297 // PostTask() to make sure the |readback_lock| is released. Also do this |
| 298 // synchronous GPU operation in a clean callstack. | 298 // synchronous GPU operation in a clean callstack. |
| 299 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 299 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 300 base::Bind(&ReleaseGLHelper)); | 300 base::Bind(&ReleaseGLHelper)); |
| 301 | 301 |
| 302 const bool lost_resource = !sync_token.HasData(); | 302 const bool lost_resource = !sync_token.HasData(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 TRACE_EVENT0("cc", | 351 TRACE_EVENT0("cc", |
| 352 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); | 352 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); |
| 353 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 353 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
| 354 return; | 354 return; |
| 355 cc::TextureMailbox texture_mailbox; | 355 cc::TextureMailbox texture_mailbox; |
| 356 std::unique_ptr<cc::SingleReleaseCallback> release_callback; | 356 std::unique_ptr<cc::SingleReleaseCallback> release_callback; |
| 357 result->TakeTexture(&texture_mailbox, &release_callback); | 357 result->TakeTexture(&texture_mailbox, &release_callback); |
| 358 DCHECK(texture_mailbox.IsTexture()); | 358 DCHECK(texture_mailbox.IsTexture()); |
| 359 if (!texture_mailbox.IsTexture()) | 359 if (!texture_mailbox.IsTexture()) |
| 360 return; | 360 return; |
| 361 display_compositor::GLHelper* gl_helper = GetPostReadbackGLHelper(); | 361 viz::GLHelper* gl_helper = GetPostReadbackGLHelper(); |
| 362 if (!gl_helper) | 362 if (!gl_helper) |
| 363 return; | 363 return; |
| 364 if (!gl_helper->IsReadbackConfigSupported(color_type)) | 364 if (!gl_helper->IsReadbackConfigSupported(color_type)) |
| 365 color_type = kRGBA_8888_SkColorType; | 365 color_type = kRGBA_8888_SkColorType; |
| 366 | 366 |
| 367 gfx::Size output_size_in_pixel; | 367 gfx::Size output_size_in_pixel; |
| 368 if (dst_size_in_pixel.IsEmpty()) | 368 if (dst_size_in_pixel.IsEmpty()) |
| 369 output_size_in_pixel = result->size(); | 369 output_size_in_pixel = result->size(); |
| 370 else | 370 else |
| 371 output_size_in_pixel = dst_size_in_pixel; | 371 output_size_in_pixel = dst_size_in_pixel; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 383 uint8_t* pixels = static_cast<uint8_t*>(bitmap->getPixels()); | 383 uint8_t* pixels = static_cast<uint8_t*>(bitmap->getPixels()); |
| 384 | 384 |
| 385 ignore_result(scoped_callback_runner.Release()); | 385 ignore_result(scoped_callback_runner.Release()); |
| 386 | 386 |
| 387 gl_helper->CropScaleReadbackAndCleanMailbox( | 387 gl_helper->CropScaleReadbackAndCleanMailbox( |
| 388 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), | 388 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), |
| 389 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, | 389 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, |
| 390 base::Bind(&CopyFromCompositingSurfaceFinished, callback, | 390 base::Bind(&CopyFromCompositingSurfaceFinished, callback, |
| 391 base::Passed(&release_callback), base::Passed(&bitmap), | 391 base::Passed(&release_callback), base::Passed(&bitmap), |
| 392 start_time, readback_lock), | 392 start_time, readback_lock), |
| 393 display_compositor::GLHelper::SCALER_QUALITY_GOOD); | 393 viz::GLHelper::SCALER_QUALITY_GOOD); |
| 394 } | 394 } |
| 395 | 395 |
| 396 void RecordToolTypeForActionDown(const ui::MotionEventAndroid& event) { | 396 void RecordToolTypeForActionDown(const ui::MotionEventAndroid& event) { |
| 397 ui::MotionEventAndroid::Action action = event.GetAction(); | 397 ui::MotionEventAndroid::Action action = event.GetAction(); |
| 398 if (action == ui::MotionEventAndroid::ACTION_DOWN || | 398 if (action == ui::MotionEventAndroid::ACTION_DOWN || |
| 399 action == ui::MotionEventAndroid::ACTION_POINTER_DOWN || | 399 action == ui::MotionEventAndroid::ACTION_POINTER_DOWN || |
| 400 action == ui::MotionEventAndroid::ACTION_BUTTON_PRESS) { | 400 action == ui::MotionEventAndroid::ACTION_BUTTON_PRESS) { |
| 401 UMA_HISTOGRAM_ENUMERATION("Event.AndroidActionDown.ToolType", | 401 UMA_HISTOGRAM_ENUMERATION("Event.AndroidActionDown.ToolType", |
| 402 event.GetToolType(0), | 402 event.GetToolType(0), |
| 403 ui::MotionEventAndroid::TOOL_TYPE_LAST + 1); | 403 ui::MotionEventAndroid::TOOL_TYPE_LAST + 1); |
| (...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2191 | 2191 |
| 2192 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); | 2192 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); |
| 2193 if (!compositor) | 2193 if (!compositor) |
| 2194 return; | 2194 return; |
| 2195 | 2195 |
| 2196 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( | 2196 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( |
| 2197 overscroll_refresh_handler, compositor, view_.GetDipScale()); | 2197 overscroll_refresh_handler, compositor, view_.GetDipScale()); |
| 2198 } | 2198 } |
| 2199 | 2199 |
| 2200 } // namespace content | 2200 } // namespace content |
| OLD | NEW |