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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 if (window->parent()) | 134 if (window->parent()) |
135 aura::Window::ConvertPointToTarget(window->parent(), window, | 135 aura::Window::ConvertPointToTarget(window->parent(), window, |
136 &local_point); | 136 &local_point); |
137 return surface->HitTestRect(gfx::Rect(local_point, gfx::Size(1, 1))); | 137 return surface->HitTestRect(gfx::Rect(local_point, gfx::Size(1, 1))); |
138 } | 138 } |
139 | 139 |
140 private: | 140 private: |
141 DISALLOW_COPY_AND_ASSIGN(CustomWindowTargeter); | 141 DISALLOW_COPY_AND_ASSIGN(CustomWindowTargeter); |
142 }; | 142 }; |
143 | 143 |
144 void SatisfyCallback(cc::SurfaceManager* manager, | 144 void SatisfyCallback(cc::mojom::MojoCompositorFrameSink* compositor_frame_sink, |
145 const cc::SurfaceSequence& sequence) { | 145 const cc::SurfaceSequence& sequence) { |
146 std::vector<uint32_t> sequences; | 146 compositor_frame_sink->Satisfy(sequence); |
147 sequences.push_back(sequence.sequence); | |
148 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences); | |
149 } | 147 } |
150 | 148 |
151 void RequireCallback(cc::SurfaceManager* manager, | 149 void RequireCallback(cc::mojom::MojoCompositorFrameSink* compositor_frame_sink, |
152 const cc::SurfaceId& id, | 150 const cc::SurfaceId& id, |
153 const cc::SurfaceSequence& sequence) { | 151 const cc::SurfaceSequence& sequence) { |
154 cc::Surface* surface = manager->GetSurfaceForId(id); | 152 compositor_frame_sink->Require(id.local_frame_id(), sequence); |
155 if (!surface) { | |
156 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; | |
157 return; | |
158 } | |
159 surface->AddDestructionDependency(sequence); | |
160 } | 153 } |
161 | 154 |
162 } // namespace | 155 } // namespace |
163 | 156 |
164 //////////////////////////////////////////////////////////////////////////////// | 157 //////////////////////////////////////////////////////////////////////////////// |
165 // SurfaceFactoryOwner, public: | |
166 | |
167 SurfaceFactoryOwner::SurfaceFactoryOwner() {} | |
168 | |
169 //////////////////////////////////////////////////////////////////////////////// | |
170 // cc::SurfaceFactoryClient overrides: | |
171 | |
172 void SurfaceFactoryOwner::ReturnResources( | |
173 const cc::ReturnedResourceArray& resources) { | |
174 scoped_refptr<SurfaceFactoryOwner> holder(this); | |
175 for (auto& resource : resources) { | |
176 auto it = release_callbacks_.find(resource.id); | |
177 DCHECK(it != release_callbacks_.end()); | |
178 it->second.second->Run(resource.sync_token, resource.lost); | |
179 release_callbacks_.erase(it); | |
180 } | |
181 } | |
182 | |
183 void SurfaceFactoryOwner::WillDrawSurface(const cc::LocalFrameId& id, | |
184 const gfx::Rect& damage_rect) { | |
185 if (surface_) | |
186 surface_->WillDraw(); | |
187 } | |
188 | |
189 void SurfaceFactoryOwner::SetBeginFrameSource( | |
190 cc::BeginFrameSource* begin_frame_source) { | |
191 if (surface_) | |
192 surface_->SetBeginFrameSource(begin_frame_source); | |
193 } | |
194 | |
195 //////////////////////////////////////////////////////////////////////////////// | |
196 // SurfaceFactoryOwner, private: | |
197 | |
198 SurfaceFactoryOwner::~SurfaceFactoryOwner() { | |
199 if (surface_factory_->manager()) | |
200 surface_factory_->manager()->InvalidateFrameSinkId(frame_sink_id_); | |
201 } | |
202 | |
203 //////////////////////////////////////////////////////////////////////////////// | |
204 // Surface, public: | 158 // Surface, public: |
205 | 159 |
206 Surface::Surface() | 160 Surface::Surface() |
207 : window_(new aura::Window(new CustomWindowDelegate(this))), | 161 : window_(new aura::Window(new CustomWindowDelegate(this))), |
| 162 frame_sink_id_( |
| 163 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId()), |
208 surface_manager_( | 164 surface_manager_( |
209 aura::Env::GetInstance()->context_factory()->GetSurfaceManager()), | 165 aura::Env::GetInstance()->context_factory()->GetSurfaceManager()), |
210 factory_owner_(new SurfaceFactoryOwner) { | 166 weak_ptr_factory_(this) { |
| 167 cc::mojom::MojoCompositorFrameSinkClientPtr pholder; |
| 168 cc::mojom::MojoCompositorFrameSinkPtr mojo_compositor_frame_sink_ptr; |
| 169 cc::mojom::MojoCompositorFrameSinkClientRequest holder_request = |
| 170 mojo::GetProxy(&pholder); |
| 171 CompositorFrameSink::Create(frame_sink_id_, surface_manager_, |
| 172 std::move(pholder), |
| 173 mojo::GetProxy(&mojo_compositor_frame_sink_ptr)); |
| 174 compositor_frame_sink_holder_ = new CompositorFrameSinkHolder( |
| 175 std::move(mojo_compositor_frame_sink_ptr), weak_ptr_factory_.GetWeakPtr(), |
| 176 std::move(holder_request)); |
211 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | 177 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
212 window_->SetName("ExoSurface"); | 178 window_->SetName("ExoSurface"); |
213 window_->SetProperty(kSurfaceKey, this); | 179 window_->SetProperty(kSurfaceKey, this); |
214 window_->Init(ui::LAYER_SOLID_COLOR); | 180 window_->Init(ui::LAYER_SOLID_COLOR); |
215 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); | 181 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); |
216 window_->set_owned_by_parent(false); | 182 window_->set_owned_by_parent(false); |
217 window_->AddObserver(this); | 183 window_->AddObserver(this); |
218 factory_owner_->surface_ = this; | |
219 factory_owner_->frame_sink_id_ = | |
220 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId(); | |
221 factory_owner_->id_allocator_.reset(new cc::SurfaceIdAllocator()); | |
222 surface_manager_->RegisterFrameSinkId(factory_owner_->frame_sink_id_); | |
223 surface_manager_->RegisterSurfaceFactoryClient(factory_owner_->frame_sink_id_, | |
224 factory_owner_.get()); | |
225 factory_owner_->surface_factory_.reset(new cc::SurfaceFactory( | |
226 factory_owner_->frame_sink_id_, surface_manager_, factory_owner_.get())); | |
227 aura::Env::GetInstance()->context_factory()->AddObserver(this); | 184 aura::Env::GetInstance()->context_factory()->AddObserver(this); |
228 } | 185 } |
229 | 186 |
230 Surface::~Surface() { | 187 Surface::~Surface() { |
231 aura::Env::GetInstance()->context_factory()->RemoveObserver(this); | 188 aura::Env::GetInstance()->context_factory()->RemoveObserver(this); |
232 for (SurfaceObserver& observer : observers_) | 189 for (SurfaceObserver& observer : observers_) |
233 observer.OnSurfaceDestroying(this); | 190 observer.OnSurfaceDestroying(this); |
234 | 191 |
235 window_->RemoveObserver(this); | 192 window_->RemoveObserver(this); |
236 window_->layer()->SetShowSolidColorContent(); | 193 window_->layer()->SetShowSolidColorContent(); |
237 | 194 |
238 factory_owner_->surface_ = nullptr; | 195 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); |
| 196 compositor_frame_sink_holder_->ActivateFrameCallbacks(frame_callbacks_); |
| 197 compositor_frame_sink_holder_->CancelFrameCallbacks(); |
239 | 198 |
240 // Call pending frame callbacks with a null frame time to indicate that they | 199 compositor_frame_sink_holder_->EvictFrame(); |
241 // have been cancelled. | |
242 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); | |
243 active_frame_callbacks_.splice(active_frame_callbacks_.end(), | |
244 frame_callbacks_); | |
245 for (const auto& frame_callback : active_frame_callbacks_) | |
246 frame_callback.Run(base::TimeTicks()); | |
247 if (begin_frame_source_ && needs_begin_frame_) | |
248 begin_frame_source_->RemoveObserver(this); | |
249 | |
250 factory_owner_->surface_factory_->EvictSurface(); | |
251 | |
252 surface_manager_->UnregisterSurfaceFactoryClient( | |
253 factory_owner_->frame_sink_id_); | |
254 } | 200 } |
255 | 201 |
256 // static | 202 // static |
257 Surface* Surface::AsSurface(const aura::Window* window) { | 203 Surface* Surface::AsSurface(const aura::Window* window) { |
258 return window->GetProperty(kSurfaceKey); | 204 return window->GetProperty(kSurfaceKey); |
259 } | 205 } |
260 | 206 |
261 cc::SurfaceId Surface::GetSurfaceId() const { | 207 cc::SurfaceId Surface::GetSurfaceId() const { |
262 return cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_); | 208 return cc::SurfaceId(frame_sink_id_, local_frame_id_); |
263 } | 209 } |
264 | 210 |
265 void Surface::Attach(Buffer* buffer) { | 211 void Surface::Attach(Buffer* buffer) { |
266 TRACE_EVENT1("exo", "Surface::Attach", "buffer", | 212 TRACE_EVENT1("exo", "Surface::Attach", "buffer", |
267 buffer ? buffer->GetSize().ToString() : "null"); | 213 buffer ? buffer->GetSize().ToString() : "null"); |
268 | 214 |
269 has_pending_contents_ = true; | 215 has_pending_contents_ = true; |
270 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>()); | 216 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>()); |
271 } | 217 } |
272 | 218 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 has_pending_contents_ = false; | 415 has_pending_contents_ = false; |
470 | 416 |
471 current_buffer_ = std::move(pending_buffer_); | 417 current_buffer_ = std::move(pending_buffer_); |
472 | 418 |
473 UpdateResource(true); | 419 UpdateResource(true); |
474 } | 420 } |
475 | 421 |
476 cc::LocalFrameId old_local_frame_id = local_frame_id_; | 422 cc::LocalFrameId old_local_frame_id = local_frame_id_; |
477 if (needs_commit_to_new_surface_ || !local_frame_id_.is_valid()) { | 423 if (needs_commit_to_new_surface_ || !local_frame_id_.is_valid()) { |
478 needs_commit_to_new_surface_ = false; | 424 needs_commit_to_new_surface_ = false; |
479 local_frame_id_ = factory_owner_->id_allocator_->GenerateId(); | 425 local_frame_id_ = id_allocator_.GenerateId(); |
480 } | 426 } |
481 | 427 |
482 UpdateSurface(true); | 428 UpdateSurface(true); |
483 | 429 |
484 if (old_local_frame_id != local_frame_id_) { | 430 if (old_local_frame_id != local_frame_id_) { |
| 431 needs_commit_to_new_surface_ = false; |
485 float contents_surface_to_layer_scale = 1.0; | 432 float contents_surface_to_layer_scale = 1.0; |
486 // The bounds must be updated before switching to the new surface, because | 433 // The bounds must be updated before switching to the new surface, because |
487 // the layer may be mirrored, in which case a surface change causes the | 434 // the layer may be mirrored, in which case a surface change causes the |
488 // mirror layer to update its surface using the latest bounds. | 435 // mirror layer to update its surface using the latest bounds. |
489 window_->layer()->SetBounds( | 436 window_->layer()->SetBounds( |
490 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); | 437 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); |
491 window_->layer()->SetShowSurface( | 438 window_->layer()->SetShowSurface( |
492 cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_), | 439 cc::SurfaceId(frame_sink_id_, local_frame_id_), |
493 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), | 440 base::Bind( |
494 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), | 441 &SatisfyCallback, |
| 442 base::Unretained( |
| 443 compositor_frame_sink_holder_->GetCompositorFrameSink())), |
| 444 base::Bind( |
| 445 &RequireCallback, |
| 446 base::Unretained( |
| 447 compositor_frame_sink_holder_->GetCompositorFrameSink())), |
495 content_size_, contents_surface_to_layer_scale, content_size_); | 448 content_size_, contents_surface_to_layer_scale, content_size_); |
496 window_->layer()->SetFillsBoundsOpaquely( | 449 window_->layer()->SetFillsBoundsOpaquely( |
497 state_.blend_mode == SkBlendMode::kSrc || | 450 state_.blend_mode == SkBlendMode::kSrc || |
498 state_.opaque_region.contains( | 451 state_.opaque_region.contains( |
499 gfx::RectToSkIRect(gfx::Rect(content_size_)))); | 452 gfx::RectToSkIRect(gfx::Rect(content_size_)))); |
500 } | 453 } |
501 | 454 |
502 // Reset damage. | 455 // Reset damage. |
503 pending_damage_.setEmpty(); | 456 pending_damage_.setEmpty(); |
504 | 457 |
505 DCHECK(!current_resource_.id || | 458 DCHECK( |
506 factory_owner_->release_callbacks_.count(current_resource_.id)); | 459 !current_resource_.id || |
| 460 compositor_frame_sink_holder_->HasReleaseCallbacks(current_resource_.id)); |
507 | 461 |
508 // Move pending frame callbacks to the end of frame_callbacks_. | 462 // Move pending frame callbacks to the end of frame_callbacks_. |
509 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); | 463 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); |
510 | 464 |
511 // Synchronize window hierarchy. This will position and update the stacking | 465 // Synchronize window hierarchy. This will position and update the stacking |
512 // order of all sub-surfaces after committing all pending state of sub-surface | 466 // order of all sub-surfaces after committing all pending state of sub-surface |
513 // descendants. | 467 // descendants. |
514 aura::Window* stacking_target = nullptr; | 468 aura::Window* stacking_target = nullptr; |
515 for (auto& sub_surface_entry : pending_sub_surfaces_) { | 469 for (auto& sub_surface_entry : pending_sub_surfaces_) { |
516 Surface* sub_surface = sub_surface_entry.first; | 470 Surface* sub_surface = sub_surface_entry.first; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 } | 555 } |
602 | 556 |
603 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const { | 557 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const { |
604 std::unique_ptr<base::trace_event::TracedValue> value( | 558 std::unique_ptr<base::trace_event::TracedValue> value( |
605 new base::trace_event::TracedValue()); | 559 new base::trace_event::TracedValue()); |
606 value->SetString("name", window_->layer()->name()); | 560 value->SetString("name", window_->layer()->name()); |
607 return value; | 561 return value; |
608 } | 562 } |
609 | 563 |
610 void Surface::WillDraw() { | 564 void Surface::WillDraw() { |
611 active_frame_callbacks_.splice(active_frame_callbacks_.end(), | 565 compositor_frame_sink_holder_->ActivateFrameCallbacks(frame_callbacks_); |
612 frame_callbacks_); | |
613 UpdateNeedsBeginFrame(); | |
614 } | |
615 | |
616 void Surface::SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) { | |
617 if (begin_frame_source_ && needs_begin_frame_) { | |
618 begin_frame_source_->RemoveObserver(this); | |
619 needs_begin_frame_ = false; | |
620 } | |
621 begin_frame_source_ = begin_frame_source; | |
622 UpdateNeedsBeginFrame(); | |
623 } | 566 } |
624 | 567 |
625 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { | 568 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { |
626 if (HasLayerHierarchyChanged()) | 569 if (HasLayerHierarchyChanged()) |
627 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); | 570 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); |
628 } | 571 } |
629 | 572 |
630 void Surface::OnLostResources() { | 573 void Surface::OnLostResources() { |
631 if (!local_frame_id_.is_valid()) | 574 if (!local_frame_id_.is_valid()) |
632 return; | 575 return; |
633 | 576 |
634 UpdateResource(false); | 577 UpdateResource(false); |
635 UpdateSurface(false); | 578 UpdateSurface(false); |
636 } | 579 } |
637 | 580 |
638 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { | 581 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { |
639 window->layer()->GetCompositor()->AddFrameSink( | 582 window->layer()->GetCompositor()->AddFrameSink(frame_sink_id_); |
640 factory_owner_->frame_sink_id_); | |
641 } | 583 } |
642 | 584 |
643 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, | 585 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, |
644 aura::Window* new_root) { | 586 aura::Window* new_root) { |
645 window->layer()->GetCompositor()->RemoveFrameSink( | 587 window->layer()->GetCompositor()->RemoveFrameSink(frame_sink_id_); |
646 factory_owner_->frame_sink_id_); | |
647 } | |
648 | |
649 void Surface::OnBeginFrame(const cc::BeginFrameArgs& args) { | |
650 while (!active_frame_callbacks_.empty()) { | |
651 active_frame_callbacks_.front().Run(args.frame_time); | |
652 active_frame_callbacks_.pop_front(); | |
653 } | |
654 last_begin_frame_args_ = args; | |
655 } | |
656 | |
657 const cc::BeginFrameArgs& Surface::LastUsedBeginFrameArgs() const { | |
658 return last_begin_frame_args_; | |
659 } | 588 } |
660 | 589 |
661 Surface::State::State() : input_region(SkIRect::MakeLargest()) {} | 590 Surface::State::State() : input_region(SkIRect::MakeLargest()) {} |
662 | 591 |
663 Surface::State::~State() = default; | 592 Surface::State::~State() = default; |
664 | 593 |
665 bool Surface::State::operator==(const State& other) { | 594 bool Surface::State::operator==(const State& other) { |
666 return (other.crop == crop && alpha == other.alpha && | 595 return (other.crop == crop && alpha == other.alpha && |
667 other.blend_mode == blend_mode && other.viewport == viewport && | 596 other.blend_mode == blend_mode && other.viewport == viewport && |
668 other.opaque_region == opaque_region && | 597 other.opaque_region == opaque_region && |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 resource.id = next_resource_id_++; | 665 resource.id = next_resource_id_++; |
737 resource.format = cc::RGBA_8888; | 666 resource.format = cc::RGBA_8888; |
738 resource.filter = | 667 resource.filter = |
739 texture_mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR; | 668 texture_mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR; |
740 resource.size = texture_mailbox.size_in_pixels(); | 669 resource.size = texture_mailbox.size_in_pixels(); |
741 resource.mailbox_holder = gpu::MailboxHolder(texture_mailbox.mailbox(), | 670 resource.mailbox_holder = gpu::MailboxHolder(texture_mailbox.mailbox(), |
742 texture_mailbox.sync_token(), | 671 texture_mailbox.sync_token(), |
743 texture_mailbox.target()); | 672 texture_mailbox.target()); |
744 resource.is_overlay_candidate = texture_mailbox.is_overlay_candidate(); | 673 resource.is_overlay_candidate = texture_mailbox.is_overlay_candidate(); |
745 | 674 |
746 factory_owner_->release_callbacks_[resource.id] = std::make_pair( | 675 compositor_frame_sink_holder_->AddResourceReleaseCallback( |
747 factory_owner_, std::move(texture_mailbox_release_callback)); | 676 resource.id, std::move(texture_mailbox_release_callback)); |
748 current_resource_ = resource; | 677 current_resource_ = resource; |
749 } else { | 678 } else { |
750 current_resource_.id = 0; | 679 current_resource_.id = 0; |
751 current_resource_.size = gfx::Size(); | 680 current_resource_.size = gfx::Size(); |
752 } | 681 } |
753 } | 682 } |
754 | 683 |
755 void Surface::UpdateSurface(bool full_damage) { | 684 void Surface::UpdateSurface(bool full_damage) { |
756 gfx::Size buffer_size = current_resource_.size; | 685 gfx::Size buffer_size = current_resource_.size; |
757 gfx::SizeF scaled_buffer_size( | 686 gfx::SizeF scaled_buffer_size( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 texture_quad->set_resource_size_in_pixels(current_resource_.size); | 755 texture_quad->set_resource_size_in_pixels(current_resource_.size); |
827 frame.resource_list.push_back(current_resource_); | 756 frame.resource_list.push_back(current_resource_); |
828 } | 757 } |
829 } else { | 758 } else { |
830 cc::SolidColorDrawQuad* solid_quad = | 759 cc::SolidColorDrawQuad* solid_quad = |
831 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); | 760 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); |
832 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); | 761 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); |
833 } | 762 } |
834 | 763 |
835 frame.render_pass_list.push_back(std::move(render_pass)); | 764 frame.render_pass_list.push_back(std::move(render_pass)); |
836 | 765 compositor_frame_sink_holder_->SubmitCompositorFrame(local_frame_id_, |
837 factory_owner_->surface_factory_->SubmitCompositorFrame( | 766 std::move(frame)); |
838 local_frame_id_, std::move(frame), cc::SurfaceFactory::DrawCallback()); | |
839 } | |
840 | |
841 void Surface::UpdateNeedsBeginFrame() { | |
842 if (!begin_frame_source_) | |
843 return; | |
844 | |
845 bool needs_begin_frame = !active_frame_callbacks_.empty(); | |
846 if (needs_begin_frame == needs_begin_frame_) | |
847 return; | |
848 | |
849 needs_begin_frame_ = needs_begin_frame; | |
850 if (needs_begin_frame) | |
851 begin_frame_source_->AddObserver(this); | |
852 else | |
853 begin_frame_source_->RemoveObserver(this); | |
854 } | 767 } |
855 | 768 |
856 int64_t Surface::SetPropertyInternal(const void* key, | 769 int64_t Surface::SetPropertyInternal(const void* key, |
857 const char* name, | 770 const char* name, |
858 PropertyDeallocator deallocator, | 771 PropertyDeallocator deallocator, |
859 int64_t value, | 772 int64_t value, |
860 int64_t default_value) { | 773 int64_t default_value) { |
861 int64_t old = GetPropertyInternal(key, default_value); | 774 int64_t old = GetPropertyInternal(key, default_value); |
862 if (value == default_value) { | 775 if (value == default_value) { |
863 prop_map_.erase(key); | 776 prop_map_.erase(key); |
864 } else { | 777 } else { |
865 Value prop_value; | 778 Value prop_value; |
866 prop_value.name = name; | 779 prop_value.name = name; |
867 prop_value.value = value; | 780 prop_value.value = value; |
868 prop_value.deallocator = deallocator; | 781 prop_value.deallocator = deallocator; |
869 prop_map_[key] = prop_value; | 782 prop_map_[key] = prop_value; |
870 } | 783 } |
871 return old; | 784 return old; |
872 } | 785 } |
873 | 786 |
874 int64_t Surface::GetPropertyInternal(const void* key, | 787 int64_t Surface::GetPropertyInternal(const void* key, |
875 int64_t default_value) const { | 788 int64_t default_value) const { |
876 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); | 789 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); |
877 if (iter == prop_map_.end()) | 790 if (iter == prop_map_.end()) |
878 return default_value; | 791 return default_value; |
879 return iter->second.value; | 792 return iter->second.value; |
880 } | 793 } |
881 | 794 |
882 } // namespace exo | 795 } // namespace exo |
OLD | NEW |