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

Unified Diff: cc/surfaces/compositor_frame_sink_support.cc

Issue 2940183002: cc: Move ownership of surfaces to SurfaceManager (Closed)
Patch Set: c Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: cc/surfaces/compositor_frame_sink_support.cc
diff --git a/cc/surfaces/compositor_frame_sink_support.cc b/cc/surfaces/compositor_frame_sink_support.cc
index 89c41bbbf8b352f4fbe6b3156f12b825dce2053b..23820f77075d50ea4c48979ea2e2d7fbfb7880db 100644
--- a/cc/surfaces/compositor_frame_sink_support.cc
+++ b/cc/surfaces/compositor_frame_sink_support.cc
@@ -77,9 +77,10 @@ void CompositorFrameSinkSupport::SetBeginFrameSource(
}
void CompositorFrameSinkSupport::EvictCurrentSurface() {
- if (!current_surface_)
+ Surface* current_surface = GetCurrentSurface();
danakj 2017/06/21 21:24:09 It feels like in general this class is dealing wit
Saman Sami 2017/06/26 20:44:05 I just keep the current SurfaceId and reset it whe
+ if (!current_surface)
return;
- DestroyCurrentSurface();
+ surface_manager_->DestroySurface(current_surface->surface_id());
danakj 2017/06/21 21:24:09 This could take a surface id and just ignore ids t
Saman Sami 2017/06/26 20:44:05 I'll just check current_surface_id_ is valid.
}
void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) {
@@ -96,8 +97,10 @@ void CompositorFrameSinkSupport::DidNotProduceFrame(const BeginFrameAck& ack) {
// |has_damage| is not transmitted, but false by default.
DCHECK(!ack.has_damage);
- if (current_surface_)
- surface_manager_->SurfaceModified(current_surface_->surface_id(), ack);
+ Surface* current_surface = GetCurrentSurface();
+ if (current_surface)
+ surface_manager_->SurfaceModified(current_surface->surface_id(), ack);
danakj 2017/06/21 21:24:09 This could also early out if the surface didn't ex
Saman Sami 2017/06/26 20:44:05 I'll just check current_surface_id_ is valid.
+
if (begin_frame_source_)
begin_frame_source_->DidFinishFrame(this);
}
@@ -127,13 +130,12 @@ bool CompositorFrameSinkSupport::SubmitCompositorFrame(
}
}
- std::unique_ptr<Surface> surface;
- bool create_new_surface =
- (!current_surface_ ||
- local_surface_id != current_surface_->surface_id().local_surface_id());
- if (!create_new_surface) {
- surface = std::move(current_surface_);
- } else {
+ Surface* current_surface = GetCurrentSurface();
+ Surface* prev_surface = current_surface;
+ if (!current_surface ||
+ surface_manager()->IsMarkedForDestruction(
+ current_surface->surface_id()) ||
+ local_surface_id != current_local_surface_id_) {
SurfaceId surface_id(frame_sink_id_, local_surface_id);
gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size();
float device_scale_factor = frame.metadata.device_scale_factor;
@@ -142,8 +144,8 @@ bool CompositorFrameSinkSupport::SubmitCompositorFrame(
if (!surface_info.is_valid()) {
TRACE_EVENT_INSTANT0("cc", "Invalid SurfaceInfo",
TRACE_EVENT_SCOPE_THREAD);
- if (current_surface_)
- DestroyCurrentSurface();
+ if (current_surface)
+ EvictCurrentSurface();
ReturnedResourceArray resources;
TransferableResource::ReturnResources(frame.resource_list, &resources);
ReturnResources(resources);
@@ -151,12 +153,13 @@ bool CompositorFrameSinkSupport::SubmitCompositorFrame(
return true;
}
- surface = CreateSurface(surface_info);
- surface_manager_->SurfaceDamageExpected(surface->surface_id(),
+ current_surface = CreateSurface(surface_info);
+ current_local_surface_id_ = local_surface_id;
+ surface_manager_->SurfaceDamageExpected(current_surface->surface_id(),
last_begin_frame_args_);
}
- bool result = surface->QueueFrame(
+ bool result = current_surface->QueueFrame(
std::move(frame),
base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
weak_factory_.GetWeakPtr()),
@@ -164,15 +167,14 @@ bool CompositorFrameSinkSupport::SubmitCompositorFrame(
weak_factory_.GetWeakPtr()));
if (!result) {
- surface_manager_->DestroySurface(std::move(surface));
+ EvictCurrentSurface();
return false;
}
- if (current_surface_) {
- surface->SetPreviousFrameSurface(current_surface_.get());
- DestroyCurrentSurface();
+ if (prev_surface && prev_surface != current_surface) {
+ current_surface->SetPreviousFrameSurface(prev_surface);
+ surface_manager_->DestroySurface(prev_surface->surface_id());
}
- current_surface_ = std::move(surface);
if (begin_frame_source_)
begin_frame_source_->DidFinishFrame(this);
@@ -288,10 +290,10 @@ void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager) {
void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) {
UpdateNeedsBeginFramesInternal();
- if (current_surface_) {
- surface_manager_->SurfaceDamageExpected(current_surface_->surface_id(),
+ Surface* current_surface = GetCurrentSurface();
+ if (current_surface)
+ surface_manager_->SurfaceDamageExpected(current_surface->surface_id(),
args);
- }
last_begin_frame_args_ = args;
if (client_)
client_->OnBeginFrame(args);
@@ -342,28 +344,29 @@ void CompositorFrameSinkSupport::UpdateNeedsBeginFramesInternal() {
begin_frame_source_->RemoveObserver(this);
}
-std::unique_ptr<Surface> CompositorFrameSinkSupport::CreateSurface(
+Surface* CompositorFrameSinkSupport::CreateSurface(
const SurfaceInfo& surface_info) {
seen_first_frame_activation_ = false;
return surface_manager_->CreateSurface(weak_factory_.GetWeakPtr(),
surface_info);
}
-void CompositorFrameSinkSupport::DestroyCurrentSurface() {
- surface_manager_->DestroySurface(std::move(current_surface_));
-}
-
void CompositorFrameSinkSupport::RequestCopyOfSurface(
std::unique_ptr<CopyOutputRequest> copy_request) {
- if (!current_surface_)
+ Surface* current_surface = GetCurrentSurface();
+ if (!current_surface)
return;
-
- DCHECK(current_surface_->compositor_frame_sink_support().get() == this);
- current_surface_->RequestCopyOfOutput(std::move(copy_request));
+ DCHECK(current_surface->compositor_frame_sink_support().get() == this);
+ current_surface->RequestCopyOfOutput(std::move(copy_request));
BeginFrameAck ack;
ack.has_damage = true;
- if (current_surface_->HasActiveFrame())
- surface_manager_->SurfaceModified(current_surface_->surface_id(), ack);
+ if (current_surface->HasActiveFrame())
+ surface_manager_->SurfaceModified(current_surface->surface_id(), ack);
+}
+
+Surface* CompositorFrameSinkSupport::GetCurrentSurface() {
+ return surface_manager_->GetSurfaceForId(
+ SurfaceId(frame_sink_id_, current_local_surface_id_));
}
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698