| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 compositor_frame_sink_holder_->GetCompositorFrameSink()->EvictFrame(); | 225 compositor_frame_sink_holder_->GetCompositorFrameSink()->EvictFrame(); |
| 226 } | 226 } |
| 227 | 227 |
| 228 // static | 228 // static |
| 229 Surface* Surface::AsSurface(const aura::Window* window) { | 229 Surface* Surface::AsSurface(const aura::Window* window) { |
| 230 return window->GetProperty(kSurfaceKey); | 230 return window->GetProperty(kSurfaceKey); |
| 231 } | 231 } |
| 232 | 232 |
| 233 cc::SurfaceId Surface::GetSurfaceId() const { | 233 cc::SurfaceId Surface::GetSurfaceId() const { |
| 234 return cc::SurfaceId(frame_sink_id_, local_frame_id_); | 234 return cc::SurfaceId(frame_sink_id_, local_surface_id_); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void Surface::Attach(Buffer* buffer) { | 237 void Surface::Attach(Buffer* buffer) { |
| 238 TRACE_EVENT1("exo", "Surface::Attach", "buffer", | 238 TRACE_EVENT1("exo", "Surface::Attach", "buffer", |
| 239 buffer ? buffer->GetSize().ToString() : "null"); | 239 buffer ? buffer->GetSize().ToString() : "null"); |
| 240 | 240 |
| 241 has_pending_contents_ = true; | 241 has_pending_contents_ = true; |
| 242 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>()); | 242 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>()); |
| 243 } | 243 } |
| 244 | 244 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 445 |
| 446 // We update contents if Attach() has been called since last commit. | 446 // We update contents if Attach() has been called since last commit. |
| 447 if (has_pending_contents_) { | 447 if (has_pending_contents_) { |
| 448 has_pending_contents_ = false; | 448 has_pending_contents_ = false; |
| 449 | 449 |
| 450 current_buffer_ = std::move(pending_buffer_); | 450 current_buffer_ = std::move(pending_buffer_); |
| 451 | 451 |
| 452 UpdateResource(true); | 452 UpdateResource(true); |
| 453 } | 453 } |
| 454 | 454 |
| 455 cc::LocalFrameId old_local_frame_id = local_frame_id_; | 455 cc::LocalSurfaceId old_local_surface_id = local_surface_id_; |
| 456 if (needs_commit_to_new_surface_ || !local_frame_id_.is_valid()) { | 456 if (needs_commit_to_new_surface_ || !local_surface_id_.is_valid()) { |
| 457 needs_commit_to_new_surface_ = false; | 457 needs_commit_to_new_surface_ = false; |
| 458 local_frame_id_ = id_allocator_.GenerateId(); | 458 local_surface_id_ = id_allocator_.GenerateId(); |
| 459 } | 459 } |
| 460 | 460 |
| 461 UpdateSurface(false); | 461 UpdateSurface(false); |
| 462 | 462 |
| 463 if (old_local_frame_id != local_frame_id_) { | 463 if (old_local_surface_id != local_surface_id_) { |
| 464 float contents_surface_to_layer_scale = 1.0; | 464 float contents_surface_to_layer_scale = 1.0; |
| 465 // The bounds must be updated before switching to the new surface, because | 465 // The bounds must be updated before switching to the new surface, because |
| 466 // the layer may be mirrored, in which case a surface change causes the | 466 // the layer may be mirrored, in which case a surface change causes the |
| 467 // mirror layer to update its surface using the latest bounds. | 467 // mirror layer to update its surface using the latest bounds. |
| 468 window_->layer()->SetBounds( | 468 window_->layer()->SetBounds( |
| 469 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); | 469 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); |
| 470 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_); | 470 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); |
| 471 window_->layer()->SetShowSurface( | 471 window_->layer()->SetShowSurface( |
| 472 cc::SurfaceInfo(surface_id, contents_surface_to_layer_scale, | 472 cc::SurfaceInfo(surface_id, contents_surface_to_layer_scale, |
| 473 content_size_), | 473 content_size_), |
| 474 surface_reference_factory_); | 474 surface_reference_factory_); |
| 475 window_->layer()->SetFillsBoundsOpaquely( | 475 window_->layer()->SetFillsBoundsOpaquely( |
| 476 state_.blend_mode == SkBlendMode::kSrc || | 476 state_.blend_mode == SkBlendMode::kSrc || |
| 477 state_.opaque_region.contains( | 477 state_.opaque_region.contains( |
| 478 gfx::RectToSkIRect(gfx::Rect(content_size_)))); | 478 gfx::RectToSkIRect(gfx::Rect(content_size_)))); |
| 479 } | 479 } |
| 480 | 480 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 | 611 |
| 612 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { | 612 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { |
| 613 if (HasLayerHierarchyChanged()) | 613 if (HasLayerHierarchyChanged()) |
| 614 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); | 614 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 615 } | 615 } |
| 616 | 616 |
| 617 //////////////////////////////////////////////////////////////////////////////// | 617 //////////////////////////////////////////////////////////////////////////////// |
| 618 // ui::ContextFactoryObserver overrides: | 618 // ui::ContextFactoryObserver overrides: |
| 619 | 619 |
| 620 void Surface::OnLostResources() { | 620 void Surface::OnLostResources() { |
| 621 if (!local_frame_id_.is_valid()) | 621 if (!local_surface_id_.is_valid()) |
| 622 return; | 622 return; |
| 623 | 623 |
| 624 UpdateResource(false); | 624 UpdateResource(false); |
| 625 UpdateSurface(true); | 625 UpdateSurface(true); |
| 626 } | 626 } |
| 627 | 627 |
| 628 //////////////////////////////////////////////////////////////////////////////// | 628 //////////////////////////////////////////////////////////////////////////////// |
| 629 // aura::WindowObserver overrides: | 629 // aura::WindowObserver overrides: |
| 630 | 630 |
| 631 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { | 631 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 frame.resource_list.push_back(current_resource_); | 813 frame.resource_list.push_back(current_resource_); |
| 814 } | 814 } |
| 815 } else { | 815 } else { |
| 816 cc::SolidColorDrawQuad* solid_quad = | 816 cc::SolidColorDrawQuad* solid_quad = |
| 817 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); | 817 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); |
| 818 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); | 818 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); |
| 819 } | 819 } |
| 820 | 820 |
| 821 frame.render_pass_list.push_back(std::move(render_pass)); | 821 frame.render_pass_list.push_back(std::move(render_pass)); |
| 822 compositor_frame_sink_holder_->GetCompositorFrameSink() | 822 compositor_frame_sink_holder_->GetCompositorFrameSink() |
| 823 ->SubmitCompositorFrame(local_frame_id_, std::move(frame)); | 823 ->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 824 } | 824 } |
| 825 | 825 |
| 826 int64_t Surface::SetPropertyInternal(const void* key, | 826 int64_t Surface::SetPropertyInternal(const void* key, |
| 827 const char* name, | 827 const char* name, |
| 828 PropertyDeallocator deallocator, | 828 PropertyDeallocator deallocator, |
| 829 int64_t value, | 829 int64_t value, |
| 830 int64_t default_value) { | 830 int64_t default_value) { |
| 831 int64_t old = GetPropertyInternal(key, default_value); | 831 int64_t old = GetPropertyInternal(key, default_value); |
| 832 if (value == default_value) { | 832 if (value == default_value) { |
| 833 prop_map_.erase(key); | 833 prop_map_.erase(key); |
| 834 } else { | 834 } else { |
| 835 Value prop_value; | 835 Value prop_value; |
| 836 prop_value.name = name; | 836 prop_value.name = name; |
| 837 prop_value.value = value; | 837 prop_value.value = value; |
| 838 prop_value.deallocator = deallocator; | 838 prop_value.deallocator = deallocator; |
| 839 prop_map_[key] = prop_value; | 839 prop_map_[key] = prop_value; |
| 840 } | 840 } |
| 841 return old; | 841 return old; |
| 842 } | 842 } |
| 843 | 843 |
| 844 int64_t Surface::GetPropertyInternal(const void* key, | 844 int64_t Surface::GetPropertyInternal(const void* key, |
| 845 int64_t default_value) const { | 845 int64_t default_value) const { |
| 846 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); | 846 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); |
| 847 if (iter == prop_map_.end()) | 847 if (iter == prop_map_.end()) |
| 848 return default_value; | 848 return default_value; |
| 849 return iter->second.value; | 849 return iter->second.value; |
| 850 } | 850 } |
| 851 | 851 |
| 852 } // namespace exo | 852 } // namespace exo |
| OLD | NEW |