| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 129 |
| 130 //////////////////////////////////////////////////////////////////////////////// | 130 //////////////////////////////////////////////////////////////////////////////// |
| 131 // Surface, public: | 131 // Surface, public: |
| 132 | 132 |
| 133 Surface::Surface() | 133 Surface::Surface() |
| 134 : aura::Window(new CustomWindowDelegate(this)), | 134 : aura::Window(new CustomWindowDelegate(this)), |
| 135 has_pending_contents_(false), | 135 has_pending_contents_(false), |
| 136 pending_input_region_(SkIRect::MakeLargest()), | 136 pending_input_region_(SkIRect::MakeLargest()), |
| 137 pending_buffer_scale_(1.0f), | 137 pending_buffer_scale_(1.0f), |
| 138 pending_only_visible_on_secure_output_(false), | 138 pending_only_visible_on_secure_output_(false), |
| 139 pending_blend_mode_(SkXfermode::kSrcOver_Mode), |
| 140 pending_alpha_(1.0f), |
| 139 input_region_(SkIRect::MakeLargest()), | 141 input_region_(SkIRect::MakeLargest()), |
| 140 needs_commit_surface_hierarchy_(false), | 142 needs_commit_surface_hierarchy_(false), |
| 141 update_contents_after_successful_compositing_(false), | 143 update_contents_after_successful_compositing_(false), |
| 142 compositor_(nullptr), | 144 compositor_(nullptr), |
| 143 delegate_(nullptr) { | 145 delegate_(nullptr) { |
| 144 SetType(ui::wm::WINDOW_TYPE_CONTROL); | 146 SetType(ui::wm::WINDOW_TYPE_CONTROL); |
| 145 SetName("ExoSurface"); | 147 SetName("ExoSurface"); |
| 146 SetProperty(kSurfaceKey, this); | 148 SetProperty(kSurfaceKey, this); |
| 147 Init(ui::LAYER_SOLID_COLOR); | 149 Init(ui::LAYER_SOLID_COLOR); |
| 148 SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); | 150 SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 pending_viewport_ = viewport; | 309 pending_viewport_ = viewport; |
| 308 } | 310 } |
| 309 | 311 |
| 310 void Surface::SetOnlyVisibleOnSecureOutput(bool only_visible_on_secure_output) { | 312 void Surface::SetOnlyVisibleOnSecureOutput(bool only_visible_on_secure_output) { |
| 311 TRACE_EVENT1("exo", "Surface::SetOnlyVisibleOnSecureOutput", | 313 TRACE_EVENT1("exo", "Surface::SetOnlyVisibleOnSecureOutput", |
| 312 "only_visible_on_secure_output", only_visible_on_secure_output); | 314 "only_visible_on_secure_output", only_visible_on_secure_output); |
| 313 | 315 |
| 314 pending_only_visible_on_secure_output_ = only_visible_on_secure_output; | 316 pending_only_visible_on_secure_output_ = only_visible_on_secure_output; |
| 315 } | 317 } |
| 316 | 318 |
| 319 void Surface::SetBlendMode(SkXfermode::Mode blend_mode) { |
| 320 TRACE_EVENT1("exo", "Surface::SetBlendMode", "blend_mode", blend_mode); |
| 321 |
| 322 pending_blend_mode_ = blend_mode; |
| 323 } |
| 324 |
| 325 void Surface::SetAlpha(float alpha) { |
| 326 TRACE_EVENT1("exo", "Surface::SetAlpha", "alpha", alpha); |
| 327 |
| 328 pending_alpha_ = alpha; |
| 329 } |
| 330 |
| 317 void Surface::Commit() { | 331 void Surface::Commit() { |
| 318 TRACE_EVENT0("exo", "Surface::Commit"); | 332 TRACE_EVENT0("exo", "Surface::Commit"); |
| 319 | 333 |
| 320 needs_commit_surface_hierarchy_ = true; | 334 needs_commit_surface_hierarchy_ = true; |
| 321 | 335 |
| 322 if (delegate_) | 336 if (delegate_) |
| 323 delegate_->OnSurfaceCommit(); | 337 delegate_->OnSurfaceCommit(); |
| 324 else | 338 else |
| 325 CommitSurfaceHierarchy(); | 339 CommitSurfaceHierarchy(); |
| 326 } | 340 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 356 gfx::Size contents_size = | 370 gfx::Size contents_size = |
| 357 pending_viewport_.IsEmpty() | 371 pending_viewport_.IsEmpty() |
| 358 ? gfx::ScaleToFlooredSize(texture_mailbox.size_in_pixels(), | 372 ? gfx::ScaleToFlooredSize(texture_mailbox.size_in_pixels(), |
| 359 1.0f / pending_buffer_scale_) | 373 1.0f / pending_buffer_scale_) |
| 360 : pending_viewport_; | 374 : pending_viewport_; |
| 361 layer()->SetTextureMailbox(texture_mailbox, | 375 layer()->SetTextureMailbox(texture_mailbox, |
| 362 std::move(texture_mailbox_release_callback), | 376 std::move(texture_mailbox_release_callback), |
| 363 contents_size); | 377 contents_size); |
| 364 layer()->SetTextureFlipped(false); | 378 layer()->SetTextureFlipped(false); |
| 365 layer()->SetBounds(gfx::Rect(layer()->bounds().origin(), contents_size)); | 379 layer()->SetBounds(gfx::Rect(layer()->bounds().origin(), contents_size)); |
| 366 layer()->SetFillsBoundsOpaquely(pending_opaque_region_.contains( | |
| 367 gfx::RectToSkIRect(gfx::Rect(contents_size)))); | |
| 368 } else { | 380 } else { |
| 369 // Show solid color content if no buffer is attached or we failed | 381 // Show solid color content if no buffer is attached or we failed |
| 370 // to produce a texture mailbox for the currently attached buffer. | 382 // to produce a texture mailbox for the currently attached buffer. |
| 371 layer()->SetShowSolidColorContent(); | 383 layer()->SetShowSolidColorContent(); |
| 372 layer()->SetColor(SK_ColorBLACK); | 384 layer()->SetColor(SK_ColorBLACK); |
| 373 } | 385 } |
| 374 | 386 |
| 375 // Schedule redraw of the damage region. | 387 // Schedule redraw of the damage region. |
| 376 for (SkRegion::Iterator it(pending_damage_); !it.done(); it.next()) | 388 for (SkRegion::Iterator it(pending_damage_); !it.done(); it.next()) |
| 377 layer()->SchedulePaint(gfx::SkIRectToRect(it.rect())); | 389 layer()->SchedulePaint(gfx::SkIRectToRect(it.rect())); |
| 378 | 390 |
| 379 // Reset damage. | 391 // Reset damage. |
| 380 pending_damage_.setEmpty(); | 392 pending_damage_.setEmpty(); |
| 381 } | 393 } |
| 382 | 394 |
| 383 // Update current input region. | 395 // Update current input region. |
| 384 input_region_ = pending_input_region_; | 396 input_region_ = pending_input_region_; |
| 385 | 397 |
| 386 // Move pending frame callbacks to the end of |frame_callbacks_|. | 398 // Move pending frame callbacks to the end of |frame_callbacks_|. |
| 387 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); | 399 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); |
| 388 | 400 |
| 401 // Update alpha compositing properties. |
| 402 // TODO(reveman): Use a more reliable way to force blending off than setting |
| 403 // fills-bounds-opaquely. |
| 404 layer()->SetFillsBoundsOpaquely( |
| 405 pending_blend_mode_ == SkXfermode::kSrc_Mode || |
| 406 pending_opaque_region_.contains( |
| 407 gfx::RectToSkIRect(gfx::Rect(layer()->size())))); |
| 408 if (layer()->has_external_content()) |
| 409 layer()->SetTextureAlpha(pending_alpha_); |
| 410 |
| 389 // Synchronize window hierarchy. This will position and update the stacking | 411 // Synchronize window hierarchy. This will position and update the stacking |
| 390 // order of all sub-surfaces after committing all pending state of sub-surface | 412 // order of all sub-surfaces after committing all pending state of sub-surface |
| 391 // descendants. | 413 // descendants. |
| 392 aura::Window* stacking_target = nullptr; | 414 aura::Window* stacking_target = nullptr; |
| 393 for (auto& sub_surface_entry : pending_sub_surfaces_) { | 415 for (auto& sub_surface_entry : pending_sub_surfaces_) { |
| 394 Surface* sub_surface = sub_surface_entry.first; | 416 Surface* sub_surface = sub_surface_entry.first; |
| 395 | 417 |
| 396 // Synchronsouly commit all pending state of the sub-surface and its | 418 // Synchronsouly commit all pending state of the sub-surface and its |
| 397 // decendents. | 419 // decendents. |
| 398 if (sub_surface->needs_commit_surface_hierarchy()) | 420 if (sub_surface->needs_commit_surface_hierarchy()) |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 // of the surface next time the compositor successfully ends compositing. | 565 // of the surface next time the compositor successfully ends compositing. |
| 544 update_contents_after_successful_compositing_ = true; | 566 update_contents_after_successful_compositing_ = true; |
| 545 } | 567 } |
| 546 | 568 |
| 547 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) { | 569 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) { |
| 548 compositor->RemoveObserver(this); | 570 compositor->RemoveObserver(this); |
| 549 compositor_ = nullptr; | 571 compositor_ = nullptr; |
| 550 } | 572 } |
| 551 | 573 |
| 552 } // namespace exo | 574 } // namespace exo |
| OLD | NEW |