[go: nahoru, domu]

cc: Plumb raster capabilities

This introduces new raster struct for easier maintaining and access of the
raster settings across cc/workers and gpu.

Bug: 1442970
Change-Id: I607436be625e61ec94bc62858832cffd22ce2675
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4547502
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Commit-Queue: Sohan Jyoti Ghosh <sohanjg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1148324}
diff --git a/cc/BUILD.gn b/cc/BUILD.gn
index c55566a..5314536 100644
--- a/cc/BUILD.gn
+++ b/cc/BUILD.gn
@@ -413,6 +413,7 @@
     "trees/proxy_impl.h",
     "trees/proxy_main.cc",
     "trees/proxy_main.h",
+    "trees/raster_capabilities.h",
     "trees/raster_context_provider_wrapper.cc",
     "trees/raster_context_provider_wrapper.h",
     "trees/render_frame_metadata.cc",
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index c51ac1fa..bec4013 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -478,9 +478,7 @@
                       compositor_frame_reporting_controller_.get()),
       lcd_text_metrics_reporter_(LCDTextMetricsReporter::CreateIfNeeded(this)),
       frame_rate_estimator_(GetTaskRunner()),
-      contains_srgb_cache_(kContainsSrgbCacheSize),
-      use_dmsaa_for_tiles_(
-          base::FeatureList::IsEnabled(features::kUseDMSAAForTiles)) {
+      contains_srgb_cache_(kContainsSrgbCacheSize) {
   DCHECK(mutator_host_);
   mutator_host_->SetMutatorHostClient(this);
   mutator_events_ = mutator_host_->CreateEvents();
@@ -531,6 +529,9 @@
   frame_trackers_.set_custom_tracker_results_added_callback(
       base::BindRepeating(&LayerTreeHostImpl::NotifyThroughputTrackerResults,
                           weak_factory_.GetWeakPtr()));
+
+  raster_caps_.use_dmsaa_for_tiles =
+      base::FeatureList::IsEnabled(features::kUseDMSAAForTiles);
 }
 
 LayerTreeHostImpl::~LayerTreeHostImpl() {
@@ -2001,13 +2002,17 @@
       kMinNumberOfSlowPathsForMSAA) {
     return 0;
   }
-  if (!can_use_msaa_)
+  if (!raster_caps().can_use_msaa) {
     return 0;
+  }
 
   if (display_list->HasNonAAPaint()) {
-    UMA_HISTOGRAM_BOOLEAN("GPU.SupportsDisableMsaa", supports_disable_msaa_);
-    if (!supports_disable_msaa_ || use_dmsaa_for_tiles_)
+    UMA_HISTOGRAM_BOOLEAN("GPU.SupportsDisableMsaa",
+                          raster_caps().supports_disable_msaa);
+    if (!raster_caps().supports_disable_msaa ||
+        raster_caps().use_dmsaa_for_tiles) {
       return 0;
+    }
   }
 
   return RequestedMSAASampleCount();
@@ -2658,7 +2663,8 @@
         draw_mode, layer_tree_frame_sink_, &resource_provider_,
         // The hud uses Gpu rasterization if the device is capable, not related
         // to the content of the web page.
-        gpu_rasterization_status_ != GpuRasterizationStatus::OFF_DEVICE,
+        raster_caps().gpu_rasterization_status !=
+            GpuRasterizationStatus::OFF_DEVICE,
         frame->render_passes);
   }
 
