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

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

Issue 2802023002: Remove SurfaceFactory And SurfaceFactoryClient (Closed)
Patch Set: Address nits and rebase Created 3 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/surfaces/surface_factory.h"
6
7 #include <utility>
8
9 #include "base/memory/ptr_util.h"
10 #include "base/trace_event/trace_event.h"
11 #include "cc/output/compositor_frame.h"
12 #include "cc/output/copy_output_request.h"
13 #include "cc/surfaces/surface.h"
14 #include "cc/surfaces/surface_factory_client.h"
15 #include "cc/surfaces/surface_info.h"
16 #include "cc/surfaces/surface_manager.h"
17 #include "ui/gfx/geometry/size.h"
18
19 namespace cc {
20 SurfaceFactory::SurfaceFactory(
21 const FrameSinkId& frame_sink_id,
22 SurfaceManager* manager,
23 SurfaceFactoryClient* client,
24 SurfaceResourceHolderClient* resource_holder_client)
25 : frame_sink_id_(frame_sink_id),
26 manager_(manager),
27 client_(client),
28 holder_(resource_holder_client),
29 needs_sync_points_(true),
30 weak_factory_(this) {}
31
32 SurfaceFactory::~SurfaceFactory() {
33 // This is to prevent troubles when a factory that resides in a client is
34 // being destroyed. In such cases, the factory might attempt to return
35 // resources to the client while it's in the middle of destruction and this
36 // could cause a crash or some unexpected behaviour.
37 DCHECK(!current_surface_) << "Please call EvictSurface before destruction";
38 }
39
40 void SurfaceFactory::EvictSurface() {
41 if (!current_surface_)
42 return;
43 Destroy(std::move(current_surface_));
44 }
45
46 void SurfaceFactory::SubmitCompositorFrame(
47 const LocalSurfaceId& local_surface_id,
48 CompositorFrame frame,
49 const DrawCallback& callback,
50 const WillDrawCallback& will_draw_callback) {
51 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame");
52 DCHECK(local_surface_id.is_valid());
53
54 if (!ui::LatencyInfo::Verify(frame.metadata.latency_info,
55 "RenderWidgetHostImpl::OnSwapCompositorFrame")) {
56 std::vector<ui::LatencyInfo>().swap(frame.metadata.latency_info);
57 }
58
59 for (ui::LatencyInfo& latency : frame.metadata.latency_info) {
60 if (latency.latency_components().size() > 0) {
61 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT,
62 0, 0);
63 }
64 }
65
66 std::unique_ptr<Surface> surface;
67 bool create_new_surface =
68 (!current_surface_ ||
69 local_surface_id != current_surface_->surface_id().local_surface_id());
70 if (!create_new_surface) {
71 surface = std::move(current_surface_);
72 } else {
73 surface = Create(local_surface_id);
74 }
75 surface->QueueFrame(std::move(frame), callback, will_draw_callback);
76
77 if (current_surface_ && create_new_surface) {
78 surface->SetPreviousFrameSurface(current_surface_.get());
79 Destroy(std::move(current_surface_));
80 }
81 current_surface_ = std::move(surface);
82 }
83
84 void SurfaceFactory::RequestCopyOfSurface(
85 std::unique_ptr<CopyOutputRequest> copy_request) {
86 if (!current_surface_) {
87 copy_request->SendEmptyResult();
88 return;
89 }
90 DCHECK(current_surface_->factory().get() == this);
91 current_surface_->RequestCopyOfOutput(std::move(copy_request));
92 manager_->SurfaceModified(current_surface_->surface_id());
93 }
94
95 void SurfaceFactory::ReceiveFromChild(
96 const TransferableResourceArray& resources) {
97 holder_.ReceiveFromChild(resources);
98 }
99
100 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) {
101 holder_.RefResources(resources);
102 }
103
104 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) {
105 holder_.UnrefResources(resources);
106 }
107
108 void SurfaceFactory::OnSurfaceActivated(Surface* surface) {
109 DCHECK(surface->HasActiveFrame());
110 if (!seen_first_frame_activation_) {
111 seen_first_frame_activation_ = true;
112
113 const CompositorFrame& frame = surface->GetActiveFrame();
114 // CompositorFrames might not be populated with a RenderPass in unit tests.
115 gfx::Size frame_size;
116 if (!frame.render_pass_list.empty())
117 frame_size = frame.render_pass_list.back()->output_rect.size();
118
119 // SurfaceCreated only applies for the first Surface activation. Thus,
120 // SurfaceFactory stops observing new activations after the first one.
121 manager_->SurfaceCreated(SurfaceInfo(
122 surface->surface_id(), frame.metadata.device_scale_factor, frame_size));
123 }
124 // Fire SurfaceCreated first so that a temporary reference is added before it
125 // is potentially transformed into a real reference by the client.
126 client_->ReferencedSurfacesChanged(surface->surface_id().local_surface_id(),
127 surface->active_referenced_surfaces());
128 if (!manager_->SurfaceModified(surface->surface_id())) {
129 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD);
130 surface->RunDrawCallback();
131 }
132 }
133
134 void SurfaceFactory::OnSurfaceDependenciesChanged(
135 Surface* surface,
136 const base::flat_set<SurfaceId>& added_dependencies,
137 const base::flat_set<SurfaceId>& removed_dependencies) {}
138
139 void SurfaceFactory::OnSurfaceDiscarded(Surface* surface) {}
140
141 std::unique_ptr<Surface> SurfaceFactory::Create(
142 const LocalSurfaceId& local_surface_id) {
143 seen_first_frame_activation_ = false;
144 std::unique_ptr<Surface> surface =
145 manager_->CreateSurface(weak_factory_.GetWeakPtr(), local_surface_id);
146 surface->AddObserver(this);
147 return surface;
148 }
149
150 void SurfaceFactory::Destroy(std::unique_ptr<Surface> surface) {
151 surface->RemoveObserver(this);
152 manager_->DestroySurface(std::move(surface));
153 }
154
155 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698