diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc index 13b4f0f3c1e390..e1e9864e81209c 100644 --- a/cc/layers/picture_layer_impl.cc +++ b/cc/layers/picture_layer_impl.cc @@ -683,13 +683,24 @@ void PictureLayerImpl::UpdateRasterSource( // If the MSAA sample count has changed, we need to re-raster the complete // layer. - if (raster_source_ && raster_source_->GetDisplayItemList() && - raster_source->GetDisplayItemList() && - layer_tree_impl()->GetMSAASampleCountForRaster( - raster_source_->GetDisplayItemList()) != + if (raster_source_) { + const auto& current_display_item_list = + raster_source_->GetDisplayItemList(); + const auto& new_display_item_list = raster_source->GetDisplayItemList(); + if (current_display_item_list && new_display_item_list) { + bool needs_full_invalidation = layer_tree_impl()->GetMSAASampleCountForRaster( - raster_source->GetDisplayItemList())) { - new_invalidation->Union(gfx::Rect(raster_source->GetSize())); + current_display_item_list) != + layer_tree_impl()->GetMSAASampleCountForRaster( + new_display_item_list); + needs_full_invalidation |= + current_display_item_list->discardable_image_map() + .contains_only_srgb_images() != + new_display_item_list->discardable_image_map() + .contains_only_srgb_images(); + if (needs_full_invalidation) + new_invalidation->Union(gfx::Rect(raster_source->GetSize())); + } } } diff --git a/cc/resources/resource_pool.cc b/cc/resources/resource_pool.cc index ceb4d5ffd27e9d..6dbfea69d6bb48 100644 --- a/cc/resources/resource_pool.cc +++ b/cc/resources/resource_pool.cc @@ -200,7 +200,8 @@ ResourcePool::TryAcquireResourceForPartialRaster( uint64_t new_content_id, const gfx::Rect& new_invalidated_rect, uint64_t previous_content_id, - gfx::Rect* total_invalidated_rect) { + gfx::Rect* total_invalidated_rect, + const gfx::ColorSpace& raster_color_space) { DCHECK(new_content_id); DCHECK(previous_content_id); *total_invalidated_rect = gfx::Rect(); @@ -213,6 +214,9 @@ ResourcePool::TryAcquireResourceForPartialRaster( for (auto it = unused_resources_.begin(); it != unused_resources_.end(); ++it) { PoolResource* resource = it->get(); + if (resource->color_space() != raster_color_space) + continue; + if (resource->content_id() == previous_content_id) { UpdateResourceContentIdAndInvalidation(resource, new_content_id, new_invalidated_rect); diff --git a/cc/resources/resource_pool.h b/cc/resources/resource_pool.h index 700bba9b88f7eb..7d30ea14ed3423 100644 --- a/cc/resources/resource_pool.h +++ b/cc/resources/resource_pool.h @@ -215,7 +215,8 @@ class CC_EXPORT ResourcePool : public base::trace_event::MemoryDumpProvider { uint64_t new_content_id, const gfx::Rect& new_invalidated_rect, uint64_t previous_content_id, - gfx::Rect* total_invalidated_rect); + gfx::Rect* total_invalidated_rect, + const gfx::ColorSpace& raster_color_space); // Gives the InUsePoolResource a |resource_id_for_export()| in order to allow // exporting of the resource to the display compositor. This must be called diff --git a/cc/resources/resource_pool_unittest.cc b/cc/resources/resource_pool_unittest.cc index 86c079593b9eb6..cce05a91c38073 100644 --- a/cc/resources/resource_pool_unittest.cc +++ b/cc/resources/resource_pool_unittest.cc @@ -361,7 +361,8 @@ TEST_F(ResourcePoolTest, UpdateContentId) { gfx::Rect invalidated_rect; ResourcePool::InUsePoolResource reacquired_resource = resource_pool_->TryAcquireResourceForPartialRaster( - new_content_id, new_invalidated_rect, content_id, &invalidated_rect); + new_content_id, new_invalidated_rect, content_id, &invalidated_rect, + color_space); EXPECT_EQ(original_id, reacquired_resource.unique_id_for_testing()); EXPECT_EQ(new_invalidated_rect, invalidated_rect); resource_pool_->ReleaseResource(std::move(reacquired_resource)); @@ -388,7 +389,7 @@ TEST_F(ResourcePoolTest, UpdateContentIdAndInvalidatedRect) { ResourcePool::InUsePoolResource reacquired_resource = resource_pool_->TryAcquireResourceForPartialRaster( content_ids[1], invalidated_rect, content_ids[0], - &new_invalidated_rect); + &new_invalidated_rect, color_space); EXPECT_FALSE(!!reacquired_resource); EXPECT_EQ(gfx::Rect(), new_invalidated_rect); @@ -397,7 +398,8 @@ TEST_F(ResourcePoolTest, UpdateContentIdAndInvalidatedRect) { // Ensure that we cannot retrieve a resource based on the original content id. reacquired_resource = resource_pool_->TryAcquireResourceForPartialRaster( - content_ids[1], invalidated_rect, content_ids[0], &new_invalidated_rect); + content_ids[1], invalidated_rect, content_ids[0], &new_invalidated_rect, + color_space); EXPECT_FALSE(!!reacquired_resource); EXPECT_EQ(gfx::Rect(), new_invalidated_rect); @@ -406,7 +408,7 @@ TEST_F(ResourcePoolTest, UpdateContentIdAndInvalidatedRect) { gfx::Rect total_invalidated_rect; reacquired_resource = resource_pool_->TryAcquireResourceForPartialRaster( content_ids[2], second_invalidated_rect, content_ids[1], - &total_invalidated_rect); + &total_invalidated_rect, color_space); EXPECT_EQ(original_id, reacquired_resource.unique_id_for_testing()); EXPECT_EQ(expected_total_invalidated_rect, total_invalidated_rect); resource_pool_->ReleaseResource(std::move(reacquired_resource)); @@ -431,7 +433,7 @@ TEST_F(ResourcePoolTest, LargeInvalidatedRect) { ResourcePool::InUsePoolResource reacquired_resource = resource_pool_->TryAcquireResourceForPartialRaster( content_ids[1], large_invalidated_rect, content_ids[0], - &new_invalidated_rect); + &new_invalidated_rect, color_space); EXPECT_FALSE(!!reacquired_resource); // Release the original resource, returning it to the unused pool. @@ -441,7 +443,7 @@ TEST_F(ResourcePoolTest, LargeInvalidatedRect) { // too large to compute the area for. resource = resource_pool_->TryAcquireResourceForPartialRaster( content_ids[2], large_invalidated_rect, content_ids[1], - &new_invalidated_rect); + &new_invalidated_rect, color_space); EXPECT_TRUE(!!resource); resource_pool_->ReleaseResource(std::move(resource)); } diff --git a/cc/test/fake_tile_manager_client.cc b/cc/test/fake_tile_manager_client.cc index 032400bda6858c..355736f4019c1e 100644 --- a/cc/test/fake_tile_manager_client.cc +++ b/cc/test/fake_tile_manager_client.cc @@ -23,7 +23,8 @@ FakeTileManagerClient::BuildEvictionQueue(TreePriority tree_priority) { return nullptr; } -const gfx::ColorSpace& FakeTileManagerClient::GetRasterColorSpace() const { +gfx::ColorSpace FakeTileManagerClient::GetRasterColorSpace( + gfx::ContentColorUsage /*content_color_usage*/) const { return color_space_; } diff --git a/cc/test/fake_tile_manager_client.h b/cc/test/fake_tile_manager_client.h index 43527eb0ce6461..6fb3bd4c80ee26 100644 --- a/cc/test/fake_tile_manager_client.h +++ b/cc/test/fake_tile_manager_client.h @@ -27,7 +27,8 @@ class FakeTileManagerClient : public TileManagerClient { std::unique_ptr BuildEvictionQueue( TreePriority tree_priority) override; void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw) override {} - const gfx::ColorSpace& GetRasterColorSpace() const override; + gfx::ColorSpace GetRasterColorSpace( + gfx::ContentColorUsage content_color_usage) const override; void RequestImplSideInvalidationForCheckerImagedTiles() override {} size_t GetFrameIndexForImage(const PaintImage& paint_image, WhichTree tree) const override; diff --git a/cc/tiles/tile_manager.cc b/cc/tiles/tile_manager.cc index 4303c7a00325c7..14bded9068ccda 100644 --- a/cc/tiles/tile_manager.cc +++ b/cc/tiles/tile_manager.cc @@ -22,6 +22,7 @@ #include "cc/base/devtools_instrumentation.h" #include "cc/base/histograms.h" #include "cc/layers/picture_layer_impl.h" +#include "cc/paint/display_item_list.h" #include "cc/raster/paint_worklet_image_provider.h" #include "cc/raster/playback_image_provider.h" #include "cc/raster/raster_buffer.h" @@ -352,6 +353,17 @@ class DidFinishRunningAllTilesTask : public TileTask { CompletionCb completion_cb_; }; +gfx::ContentColorUsage GetContentColorUsageForPrioritizedTile( + const PrioritizedTile& prioritized_tile) { + // TODO(cblume,ccameron): Add support for HDR. + bool contains_only_srgb_images = prioritized_tile.raster_source() + ->GetDisplayItemList() + ->discardable_image_map() + .contains_only_srgb_images(); + return contains_only_srgb_images ? gfx::ContentColorUsage::kSRGB + : gfx::ContentColorUsage::kWideColorGamut; +} + } // namespace RasterTaskCompletionStats::RasterTaskCompletionStats() @@ -679,8 +691,6 @@ TileManager::PrioritizedWorkToSchedule TileManager::AssignGpuMemoryToTiles() { MemoryUsage memory_usage(resource_pool_->memory_usage_bytes(), resource_pool_->resource_count()); - gfx::ColorSpace raster_color_space = client_->GetRasterColorSpace(); - std::unique_ptr raster_priority_queue( client_->BuildRasterQueue(global_state_.tree_priority, RasterTilePriorityQueue::Type::ALL)); @@ -721,6 +731,11 @@ TileManager::PrioritizedWorkToSchedule TileManager::AssignGpuMemoryToTiles() { continue; } + auto content_color_usage = + GetContentColorUsageForPrioritizedTile(prioritized_tile); + const gfx::ColorSpace raster_color_space = + client_->GetRasterColorSpace(content_color_usage); + // Tiles in the raster queue should either require raster or decode for // checker-images. If this tile does not need raster, process it only to // build the decode queue for checkered images. @@ -799,8 +814,8 @@ TileManager::PrioritizedWorkToSchedule TileManager::AssignGpuMemoryToTiles() { } else { // Creating the raster task here will acquire resources, but // this resource usage has already been accounted for above. - auto raster_task = CreateRasterTask( - prioritized_tile, client_->GetRasterColorSpace(), &work_to_schedule); + auto raster_task = CreateRasterTask(prioritized_tile, raster_color_space, + &work_to_schedule); if (!raster_task) { continue; } @@ -836,6 +851,11 @@ TileManager::PrioritizedWorkToSchedule TileManager::AssignGpuMemoryToTiles() { if (!prioritized_tile.should_decode_checkered_images_for_tile()) continue; + auto content_color_usage = + GetContentColorUsageForPrioritizedTile(prioritized_tile); + gfx::ColorSpace raster_color_space = + client_->GetRasterColorSpace(content_color_usage); + Tile* tile = prioritized_tile.tile(); if (tile->draw_info().is_checker_imaged() || tile->raster_task_scheduled_with_checker_images()) { @@ -973,8 +993,6 @@ void TileManager::ScheduleTasks(PrioritizedWorkToSchedule work_to_schedule) { graph_.Reset(); - gfx::ColorSpace raster_color_space = client_->GetRasterColorSpace(); - scoped_refptr required_for_activation_done_task = CreateTaskSetFinishedTask( &TileManager::DidFinishRunningTileTasksRequiredForActivation); @@ -1028,6 +1046,11 @@ void TileManager::ScheduleTasks(PrioritizedWorkToSchedule work_to_schedule) { work_to_schedule.tiles_to_process_for_images; std::vector new_locked_images; for (const PrioritizedTile& prioritized_tile : tiles_to_process_for_images) { + auto content_color_usage = + GetContentColorUsageForPrioritizedTile(prioritized_tile); + gfx::ColorSpace raster_color_space = + client_->GetRasterColorSpace(content_color_usage); + std::vector sync_decoded_images; std::vector checkered_images; PartitionImagesForCheckering(prioritized_tile, raster_color_space, @@ -1143,7 +1166,7 @@ scoped_refptr TileManager::CreateRasterTask( if (UsePartialRaster(msaa_sample_count) && tile->invalidated_id()) { resource = resource_pool_->TryAcquireResourceForPartialRaster( tile->id(), tile->invalidated_content_rect(), tile->invalidated_id(), - &invalidated_rect); + &invalidated_rect, raster_color_space); } bool partial_tile_decode = false; diff --git a/cc/tiles/tile_manager.h b/cc/tiles/tile_manager.h index c41a1355440d08..8998ccb759a6d1 100644 --- a/cc/tiles/tile_manager.h +++ b/cc/tiles/tile_manager.h @@ -30,6 +30,7 @@ #include "cc/tiles/tile_draw_info.h" #include "cc/tiles/tile_manager_settings.h" #include "cc/tiles/tile_task_manager.h" +#include "ui/gfx/display_color_spaces.h" #include "url/gurl.h" namespace base { @@ -80,7 +81,8 @@ class CC_EXPORT TileManagerClient { virtual void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw) = 0; // Requests the color space into which tiles should be rasterized. - virtual const gfx::ColorSpace& GetRasterColorSpace() const = 0; + virtual gfx::ColorSpace GetRasterColorSpace( + gfx::ContentColorUsage content_color_usage) const = 0; // Requests that a pending tree be scheduled to invalidate content on the // pending on active tree. This is currently used when tiles that are @@ -206,7 +208,7 @@ class CC_EXPORT TileManager : CheckerImageTrackerClient { resource_pool_->AcquireResource( tiles[i]->desired_texture_size(), raster_buffer_provider_->GetResourceFormat(), - client_->GetRasterColorSpace()); + client_->GetRasterColorSpace(gfx::ContentColorUsage::kSRGB)); raster_buffer_provider_->AcquireBufferForRaster( resource, 0, 0, /*depends_on_at_raster_decodes=*/false, diff --git a/cc/tiles/tile_manager_unittest.cc b/cc/tiles/tile_manager_unittest.cc index dc0be3ff8fc9d4..fad7fbbe27f5ba 100644 --- a/cc/tiles/tile_manager_unittest.cc +++ b/cc/tiles/tile_manager_unittest.cc @@ -1949,8 +1949,8 @@ TEST_F(PartialRasterTileManagerTest, CancelledTasksHaveNoContentId) { // with its invalidated resource ID. gfx::Rect total_invalidated_rect; EXPECT_FALSE(host_impl()->resource_pool()->TryAcquireResourceForPartialRaster( - kInvalidatedId + 1, gfx::Rect(), kInvalidatedId, - &total_invalidated_rect)); + kInvalidatedId + 1, gfx::Rect(), kInvalidatedId, &total_invalidated_rect, + gfx::ColorSpace::CreateSRGB())); EXPECT_EQ(gfx::Rect(), total_invalidated_rect); // Free our host_impl_ before the tile_task_manager we passed it, as it @@ -2007,8 +2007,8 @@ void RunPartialRasterCheck(std::unique_ptr host_impl, // Ensure there's a resource with our |kInvalidatedId| in the resource pool. ResourcePool::InUsePoolResource resource = - host_impl->resource_pool()->AcquireResource(kTileSize, viz::RGBA_8888, - gfx::ColorSpace()); + host_impl->resource_pool()->AcquireResource( + kTileSize, viz::RGBA_8888, gfx::ColorSpace::CreateSRGB()); resource.set_software_backing(std::make_unique()); host_impl->resource_pool()->PrepareForExport(resource); @@ -2072,8 +2072,8 @@ void RunPartialTileDecodeCheck(std::unique_ptr host_impl, // Ensure there's a resource with our |kInvalidatedId| in the resource pool. ResourcePool::InUsePoolResource resource = - host_impl->resource_pool()->AcquireResource(kTileSize, viz::RGBA_8888, - gfx::ColorSpace()); + host_impl->resource_pool()->AcquireResource( + kTileSize, viz::RGBA_8888, gfx::ColorSpace::CreateSRGB()); host_impl->resource_pool()->OnContentReplaced(resource, kInvalidatedId); host_impl->resource_pool()->ReleaseResource(std::move(resource)); diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index 14ee51b5a50019..31151814f9b3f7 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -1808,14 +1808,21 @@ void LayerTreeHostImpl::SetIsLikelyToRequireADraw( is_likely_to_require_a_draw_ = is_likely_to_require_a_draw; } -const gfx::ColorSpace& LayerTreeHostImpl::GetRasterColorSpace() const { - const gfx::ColorSpace* result = nullptr; +gfx::ColorSpace LayerTreeHostImpl::GetRasterColorSpace( + gfx::ContentColorUsage content_color_usage) const { + constexpr gfx::ColorSpace srgb = gfx::ColorSpace::CreateSRGB(); + + if (settings_.prefer_raster_in_srgb && + content_color_usage == gfx::ContentColorUsage::kSRGB) + return srgb; + + gfx::ColorSpace result; // The pending tree will have the most recently updated color space, so // prefer that. if (pending_tree_) { - result = &pending_tree_->raster_color_space(); + result = pending_tree_->raster_color_space(); } else if (active_tree_) { - result = &active_tree_->raster_color_space(); + result = active_tree_->raster_color_space(); } // If we are likely to software composite the resource, we use sRGB because @@ -1824,10 +1831,10 @@ const gfx::ColorSpace& LayerTreeHostImpl::GetRasterColorSpace() const { // (not specifying a color space indicates that no color conversion is // required). if (!layer_tree_frame_sink_ || !layer_tree_frame_sink_->context_provider() || - !result || !result->IsValid()) { - result = &default_color_space_; + !result.IsValid()) { + result = srgb; } - return *result; + return result; } void LayerTreeHostImpl::RequestImplSideInvalidationForCheckerImagedTiles() { @@ -3372,8 +3379,11 @@ void LayerTreeHostImpl::QueueImageDecode(int request_id, image.GetKeyForFrame(PaintImage::kDefaultFrameIndex).ToString()); // Optimistically specify the current raster color space, since we assume that // it won't change. + auto content_color_usage = image.isSRGB() + ? gfx::ContentColorUsage::kSRGB + : gfx::ContentColorUsage::kWideColorGamut; tile_manager_.decoded_image_tracker().QueueImageDecode( - image, GetRasterColorSpace(), + image, GetRasterColorSpace(content_color_usage), base::BindOnce(&LayerTreeHostImpl::ImageDecodeFinished, weak_factory_.GetWeakPtr(), request_id)); tile_manager_.checker_image_tracker().DisallowCheckeringForImage(image); diff --git a/cc/trees/layer_tree_host_impl.h b/cc/trees/layer_tree_host_impl.h index d5e9be90ea789d..88d9fede1addd1 100644 --- a/cc/trees/layer_tree_host_impl.h +++ b/cc/trees/layer_tree_host_impl.h @@ -470,7 +470,8 @@ class CC_EXPORT LayerTreeHostImpl : public InputHandler, std::unique_ptr BuildEvictionQueue( TreePriority tree_priority) override; void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw) override; - const gfx::ColorSpace& GetRasterColorSpace() const override; + gfx::ColorSpace GetRasterColorSpace( + gfx::ContentColorUsage content_color_usage) const override; void RequestImplSideInvalidationForCheckerImagedTiles() override; size_t GetFrameIndexForImage(const PaintImage& paint_image, WhichTree tree) const override; @@ -1043,8 +1044,6 @@ class CC_EXPORT LayerTreeHostImpl : public InputHandler, // This is usually turned on only in some tests (e.g. web-tests). const bool is_synchronous_single_threaded_; - const gfx::ColorSpace default_color_space_ = gfx::ColorSpace::CreateSRGB(); - viz::ClientResourceProvider resource_provider_; std::unordered_map ui_resource_map_; diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc index 68a8403579a592..26c2dc8f04f133 100644 --- a/cc/trees/layer_tree_host_impl_unittest.cc +++ b/cc/trees/layer_tree_host_impl_unittest.cc @@ -13666,22 +13666,46 @@ TEST_F(LayerTreeHostImplTest, RasterColorSpace) { LayerTreeSettings settings = DefaultSettings(); CreateHostImpl(settings, CreateLayerTreeFrameSink()); // The default raster color space should be sRGB. - EXPECT_EQ(host_impl_->GetRasterColorSpace(), gfx::ColorSpace::CreateSRGB()); + EXPECT_EQ( + host_impl_->GetRasterColorSpace(gfx::ContentColorUsage::kWideColorGamut), + gfx::ColorSpace::CreateSRGB()); // The raster color space should update with tree activation. host_impl_->active_tree()->SetRasterColorSpace( gfx::ColorSpace::CreateDisplayP3D65()); - EXPECT_EQ(host_impl_->GetRasterColorSpace(), - gfx::ColorSpace::CreateDisplayP3D65()); + EXPECT_EQ( + host_impl_->GetRasterColorSpace(gfx::ContentColorUsage::kWideColorGamut), + gfx::ColorSpace::CreateDisplayP3D65()); } TEST_F(LayerTreeHostImplTest, RasterColorSpaceSoftware) { LayerTreeSettings settings = DefaultSettings(); CreateHostImpl(settings, FakeLayerTreeFrameSink::CreateSoftware()); // Software composited resources should always use sRGB as their color space. - EXPECT_EQ(host_impl_->GetRasterColorSpace(), gfx::ColorSpace::CreateSRGB()); + EXPECT_EQ( + host_impl_->GetRasterColorSpace(gfx::ContentColorUsage::kWideColorGamut), + gfx::ColorSpace::CreateSRGB()); host_impl_->active_tree()->SetRasterColorSpace( gfx::ColorSpace::CreateDisplayP3D65()); - EXPECT_EQ(host_impl_->GetRasterColorSpace(), gfx::ColorSpace::CreateSRGB()); + EXPECT_EQ( + host_impl_->GetRasterColorSpace(gfx::ContentColorUsage::kWideColorGamut), + gfx::ColorSpace::CreateSRGB()); +} + +TEST_F(LayerTreeHostImplTest, RasterColorPrefersSRGB) { + auto p3 = gfx::ColorSpace::CreateDisplayP3D65(); + + LayerTreeSettings settings = DefaultSettings(); + settings.prefer_raster_in_srgb = true; + CreateHostImpl(settings, CreateLayerTreeFrameSink()); + host_impl_->active_tree()->SetRasterColorSpace(p3); + + EXPECT_EQ(host_impl_->GetRasterColorSpace(gfx::ContentColorUsage::kSRGB), + gfx::ColorSpace::CreateSRGB()); + + settings.prefer_raster_in_srgb = false; + CreateHostImpl(settings, CreateLayerTreeFrameSink()); + host_impl_->active_tree()->SetRasterColorSpace(p3); + EXPECT_EQ(host_impl_->GetRasterColorSpace(gfx::ContentColorUsage::kSRGB), p3); } TEST_F(LayerTreeHostImplTest, UpdatedTilingsForNonDrawingLayers) { diff --git a/cc/trees/layer_tree_settings.h b/cc/trees/layer_tree_settings.h index 799ea55b4d74fa..02e956d484f5a9 100644 --- a/cc/trees/layer_tree_settings.h +++ b/cc/trees/layer_tree_settings.h @@ -106,6 +106,11 @@ class CC_EXPORT LayerTreeSettings { // ready. bool enable_checker_imaging = false; + // When content needs a wide color gamut, raster in wide if available. + // But when the content is sRGB, some situations prefer to raster in + // wide while others prefer to raster in sRGB. + bool prefer_raster_in_srgb = false; + // The minimum size of an image we should considering decoding using the // deferred path. size_t min_image_bytes_to_checker = 1 * 1024 * 1024; // 1MB. diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index 56d705abc4e917..ad03a6a54a8b22 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -3000,6 +3000,7 @@ jumbo_static_library("browser") { "//components/resources:components_resources", "//components/send_tab_to_self", "//components/signin/internal/identity_manager", # cf android/signin/DEPS + "//components/viz/common", "//media/mojo/clients", "//rlz:rlz_utils", "//sandbox", diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 3edb48cbb504b1..34494e222cf148 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -4,7 +4,6 @@ #include "chrome/browser/chrome_content_browser_client.h" -#include #include #include #include @@ -258,6 +257,7 @@ #include "components/variations/variations_http_header_provider.h" #include "components/variations/variations_switches.h" #include "components/version_info/version_info.h" +#include "components/viz/common/viz_utils.h" #include "content/public/browser/browser_child_process_host.h" #include "content/public/browser/browser_main_parts.h" #include "content/public/browser/browser_ppapi_host.h" @@ -396,7 +396,6 @@ #include "chrome/browser/chrome_browser_main_linux.h" #elif defined(OS_ANDROID) #include "base/android/application_status_listener.h" -#include "base/android/build_info.h" #include "chrome/android/features/dev_ui/buildflags.h" #include "chrome/android/modules/extra_icu/provider/module_provider.h" #include "chrome/browser/android/app_hooks.h" @@ -882,26 +881,6 @@ float GetDeviceScaleAdjustment() { (kWidthForMaxFSM - kWidthForMinFSM); return ratio * (kMaxFSM - kMinFSM) + kMinFSM; } - -bool UseDisplayWideColorGamut() { - auto compute_use_display_wide_color_gamut = []() { - const char* current_model = - base::android::BuildInfo::GetInstance()->model(); - const std::array enabled_models = { - std::string{"Pixel 4"}, std::string{"Pixel 4 XL"}}; - for (const std::string& model : enabled_models) { - if (model == current_model) - return true; - } - - return false; - }; - - // As it takes some work to compute this, cache the result. - static base::NoDestructor is_wide_color_gamut_enabled( - compute_use_display_wide_color_gamut()); - return *is_wide_color_gamut_enabled; -} #endif // defined(OS_ANDROID) #if BUILDFLAG(ENABLE_EXTENSIONS) @@ -5364,7 +5343,7 @@ ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext( #if defined(OS_ANDROID) content::ContentBrowserClient::WideColorGamutHeuristic ChromeContentBrowserClient::GetWideColorGamutHeuristic() { - if (UseDisplayWideColorGamut() || + if (viz::AlwaysUseWideColorGamut() || base::FeatureList::IsEnabled(features::kDynamicColorGamut)) { return WideColorGamutHeuristic::kUseDisplay; } diff --git a/components/viz/common/viz_utils.cc b/components/viz/common/viz_utils.cc index 53a251446f29f7..5d1dd3dac731bc 100644 --- a/components/viz/common/viz_utils.cc +++ b/components/viz/common/viz_utils.cc @@ -5,10 +5,16 @@ #include "components/viz/common/viz_utils.h" #include "base/system/sys_info.h" -#include "build/build_config.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/rrect_f.h" +#if defined(OS_ANDROID) +#include + +#include "base/android/build_info.h" +#include "base/no_destructor.h" +#endif + namespace viz { bool PreferRGB565ResourcesForDisplay() { @@ -18,6 +24,28 @@ bool PreferRGB565ResourcesForDisplay() { return false; } +#if defined(OS_ANDROID) +bool AlwaysUseWideColorGamut() { + auto compute_always_use_wide_color_gamut = []() { + const char* current_model = + base::android::BuildInfo::GetInstance()->model(); + const std::array enabled_models = { + std::string{"Pixel 4"}, std::string{"Pixel 4 XL"}}; + for (const std::string& model : enabled_models) { + if (model == current_model) + return true; + } + + return false; + }; + + // As it takes some work to compute this, cache the result. + static base::NoDestructor is_always_use_wide_color_gamut_enabled( + compute_always_use_wide_color_gamut()); + return *is_always_use_wide_color_gamut_enabled; +} +#endif + bool GetScaledRegion(const gfx::Rect& rect, const gfx::QuadF* clip, gfx::QuadF* scaled_region) { diff --git a/components/viz/common/viz_utils.h b/components/viz/common/viz_utils.h index f290152948e972..be7ea5e5bc5408 100644 --- a/components/viz/common/viz_utils.h +++ b/components/viz/common/viz_utils.h @@ -7,6 +7,8 @@ #include "components/viz/common/viz_common_export.h" +#include "build/build_config.h" + namespace gfx { class Rect; class RRectF; @@ -16,6 +18,11 @@ class QuadF; namespace viz { VIZ_COMMON_EXPORT bool PreferRGB565ResourcesForDisplay(); + +#if defined(OS_ANDROID) +VIZ_COMMON_EXPORT bool AlwaysUseWideColorGamut(); +#endif + // This takes a gfx::Rect and a clip region quad in the same space, // and returns a quad with the same proportions in the space -0.5->0.5. VIZ_COMMON_EXPORT bool GetScaledRegion(const gfx::Rect& rect,