Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: android_webview/browser/browser_view_renderer.cc

Issue 331103002: aw: Remove legacy rendering path (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 BrowserViewRendererClient* client, 117 BrowserViewRendererClient* client,
120 SharedRendererState* shared_renderer_state, 118 SharedRendererState* shared_renderer_state,
121 content::WebContents* web_contents, 119 content::WebContents* web_contents,
122 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) 120 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
123 : client_(client), 121 : client_(client),
124 shared_renderer_state_(shared_renderer_state), 122 shared_renderer_state_(shared_renderer_state),
125 web_contents_(web_contents), 123 web_contents_(web_contents),
126 weak_factory_on_ui_thread_(this), 124 weak_factory_on_ui_thread_(this),
127 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()), 125 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()),
128 ui_task_runner_(ui_task_runner), 126 ui_task_runner_(ui_task_runner),
129 has_compositor_(false), 127 compositor_(NULL),
130 is_paused_(false), 128 is_paused_(false),
131 view_visible_(false), 129 view_visible_(false),
132 window_visible_(false), 130 window_visible_(false),
133 attached_to_window_(false), 131 attached_to_window_(false),
134 hardware_enabled_(false), 132 hardware_enabled_(false),
135 dip_scale_(0.0), 133 dip_scale_(0.0),
136 page_scale_factor_(1.0), 134 page_scale_factor_(1.0),
137 on_new_picture_enable_(false), 135 on_new_picture_enable_(false),
138 clear_view_(false), 136 clear_view_(false),
139 compositor_needs_continuous_invalidate_(false), 137 compositor_needs_continuous_invalidate_(false),
140 block_invalidates_(false), 138 block_invalidates_(false),
141 width_(0), 139 width_(0),
142 height_(0), 140 height_(0),
143 num_tiles_(0u), 141 num_tiles_(0u),
144 num_bytes_(0u) { 142 num_bytes_(0u) {
145 CHECK(web_contents_); 143 CHECK(web_contents_);
146 content::SynchronousCompositor::SetClientForWebContents(web_contents_, this); 144 content::SynchronousCompositor::SetClientForWebContents(web_contents_, this);
147 145
148 // Currently the logic in this class relies on |has_compositor_| remaining 146 // Currently the logic in this class relies on |compositor_| remaining
149 // false until the DidInitializeCompositor() call, hence it is not set here. 147 // NULL until the DidInitializeCompositor() call, hence it is not set here.
150 } 148 }
151 149
152 BrowserViewRenderer::~BrowserViewRenderer() { 150 BrowserViewRenderer::~BrowserViewRenderer() {
153 content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL); 151 content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL);
154 // OnDetachedFromWindow should be called before the destructor, so the memory 152 // OnDetachedFromWindow should be called before the destructor, so the memory
155 // policy should have already been updated. 153 // policy should have already been updated.
156 } 154 }
157 155
158 // This function updates the cached memory policy in shared renderer state, as 156 // This function updates the cached memory policy in shared renderer state, as
159 // well as the tile resource allocation in GlobalTileManager. 157 // well as the tile resource allocation in GlobalTileManager.
(...skipping 12 matching lines...) Expand all
172 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN) 170 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN)
173 return; 171 return;
174 172
175 // Do not release resources on view we expect to get DrawGL soon. 173 // Do not release resources on view we expect to get DrawGL soon.
176 if (level < TRIM_MEMORY_BACKGROUND && visible) 174 if (level < TRIM_MEMORY_BACKGROUND && visible)
177 return; 175 return;
178 176
179 // Just set the memory limit to 0 and drop all tiles. This will be reset to 177 // Just set the memory limit to 0 and drop all tiles. This will be reset to
180 // normal levels in the next DrawGL call. 178 // normal levels in the next DrawGL call.
181 SynchronousCompositorMemoryPolicy zero_policy; 179 SynchronousCompositorMemoryPolicy zero_policy;
182 if (shared_renderer_state_->GetMemoryPolicy() == zero_policy) 180 if (memory_policy_ == zero_policy)
183 return; 181 return;
184 182
185 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); 183 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory");
186 184
187 RequestMemoryPolicy(zero_policy); 185 RequestMemoryPolicy(zero_policy);
188 EnforceMemoryPolicyImmediately(zero_policy); 186 EnforceMemoryPolicyImmediately(zero_policy);
189 } 187 }
190 188
191 SynchronousCompositorMemoryPolicy 189 SynchronousCompositorMemoryPolicy
192 BrowserViewRenderer::CalculateDesiredMemoryPolicy() { 190 BrowserViewRenderer::CalculateDesiredMemoryPolicy() {
(...skipping 25 matching lines...) Expand all
218 // The following line will call BrowserViewRenderer::SetTilesNum(). 216 // The following line will call BrowserViewRenderer::SetTilesNum().
219 manager->RequestTiles(new_policy.num_resources_limit, tile_manager_key_); 217 manager->RequestTiles(new_policy.num_resources_limit, tile_manager_key_);
220 } 218 }
221 219
222 void BrowserViewRenderer::SetNumTiles(size_t num_tiles, 220 void BrowserViewRenderer::SetNumTiles(size_t num_tiles,
223 bool effective_immediately) { 221 bool effective_immediately) {
224 if (num_tiles == num_tiles_) 222 if (num_tiles == num_tiles_)
225 return; 223 return;
226 num_tiles_ = num_tiles; 224 num_tiles_ = num_tiles;
227 225
228 SynchronousCompositorMemoryPolicy new_policy; 226 memory_policy_.num_resources_limit = num_tiles_;
229 new_policy.num_resources_limit = num_tiles_; 227 memory_policy_.bytes_limit = num_bytes_;
230 new_policy.bytes_limit = num_bytes_;
231 shared_renderer_state_->SetMemoryPolicy(new_policy);
232 228
233 if (effective_immediately) 229 if (effective_immediately)
234 EnforceMemoryPolicyImmediately(new_policy); 230 EnforceMemoryPolicyImmediately(memory_policy_);
235 } 231 }
236 232
237 void BrowserViewRenderer::EnforceMemoryPolicyImmediately( 233 void BrowserViewRenderer::EnforceMemoryPolicyImmediately(
238 SynchronousCompositorMemoryPolicy new_policy) { 234 SynchronousCompositorMemoryPolicy new_policy) {
239 shared_renderer_state_->GetCompositor()->SetMemoryPolicy(new_policy); 235 compositor_->SetMemoryPolicy(new_policy);
240 ForceFakeCompositeSW(); 236 ForceFakeCompositeSW();
241 shared_renderer_state_->SetMemoryPolicyDirty(false);
242 } 237 }
243 238
244 size_t BrowserViewRenderer::GetNumTiles() const { 239 size_t BrowserViewRenderer::GetNumTiles() const {
245 return shared_renderer_state_->GetMemoryPolicy().num_resources_limit; 240 return memory_policy_.num_resources_limit;
246 } 241 }
247 242
248 bool BrowserViewRenderer::OnDraw(jobject java_canvas, 243 bool BrowserViewRenderer::OnDraw(jobject java_canvas,
249 bool is_hardware_canvas, 244 bool is_hardware_canvas,
250 const gfx::Vector2d& scroll, 245 const gfx::Vector2d& scroll,
251 const gfx::Rect& global_visible_rect, 246 const gfx::Rect& global_visible_rect,
252 const gfx::Rect& clip) { 247 const gfx::Rect& clip) {
253 last_on_draw_scroll_offset_ = scroll; 248 last_on_draw_scroll_offset_ = scroll;
254 last_on_draw_global_visible_rect_ = global_visible_rect; 249 last_on_draw_global_visible_rect_ = global_visible_rect;
255 250
256 if (clear_view_) 251 if (clear_view_)
257 return false; 252 return false;
258 253
259 if (is_hardware_canvas && attached_to_window_) { 254 if (is_hardware_canvas && attached_to_window_)
260 if (switches::UbercompEnabled()) { 255 return OnDrawHardware(java_canvas);
261 return OnDrawHardware(java_canvas);
262 } else {
263 return OnDrawHardwareLegacy(java_canvas);
264 }
265 }
266 // Perform a software draw 256 // Perform a software draw
267 return DrawSWInternal(java_canvas, clip); 257 return DrawSWInternal(java_canvas, clip);
268 } 258 }
269 259
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);
hush (inactive) 2014/06/16 21:41:50 after you delete this line, DidComposite will alwa
boliu 2014/06/16 22:43:27 Good catch. Removed the arg to DidComposite Force
298 }
299
300 bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) { 260 bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) {
301 if (!has_compositor_) 261 if (!compositor_)
302 return false; 262 return false;
303 263
304 if (!hardware_enabled_) { 264 if (!hardware_enabled_) {
305 hardware_enabled_ = 265 hardware_enabled_ = compositor_->InitializeHwDraw(NULL);
hush (inactive) 2014/06/16 21:41:50 what does it mean to initialize hw draw with a NUL
boliu 2014/06/16 22:43:27 Good catch again, removed the GLSurface path. Nor
306 shared_renderer_state_->GetCompositor()->InitializeHwDraw(NULL);
307 if (hardware_enabled_) { 266 if (hardware_enabled_) {
308 gpu::GLInProcessContext* share_context = 267 gpu::GLInProcessContext* share_context = compositor_->GetShareContext();
309 shared_renderer_state_->GetCompositor()->GetShareContext();
310 DCHECK(share_context); 268 DCHECK(share_context);
311 shared_renderer_state_->SetSharedContext(share_context); 269 shared_renderer_state_->SetSharedContext(share_context);
312 } 270 }
313 } 271 }
314 if (!hardware_enabled_) 272 if (!hardware_enabled_)
315 return false; 273 return false;
316 274
317 ReturnResources(); 275 ReturnResources();
318 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); 276 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy();
319 RequestMemoryPolicy(new_policy); 277 RequestMemoryPolicy(new_policy);
320 shared_renderer_state_->GetCompositor()->SetMemoryPolicy( 278 compositor_->SetMemoryPolicy(memory_policy_);
321 shared_renderer_state_->GetMemoryPolicy());
322 279
323 scoped_ptr<DrawGLInput> draw_gl_input(new DrawGLInput); 280 scoped_ptr<DrawGLInput> draw_gl_input(new DrawGLInput);
324 draw_gl_input->scroll_offset = last_on_draw_scroll_offset_; 281 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_; 282 draw_gl_input->width = width_;
327 draw_gl_input->height = height_; 283 draw_gl_input->height = height_;
328 284
329 gfx::Transform transform; 285 gfx::Transform transform;
330 gfx::Size surface_size(width_, height_); 286 gfx::Size surface_size(width_, height_);
331 gfx::Rect viewport(surface_size); 287 gfx::Rect viewport(surface_size);
332 // TODO(boliu): Should really be |last_on_draw_global_visible_rect_|. 288 // TODO(boliu): Should really be |last_on_draw_global_visible_rect_|.
333 // See crbug.com/372073. 289 // See crbug.com/372073.
334 gfx::Rect clip = viewport; 290 gfx::Rect clip = viewport;
335 bool stencil_enabled = false; 291 bool stencil_enabled = false;
336 scoped_ptr<cc::CompositorFrame> frame = 292 scoped_ptr<cc::CompositorFrame> frame = compositor_->DemandDrawHw(
337 shared_renderer_state_->GetCompositor()->DemandDrawHw( 293 surface_size, transform, viewport, clip, stencil_enabled);
338 surface_size, transform, viewport, clip, stencil_enabled);
339 if (!frame.get()) 294 if (!frame.get())
340 return false; 295 return false;
341 296
342 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); 297 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_);
343 298
344 frame->AssignTo(&draw_gl_input->frame); 299 frame->AssignTo(&draw_gl_input->frame);
345 scoped_ptr<DrawGLInput> old_input = shared_renderer_state_->PassDrawGLInput(); 300 scoped_ptr<DrawGLInput> old_input = shared_renderer_state_->PassDrawGLInput();
346 if (old_input.get()) { 301 if (old_input.get()) {
347 shared_renderer_state_->ReturnResources( 302 shared_renderer_state_->ReturnResources(
348 old_input->frame.delegated_frame_data->resource_list); 303 old_input->frame.delegated_frame_data->resource_list);
349 } 304 }
350 shared_renderer_state_->SetDrawGLInput(draw_gl_input.Pass()); 305 shared_renderer_state_->SetDrawGLInput(draw_gl_input.Pass());
351 306
352 DidComposite(false); 307 DidComposite(false);
353 bool did_request = client_->RequestDrawGL(java_canvas, false); 308 bool did_request = client_->RequestDrawGL(java_canvas, false);
354 if (did_request) 309 if (did_request)
355 return true; 310 return true;
356 311
357 ReturnResources(); 312 ReturnResources();
358 return false; 313 return false;
359 } 314 }
360 315
361 void BrowserViewRenderer::DidDrawDelegated(scoped_ptr<DrawGLResult> result) { 316 void BrowserViewRenderer::DidDrawDelegated() {
362 if (!ui_task_runner_->BelongsToCurrentThread()) { 317 if (!ui_task_runner_->BelongsToCurrentThread()) {
363 // TODO(boliu): This should be a cancelable callback. 318 // TODO(boliu): This should be a cancelable callback.
364 ui_task_runner_->PostTask(FROM_HERE, 319 ui_task_runner_->PostTask(FROM_HERE,
365 base::Bind(&BrowserViewRenderer::DidDrawDelegated, 320 base::Bind(&BrowserViewRenderer::DidDrawDelegated,
366 ui_thread_weak_ptr_, 321 ui_thread_weak_ptr_));
367 base::Passed(&result)));
368 return; 322 return;
369 } 323 }
370 ReturnResources(); 324 ReturnResources();
371 } 325 }
372 326
373 void BrowserViewRenderer::ReturnResources() { 327 void BrowserViewRenderer::ReturnResources() {
374 cc::CompositorFrameAck frame_ack; 328 cc::CompositorFrameAck frame_ack;
375 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources); 329 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources);
376 if (!frame_ack.resources.empty()) { 330 if (!frame_ack.resources.empty()) {
377 shared_renderer_state_->GetCompositor()->ReturnResources(frame_ack); 331 compositor_->ReturnResources(frame_ack);
378 } 332 }
379 } 333 }
380 334
381 bool BrowserViewRenderer::DrawSWInternal(jobject java_canvas, 335 bool BrowserViewRenderer::DrawSWInternal(jobject java_canvas,
382 const gfx::Rect& clip) { 336 const gfx::Rect& clip) {
383 if (clip.IsEmpty()) { 337 if (clip.IsEmpty()) {
384 TRACE_EVENT_INSTANT0( 338 TRACE_EVENT_INSTANT0(
385 "android_webview", "EarlyOut_EmptyClip", TRACE_EVENT_SCOPE_THREAD); 339 "android_webview", "EarlyOut_EmptyClip", TRACE_EVENT_SCOPE_THREAD);
386 return true; 340 return true;
387 } 341 }
388 342
389 if (!has_compositor_) { 343 if (!compositor_) {
390 TRACE_EVENT_INSTANT0( 344 TRACE_EVENT_INSTANT0(
391 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD); 345 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD);
392 return false; 346 return false;
393 } 347 }
394 348
395 return BrowserViewRendererJavaHelper::GetInstance() 349 return BrowserViewRendererJavaHelper::GetInstance()
396 ->RenderViaAuxilaryBitmapIfNeeded( 350 ->RenderViaAuxilaryBitmapIfNeeded(
397 java_canvas, 351 java_canvas,
398 last_on_draw_scroll_offset_, 352 last_on_draw_scroll_offset_,
399 clip, 353 clip,
(...skipping 10 matching lines...) Expand all
410 return skia::AdoptRef(new SkPicture); 364 return skia::AdoptRef(new SkPicture);
411 } 365 }
412 366
413 // Reset scroll back to the origin, will go back to the old 367 // Reset scroll back to the origin, will go back to the old
414 // value when scroll_reset is out of scope. 368 // value when scroll_reset is out of scope.
415 AutoResetWithLock scroll_reset( 369 AutoResetWithLock scroll_reset(
416 &scroll_offset_dip_, gfx::Vector2dF(), render_thread_lock_); 370 &scroll_offset_dip_, gfx::Vector2dF(), render_thread_lock_);
417 371
418 SkPictureRecorder recorder; 372 SkPictureRecorder recorder;
419 SkCanvas* rec_canvas = recorder.beginRecording(width, height, NULL, 0); 373 SkCanvas* rec_canvas = recorder.beginRecording(width, height, NULL, 0);
420 if (has_compositor_) 374 if (compositor_)
421 CompositeSW(rec_canvas); 375 CompositeSW(rec_canvas);
422 return skia::AdoptRef(recorder.endRecording()); 376 return skia::AdoptRef(recorder.endRecording());
423 } 377 }
424 378
425 void BrowserViewRenderer::EnableOnNewPicture(bool enabled) { 379 void BrowserViewRenderer::EnableOnNewPicture(bool enabled) {
426 on_new_picture_enable_ = enabled; 380 on_new_picture_enable_ = enabled;
427 } 381 }
428 382
429 void BrowserViewRenderer::ClearView() { 383 void BrowserViewRenderer::ClearView() {
430 TRACE_EVENT_INSTANT0("android_webview", 384 TRACE_EVENT_INSTANT0("android_webview",
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 attached_to_window_ = false; 451 attached_to_window_ = false;
498 if (hardware_enabled_) { 452 if (hardware_enabled_) {
499 scoped_ptr<DrawGLInput> input = shared_renderer_state_->PassDrawGLInput(); 453 scoped_ptr<DrawGLInput> input = shared_renderer_state_->PassDrawGLInput();
500 if (input.get()) { 454 if (input.get()) {
501 shared_renderer_state_->ReturnResources( 455 shared_renderer_state_->ReturnResources(
502 input->frame.delegated_frame_data->resource_list); 456 input->frame.delegated_frame_data->resource_list);
503 } 457 }
504 ReturnResources(); 458 ReturnResources();
505 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty()); 459 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty());
506 460
507 if (switches::UbercompEnabled()) 461 compositor_->ReleaseHwDraw();
508 shared_renderer_state_->GetCompositor()->ReleaseHwDraw();
509 shared_renderer_state_->SetSharedContext(NULL); 462 shared_renderer_state_->SetSharedContext(NULL);
510 hardware_enabled_ = false; 463 hardware_enabled_ = false;
511 } 464 }
512 SynchronousCompositorMemoryPolicy zero_policy; 465 SynchronousCompositorMemoryPolicy zero_policy;
513 RequestMemoryPolicy(zero_policy); 466 RequestMemoryPolicy(zero_policy);
514 GlobalTileManager::GetInstance()->Remove(tile_manager_key_); 467 GlobalTileManager::GetInstance()->Remove(tile_manager_key_);
515 // The hardware resources are released in the destructor of hardware renderer, 468 // The hardware resources are released in the destructor of hardware renderer,
516 // so we don't need to do it here. 469 // so we don't need to do it here.
517 // See AwContents::ReleaseHardwareDrawOnRenderThread(JNIEnv*, jobject). 470 // See AwContents::ReleaseHardwareDrawOnRenderThread(JNIEnv*, jobject).
518 } 471 }
519 472
520 bool BrowserViewRenderer::IsAttachedToWindow() const { 473 bool BrowserViewRenderer::IsAttachedToWindow() const {
521 return attached_to_window_; 474 return attached_to_window_;
522 } 475 }
523 476
524 bool BrowserViewRenderer::IsVisible() const { 477 bool BrowserViewRenderer::IsVisible() const {
525 // Ignore |window_visible_| if |attached_to_window_| is false. 478 // Ignore |window_visible_| if |attached_to_window_| is false.
526 return view_visible_ && (!attached_to_window_ || window_visible_); 479 return view_visible_ && (!attached_to_window_ || window_visible_);
527 } 480 }
528 481
529 gfx::Rect BrowserViewRenderer::GetScreenRect() const { 482 gfx::Rect BrowserViewRenderer::GetScreenRect() const {
530 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_)); 483 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_));
531 } 484 }
532 485
533 void BrowserViewRenderer::DidInitializeCompositor( 486 void BrowserViewRenderer::DidInitializeCompositor(
534 content::SynchronousCompositor* compositor) { 487 content::SynchronousCompositor* compositor) {
535 TRACE_EVENT0("android_webview", 488 TRACE_EVENT0("android_webview",
536 "BrowserViewRenderer::DidInitializeCompositor"); 489 "BrowserViewRenderer::DidInitializeCompositor");
537 DCHECK(compositor); 490 DCHECK(compositor);
538 DCHECK(!has_compositor_); 491 DCHECK(!compositor_);
539 DCHECK(ui_task_runner_->BelongsToCurrentThread()); 492 DCHECK(ui_task_runner_->BelongsToCurrentThread());
540 has_compositor_ = true; 493 compositor_ = compositor;
541 shared_renderer_state_->SetCompositorOnUiThread(compositor);
542 } 494 }
543 495
544 void BrowserViewRenderer::DidDestroyCompositor( 496 void BrowserViewRenderer::DidDestroyCompositor(
545 content::SynchronousCompositor* compositor) { 497 content::SynchronousCompositor* compositor) {
546 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor"); 498 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor");
547 DCHECK(has_compositor_); 499 DCHECK(compositor_);
548 DCHECK(ui_task_runner_->BelongsToCurrentThread()); 500 DCHECK(ui_task_runner_->BelongsToCurrentThread());
549 has_compositor_ = false; 501 compositor_ = NULL;
550 shared_renderer_state_->SetCompositorOnUiThread(NULL);
551 SynchronousCompositorMemoryPolicy zero_policy; 502 SynchronousCompositorMemoryPolicy zero_policy;
552 DCHECK(shared_renderer_state_->GetMemoryPolicy() == zero_policy); 503 DCHECK(memory_policy_ == zero_policy);
553 } 504 }
554 505
555 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) { 506 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) {
556 { 507 {
557 base::AutoLock lock(render_thread_lock_); 508 base::AutoLock lock(render_thread_lock_);
558 if (compositor_needs_continuous_invalidate_ == invalidate) 509 if (compositor_needs_continuous_invalidate_ == invalidate)
559 return; 510 return;
560 511
561 TRACE_EVENT_INSTANT1("android_webview", 512 TRACE_EVENT_INSTANT1("android_webview",
562 "BrowserViewRenderer::SetContinuousInvalidate", 513 "BrowserViewRenderer::SetContinuousInvalidate",
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 } 569 }
619 570
620 TRACE_EVENT_INSTANT2("android_webview", 571 TRACE_EVENT_INSTANT2("android_webview",
621 "BrowserViewRenderer::ScrollTo", 572 "BrowserViewRenderer::ScrollTo",
622 TRACE_EVENT_SCOPE_THREAD, 573 TRACE_EVENT_SCOPE_THREAD,
623 "x", 574 "x",
624 scroll_offset_dip.x(), 575 scroll_offset_dip.x(),
625 "y", 576 "y",
626 scroll_offset_dip.y()); 577 scroll_offset_dip.y());
627 578
628 if (has_compositor_) 579 if (compositor_)
629 shared_renderer_state_->GetCompositor()-> 580 compositor_->DidChangeRootLayerScrollOffset();
630 DidChangeRootLayerScrollOffset();
631 } 581 }
632 582
633 void BrowserViewRenderer::DidUpdateContent() { 583 void BrowserViewRenderer::DidUpdateContent() {
634 if (!ui_task_runner_->BelongsToCurrentThread()) { 584 if (!ui_task_runner_->BelongsToCurrentThread()) {
635 ui_task_runner_->PostTask(FROM_HERE, 585 ui_task_runner_->PostTask(FROM_HERE,
636 base::Bind(&BrowserViewRenderer::DidUpdateContent, 586 base::Bind(&BrowserViewRenderer::DidUpdateContent,
637 ui_thread_weak_ptr_)); 587 ui_thread_weak_ptr_));
638 return; 588 return;
639 } 589 }
640 TRACE_EVENT_INSTANT0("android_webview", 590 TRACE_EVENT_INSTANT0("android_webview",
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 778
829 void BrowserViewRenderer::FallbackTickFired() { 779 void BrowserViewRenderer::FallbackTickFired() {
830 TRACE_EVENT1("android_webview", 780 TRACE_EVENT1("android_webview",
831 "BrowserViewRenderer::FallbackTickFired", 781 "BrowserViewRenderer::FallbackTickFired",
832 "compositor_needs_continuous_invalidate_", 782 "compositor_needs_continuous_invalidate_",
833 compositor_needs_continuous_invalidate_); 783 compositor_needs_continuous_invalidate_);
834 784
835 // This should only be called if OnDraw or DrawGL did not come in time, which 785 // This should only be called if OnDraw or DrawGL did not come in time, which
836 // means block_invalidates_ must still be true. 786 // means block_invalidates_ must still be true.
837 DCHECK(block_invalidates_); 787 DCHECK(block_invalidates_);
838 if (compositor_needs_continuous_invalidate_ && has_compositor_) 788 if (compositor_needs_continuous_invalidate_ && compositor_)
839 ForceFakeCompositeSW(); 789 ForceFakeCompositeSW();
840 } 790 }
841 791
842 void BrowserViewRenderer::ForceFakeCompositeSW() { 792 void BrowserViewRenderer::ForceFakeCompositeSW() {
843 DCHECK(has_compositor_); 793 DCHECK(compositor_);
844 SkBitmap bitmap; 794 SkBitmap bitmap;
845 bitmap.allocN32Pixels(1, 1); 795 bitmap.allocN32Pixels(1, 1);
846 bitmap.eraseColor(0); 796 bitmap.eraseColor(0);
847 SkCanvas canvas(bitmap); 797 SkCanvas canvas(bitmap);
848 CompositeSW(&canvas); 798 CompositeSW(&canvas);
849 } 799 }
850 800
851 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) { 801 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) {
852 DCHECK(has_compositor_); 802 DCHECK(compositor_);
853 bool result = shared_renderer_state_->GetCompositor()-> 803 bool result = compositor_->DemandDrawSw(canvas);
854 DemandDrawSw(canvas);
855 DidComposite(false); 804 DidComposite(false);
856 return result; 805 return result;
857 } 806 }
858 807
859 void BrowserViewRenderer::DidComposite(bool force_invalidate) { 808 void BrowserViewRenderer::DidComposite(bool force_invalidate) {
860 { 809 {
861 base::AutoLock lock(render_thread_lock_); 810 base::AutoLock lock(render_thread_lock_);
862 block_invalidates_ = false; 811 block_invalidates_ = false;
863 } 812 }
864 813
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 base::StringAppendF(&str, 858 base::StringAppendF(&str,
910 "surface width height: [%d %d] ", 859 "surface width height: [%d %d] ",
911 draw_info->width, 860 draw_info->width,
912 draw_info->height); 861 draw_info->height);
913 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); 862 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer);
914 } 863 }
915 return str; 864 return str;
916 } 865 }
917 866
918 } // namespace android_webview 867 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698