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

Side by Side Diff: content/browser/renderer_host/compositor_impl_android.cc

Issue 1371523003: Android: Don't destroy LayerTreeHost when Surface goes away (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « content/browser/renderer_host/compositor_impl_android.h ('k') | ui/android/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/compositor_impl_android.h" 5 #include "content/browser/renderer_host/compositor_impl_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 #include <android/native_window_jni.h> 8 #include <android/native_window_jni.h>
9 9
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
11 #include "base/android/scoped_java_ref.h" 11 #include "base/android/scoped_java_ref.h"
12 #include "base/auto_reset.h"
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/cancelable_callback.h" 14 #include "base/cancelable_callback.h"
14 #include "base/command_line.h" 15 #include "base/command_line.h"
15 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
16 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
19 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
20 #include "base/synchronization/lock.h" 21 #include "base/synchronization/lock.h"
21 #include "base/thread_task_runner_handle.h" 22 #include "base/thread_task_runner_handle.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 new cc::SurfaceIdAllocator(++g_surface_id_namespace)); 224 new cc::SurfaceIdAllocator(++g_surface_id_namespace));
224 cc::SurfaceManager* manager = GetSurfaceManager(); 225 cc::SurfaceManager* manager = GetSurfaceManager();
225 DCHECK(manager); 226 DCHECK(manager);
226 allocator->RegisterSurfaceIdNamespace(manager); 227 allocator->RegisterSurfaceIdNamespace(manager);
227 return allocator.Pass(); 228 return allocator.Pass();
228 } 229 }
229 230
230 CompositorImpl::CompositorImpl(CompositorClient* client, 231 CompositorImpl::CompositorImpl(CompositorClient* client,
231 gfx::NativeWindow root_window) 232 gfx::NativeWindow root_window)
232 : root_layer_(cc::Layer::Create(Compositor::LayerSettings())), 233 : root_layer_(cc::Layer::Create(Compositor::LayerSettings())),
233 resource_manager_(&ui_resource_provider_),
234 surface_id_allocator_(GetSurfaceManager() ? CreateSurfaceIdAllocator() 234 surface_id_allocator_(GetSurfaceManager() ? CreateSurfaceIdAllocator()
235 : nullptr), 235 : nullptr),
236 has_transparent_background_(false), 236 has_transparent_background_(false),
237 device_scale_factor_(1), 237 device_scale_factor_(1),
238 window_(NULL), 238 window_(NULL),
239 surface_id_(0), 239 surface_id_(0),
240 client_(client), 240 client_(client),
241 root_window_(root_window), 241 root_window_(root_window),
242 did_post_swapbuffers_(false), 242 did_post_swapbuffers_(false),
243 ignore_schedule_composite_(false), 243 ignore_schedule_composite_(false),
244 needs_composite_(false), 244 needs_composite_(false),
245 needs_animate_(false), 245 needs_animate_(false),
246 will_composite_immediately_(false), 246 will_composite_immediately_(false),
247 composite_on_vsync_trigger_(DO_NOT_COMPOSITE), 247 composite_on_vsync_trigger_(DO_NOT_COMPOSITE),
248 pending_swapbuffers_(0U), 248 pending_swapbuffers_(0U),
249 num_successive_context_creation_failures_(0), 249 num_successive_context_creation_failures_(0),
250 output_surface_request_pending_(false), 250 output_surface_request_pending_(false),
251 weak_factory_(this) { 251 weak_factory_(this) {
252 DCHECK(client); 252 DCHECK(client);
253 DCHECK(root_window); 253 DCHECK(root_window);
254 root_window->AttachCompositor(this); 254 root_window->AttachCompositor(this);
255 CreateLayerTreeHost();
256 resource_manager_.Init(host_.get());
255 } 257 }
256 258
257 CompositorImpl::~CompositorImpl() { 259 CompositorImpl::~CompositorImpl() {
258 root_window_->DetachCompositor(); 260 root_window_->DetachCompositor();
259 // Clean-up any surface references. 261 // Clean-up any surface references.
260 SetSurface(NULL); 262 SetSurface(NULL);
261 } 263 }
262 264
263 void CompositorImpl::PostComposite(CompositingTrigger trigger) { 265 void CompositorImpl::PostComposite(CompositingTrigger trigger) {
266 DCHECK(host_->visible());
264 DCHECK(needs_composite_); 267 DCHECK(needs_composite_);
265 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); 268 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY);
266 269
267 if (will_composite_immediately_ || 270 if (will_composite_immediately_ ||
268 (trigger == COMPOSITE_EVENTUALLY && WillComposite())) { 271 (trigger == COMPOSITE_EVENTUALLY && WillComposite())) {
269 // We will already composite soon enough. 272 // We will already composite soon enough.
270 DCHECK(WillComposite()); 273 DCHECK(WillComposite());
271 return; 274 return;
272 } 275 }
273 276
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 current_composite_task_.reset(new base::CancelableClosure( 320 current_composite_task_.reset(new base::CancelableClosure(
318 base::Bind(&CompositorImpl::Composite, base::Unretained(this), trigger))); 321 base::Bind(&CompositorImpl::Composite, base::Unretained(this), trigger)));
319 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 322 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
320 FROM_HERE, current_composite_task_->callback(), delay); 323 FROM_HERE, current_composite_task_->callback(), delay);
321 } 324 }
322 325
323 void CompositorImpl::Composite(CompositingTrigger trigger) { 326 void CompositorImpl::Composite(CompositingTrigger trigger) {
324 if (trigger == COMPOSITE_IMMEDIATELY) 327 if (trigger == COMPOSITE_IMMEDIATELY)
325 will_composite_immediately_ = false; 328 will_composite_immediately_ = false;
326 329
327 DCHECK(host_); 330 DCHECK(host_->visible());
328 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); 331 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY);
329 DCHECK(needs_composite_); 332 DCHECK(needs_composite_);
330 DCHECK(!DidCompositeThisFrame()); 333 DCHECK(!DidCompositeThisFrame());
331 334
332 DCHECK_LE(pending_swapbuffers_, kMaxSwapBuffers); 335 DCHECK_LE(pending_swapbuffers_, kMaxSwapBuffers);
333 // Swap Ack accounting is unreliable if the OutputSurface was lost. 336 // Swap Ack accounting is unreliable if the OutputSurface was lost.
334 // In that case still attempt to composite, which will cause creation of a 337 // In that case still attempt to composite, which will cause creation of a
335 // new OutputSurface and reset pending_swapbuffers_. 338 // new OutputSurface and reset pending_swapbuffers_.
336 if (pending_swapbuffers_ == kMaxSwapBuffers && 339 if (pending_swapbuffers_ == kMaxSwapBuffers &&
337 !host_->output_surface_lost()) { 340 !host_->output_surface_lost()) {
338 TRACE_EVENT0("compositor", "CompositorImpl_SwapLimit"); 341 TRACE_EVENT0("compositor", "CompositorImpl_SwapLimit");
339 return; 342 return;
340 } 343 }
341 344
342 // Reset state before Layout+Composite since that might create more 345 // Reset state before Layout+Composite since that might create more
343 // requests to Composite that we need to respect. 346 // requests to Composite that we need to respect.
344 needs_composite_ = false; 347 needs_composite_ = false;
345 348
346 // Only allow compositing once per vsync. 349 // Only allow compositing once per vsync.
347 current_composite_task_->Cancel(); 350 current_composite_task_->Cancel();
348 DCHECK(DidCompositeThisFrame() && !WillComposite()); 351 DCHECK(DidCompositeThisFrame() && !WillComposite());
349 352
350 // Ignore ScheduleComposite() from layer tree changes during layout and
351 // animation updates that will already be reflected in the current frame
352 // we are about to draw.
353 ignore_schedule_composite_ = true;
354
355 const base::TimeTicks frame_time = base::TimeTicks::Now(); 353 const base::TimeTicks frame_time = base::TimeTicks::Now();
356 if (needs_animate_) { 354 if (needs_animate_) {
355 base::AutoReset<bool> auto_reset_ignore_schedule(
356 &ignore_schedule_composite_, true);
357 needs_animate_ = false; 357 needs_animate_ = false;
358 root_window_->Animate(frame_time); 358 root_window_->Animate(frame_time);
359 } 359 }
360 ignore_schedule_composite_ = false;
361 360
362 did_post_swapbuffers_ = false; 361 did_post_swapbuffers_ = false;
363 host_->Composite(frame_time); 362 host_->Composite(frame_time);
364 if (did_post_swapbuffers_) 363 if (did_post_swapbuffers_)
365 pending_swapbuffers_++; 364 pending_swapbuffers_++;
366 365
367 // Need to track vsync to avoid compositing more than once per frame. 366 // Need to track vsync to avoid compositing more than once per frame.
368 root_window_->RequestVSyncUpdate(); 367 root_window_->RequestVSyncUpdate();
369 } 368 }
370 369
371 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { 370 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() {
372 return ui_resource_provider_; 371 return *this;
373 } 372 }
374 373
375 ui::ResourceManager& CompositorImpl::GetResourceManager() { 374 ui::ResourceManager& CompositorImpl::GetResourceManager() {
376 return resource_manager_; 375 return resource_manager_;
377 } 376 }
378 377
379 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { 378 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) {
380 if (subroot_layer_.get()) { 379 if (subroot_layer_.get()) {
381 subroot_layer_->RemoveFromParent(); 380 subroot_layer_->RemoveFromParent();
382 subroot_layer_ = NULL; 381 subroot_layer_ = NULL;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 if (window) { 432 if (window) {
434 SetWindowSurface(window); 433 SetWindowSurface(window);
435 ANativeWindow_release(window); 434 ANativeWindow_release(window);
436 RegisterViewSurface(surface_id_, j_surface.obj()); 435 RegisterViewSurface(surface_id_, j_surface.obj());
437 } 436 }
438 } 437 }
439 438
440 void CompositorImpl::CreateLayerTreeHost() { 439 void CompositorImpl::CreateLayerTreeHost() {
441 DCHECK(!host_); 440 DCHECK(!host_);
442 DCHECK(!WillCompositeThisFrame()); 441 DCHECK(!WillCompositeThisFrame());
443 needs_composite_ = false; 442
444 pending_swapbuffers_ = 0; 443 // Just in case, since we immediately hide the LTH in this function,
444 // and we do not want to end up with a pending Composite task when the
445 // host is hidden.
446 base::AutoReset<bool> auto_reset_ignore_schedule(&ignore_schedule_composite_,
447 true);
448
445 cc::LayerTreeSettings settings; 449 cc::LayerTreeSettings settings;
446 settings.renderer_settings.refresh_rate = 60.0; 450 settings.renderer_settings.refresh_rate = 60.0;
447 settings.renderer_settings.allow_antialiasing = false; 451 settings.renderer_settings.allow_antialiasing = false;
448 settings.renderer_settings.highp_threshold_min = 2048; 452 settings.renderer_settings.highp_threshold_min = 2048;
449 settings.use_zero_copy = true; 453 settings.use_zero_copy = true;
450 454
451 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 455 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
452 settings.initial_debug_state.SetRecordRenderingStats( 456 settings.initial_debug_state.SetRecordRenderingStats(
453 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); 457 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking));
454 settings.initial_debug_state.show_fps_counter = 458 settings.initial_debug_state.show_fps_counter =
455 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); 459 command_line->HasSwitch(cc::switches::kUIShowFPSCounter);
456 // TODO(enne): Update this this compositor to use the scheduler. 460 // TODO(enne): Update this this compositor to use the scheduler.
457 settings.single_thread_proxy_scheduler = false; 461 settings.single_thread_proxy_scheduler = false;
458 462
459 if (command_line->HasSwitch( 463 if (command_line->HasSwitch(
460 switches::kEnableAndroidCompositorAnimationTimelines)) 464 switches::kEnableAndroidCompositorAnimationTimelines))
461 settings.use_compositor_animation_timelines = true; 465 settings.use_compositor_animation_timelines = true;
462 466
463 cc::LayerTreeHost::InitParams params; 467 cc::LayerTreeHost::InitParams params;
464 params.client = this; 468 params.client = this;
465 params.shared_bitmap_manager = HostSharedBitmapManager::current(); 469 params.shared_bitmap_manager = HostSharedBitmapManager::current();
466 params.gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager::current(); 470 params.gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager::current();
467 params.task_graph_runner = g_task_graph_runner.Pointer(); 471 params.task_graph_runner = g_task_graph_runner.Pointer();
468 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); 472 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
469 params.settings = &settings; 473 params.settings = &settings;
470 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, &params); 474 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, &params);
475 host_->SetVisible(false);
471 host_->SetRootLayer(root_layer_); 476 host_->SetRootLayer(root_layer_);
472
473 host_->SetVisible(true);
474 host_->SetLayerTreeHostClientReady(); 477 host_->SetLayerTreeHostClientReady();
475 host_->SetViewportSize(size_); 478 host_->SetViewportSize(size_);
476 host_->set_has_transparent_background(has_transparent_background_); 479 host_->set_has_transparent_background(has_transparent_background_);
477 host_->SetDeviceScaleFactor(device_scale_factor_); 480 host_->SetDeviceScaleFactor(device_scale_factor_);
478 481
479 if (needs_animate_) 482 if (needs_animate_)
480 host_->SetNeedsAnimate(); 483 host_->SetNeedsAnimate();
481 } 484 }
482 485
483 void CompositorImpl::SetVisible(bool visible) { 486 void CompositorImpl::SetVisible(bool visible) {
484 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); 487 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible);
485 if (!visible) { 488 if (!visible) {
486 DCHECK(host_); 489 DCHECK(host_->visible());
487 // Look for any layers that were attached to the root for readback 490 // Look for any layers that were attached to the root for readback
488 // and are waiting for Composite() to happen. 491 // and are waiting for Composite() to happen.
489 bool readback_pending = false; 492 bool readback_pending = false;
490 for (size_t i = 0; i < root_layer_->children().size(); ++i) { 493 for (size_t i = 0; i < root_layer_->children().size(); ++i) {
491 if (root_layer_->children()[i]->HasCopyRequest()) { 494 if (root_layer_->children()[i]->HasCopyRequest()) {
492 readback_pending = true; 495 readback_pending = true;
493 break; 496 break;
494 } 497 }
495 } 498 }
496 if (readback_pending) { 499 if (readback_pending) {
497 ignore_schedule_composite_ = true; 500 base::AutoReset<bool> auto_reset_ignore_schedule(
501 &ignore_schedule_composite_, true);
498 host_->Composite(base::TimeTicks::Now()); 502 host_->Composite(base::TimeTicks::Now());
499 ignore_schedule_composite_ = false;
500 } 503 }
501 if (WillComposite()) 504 if (WillComposite())
502 CancelComposite(); 505 CancelComposite();
503 ui_resource_provider_.SetLayerTreeHost(NULL); 506 host_->SetVisible(false);
504 host_.reset(); 507 if (!host_->output_surface_lost())
508 host_->ReleaseOutputSurface();
509 pending_swapbuffers_ = 0;
510 needs_composite_ = false;
511 composite_on_vsync_trigger_ = DO_NOT_COMPOSITE;
505 establish_gpu_channel_timeout_.Stop(); 512 establish_gpu_channel_timeout_.Stop();
506 output_surface_request_pending_ = false;
507 display_client_.reset(); 513 display_client_.reset();
508 if (current_composite_task_) { 514 if (current_composite_task_) {
509 current_composite_task_->Cancel(); 515 current_composite_task_->Cancel();
510 current_composite_task_.reset(); 516 current_composite_task_.reset();
511 } 517 }
512 } else if (!host_) { 518 } else {
513 CreateLayerTreeHost(); 519 host_->SetVisible(true);
514 ui_resource_provider_.SetLayerTreeHost(host_.get()); 520 if (output_surface_request_pending_)
521 RequestNewOutputSurface();
522 SetNeedsComposite();
515 } 523 }
516 } 524 }
517 525
518 void CompositorImpl::setDeviceScaleFactor(float factor) { 526 void CompositorImpl::setDeviceScaleFactor(float factor) {
519 device_scale_factor_ = factor; 527 device_scale_factor_ = factor;
520 if (host_) 528 if (host_)
521 host_->SetDeviceScaleFactor(factor); 529 host_->SetDeviceScaleFactor(factor);
522 } 530 }
523 531
524 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { 532 void CompositorImpl::SetWindowBounds(const gfx::Size& size) {
525 if (size_ == size) 533 if (size_ == size)
526 return; 534 return;
527 535
528 size_ = size; 536 size_ = size;
529 if (host_) 537 if (host_)
530 host_->SetViewportSize(size); 538 host_->SetViewportSize(size);
531 if (display_client_) 539 if (display_client_)
532 display_client_->display()->Resize(size); 540 display_client_->display()->Resize(size);
533 root_layer_->SetBounds(size); 541 root_layer_->SetBounds(size);
534 } 542 }
535 543
536 void CompositorImpl::SetHasTransparentBackground(bool flag) { 544 void CompositorImpl::SetHasTransparentBackground(bool flag) {
537 has_transparent_background_ = flag; 545 has_transparent_background_ = flag;
538 if (host_) 546 if (host_)
539 host_->set_has_transparent_background(flag); 547 host_->set_has_transparent_background(flag);
540 } 548 }
541 549
542 void CompositorImpl::SetNeedsComposite() { 550 void CompositorImpl::SetNeedsComposite() {
543 if (!host_.get()) 551 if (!host_->visible())
544 return; 552 return;
545 DCHECK(!needs_composite_ || WillComposite()); 553 DCHECK(!needs_composite_ || WillComposite());
546 554
547 needs_composite_ = true; 555 needs_composite_ = true;
548 PostComposite(COMPOSITE_IMMEDIATELY); 556 PostComposite(COMPOSITE_IMMEDIATELY);
549 } 557 }
550 558
551 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> 559 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
552 CreateGpuProcessViewContext( 560 CreateGpuProcessViewContext(
553 const scoped_refptr<GpuChannelHost>& gpu_channel_host, 561 const scoped_refptr<GpuChannelHost>& gpu_channel_host,
(...skipping 18 matching lines...) Expand all
572 new WebGraphicsContext3DCommandBufferImpl(surface_id, 580 new WebGraphicsContext3DCommandBufferImpl(surface_id,
573 url, 581 url,
574 gpu_channel_host.get(), 582 gpu_channel_host.get(),
575 attributes, 583 attributes,
576 lose_context_when_out_of_memory, 584 lose_context_when_out_of_memory,
577 limits, 585 limits,
578 NULL)); 586 NULL));
579 } 587 }
580 588
581 void CompositorImpl::Layout() { 589 void CompositorImpl::Layout() {
582 ignore_schedule_composite_ = true; 590 base::AutoReset<bool> auto_reset_ignore_schedule(&ignore_schedule_composite_,
591 true);
583 client_->Layout(); 592 client_->Layout();
584 ignore_schedule_composite_ = false;
585 } 593 }
586 594
587 void CompositorImpl::OnGpuChannelEstablished() { 595 void CompositorImpl::OnGpuChannelEstablished() {
588 establish_gpu_channel_timeout_.Stop(); 596 establish_gpu_channel_timeout_.Stop();
589 CreateOutputSurface(); 597 CreateOutputSurface();
590 } 598 }
591 599
592 void CompositorImpl::OnGpuChannelTimeout() { 600 void CompositorImpl::OnGpuChannelTimeout() {
593 LOG(FATAL) << "Timed out waiting for GPU channel."; 601 LOG(FATAL) << "Timed out waiting for GPU channel.";
594 } 602 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 634
627 void CompositorImpl::DidFailToInitializeOutputSurface() { 635 void CompositorImpl::DidFailToInitializeOutputSurface() {
628 LOG(ERROR) << "Failed to init OutputSurface for compositor."; 636 LOG(ERROR) << "Failed to init OutputSurface for compositor.";
629 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) 637 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2)
630 << "Too many context creation failures. Giving up... "; 638 << "Too many context creation failures. Giving up... ";
631 RequestNewOutputSurface(); 639 RequestNewOutputSurface();
632 } 640 }
633 641
634 void CompositorImpl::CreateOutputSurface() { 642 void CompositorImpl::CreateOutputSurface() {
635 // We might have had a request from a LayerTreeHost that was then 643 // We might have had a request from a LayerTreeHost that was then
636 // deleted. 644 // hidden (and hidden means we don't have a native surface).
637 if (!output_surface_request_pending_) 645 // Also make sure we only handle this once.
646 if (!output_surface_request_pending_ || !host_->visible())
638 return; 647 return;
639 648
640 blink::WebGraphicsContext3D::Attributes attrs; 649 blink::WebGraphicsContext3D::Attributes attrs;
641 attrs.shareResources = true; 650 attrs.shareResources = true;
642 attrs.noAutomaticFlushes = true; 651 attrs.noAutomaticFlushes = true;
643 pending_swapbuffers_ = 0; 652 pending_swapbuffers_ = 0;
644 653
645 DCHECK(window_); 654 DCHECK(window_);
646 DCHECK(surface_id_); 655 DCHECK(surface_id_);
647 656
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 surface_output_surface->set_display_client(display_client_.get()); 688 surface_output_surface->set_display_client(display_client_.get());
680 display_client_->display()->Resize(size_); 689 display_client_->display()->Resize(size_);
681 host_->SetOutputSurface(surface_output_surface.Pass()); 690 host_->SetOutputSurface(surface_output_surface.Pass());
682 } else { 691 } else {
683 host_->SetOutputSurface(real_output_surface.Pass()); 692 host_->SetOutputSurface(real_output_surface.Pass());
684 } 693 }
685 } 694 }
686 695
687 void CompositorImpl::PopulateGpuCapabilities( 696 void CompositorImpl::PopulateGpuCapabilities(
688 gpu::Capabilities gpu_capabilities) { 697 gpu::Capabilities gpu_capabilities) {
689 ui_resource_provider_.SetSupportsETC1NonPowerOfTwo( 698 gpu_capabilities_ = gpu_capabilities;
690 gpu_capabilities.texture_format_etc1_npot);
691 } 699 }
692 700
693 void CompositorImpl::AddObserver(VSyncObserver* observer) { 701 void CompositorImpl::AddObserver(VSyncObserver* observer) {
694 observer_list_.AddObserver(observer); 702 observer_list_.AddObserver(observer);
695 } 703 }
696 704
697 void CompositorImpl::RemoveObserver(VSyncObserver* observer) { 705 void CompositorImpl::RemoveObserver(VSyncObserver* observer) {
698 observer_list_.RemoveObserver(observer); 706 observer_list_.RemoveObserver(observer);
699 } 707 }
700 708
709 cc::UIResourceId CompositorImpl::CreateUIResource(
710 cc::UIResourceClient* client) {
711 return host_->CreateUIResource(client);
712 }
713
714 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) {
715 host_->DeleteUIResource(resource_id);
716 }
717
718 bool CompositorImpl::SupportsETC1NonPowerOfTwo() const {
719 return gpu_capabilities_.texture_format_etc1_npot;
720 }
721
701 void CompositorImpl::ScheduleComposite() { 722 void CompositorImpl::ScheduleComposite() {
702 DCHECK(!needs_composite_ || WillComposite()); 723 if (ignore_schedule_composite_ || !host_->visible())
703 if (ignore_schedule_composite_)
704 return; 724 return;
705 725
726 DCHECK_IMPLIES(needs_composite_, WillComposite());
706 needs_composite_ = true; 727 needs_composite_ = true;
707 // We currently expect layer tree invalidations at most once per frame 728 // We currently expect layer tree invalidations at most once per frame
708 // during normal operation and therefore try to composite immediately 729 // during normal operation and therefore try to composite immediately
709 // to minimize latency. 730 // to minimize latency.
710 PostComposite(COMPOSITE_IMMEDIATELY); 731 PostComposite(COMPOSITE_IMMEDIATELY);
711 } 732 }
712 733
713 void CompositorImpl::ScheduleAnimation() { 734 void CompositorImpl::ScheduleAnimation() {
714 DCHECK(!needs_composite_ || WillComposite());
715 needs_animate_ = true; 735 needs_animate_ = true;
716 736
717 if (needs_composite_) 737 if (!host_->visible())
718 return; 738 return;
719 739
740 if (needs_composite_) {
741 DCHECK(WillComposite());
742 return;
743 }
744
720 TRACE_EVENT0("cc", "CompositorImpl::ScheduleAnimation"); 745 TRACE_EVENT0("cc", "CompositorImpl::ScheduleAnimation");
721 needs_composite_ = true; 746 needs_composite_ = true;
722 PostComposite(COMPOSITE_EVENTUALLY); 747 PostComposite(COMPOSITE_EVENTUALLY);
723 } 748 }
724 749
725 void CompositorImpl::DidPostSwapBuffers() { 750 void CompositorImpl::DidPostSwapBuffers() {
726 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); 751 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers");
727 did_post_swapbuffers_ = true; 752 did_post_swapbuffers_ = true;
728 } 753 }
729 754
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 composite_on_vsync_trigger_ = DO_NOT_COMPOSITE; 803 composite_on_vsync_trigger_ = DO_NOT_COMPOSITE;
779 PostComposite(trigger); 804 PostComposite(trigger);
780 } 805 }
781 806
782 FOR_EACH_OBSERVER(VSyncObserver, observer_list_, 807 FOR_EACH_OBSERVER(VSyncObserver, observer_list_,
783 OnUpdateVSyncParameters(frame_time, vsync_period)); 808 OnUpdateVSyncParameters(frame_time, vsync_period));
784 } 809 }
785 810
786 void CompositorImpl::SetNeedsAnimate() { 811 void CompositorImpl::SetNeedsAnimate() {
787 needs_animate_ = true; 812 needs_animate_ = true;
788 if (!host_) 813 if (!host_->visible())
789 return; 814 return;
790 815
791 host_->SetNeedsAnimate(); 816 host_->SetNeedsAnimate();
792 } 817 }
793 818
794 } // namespace content 819 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/compositor_impl_android.h ('k') | ui/android/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698