OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/exo/surface.h" | 5 #include "components/exo/surface.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 185 |
186 //////////////////////////////////////////////////////////////////////////////// | 186 //////////////////////////////////////////////////////////////////////////////// |
187 // Surface, public: | 187 // Surface, public: |
188 | 188 |
189 Surface::Surface() | 189 Surface::Surface() |
190 : aura::Window(new CustomWindowDelegate(this)), | 190 : aura::Window(new CustomWindowDelegate(this)), |
191 has_pending_contents_(false), | 191 has_pending_contents_(false), |
192 pending_input_region_(SkIRect::MakeLargest()), | 192 pending_input_region_(SkIRect::MakeLargest()), |
193 pending_buffer_scale_(1.0f), | 193 pending_buffer_scale_(1.0f), |
194 pending_only_visible_on_secure_output_(false), | 194 pending_only_visible_on_secure_output_(false), |
| 195 only_visible_on_secure_output_(false), |
195 pending_blend_mode_(SkXfermode::kSrcOver_Mode), | 196 pending_blend_mode_(SkXfermode::kSrcOver_Mode), |
196 pending_alpha_(1.0f), | 197 pending_alpha_(1.0f), |
| 198 alpha_(1.0f), |
197 input_region_(SkIRect::MakeLargest()), | 199 input_region_(SkIRect::MakeLargest()), |
198 needs_commit_surface_hierarchy_(false), | 200 needs_commit_surface_hierarchy_(false), |
199 update_contents_after_successful_compositing_(false), | 201 update_contents_after_successful_compositing_(false), |
200 compositor_(nullptr), | 202 compositor_(nullptr), |
201 delegate_(nullptr) { | 203 delegate_(nullptr) { |
202 SetType(ui::wm::WINDOW_TYPE_CONTROL); | 204 SetType(ui::wm::WINDOW_TYPE_CONTROL); |
203 SetName("ExoSurface"); | 205 SetName("ExoSurface"); |
204 SetProperty(kSurfaceKey, this); | 206 SetProperty(kSurfaceKey, this); |
205 Init(ui::LAYER_SOLID_COLOR); | 207 Init(ui::LAYER_SOLID_COLOR); |
| 208 set_layer_owner_delegate(this); |
206 SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); | 209 SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); |
207 set_owned_by_parent(false); | 210 set_owned_by_parent(false); |
208 surface_manager_ = | 211 surface_manager_ = |
209 aura::Env::GetInstance()->context_factory()->GetSurfaceManager(); | 212 aura::Env::GetInstance()->context_factory()->GetSurfaceManager(); |
210 if (use_surface_layer_) { | 213 if (use_surface_layer_) { |
211 factory_owner_ = make_scoped_refptr(new SurfaceFactoryOwner); | 214 factory_owner_ = make_scoped_refptr(new SurfaceFactoryOwner); |
212 factory_owner_->surface_ = this; | 215 factory_owner_->surface_ = this; |
213 factory_owner_->id_allocator_ = | 216 factory_owner_->id_allocator_ = |
214 aura::Env::GetInstance()->context_factory()->CreateSurfaceIdAllocator(); | 217 aura::Env::GetInstance()->context_factory()->CreateSurfaceIdAllocator(); |
215 factory_owner_->surface_factory_.reset( | 218 factory_owner_->surface_factory_.reset( |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 TRACE_EVENT0("exo", "Surface::Commit"); | 422 TRACE_EVENT0("exo", "Surface::Commit"); |
420 | 423 |
421 needs_commit_surface_hierarchy_ = true; | 424 needs_commit_surface_hierarchy_ = true; |
422 | 425 |
423 if (delegate_) | 426 if (delegate_) |
424 delegate_->OnSurfaceCommit(); | 427 delegate_->OnSurfaceCommit(); |
425 else | 428 else |
426 CommitSurfaceHierarchy(); | 429 CommitSurfaceHierarchy(); |
427 } | 430 } |
428 | 431 |
429 void Surface::CommitLayerContents() { | 432 void Surface::CommitTextureContents() { |
430 // We update contents if Attach() has been called since last commit. | 433 // We update contents if Attach() has been called since last commit. |
431 if (has_pending_contents_) { | 434 if (has_pending_contents_) { |
432 has_pending_contents_ = false; | 435 has_pending_contents_ = false; |
433 | 436 |
434 current_buffer_ = pending_buffer_; | 437 current_buffer_ = pending_buffer_; |
435 pending_buffer_.reset(); | 438 pending_buffer_.reset(); |
436 | 439 |
437 // TODO(dcastagna): Make secure_output_only a layer property instead of a | |
438 // texture mailbox flag so this can be changed without have to provide | |
439 // new contents. | |
440 bool secure_output_only = pending_only_visible_on_secure_output_; | |
441 pending_only_visible_on_secure_output_ = false; | |
442 | |
443 cc::TextureMailbox texture_mailbox; | 440 cc::TextureMailbox texture_mailbox; |
444 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; | 441 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; |
445 if (current_buffer_) { | 442 if (current_buffer_) { |
446 texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox( | 443 texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox( |
447 &texture_mailbox, secure_output_only, false); | 444 &texture_mailbox, only_visible_on_secure_output_, |
| 445 true /* client_usage */); |
448 } | 446 } |
449 | 447 |
450 // Update layer with the new contents. | 448 // Update layer with the new contents. |
451 if (texture_mailbox_release_callback) { | 449 if (texture_mailbox_release_callback) { |
452 texture_size_in_dip_ = gfx::ScaleToFlooredSize( | 450 texture_size_in_dip_ = gfx::ScaleToFlooredSize( |
453 texture_mailbox.size_in_pixels(), 1.0f / pending_buffer_scale_); | 451 texture_mailbox.size_in_pixels(), 1.0f / pending_buffer_scale_); |
454 layer()->SetTextureMailbox(texture_mailbox, | 452 layer()->SetTextureMailbox(texture_mailbox, |
455 std::move(texture_mailbox_release_callback), | 453 std::move(texture_mailbox_release_callback), |
456 texture_size_in_dip_); | 454 texture_size_in_dip_); |
457 layer()->SetTextureFlipped(false); | 455 layer()->SetTextureFlipped(false); |
(...skipping 13 matching lines...) Expand all Loading... |
471 } | 469 } |
472 | 470 |
473 if (layer()->has_external_content()) { | 471 if (layer()->has_external_content()) { |
474 // Determine the new surface size. | 472 // Determine the new surface size. |
475 // - Texture size in DIP defines the size if nothing else is set. | 473 // - Texture size in DIP defines the size if nothing else is set. |
476 // - If a viewport is set then that defines the size, otherwise | 474 // - If a viewport is set then that defines the size, otherwise |
477 // the crop rectangle defines the size if set. | 475 // the crop rectangle defines the size if set. |
478 gfx::Size contents_size = texture_size_in_dip_; | 476 gfx::Size contents_size = texture_size_in_dip_; |
479 if (!pending_viewport_.IsEmpty()) { | 477 if (!pending_viewport_.IsEmpty()) { |
480 contents_size = pending_viewport_; | 478 contents_size = pending_viewport_; |
481 } else if (!pending_crop_.IsEmpty()) { | 479 } else if (!crop_.IsEmpty()) { |
482 DLOG_IF(WARNING, !gfx::IsExpressibleAsInt(pending_crop_.width()) || | 480 DLOG_IF(WARNING, !gfx::IsExpressibleAsInt(crop_.width()) || |
483 !gfx::IsExpressibleAsInt(pending_crop_.height())) | 481 !gfx::IsExpressibleAsInt(crop_.height())) |
484 << "Crop rectangle size (" << pending_crop_.size().ToString() | 482 << "Crop rectangle size (" << crop_.size().ToString() |
485 << ") most be expressible using integers when viewport is not set"; | 483 << ") most be expressible using integers when viewport is not set"; |
486 contents_size = gfx::ToCeiledSize(pending_crop_.size()); | 484 contents_size = gfx::ToCeiledSize(crop_.size()); |
487 } | 485 } |
488 layer()->SetTextureCrop(pending_crop_); | 486 layer()->SetTextureCrop(crop_); |
489 layer()->SetTextureScale(static_cast<float>(texture_size_in_dip_.width()) / | 487 layer()->SetTextureScale(static_cast<float>(texture_size_in_dip_.width()) / |
490 contents_size.width(), | 488 contents_size.width(), |
491 static_cast<float>(texture_size_in_dip_.height()) / | 489 static_cast<float>(texture_size_in_dip_.height()) / |
492 contents_size.height()); | 490 contents_size.height()); |
| 491 layer()->SetTextureAlpha(alpha_); |
493 layer()->SetBounds(gfx::Rect(layer()->bounds().origin(), contents_size)); | 492 layer()->SetBounds(gfx::Rect(layer()->bounds().origin(), contents_size)); |
494 layer()->SetTextureAlpha(pending_alpha_); | |
495 } | 493 } |
496 | 494 |
497 // Move pending frame callbacks to the end of |frame_callbacks_|. | 495 // Move pending frame callbacks to the end of |frame_callbacks_|. |
498 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); | 496 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); |
499 | 497 |
500 // Update alpha compositing properties. | 498 // Update alpha compositing properties. |
501 // TODO(reveman): Use a more reliable way to force blending off than setting | 499 // TODO(reveman): Use a more reliable way to force blending off than setting |
502 // fills-bounds-opaquely. | 500 // fills-bounds-opaquely. |
503 layer()->SetFillsBoundsOpaquely( | 501 layer()->SetFillsBoundsOpaquely( |
504 pending_blend_mode_ == SkXfermode::kSrc_Mode || | 502 pending_blend_mode_ == SkXfermode::kSrc_Mode || |
505 pending_opaque_region_.contains( | 503 pending_opaque_region_.contains( |
506 gfx::RectToSkIRect(gfx::Rect(layer()->size())))); | 504 gfx::RectToSkIRect(gfx::Rect(layer()->size())))); |
507 } | 505 } |
508 | 506 |
509 void Surface::CommitSurfaceContents() { | 507 void Surface::CommitSurfaceContents() { |
510 // We update contents if Attach() has been called since last commit. | 508 // We update contents if Attach() has been called since last commit. |
511 if (has_pending_contents_) { | 509 if (has_pending_contents_) { |
512 has_pending_contents_ = false; | 510 has_pending_contents_ = false; |
513 | 511 |
514 current_buffer_ = pending_buffer_; | 512 current_buffer_ = pending_buffer_; |
515 pending_buffer_.reset(); | 513 pending_buffer_.reset(); |
516 | 514 |
517 bool secure_output_only = pending_only_visible_on_secure_output_; | |
518 pending_only_visible_on_secure_output_ = false; | |
519 | |
520 cc::TextureMailbox texture_mailbox; | 515 cc::TextureMailbox texture_mailbox; |
521 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; | 516 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; |
522 if (current_buffer_) { | 517 if (current_buffer_) { |
523 texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox( | 518 texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox( |
524 &texture_mailbox, secure_output_only, false); | 519 &texture_mailbox, only_visible_on_secure_output_, |
| 520 true /* client_usage */); |
525 } | 521 } |
526 | 522 |
527 cc::SurfaceId old_surface_id = surface_id_; | 523 cc::SurfaceId old_surface_id = surface_id_; |
528 surface_id_ = factory_owner_->id_allocator_->GenerateId(); | 524 surface_id_ = factory_owner_->id_allocator_->GenerateId(); |
529 factory_owner_->surface_factory_->Create(surface_id_); | 525 factory_owner_->surface_factory_->Create(surface_id_); |
530 | 526 |
531 gfx::Size buffer_size = texture_mailbox.size_in_pixels(); | 527 gfx::Size buffer_size = texture_mailbox.size_in_pixels(); |
532 gfx::SizeF scaled_buffer_size( | 528 gfx::SizeF scaled_buffer_size( |
533 gfx::ScaleSize(gfx::SizeF(buffer_size), 1.0f / pending_buffer_scale_)); | 529 gfx::ScaleSize(gfx::SizeF(buffer_size), 1.0f / pending_buffer_scale_)); |
534 | 530 |
535 gfx::Size layer_size; // Size of the output layer, in DIP. | 531 gfx::Size layer_size; // Size of the output layer, in DIP. |
536 if (!pending_viewport_.IsEmpty()) { | 532 if (!pending_viewport_.IsEmpty()) { |
537 layer_size = pending_viewport_; | 533 layer_size = pending_viewport_; |
538 } else if (!pending_crop_.IsEmpty()) { | 534 } else if (!crop_.IsEmpty()) { |
539 DLOG_IF(WARNING, !gfx::IsExpressibleAsInt(pending_crop_.width()) || | 535 DLOG_IF(WARNING, !gfx::IsExpressibleAsInt(crop_.width()) || |
540 !gfx::IsExpressibleAsInt(pending_crop_.height())) | 536 !gfx::IsExpressibleAsInt(crop_.height())) |
541 << "Crop rectangle size (" << pending_crop_.size().ToString() | 537 << "Crop rectangle size (" << crop_.size().ToString() |
542 << ") most be expressible using integers when viewport is not set"; | 538 << ") most be expressible using integers when viewport is not set"; |
543 layer_size = gfx::ToCeiledSize(pending_crop_.size()); | 539 layer_size = gfx::ToCeiledSize(crop_.size()); |
544 } else { | 540 } else { |
545 layer_size = gfx::ToCeiledSize(scaled_buffer_size); | 541 layer_size = gfx::ToCeiledSize(scaled_buffer_size); |
546 } | 542 } |
547 | 543 |
548 // TODO(jbauman): Figure out how this interacts with the pixel size of | 544 // TODO(jbauman): Figure out how this interacts with the pixel size of |
549 // CopyOutputRequests on the layer. | 545 // CopyOutputRequests on the layer. |
550 float contents_surface_to_layer_scale = 1.0; | 546 float contents_surface_to_layer_scale = 1.0; |
551 gfx::Size contents_surface_size = layer_size; | 547 gfx::Size contents_surface_size = layer_size; |
552 | 548 |
553 gfx::PointF uv_top_left(0.f, 0.f); | 549 gfx::PointF uv_top_left(0.f, 0.f); |
554 gfx::PointF uv_bottom_right(1.f, 1.f); | 550 gfx::PointF uv_bottom_right(1.f, 1.f); |
555 if (!pending_crop_.IsEmpty()) { | 551 if (!crop_.IsEmpty()) { |
556 uv_top_left = pending_crop_.origin(); | 552 uv_top_left = crop_.origin(); |
557 | 553 |
558 uv_top_left.Scale(1.f / scaled_buffer_size.width(), | 554 uv_top_left.Scale(1.f / scaled_buffer_size.width(), |
559 1.f / scaled_buffer_size.height()); | 555 1.f / scaled_buffer_size.height()); |
560 uv_bottom_right = pending_crop_.bottom_right(); | 556 uv_bottom_right = crop_.bottom_right(); |
561 uv_bottom_right.Scale(1.f / scaled_buffer_size.width(), | 557 uv_bottom_right.Scale(1.f / scaled_buffer_size.width(), |
562 1.f / scaled_buffer_size.height()); | 558 1.f / scaled_buffer_size.height()); |
563 } | 559 } |
564 | 560 |
565 // pending_damage_ is in Surface coordinates. | 561 // pending_damage_ is in Surface coordinates. |
566 gfx::Rect damage_rect = gfx::SkIRectToRect(pending_damage_.getBounds()); | 562 gfx::Rect damage_rect = gfx::SkIRectToRect(pending_damage_.getBounds()); |
567 | 563 |
568 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | 564 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); |
569 render_pass->SetAll(cc::RenderPassId(1, 1), | 565 render_pass->SetAll(cc::RenderPassId(1, 1), |
570 gfx::Rect(contents_surface_size), damage_rect, | 566 gfx::Rect(contents_surface_size), damage_rect, |
571 gfx::Transform(), true); | 567 gfx::Transform(), true); |
572 | 568 |
573 gfx::Rect quad_rect = gfx::Rect(contents_surface_size); | 569 gfx::Rect quad_rect = gfx::Rect(contents_surface_size); |
574 cc::SharedQuadState* quad_state = | 570 cc::SharedQuadState* quad_state = |
575 render_pass->CreateAndAppendSharedQuadState(); | 571 render_pass->CreateAndAppendSharedQuadState(); |
576 quad_state->quad_layer_bounds = contents_surface_size; | 572 quad_state->quad_layer_bounds = contents_surface_size; |
577 quad_state->visible_quad_layer_rect = quad_rect; | 573 quad_state->visible_quad_layer_rect = quad_rect; |
578 quad_state->opacity = pending_alpha_; | 574 quad_state->opacity = alpha_; |
579 | 575 |
580 bool frame_is_opaque = false; | 576 bool frame_is_opaque = false; |
581 | 577 |
582 std::unique_ptr<cc::DelegatedFrameData> delegated_frame( | 578 std::unique_ptr<cc::DelegatedFrameData> delegated_frame( |
583 new cc::DelegatedFrameData); | 579 new cc::DelegatedFrameData); |
584 if (texture_mailbox_release_callback) { | 580 if (texture_mailbox_release_callback) { |
585 cc::TransferableResource resource; | 581 cc::TransferableResource resource; |
586 resource.id = next_resource_id_++; | 582 resource.id = next_resource_id_++; |
587 resource.format = cc::RGBA_8888; | 583 resource.format = cc::RGBA_8888; |
588 resource.filter = | 584 resource.filter = |
(...skipping 13 matching lines...) Expand all Loading... |
602 pending_opaque_region_.contains(gfx::RectToSkIRect(quad_rect)); | 598 pending_opaque_region_.contains(gfx::RectToSkIRect(quad_rect)); |
603 if (frame_is_opaque) { | 599 if (frame_is_opaque) { |
604 opaque_rect = quad_rect; | 600 opaque_rect = quad_rect; |
605 } else if (pending_opaque_region_.isRect()) { | 601 } else if (pending_opaque_region_.isRect()) { |
606 opaque_rect = gfx::SkIRectToRect(pending_opaque_region_.getBounds()); | 602 opaque_rect = gfx::SkIRectToRect(pending_opaque_region_.getBounds()); |
607 } | 603 } |
608 | 604 |
609 texture_quad->SetNew(quad_state, quad_rect, opaque_rect, quad_rect, | 605 texture_quad->SetNew(quad_state, quad_rect, opaque_rect, quad_rect, |
610 resource.id, true, uv_top_left, uv_bottom_right, | 606 resource.id, true, uv_top_left, uv_bottom_right, |
611 SK_ColorTRANSPARENT, vertex_opacity, false, false, | 607 SK_ColorTRANSPARENT, vertex_opacity, false, false, |
612 secure_output_only); | 608 only_visible_on_secure_output_); |
613 | 609 |
614 factory_owner_->release_callbacks_[resource.id] = std::make_pair( | 610 factory_owner_->release_callbacks_[resource.id] = std::make_pair( |
615 factory_owner_, std::move(texture_mailbox_release_callback)); | 611 factory_owner_, std::move(texture_mailbox_release_callback)); |
616 delegated_frame->resource_list.push_back(resource); | 612 delegated_frame->resource_list.push_back(resource); |
617 } else { | 613 } else { |
618 cc::SolidColorDrawQuad* solid_quad = | 614 cc::SolidColorDrawQuad* solid_quad = |
619 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); | 615 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); |
620 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, | 616 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, |
621 false); | 617 false); |
622 frame_is_opaque = true; | 618 frame_is_opaque = true; |
(...skipping 11 matching lines...) Expand all Loading... |
634 old_surface_id); | 630 old_surface_id); |
635 factory_owner_->surface_factory_->Destroy(old_surface_id); | 631 factory_owner_->surface_factory_->Destroy(old_surface_id); |
636 } | 632 } |
637 | 633 |
638 layer()->SetShowSurface( | 634 layer()->SetShowSurface( |
639 surface_id_, | 635 surface_id_, |
640 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), | 636 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), |
641 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), | 637 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), |
642 contents_surface_size, contents_surface_to_layer_scale, layer_size); | 638 contents_surface_size, contents_surface_to_layer_scale, layer_size); |
643 layer()->SetBounds(gfx::Rect(layer()->bounds().origin(), layer_size)); | 639 layer()->SetBounds(gfx::Rect(layer()->bounds().origin(), layer_size)); |
644 layer()->SetFillsBoundsOpaquely(pending_alpha_ == 1.0f && frame_is_opaque); | 640 layer()->SetFillsBoundsOpaquely(alpha_ == 1.0f && frame_is_opaque); |
645 | 641 |
646 // Reset damage. | 642 // Reset damage. |
647 pending_damage_.setEmpty(); | 643 pending_damage_.setEmpty(); |
648 } | 644 } |
649 // Move pending frame callbacks to the end of active_frame_callbacks_ | 645 // Move pending frame callbacks to the end of active_frame_callbacks_ |
650 active_frame_callbacks_.splice(active_frame_callbacks_.end(), | 646 active_frame_callbacks_.splice(active_frame_callbacks_.end(), |
651 pending_frame_callbacks_); | 647 pending_frame_callbacks_); |
652 } | 648 } |
653 | 649 |
654 void Surface::CommitSurfaceHierarchy() { | 650 void Surface::CommitSurfaceHierarchy() { |
655 DCHECK(needs_commit_surface_hierarchy_); | 651 DCHECK(needs_commit_surface_hierarchy_); |
656 needs_commit_surface_hierarchy_ = false; | 652 needs_commit_surface_hierarchy_ = false; |
657 | 653 |
| 654 // TODO(dcastagna): Make secure_output_only a layer property instead of a |
| 655 // texture mailbox flag so this can be changed without have to provide |
| 656 // new contents. |
| 657 only_visible_on_secure_output_ = pending_only_visible_on_secure_output_; |
| 658 pending_only_visible_on_secure_output_ = false; |
| 659 |
| 660 // Update current alpha. |
| 661 alpha_ = pending_alpha_; |
| 662 |
| 663 // Update current crop rectangle. |
| 664 crop_ = pending_crop_; |
| 665 |
658 if (factory_owner_) { | 666 if (factory_owner_) { |
659 CommitSurfaceContents(); | 667 CommitSurfaceContents(); |
660 } else { | 668 } else { |
661 CommitLayerContents(); | 669 CommitTextureContents(); |
662 } | 670 } |
663 | 671 |
664 // Update current input region. | 672 // Update current input region. |
665 input_region_ = pending_input_region_; | 673 input_region_ = pending_input_region_; |
666 | 674 |
667 // Synchronize window hierarchy. This will position and update the stacking | 675 // Synchronize window hierarchy. This will position and update the stacking |
668 // order of all sub-surfaces after committing all pending state of sub-surface | 676 // order of all sub-surfaces after committing all pending state of sub-surface |
669 // descendants. | 677 // descendants. |
670 aura::Window* stacking_target = nullptr; | 678 aura::Window* stacking_target = nullptr; |
671 for (auto& sub_surface_entry : pending_sub_surfaces_) { | 679 for (auto& sub_surface_entry : pending_sub_surfaces_) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 } | 781 } |
774 | 782 |
775 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, | 783 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, |
776 aura::Window* new_root) { | 784 aura::Window* new_root) { |
777 DCHECK(compositor_); | 785 DCHECK(compositor_); |
778 compositor_->RemoveObserver(this); | 786 compositor_->RemoveObserver(this); |
779 compositor_ = nullptr; | 787 compositor_ = nullptr; |
780 } | 788 } |
781 | 789 |
782 //////////////////////////////////////////////////////////////////////////////// | 790 //////////////////////////////////////////////////////////////////////////////// |
| 791 // ui::LayerOwnerDelegate overrides: |
| 792 |
| 793 void Surface::OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) { |
| 794 if (!current_buffer_) |
| 795 return; |
| 796 |
| 797 // TODO(reveman): Give the client a chance to provide new contents. |
| 798 if (factory_owner_) { |
| 799 SetSurfaceLayerContents(new_layer); |
| 800 } else { |
| 801 SetTextureLayerContents(new_layer); |
| 802 } |
| 803 } |
| 804 |
| 805 //////////////////////////////////////////////////////////////////////////////// |
783 // ui::CompositorObserver overrides: | 806 // ui::CompositorObserver overrides: |
784 | 807 |
785 void Surface::OnCompositingDidCommit(ui::Compositor* compositor) { | 808 void Surface::OnCompositingDidCommit(ui::Compositor* compositor) { |
786 DCHECK(!factory_owner_); | 809 DCHECK(!factory_owner_); |
787 // Move frame callbacks to the end of |active_frame_callbacks_|. | 810 // Move frame callbacks to the end of |active_frame_callbacks_|. |
788 active_frame_callbacks_.splice(active_frame_callbacks_.end(), | 811 active_frame_callbacks_.splice(active_frame_callbacks_.end(), |
789 frame_callbacks_); | 812 frame_callbacks_); |
790 } | 813 } |
791 | 814 |
792 void Surface::OnCompositingStarted(ui::Compositor* compositor, | 815 void Surface::OnCompositingStarted(ui::Compositor* compositor, |
(...skipping 11 matching lines...) Expand all Loading... |
804 // Nothing more to do in here unless this has been set. | 827 // Nothing more to do in here unless this has been set. |
805 if (!update_contents_after_successful_compositing_) | 828 if (!update_contents_after_successful_compositing_) |
806 return; | 829 return; |
807 | 830 |
808 update_contents_after_successful_compositing_ = false; | 831 update_contents_after_successful_compositing_ = false; |
809 | 832 |
810 // Early out if no contents is currently assigned to the surface. | 833 // Early out if no contents is currently assigned to the surface. |
811 if (!current_buffer_) | 834 if (!current_buffer_) |
812 return; | 835 return; |
813 | 836 |
814 // TODO(dcastagna): Make secure_output_only a layer property instead of a | |
815 // texture mailbox flag. | |
816 bool secure_output_only = false; | |
817 | |
818 // Update contents by producing a new texture mailbox for the current buffer. | 837 // Update contents by producing a new texture mailbox for the current buffer. |
819 cc::TextureMailbox texture_mailbox; | 838 SetTextureLayerContents(layer()); |
820 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback = | |
821 current_buffer_->ProduceTextureMailbox(&texture_mailbox, | |
822 secure_output_only, true); | |
823 if (texture_mailbox_release_callback) { | |
824 layer()->SetTextureMailbox(texture_mailbox, | |
825 std::move(texture_mailbox_release_callback), | |
826 layer()->bounds().size()); | |
827 layer()->SetTextureFlipped(false); | |
828 layer()->SchedulePaint(gfx::Rect(texture_mailbox.size_in_pixels())); | |
829 } | |
830 } | 839 } |
831 | 840 |
832 void Surface::OnCompositingAborted(ui::Compositor* compositor) { | 841 void Surface::OnCompositingAborted(ui::Compositor* compositor) { |
833 // The contents of this surface might be lost if compositing aborted because | 842 // The contents of this surface might be lost if compositing aborted because |
834 // of a lost graphics context. We recover from this by updating the contents | 843 // of a lost graphics context. We recover from this by updating the contents |
835 // of the surface next time the compositor successfully ends compositing. | 844 // of the surface next time the compositor successfully ends compositing. |
836 update_contents_after_successful_compositing_ = true; | 845 update_contents_after_successful_compositing_ = true; |
837 } | 846 } |
838 | 847 |
839 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) { | 848 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) { |
840 compositor->RemoveObserver(this); | 849 compositor->RemoveObserver(this); |
841 compositor_ = nullptr; | 850 compositor_ = nullptr; |
842 } | 851 } |
843 | 852 |
844 void Surface::WillDraw(cc::SurfaceId id) { | 853 void Surface::WillDraw(cc::SurfaceId id) { |
845 while (!active_frame_callbacks_.empty()) { | 854 while (!active_frame_callbacks_.empty()) { |
846 active_frame_callbacks_.front().Run(base::TimeTicks::Now()); | 855 active_frame_callbacks_.front().Run(base::TimeTicks::Now()); |
847 active_frame_callbacks_.pop_front(); | 856 active_frame_callbacks_.pop_front(); |
848 } | 857 } |
849 } | 858 } |
850 | 859 |
| 860 void Surface::SetTextureLayerContents(ui::Layer* layer) { |
| 861 DCHECK(current_buffer_); |
| 862 |
| 863 cc::TextureMailbox texture_mailbox; |
| 864 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback = |
| 865 current_buffer_->ProduceTextureMailbox(&texture_mailbox, |
| 866 only_visible_on_secure_output_, |
| 867 false /* client_usage */); |
| 868 if (!texture_mailbox_release_callback) |
| 869 return; |
| 870 |
| 871 layer->SetTextureMailbox(texture_mailbox, |
| 872 std::move(texture_mailbox_release_callback), |
| 873 texture_size_in_dip_); |
| 874 layer->SetTextureFlipped(false); |
| 875 layer->SetTextureCrop(crop_); |
| 876 layer->SetTextureScale(static_cast<float>(texture_size_in_dip_.width()) / |
| 877 layer->bounds().width(), |
| 878 static_cast<float>(texture_size_in_dip_.height()) / |
| 879 layer->bounds().height()); |
| 880 layer->SetTextureAlpha(alpha_); |
| 881 } |
| 882 |
| 883 void Surface::SetSurfaceLayerContents(ui::Layer* layer) { |
| 884 // TODO(jbauman): Implement this. |
| 885 NOTIMPLEMENTED(); |
| 886 } |
| 887 |
851 bool Surface::use_surface_layer_ = false; | 888 bool Surface::use_surface_layer_ = false; |
852 | 889 |
853 } // namespace exo | 890 } // namespace exo |
OLD | NEW |