Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "android_webview/browser/browser_view_renderer.h" | 5 #include "android_webview/browser/browser_view_renderer.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/browser_view_renderer_client.h" | 7 #include "android_webview/browser/browser_view_renderer_client.h" |
| 8 #include "android_webview/browser/shared_renderer_state.h" | 8 #include "android_webview/browser/shared_renderer_state.h" |
| 9 #include "android_webview/common/aw_switches.h" | |
| 10 #include "android_webview/public/browser/draw_gl.h" | 9 #include "android_webview/public/browser/draw_gl.h" |
| 11 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| 12 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 13 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 14 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
| 15 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 16 #include "base/logging.h" | 15 #include "base/logging.h" |
| 17 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 19 #include "cc/output/compositor_frame.h" | 18 #include "cc/output/compositor_frame.h" |
| 20 #include "content/public/browser/android/synchronous_compositor.h" | |
| 21 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
| 24 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
| 25 #include "third_party/skia/include/core/SkCanvas.h" | 23 #include "third_party/skia/include/core/SkCanvas.h" |
| 26 #include "third_party/skia/include/core/SkPicture.h" | 24 #include "third_party/skia/include/core/SkPicture.h" |
| 27 #include "third_party/skia/include/core/SkPictureRecorder.h" | 25 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 28 #include "ui/gfx/vector2d_conversions.h" | 26 #include "ui/gfx/vector2d_conversions.h" |
| 29 | 27 |
| 30 using base::android::AttachCurrentThread; | 28 using base::android::AttachCurrentThread; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 44 const size_t kBytesPerPixel = 4; | 42 const size_t kBytesPerPixel = 4; |
| 45 const size_t kMemoryAllocationStep = 5 * 1024 * 1024; | 43 const size_t kMemoryAllocationStep = 5 * 1024 * 1024; |
| 46 | 44 |
| 47 // Used to calculate tile allocation. Determined experimentally. | 45 // Used to calculate tile allocation. Determined experimentally. |
| 48 const size_t kTileMultiplier = 12; | 46 const size_t kTileMultiplier = 12; |
| 49 const size_t kTileAllocationStep = 20; | 47 const size_t kTileAllocationStep = 20; |
| 50 // This will be set by static function CalculateTileMemoryPolicy() during init. | 48 // This will be set by static function CalculateTileMemoryPolicy() during init. |
| 51 // See AwMainDelegate::BasicStartupComplete. | 49 // See AwMainDelegate::BasicStartupComplete. |
| 52 size_t g_tile_area; | 50 size_t g_tile_area; |
| 53 | 51 |
| 54 class AutoResetWithLock { | |
| 55 public: | |
| 56 AutoResetWithLock(gfx::Vector2dF* scoped_variable, | |
| 57 gfx::Vector2dF new_value, | |
| 58 base::Lock& lock) | |
| 59 : scoped_variable_(scoped_variable), | |
| 60 original_value_(*scoped_variable), | |
| 61 lock_(lock) { | |
| 62 base::AutoLock auto_lock(lock_); | |
| 63 *scoped_variable_ = new_value; | |
| 64 } | |
| 65 | |
| 66 ~AutoResetWithLock() { | |
| 67 base::AutoLock auto_lock(lock_); | |
| 68 *scoped_variable_ = original_value_; | |
| 69 } | |
| 70 | |
| 71 private: | |
| 72 gfx::Vector2dF* scoped_variable_; | |
| 73 gfx::Vector2dF original_value_; | |
| 74 base::Lock& lock_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(AutoResetWithLock); | |
| 77 }; | |
| 78 | |
| 79 class TracedValue : public base::debug::ConvertableToTraceFormat { | 52 class TracedValue : public base::debug::ConvertableToTraceFormat { |
| 80 public: | 53 public: |
| 81 explicit TracedValue(base::Value* value) : value_(value) {} | 54 explicit TracedValue(base::Value* value) : value_(value) {} |
| 82 static scoped_refptr<base::debug::ConvertableToTraceFormat> FromValue( | 55 static scoped_refptr<base::debug::ConvertableToTraceFormat> FromValue( |
| 83 base::Value* value) { | 56 base::Value* value) { |
| 84 return scoped_refptr<base::debug::ConvertableToTraceFormat>( | 57 return scoped_refptr<base::debug::ConvertableToTraceFormat>( |
| 85 new TracedValue(value)); | 58 new TracedValue(value)); |
| 86 } | 59 } |
| 87 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE { | 60 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE { |
| 88 std::string tmp; | 61 std::string tmp; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 119 BrowserViewRendererClient* client, | 92 BrowserViewRendererClient* client, |
| 120 SharedRendererState* shared_renderer_state, | 93 SharedRendererState* shared_renderer_state, |
| 121 content::WebContents* web_contents, | 94 content::WebContents* web_contents, |
| 122 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) | 95 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) |
| 123 : client_(client), | 96 : client_(client), |
| 124 shared_renderer_state_(shared_renderer_state), | 97 shared_renderer_state_(shared_renderer_state), |
| 125 web_contents_(web_contents), | 98 web_contents_(web_contents), |
| 126 weak_factory_on_ui_thread_(this), | 99 weak_factory_on_ui_thread_(this), |
| 127 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()), | 100 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()), |
| 128 ui_task_runner_(ui_task_runner), | 101 ui_task_runner_(ui_task_runner), |
| 129 has_compositor_(false), | 102 compositor_(NULL), |
| 130 is_paused_(false), | 103 is_paused_(false), |
| 131 view_visible_(false), | 104 view_visible_(false), |
| 132 window_visible_(false), | 105 window_visible_(false), |
| 133 attached_to_window_(false), | 106 attached_to_window_(false), |
| 134 hardware_enabled_(false), | 107 hardware_enabled_(false), |
| 135 dip_scale_(0.0), | 108 dip_scale_(0.0), |
| 136 page_scale_factor_(1.0), | 109 page_scale_factor_(1.0), |
| 137 on_new_picture_enable_(false), | 110 on_new_picture_enable_(false), |
| 138 clear_view_(false), | 111 clear_view_(false), |
| 139 compositor_needs_continuous_invalidate_(false), | 112 compositor_needs_continuous_invalidate_(false), |
| 140 block_invalidates_(false), | 113 block_invalidates_(false), |
| 141 width_(0), | 114 width_(0), |
| 142 height_(0), | 115 height_(0), |
| 143 num_tiles_(0u), | 116 num_tiles_(0u), |
| 144 num_bytes_(0u) { | 117 num_bytes_(0u) { |
| 145 CHECK(web_contents_); | 118 CHECK(web_contents_); |
| 146 content::SynchronousCompositor::SetClientForWebContents(web_contents_, this); | 119 content::SynchronousCompositor::SetClientForWebContents(web_contents_, this); |
| 147 | 120 |
| 148 // Currently the logic in this class relies on |has_compositor_| remaining | 121 // Currently the logic in this class relies on |compositor_| remaining |
| 149 // false until the DidInitializeCompositor() call, hence it is not set here. | 122 // NULL until the DidInitializeCompositor() call, hence it is not set here. |
| 150 } | 123 } |
| 151 | 124 |
| 152 BrowserViewRenderer::~BrowserViewRenderer() { | 125 BrowserViewRenderer::~BrowserViewRenderer() { |
| 153 content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL); | 126 content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL); |
| 154 // OnDetachedFromWindow should be called before the destructor, so the memory | 127 // OnDetachedFromWindow should be called before the destructor, so the memory |
| 155 // policy should have already been updated. | 128 // policy should have already been updated. |
| 156 } | 129 } |
| 157 | 130 |
| 158 // This function updates the cached memory policy in shared renderer state, as | 131 // This function updates the cached memory policy in shared renderer state, as |
| 159 // well as the tile resource allocation in GlobalTileManager. | 132 // well as the tile resource allocation in GlobalTileManager. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 172 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN) | 145 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN) |
| 173 return; | 146 return; |
| 174 | 147 |
| 175 // Do not release resources on view we expect to get DrawGL soon. | 148 // Do not release resources on view we expect to get DrawGL soon. |
| 176 if (level < TRIM_MEMORY_BACKGROUND && visible) | 149 if (level < TRIM_MEMORY_BACKGROUND && visible) |
| 177 return; | 150 return; |
| 178 | 151 |
| 179 // Just set the memory limit to 0 and drop all tiles. This will be reset to | 152 // Just set the memory limit to 0 and drop all tiles. This will be reset to |
| 180 // normal levels in the next DrawGL call. | 153 // normal levels in the next DrawGL call. |
| 181 SynchronousCompositorMemoryPolicy zero_policy; | 154 SynchronousCompositorMemoryPolicy zero_policy; |
| 182 if (shared_renderer_state_->GetMemoryPolicy() == zero_policy) | 155 if (memory_policy_ == zero_policy) |
| 183 return; | 156 return; |
| 184 | 157 |
| 185 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); | 158 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); |
| 186 | 159 |
| 187 RequestMemoryPolicy(zero_policy); | 160 RequestMemoryPolicy(zero_policy); |
| 188 EnforceMemoryPolicyImmediately(zero_policy); | 161 EnforceMemoryPolicyImmediately(zero_policy); |
| 189 } | 162 } |
| 190 | 163 |
| 191 SynchronousCompositorMemoryPolicy | 164 SynchronousCompositorMemoryPolicy |
| 192 BrowserViewRenderer::CalculateDesiredMemoryPolicy() { | 165 BrowserViewRenderer::CalculateDesiredMemoryPolicy() { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 218 // The following line will call BrowserViewRenderer::SetTilesNum(). | 191 // The following line will call BrowserViewRenderer::SetTilesNum(). |
| 219 manager->RequestTiles(new_policy.num_resources_limit, tile_manager_key_); | 192 manager->RequestTiles(new_policy.num_resources_limit, tile_manager_key_); |
| 220 } | 193 } |
| 221 | 194 |
| 222 void BrowserViewRenderer::SetNumTiles(size_t num_tiles, | 195 void BrowserViewRenderer::SetNumTiles(size_t num_tiles, |
| 223 bool effective_immediately) { | 196 bool effective_immediately) { |
| 224 if (num_tiles == num_tiles_) | 197 if (num_tiles == num_tiles_) |
| 225 return; | 198 return; |
| 226 num_tiles_ = num_tiles; | 199 num_tiles_ = num_tiles; |
| 227 | 200 |
| 228 SynchronousCompositorMemoryPolicy new_policy; | 201 memory_policy_.num_resources_limit = num_tiles_; |
| 229 new_policy.num_resources_limit = num_tiles_; | 202 memory_policy_.bytes_limit = num_bytes_; |
| 230 new_policy.bytes_limit = num_bytes_; | |
| 231 shared_renderer_state_->SetMemoryPolicy(new_policy); | |
| 232 | 203 |
| 233 if (effective_immediately) | 204 if (effective_immediately) |
| 234 EnforceMemoryPolicyImmediately(new_policy); | 205 EnforceMemoryPolicyImmediately(memory_policy_); |
| 235 } | 206 } |
| 236 | 207 |
| 237 void BrowserViewRenderer::EnforceMemoryPolicyImmediately( | 208 void BrowserViewRenderer::EnforceMemoryPolicyImmediately( |
| 238 SynchronousCompositorMemoryPolicy new_policy) { | 209 SynchronousCompositorMemoryPolicy new_policy) { |
| 239 shared_renderer_state_->GetCompositor()->SetMemoryPolicy(new_policy); | 210 compositor_->SetMemoryPolicy(new_policy); |
| 240 ForceFakeCompositeSW(); | 211 ForceFakeCompositeSW(); |
| 241 shared_renderer_state_->SetMemoryPolicyDirty(false); | |
| 242 } | 212 } |
| 243 | 213 |
| 244 size_t BrowserViewRenderer::GetNumTiles() const { | 214 size_t BrowserViewRenderer::GetNumTiles() const { |
| 245 return shared_renderer_state_->GetMemoryPolicy().num_resources_limit; | 215 return memory_policy_.num_resources_limit; |
| 246 } | 216 } |
| 247 | 217 |
| 248 bool BrowserViewRenderer::OnDraw(jobject java_canvas, | 218 bool BrowserViewRenderer::OnDraw(jobject java_canvas, |
| 249 bool is_hardware_canvas, | 219 bool is_hardware_canvas, |
| 250 const gfx::Vector2d& scroll, | 220 const gfx::Vector2d& scroll, |
| 251 const gfx::Rect& global_visible_rect, | 221 const gfx::Rect& global_visible_rect, |
| 252 const gfx::Rect& clip) { | 222 const gfx::Rect& clip) { |
| 253 last_on_draw_scroll_offset_ = scroll; | 223 last_on_draw_scroll_offset_ = scroll; |
| 254 last_on_draw_global_visible_rect_ = global_visible_rect; | 224 last_on_draw_global_visible_rect_ = global_visible_rect; |
| 255 | 225 |
| 256 if (clear_view_) | 226 if (clear_view_) |
| 257 return false; | 227 return false; |
| 258 | 228 |
| 259 if (is_hardware_canvas && attached_to_window_) { | 229 if (is_hardware_canvas && attached_to_window_) |
| 260 if (switches::UbercompEnabled()) { | 230 return OnDrawHardware(java_canvas); |
| 261 return OnDrawHardware(java_canvas); | |
| 262 } else { | |
| 263 return OnDrawHardwareLegacy(java_canvas); | |
| 264 } | |
| 265 } | |
| 266 // Perform a software draw | 231 // Perform a software draw |
| 267 return DrawSWInternal(java_canvas, clip); | 232 return DrawSWInternal(java_canvas, clip); |
| 268 } | 233 } |
| 269 | 234 |
| 270 bool BrowserViewRenderer::OnDrawHardwareLegacy(jobject java_canvas) { | |
| 271 scoped_ptr<DrawGLInput> draw_gl_input(new DrawGLInput); | |
| 272 draw_gl_input->scroll_offset = last_on_draw_scroll_offset_; | |
| 273 draw_gl_input->global_visible_rect = last_on_draw_global_visible_rect_; | |
| 274 draw_gl_input->width = width_; | |
| 275 draw_gl_input->height = height_; | |
| 276 | |
| 277 SynchronousCompositorMemoryPolicy old_policy = | |
| 278 shared_renderer_state_->GetMemoryPolicy(); | |
| 279 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); | |
| 280 RequestMemoryPolicy(new_policy); | |
| 281 // We should be performing a hardware draw here. If we don't have the | |
| 282 // compositor yet or if RequestDrawGL fails, it means we failed this draw | |
| 283 // and thus return false here to clear to background color for this draw. | |
| 284 bool did_draw_gl = | |
| 285 has_compositor_ && client_->RequestDrawGL(java_canvas, false); | |
| 286 if (did_draw_gl) { | |
| 287 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); | |
| 288 shared_renderer_state_->SetDrawGLInput(draw_gl_input.Pass()); | |
| 289 } else { | |
| 290 RequestMemoryPolicy(old_policy); | |
| 291 } | |
| 292 | |
| 293 return did_draw_gl; | |
| 294 } | |
| 295 | |
| 296 void BrowserViewRenderer::DidDrawGL(scoped_ptr<DrawGLResult> result) { | |
| 297 DidComposite(!result->clip_contains_visible_rect); | |
| 298 } | |
| 299 | |
| 300 bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) { | 235 bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) { |
| 301 if (!has_compositor_) | 236 if (!compositor_) |
| 302 return false; | 237 return false; |
| 303 | 238 |
| 304 if (!hardware_enabled_) { | 239 if (!hardware_enabled_) { |
| 305 hardware_enabled_ = | 240 hardware_enabled_ = compositor_->InitializeHwDraw(); |
| 306 shared_renderer_state_->GetCompositor()->InitializeHwDraw(NULL); | |
| 307 if (hardware_enabled_) { | 241 if (hardware_enabled_) { |
| 308 gpu::GLInProcessContext* share_context = | 242 gpu::GLInProcessContext* share_context = compositor_->GetShareContext(); |
| 309 shared_renderer_state_->GetCompositor()->GetShareContext(); | |
| 310 DCHECK(share_context); | 243 DCHECK(share_context); |
| 311 shared_renderer_state_->SetSharedContext(share_context); | 244 shared_renderer_state_->SetSharedContext(share_context); |
| 312 } | 245 } |
| 313 } | 246 } |
| 314 if (!hardware_enabled_) | 247 if (!hardware_enabled_) |
| 315 return false; | 248 return false; |
| 316 | 249 |
| 317 ReturnResources(); | 250 ReturnResources(); |
| 318 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); | 251 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); |
| 319 RequestMemoryPolicy(new_policy); | 252 RequestMemoryPolicy(new_policy); |
| 320 shared_renderer_state_->GetCompositor()->SetMemoryPolicy( | 253 compositor_->SetMemoryPolicy(memory_policy_); |
| 321 shared_renderer_state_->GetMemoryPolicy()); | |
| 322 | 254 |
| 323 scoped_ptr<DrawGLInput> draw_gl_input(new DrawGLInput); | 255 scoped_ptr<DrawGLInput> draw_gl_input(new DrawGLInput); |
| 324 draw_gl_input->scroll_offset = last_on_draw_scroll_offset_; | 256 draw_gl_input->scroll_offset = last_on_draw_scroll_offset_; |
| 325 draw_gl_input->global_visible_rect = last_on_draw_global_visible_rect_; | |
| 326 draw_gl_input->width = width_; | 257 draw_gl_input->width = width_; |
| 327 draw_gl_input->height = height_; | 258 draw_gl_input->height = height_; |
| 328 | 259 |
| 329 gfx::Transform transform; | 260 gfx::Transform transform; |
| 330 gfx::Size surface_size(width_, height_); | 261 gfx::Size surface_size(width_, height_); |
| 331 gfx::Rect viewport(surface_size); | 262 gfx::Rect viewport(surface_size); |
| 332 // TODO(boliu): Should really be |last_on_draw_global_visible_rect_|. | 263 // TODO(boliu): Should really be |last_on_draw_global_visible_rect_|. |
| 333 // See crbug.com/372073. | 264 // See crbug.com/372073. |
| 334 gfx::Rect clip = viewport; | 265 gfx::Rect clip = viewport; |
| 335 bool stencil_enabled = false; | 266 scoped_ptr<cc::CompositorFrame> frame = compositor_->DemandDrawHw( |
| 336 scoped_ptr<cc::CompositorFrame> frame = | 267 surface_size, transform, viewport, clip); |
| 337 shared_renderer_state_->GetCompositor()->DemandDrawHw( | |
| 338 surface_size, transform, viewport, clip, stencil_enabled); | |
| 339 if (!frame.get()) | 268 if (!frame.get()) |
| 340 return false; | 269 return false; |
| 341 | 270 |
| 342 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); | 271 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); |
| 343 | 272 |
| 344 frame->AssignTo(&draw_gl_input->frame); | 273 frame->AssignTo(&draw_gl_input->frame); |
| 345 scoped_ptr<DrawGLInput> old_input = shared_renderer_state_->PassDrawGLInput(); | 274 scoped_ptr<DrawGLInput> old_input = shared_renderer_state_->PassDrawGLInput(); |
| 346 if (old_input.get()) { | 275 if (old_input.get()) { |
| 347 shared_renderer_state_->ReturnResources( | 276 shared_renderer_state_->ReturnResources( |
| 348 old_input->frame.delegated_frame_data->resource_list); | 277 old_input->frame.delegated_frame_data->resource_list); |
| 349 } | 278 } |
| 350 shared_renderer_state_->SetDrawGLInput(draw_gl_input.Pass()); | 279 shared_renderer_state_->SetDrawGLInput(draw_gl_input.Pass()); |
| 351 | 280 |
| 352 DidComposite(false); | 281 DidComposite(); |
| 353 bool did_request = client_->RequestDrawGL(java_canvas, false); | 282 bool did_request = client_->RequestDrawGL(java_canvas, false); |
| 354 if (did_request) | 283 if (did_request) |
| 355 return true; | 284 return true; |
| 356 | 285 |
| 357 ReturnResources(); | 286 ReturnResources(); |
| 358 return false; | 287 return false; |
| 359 } | 288 } |
| 360 | 289 |
| 361 void BrowserViewRenderer::DidDrawDelegated(scoped_ptr<DrawGLResult> result) { | 290 void BrowserViewRenderer::DidDrawDelegated() { |
| 362 if (!ui_task_runner_->BelongsToCurrentThread()) { | 291 if (!ui_task_runner_->BelongsToCurrentThread()) { |
| 363 // TODO(boliu): This should be a cancelable callback. | 292 // TODO(boliu): This should be a cancelable callback. |
| 293 // TODO(boliu): Do this PostTask in AwContents instead so every method in | |
| 294 // this class is called by UI thread. | |
| 364 ui_task_runner_->PostTask(FROM_HERE, | 295 ui_task_runner_->PostTask(FROM_HERE, |
| 365 base::Bind(&BrowserViewRenderer::DidDrawDelegated, | 296 base::Bind(&BrowserViewRenderer::DidDrawDelegated, |
|
hush (inactive)
2014/06/17 17:45:54
i see the only place where DidDrawDelegated is cal
boliu
2014/06/17 17:47:23
Yes because it then calls *itself* on UI thread...
| |
| 366 ui_thread_weak_ptr_, | 297 ui_thread_weak_ptr_)); |
| 367 base::Passed(&result))); | |
| 368 return; | 298 return; |
| 369 } | 299 } |
| 370 ReturnResources(); | 300 ReturnResources(); |
| 371 } | 301 } |
| 372 | 302 |
| 373 void BrowserViewRenderer::ReturnResources() { | 303 void BrowserViewRenderer::ReturnResources() { |
| 374 cc::CompositorFrameAck frame_ack; | 304 cc::CompositorFrameAck frame_ack; |
| 375 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources); | 305 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources); |
| 376 if (!frame_ack.resources.empty()) { | 306 if (!frame_ack.resources.empty()) { |
| 377 shared_renderer_state_->GetCompositor()->ReturnResources(frame_ack); | 307 compositor_->ReturnResources(frame_ack); |
| 378 } | 308 } |
| 379 } | 309 } |
| 380 | 310 |
| 381 bool BrowserViewRenderer::DrawSWInternal(jobject java_canvas, | 311 bool BrowserViewRenderer::DrawSWInternal(jobject java_canvas, |
| 382 const gfx::Rect& clip) { | 312 const gfx::Rect& clip) { |
| 383 if (clip.IsEmpty()) { | 313 if (clip.IsEmpty()) { |
| 384 TRACE_EVENT_INSTANT0( | 314 TRACE_EVENT_INSTANT0( |
| 385 "android_webview", "EarlyOut_EmptyClip", TRACE_EVENT_SCOPE_THREAD); | 315 "android_webview", "EarlyOut_EmptyClip", TRACE_EVENT_SCOPE_THREAD); |
| 386 return true; | 316 return true; |
| 387 } | 317 } |
| 388 | 318 |
| 389 if (!has_compositor_) { | 319 if (!compositor_) { |
| 390 TRACE_EVENT_INSTANT0( | 320 TRACE_EVENT_INSTANT0( |
| 391 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD); | 321 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD); |
| 392 return false; | 322 return false; |
| 393 } | 323 } |
| 394 | 324 |
| 395 return BrowserViewRendererJavaHelper::GetInstance() | 325 return BrowserViewRendererJavaHelper::GetInstance() |
| 396 ->RenderViaAuxilaryBitmapIfNeeded( | 326 ->RenderViaAuxilaryBitmapIfNeeded( |
| 397 java_canvas, | 327 java_canvas, |
| 398 last_on_draw_scroll_offset_, | 328 last_on_draw_scroll_offset_, |
| 399 clip, | 329 clip, |
| 400 base::Bind(&BrowserViewRenderer::CompositeSW, | 330 base::Bind(&BrowserViewRenderer::CompositeSW, |
| 401 base::Unretained(this))); | 331 base::Unretained(this))); |
| 402 } | 332 } |
| 403 | 333 |
| 404 skia::RefPtr<SkPicture> BrowserViewRenderer::CapturePicture(int width, | 334 skia::RefPtr<SkPicture> BrowserViewRenderer::CapturePicture(int width, |
| 405 int height) { | 335 int height) { |
| 406 TRACE_EVENT0("android_webview", "BrowserViewRenderer::CapturePicture"); | 336 TRACE_EVENT0("android_webview", "BrowserViewRenderer::CapturePicture"); |
| 407 | 337 |
| 408 // Return empty Picture objects for empty SkPictures. | 338 // Return empty Picture objects for empty SkPictures. |
| 409 if (width <= 0 || height <= 0) { | 339 if (width <= 0 || height <= 0) { |
| 410 return skia::AdoptRef(new SkPicture); | 340 return skia::AdoptRef(new SkPicture); |
| 411 } | 341 } |
| 412 | 342 |
| 413 // Reset scroll back to the origin, will go back to the old | 343 // Reset scroll back to the origin, will go back to the old |
| 414 // value when scroll_reset is out of scope. | 344 // value when scroll_reset is out of scope. |
| 415 AutoResetWithLock scroll_reset( | 345 base::AutoReset<gfx::Vector2dF> scroll_reset(&scroll_offset_dip_, |
| 416 &scroll_offset_dip_, gfx::Vector2dF(), render_thread_lock_); | 346 gfx::Vector2dF()); |
| 417 | 347 |
| 418 SkPictureRecorder recorder; | 348 SkPictureRecorder recorder; |
| 419 SkCanvas* rec_canvas = recorder.beginRecording(width, height, NULL, 0); | 349 SkCanvas* rec_canvas = recorder.beginRecording(width, height, NULL, 0); |
| 420 if (has_compositor_) | 350 if (compositor_) |
| 421 CompositeSW(rec_canvas); | 351 CompositeSW(rec_canvas); |
| 422 return skia::AdoptRef(recorder.endRecording()); | 352 return skia::AdoptRef(recorder.endRecording()); |
| 423 } | 353 } |
| 424 | 354 |
| 425 void BrowserViewRenderer::EnableOnNewPicture(bool enabled) { | 355 void BrowserViewRenderer::EnableOnNewPicture(bool enabled) { |
| 426 on_new_picture_enable_ = enabled; | 356 on_new_picture_enable_ = enabled; |
| 427 } | 357 } |
| 428 | 358 |
| 429 void BrowserViewRenderer::ClearView() { | 359 void BrowserViewRenderer::ClearView() { |
| 430 TRACE_EVENT_INSTANT0("android_webview", | 360 TRACE_EVENT_INSTANT0("android_webview", |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 attached_to_window_ = false; | 427 attached_to_window_ = false; |
| 498 if (hardware_enabled_) { | 428 if (hardware_enabled_) { |
| 499 scoped_ptr<DrawGLInput> input = shared_renderer_state_->PassDrawGLInput(); | 429 scoped_ptr<DrawGLInput> input = shared_renderer_state_->PassDrawGLInput(); |
| 500 if (input.get()) { | 430 if (input.get()) { |
| 501 shared_renderer_state_->ReturnResources( | 431 shared_renderer_state_->ReturnResources( |
| 502 input->frame.delegated_frame_data->resource_list); | 432 input->frame.delegated_frame_data->resource_list); |
| 503 } | 433 } |
| 504 ReturnResources(); | 434 ReturnResources(); |
| 505 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty()); | 435 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty()); |
| 506 | 436 |
| 507 if (switches::UbercompEnabled()) | 437 compositor_->ReleaseHwDraw(); |
| 508 shared_renderer_state_->GetCompositor()->ReleaseHwDraw(); | |
| 509 shared_renderer_state_->SetSharedContext(NULL); | 438 shared_renderer_state_->SetSharedContext(NULL); |
| 510 hardware_enabled_ = false; | 439 hardware_enabled_ = false; |
| 511 } | 440 } |
| 512 SynchronousCompositorMemoryPolicy zero_policy; | 441 SynchronousCompositorMemoryPolicy zero_policy; |
| 513 RequestMemoryPolicy(zero_policy); | 442 RequestMemoryPolicy(zero_policy); |
| 514 GlobalTileManager::GetInstance()->Remove(tile_manager_key_); | 443 GlobalTileManager::GetInstance()->Remove(tile_manager_key_); |
| 515 // The hardware resources are released in the destructor of hardware renderer, | 444 // The hardware resources are released in the destructor of hardware renderer, |
| 516 // so we don't need to do it here. | 445 // so we don't need to do it here. |
| 517 // See AwContents::ReleaseHardwareDrawOnRenderThread(JNIEnv*, jobject). | 446 // See AwContents::ReleaseHardwareDrawOnRenderThread(JNIEnv*, jobject). |
| 518 } | 447 } |
| 519 | 448 |
| 520 bool BrowserViewRenderer::IsAttachedToWindow() const { | 449 bool BrowserViewRenderer::IsAttachedToWindow() const { |
| 521 return attached_to_window_; | 450 return attached_to_window_; |
| 522 } | 451 } |
| 523 | 452 |
| 524 bool BrowserViewRenderer::IsVisible() const { | 453 bool BrowserViewRenderer::IsVisible() const { |
| 525 // Ignore |window_visible_| if |attached_to_window_| is false. | 454 // Ignore |window_visible_| if |attached_to_window_| is false. |
| 526 return view_visible_ && (!attached_to_window_ || window_visible_); | 455 return view_visible_ && (!attached_to_window_ || window_visible_); |
| 527 } | 456 } |
| 528 | 457 |
| 529 gfx::Rect BrowserViewRenderer::GetScreenRect() const { | 458 gfx::Rect BrowserViewRenderer::GetScreenRect() const { |
| 530 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_)); | 459 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_)); |
| 531 } | 460 } |
| 532 | 461 |
| 533 void BrowserViewRenderer::DidInitializeCompositor( | 462 void BrowserViewRenderer::DidInitializeCompositor( |
| 534 content::SynchronousCompositor* compositor) { | 463 content::SynchronousCompositor* compositor) { |
| 535 TRACE_EVENT0("android_webview", | 464 TRACE_EVENT0("android_webview", |
| 536 "BrowserViewRenderer::DidInitializeCompositor"); | 465 "BrowserViewRenderer::DidInitializeCompositor"); |
| 537 DCHECK(compositor); | 466 DCHECK(compositor); |
| 538 DCHECK(!has_compositor_); | 467 DCHECK(!compositor_); |
| 539 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 468 compositor_ = compositor; |
| 540 has_compositor_ = true; | |
| 541 shared_renderer_state_->SetCompositorOnUiThread(compositor); | |
| 542 } | 469 } |
| 543 | 470 |
| 544 void BrowserViewRenderer::DidDestroyCompositor( | 471 void BrowserViewRenderer::DidDestroyCompositor( |
| 545 content::SynchronousCompositor* compositor) { | 472 content::SynchronousCompositor* compositor) { |
| 546 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor"); | 473 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor"); |
| 547 DCHECK(has_compositor_); | 474 DCHECK(compositor_); |
| 548 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 475 compositor_ = NULL; |
| 549 has_compositor_ = false; | |
| 550 shared_renderer_state_->SetCompositorOnUiThread(NULL); | |
| 551 SynchronousCompositorMemoryPolicy zero_policy; | 476 SynchronousCompositorMemoryPolicy zero_policy; |
| 552 DCHECK(shared_renderer_state_->GetMemoryPolicy() == zero_policy); | 477 DCHECK(memory_policy_ == zero_policy); |
| 553 } | 478 } |
| 554 | 479 |
| 555 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) { | 480 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) { |
| 556 { | 481 if (compositor_needs_continuous_invalidate_ == invalidate) |
| 557 base::AutoLock lock(render_thread_lock_); | 482 return; |
| 558 if (compositor_needs_continuous_invalidate_ == invalidate) | |
| 559 return; | |
| 560 | 483 |
| 561 TRACE_EVENT_INSTANT1("android_webview", | 484 TRACE_EVENT_INSTANT1("android_webview", |
| 562 "BrowserViewRenderer::SetContinuousInvalidate", | 485 "BrowserViewRenderer::SetContinuousInvalidate", |
| 563 TRACE_EVENT_SCOPE_THREAD, | 486 TRACE_EVENT_SCOPE_THREAD, |
| 564 "invalidate", | 487 "invalidate", |
| 565 invalidate); | 488 invalidate); |
| 566 compositor_needs_continuous_invalidate_ = invalidate; | 489 compositor_needs_continuous_invalidate_ = invalidate; |
| 567 } | |
| 568 | 490 |
| 569 if (ui_task_runner_->BelongsToCurrentThread()) { | 491 EnsureContinuousInvalidation(false); |
| 570 EnsureContinuousInvalidation(false); | |
| 571 return; | |
| 572 } | |
| 573 ui_task_runner_->PostTask( | |
| 574 FROM_HERE, | |
| 575 base::Bind(&BrowserViewRenderer::EnsureContinuousInvalidation, | |
| 576 ui_thread_weak_ptr_, | |
| 577 false)); | |
| 578 } | 492 } |
| 579 | 493 |
| 580 void BrowserViewRenderer::SetDipScale(float dip_scale) { | 494 void BrowserViewRenderer::SetDipScale(float dip_scale) { |
| 581 dip_scale_ = dip_scale; | 495 dip_scale_ = dip_scale; |
| 582 CHECK(dip_scale_ > 0); | 496 CHECK(dip_scale_ > 0); |
| 583 } | 497 } |
| 584 | 498 |
| 585 gfx::Vector2d BrowserViewRenderer::max_scroll_offset() const { | 499 gfx::Vector2d BrowserViewRenderer::max_scroll_offset() const { |
| 586 DCHECK_GT(dip_scale_, 0); | 500 DCHECK_GT(dip_scale_, 0); |
| 587 return gfx::ToCeiledVector2d(gfx::ScaleVector2d( | 501 return gfx::ToCeiledVector2d(gfx::ScaleVector2d( |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 602 if (max_offset.y()) { | 516 if (max_offset.y()) { |
| 603 scroll_offset_dip.set_y((scroll_offset.y() * max_scroll_offset_dip_.y()) / | 517 scroll_offset_dip.set_y((scroll_offset.y() * max_scroll_offset_dip_.y()) / |
| 604 max_offset.y()); | 518 max_offset.y()); |
| 605 } | 519 } |
| 606 | 520 |
| 607 DCHECK_LE(0, scroll_offset_dip.x()); | 521 DCHECK_LE(0, scroll_offset_dip.x()); |
| 608 DCHECK_LE(0, scroll_offset_dip.y()); | 522 DCHECK_LE(0, scroll_offset_dip.y()); |
| 609 DCHECK_LE(scroll_offset_dip.x(), max_scroll_offset_dip_.x()); | 523 DCHECK_LE(scroll_offset_dip.x(), max_scroll_offset_dip_.x()); |
| 610 DCHECK_LE(scroll_offset_dip.y(), max_scroll_offset_dip_.y()); | 524 DCHECK_LE(scroll_offset_dip.y(), max_scroll_offset_dip_.y()); |
| 611 | 525 |
| 612 { | 526 if (scroll_offset_dip_ == scroll_offset_dip) |
| 613 base::AutoLock lock(render_thread_lock_); | 527 return; |
| 614 if (scroll_offset_dip_ == scroll_offset_dip) | |
| 615 return; | |
| 616 | 528 |
| 617 scroll_offset_dip_ = scroll_offset_dip; | 529 scroll_offset_dip_ = scroll_offset_dip; |
| 618 } | |
| 619 | 530 |
| 620 TRACE_EVENT_INSTANT2("android_webview", | 531 TRACE_EVENT_INSTANT2("android_webview", |
| 621 "BrowserViewRenderer::ScrollTo", | 532 "BrowserViewRenderer::ScrollTo", |
| 622 TRACE_EVENT_SCOPE_THREAD, | 533 TRACE_EVENT_SCOPE_THREAD, |
| 623 "x", | 534 "x", |
| 624 scroll_offset_dip.x(), | 535 scroll_offset_dip.x(), |
| 625 "y", | 536 "y", |
| 626 scroll_offset_dip.y()); | 537 scroll_offset_dip.y()); |
| 627 | 538 |
| 628 if (has_compositor_) | 539 if (compositor_) |
| 629 shared_renderer_state_->GetCompositor()-> | 540 compositor_->DidChangeRootLayerScrollOffset(); |
| 630 DidChangeRootLayerScrollOffset(); | |
| 631 } | 541 } |
| 632 | 542 |
| 633 void BrowserViewRenderer::DidUpdateContent() { | 543 void BrowserViewRenderer::DidUpdateContent() { |
| 634 if (!ui_task_runner_->BelongsToCurrentThread()) { | |
| 635 ui_task_runner_->PostTask(FROM_HERE, | |
| 636 base::Bind(&BrowserViewRenderer::DidUpdateContent, | |
| 637 ui_thread_weak_ptr_)); | |
| 638 return; | |
| 639 } | |
| 640 TRACE_EVENT_INSTANT0("android_webview", | 544 TRACE_EVENT_INSTANT0("android_webview", |
| 641 "BrowserViewRenderer::DidUpdateContent", | 545 "BrowserViewRenderer::DidUpdateContent", |
| 642 TRACE_EVENT_SCOPE_THREAD); | 546 TRACE_EVENT_SCOPE_THREAD); |
| 643 clear_view_ = false; | 547 clear_view_ = false; |
| 644 if (on_new_picture_enable_) | 548 if (on_new_picture_enable_) |
| 645 client_->OnNewPicture(); | 549 client_->OnNewPicture(); |
| 646 } | 550 } |
| 647 | 551 |
| 648 void BrowserViewRenderer::SetTotalRootLayerScrollOffset( | 552 void BrowserViewRenderer::SetTotalRootLayerScrollOffset( |
| 649 gfx::Vector2dF scroll_offset_dip) { | 553 gfx::Vector2dF scroll_offset_dip) { |
| 554 // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during | |
| 555 // DrawGl when http://crbug.com/249972 is fixed. | |
| 556 if (scroll_offset_dip_ == scroll_offset_dip) | |
| 557 return; | |
| 650 | 558 |
| 651 { | 559 scroll_offset_dip_ = scroll_offset_dip; |
| 652 base::AutoLock lock(render_thread_lock_); | |
| 653 // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during | |
| 654 // DrawGl when http://crbug.com/249972 is fixed. | |
| 655 if (scroll_offset_dip_ == scroll_offset_dip) | |
| 656 return; | |
| 657 | |
| 658 scroll_offset_dip_ = scroll_offset_dip; | |
| 659 } | |
| 660 | 560 |
| 661 gfx::Vector2d max_offset = max_scroll_offset(); | 561 gfx::Vector2d max_offset = max_scroll_offset(); |
| 662 gfx::Vector2d scroll_offset; | 562 gfx::Vector2d scroll_offset; |
| 663 // For an explanation as to why this is done this way see the comment in | 563 // For an explanation as to why this is done this way see the comment in |
| 664 // BrowserViewRenderer::ScrollTo. | 564 // BrowserViewRenderer::ScrollTo. |
| 665 if (max_scroll_offset_dip_.x()) { | 565 if (max_scroll_offset_dip_.x()) { |
| 666 scroll_offset.set_x((scroll_offset_dip.x() * max_offset.x()) / | 566 scroll_offset.set_x((scroll_offset_dip.x() * max_offset.x()) / |
| 667 max_scroll_offset_dip_.x()); | 567 max_scroll_offset_dip_.x()); |
| 668 } | 568 } |
| 669 | 569 |
| 670 if (max_scroll_offset_dip_.y()) { | 570 if (max_scroll_offset_dip_.y()) { |
| 671 scroll_offset.set_y((scroll_offset_dip.y() * max_offset.y()) / | 571 scroll_offset.set_y((scroll_offset_dip.y() * max_offset.y()) / |
| 672 max_scroll_offset_dip_.y()); | 572 max_scroll_offset_dip_.y()); |
| 673 } | 573 } |
| 674 | 574 |
| 675 DCHECK(0 <= scroll_offset.x()); | 575 DCHECK(0 <= scroll_offset.x()); |
| 676 DCHECK(0 <= scroll_offset.y()); | 576 DCHECK(0 <= scroll_offset.y()); |
| 677 DCHECK(scroll_offset.x() <= max_offset.x()); | 577 DCHECK(scroll_offset.x() <= max_offset.x()); |
| 678 DCHECK(scroll_offset.y() <= max_offset.y()); | 578 DCHECK(scroll_offset.y() <= max_offset.y()); |
| 679 | 579 |
| 680 client_->ScrollContainerViewTo(scroll_offset); | 580 client_->ScrollContainerViewTo(scroll_offset); |
| 681 } | 581 } |
| 682 | 582 |
| 683 gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() { | 583 gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() { |
| 684 base::AutoLock lock(render_thread_lock_); | |
| 685 return scroll_offset_dip_; | 584 return scroll_offset_dip_; |
| 686 } | 585 } |
| 687 | 586 |
| 688 bool BrowserViewRenderer::IsExternalFlingActive() const { | 587 bool BrowserViewRenderer::IsExternalFlingActive() const { |
| 689 if (!ui_task_runner_->BelongsToCurrentThread()) { | |
| 690 // TODO(boliu): This is short term hack since we cannot call into | |
| 691 // view system on non-UI thread. | |
| 692 return false; | |
| 693 } | |
| 694 return client_->IsFlingActive(); | 588 return client_->IsFlingActive(); |
| 695 } | 589 } |
| 696 | 590 |
| 697 void BrowserViewRenderer::UpdateRootLayerState( | 591 void BrowserViewRenderer::UpdateRootLayerState( |
| 698 const gfx::Vector2dF& total_scroll_offset_dip, | 592 const gfx::Vector2dF& total_scroll_offset_dip, |
| 699 const gfx::Vector2dF& max_scroll_offset_dip, | 593 const gfx::Vector2dF& max_scroll_offset_dip, |
| 700 const gfx::SizeF& scrollable_size_dip, | 594 const gfx::SizeF& scrollable_size_dip, |
| 701 float page_scale_factor, | 595 float page_scale_factor, |
| 702 float min_page_scale_factor, | 596 float min_page_scale_factor, |
| 703 float max_page_scale_factor) { | 597 float max_page_scale_factor) { |
| 704 if (!ui_task_runner_->BelongsToCurrentThread()) { | |
| 705 ui_task_runner_->PostTask( | |
| 706 FROM_HERE, | |
| 707 base::Bind(&BrowserViewRenderer::UpdateRootLayerState, | |
| 708 ui_thread_weak_ptr_, | |
| 709 total_scroll_offset_dip, | |
| 710 max_scroll_offset_dip, | |
| 711 scrollable_size_dip, | |
| 712 page_scale_factor, | |
| 713 min_page_scale_factor, | |
| 714 max_page_scale_factor)); | |
| 715 return; | |
| 716 } | |
| 717 TRACE_EVENT_INSTANT1( | 598 TRACE_EVENT_INSTANT1( |
| 718 "android_webview", | 599 "android_webview", |
| 719 "BrowserViewRenderer::UpdateRootLayerState", | 600 "BrowserViewRenderer::UpdateRootLayerState", |
| 720 TRACE_EVENT_SCOPE_THREAD, | 601 TRACE_EVENT_SCOPE_THREAD, |
| 721 "state", | 602 "state", |
| 722 TracedValue::FromValue( | 603 TracedValue::FromValue( |
| 723 RootLayerStateAsValue(total_scroll_offset_dip, scrollable_size_dip) | 604 RootLayerStateAsValue(total_scroll_offset_dip, scrollable_size_dip) |
| 724 .release())); | 605 .release())); |
| 725 | 606 |
| 726 DCHECK_GT(dip_scale_, 0); | 607 DCHECK_GT(dip_scale_, 0); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 754 state->SetDouble("scrollable_size_dip.width", scrollable_size_dip.width()); | 635 state->SetDouble("scrollable_size_dip.width", scrollable_size_dip.width()); |
| 755 state->SetDouble("scrollable_size_dip.height", scrollable_size_dip.height()); | 636 state->SetDouble("scrollable_size_dip.height", scrollable_size_dip.height()); |
| 756 | 637 |
| 757 state->SetDouble("page_scale_factor", page_scale_factor_); | 638 state->SetDouble("page_scale_factor", page_scale_factor_); |
| 758 return state.PassAs<base::Value>(); | 639 return state.PassAs<base::Value>(); |
| 759 } | 640 } |
| 760 | 641 |
| 761 void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll, | 642 void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll, |
| 762 gfx::Vector2dF latest_overscroll_delta, | 643 gfx::Vector2dF latest_overscroll_delta, |
| 763 gfx::Vector2dF current_fling_velocity) { | 644 gfx::Vector2dF current_fling_velocity) { |
| 764 if (!ui_task_runner_->BelongsToCurrentThread()) { | |
| 765 ui_task_runner_->PostTask( | |
| 766 FROM_HERE, | |
| 767 base::Bind(&BrowserViewRenderer::DidOverscroll, | |
| 768 ui_thread_weak_ptr_, | |
| 769 accumulated_overscroll, | |
| 770 latest_overscroll_delta, | |
| 771 current_fling_velocity)); | |
| 772 return; | |
| 773 } | |
| 774 const float physical_pixel_scale = dip_scale_ * page_scale_factor_; | 645 const float physical_pixel_scale = dip_scale_ * page_scale_factor_; |
| 775 if (accumulated_overscroll == latest_overscroll_delta) | 646 if (accumulated_overscroll == latest_overscroll_delta) |
| 776 overscroll_rounding_error_ = gfx::Vector2dF(); | 647 overscroll_rounding_error_ = gfx::Vector2dF(); |
| 777 gfx::Vector2dF scaled_overscroll_delta = | 648 gfx::Vector2dF scaled_overscroll_delta = |
| 778 gfx::ScaleVector2d(latest_overscroll_delta, physical_pixel_scale); | 649 gfx::ScaleVector2d(latest_overscroll_delta, physical_pixel_scale); |
| 779 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d( | 650 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d( |
| 780 scaled_overscroll_delta + overscroll_rounding_error_); | 651 scaled_overscroll_delta + overscroll_rounding_error_); |
| 781 overscroll_rounding_error_ = | 652 overscroll_rounding_error_ = |
| 782 scaled_overscroll_delta - rounded_overscroll_delta; | 653 scaled_overscroll_delta - rounded_overscroll_delta; |
| 783 client_->DidOverscroll(rounded_overscroll_delta); | 654 client_->DidOverscroll(rounded_overscroll_delta); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 798 // 1) Webview is paused. Also need to check we are not in clear view since | 669 // 1) Webview is paused. Also need to check we are not in clear view since |
| 799 // paused, offscreen still expect clear view to recover. | 670 // paused, offscreen still expect clear view to recover. |
| 800 // 2) If we are attached to window and the window is not visible (eg when | 671 // 2) If we are attached to window and the window is not visible (eg when |
| 801 // app is in the background). We are sure in this case the webview is used | 672 // app is in the background). We are sure in this case the webview is used |
| 802 // "on-screen" but that updates are not needed when in the background. | 673 // "on-screen" but that updates are not needed when in the background. |
| 803 bool throttle_fallback_tick = | 674 bool throttle_fallback_tick = |
| 804 (is_paused_ && !clear_view_) || (attached_to_window_ && !window_visible_); | 675 (is_paused_ && !clear_view_) || (attached_to_window_ && !window_visible_); |
| 805 if (throttle_fallback_tick) | 676 if (throttle_fallback_tick) |
| 806 return; | 677 return; |
| 807 | 678 |
| 808 { | 679 block_invalidates_ = compositor_needs_continuous_invalidate_; |
| 809 base::AutoLock lock(render_thread_lock_); | |
| 810 block_invalidates_ = compositor_needs_continuous_invalidate_; | |
| 811 } | |
| 812 | 680 |
| 813 // Unretained here is safe because the callback is cancelled when | 681 // Unretained here is safe because the callback is cancelled when |
| 814 // |fallback_tick_| is destroyed. | 682 // |fallback_tick_| is destroyed. |
| 815 fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::FallbackTickFired, | 683 fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::FallbackTickFired, |
| 816 base::Unretained(this))); | 684 base::Unretained(this))); |
| 817 | 685 |
| 818 // No need to reschedule fallback tick if compositor does not need to be | 686 // No need to reschedule fallback tick if compositor does not need to be |
| 819 // ticked. This can happen if this is reached because force_invalidate is | 687 // ticked. This can happen if this is reached because force_invalidate is |
| 820 // true. | 688 // true. |
| 821 if (compositor_needs_continuous_invalidate_) { | 689 if (compositor_needs_continuous_invalidate_) { |
| 822 ui_task_runner_->PostDelayedTask( | 690 ui_task_runner_->PostDelayedTask( |
| 823 FROM_HERE, | 691 FROM_HERE, |
| 824 fallback_tick_.callback(), | 692 fallback_tick_.callback(), |
| 825 base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds)); | 693 base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds)); |
| 826 } | 694 } |
| 827 } | 695 } |
| 828 | 696 |
| 829 void BrowserViewRenderer::FallbackTickFired() { | 697 void BrowserViewRenderer::FallbackTickFired() { |
| 830 TRACE_EVENT1("android_webview", | 698 TRACE_EVENT1("android_webview", |
| 831 "BrowserViewRenderer::FallbackTickFired", | 699 "BrowserViewRenderer::FallbackTickFired", |
| 832 "compositor_needs_continuous_invalidate_", | 700 "compositor_needs_continuous_invalidate_", |
| 833 compositor_needs_continuous_invalidate_); | 701 compositor_needs_continuous_invalidate_); |
| 834 | 702 |
| 835 // This should only be called if OnDraw or DrawGL did not come in time, which | 703 // This should only be called if OnDraw or DrawGL did not come in time, which |
| 836 // means block_invalidates_ must still be true. | 704 // means block_invalidates_ must still be true. |
| 837 DCHECK(block_invalidates_); | 705 DCHECK(block_invalidates_); |
| 838 if (compositor_needs_continuous_invalidate_ && has_compositor_) | 706 if (compositor_needs_continuous_invalidate_ && compositor_) |
| 839 ForceFakeCompositeSW(); | 707 ForceFakeCompositeSW(); |
| 840 } | 708 } |
| 841 | 709 |
| 842 void BrowserViewRenderer::ForceFakeCompositeSW() { | 710 void BrowserViewRenderer::ForceFakeCompositeSW() { |
| 843 DCHECK(has_compositor_); | 711 DCHECK(compositor_); |
| 844 SkBitmap bitmap; | 712 SkBitmap bitmap; |
| 845 bitmap.allocN32Pixels(1, 1); | 713 bitmap.allocN32Pixels(1, 1); |
| 846 bitmap.eraseColor(0); | 714 bitmap.eraseColor(0); |
| 847 SkCanvas canvas(bitmap); | 715 SkCanvas canvas(bitmap); |
| 848 CompositeSW(&canvas); | 716 CompositeSW(&canvas); |
| 849 } | 717 } |
| 850 | 718 |
| 851 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) { | 719 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) { |
| 852 DCHECK(has_compositor_); | 720 DCHECK(compositor_); |
| 853 bool result = shared_renderer_state_->GetCompositor()-> | 721 bool result = compositor_->DemandDrawSw(canvas); |
| 854 DemandDrawSw(canvas); | 722 DidComposite(); |
| 855 DidComposite(false); | |
| 856 return result; | 723 return result; |
| 857 } | 724 } |
| 858 | 725 |
| 859 void BrowserViewRenderer::DidComposite(bool force_invalidate) { | 726 void BrowserViewRenderer::DidComposite() { |
| 860 { | 727 block_invalidates_ = false; |
| 861 base::AutoLock lock(render_thread_lock_); | |
| 862 block_invalidates_ = false; | |
| 863 } | |
| 864 | |
| 865 if (!ui_task_runner_->BelongsToCurrentThread()) { | |
| 866 ui_task_runner_->PostTask( | |
| 867 FROM_HERE, | |
| 868 base::Bind(&BrowserViewRenderer::EnsureContinuousInvalidation, | |
| 869 ui_thread_weak_ptr_, | |
| 870 force_invalidate)); | |
| 871 return; | |
| 872 } | |
| 873 | |
| 874 fallback_tick_.Cancel(); | 728 fallback_tick_.Cancel(); |
| 875 EnsureContinuousInvalidation(force_invalidate); | 729 EnsureContinuousInvalidation(false); |
| 876 } | 730 } |
| 877 | 731 |
| 878 std::string BrowserViewRenderer::ToString(AwDrawGLInfo* draw_info) const { | 732 std::string BrowserViewRenderer::ToString(AwDrawGLInfo* draw_info) const { |
| 879 std::string str; | 733 std::string str; |
| 880 base::StringAppendF(&str, "is_paused: %d ", is_paused_); | 734 base::StringAppendF(&str, "is_paused: %d ", is_paused_); |
| 881 base::StringAppendF(&str, "view_visible: %d ", view_visible_); | 735 base::StringAppendF(&str, "view_visible: %d ", view_visible_); |
| 882 base::StringAppendF(&str, "window_visible: %d ", window_visible_); | 736 base::StringAppendF(&str, "window_visible: %d ", window_visible_); |
| 883 base::StringAppendF(&str, "dip_scale: %f ", dip_scale_); | 737 base::StringAppendF(&str, "dip_scale: %f ", dip_scale_); |
| 884 base::StringAppendF(&str, "page_scale_factor: %f ", page_scale_factor_); | 738 base::StringAppendF(&str, "page_scale_factor: %f ", page_scale_factor_); |
| 885 base::StringAppendF(&str, | 739 base::StringAppendF(&str, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 909 base::StringAppendF(&str, | 763 base::StringAppendF(&str, |
| 910 "surface width height: [%d %d] ", | 764 "surface width height: [%d %d] ", |
| 911 draw_info->width, | 765 draw_info->width, |
| 912 draw_info->height); | 766 draw_info->height); |
| 913 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 767 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
| 914 } | 768 } |
| 915 return str; | 769 return str; |
| 916 } | 770 } |
| 917 | 771 |
| 918 } // namespace android_webview | 772 } // namespace android_webview |
| OLD | NEW |