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

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

Issue 2582823002: WIP: Surface Synchronization System
Patch Set: Only create ClientSurfaceEmbedder if window is visible. Trash it otherwise. Created 3 years, 11 months 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_factory.h" 5 #include "cc/surfaces/surface_factory.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); 57 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame");
58 DCHECK(local_frame_id.is_valid()); 58 DCHECK(local_frame_id.is_valid());
59 std::unique_ptr<Surface> surface; 59 std::unique_ptr<Surface> surface;
60 bool create_new_surface = 60 bool create_new_surface =
61 (!current_surface_ || 61 (!current_surface_ ||
62 local_frame_id != current_surface_->surface_id().local_frame_id()); 62 local_frame_id != current_surface_->surface_id().local_frame_id());
63 if (!create_new_surface) { 63 if (!create_new_surface) {
64 surface = std::move(current_surface_); 64 surface = std::move(current_surface_);
65 } else { 65 } else {
66 surface = Create(local_frame_id); 66 surface = Create(local_frame_id);
67 gfx::Size frame_size;
68 // CompositorFrames may not be populated with a RenderPass in unit tests.
69 if (!frame.render_pass_list.empty())
70 frame_size = frame.render_pass_list.back()->output_rect.size();
71 manager_->SurfaceCreated(SurfaceInfo(
72 surface->surface_id(), frame.metadata.device_scale_factor, frame_size));
73 } 67 }
74 surface->QueueFrame(std::move(frame), callback); 68 surface->QueueFrame(std::move(frame), callback);
69
70 // Ask the surface manager to resolve the surface if it has a pending frame.
71 if (surface->GetPendingFrame().has_value())
72 manager_->RequestSurfaceResolution(surface.get());
73
75 if (!manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id))) { 74 if (!manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id))) {
76 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); 75 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD);
77 surface->RunDrawCallbacks(); 76 surface->RunDrawCallbacks();
78 } 77 }
79 if (current_surface_ && create_new_surface) { 78 if (current_surface_ && create_new_surface) {
80 surface->SetPreviousFrameSurface(current_surface_.get()); 79 surface->SetPreviousFrameSurface(current_surface_.get());
81 Destroy(std::move(current_surface_)); 80 Destroy(std::move(current_surface_));
82 } 81 }
83 current_surface_ = std::move(surface); 82 current_surface_ = std::move(surface);
84 } 83 }
(...skipping 27 matching lines...) Expand all
112 } 111 }
113 112
114 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { 113 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) {
115 holder_.RefResources(resources); 114 holder_.RefResources(resources);
116 } 115 }
117 116
118 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { 117 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) {
119 holder_.UnrefResources(resources); 118 holder_.UnrefResources(resources);
120 } 119 }
121 120
121 void SurfaceFactory::OnSurfaceActivated(Surface* surface) {
122 gfx::Size frame_size;
123 // CompositorFrames may not be populated with a RenderPass in unit tests.
124 const CompositorFrame& frame = surface->GetEligibleFrame();
125 if (!frame.render_pass_list.empty())
126 frame_size = frame.render_pass_list.back()->output_rect.size();
127
128 manager_->SurfaceCreated(SurfaceInfo(
129 surface->surface_id(), frame.metadata.device_scale_factor, frame_size));
130 fprintf(stderr, ">>>SurfaceFactory::OnSurfaeActivated :%s\n",
131 surface->surface_id().ToString().c_str());
132 surface->RemoveObserver(this);
133 }
134
135 void SurfaceFactory::OnSurfaceChanged(
136 Surface* pending_surface,
137 const SurfaceDependencies& added_dependencies,
138 const SurfaceDependencies& removed_dependencies) {}
139
140 void SurfaceFactory::OnSurfaceDiscarded(Surface* pending_surface) {}
141
122 std::unique_ptr<Surface> SurfaceFactory::Create( 142 std::unique_ptr<Surface> SurfaceFactory::Create(
123 const LocalFrameId& local_frame_id) { 143 const LocalFrameId& local_frame_id) {
124 auto surface = base::MakeUnique<Surface>( 144 auto surface = base::MakeUnique<Surface>(
125 SurfaceId(frame_sink_id_, local_frame_id), weak_factory_.GetWeakPtr()); 145 SurfaceId(frame_sink_id_, local_frame_id), weak_factory_.GetWeakPtr());
126 manager_->RegisterSurface(surface.get()); 146 manager_->RegisterSurface(surface.get());
147 surface->AddObserver(this);
127 return surface; 148 return surface;
128 } 149 }
129 150
130 void SurfaceFactory::Destroy(std::unique_ptr<Surface> surface) { 151 void SurfaceFactory::Destroy(std::unique_ptr<Surface> surface) {
152 surface->RemoveObserver(this);
131 if (manager_) 153 if (manager_)
132 manager_->Destroy(std::move(surface)); 154 manager_->Destroy(std::move(surface));
133 } 155 }
134 156
135 } // namespace cc 157 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698