// 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/color_space_win.h" #include "ui/gfx/geometry/size.h" #include "ui/gl/dc_renderer_layer_params.h" #include "ui/gl/hdr_metadata_helper_win.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_vp_scaling, bool reset_vp_when_colorspace_changes); ~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, const gfx::ColorSpace& input_color_space, const gfx::ColorSpace& output_color_space, Microsoft::WRL::ComPtr swap_chain, bool is_yuv_swapchain); void SetNeedsRebuildVisualTree() { needs_rebuild_visual_tree_ = true; } bool disable_nv12_dynamic_textures() const { return disable_nv12_dynamic_textures_; } 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; void GetSwapChainVisualInfoForTesting(size_t index, gfx::Transform* transform, gfx::Point* offset, gfx::Rect* clip_rect) const; void SetFrameRate(float frame_rate); const std::unique_ptr& GetHDRMetadataHelper() { return hdr_metadata_helper_; } HWND window() const { return window_; } private: void SetColorSpaceForVideoProcessor( const gfx::ColorSpace& input_color_space, const gfx::ColorSpace& output_color_space, Microsoft::WRL::ComPtr swap_chain, bool is_yuv_swapchain); const bool disable_nv12_dynamic_textures_; const bool disable_vp_scaling_; const bool reset_vp_when_colorspace_changes_; HWND window_; 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_; // Current video processor input and output colorspace. gfx::ColorSpace video_input_color_space_; gfx::ColorSpace video_output_color_space_; bool is_yuv_video_output_ = false; // 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_; // Number of frames per second. float frame_rate_ = 0.f; // dealing with hdr metadata std::unique_ptr hdr_metadata_helper_; DISALLOW_COPY_AND_ASSIGN(DCLayerTree); }; } // namespace gl #endif // UI_GL_DC_LAYER_TREE_H_