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

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

Issue 2802023002: Remove SurfaceFactory And SurfaceFactoryClient (Closed)
Patch Set: Address Comments 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 for (ui::LatencyInfo& latency : frame.metadata.latency_info) {
55 if (latency.latency_components().size() > 0) {
56 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT,
57 0, 0);
58 }
59 }
60
61 std::unique_ptr<Surface> surface;
62 bool create_new_surface =
63 (!current_surface_ ||
64 local_surface_id != current_surface_->surface_id().local_surface_id());
65 if (!create_new_surface) {
66 surface = std::move(current_surface_);
67 } else {
68 surface = Create(local_surface_id);
69 }
70 surface->QueueFrame(std::move(frame), callback, will_draw_callback);
71
72 if (current_surface_ && create_new_surface) {
73 surface->SetPreviousFrameSurface(current_surface_.get());
74 Destroy(std::move(current_surface_));
75 }
76 current_surface_ = std::move(surface);
77 }
78
79 void SurfaceFactory::RequestCopyOfSurface(
80 std::unique_ptr<CopyOutputRequest> copy_request) {
81 if (!current_surface_) {
82 copy_request->SendEmptyResult();
83 return;
84 }
85 DCHECK(current_surface_->factory().get() == this);
86 current_surface_->RequestCopyOfOutput(std::move(copy_request));
87 manager_->SurfaceModified(current_surface_->surface_id());
88 }
89
90 void SurfaceFactory::ReceiveFromChild(
91 const TransferableResourceArray& resources) {
92 holder_.ReceiveFromChild(resources);
93 }
94
95 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) {
96 holder_.RefResources(resources);
97 }
98
99 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) {
100 holder_.UnrefResources(resources);
101 }
102
103 void SurfaceFactory::OnSurfaceActivated(Surface* surface) {
104 DCHECK(surface->HasActiveFrame());
105 if (!seen_first_frame_activation_) {
106 seen_first_frame_activation_ = true;
107
108 const CompositorFrame& frame = surface->GetActiveFrame();
109 // CompositorFrames might not be populated with a RenderPass in unit tests.
110 gfx::Size frame_size;
111 if (!frame.render_pass_list.empty())
112 frame_size = frame.render_pass_list.back()->output_rect.size();
113
114 // SurfaceCreated only applies for the first Surface activation. Thus,
115 // SurfaceFactory stops observing new activations after the first one.
116 manager_->SurfaceCreated(SurfaceInfo(
117 surface->surface_id(), frame.metadata.device_scale_factor, frame_size));
118 }
119 // Fire SurfaceCreated first so that a temporary reference is added before it
120 // is potentially transformed into a real reference by the client.
121 client_->ReferencedSurfacesChanged(surface->surface_id().local_surface_id(),
122 surface->active_referenced_surfaces());
123 if (!manager_->SurfaceModified(surface->surface_id())) {
124 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD);
125 surface->RunDrawCallback();
126 }
127 }
128
129 void SurfaceFactory::OnSurfaceDependenciesChanged(
130 Surface* surface,
131 const SurfaceDependencies& added_dependencies,
132 const SurfaceDependencies& removed_dependencies) {}
133
134 void SurfaceFactory::OnSurfaceDiscarded(Surface* surface) {}
135
136 std::unique_ptr<Surface> SurfaceFactory::Create(
137 const LocalSurfaceId& local_surface_id) {
138 seen_first_frame_activation_ = false;
139 std::unique_ptr<Surface> surface =
140 manager_->CreateSurface(weak_factory_.GetWeakPtr(), local_surface_id);
141 surface->AddObserver(this);
142 return surface;
143 }
144
145 void SurfaceFactory::Destroy(std::unique_ptr<Surface> surface) {
146 surface->RemoveObserver(this);
147 manager_->DestroySurface(std::move(surface));
148 }
149
150 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698