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

Unified Diff: cc/surfaces/compositor_frame_sink_support.cc

Issue 2940183002: cc: Move ownership of surfaces to SurfaceManager (Closed)
Patch Set: Fix test 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 6ac4753fe0a1d81e10882913824793c388aae7b4..2b2b7fc0aec6d11ab7a68ca62dc2b332502ecf3f 100644
--- a/cc/surfaces/compositor_frame_sink_support.cc
+++ b/cc/surfaces/compositor_frame_sink_support.cc
@@ -77,9 +77,9 @@ void CompositorFrameSinkSupport::SetBeginFrameSource(
}
void CompositorFrameSinkSupport::EvictCurrentSurface() {
- if (!current_surface_)
+ if (!GetCurrentSurface())
Fady Samuel 2017/06/20 17:29:06 This is less efficient than it needs to be. Surfa
Saman Sami 2017/06/20 22:47:10 Done.
return;
- DestroyCurrentSurface();
+ surface_manager_->DestroySurface(GetCurrentSurfaceId());
}
void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) {
@@ -96,8 +96,8 @@ 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);
+ if (GetCurrentSurface())
Fady Samuel 2017/06/20 17:29:06 Surface* current_surface = GetCurrentSurface(); if
Saman Sami 2017/06/20 22:47:10 Done.
+ surface_manager_->SurfaceModified(GetCurrentSurfaceId(), ack);
if (begin_frame_source_)
begin_frame_source_->DidFinishFrame(this);
}
@@ -127,13 +127,11 @@ 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(GetCurrentSurfaceId()) ||
Fady Samuel 2017/06/20 17:29:06 replace GetCurrentSurface() => current_surface->su
Saman Sami 2017/06/20 22:47:10 Done.
+ 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 +140,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,10 +149,11 @@ bool CompositorFrameSinkSupport::SubmitCompositorFrame(
return true;
}
- surface = CreateSurface(surface_info);
+ current_surface = CreateSurface(surface_info);
+ current_local_surface_id_ = local_surface_id;
}
- bool result = surface->QueueFrame(
+ bool result = current_surface->QueueFrame(
std::move(frame),
base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck,
weak_factory_.GetWeakPtr()),
@@ -162,15 +161,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);
@@ -286,9 +284,8 @@ void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager) {
void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) {
UpdateNeedsBeginFramesInternal();
- if (current_surface_) {
- surface_manager_->SurfaceDamageExpected(current_surface_->surface_id(),
- args);
+ if (GetCurrentSurface()) {
Fady Samuel 2017/06/20 17:29:06 Drop the braces: Surface* current_surface = GetCu
Saman Sami 2017/06/20 22:47:10 Done.
+ surface_manager_->SurfaceDamageExpected(GetCurrentSurfaceId(), args);
}
last_begin_frame_args_ = args;
if (client_)
@@ -340,28 +337,32 @@ 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(GetCurrentSurfaceId());
+}
+
+SurfaceId CompositorFrameSinkSupport::GetCurrentSurfaceId() {
Fady Samuel 2017/06/20 17:29:06 Maybe we don't need this?
Saman Sami 2017/06/20 22:47:10 Done.
+ return SurfaceId(frame_sink_id_, current_local_surface_id_);
}
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698