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

Side by Side Diff: cc/surfaces/surface_manager.cc

Issue 2514033002: Introducing SurfaceReferenceFactory (Closed)
Patch Set: fix 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "cc/surfaces/surface_manager.h" 5 #include "cc/surfaces/surface_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "cc/surfaces/surface.h" 13 #include "cc/surfaces/surface.h"
14 #include "cc/surfaces/surface_factory_client.h" 14 #include "cc/surfaces/surface_factory_client.h"
15 #include "cc/surfaces/surface_id_allocator.h" 15 #include "cc/surfaces/surface_id_allocator.h"
16 16
17 namespace cc { 17 namespace cc {
18 18
19 namespace {
20
21 class SurfaceRef final : public SurfaceRefWithSequence<SurfaceRef> {
Saman Sami 2016/11/30 18:05:52 Move to a separate file and rename?
22 public:
23 SurfaceRef(SurfaceManager* manager,
24 const SurfaceId& surface_id,
25 float scale,
26 const gfx::Size& size);
27 // SurfaceRef(const SurfaceRef&);
28
29 protected:
30 void SatisfySequence(const SurfaceSequence&) override;
31 void RequireSequence(const SurfaceSequence&) override;
32
33 private:
34 SurfaceManager* manager_ = nullptr;
35 };
36
37 SurfaceRef::SurfaceRef(SurfaceManager* manager,
38 const SurfaceId& surface_id,
39 float scale,
40 const gfx::Size& size)
41 : manager_(manager) {
42 SetMetadata(surface_id, scale, size);
Fady Samuel 2016/11/30 19:51:29 Call the base class' constructor instead?
43 }
44
45 // SurfaceRef::SurfaceRef(const SurfaceRef& surface_ref) = default;
46
47 void SurfaceRef::SatisfySequence(const SurfaceSequence& seq) {
48 std::vector<uint32_t> sequences;
49 sequences.push_back(seq.sequence);
50 manager_->DidSatisfySequences(seq.frame_sink_id, &sequences);
51 }
52
53 void SurfaceRef::RequireSequence(const SurfaceSequence& seq) {
54 auto surface = manager_->GetSurfaceForId(id());
55 if (!surface) {
56 LOG(ERROR) << "Attempting to require callback on nonexistent surface";
57 return;
58 }
59 surface->AddDestructionDependency(seq);
60 }
61
62 } // namespace
63
19 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping() 64 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping()
20 : client(nullptr), source(nullptr) {} 65 : client(nullptr), source(nullptr) {}
21 66
22 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping( 67 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping(
23 const FrameSinkSourceMapping& other) = default; 68 const FrameSinkSourceMapping& other) = default;
24 69
25 SurfaceManager::FrameSinkSourceMapping::~FrameSinkSourceMapping() { 70 SurfaceManager::FrameSinkSourceMapping::~FrameSinkSourceMapping() {
26 DCHECK(is_empty()) << "client: " << client 71 DCHECK(is_empty()) << "client: " << client
27 << ", children: " << children.size(); 72 << ", children: " << children.size();
28 } 73 }
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 BeginFrameSource* parent_source = iter->second.source; 458 BeginFrameSource* parent_source = iter->second.source;
414 if (!parent_source) 459 if (!parent_source)
415 return; 460 return;
416 461
417 // TODO(enne): these walks could be done in one step. 462 // TODO(enne): these walks could be done in one step.
418 RecursivelyDetachBeginFrameSource(child_frame_sink_id, parent_source); 463 RecursivelyDetachBeginFrameSource(child_frame_sink_id, parent_source);
419 for (auto source_iter : registered_sources_) 464 for (auto source_iter : registered_sources_)
420 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first); 465 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first);
421 } 466 }
422 467
468 SurfaceRefPtr SurfaceManager::NewSurfaceRef(const SurfaceId& surface_id,
469 float scale,
470 const gfx::Size& size) {
471 return SurfaceRefPtr(new SurfaceRef(this, surface_id, scale, size));
472 }
473
423 Surface* SurfaceManager::GetSurfaceForId(const SurfaceId& surface_id) { 474 Surface* SurfaceManager::GetSurfaceForId(const SurfaceId& surface_id) {
424 DCHECK(thread_checker_.CalledOnValidThread()); 475 DCHECK(thread_checker_.CalledOnValidThread());
425 SurfaceMap::iterator it = surface_map_.find(surface_id); 476 SurfaceMap::iterator it = surface_map_.find(surface_id);
426 if (it == surface_map_.end()) 477 if (it == surface_map_.end())
427 return nullptr; 478 return nullptr;
428 return it->second; 479 return it->second;
429 } 480 }
430 481
431 bool SurfaceManager::SurfaceModified(const SurfaceId& surface_id) { 482 bool SurfaceManager::SurfaceModified(const SurfaceId& surface_id) {
432 CHECK(thread_checker_.CalledOnValidThread()); 483 CHECK(thread_checker_.CalledOnValidThread());
433 bool changed = false; 484 bool changed = false;
434 for (auto& observer : observer_list_) 485 for (auto& observer : observer_list_)
435 observer.OnSurfaceDamaged(surface_id, &changed); 486 observer.OnSurfaceDamaged(surface_id, &changed);
436 return changed; 487 return changed;
437 } 488 }
438 489
439 void SurfaceManager::SurfaceCreated(const SurfaceId& surface_id, 490 void SurfaceManager::SurfaceCreated(const SurfaceId& surface_id,
440 const gfx::Size& frame_size, 491 const gfx::Size& frame_size,
441 float device_scale_factor) { 492 float device_scale_factor) {
442 CHECK(thread_checker_.CalledOnValidThread()); 493 CHECK(thread_checker_.CalledOnValidThread());
443 for (auto& observer : observer_list_) 494 for (auto& observer : observer_list_)
444 observer.OnSurfaceCreated(surface_id, frame_size, device_scale_factor); 495 observer.OnSurfaceCreated(surface_id, frame_size, device_scale_factor);
445 } 496 }
446 497
447 } // namespace cc 498 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698