gpu: win: Cleanup ScheduleDCLayer
ScheduleDCLayer is always infallible on Windows, so this change makes it
return void. It shouldn't be called on other platforms.
Also, DCLayerTree::ScheduleDCLayer just acts as a level of indirection,
so this change makes DCLayerTree::CommitAndClearPendingOverlays instead
just take the list of pending overlays instead.
Bug: 41490668
Change-Id: Ibb61e42539b61d26a3e25017ec6f18f11681d536
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5411493
Commit-Queue: Michael Tang <tangm@microsoft.com>
Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com>
Reviewed-by: Maggie Chen <magchen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1284879}
diff --git a/components/viz/service/display_embedder/skia_output_device_dcomp.cc b/components/viz/service/display_embedder/skia_output_device_dcomp.cc
index bca9668..2c360b7 100644
--- a/components/viz/service/display_embedder/skia_output_device_dcomp.cc
+++ b/components/viz/service/display_embedder/skia_output_device_dcomp.cc
@@ -462,10 +462,7 @@
dc_layer.possible_video_fullscreen_letterboxing;
// Schedule DC layer overlay to be presented at next SwapBuffers().
- if (!presenter_->ScheduleDCLayer(std::move(params))) {
- DLOG(ERROR) << "ScheduleDCLayer failed";
- continue;
- }
+ presenter_->ScheduleDCLayer(std::move(params));
scheduled_overlay_mailboxes_.insert(mailbox);
}
}
diff --git a/ui/gl/dc_layer_tree.cc b/ui/gl/dc_layer_tree.cc
index 8c7ec85b..cddf147 100644
--- a/ui/gl/dc_layer_tree.cc
+++ b/ui/gl/dc_layer_tree.cc
@@ -1171,17 +1171,17 @@
}
}
-bool DCLayerTree::CommitAndClearPendingOverlays() {
+bool DCLayerTree::CommitAndClearPendingOverlays(
+ std::vector<std::unique_ptr<DCLayerOverlayParams>> overlays) {
TRACE_EVENT1("gpu", "DCLayerTree::CommitAndClearPendingOverlays",
- "num_pending_overlays", pending_overlays_.size());
+ "num_overlays", overlays.size());
DCHECK(!needs_rebuild_visual_tree_ || ink_renderer_->HasBeenInitialized());
{
Microsoft::WRL::ComPtr<IDXGISwapChain1> root_swap_chain;
Microsoft::WRL::ComPtr<IDCompositionSurface> root_dcomp_surface;
- auto it = base::ranges::find(pending_overlays_, 0,
- &DCLayerOverlayParams::z_order);
- if (it != pending_overlays_.end() && (*it)->overlay_image) {
+ auto it = base::ranges::find(overlays, 0, &DCLayerOverlayParams::z_order);
+ if (it != overlays.end() && (*it)->overlay_image) {
Microsoft::WRL::ComPtr<IUnknown> root_visual_content =
(*it)->overlay_image->dcomp_visual_content();
CHECK(root_visual_content);
@@ -1205,9 +1205,6 @@
}
}
- std::vector<std::unique_ptr<DCLayerOverlayParams>> overlays;
- std::swap(pending_overlays_, overlays);
-
// Grow or shrink list of swap chain presenters to match pending overlays.
const size_t num_swap_chain_presenters =
std::count_if(overlays.begin(), overlays.end(), [](const auto& overlay) {
@@ -1283,12 +1280,6 @@
return status;
}
-bool DCLayerTree::ScheduleDCLayer(
- std::unique_ptr<DCLayerOverlayParams> params) {
- pending_overlays_.push_back(std::move(params));
- return true;
-}
-
size_t DCLayerTree::GetNumSurfacesInPoolForTesting() const {
CHECK_IS_TEST();
return solid_color_surface_pool_
diff --git a/ui/gl/dc_layer_tree.h b/ui/gl/dc_layer_tree.h
index 5e4920da..19dbde9 100644
--- a/ui/gl/dc_layer_tree.h
+++ b/ui/gl/dc_layer_tree.h
@@ -139,9 +139,7 @@
};
// DCLayerTree manages a tree of direct composition visuals, and associated
-// swap chains for given overlay layers. It maintains a list of pending layers
-// submitted using ScheduleDCLayer() that are presented and committed in
-// CommitAndClearPendingOverlays().
+// swap chains for given overlay layers.
class GL_EXPORT DCLayerTree {
public:
using DelegatedInkRenderer = DelegatedInkPointRendererGpu;
@@ -161,12 +159,10 @@
void Initialize(HWND window,
Microsoft::WRL::ComPtr<ID3D11Device> d3d11_device);
- // Present pending overlay layers, and perform a direct composition commit if
- // necessary. Returns true if presentation and commit succeeded.
- bool CommitAndClearPendingOverlays();
-
- // Schedule an overlay layer for the next CommitAndClearPendingOverlays call.
- bool ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params);
+ // Present overlay layers, and perform a direct composition commit if
+ // necessary. Returns true if presentation and commit succeeded.
+ bool CommitAndClearPendingOverlays(
+ std::vector<std::unique_ptr<DCLayerOverlayParams>> overlays);
// Called by SwapChainPresenter to initialize video processor that can handle
// at least given input and output size. The video processor is shared across
@@ -254,11 +250,6 @@
return ink_renderer_.get();
}
- bool HasPendingOverlaysForTesting() const {
- CHECK_IS_TEST();
- return pending_overlays_.size() > 0;
- }
-
// Owns a list of |VisualSubtree|s that represent visual layers.
class VisualTree {
public:
@@ -269,7 +260,7 @@
VisualTree& operator=(const VisualTree&) = delete;
~VisualTree();
- // Given pending overlays, builds or updates this visual tree.
+ // Given overlays, builds or updates this visual tree.
// Returns true if commit succeeded.
bool BuildTree(
const std::vector<std::unique_ptr<DCLayerOverlayParams>>& overlays,
@@ -562,9 +553,6 @@
// Root direct composition visual for window dcomp target.
Microsoft::WRL::ComPtr<IDCompositionVisual2> dcomp_root_visual_;
- // List of pending overlay layers from ScheduleDCLayer().
- std::vector<std::unique_ptr<DCLayerOverlayParams>> pending_overlays_;
-
// List of swap chain presenters for previous frame.
std::vector<std::unique_ptr<SwapChainPresenter>> video_swap_chains_;
diff --git a/ui/gl/dcomp_presenter.cc b/ui/gl/dcomp_presenter.cc
index c7083fa..9541bae6 100644
--- a/ui/gl/dcomp_presenter.cc
+++ b/ui/gl/dcomp_presenter.cc
@@ -90,9 +90,9 @@
weak_factory_.GetWeakPtr(), vsync_time, interval));
}
-bool DCompPresenter::ScheduleDCLayer(
+void DCompPresenter::ScheduleDCLayer(
std::unique_ptr<DCLayerOverlayParams> params) {
- return layer_tree_->ScheduleDCLayer(std::move(params));
+ pending_overlays_.push_back(std::move(params));
}
void DCompPresenter::SetFrameRate(float frame_rate) {
@@ -114,7 +114,8 @@
/*create_query=*/create_query_this_frame_);
create_query_this_frame_ = false;
- if (!layer_tree_->CommitAndClearPendingOverlays()) {
+ if (!layer_tree_->CommitAndClearPendingOverlays(
+ std::move(pending_overlays_))) {
std::move(completion_callback)
.Run(gfx::SwapCompletionResult(gfx::SwapResult::SWAP_FAILED));
return;
diff --git a/ui/gl/dcomp_presenter.h b/ui/gl/dcomp_presenter.h
index 341e915..149228e 100644
--- a/ui/gl/dcomp_presenter.h
+++ b/ui/gl/dcomp_presenter.h
@@ -73,7 +73,7 @@
// to remain in the layer tree. This surface's backbuffer doesn't have to be
// scheduled with ScheduleDCLayer, as it's automatically placed in the layer
// tree at z-order 0.
- bool ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params) override;
+ void ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params) override;
void SetFrameRate(float frame_rate) override;
void Present(SwapCompletionCallback completion_callback,
@@ -141,6 +141,8 @@
base::circular_deque<PendingFrame> pending_frames_;
const size_t max_pending_frames_;
+ std::vector<std::unique_ptr<DCLayerOverlayParams>> pending_overlays_;
+
base::TimeTicks last_vsync_time_;
base::TimeDelta last_vsync_interval_;
diff --git a/ui/gl/dcomp_presenter_unittest.cc b/ui/gl/dcomp_presenter_unittest.cc
index 22a9cd4..ef3e4f8b 100644
--- a/ui/gl/dcomp_presenter_unittest.cc
+++ b/ui/gl/dcomp_presenter_unittest.cc
@@ -261,7 +261,7 @@
params->z_order = 0;
params->quad_rect = gfx::Rect(window_size);
params->overlay_image = CreateDCompSurface(window_size, initial_color);
- EXPECT_TRUE(presenter_->ScheduleDCLayer(std::move(params)));
+ presenter_->ScheduleDCLayer(std::move(params));
}
// Wait for |presenter_| to present asynchronously check the swap result.
@@ -680,8 +680,7 @@
}
layer_tree->SetDelegatedInkTrailStartPoint(std::move(metadata));
- EXPECT_FALSE(layer_tree->HasPendingOverlaysForTesting());
- EXPECT_TRUE(layer_tree->CommitAndClearPendingOverlays());
+ EXPECT_TRUE(layer_tree->CommitAndClearPendingOverlays({}));
}
class DCompPresenterPixelTest : public DCompPresenterTest {
@@ -1738,7 +1737,7 @@
overlay->transform.Translate(25, 25);
- EXPECT_TRUE(presenter_->ScheduleDCLayer(std::move(overlay)));
+ presenter_->ScheduleDCLayer(std::move(overlay));
PresentAndCheckScreenshot();
}
@@ -1758,7 +1757,7 @@
overlay->transform.Scale(1.2);
overlay->transform.Translate(-25, -25);
- EXPECT_TRUE(presenter_->ScheduleDCLayer(std::move(overlay)));
+ presenter_->ScheduleDCLayer(std::move(overlay));
PresentAndCheckScreenshot();
}
@@ -1779,7 +1778,7 @@
overlay->transform.Rotate(15);
overlay->transform.Translate(-25, -25);
- EXPECT_TRUE(presenter_->ScheduleDCLayer(std::move(overlay)));
+ presenter_->ScheduleDCLayer(std::move(overlay));
PresentAndCheckScreenshot();
}
@@ -1804,7 +1803,7 @@
overlay->transform.RotateAboutXAxis(30);
overlay->transform.Translate(-25, -25);
- EXPECT_TRUE(presenter_->ScheduleDCLayer(std::move(overlay)));
+ presenter_->ScheduleDCLayer(std::move(overlay));
PresentAndCheckScreenshot();
}
@@ -1823,7 +1822,7 @@
overlay->transform.Translate(50, 50);
overlay->transform.Skew(15, 30);
overlay->transform.Translate(-25, -25);
- EXPECT_TRUE(presenter_->ScheduleDCLayer(std::move(overlay)));
+ presenter_->ScheduleDCLayer(std::move(overlay));
PresentAndCheckScreenshot();
}
@@ -2164,7 +2163,7 @@
overlay->background_color = SkColors::kGreen;
overlay->z_order = 1;
- EXPECT_TRUE(presenter_->ScheduleDCLayer(std::move(overlay)));
+ presenter_->ScheduleDCLayer(std::move(overlay));
PresentAndCheckScreenshot();
}
@@ -2236,7 +2235,7 @@
CreateParamsFromImage(DCLayerOverlayImage(texture_size, texture));
params->quad_rect = gfx::Rect(window_size);
params->color_space = gfx::ColorSpace::CreateREC709();
- EXPECT_TRUE(presenter_->ScheduleDCLayer(std::move(params)));
+ presenter_->ScheduleDCLayer(std::move(params));
PresentAndCheckSwapResult(gfx::SwapResult::SWAP_ACK);
diff --git a/ui/gl/direct_composition_surface_win.cc b/ui/gl/direct_composition_surface_win.cc
index e302060..0c1092a 100644
--- a/ui/gl/direct_composition_surface_win.cc
+++ b/ui/gl/direct_composition_surface_win.cc
@@ -144,10 +144,11 @@
root_surface_->dcomp_surface_serial());
root_params->content_rect = gfx::RectF(root_params->overlay_image->size());
root_params->quad_rect = gfx::Rect(root_params->overlay_image->size());
- CHECK(ScheduleDCLayer(std::move(root_params)));
+ ScheduleDCLayer(std::move(root_params));
}
- if (!layer_tree_->CommitAndClearPendingOverlays()) {
+ if (!layer_tree_->CommitAndClearPendingOverlays(
+ std::move(pending_overlays_))) {
return gfx::SwapResult::SWAP_FAILED;
}
@@ -182,9 +183,9 @@
weak_factory_.GetWeakPtr(), vsync_time, interval));
}
-bool DirectCompositionSurfaceWin::ScheduleDCLayer(
+void DirectCompositionSurfaceWin::ScheduleDCLayer(
std::unique_ptr<DCLayerOverlayParams> params) {
- return layer_tree_->ScheduleDCLayer(std::move(params));
+ pending_overlays_.push_back(std::move(params));
}
void DirectCompositionSurfaceWin::SetFrameRate(float frame_rate) {
diff --git a/ui/gl/direct_composition_surface_win.h b/ui/gl/direct_composition_surface_win.h
index e285ae9..9a1b7caa 100644
--- a/ui/gl/direct_composition_surface_win.h
+++ b/ui/gl/direct_composition_surface_win.h
@@ -99,7 +99,7 @@
// to remain in the layer tree. This surface's backbuffer doesn't have to be
// scheduled with ScheduleDCLayer, as it's automatically placed in the layer
// tree at z-order 0.
- bool ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params) override;
+ void ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params) override;
void SetFrameRate(float frame_rate) override;
// VSyncObserver implementation.
@@ -171,6 +171,8 @@
base::circular_deque<PendingFrame> pending_frames_;
const size_t max_pending_frames_;
+ std::vector<std::unique_ptr<DCLayerOverlayParams>> pending_overlays_;
+
base::TimeTicks last_vsync_time_;
base::TimeDelta last_vsync_interval_;
diff --git a/ui/gl/direct_composition_surface_win_unittest.cc b/ui/gl/direct_composition_surface_win_unittest.cc
index d11b991f..c6e41a0 100644
--- a/ui/gl/direct_composition_surface_win_unittest.cc
+++ b/ui/gl/direct_composition_surface_win_unittest.cc
@@ -1437,7 +1437,7 @@
params->content_rect = gfx::RectF(texture_size);
params->quad_rect = gfx::Rect(window_size);
params->color_space = gfx::ColorSpace::CreateREC709();
- EXPECT_TRUE(surface->ScheduleDCLayer(std::move(params)));
+ surface->ScheduleDCLayer(std::move(params));
}
EXPECT_EQ(gfx::SwapResult::SWAP_ACK,
diff --git a/ui/gl/gl_surface.cc b/ui/gl/gl_surface.cc
index 985dab2..51e93d2 100644
--- a/ui/gl/gl_surface.cc
+++ b/ui/gl/gl_surface.cc
@@ -134,9 +134,8 @@
void GLSurface::SetVSyncEnabled(bool enabled) {}
-bool GLSurface::ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params) {
+void GLSurface::ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params) {
NOTIMPLEMENTED();
- return false;
}
bool GLSurface::SetEnableDCLayers(bool enable) {
diff --git a/ui/gl/gl_surface.h b/ui/gl/gl_surface.h
index 7307f6ed..a60df00 100644
--- a/ui/gl/gl_surface.h
+++ b/ui/gl/gl_surface.h
@@ -202,7 +202,7 @@
// default. Does nothing if vsync cannot be changed.
virtual void SetVSyncEnabled(bool enabled);
- virtual bool ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params);
+ virtual void ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params);
// Enables or disables DC layers, returning success. If failed, it is possible
// that the context is no longer current.
diff --git a/ui/gl/presenter.cc b/ui/gl/presenter.cc
index f8c72a8..9380570 100644
--- a/ui/gl/presenter.cc
+++ b/ui/gl/presenter.cc
@@ -44,9 +44,8 @@
return false;
}
-bool Presenter::ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params) {
+void Presenter::ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params) {
NOTIMPLEMENTED();
- return false;
}
bool Presenter::Resize(const gfx::Size& size,
diff --git a/ui/gl/presenter.h b/ui/gl/presenter.h
index 7da4ed1f..5f9c471 100644
--- a/ui/gl/presenter.h
+++ b/ui/gl/presenter.h
@@ -114,7 +114,7 @@
// Schedule a DCLayer to be shown at next Present(). Semantics is similar to
// ScheduleOverlayPlane() above. All arguments correspond to their DCLayer
// properties.
- virtual bool ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params);
+ virtual void ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params);
// Presents current frame asynchronously. `completion_callback` will be called
// once all necessary steps were taken to display the frame.