// Copyright 2019 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_GL_DC_LAYER_TREE_H_ #define UI_GL_DC_LAYER_TREE_H_ #include #include #include #include #include #include "ui/gfx/geometry/size.h" #include "ui/gl/dc_renderer_layer_params.h" namespace gl { class DirectCompositionChildSurfaceWin; class SwapChainPresenter; // 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(). class DCLayerTree { public: DCLayerTree(bool disable_nv12_dynamic_textures, bool disable_larger_than_screen_overlays, bool disable_vp_scaling); ~DCLayerTree(); // Returns true on success. bool Initialize(HWND window, Microsoft::WRL::ComPtr d3d11_device, Microsoft::WRL::ComPtr dcomp_device); // Present pending overlay layers, and perform a direct composition commit if // necessary. Returns true if presentation and commit succeeded. bool CommitAndClearPendingOverlays( DirectCompositionChildSurfaceWin* root_surface); // Schedule an overlay layer for the next CommitAndClearPendingOverlays call. bool ScheduleDCLayer(const ui::DCRendererLayerParams& params); // Called by SwapChainPresenter to initialize video processor that can handle // at least given input and output size. The video processor is shared across // layers so the same one can be reused if it's large enough. Returns true on // success. bool InitializeVideoProcessor(const gfx::Size& input_size, const gfx::Size& output_size); void SetNeedsRebuildVisualTree() { needs_rebuild_visual_tree_ = true; } bool disable_nv12_dynamic_textures() const { return disable_nv12_dynamic_textures_; } bool disable_larger_than_screen_overlays() const { return disable_larger_than_screen_overlays_; } bool disable_vp_scaling() const { return disable_vp_scaling_; } const Microsoft::WRL::ComPtr& video_device() const { return video_device_; } const Microsoft::WRL::ComPtr& video_context() const { return video_context_; } const Microsoft::WRL::ComPtr& video_processor() const { return video_processor_; } const Microsoft::WRL::ComPtr& video_processor_enumerator() const { return video_processor_enumerator_; } Microsoft::WRL::ComPtr GetLayerSwapChainForTesting( size_t index) const; private: const bool disable_nv12_dynamic_textures_; const bool disable_larger_than_screen_overlays_; const bool disable_vp_scaling_; Microsoft::WRL::ComPtr d3d11_device_; Microsoft::WRL::ComPtr dcomp_device_; Microsoft::WRL::ComPtr dcomp_target_; // The video processor is cached so SwapChains don't have to recreate it // whenever they're created. Microsoft::WRL::ComPtr video_device_; Microsoft::WRL::ComPtr video_context_; Microsoft::WRL::ComPtr video_processor_; Microsoft::WRL::ComPtr video_processor_enumerator_; // Current video processor input and output size. gfx::Size video_input_size_; gfx::Size video_output_size_; // Set to true if a direct composition visual tree needs rebuild. bool needs_rebuild_visual_tree_ = false; // Set if root surface is using a swap chain currently. Microsoft::WRL::ComPtr root_swap_chain_; // Set if root surface is using a direct composition surface currently. Microsoft::WRL::ComPtr root_dcomp_surface_; uint64_t root_dcomp_surface_serial_; // Direct composition visual for root surface. Microsoft::WRL::ComPtr root_surface_visual_; // Root direct composition visual for window dcomp target. Microsoft::WRL::ComPtr dcomp_root_visual_; // List of pending overlay layers from ScheduleDCLayer(). std::vector> pending_overlays_; // List of swap chain presenters for previous frame. std::vector> video_swap_chains_; DISALLOW_COPY_AND_ASSIGN(DCLayerTree); }; } // namespace gl #endif // UI_GL_DC_LAYER_TREE_H_