Chromium Code Reviews| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 | 182 |
| 183 void SurfaceFactoryOwner::SetBeginFrameSource( | 183 void SurfaceFactoryOwner::SetBeginFrameSource( |
| 184 cc::BeginFrameSource* begin_frame_source) {} | 184 cc::BeginFrameSource* begin_frame_source) {} |
| 185 | 185 |
| 186 //////////////////////////////////////////////////////////////////////////////// | 186 //////////////////////////////////////////////////////////////////////////////// |
| 187 // Surface, public: | 187 // Surface, public: |
| 188 | 188 |
| 189 Surface::Surface() | 189 Surface::Surface() |
| 190 : window_(new aura::Window(new CustomWindowDelegate(this))), | 190 : window_(new aura::Window(new CustomWindowDelegate(this))), |
| 191 has_pending_contents_(false), | 191 has_pending_contents_(false), |
| 192 pending_input_region_(SkIRect::MakeLargest()), | |
| 193 pending_buffer_scale_(1.0f), | |
| 194 pending_only_visible_on_secure_output_(false), | |
| 195 only_visible_on_secure_output_(false), | |
| 196 pending_blend_mode_(SkXfermode::kSrcOver_Mode), | |
| 197 pending_alpha_(1.0f), | |
| 198 alpha_(1.0f), | |
| 199 input_region_(SkIRect::MakeLargest()), | |
| 200 needs_commit_surface_hierarchy_(false), | 192 needs_commit_surface_hierarchy_(false), |
| 201 update_contents_after_successful_compositing_(false), | 193 update_contents_after_successful_compositing_(false), |
| 202 compositor_(nullptr), | 194 compositor_(nullptr), |
| 203 delegate_(nullptr) { | 195 delegate_(nullptr) { |
| 204 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | 196 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
| 205 window_->SetName("ExoSurface"); | 197 window_->SetName("ExoSurface"); |
| 206 window_->SetProperty(kSurfaceKey, this); | 198 window_->SetProperty(kSurfaceKey, this); |
| 207 window_->Init(ui::LAYER_SOLID_COLOR); | 199 window_->Init(ui::LAYER_SOLID_COLOR); |
| 208 window_->set_layer_owner_delegate(this); | 200 window_->set_layer_owner_delegate(this); |
| 209 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); | 201 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 void Surface::RequestFrameCallback(const FrameCallback& callback) { | 268 void Surface::RequestFrameCallback(const FrameCallback& callback) { |
| 277 TRACE_EVENT0("exo", "Surface::RequestFrameCallback"); | 269 TRACE_EVENT0("exo", "Surface::RequestFrameCallback"); |
| 278 | 270 |
| 279 pending_frame_callbacks_.push_back(callback); | 271 pending_frame_callbacks_.push_back(callback); |
| 280 } | 272 } |
| 281 | 273 |
| 282 void Surface::SetOpaqueRegion(const SkRegion& region) { | 274 void Surface::SetOpaqueRegion(const SkRegion& region) { |
| 283 TRACE_EVENT1("exo", "Surface::SetOpaqueRegion", "region", | 275 TRACE_EVENT1("exo", "Surface::SetOpaqueRegion", "region", |
| 284 gfx::SkIRectToRect(region.getBounds()).ToString()); | 276 gfx::SkIRectToRect(region.getBounds()).ToString()); |
| 285 | 277 |
| 286 pending_opaque_region_ = region; | 278 pending_state_.opaque_region = region; |
| 287 } | 279 } |
| 288 | 280 |
| 289 void Surface::SetInputRegion(const SkRegion& region) { | 281 void Surface::SetInputRegion(const SkRegion& region) { |
| 290 TRACE_EVENT1("exo", "Surface::SetInputRegion", "region", | 282 TRACE_EVENT1("exo", "Surface::SetInputRegion", "region", |
| 291 gfx::SkIRectToRect(region.getBounds()).ToString()); | 283 gfx::SkIRectToRect(region.getBounds()).ToString()); |
| 292 | 284 |
| 293 pending_input_region_ = region; | 285 pending_state_.input_region = region; |
| 294 } | 286 } |
| 295 | 287 |
| 296 void Surface::SetBufferScale(float scale) { | 288 void Surface::SetBufferScale(float scale) { |
| 297 TRACE_EVENT1("exo", "Surface::SetBufferScale", "scale", scale); | 289 TRACE_EVENT1("exo", "Surface::SetBufferScale", "scale", scale); |
| 298 | 290 |
| 299 pending_buffer_scale_ = scale; | 291 pending_state_.buffer_scale = scale; |
| 300 } | 292 } |
| 301 | 293 |
| 302 void Surface::AddSubSurface(Surface* sub_surface) { | 294 void Surface::AddSubSurface(Surface* sub_surface) { |
| 303 TRACE_EVENT1("exo", "Surface::AddSubSurface", "sub_surface", | 295 TRACE_EVENT1("exo", "Surface::AddSubSurface", "sub_surface", |
| 304 sub_surface->AsTracedValue()); | 296 sub_surface->AsTracedValue()); |
| 305 | 297 |
| 306 DCHECK(!sub_surface->window()->parent()); | 298 DCHECK(!sub_surface->window()->parent()); |
| 307 DCHECK(!sub_surface->window()->IsVisible()); | 299 DCHECK(!sub_surface->window()->IsVisible()); |
| 308 window_->AddChild(sub_surface->window()); | 300 window_->AddChild(sub_surface->window()); |
| 309 | 301 |
| 310 DCHECK(!ListContainsEntry(pending_sub_surfaces_, sub_surface)); | 302 DCHECK(!ListContainsEntry(pending_sub_surfaces_, sub_surface)); |
| 311 pending_sub_surfaces_.push_back(std::make_pair(sub_surface, gfx::Point())); | 303 pending_sub_surfaces_.push_back(std::make_pair(sub_surface, gfx::Point())); |
| 304 modified_layer_info_ = true; | |
| 312 } | 305 } |
| 313 | 306 |
| 314 void Surface::RemoveSubSurface(Surface* sub_surface) { | 307 void Surface::RemoveSubSurface(Surface* sub_surface) { |
| 315 TRACE_EVENT1("exo", "Surface::AddSubSurface", "sub_surface", | 308 TRACE_EVENT1("exo", "Surface::AddSubSurface", "sub_surface", |
| 316 sub_surface->AsTracedValue()); | 309 sub_surface->AsTracedValue()); |
| 317 | 310 |
| 318 window_->RemoveChild(sub_surface->window()); | 311 window_->RemoveChild(sub_surface->window()); |
| 319 if (sub_surface->window()->IsVisible()) | 312 if (sub_surface->window()->IsVisible()) |
| 320 sub_surface->window()->Hide(); | 313 sub_surface->window()->Hide(); |
| 321 | 314 |
| 322 DCHECK(ListContainsEntry(pending_sub_surfaces_, sub_surface)); | 315 DCHECK(ListContainsEntry(pending_sub_surfaces_, sub_surface)); |
| 323 pending_sub_surfaces_.erase( | 316 pending_sub_surfaces_.erase( |
| 324 FindListEntry(pending_sub_surfaces_, sub_surface)); | 317 FindListEntry(pending_sub_surfaces_, sub_surface)); |
| 318 modified_layer_info_ = true; | |
| 325 } | 319 } |
| 326 | 320 |
| 327 void Surface::SetSubSurfacePosition(Surface* sub_surface, | 321 void Surface::SetSubSurfacePosition(Surface* sub_surface, |
| 328 const gfx::Point& position) { | 322 const gfx::Point& position) { |
| 329 TRACE_EVENT2("exo", "Surface::SetSubSurfacePosition", "sub_surface", | 323 TRACE_EVENT2("exo", "Surface::SetSubSurfacePosition", "sub_surface", |
| 330 sub_surface->AsTracedValue(), "position", position.ToString()); | 324 sub_surface->AsTracedValue(), "position", position.ToString()); |
| 331 | 325 |
| 332 auto it = FindListEntry(pending_sub_surfaces_, sub_surface); | 326 auto it = FindListEntry(pending_sub_surfaces_, sub_surface); |
| 333 DCHECK(it != pending_sub_surfaces_.end()); | 327 DCHECK(it != pending_sub_surfaces_.end()); |
| 328 if (it->second == position) | |
| 329 return; | |
| 334 it->second = position; | 330 it->second = position; |
| 331 modified_layer_info_ = true; | |
| 335 } | 332 } |
| 336 | 333 |
| 337 void Surface::PlaceSubSurfaceAbove(Surface* sub_surface, Surface* reference) { | 334 void Surface::PlaceSubSurfaceAbove(Surface* sub_surface, Surface* reference) { |
| 338 TRACE_EVENT2("exo", "Surface::PlaceSubSurfaceAbove", "sub_surface", | 335 TRACE_EVENT2("exo", "Surface::PlaceSubSurfaceAbove", "sub_surface", |
| 339 sub_surface->AsTracedValue(), "reference", | 336 sub_surface->AsTracedValue(), "reference", |
| 340 reference->AsTracedValue()); | 337 reference->AsTracedValue()); |
| 341 | 338 |
| 342 if (sub_surface == reference) { | 339 if (sub_surface == reference) { |
| 343 DLOG(WARNING) << "Client tried to place sub-surface above itself"; | 340 DLOG(WARNING) << "Client tried to place sub-surface above itself"; |
| 344 return; | 341 return; |
| 345 } | 342 } |
| 346 | 343 |
| 347 auto position_it = pending_sub_surfaces_.begin(); | 344 auto position_it = pending_sub_surfaces_.begin(); |
| 348 if (reference != this) { | 345 if (reference != this) { |
| 349 position_it = FindListEntry(pending_sub_surfaces_, reference); | 346 position_it = FindListEntry(pending_sub_surfaces_, reference); |
| 350 if (position_it == pending_sub_surfaces_.end()) { | 347 if (position_it == pending_sub_surfaces_.end()) { |
| 351 DLOG(WARNING) << "Client tried to place sub-surface above a reference " | 348 DLOG(WARNING) << "Client tried to place sub-surface above a reference " |
| 352 "surface that is neither a parent nor a sibling"; | 349 "surface that is neither a parent nor a sibling"; |
| 353 return; | 350 return; |
| 354 } | 351 } |
| 355 | 352 |
| 356 // Advance iterator to have |position_it| point to the sibling surface | 353 // Advance iterator to have |position_it| point to the sibling surface |
| 357 // above |reference|. | 354 // above |reference|. |
| 358 ++position_it; | 355 ++position_it; |
| 359 } | 356 } |
| 360 | 357 |
| 361 DCHECK(ListContainsEntry(pending_sub_surfaces_, sub_surface)); | 358 DCHECK(ListContainsEntry(pending_sub_surfaces_, sub_surface)); |
| 362 pending_sub_surfaces_.splice( | 359 auto it = FindListEntry(pending_sub_surfaces_, sub_surface); |
| 363 position_it, pending_sub_surfaces_, | 360 if (it == position_it) |
| 364 FindListEntry(pending_sub_surfaces_, sub_surface)); | 361 return; |
| 362 pending_sub_surfaces_.splice(position_it, pending_sub_surfaces_, it); | |
| 363 modified_layer_info_ = true; | |
| 365 } | 364 } |
| 366 | 365 |
| 367 void Surface::PlaceSubSurfaceBelow(Surface* sub_surface, Surface* sibling) { | 366 void Surface::PlaceSubSurfaceBelow(Surface* sub_surface, Surface* sibling) { |
| 368 TRACE_EVENT2("exo", "Surface::PlaceSubSurfaceBelow", "sub_surface", | 367 TRACE_EVENT2("exo", "Surface::PlaceSubSurfaceBelow", "sub_surface", |
| 369 sub_surface->AsTracedValue(), "sibling", | 368 sub_surface->AsTracedValue(), "sibling", |
| 370 sibling->AsTracedValue()); | 369 sibling->AsTracedValue()); |
| 371 | 370 |
| 372 if (sub_surface == sibling) { | 371 if (sub_surface == sibling) { |
| 373 DLOG(WARNING) << "Client tried to place sub-surface below itself"; | 372 DLOG(WARNING) << "Client tried to place sub-surface below itself"; |
| 374 return; | 373 return; |
| 375 } | 374 } |
| 376 | 375 |
| 377 auto sibling_it = FindListEntry(pending_sub_surfaces_, sibling); | 376 auto sibling_it = FindListEntry(pending_sub_surfaces_, sibling); |
| 378 if (sibling_it == pending_sub_surfaces_.end()) { | 377 if (sibling_it == pending_sub_surfaces_.end()) { |
| 379 DLOG(WARNING) << "Client tried to place sub-surface below a surface that " | 378 DLOG(WARNING) << "Client tried to place sub-surface below a surface that " |
| 380 "is not a sibling"; | 379 "is not a sibling"; |
| 381 return; | 380 return; |
| 382 } | 381 } |
| 383 | 382 |
| 384 DCHECK(ListContainsEntry(pending_sub_surfaces_, sub_surface)); | 383 DCHECK(ListContainsEntry(pending_sub_surfaces_, sub_surface)); |
| 385 pending_sub_surfaces_.splice( | 384 auto it = FindListEntry(pending_sub_surfaces_, sub_surface); |
| 386 sibling_it, pending_sub_surfaces_, | 385 if (it == sibling_it) |
| 387 FindListEntry(pending_sub_surfaces_, sub_surface)); | 386 return; |
| 387 pending_sub_surfaces_.splice(sibling_it, pending_sub_surfaces_, it); | |
| 388 modified_layer_info_ = true; | |
| 388 } | 389 } |
| 389 | 390 |
| 390 void Surface::SetViewport(const gfx::Size& viewport) { | 391 void Surface::SetViewport(const gfx::Size& viewport) { |
| 391 TRACE_EVENT1("exo", "Surface::SetViewport", "viewport", viewport.ToString()); | 392 TRACE_EVENT1("exo", "Surface::SetViewport", "viewport", viewport.ToString()); |
| 392 | 393 |
| 393 pending_viewport_ = viewport; | 394 pending_state_.viewport = viewport; |
| 394 } | 395 } |
| 395 | 396 |
| 396 void Surface::SetCrop(const gfx::RectF& crop) { | 397 void Surface::SetCrop(const gfx::RectF& crop) { |
| 397 TRACE_EVENT1("exo", "Surface::SetCrop", "crop", crop.ToString()); | 398 TRACE_EVENT1("exo", "Surface::SetCrop", "crop", crop.ToString()); |
| 398 | 399 |
| 399 pending_crop_ = crop; | 400 pending_state_.crop = crop; |
| 400 } | 401 } |
| 401 | 402 |
| 402 void Surface::SetOnlyVisibleOnSecureOutput(bool only_visible_on_secure_output) { | 403 void Surface::SetOnlyVisibleOnSecureOutput(bool only_visible_on_secure_output) { |
| 403 TRACE_EVENT1("exo", "Surface::SetOnlyVisibleOnSecureOutput", | 404 TRACE_EVENT1("exo", "Surface::SetOnlyVisibleOnSecureOutput", |
| 404 "only_visible_on_secure_output", only_visible_on_secure_output); | 405 "only_visible_on_secure_output", only_visible_on_secure_output); |
| 405 | 406 |
| 406 pending_only_visible_on_secure_output_ = only_visible_on_secure_output; | 407 pending_state_.only_visible_on_secure_output = only_visible_on_secure_output; |
| 407 } | 408 } |
| 408 | 409 |
| 409 void Surface::SetBlendMode(SkXfermode::Mode blend_mode) { | 410 void Surface::SetBlendMode(SkXfermode::Mode blend_mode) { |
| 410 TRACE_EVENT1("exo", "Surface::SetBlendMode", "blend_mode", blend_mode); | 411 TRACE_EVENT1("exo", "Surface::SetBlendMode", "blend_mode", blend_mode); |
| 411 | 412 |
| 412 pending_blend_mode_ = blend_mode; | 413 pending_state_.blend_mode = blend_mode; |
| 413 } | 414 } |
| 414 | 415 |
| 415 void Surface::SetAlpha(float alpha) { | 416 void Surface::SetAlpha(float alpha) { |
| 416 TRACE_EVENT1("exo", "Surface::SetAlpha", "alpha", alpha); | 417 TRACE_EVENT1("exo", "Surface::SetAlpha", "alpha", alpha); |
| 417 | 418 |
| 418 pending_alpha_ = alpha; | 419 pending_state_.alpha = alpha; |
| 419 } | 420 } |
| 420 | 421 |
| 421 void Surface::Commit() { | 422 void Surface::Commit() { |
| 422 TRACE_EVENT0("exo", "Surface::Commit"); | 423 TRACE_EVENT0("exo", "Surface::Commit"); |
| 423 | 424 |
| 424 needs_commit_surface_hierarchy_ = true; | 425 needs_commit_surface_hierarchy_ = true; |
| 425 | 426 |
| 426 if (delegate_) | 427 if (state_.ChangesLayerState(pending_state_)) |
| 428 modified_layer_info_ = true; | |
| 429 | |
| 430 if (has_pending_contents_ && | |
|
reveman
2016/06/10 03:42:20
can you split this into multiple if-statements to
| |
| 431 ((pending_buffer_ && | |
| 432 (current_resource_.size != pending_buffer_->GetSize())) || | |
| 433 (!pending_buffer_ && !current_resource_.size.IsEmpty()))) { | |
| 434 modified_layer_info_ = true; | |
| 435 } | |
| 436 | |
| 437 if (delegate_) { | |
| 427 delegate_->OnSurfaceCommit(); | 438 delegate_->OnSurfaceCommit(); |
| 428 else | 439 } else { |
| 440 CheckForCommittingToNewSurface(); | |
| 429 CommitSurfaceHierarchy(); | 441 CommitSurfaceHierarchy(); |
| 442 } | |
| 430 } | 443 } |
| 431 | 444 |
| 432 void Surface::CommitSurfaceHierarchy() { | 445 void Surface::CommitSurfaceHierarchy() { |
| 433 DCHECK(needs_commit_surface_hierarchy_); | 446 DCHECK(needs_commit_surface_hierarchy_); |
| 434 needs_commit_surface_hierarchy_ = false; | 447 needs_commit_surface_hierarchy_ = false; |
| 448 modified_layer_info_ = false; | |
| 435 | 449 |
| 436 // TODO(dcastagna): Make secure_output_only a layer property instead of a | 450 state_ = pending_state_; |
| 437 // texture mailbox flag so this can be changed without have to provide | 451 pending_state_.only_visible_on_secure_output = false; |
| 438 // new contents. | |
| 439 only_visible_on_secure_output_ = pending_only_visible_on_secure_output_; | |
| 440 pending_only_visible_on_secure_output_ = false; | |
| 441 | |
| 442 // Update current alpha. | |
| 443 alpha_ = pending_alpha_; | |
| 444 | |
| 445 // Update current crop rectangle. | |
| 446 crop_ = pending_crop_; | |
| 447 | 452 |
| 448 if (factory_owner_) { | 453 if (factory_owner_) { |
| 449 CommitSurfaceContents(); | 454 CommitSurfaceContents(); |
| 450 } else { | 455 } else { |
| 451 CommitTextureContents(); | 456 CommitTextureContents(); |
| 452 } | 457 } |
| 453 | 458 |
| 454 // Update current input region. | |
| 455 input_region_ = pending_input_region_; | |
| 456 | |
| 457 // Synchronize window hierarchy. This will position and update the stacking | 459 // Synchronize window hierarchy. This will position and update the stacking |
| 458 // order of all sub-surfaces after committing all pending state of sub-surface | 460 // order of all sub-surfaces after committing all pending state of sub-surface |
| 459 // descendants. | 461 // descendants. |
| 460 aura::Window* stacking_target = nullptr; | 462 aura::Window* stacking_target = nullptr; |
| 461 for (auto& sub_surface_entry : pending_sub_surfaces_) { | 463 for (auto& sub_surface_entry : pending_sub_surfaces_) { |
| 462 Surface* sub_surface = sub_surface_entry.first; | 464 Surface* sub_surface = sub_surface_entry.first; |
| 463 | 465 |
| 464 // Synchronsouly commit all pending state of the sub-surface and its | 466 // Synchronsouly commit all pending state of the sub-surface and its |
| 465 // decendents. | 467 // decendents. |
| 466 if (sub_surface->needs_commit_surface_hierarchy()) | 468 if (sub_surface->needs_commit_surface_hierarchy()) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 483 sub_surface->window()->SetBounds(gfx::Rect( | 485 sub_surface->window()->SetBounds(gfx::Rect( |
| 484 sub_surface_entry.second, sub_surface->window()->layer()->size())); | 486 sub_surface_entry.second, sub_surface->window()->layer()->size())); |
| 485 } | 487 } |
| 486 } | 488 } |
| 487 | 489 |
| 488 bool Surface::IsSynchronized() const { | 490 bool Surface::IsSynchronized() const { |
| 489 return delegate_ ? delegate_->IsSurfaceSynchronized() : false; | 491 return delegate_ ? delegate_->IsSurfaceSynchronized() : false; |
| 490 } | 492 } |
| 491 | 493 |
| 492 gfx::Rect Surface::GetHitTestBounds() const { | 494 gfx::Rect Surface::GetHitTestBounds() const { |
| 493 SkIRect bounds = input_region_.getBounds(); | 495 SkIRect bounds = state_.input_region.getBounds(); |
| 494 if (!bounds.intersect( | 496 if (!bounds.intersect( |
| 495 gfx::RectToSkIRect(gfx::Rect(window_->layer()->size())))) | 497 gfx::RectToSkIRect(gfx::Rect(window_->layer()->size())))) |
| 496 return gfx::Rect(); | 498 return gfx::Rect(); |
| 497 return gfx::SkIRectToRect(bounds); | 499 return gfx::SkIRectToRect(bounds); |
| 498 } | 500 } |
| 499 | 501 |
| 500 bool Surface::HitTestRect(const gfx::Rect& rect) const { | 502 bool Surface::HitTestRect(const gfx::Rect& rect) const { |
| 501 if (HasHitTestMask()) | 503 if (HasHitTestMask()) |
| 502 return input_region_.intersects(gfx::RectToSkIRect(rect)); | 504 return state_.input_region.intersects(gfx::RectToSkIRect(rect)); |
| 503 | 505 |
| 504 return rect.Intersects(gfx::Rect(window_->layer()->size())); | 506 return rect.Intersects(gfx::Rect(window_->layer()->size())); |
| 505 } | 507 } |
| 506 | 508 |
| 507 bool Surface::HasHitTestMask() const { | 509 bool Surface::HasHitTestMask() const { |
| 508 return !input_region_.contains( | 510 return !state_.input_region.contains( |
| 509 gfx::RectToSkIRect(gfx::Rect(window_->layer()->size()))); | 511 gfx::RectToSkIRect(gfx::Rect(window_->layer()->size()))); |
| 510 } | 512 } |
| 511 | 513 |
| 512 void Surface::GetHitTestMask(gfx::Path* mask) const { | 514 void Surface::GetHitTestMask(gfx::Path* mask) const { |
| 513 input_region_.getBoundaryPath(mask); | 515 state_.input_region.getBoundaryPath(mask); |
| 514 } | 516 } |
| 515 | 517 |
| 516 void Surface::RegisterCursorProvider(Pointer* provider) { | 518 void Surface::RegisterCursorProvider(Pointer* provider) { |
| 517 cursor_providers_.insert(provider); | 519 cursor_providers_.insert(provider); |
| 518 } | 520 } |
| 519 | 521 |
| 520 void Surface::UnregisterCursorProvider(Pointer* provider) { | 522 void Surface::UnregisterCursorProvider(Pointer* provider) { |
| 521 cursor_providers_.erase(provider); | 523 cursor_providers_.erase(provider); |
| 522 } | 524 } |
| 523 | 525 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 compositor_ = nullptr; | 635 compositor_ = nullptr; |
| 634 } | 636 } |
| 635 | 637 |
| 636 void Surface::WillDraw(cc::SurfaceId id) { | 638 void Surface::WillDraw(cc::SurfaceId id) { |
| 637 while (!active_frame_callbacks_.empty()) { | 639 while (!active_frame_callbacks_.empty()) { |
| 638 active_frame_callbacks_.front().Run(base::TimeTicks::Now()); | 640 active_frame_callbacks_.front().Run(base::TimeTicks::Now()); |
| 639 active_frame_callbacks_.pop_front(); | 641 active_frame_callbacks_.pop_front(); |
| 640 } | 642 } |
| 641 } | 643 } |
| 642 | 644 |
| 645 void Surface::CheckForCommittingToNewSurface() { | |
|
reveman
2016/06/10 03:42:20
I feel like the correct name for this function is
| |
| 646 if (HaveChildLayersChanged()) | |
| 647 SetChildrenCommitToNewSurface(); | |
| 648 } | |
| 649 | |
| 650 Surface::State::State() | |
| 651 : input_region(SkIRect::MakeLargest()), | |
| 652 buffer_scale(1.0f), | |
| 653 only_visible_on_secure_output(false), | |
| 654 blend_mode(SkXfermode::kSrcOver_Mode), | |
| 655 alpha(1.0f) {} | |
|
reveman
2016/06/10 03:42:20
feel free to move these to the deceleration if you
| |
| 656 | |
| 657 Surface::State::~State() = default; | |
| 658 | |
| 659 bool Surface::State::ChangesLayerState(const State& other) { | |
|
reveman
2016/06/10 03:42:20
"Changes" is a bit weird as it implies something s
| |
| 660 return (other.crop != crop || alpha != other.alpha || | |
| 661 other.blend_mode != blend_mode || other.viewport != viewport || | |
| 662 other.opaque_region != opaque_region || | |
| 663 other.buffer_scale != buffer_scale || | |
| 664 other.input_region != input_region); | |
| 665 } | |
| 666 | |
| 667 bool Surface::HaveChildLayersChanged() { | |
|
reveman
2016/06/10 03:42:20
This is not only dealing with child layers but als
| |
| 668 if (needs_commit_surface_hierarchy_ && modified_layer_info_) | |
| 669 return true; | |
| 670 | |
| 671 for (auto& surf : pending_sub_surfaces_) { | |
|
reveman
2016/06/10 03:42:20
nit: const auto&? and s/surf/sub_surface_entry/
| |
| 672 if (surf.first->HaveChildLayersChanged()) | |
| 673 return true; | |
| 674 } | |
| 675 return false; | |
| 676 } | |
| 677 | |
| 678 void Surface::SetChildrenCommitToNewSurface() { | |
|
reveman
2016/06/10 03:42:20
nit: SetSurfaceHierarchyNeedsCommitToNewSurfaces()
| |
| 679 commit_to_new_surface_ = true; | |
| 680 for (auto& surf : pending_sub_surfaces_) { | |
|
reveman
2016/06/10 03:42:20
nit: s/surf/sub_surface_entry/
| |
| 681 surf.first->SetChildrenCommitToNewSurface(); | |
| 682 } | |
| 683 } | |
| 684 | |
| 643 void Surface::CommitTextureContents() { | 685 void Surface::CommitTextureContents() { |
| 644 // We update contents if Attach() has been called since last commit. | 686 // We update contents if Attach() has been called since last commit. |
| 645 if (has_pending_contents_) { | 687 if (has_pending_contents_) { |
| 646 has_pending_contents_ = false; | 688 has_pending_contents_ = false; |
| 647 | 689 |
| 648 current_buffer_ = pending_buffer_; | 690 current_buffer_ = pending_buffer_; |
| 649 pending_buffer_.reset(); | 691 pending_buffer_.reset(); |
| 650 | 692 |
| 651 cc::TextureMailbox texture_mailbox; | 693 cc::TextureMailbox texture_mailbox; |
| 652 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; | 694 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; |
| 653 if (current_buffer_) { | 695 if (current_buffer_) { |
| 654 texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox( | 696 texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox( |
| 655 &texture_mailbox, only_visible_on_secure_output_, | 697 &texture_mailbox, state_.only_visible_on_secure_output, |
| 656 true /* client_usage */); | 698 true /* client_usage */); |
| 657 } | 699 } |
| 658 | 700 |
| 659 // Update layer with the new contents. | 701 // Update layer with the new contents. |
| 660 if (texture_mailbox_release_callback) { | 702 if (texture_mailbox_release_callback) { |
| 661 texture_size_in_dip_ = gfx::ScaleToFlooredSize( | 703 texture_size_in_dip_ = gfx::ScaleToFlooredSize( |
| 662 texture_mailbox.size_in_pixels(), 1.0f / pending_buffer_scale_); | 704 texture_mailbox.size_in_pixels(), 1.0f / state_.buffer_scale); |
| 663 window_->layer()->SetTextureMailbox( | 705 window_->layer()->SetTextureMailbox( |
| 664 texture_mailbox, std::move(texture_mailbox_release_callback), | 706 texture_mailbox, std::move(texture_mailbox_release_callback), |
| 665 texture_size_in_dip_); | 707 texture_size_in_dip_); |
| 666 window_->layer()->SetTextureFlipped(false); | 708 window_->layer()->SetTextureFlipped(false); |
| 667 } else { | 709 } else { |
| 668 // Show solid color content if no buffer is attached or we failed | 710 // Show solid color content if no buffer is attached or we failed |
| 669 // to produce a texture mailbox for the currently attached buffer. | 711 // to produce a texture mailbox for the currently attached buffer. |
| 670 window_->layer()->SetShowSolidColorContent(); | 712 window_->layer()->SetShowSolidColorContent(); |
| 671 window_->layer()->SetColor(SK_ColorBLACK); | 713 window_->layer()->SetColor(SK_ColorBLACK); |
| 672 } | 714 } |
| 673 | 715 |
| 674 // Schedule redraw of the damage region. | 716 // Schedule redraw of the damage region. |
| 675 for (SkRegion::Iterator it(pending_damage_); !it.done(); it.next()) | 717 for (SkRegion::Iterator it(pending_damage_); !it.done(); it.next()) |
| 676 window_->layer()->SchedulePaint(gfx::SkIRectToRect(it.rect())); | 718 window_->layer()->SchedulePaint(gfx::SkIRectToRect(it.rect())); |
| 677 | 719 |
| 678 // Reset damage. | 720 // Reset damage. |
| 679 pending_damage_.setEmpty(); | 721 pending_damage_.setEmpty(); |
| 680 } | 722 } |
| 681 | 723 |
| 682 if (window_->layer()->has_external_content()) { | 724 if (window_->layer()->has_external_content()) { |
| 683 // Determine the new surface size. | 725 // Determine the new surface size. |
| 684 // - Texture size in DIP defines the size if nothing else is set. | 726 // - Texture size in DIP defines the size if nothing else is set. |
| 685 // - If a viewport is set then that defines the size, otherwise | 727 // - If a viewport is set then that defines the size, otherwise |
| 686 // the crop rectangle defines the size if set. | 728 // the crop rectangle defines the size if set. |
| 687 gfx::Size contents_size = texture_size_in_dip_; | 729 gfx::Size contents_size = texture_size_in_dip_; |
| 688 if (!pending_viewport_.IsEmpty()) { | 730 if (!state_.viewport.IsEmpty()) { |
| 689 contents_size = pending_viewport_; | 731 contents_size = state_.viewport; |
| 690 } else if (!crop_.IsEmpty()) { | 732 } else if (!state_.crop.IsEmpty()) { |
| 691 DLOG_IF(WARNING, !gfx::IsExpressibleAsInt(crop_.width()) || | 733 DLOG_IF(WARNING, !gfx::IsExpressibleAsInt(state_.crop.width()) || |
| 692 !gfx::IsExpressibleAsInt(crop_.height())) | 734 !gfx::IsExpressibleAsInt(state_.crop.height())) |
| 693 << "Crop rectangle size (" << crop_.size().ToString() | 735 << "Crop rectangle size (" << state_.crop.size().ToString() |
| 694 << ") most be expressible using integers when viewport is not set"; | 736 << ") most be expressible using integers when viewport is not set"; |
| 695 contents_size = gfx::ToCeiledSize(crop_.size()); | 737 contents_size = gfx::ToCeiledSize(state_.crop.size()); |
| 696 } | 738 } |
| 697 window_->layer()->SetTextureCrop(crop_); | 739 window_->layer()->SetTextureCrop(state_.crop); |
| 698 window_->layer()->SetTextureScale( | 740 window_->layer()->SetTextureScale( |
| 699 static_cast<float>(texture_size_in_dip_.width()) / | 741 static_cast<float>(texture_size_in_dip_.width()) / |
| 700 contents_size.width(), | 742 contents_size.width(), |
| 701 static_cast<float>(texture_size_in_dip_.height()) / | 743 static_cast<float>(texture_size_in_dip_.height()) / |
| 702 contents_size.height()); | 744 contents_size.height()); |
| 703 window_->layer()->SetTextureAlpha(alpha_); | 745 window_->layer()->SetTextureAlpha(state_.alpha); |
| 704 window_->layer()->SetBounds( | 746 window_->layer()->SetBounds( |
| 705 gfx::Rect(window_->layer()->bounds().origin(), contents_size)); | 747 gfx::Rect(window_->layer()->bounds().origin(), contents_size)); |
| 706 } | 748 } |
| 707 | 749 |
| 708 // Move pending frame callbacks to the end of |frame_callbacks_|. | 750 // Move pending frame callbacks to the end of |frame_callbacks_|. |
| 709 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); | 751 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); |
| 710 | 752 |
| 711 // Update alpha compositing properties. | 753 // Update alpha compositing properties. |
| 712 // TODO(reveman): Use a more reliable way to force blending off than setting | 754 // TODO(reveman): Use a more reliable way to force blending off than setting |
| 713 // fills-bounds-opaquely. | 755 // fills-bounds-opaquely. |
| 714 window_->layer()->SetFillsBoundsOpaquely( | 756 window_->layer()->SetFillsBoundsOpaquely( |
| 715 pending_blend_mode_ == SkXfermode::kSrc_Mode || | 757 state_.blend_mode == SkXfermode::kSrc_Mode || |
| 716 pending_opaque_region_.contains( | 758 state_.opaque_region.contains( |
| 717 gfx::RectToSkIRect(gfx::Rect(window_->layer()->size())))); | 759 gfx::RectToSkIRect(gfx::Rect(window_->layer()->size())))); |
| 718 } | 760 } |
| 719 | 761 |
| 720 void Surface::CommitSurfaceContents() { | 762 void Surface::CommitSurfaceContents() { |
| 721 // We update contents if Attach() has been called since last commit. | 763 // We update contents if Attach() has been called since last commit. |
| 722 if (has_pending_contents_) { | 764 if (has_pending_contents_) { |
| 723 has_pending_contents_ = false; | 765 has_pending_contents_ = false; |
| 724 current_buffer_ = pending_buffer_; | 766 current_buffer_ = pending_buffer_; |
| 725 pending_buffer_.reset(); | 767 pending_buffer_.reset(); |
| 726 | 768 |
| 727 if (current_buffer_) { | 769 if (current_buffer_) { |
| 728 std::unique_ptr<cc::SingleReleaseCallback> | 770 std::unique_ptr<cc::SingleReleaseCallback> |
| 729 texture_mailbox_release_callback; | 771 texture_mailbox_release_callback; |
| 730 | 772 |
| 731 cc::TextureMailbox texture_mailbox; | 773 cc::TextureMailbox texture_mailbox; |
| 732 texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox( | 774 texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox( |
| 733 &texture_mailbox, only_visible_on_secure_output_, | 775 &texture_mailbox, state_.only_visible_on_secure_output, |
| 734 true /* client_usage */); | 776 true /* client_usage */); |
| 735 cc::TransferableResource resource; | 777 cc::TransferableResource resource; |
| 736 resource.id = next_resource_id_++; | 778 resource.id = next_resource_id_++; |
| 737 resource.format = cc::RGBA_8888; | 779 resource.format = cc::RGBA_8888; |
| 738 resource.filter = | 780 resource.filter = |
| 739 texture_mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR; | 781 texture_mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR; |
| 740 resource.size = texture_mailbox.size_in_pixels(); | 782 resource.size = texture_mailbox.size_in_pixels(); |
| 741 resource.mailbox_holder = gpu::MailboxHolder(texture_mailbox.mailbox(), | 783 resource.mailbox_holder = gpu::MailboxHolder(texture_mailbox.mailbox(), |
| 742 texture_mailbox.sync_token(), | 784 texture_mailbox.sync_token(), |
| 743 texture_mailbox.target()); | 785 texture_mailbox.target()); |
| 744 resource.is_overlay_candidate = texture_mailbox.is_overlay_candidate(); | 786 resource.is_overlay_candidate = texture_mailbox.is_overlay_candidate(); |
| 745 | 787 |
| 746 factory_owner_->release_callbacks_[resource.id] = std::make_pair( | 788 factory_owner_->release_callbacks_[resource.id] = std::make_pair( |
| 747 factory_owner_, std::move(texture_mailbox_release_callback)); | 789 factory_owner_, std::move(texture_mailbox_release_callback)); |
| 748 current_resource_ = resource; | 790 current_resource_ = resource; |
| 749 } else { | 791 } else { |
| 750 current_resource_.id = 0; | 792 current_resource_.id = 0; |
| 751 current_resource_.size = gfx::Size(); | 793 current_resource_.size = gfx::Size(); |
| 752 } | 794 } |
| 753 } | 795 } |
| 754 | 796 |
| 755 cc::SurfaceId old_surface_id = surface_id_; | 797 cc::SurfaceId old_surface_id = surface_id_; |
| 756 surface_id_ = factory_owner_->id_allocator_->GenerateId(); | 798 if (commit_to_new_surface_ || surface_id_.is_null()) { |
| 757 factory_owner_->surface_factory_->Create(surface_id_); | 799 commit_to_new_surface_ = false; |
| 800 surface_id_ = factory_owner_->id_allocator_->GenerateId(); | |
| 801 factory_owner_->surface_factory_->Create(surface_id_); | |
| 802 } | |
| 758 | 803 |
| 759 gfx::Size buffer_size = current_resource_.size; | 804 gfx::Size buffer_size = current_resource_.size; |
| 760 gfx::SizeF scaled_buffer_size( | 805 gfx::SizeF scaled_buffer_size( |
| 761 gfx::ScaleSize(gfx::SizeF(buffer_size), 1.0f / pending_buffer_scale_)); | 806 gfx::ScaleSize(gfx::SizeF(buffer_size), 1.0f / state_.buffer_scale)); |
| 762 | 807 |
| 763 gfx::Size layer_size; // Size of the output layer, in DIP. | 808 gfx::Size layer_size; // Size of the output layer, in DIP. |
| 764 if (!pending_viewport_.IsEmpty()) { | 809 if (!state_.viewport.IsEmpty()) { |
| 765 layer_size = pending_viewport_; | 810 layer_size = state_.viewport; |
| 766 } else if (!crop_.IsEmpty()) { | 811 } else if (!state_.crop.IsEmpty()) { |
| 767 DLOG_IF(WARNING, !gfx::IsExpressibleAsInt(crop_.width()) || | 812 DLOG_IF(WARNING, !gfx::IsExpressibleAsInt(state_.crop.width()) || |
| 768 !gfx::IsExpressibleAsInt(crop_.height())) | 813 !gfx::IsExpressibleAsInt(state_.crop.height())) |
| 769 << "Crop rectangle size (" << crop_.size().ToString() | 814 << "Crop rectangle size (" << state_.crop.size().ToString() |
| 770 << ") most be expressible using integers when viewport is not set"; | 815 << ") most be expressible using integers when viewport is not set"; |
| 771 layer_size = gfx::ToCeiledSize(crop_.size()); | 816 layer_size = gfx::ToCeiledSize(state_.crop.size()); |
| 772 } else { | 817 } else { |
| 773 layer_size = gfx::ToCeiledSize(scaled_buffer_size); | 818 layer_size = gfx::ToCeiledSize(scaled_buffer_size); |
| 774 } | 819 } |
| 775 | 820 |
| 776 // TODO(jbauman): Figure out how this interacts with the pixel size of | 821 // TODO(jbauman): Figure out how this interacts with the pixel size of |
| 777 // CopyOutputRequests on the layer. | 822 // CopyOutputRequests on the layer. |
| 778 float contents_surface_to_layer_scale = 1.0; | 823 float contents_surface_to_layer_scale = 1.0; |
| 779 gfx::Size contents_surface_size = layer_size; | 824 gfx::Size contents_surface_size = layer_size; |
| 780 | 825 |
| 781 gfx::PointF uv_top_left(0.f, 0.f); | 826 gfx::PointF uv_top_left(0.f, 0.f); |
| 782 gfx::PointF uv_bottom_right(1.f, 1.f); | 827 gfx::PointF uv_bottom_right(1.f, 1.f); |
| 783 if (!crop_.IsEmpty()) { | 828 if (!state_.crop.IsEmpty()) { |
| 784 uv_top_left = crop_.origin(); | 829 uv_top_left = state_.crop.origin(); |
| 785 | 830 |
| 786 uv_top_left.Scale(1.f / scaled_buffer_size.width(), | 831 uv_top_left.Scale(1.f / scaled_buffer_size.width(), |
| 787 1.f / scaled_buffer_size.height()); | 832 1.f / scaled_buffer_size.height()); |
| 788 uv_bottom_right = crop_.bottom_right(); | 833 uv_bottom_right = state_.crop.bottom_right(); |
| 789 uv_bottom_right.Scale(1.f / scaled_buffer_size.width(), | 834 uv_bottom_right.Scale(1.f / scaled_buffer_size.width(), |
| 790 1.f / scaled_buffer_size.height()); | 835 1.f / scaled_buffer_size.height()); |
| 791 } | 836 } |
| 792 | 837 |
| 793 // pending_damage_ is in Surface coordinates. | 838 // pending_damage_ is in Surface coordinates. |
| 794 gfx::Rect damage_rect = gfx::SkIRectToRect(pending_damage_.getBounds()); | 839 gfx::Rect damage_rect = gfx::SkIRectToRect(pending_damage_.getBounds()); |
| 795 | 840 |
| 796 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | 841 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); |
| 797 render_pass->SetAll(cc::RenderPassId(1, 1), gfx::Rect(contents_surface_size), | 842 render_pass->SetAll(cc::RenderPassId(1, 1), gfx::Rect(contents_surface_size), |
| 798 damage_rect, gfx::Transform(), true); | 843 damage_rect, gfx::Transform(), true); |
| 799 | 844 |
| 800 gfx::Rect quad_rect = gfx::Rect(contents_surface_size); | 845 gfx::Rect quad_rect = gfx::Rect(contents_surface_size); |
| 801 cc::SharedQuadState* quad_state = | 846 cc::SharedQuadState* quad_state = |
| 802 render_pass->CreateAndAppendSharedQuadState(); | 847 render_pass->CreateAndAppendSharedQuadState(); |
| 803 quad_state->quad_layer_bounds = contents_surface_size; | 848 quad_state->quad_layer_bounds = contents_surface_size; |
| 804 quad_state->visible_quad_layer_rect = quad_rect; | 849 quad_state->visible_quad_layer_rect = quad_rect; |
| 805 quad_state->opacity = alpha_; | 850 quad_state->opacity = state_.alpha; |
| 806 | 851 |
| 807 bool frame_is_opaque = false; | 852 bool frame_is_opaque = false; |
| 808 | 853 |
| 809 std::unique_ptr<cc::DelegatedFrameData> delegated_frame( | 854 std::unique_ptr<cc::DelegatedFrameData> delegated_frame( |
| 810 new cc::DelegatedFrameData); | 855 new cc::DelegatedFrameData); |
| 811 if (current_resource_.id) { | 856 if (current_resource_.id) { |
| 812 cc::TextureDrawQuad* texture_quad = | 857 cc::TextureDrawQuad* texture_quad = |
| 813 render_pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); | 858 render_pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); |
| 814 float vertex_opacity[4] = {1.0, 1.0, 1.0, 1.0}; | 859 float vertex_opacity[4] = {1.0, 1.0, 1.0, 1.0}; |
| 815 gfx::Rect opaque_rect; | 860 gfx::Rect opaque_rect; |
| 816 frame_is_opaque = | 861 frame_is_opaque = |
| 817 pending_blend_mode_ == SkXfermode::kSrc_Mode || | 862 state_.blend_mode == SkXfermode::kSrc_Mode || |
| 818 pending_opaque_region_.contains(gfx::RectToSkIRect(quad_rect)); | 863 state_.opaque_region.contains(gfx::RectToSkIRect(quad_rect)); |
| 819 if (frame_is_opaque) { | 864 if (frame_is_opaque) { |
| 820 opaque_rect = quad_rect; | 865 opaque_rect = quad_rect; |
| 821 } else if (pending_opaque_region_.isRect()) { | 866 } else if (state_.opaque_region.isRect()) { |
| 822 opaque_rect = gfx::SkIRectToRect(pending_opaque_region_.getBounds()); | 867 opaque_rect = gfx::SkIRectToRect(state_.opaque_region.getBounds()); |
| 823 } | 868 } |
| 824 | 869 |
| 825 texture_quad->SetNew(quad_state, quad_rect, opaque_rect, quad_rect, | 870 texture_quad->SetNew(quad_state, quad_rect, opaque_rect, quad_rect, |
| 826 current_resource_.id, true, uv_top_left, | 871 current_resource_.id, true, uv_top_left, |
| 827 uv_bottom_right, SK_ColorTRANSPARENT, vertex_opacity, | 872 uv_bottom_right, SK_ColorTRANSPARENT, vertex_opacity, |
| 828 false, false, only_visible_on_secure_output_); | 873 false, false, state_.only_visible_on_secure_output); |
| 829 delegated_frame->resource_list.push_back(current_resource_); | 874 delegated_frame->resource_list.push_back(current_resource_); |
| 830 } else { | 875 } else { |
| 831 cc::SolidColorDrawQuad* solid_quad = | 876 cc::SolidColorDrawQuad* solid_quad = |
| 832 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); | 877 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); |
| 833 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); | 878 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); |
| 834 frame_is_opaque = true; | 879 frame_is_opaque = true; |
| 835 } | 880 } |
| 836 | 881 |
| 837 delegated_frame->render_pass_list.push_back(std::move(render_pass)); | 882 delegated_frame->render_pass_list.push_back(std::move(render_pass)); |
| 838 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | 883 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
| 839 frame->delegated_frame_data = std::move(delegated_frame); | 884 frame->delegated_frame_data = std::move(delegated_frame); |
| 840 | 885 |
| 841 factory_owner_->surface_factory_->SubmitCompositorFrame( | 886 factory_owner_->surface_factory_->SubmitCompositorFrame( |
| 842 surface_id_, std::move(frame), cc::SurfaceFactory::DrawCallback()); | 887 surface_id_, std::move(frame), cc::SurfaceFactory::DrawCallback()); |
| 843 | 888 |
| 844 if (!old_surface_id.is_null()) { | 889 if (!old_surface_id.is_null() && old_surface_id != surface_id_) { |
| 845 factory_owner_->surface_factory_->SetPreviousFrameSurface(surface_id_, | 890 factory_owner_->surface_factory_->SetPreviousFrameSurface(surface_id_, |
| 846 old_surface_id); | 891 old_surface_id); |
| 847 factory_owner_->surface_factory_->Destroy(old_surface_id); | 892 factory_owner_->surface_factory_->Destroy(old_surface_id); |
| 848 } | 893 } |
| 849 | 894 |
| 850 window_->layer()->SetShowSurface( | 895 if (old_surface_id != surface_id_) { |
| 851 surface_id_, | 896 window_->layer()->SetShowSurface( |
| 852 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), | 897 surface_id_, |
| 853 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), | 898 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), |
| 854 contents_surface_size, contents_surface_to_layer_scale, layer_size); | 899 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), |
| 855 window_->layer()->SetBounds( | 900 contents_surface_size, contents_surface_to_layer_scale, layer_size); |
| 856 gfx::Rect(window_->layer()->bounds().origin(), layer_size)); | 901 window_->layer()->SetBounds( |
| 857 window_->layer()->SetFillsBoundsOpaquely(alpha_ == 1.0f && frame_is_opaque); | 902 gfx::Rect(window_->layer()->bounds().origin(), layer_size)); |
| 903 window_->layer()->SetFillsBoundsOpaquely(state_.alpha == 1.0f && | |
| 904 frame_is_opaque); | |
| 905 } | |
| 858 | 906 |
| 859 // Reset damage. | 907 // Reset damage. |
| 860 pending_damage_.setEmpty(); | 908 pending_damage_.setEmpty(); |
| 861 | 909 |
| 862 DCHECK(!current_resource_.id || | 910 DCHECK(!current_resource_.id || |
| 863 factory_owner_->release_callbacks_.count(current_resource_.id)); | 911 factory_owner_->release_callbacks_.count(current_resource_.id)); |
| 864 | 912 |
| 865 // Move pending frame callbacks to the end of active_frame_callbacks_ | 913 // Move pending frame callbacks to the end of active_frame_callbacks_ |
| 866 active_frame_callbacks_.splice(active_frame_callbacks_.end(), | 914 active_frame_callbacks_.splice(active_frame_callbacks_.end(), |
| 867 pending_frame_callbacks_); | 915 pending_frame_callbacks_); |
| 868 } | 916 } |
| 869 | 917 |
| 870 void Surface::SetTextureLayerContents(ui::Layer* layer) { | 918 void Surface::SetTextureLayerContents(ui::Layer* layer) { |
| 871 DCHECK(current_buffer_); | 919 DCHECK(current_buffer_); |
| 872 | 920 |
| 873 cc::TextureMailbox texture_mailbox; | 921 cc::TextureMailbox texture_mailbox; |
| 874 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback = | 922 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback = |
| 875 current_buffer_->ProduceTextureMailbox(&texture_mailbox, | 923 current_buffer_->ProduceTextureMailbox( |
| 876 only_visible_on_secure_output_, | 924 &texture_mailbox, state_.only_visible_on_secure_output, |
| 877 false /* client_usage */); | 925 false /* client_usage */); |
| 878 if (!texture_mailbox_release_callback) | 926 if (!texture_mailbox_release_callback) |
| 879 return; | 927 return; |
| 880 | 928 |
| 881 layer->SetTextureMailbox(texture_mailbox, | 929 layer->SetTextureMailbox(texture_mailbox, |
| 882 std::move(texture_mailbox_release_callback), | 930 std::move(texture_mailbox_release_callback), |
| 883 texture_size_in_dip_); | 931 texture_size_in_dip_); |
| 884 layer->SetTextureFlipped(false); | 932 layer->SetTextureFlipped(false); |
| 885 layer->SetTextureCrop(crop_); | 933 layer->SetTextureCrop(state_.crop); |
| 886 layer->SetTextureScale(static_cast<float>(texture_size_in_dip_.width()) / | 934 layer->SetTextureScale(static_cast<float>(texture_size_in_dip_.width()) / |
| 887 layer->bounds().width(), | 935 layer->bounds().width(), |
| 888 static_cast<float>(texture_size_in_dip_.height()) / | 936 static_cast<float>(texture_size_in_dip_.height()) / |
| 889 layer->bounds().height()); | 937 layer->bounds().height()); |
| 890 layer->SetTextureAlpha(alpha_); | 938 layer->SetTextureAlpha(state_.alpha); |
| 891 } | 939 } |
| 892 | 940 |
| 893 void Surface::SetSurfaceLayerContents(ui::Layer* layer) { | 941 void Surface::SetSurfaceLayerContents(ui::Layer* layer) { |
| 894 if (surface_id_.is_null()) | 942 if (surface_id_.is_null()) |
| 895 return; | 943 return; |
| 896 | 944 |
| 897 gfx::Size layer_size = layer->bounds().size(); | 945 gfx::Size layer_size = layer->bounds().size(); |
| 898 float contents_surface_to_layer_scale = 1.0f; | 946 float contents_surface_to_layer_scale = 1.0f; |
| 899 | 947 |
| 900 layer->SetShowSurface( | 948 layer->SetShowSurface( |
| 901 surface_id_, | 949 surface_id_, |
| 902 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), | 950 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), |
| 903 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), | 951 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), |
| 904 layer_size, contents_surface_to_layer_scale, layer_size); | 952 layer_size, contents_surface_to_layer_scale, layer_size); |
| 905 } | 953 } |
| 906 | 954 |
| 907 bool Surface::use_surface_layer_ = false; | 955 bool Surface::use_surface_layer_ = false; |
| 908 | 956 |
| 909 } // namespace exo | 957 } // namespace exo |
| OLD | NEW |