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

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

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

Powered by Google App Engine
This is Rietveld 408576698