@@ -2867,9 +2873,10 @@
 }
 
 bool LayerTreeHostImpl::UpdateGpuRasterizationStatus() {
-  if (!need_update_gpu_rasterization_status_)
+  if (!raster_caps().need_update_gpu_rasterization_status) {
     return false;
-  need_update_gpu_rasterization_status_ = false;
+  }
+  raster_caps_.need_update_gpu_rasterization_status = false;
 
   // TODO(danakj): Can we avoid having this run when there's no
   // LayerTreeFrameSink?
@@ -2890,23 +2897,26 @@
 
   if (!gpu_rasterization_enabled) {
     if (gpu_rasterization_supported)
-      gpu_rasterization_status_ = GpuRasterizationStatus::OFF_FORCED;
+      raster_caps_.gpu_rasterization_status =
+          GpuRasterizationStatus::OFF_FORCED;
     else
-      gpu_rasterization_status_ = GpuRasterizationStatus::OFF_DEVICE;
+      raster_caps_.gpu_rasterization_status =
+          GpuRasterizationStatus::OFF_DEVICE;
   } else {
     use_gpu = true;
-    gpu_rasterization_status_ = GpuRasterizationStatus::ON;
+    raster_caps_.gpu_rasterization_status = GpuRasterizationStatus::ON;
   }
 
-  if (use_gpu && !use_gpu_rasterization_) {
+  if (use_gpu && !raster_caps().use_gpu_rasterization) {
     if (!gpu_rasterization_supported) {
       // If GPU rasterization is unusable, e.g. if GlContext could not
       // be created due to losing the GL context, force use of software
       // raster.
       use_gpu = false;
-      can_use_msaa_ = false;
-      supports_disable_msaa_ = false;
-      gpu_rasterization_status_ = GpuRasterizationStatus::OFF_DEVICE;
+      raster_caps_.can_use_msaa = false;
+      raster_caps_.supports_disable_msaa = false;
+      raster_caps_.gpu_rasterization_status =
+          GpuRasterizationStatus::OFF_DEVICE;
     }
   }
 
@@ -2914,14 +2924,15 @@
   // settings to take effect. But we don't need to trigger any raster
   // invalidation in this case since these settings change only if the context
   // changed. In this case we already re-allocate and re-raster all resources.
-  if (use_gpu == use_gpu_rasterization_ && can_use_msaa == can_use_msaa_ &&
-      supports_disable_msaa == supports_disable_msaa_) {
+  if (use_gpu == raster_caps().use_gpu_rasterization &&
+      can_use_msaa == raster_caps().can_use_msaa &&
+      supports_disable_msaa == raster_caps().supports_disable_msaa) {
     return false;
   }
 
-  use_gpu_rasterization_ = use_gpu;
-  can_use_msaa_ = can_use_msaa;
-  supports_disable_msaa_ = supports_disable_msaa;
+  raster_caps_.use_gpu_rasterization = use_gpu;
+  raster_caps_.can_use_msaa = can_use_msaa;
+  raster_caps_.supports_disable_msaa = supports_disable_msaa;
   return true;
 }
 
@@ -3617,17 +3628,17 @@
 void LayerTreeHostImpl::CreateTileManagerResources() {
   viz::SharedImageFormat tile_format = TileRasterBufferFormat(
       settings_, layer_tree_frame_sink_->context_provider(),
-      use_gpu_rasterization_);
+      raster_caps().use_gpu_rasterization);
 
   const bool gpu_compositing = !!layer_tree_frame_sink_->context_provider();
   image_decode_cache_holder_ = std::make_unique<ImageDecodeCacheHolder>(
-      settings_.enable_shared_image_cache_for_gpu, use_gpu_rasterization_,
-      gpu_compositing,
+      settings_.enable_shared_image_cache_for_gpu,
+      raster_caps().use_gpu_rasterization, gpu_compositing,
       layer_tree_frame_sink_->worker_context_provider_wrapper(), tile_format,
-      settings_.decoded_image_working_set_budget_bytes, max_texture_size_,
-      dark_mode_filter_);
+      settings_.decoded_image_working_set_budget_bytes,
+      raster_caps().max_texture_size, dark_mode_filter_);
 
-  if (use_gpu_rasterization_) {
+  if (raster_caps().use_gpu_rasterization) {
     pending_raster_queries_ = std::make_unique<RasterQueryQueue>(
         layer_tree_frame_sink_->worker_context_provider());
   }
@@ -3646,10 +3657,11 @@
 
   tile_manager_.SetResources(resource_pool_.get(), GetImageDecodeCache(),
                              task_graph_runner, raster_buffer_provider_.get(),
-                             use_gpu_rasterization_,
+                             raster_caps().use_gpu_rasterization,
                              pending_raster_queries_.get());
   tile_manager_.SetCheckerImagingForceDisabled(
-      settings_.only_checker_images_with_gpu_raster && !use_gpu_rasterization_);
+      settings_.only_checker_images_with_gpu_raster &&
+      !raster_caps().use_gpu_rasterization);
   UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy());
 }
 
@@ -3667,10 +3679,11 @@
   viz::RasterContextProvider* worker_context_provider =
       layer_tree_frame_sink_->worker_context_provider();
 
-  viz::SharedImageFormat tile_format = TileRasterBufferFormat(
-      settings_, compositor_context_provider, use_gpu_rasterization_);
+  viz::SharedImageFormat tile_format =
+      TileRasterBufferFormat(settings_, compositor_context_provider,
+                             raster_caps().use_gpu_rasterization);
 
