Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1388)

Side by Side Diff: components/exo/surface.cc

Issue 2493223002: Change exo::SurfaceFactoryOwner to exo::ExoCompositorFrameSink (Closed)
Patch Set: Override DesktopMediaListAshTest::TearDown() to reset list_ Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/exo/surface.h ('k') | components/exo/surface_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 #include "base/trace_event/trace_event_argument.h" 14 #include "base/trace_event/trace_event_argument.h"
15 #include "cc/quads/render_pass.h" 15 #include "cc/quads/render_pass.h"
16 #include "cc/quads/shared_quad_state.h" 16 #include "cc/quads/shared_quad_state.h"
17 #include "cc/quads/solid_color_draw_quad.h" 17 #include "cc/quads/solid_color_draw_quad.h"
18 #include "cc/quads/texture_draw_quad.h" 18 #include "cc/quads/texture_draw_quad.h"
19 #include "cc/resources/single_release_callback.h" 19 #include "cc/resources/single_release_callback.h"
20 #include "cc/surfaces/surface.h" 20 #include "cc/surfaces/surface.h"
21 #include "cc/surfaces/surface_factory.h"
22 #include "cc/surfaces/surface_id_allocator.h" 21 #include "cc/surfaces/surface_id_allocator.h"
23 #include "cc/surfaces/surface_manager.h"
24 #include "components/exo/buffer.h" 22 #include "components/exo/buffer.h"
25 #include "components/exo/surface_delegate.h" 23 #include "components/exo/surface_delegate.h"
26 #include "components/exo/surface_observer.h" 24 #include "components/exo/surface_observer.h"
27 #include "third_party/khronos/GLES2/gl2.h" 25 #include "third_party/khronos/GLES2/gl2.h"
28 #include "ui/aura/env.h" 26 #include "ui/aura/env.h"
29 #include "ui/aura/window_delegate.h" 27 #include "ui/aura/window_delegate.h"
30 #include "ui/aura/window_property.h" 28 #include "ui/aura/window_property.h"
31 #include "ui/aura/window_targeter.h" 29 #include "ui/aura/window_targeter.h"
32 #include "ui/base/cursor/cursor.h" 30 #include "ui/base/cursor/cursor.h"
33 #include "ui/base/hit_test.h" 31 #include "ui/base/hit_test.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 if (window->parent()) 132 if (window->parent())
135 aura::Window::ConvertPointToTarget(window->parent(), window, 133 aura::Window::ConvertPointToTarget(window->parent(), window,
136 &local_point); 134 &local_point);
137 return surface->HitTestRect(gfx::Rect(local_point, gfx::Size(1, 1))); 135 return surface->HitTestRect(gfx::Rect(local_point, gfx::Size(1, 1)));
138 } 136 }
139 137
140 private: 138 private:
141 DISALLOW_COPY_AND_ASSIGN(CustomWindowTargeter); 139 DISALLOW_COPY_AND_ASSIGN(CustomWindowTargeter);
142 }; 140 };
143 141
144 void SatisfyCallback(cc::SurfaceManager* manager,
145 const cc::SurfaceSequence& sequence) {
146 std::vector<uint32_t> sequences;
147 sequences.push_back(sequence.sequence);
148 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences);
149 }
150
151 void RequireCallback(cc::SurfaceManager* manager,
152 const cc::SurfaceId& id,
153 const cc::SurfaceSequence& sequence) {
154 cc::Surface* surface = manager->GetSurfaceForId(id);
155 if (!surface) {
156 LOG(ERROR) << "Attempting to require callback on nonexistent surface";
157 return;
158 }
159 surface->AddDestructionDependency(sequence);
160 }
161
162 } // namespace 142 } // namespace
163 143
164 //////////////////////////////////////////////////////////////////////////////// 144 ////////////////////////////////////////////////////////////////////////////////
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: 145 // Surface, public:
205 146
206 Surface::Surface() 147 Surface::Surface()
207 : window_(new aura::Window(new CustomWindowDelegate(this))), 148 : window_(new aura::Window(new CustomWindowDelegate(this))),
208 surface_manager_( 149 frame_sink_id_(
209 aura::Env::GetInstance()->context_factory()->GetSurfaceManager()), 150 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId()) {
210 factory_owner_(new SurfaceFactoryOwner) { 151 cc::mojom::MojoCompositorFrameSinkClientPtr frame_sink_holder_ptr;
152 cc::mojom::MojoCompositorFrameSinkClientRequest frame_sink_client_request =
153 mojo::GetProxy(&frame_sink_holder_ptr);
154 std::unique_ptr<CompositorFrameSink> frame_sink(new CompositorFrameSink(
155 frame_sink_id_,
156 aura::Env::GetInstance()->context_factory()->GetSurfaceManager(),
157 std::move(frame_sink_holder_ptr)));
158 compositor_frame_sink_holder_ = new CompositorFrameSinkHolder(
159 this, std::move(frame_sink), std::move(frame_sink_client_request));
211 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); 160 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
212 window_->SetName("ExoSurface"); 161 window_->SetName("ExoSurface");
213 window_->SetProperty(kSurfaceKey, this); 162 window_->SetProperty(kSurfaceKey, this);
214 window_->Init(ui::LAYER_SOLID_COLOR); 163 window_->Init(ui::LAYER_SOLID_COLOR);
215 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); 164 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter));
216 window_->set_owned_by_parent(false); 165 window_->set_owned_by_parent(false);
217 window_->AddObserver(this); 166 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); 167 aura::Env::GetInstance()->context_factory()->AddObserver(this);
228 } 168 }
229 169
230 Surface::~Surface() { 170 Surface::~Surface() {
231 aura::Env::GetInstance()->context_factory()->RemoveObserver(this); 171 aura::Env::GetInstance()->context_factory()->RemoveObserver(this);
232 for (SurfaceObserver& observer : observers_) 172 for (SurfaceObserver& observer : observers_)
233 observer.OnSurfaceDestroying(this); 173 observer.OnSurfaceDestroying(this);
234 174
235 window_->RemoveObserver(this); 175 window_->RemoveObserver(this);
236 window_->layer()->SetShowSolidColorContent(); 176 window_->layer()->SetShowSolidColorContent();
237 177
238 factory_owner_->surface_ = nullptr; 178 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
179 compositor_frame_sink_holder_->ActivateFrameCallbacks(&frame_callbacks_);
180 compositor_frame_sink_holder_->CancelFrameCallbacks();
239 181
240 // Call pending frame callbacks with a null frame time to indicate that they 182 compositor_frame_sink_holder_->GetCompositorFrameSink()->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 } 183 }
255 184
256 // static 185 // static
257 Surface* Surface::AsSurface(const aura::Window* window) { 186 Surface* Surface::AsSurface(const aura::Window* window) {
258 return window->GetProperty(kSurfaceKey); 187 return window->GetProperty(kSurfaceKey);
259 } 188 }
260 189
261 cc::SurfaceId Surface::GetSurfaceId() const { 190 cc::SurfaceId Surface::GetSurfaceId() const {
262 return cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_); 191 return cc::SurfaceId(frame_sink_id_, local_frame_id_);
263 } 192 }
264 193
265 void Surface::Attach(Buffer* buffer) { 194 void Surface::Attach(Buffer* buffer) {
266 TRACE_EVENT1("exo", "Surface::Attach", "buffer", 195 TRACE_EVENT1("exo", "Surface::Attach", "buffer",
267 buffer ? buffer->GetSize().ToString() : "null"); 196 buffer ? buffer->GetSize().ToString() : "null");
268 197
269 has_pending_contents_ = true; 198 has_pending_contents_ = true;
270 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>()); 199 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>());
271 } 200 }
272 201
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 has_pending_contents_ = false; 398 has_pending_contents_ = false;
470 399
471 current_buffer_ = std::move(pending_buffer_); 400 current_buffer_ = std::move(pending_buffer_);
472 401
473 UpdateResource(true); 402 UpdateResource(true);
474 } 403 }
475 404
476 cc::LocalFrameId old_local_frame_id = local_frame_id_; 405 cc::LocalFrameId old_local_frame_id = local_frame_id_;
477 if (needs_commit_to_new_surface_ || !local_frame_id_.is_valid()) { 406 if (needs_commit_to_new_surface_ || !local_frame_id_.is_valid()) {
478 needs_commit_to_new_surface_ = false; 407 needs_commit_to_new_surface_ = false;
479 local_frame_id_ = factory_owner_->id_allocator_->GenerateId(); 408 local_frame_id_ = id_allocator_.GenerateId();
480 } 409 }
481 410
482 UpdateSurface(true); 411 UpdateSurface(true);
483 412
484 if (old_local_frame_id != local_frame_id_) { 413 if (old_local_frame_id != local_frame_id_) {
485 float contents_surface_to_layer_scale = 1.0; 414 float contents_surface_to_layer_scale = 1.0;
486 // The bounds must be updated before switching to the new surface, because 415 // 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 416 // the layer may be mirrored, in which case a surface change causes the
488 // mirror layer to update its surface using the latest bounds. 417 // mirror layer to update its surface using the latest bounds.
489 window_->layer()->SetBounds( 418 window_->layer()->SetBounds(
490 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); 419 gfx::Rect(window_->layer()->bounds().origin(), content_size_));
491 window_->layer()->SetShowSurface( 420 window_->layer()->SetShowSurface(
492 cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_), 421 cc::SurfaceId(frame_sink_id_, local_frame_id_),
493 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), 422 base::Bind(&CompositorFrameSinkHolder::Satisfy,
494 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), 423 compositor_frame_sink_holder_),
424 base::Bind(&CompositorFrameSinkHolder::Require,
425 compositor_frame_sink_holder_),
495 content_size_, contents_surface_to_layer_scale, content_size_); 426 content_size_, contents_surface_to_layer_scale, content_size_);
496 window_->layer()->SetFillsBoundsOpaquely( 427 window_->layer()->SetFillsBoundsOpaquely(
497 state_.blend_mode == SkBlendMode::kSrc || 428 state_.blend_mode == SkBlendMode::kSrc ||
498 state_.opaque_region.contains( 429 state_.opaque_region.contains(
499 gfx::RectToSkIRect(gfx::Rect(content_size_)))); 430 gfx::RectToSkIRect(gfx::Rect(content_size_))));
500 } 431 }
501 432
502 // Reset damage. 433 // Reset damage.
503 pending_damage_.setEmpty(); 434 pending_damage_.setEmpty();
504 435
505 DCHECK(!current_resource_.id || 436 DCHECK(!current_resource_.id ||
506 factory_owner_->release_callbacks_.count(current_resource_.id)); 437 compositor_frame_sink_holder_->HasReleaseCallbackForResource(
438 current_resource_.id));
507 439
508 // Move pending frame callbacks to the end of frame_callbacks_. 440 // Move pending frame callbacks to the end of frame_callbacks_.
509 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); 441 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
510 442
511 // Synchronize window hierarchy. This will position and update the stacking 443 // Synchronize window hierarchy. This will position and update the stacking
512 // order of all sub-surfaces after committing all pending state of sub-surface 444 // order of all sub-surfaces after committing all pending state of sub-surface
513 // descendants. 445 // descendants.
514 aura::Window* stacking_target = nullptr; 446 aura::Window* stacking_target = nullptr;
515 for (auto& sub_surface_entry : pending_sub_surfaces_) { 447 for (auto& sub_surface_entry : pending_sub_surfaces_) {
516 Surface* sub_surface = sub_surface_entry.first; 448 Surface* sub_surface = sub_surface_entry.first;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 } 533 }
602 534
603 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const { 535 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const {
604 std::unique_ptr<base::trace_event::TracedValue> value( 536 std::unique_ptr<base::trace_event::TracedValue> value(
605 new base::trace_event::TracedValue()); 537 new base::trace_event::TracedValue());
606 value->SetString("name", window_->layer()->name()); 538 value->SetString("name", window_->layer()->name());
607 return value; 539 return value;
608 } 540 }
609 541
610 void Surface::WillDraw() { 542 void Surface::WillDraw() {
611 active_frame_callbacks_.splice(active_frame_callbacks_.end(), 543 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 } 544 }
624 545
625 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { 546 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() {
626 if (HasLayerHierarchyChanged()) 547 if (HasLayerHierarchyChanged())
627 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); 548 SetSurfaceHierarchyNeedsCommitToNewSurfaces();
628 } 549 }
629 550
630 void Surface::OnLostResources() { 551 void Surface::OnLostResources() {
631 if (!local_frame_id_.is_valid()) 552 if (!local_frame_id_.is_valid())
632 return; 553 return;
633 554
634 UpdateResource(false); 555 UpdateResource(false);
635 UpdateSurface(false); 556 UpdateSurface(false);
636 } 557 }
637 558
638 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { 559 void Surface::OnWindowAddedToRootWindow(aura::Window* window) {
639 window->layer()->GetCompositor()->AddFrameSink( 560 window->layer()->GetCompositor()->AddFrameSink(frame_sink_id_);
640 factory_owner_->frame_sink_id_);
641 } 561 }
642 562
643 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, 563 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window,
644 aura::Window* new_root) { 564 aura::Window* new_root) {
645 window->layer()->GetCompositor()->RemoveFrameSink( 565 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 } 566 }
660 567
661 Surface::State::State() : input_region(SkIRect::MakeLargest()) {} 568 Surface::State::State() : input_region(SkIRect::MakeLargest()) {}
662 569
663 Surface::State::~State() = default; 570 Surface::State::~State() = default;
664 571
665 bool Surface::State::operator==(const State& other) { 572 bool Surface::State::operator==(const State& other) {
666 return (other.crop == crop && alpha == other.alpha && 573 return (other.crop == crop && alpha == other.alpha &&
667 other.blend_mode == blend_mode && other.viewport == viewport && 574 other.blend_mode == blend_mode && other.viewport == viewport &&
668 other.opaque_region == opaque_region && 575 other.opaque_region == opaque_region &&
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 resource.id = next_resource_id_++; 643 resource.id = next_resource_id_++;
737 resource.format = cc::RGBA_8888; 644 resource.format = cc::RGBA_8888;
738 resource.filter = 645 resource.filter =
739 texture_mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR; 646 texture_mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR;
740 resource.size = texture_mailbox.size_in_pixels(); 647 resource.size = texture_mailbox.size_in_pixels();
741 resource.mailbox_holder = gpu::MailboxHolder(texture_mailbox.mailbox(), 648 resource.mailbox_holder = gpu::MailboxHolder(texture_mailbox.mailbox(),
742 texture_mailbox.sync_token(), 649 texture_mailbox.sync_token(),
743 texture_mailbox.target()); 650 texture_mailbox.target());
744 resource.is_overlay_candidate = texture_mailbox.is_overlay_candidate(); 651 resource.is_overlay_candidate = texture_mailbox.is_overlay_candidate();
745 652
746 factory_owner_->release_callbacks_[resource.id] = std::make_pair( 653 compositor_frame_sink_holder_->AddResourceReleaseCallback(
747 factory_owner_, std::move(texture_mailbox_release_callback)); 654 resource.id, std::move(texture_mailbox_release_callback));
748 current_resource_ = resource; 655 current_resource_ = resource;
749 } else { 656 } else {
750 current_resource_.id = 0; 657 current_resource_.id = 0;
751 current_resource_.size = gfx::Size(); 658 current_resource_.size = gfx::Size();
752 } 659 }
753 } 660 }
754 661
755 void Surface::UpdateSurface(bool full_damage) { 662 void Surface::UpdateSurface(bool full_damage) {
756 gfx::Size buffer_size = current_resource_.size; 663 gfx::Size buffer_size = current_resource_.size;
757 gfx::SizeF scaled_buffer_size( 664 gfx::SizeF scaled_buffer_size(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 texture_quad->set_resource_size_in_pixels(current_resource_.size); 734 texture_quad->set_resource_size_in_pixels(current_resource_.size);
828 frame.resource_list.push_back(current_resource_); 735 frame.resource_list.push_back(current_resource_);
829 } 736 }
830 } else { 737 } else {
831 cc::SolidColorDrawQuad* solid_quad = 738 cc::SolidColorDrawQuad* solid_quad =
832 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); 739 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>();
833 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); 740 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false);
834 } 741 }
835 742
836 frame.render_pass_list.push_back(std::move(render_pass)); 743 frame.render_pass_list.push_back(std::move(render_pass));
837 744 compositor_frame_sink_holder_->GetCompositorFrameSink()
838 factory_owner_->surface_factory_->SubmitCompositorFrame( 745 ->SubmitCompositorFrame(local_frame_id_, std::move(frame));
839 local_frame_id_, std::move(frame), cc::SurfaceFactory::DrawCallback());
840 }
841
842 void Surface::UpdateNeedsBeginFrame() {
843 if (!begin_frame_source_)
844 return;
845
846 bool needs_begin_frame = !active_frame_callbacks_.empty();
847 if (needs_begin_frame == needs_begin_frame_)
848 return;
849
850 needs_begin_frame_ = needs_begin_frame;
851 if (needs_begin_frame)
852 begin_frame_source_->AddObserver(this);
853 else
854 begin_frame_source_->RemoveObserver(this);
855 } 746 }
856 747
857 int64_t Surface::SetPropertyInternal(const void* key, 748 int64_t Surface::SetPropertyInternal(const void* key,
858 const char* name, 749 const char* name,
859 PropertyDeallocator deallocator, 750 PropertyDeallocator deallocator,
860 int64_t value, 751 int64_t value,
861 int64_t default_value) { 752 int64_t default_value) {
862 int64_t old = GetPropertyInternal(key, default_value); 753 int64_t old = GetPropertyInternal(key, default_value);
863 if (value == default_value) { 754 if (value == default_value) {
864 prop_map_.erase(key); 755 prop_map_.erase(key);
865 } else { 756 } else {
866 Value prop_value; 757 Value prop_value;
867 prop_value.name = name; 758 prop_value.name = name;
868 prop_value.value = value; 759 prop_value.value = value;
869 prop_value.deallocator = deallocator; 760 prop_value.deallocator = deallocator;
870 prop_map_[key] = prop_value; 761 prop_map_[key] = prop_value;
871 } 762 }
872 return old; 763 return old;
873 } 764 }
874 765
875 int64_t Surface::GetPropertyInternal(const void* key, 766 int64_t Surface::GetPropertyInternal(const void* key,
876 int64_t default_value) const { 767 int64_t default_value) const {
877 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); 768 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key);
878 if (iter == prop_map_.end()) 769 if (iter == prop_map_.end())
879 return default_value; 770 return default_value;
880 return iter->second.value; 771 return iter->second.value;
881 } 772 }
882 773
883 } // namespace exo 774 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/surface.h ('k') | components/exo/surface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698