Chromium Code Reviews| Index: components/exo/surface.cc |
| diff --git a/components/exo/surface.cc b/components/exo/surface.cc |
| index eebd302c0fc36371c9648af7092edbbf4dd73207..b4b2681f95430a8f0c0bd56bacbf393596a9ffbf 100644 |
| --- a/components/exo/surface.cc |
| +++ b/components/exo/surface.cc |
| @@ -190,8 +190,6 @@ Surface::Surface() |
| : window_(new aura::Window(new CustomWindowDelegate(this))), |
| has_pending_contents_(false), |
| needs_commit_surface_hierarchy_(false), |
| - update_contents_after_successful_compositing_(false), |
| - compositor_(nullptr), |
| delegate_(nullptr) { |
| window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
| window_->SetName("ExoSurface"); |
| @@ -202,18 +200,12 @@ Surface::Surface() |
| window_->set_owned_by_parent(false); |
| surface_manager_ = |
| aura::Env::GetInstance()->context_factory()->GetSurfaceManager(); |
| - if (use_surface_layer_) { |
| - factory_owner_ = make_scoped_refptr(new SurfaceFactoryOwner); |
| - factory_owner_->surface_ = this; |
| - factory_owner_->id_allocator_ = |
| - aura::Env::GetInstance()->context_factory()->CreateSurfaceIdAllocator(); |
| - factory_owner_->surface_factory_.reset( |
| - new cc::SurfaceFactory(surface_manager_, factory_owner_.get())); |
| - } |
| - |
| - if (!factory_owner_) { |
| - window_->AddObserver(this); |
| - } |
| + factory_owner_ = make_scoped_refptr(new SurfaceFactoryOwner); |
|
reveman
2016/06/15 19:05:08
nit: move to initializer list
|
| + factory_owner_->surface_ = this; |
| + factory_owner_->id_allocator_ = |
| + aura::Env::GetInstance()->context_factory()->CreateSurfaceIdAllocator(); |
| + factory_owner_->surface_factory_.reset( |
| + new cc::SurfaceFactory(surface_manager_, factory_owner_.get())); |
| } |
| Surface::~Surface() { |
| @@ -221,13 +213,7 @@ Surface::~Surface() { |
| window_->layer()->SetShowSolidColorContent(); |
| - if (factory_owner_) { |
| - factory_owner_->surface_ = nullptr; |
| - } else { |
| - window_->RemoveObserver(this); |
| - } |
| - if (compositor_) |
| - compositor_->RemoveObserver(this); |
| + factory_owner_->surface_ = nullptr; |
| // Call pending frame callbacks with a null frame time to indicate that they |
| // have been cancelled. |
| @@ -246,11 +232,6 @@ Surface* Surface::AsSurface(const aura::Window* window) { |
| return window->GetProperty(kSurfaceKey); |
| } |
| -// static |
| -void Surface::SetUseSurfaceLayer(bool use_surface_layer) { |
| - use_surface_layer_ = use_surface_layer; |
| -} |
| - |
| void Surface::Attach(Buffer* buffer) { |
| TRACE_EVENT1("exo", "Surface::Attach", "buffer", |
| buffer ? buffer->GetSize().ToString() : "null"); |
| @@ -452,11 +433,7 @@ void Surface::CommitSurfaceHierarchy() { |
| state_ = pending_state_; |
| pending_state_.only_visible_on_secure_output = false; |
| - if (factory_owner_) { |
| - CommitSurfaceContents(); |
| - } else { |
| - CommitTextureContents(); |
| - } |
| + CommitSurfaceContents(); |
|
reveman
2016/06/15 19:05:08
nit: can we just move the implementation of this f
reveman
2016/06/15 19:05:08
nit: can we just move the impl of CommitSurfaceCon
|
| // Synchronize window hierarchy. This will position and update the stacking |
| // order of all sub-surfaces after committing all pending state of sub-surface |
| @@ -558,23 +535,6 @@ std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const { |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// aura::WindowObserver overrides: |
| - |
| -void Surface::OnWindowAddedToRootWindow(aura::Window* window) { |
| - DCHECK(!compositor_); |
| - DCHECK(!factory_owner_); |
| - compositor_ = window_->layer()->GetCompositor(); |
| - compositor_->AddObserver(this); |
| -} |
| - |
| -void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, |
| - aura::Window* new_root) { |
| - DCHECK(compositor_); |
| - compositor_->RemoveObserver(this); |
| - compositor_ = nullptr; |
| -} |
| - |
| -//////////////////////////////////////////////////////////////////////////////// |
| // ui::LayerOwnerDelegate overrides: |
| void Surface::OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) { |
| @@ -582,59 +542,7 @@ void Surface::OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) { |
| return; |
| // TODO(reveman): Give the client a chance to provide new contents. |
| - if (factory_owner_) { |
| - SetSurfaceLayerContents(new_layer); |
| - } else { |
| - SetTextureLayerContents(new_layer); |
| - } |
| -} |
| - |
| -//////////////////////////////////////////////////////////////////////////////// |
| -// ui::CompositorObserver overrides: |
| - |
| -void Surface::OnCompositingDidCommit(ui::Compositor* compositor) { |
| - DCHECK(!factory_owner_); |
| - // Move frame callbacks to the end of |active_frame_callbacks_|. |
| - active_frame_callbacks_.splice(active_frame_callbacks_.end(), |
| - frame_callbacks_); |
| -} |
| - |
| -void Surface::OnCompositingStarted(ui::Compositor* compositor, |
| - base::TimeTicks start_time) { |
| - last_compositing_start_time_ = start_time; |
| -} |
| - |
| -void Surface::OnCompositingEnded(ui::Compositor* compositor) { |
| - // Run all frame callbacks associated with the compositor's active tree. |
| - while (!active_frame_callbacks_.empty()) { |
| - active_frame_callbacks_.front().Run(last_compositing_start_time_); |
| - active_frame_callbacks_.pop_front(); |
| - } |
| - |
| - // Nothing more to do in here unless this has been set. |
| - if (!update_contents_after_successful_compositing_) |
| - return; |
| - |
| - update_contents_after_successful_compositing_ = false; |
| - |
| - // Early out if no contents is currently assigned to the surface. |
| - if (!current_buffer_) |
| - return; |
| - |
| - // Update contents by producing a new texture mailbox for the current buffer. |
|
reveman
2016/06/15 19:05:09
nit: this could was here to handle lost context si
|
| - SetTextureLayerContents(window_->layer()); |
| -} |
| - |
| -void Surface::OnCompositingAborted(ui::Compositor* compositor) { |
| - // The contents of this surface might be lost if compositing aborted because |
| - // of a lost graphics context. We recover from this by updating the contents |
| - // of the surface next time the compositor successfully ends compositing. |
| - update_contents_after_successful_compositing_ = true; |
| -} |
| - |
| -void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) { |
| - compositor->RemoveObserver(this); |
| - compositor_ = nullptr; |
| + SetSurfaceLayerContents(new_layer); |
| } |
| void Surface::WillDraw(cc::SurfaceId id) { |
| @@ -679,83 +587,6 @@ void Surface::SetSurfaceHierarchyNeedsCommitToNewSurfaces() { |
| } |
| } |
| -void Surface::CommitTextureContents() { |
| - // We update contents if Attach() has been called since last commit. |
| - if (has_pending_contents_) { |
| - has_pending_contents_ = false; |
| - |
| - current_buffer_ = pending_buffer_; |
| - pending_buffer_.reset(); |
| - |
| - cc::TextureMailbox texture_mailbox; |
| - std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; |
| - if (current_buffer_) { |
| - texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox( |
| - &texture_mailbox, state_.only_visible_on_secure_output, |
| - true /* client_usage */); |
| - } |
| - |
| - // Update layer with the new contents. |
| - if (texture_mailbox_release_callback) { |
| - texture_size_in_dip_ = gfx::ScaleToFlooredSize( |
| - texture_mailbox.size_in_pixels(), 1.0f / state_.buffer_scale); |
| - window_->layer()->SetTextureMailbox( |
| - texture_mailbox, std::move(texture_mailbox_release_callback), |
| - texture_size_in_dip_); |
| - window_->layer()->SetTextureFlipped(false); |
| - } else { |
| - // Show solid color content if no buffer is attached or we failed |
| - // to produce a texture mailbox for the currently attached buffer. |
| - window_->layer()->SetShowSolidColorContent(); |
| - window_->layer()->SetColor(SK_ColorBLACK); |
| - } |
| - |
| - // Schedule redraw of the damage region. |
| - for (SkRegion::Iterator it(pending_damage_); !it.done(); it.next()) |
| - window_->layer()->SchedulePaint(gfx::SkIRectToRect(it.rect())); |
| - |
| - // Reset damage. |
| - pending_damage_.setEmpty(); |
| - } |
| - |
| - if (window_->layer()->has_external_content()) { |
| - // Determine the new surface size. |
| - // - Texture size in DIP defines the size if nothing else is set. |
| - // - If a viewport is set then that defines the size, otherwise |
| - // the crop rectangle defines the size if set. |
| - gfx::Size contents_size = texture_size_in_dip_; |
| - if (!state_.viewport.IsEmpty()) { |
| - contents_size = state_.viewport; |
| - } else if (!state_.crop.IsEmpty()) { |
| - DLOG_IF(WARNING, !gfx::IsExpressibleAsInt(state_.crop.width()) || |
| - !gfx::IsExpressibleAsInt(state_.crop.height())) |
| - << "Crop rectangle size (" << state_.crop.size().ToString() |
| - << ") most be expressible using integers when viewport is not set"; |
| - contents_size = gfx::ToCeiledSize(state_.crop.size()); |
| - } |
| - window_->layer()->SetTextureCrop(state_.crop); |
| - window_->layer()->SetTextureScale( |
| - static_cast<float>(texture_size_in_dip_.width()) / |
| - contents_size.width(), |
| - static_cast<float>(texture_size_in_dip_.height()) / |
| - contents_size.height()); |
| - window_->layer()->SetTextureAlpha(state_.alpha); |
| - window_->layer()->SetBounds( |
| - gfx::Rect(window_->layer()->bounds().origin(), contents_size)); |
| - } |
| - |
| - // Move pending frame callbacks to the end of |frame_callbacks_|. |
| - frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); |
| - |
| - // Update alpha compositing properties. |
| - // TODO(reveman): Use a more reliable way to force blending off than setting |
| - // fills-bounds-opaquely. |
| - window_->layer()->SetFillsBoundsOpaquely( |
| - state_.blend_mode == SkXfermode::kSrc_Mode || |
| - state_.opaque_region.contains( |
| - gfx::RectToSkIRect(gfx::Rect(window_->layer()->size())))); |
| -} |
| - |
| void Surface::CommitSurfaceContents() { |
| // We update contents if Attach() has been called since last commit. |
| if (has_pending_contents_) { |
| @@ -912,29 +743,6 @@ void Surface::CommitSurfaceContents() { |
| pending_frame_callbacks_); |
| } |
| -void Surface::SetTextureLayerContents(ui::Layer* layer) { |
| - DCHECK(current_buffer_); |
| - |
| - cc::TextureMailbox texture_mailbox; |
| - std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback = |
| - current_buffer_->ProduceTextureMailbox( |
| - &texture_mailbox, state_.only_visible_on_secure_output, |
| - false /* client_usage */); |
| - if (!texture_mailbox_release_callback) |
| - return; |
| - |
| - layer->SetTextureMailbox(texture_mailbox, |
| - std::move(texture_mailbox_release_callback), |
| - texture_size_in_dip_); |
| - layer->SetTextureFlipped(false); |
| - layer->SetTextureCrop(state_.crop); |
| - layer->SetTextureScale(static_cast<float>(texture_size_in_dip_.width()) / |
| - layer->bounds().width(), |
| - static_cast<float>(texture_size_in_dip_.height()) / |
| - layer->bounds().height()); |
| - layer->SetTextureAlpha(state_.alpha); |
| -} |
| - |
| void Surface::SetSurfaceLayerContents(ui::Layer* layer) { |
| if (surface_id_.is_null()) |
| return; |
| @@ -949,6 +757,4 @@ void Surface::SetSurfaceLayerContents(ui::Layer* layer) { |
| layer_size, contents_surface_to_layer_scale, layer_size); |
| } |
| -bool Surface::use_surface_layer_ = false; |
| - |
| } // namespace exo |