-  if (use_gpu_rasterization_) {
+  if (raster_caps().use_gpu_rasterization) {
     DCHECK(worker_context_provider);
 
     return std::make_unique<GpuRasterBufferProvider>(
@@ -3890,7 +3903,7 @@
   // We don't know if the next LayerTreeFrameSink will support GPU
   // rasterization. Make sure to clear the flag so that we force a
   // re-computation.
-  use_gpu_rasterization_ = false;
+  raster_caps_.use_gpu_rasterization = false;
 }
 
 bool LayerTreeHostImpl::InitializeFrameSink(
@@ -3915,13 +3928,13 @@
   if (worker_context_provider) {
     viz::RasterContextProvider::ScopedRasterContextLock scoped_context(
         worker_context_provider);
-    max_texture_size_ =
+    raster_caps_.max_texture_size =
         worker_context_provider->ContextCapabilities().max_texture_size;
   } else if (context_provider) {
-    max_texture_size_ =
+    raster_caps_.max_texture_size =
         context_provider->ContextCapabilities().max_texture_size;
   } else {
-    max_texture_size_ = settings_.max_render_buffer_bounds_for_sw;
+    raster_caps_.max_texture_size = settings_.max_render_buffer_bounds_for_sw;
   }
 
   resource_pool_ = std::make_unique<ResourcePool>(
@@ -4616,12 +4629,12 @@
   // UIResources are assumed to be rastered in SRGB.
   const gfx::ColorSpace& color_space = gfx::ColorSpace::CreateSRGB();
 
-  if (source_size.width() > max_texture_size_ ||
-      source_size.height() > max_texture_size_) {
+  if (source_size.width() > raster_caps().max_texture_size ||
+      source_size.height() > raster_caps().max_texture_size) {
     // Must resize the bitmap to fit within the max texture size.
     scaled = true;
     int edge = std::max(source_size.width(), source_size.height());
-    float scale = static_cast<float>(max_texture_size_ - 1) / edge;
+    float scale = static_cast<float>(raster_caps().max_texture_size - 1) / edge;
     DCHECK_LT(scale, 1.f);
     upload_size = gfx::ScaleToCeiledSize(source_size, scale, scale);
   }
@@ -4975,7 +4988,7 @@
 }
 
 void LayerTreeHostImpl::SetNeedUpdateGpuRasterizationStatus() {
-  need_update_gpu_rasterization_status_ = true;
+  raster_caps_.need_update_gpu_rasterization_status = true;
 }
 
 void LayerTreeHostImpl::SetElementFilterMutated(
@@ -5268,8 +5281,8 @@
                               paint_worklet_painter_->HasOngoingDispatch()),
              static_cast<int>(tile_manager_.IsReadyToActivate()),
              static_cast<int>(GetActivelyScrollingType()),
-             static_cast<int>(use_gpu_rasterization_),
-             static_cast<int>(gpu_rasterization_status_),
+             static_cast<int>(raster_caps().use_gpu_rasterization),
+             static_cast<int>(raster_caps().gpu_rasterization_status),
              static_cast<int>(has_valid_layer_tree_frame_sink_),
              static_cast<int>(layer_tree_frame_sink_ &&
                               layer_tree_frame_sink_->context_provider()),
diff --git a/cc/trees/layer_tree_host_impl.h b/cc/trees/layer_tree_host_impl.h
index 591bd72..9abb961 100644
--- a/cc/trees/layer_tree_host_impl.h
+++ b/cc/trees/layer_tree_host_impl.h
@@ -54,6 +54,7 @@
 #include "cc/trees/managed_memory_policy.h"
 #include "cc/trees/mutator_host_client.h"
 #include "cc/trees/presentation_time_callback_buffer.h"
+#include "cc/trees/raster_capabilities.h"
 #include "cc/trees/render_frame_metadata.h"
 #include "cc/trees/task_runner_provider.h"
 #include "cc/trees/throttle_decider.h"
@@ -105,12 +106,6 @@
 class UIResourceBitmap;
 class Viewport;
 
-enum class GpuRasterizationStatus {
-  ON,
-  OFF_FORCED,
-  OFF_DEVICE,
-};
-
 // LayerTreeHost->Proxy callback interface.
 class LayerTreeHostImplClient {
  public:
@@ -422,7 +417,7 @@
                                        const gfx::PointF& scroll_offset);
   void SetNeedUpdateGpuRasterizationStatus();
   bool NeedUpdateGpuRasterizationStatusForTesting() const {
-    return need_update_gpu_rasterization_status_;
+    return raster_caps().need_update_gpu_rasterization_status;
   }
 
   // ProtectedSequenceSynchronizer implementation.
@@ -595,7 +590,7 @@
   LayerTreeFrameSink* layer_tree_frame_sink() const {
     return layer_tree_frame_sink_;
   }
-  int max_texture_size() const { return max_texture_size_; }
+  int max_texture_size() const { return raster_caps().max_texture_size; }
   void ReleaseLayerTreeFrameSink();
 
   int RequestedMSAASampleCount() const;
@@ -603,18 +598,22 @@
   virtual bool InitializeFrameSink(LayerTreeFrameSink* layer_tree_frame_sink);
   TileManager* tile_manager() { return &tile_manager_; }
 
+  const RasterCapabilities& raster_caps() const { return raster_caps_; }
   void GetGpuRasterizationCapabilities(bool* gpu_rasterization_enabled,
                                        bool* gpu_rasterization_supported,
                                        bool* can_use_msaa,
                                        bool* supports_disable_msaa);
-  bool use_gpu_rasterization() const { return use_gpu_rasterization_; }
+  bool use_gpu_rasterization() const {
+    return raster_caps().use_gpu_rasterization;
+  }
 
   GpuRasterizationStatus gpu_rasterization_status() const {
-    return gpu_rasterization_status_;
+    return raster_caps().gpu_rasterization_status;
   }
 
   bool create_low_res_tiling() const {
-    return settings_.create_low_res_tiling && !use_gpu_rasterization_;
+    return settings_.create_low_res_tiling &&
+           !raster_caps().use_gpu_rasterization;
   }
   ResourcePool* resource_pool() { return resource_pool_.get(); }
   ImageAnimationController* image_animation_controller() {
@@ -888,7 +887,7 @@
     return paint_worklet_tracker_;
   }
 
-  bool can_use_msaa() const { return can_use_msaa_; }
+  bool can_use_msaa() const { return raster_caps().can_use_msaa; }
 
   Viewport& viewport() const { return *viewport_.get(); }
 
@@ -1095,9 +1094,6 @@
   // A pointer used for communicating with and submitting output to the display
   // compositor.
   raw_ptr<LayerTreeFrameSink> layer_tree_frame_sink_ = nullptr;
-  // The maximum size (either width or height) that any texture can be. Also
-  // holds a reasonable value for software compositing bitmaps.
-  int max_texture_size_ = 0;
 
   // The following scoped variables must not outlive the
   // |layer_tree_frame_sink_|.
@@ -1108,13 +1104,8 @@
   std::unique_ptr<viz::ContextCacheController::ScopedVisibility>
       worker_context_visibility_;
 
-  bool can_use_msaa_ = false;
-  bool supports_disable_msaa_ = false;
+  RasterCapabilities raster_caps_;
 
-  bool need_update_gpu_rasterization_status_ = false;
-  bool use_gpu_rasterization_ = false;
-  GpuRasterizationStatus gpu_rasterization_status_ =
-      GpuRasterizationStatus::OFF_DEVICE;
   std::unique_ptr<RasterBufferProvider> raster_buffer_provider_;
   std::unique_ptr<ResourcePool> resource_pool_;
   std::unique_ptr<RasterQueryQueue> pending_raster_queries_;
@@ -1334,8 +1325,6 @@
   bool downsample_metrics_ = true;
   base::MetricsSubSampler metrics_subsampler_;
 
-  const bool use_dmsaa_for_tiles_;
-
   // Must be the last member to ensure this is destroyed first in the
   // destruction order and invalidates all weak pointers.
   base::WeakPtrFactory<LayerTreeHostImpl> weak_factory_{this};
diff --git a/cc/trees/raster_capabilities.h b/cc/trees/raster_capabilities.h
new file mode 100644
index 0000000..b2400f8
--- /dev/null
+++ b/cc/trees/raster_capabilities.h
@@ -0,0 +1,38 @@
+// Copyright 2023 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_TREES_RASTER_CAPABILITIES_H_
+#define CC_TREES_RASTER_CAPABILITIES_H_
+
+#include "cc/cc_export.h"
+
+namespace cc {
+
+enum class GpuRasterizationStatus {
+  ON,
+  OFF_FORCED,
+  OFF_DEVICE,
+};
+
+struct CC_EXPORT RasterCapabilities {
+  RasterCapabilities() = default;
+  RasterCapabilities(const RasterCapabilities& other) = delete;
+  RasterCapabilities& operator=(const RasterCapabilities& other) = delete;
+  ~RasterCapabilities() = default;
+
+  bool can_use_msaa = false;
+  bool supports_disable_msaa = false;
+
+  bool need_update_gpu_rasterization_status = false;
+  bool use_gpu_rasterization = false;
+  GpuRasterizationStatus gpu_rasterization_status =
+      GpuRasterizationStatus::OFF_DEVICE;
+  // The maximum size (either width or height) that any texture can be. Also
+  // holds a reasonable value for software compositing bitmaps.
+  int max_texture_size = 0;
+  bool use_dmsaa_for_tiles = false;
+};
+}  // namespace cc
+
+#endif  // CC_TREES_RASTER_CAPABILITIES_H_