| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } // namespace | 117 } // namespace |
| 118 | 118 |
| 119 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
| 120 // Surface, public: | 120 // Surface, public: |
| 121 | 121 |
| 122 Surface::Surface() | 122 Surface::Surface() |
| 123 : aura::Window(new CustomWindowDelegate(this)), | 123 : aura::Window(new CustomWindowDelegate(this)), |
| 124 has_pending_contents_(false), | 124 has_pending_contents_(false), |
| 125 pending_input_region_(SkIRect::MakeLargest()), | 125 pending_input_region_(SkIRect::MakeLargest()), |
| 126 pending_buffer_scale_(1.0f), | 126 pending_buffer_scale_(1.0f), |
| 127 pending_only_visible_on_secure_output_(false), |
| 127 input_region_(SkIRect::MakeLargest()), | 128 input_region_(SkIRect::MakeLargest()), |
| 128 needs_commit_surface_hierarchy_(false), | 129 needs_commit_surface_hierarchy_(false), |
| 129 update_contents_after_successful_compositing_(false), | 130 update_contents_after_successful_compositing_(false), |
| 130 compositor_(nullptr), | 131 compositor_(nullptr), |
| 131 delegate_(nullptr) { | 132 delegate_(nullptr) { |
| 132 SetType(ui::wm::WINDOW_TYPE_CONTROL); | 133 SetType(ui::wm::WINDOW_TYPE_CONTROL); |
| 133 SetName("ExoSurface"); | 134 SetName("ExoSurface"); |
| 134 SetProperty(kSurfaceKey, this); | 135 SetProperty(kSurfaceKey, this); |
| 135 Init(ui::LAYER_SOLID_COLOR); | 136 Init(ui::LAYER_SOLID_COLOR); |
| 136 SetEventTargeter(make_scoped_ptr(new CustomWindowTargeter)); | 137 SetEventTargeter(make_scoped_ptr(new CustomWindowTargeter)); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 sibling_it, pending_sub_surfaces_, | 289 sibling_it, pending_sub_surfaces_, |
| 289 FindListEntry(pending_sub_surfaces_, sub_surface)); | 290 FindListEntry(pending_sub_surfaces_, sub_surface)); |
| 290 } | 291 } |
| 291 | 292 |
| 292 void Surface::SetViewport(const gfx::Size& viewport) { | 293 void Surface::SetViewport(const gfx::Size& viewport) { |
| 293 TRACE_EVENT1("exo", "Surface::SetViewport", "viewport", viewport.ToString()); | 294 TRACE_EVENT1("exo", "Surface::SetViewport", "viewport", viewport.ToString()); |
| 294 | 295 |
| 295 pending_viewport_ = viewport; | 296 pending_viewport_ = viewport; |
| 296 } | 297 } |
| 297 | 298 |
| 299 void Surface::SetOnlyVisibleOnSecureOutput(bool only_visible_on_secure_output) { |
| 300 TRACE_EVENT1("exo", "Surface::SetOnlyVisibleOnSecureOutput", |
| 301 "only_visible_on_secure_output", only_visible_on_secure_output); |
| 302 |
| 303 pending_only_visible_on_secure_output_ = only_visible_on_secure_output; |
| 304 } |
| 305 |
| 298 void Surface::Commit() { | 306 void Surface::Commit() { |
| 299 TRACE_EVENT0("exo", "Surface::Commit"); | 307 TRACE_EVENT0("exo", "Surface::Commit"); |
| 300 | 308 |
| 301 needs_commit_surface_hierarchy_ = true; | 309 needs_commit_surface_hierarchy_ = true; |
| 302 | 310 |
| 303 if (delegate_) | 311 if (delegate_) |
| 304 delegate_->OnSurfaceCommit(); | 312 delegate_->OnSurfaceCommit(); |
| 305 else | 313 else |
| 306 CommitSurfaceHierarchy(); | 314 CommitSurfaceHierarchy(); |
| 307 } | 315 } |
| 308 | 316 |
| 309 void Surface::CommitSurfaceHierarchy() { | 317 void Surface::CommitSurfaceHierarchy() { |
| 310 DCHECK(needs_commit_surface_hierarchy_); | 318 DCHECK(needs_commit_surface_hierarchy_); |
| 311 needs_commit_surface_hierarchy_ = false; | 319 needs_commit_surface_hierarchy_ = false; |
| 312 | 320 |
| 313 // We update contents if Attach() has been called since last commit. | 321 // We update contents if Attach() has been called since last commit. |
| 314 if (has_pending_contents_) { | 322 if (has_pending_contents_) { |
| 315 has_pending_contents_ = false; | 323 has_pending_contents_ = false; |
| 316 | 324 |
| 317 current_buffer_ = pending_buffer_; | 325 current_buffer_ = pending_buffer_; |
| 318 pending_buffer_.reset(); | 326 pending_buffer_.reset(); |
| 319 | 327 |
| 328 // TODO(dcastagna): Make secure_output_only a layer property instead of a |
| 329 // texture mailbox flag so this can be changed without have to provide |
| 330 // new contents. |
| 331 bool secure_output_only = pending_only_visible_on_secure_output_; |
| 332 pending_only_visible_on_secure_output_ = false; |
| 333 |
| 320 cc::TextureMailbox texture_mailbox; | 334 cc::TextureMailbox texture_mailbox; |
| 321 scoped_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; | 335 scoped_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; |
| 322 if (current_buffer_) { | 336 if (current_buffer_) { |
| 323 texture_mailbox_release_callback = | 337 texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox( |
| 324 current_buffer_->ProduceTextureMailbox(&texture_mailbox, false); | 338 &texture_mailbox, secure_output_only, false); |
| 325 } | 339 } |
| 326 | 340 |
| 327 if (texture_mailbox_release_callback) { | 341 if (texture_mailbox_release_callback) { |
| 328 // Update layer with the new contents. If a viewport has been set then | 342 // Update layer with the new contents. If a viewport has been set then |
| 329 // use that to determine the size of the layer and the surface, otherwise | 343 // use that to determine the size of the layer and the surface, otherwise |
| 330 // buffer scale and buffer size determines the size. | 344 // buffer scale and buffer size determines the size. |
| 331 gfx::Size contents_size = | 345 gfx::Size contents_size = |
| 332 pending_viewport_.IsEmpty() | 346 pending_viewport_.IsEmpty() |
| 333 ? gfx::ScaleToFlooredSize(texture_mailbox.size_in_pixels(), | 347 ? gfx::ScaleToFlooredSize(texture_mailbox.size_in_pixels(), |
| 334 1.0f / pending_buffer_scale_) | 348 1.0f / pending_buffer_scale_) |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 // Nothing more to do in here unless this has been set. | 504 // Nothing more to do in here unless this has been set. |
| 491 if (!update_contents_after_successful_compositing_) | 505 if (!update_contents_after_successful_compositing_) |
| 492 return; | 506 return; |
| 493 | 507 |
| 494 update_contents_after_successful_compositing_ = false; | 508 update_contents_after_successful_compositing_ = false; |
| 495 | 509 |
| 496 // Early out if no contents is currently assigned to the surface. | 510 // Early out if no contents is currently assigned to the surface. |
| 497 if (!current_buffer_) | 511 if (!current_buffer_) |
| 498 return; | 512 return; |
| 499 | 513 |
| 514 // TODO(dcastagna): Make secure_output_only a layer property instead of a |
| 515 // texture mailbox flag. |
| 516 bool secure_output_only = false; |
| 517 |
| 500 // Update contents by producing a new texture mailbox for the current buffer. | 518 // Update contents by producing a new texture mailbox for the current buffer. |
| 501 cc::TextureMailbox texture_mailbox; | 519 cc::TextureMailbox texture_mailbox; |
| 502 scoped_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback = | 520 scoped_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback = |
| 503 current_buffer_->ProduceTextureMailbox(&texture_mailbox, true); | 521 current_buffer_->ProduceTextureMailbox(&texture_mailbox, |
| 522 secure_output_only, true); |
| 504 if (texture_mailbox_release_callback) { | 523 if (texture_mailbox_release_callback) { |
| 505 layer()->SetTextureMailbox(texture_mailbox, | 524 layer()->SetTextureMailbox(texture_mailbox, |
| 506 std::move(texture_mailbox_release_callback), | 525 std::move(texture_mailbox_release_callback), |
| 507 layer()->bounds().size()); | 526 layer()->bounds().size()); |
| 508 layer()->SetTextureFlipped(false); | 527 layer()->SetTextureFlipped(false); |
| 509 layer()->SchedulePaint(gfx::Rect(texture_mailbox.size_in_pixels())); | 528 layer()->SchedulePaint(gfx::Rect(texture_mailbox.size_in_pixels())); |
| 510 } | 529 } |
| 511 } | 530 } |
| 512 | 531 |
| 513 void Surface::OnCompositingAborted(ui::Compositor* compositor) { | 532 void Surface::OnCompositingAborted(ui::Compositor* compositor) { |
| 514 // The contents of this surface might be lost if compositing aborted because | 533 // The contents of this surface might be lost if compositing aborted because |
| 515 // of a lost graphics context. We recover from this by updating the contents | 534 // of a lost graphics context. We recover from this by updating the contents |
| 516 // of the surface next time the compositor successfully ends compositing. | 535 // of the surface next time the compositor successfully ends compositing. |
| 517 update_contents_after_successful_compositing_ = true; | 536 update_contents_after_successful_compositing_ = true; |
| 518 } | 537 } |
| 519 | 538 |
| 520 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) { | 539 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) { |
| 521 compositor->RemoveObserver(this); | 540 compositor->RemoveObserver(this); |
| 522 compositor_ = nullptr; | 541 compositor_ = nullptr; |
| 523 } | 542 } |
| 524 | 543 |
| 525 } // namespace exo | 544 } // namespace exo |
| OLD | NEW |