Commit c6959582 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

Set ContentColorUsage in more quad types, aggregate in prewalk

Add ContentColorUsage to the SurfaceAggregator's PrewalkResult, and
populate it during the pre-walk step.

Add implementations of the GetContentColorUsage method to
TextureLayerImpl, VideoLayerImpl. Set the corresponding
CompositorFrameMetadata for VideoResourceUpdater as well.

Bug: 955158, 976426
Change-Id: Iae00a5c413e3bb893cdc84319d8426b30b357667
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2036634Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738072}
parent d0bb7fa8
...@@ -64,6 +64,7 @@ class CC_EXPORT PictureLayerImpl ...@@ -64,6 +64,7 @@ class CC_EXPORT PictureLayerImpl
void RecreateTileResources() override; void RecreateTileResources() override;
Region GetInvalidationRegionForDebugging() override; Region GetInvalidationRegionForDebugging() override;
gfx::Rect GetEnclosingRectInTargetSpace() const override; gfx::Rect GetEnclosingRectInTargetSpace() const override;
gfx::ContentColorUsage GetContentColorUsage() const override;
// PictureLayerTilingClient overrides. // PictureLayerTilingClient overrides.
std::unique_ptr<Tile> CreateTile(const Tile::CreateInfo& info) override; std::unique_ptr<Tile> CreateTile(const Tile::CreateInfo& info) override;
...@@ -157,8 +158,6 @@ class CC_EXPORT PictureLayerImpl ...@@ -157,8 +158,6 @@ class CC_EXPORT PictureLayerImpl
// an animation, at which point the PaintWorklet must be re-painted. // an animation, at which point the PaintWorklet must be re-painted.
void InvalidatePaintWorklets(const PaintWorkletInput::PropertyKey& key); void InvalidatePaintWorklets(const PaintWorkletInput::PropertyKey& key);
gfx::ContentColorUsage GetContentColorUsage() const override;
protected: protected:
PictureLayerImpl(LayerTreeImpl* tree_impl, int id); PictureLayerImpl(LayerTreeImpl* tree_impl, int id);
PictureLayerTiling* AddTiling(const gfx::AxisTransform2d& contents_transform); PictureLayerTiling* AddTiling(const gfx::AxisTransform2d& contents_transform);
......
...@@ -200,6 +200,10 @@ void TextureLayerImpl::ReleaseResources() { ...@@ -200,6 +200,10 @@ void TextureLayerImpl::ReleaseResources() {
// all) instead. // all) instead.
} }
gfx::ContentColorUsage TextureLayerImpl::GetContentColorUsage() const {
return transferable_resource_.color_space.GetContentColorUsage();
}
void TextureLayerImpl::SetPremultipliedAlpha(bool premultiplied_alpha) { void TextureLayerImpl::SetPremultipliedAlpha(bool premultiplied_alpha) {
premultiplied_alpha_ = premultiplied_alpha; premultiplied_alpha_ = premultiplied_alpha;
} }
......
...@@ -44,6 +44,7 @@ class CC_EXPORT TextureLayerImpl : public LayerImpl { ...@@ -44,6 +44,7 @@ class CC_EXPORT TextureLayerImpl : public LayerImpl {
SimpleEnclosedRegion VisibleOpaqueRegion() const override; SimpleEnclosedRegion VisibleOpaqueRegion() const override;
void ReleaseResources() override; void ReleaseResources() override;
void OnPurgeMemory() override; void OnPurgeMemory() override;
gfx::ContentColorUsage GetContentColorUsage() const override;
// These setter methods don't cause any implicit damage, so the texture client // These setter methods don't cause any implicit damage, so the texture client
// must explicitly invalidate if they intend to cause a visible change in the // must explicitly invalidate if they intend to cause a visible change in the
......
...@@ -187,6 +187,13 @@ void VideoLayerImpl::ReleaseResources() { ...@@ -187,6 +187,13 @@ void VideoLayerImpl::ReleaseResources() {
updater_ = nullptr; updater_ = nullptr;
} }
gfx::ContentColorUsage VideoLayerImpl::GetContentColorUsage() const {
gfx::ColorSpace frame_color_space;
if (frame_)
frame_color_space = frame_->ColorSpace();
return frame_color_space.GetContentColorUsage();
}
void VideoLayerImpl::SetNeedsRedraw() { void VideoLayerImpl::SetNeedsRedraw() {
UnionUpdateRect(gfx::Rect(bounds())); UnionUpdateRect(gfx::Rect(bounds()));
layer_tree_impl()->SetNeedsRedraw(); layer_tree_impl()->SetNeedsRedraw();
......
...@@ -45,6 +45,7 @@ class CC_EXPORT VideoLayerImpl : public LayerImpl { ...@@ -45,6 +45,7 @@ class CC_EXPORT VideoLayerImpl : public LayerImpl {
SimpleEnclosedRegion VisibleOpaqueRegion() const override; SimpleEnclosedRegion VisibleOpaqueRegion() const override;
void DidBecomeActive() override; void DidBecomeActive() override;
void ReleaseResources() override; void ReleaseResources() override;
gfx::ContentColorUsage GetContentColorUsage() const override;
void SetNeedsRedraw(); void SetNeedsRedraw();
media::VideoRotation video_rotation() const { return video_rotation_; } media::VideoRotation video_rotation() const { return video_rotation_; }
......
...@@ -77,26 +77,6 @@ bool CalculateQuadSpaceDamageRect( ...@@ -77,26 +77,6 @@ bool CalculateQuadSpaceDamageRect(
return true; return true;
} }
gfx::ContentColorUsage FindWidestContentColorUsage(
Surface* root_surface,
base::flat_set<SurfaceId> referenced_surfaces,
const SurfaceManager& manager) {
gfx::ContentColorUsage result = gfx::ContentColorUsage::kSRGB;
result = std::max(
result, root_surface->GetActiveFrame().metadata.content_color_usage);
for (auto& referenced_surface_id : referenced_surfaces) {
Surface* referenced_surface =
manager.GetSurfaceForId(referenced_surface_id);
result = std::max(
result,
referenced_surface->GetActiveFrame().metadata.content_color_usage);
}
return result;
}
} // namespace } // namespace
struct SurfaceAggregator::ClipData { struct SurfaceAggregator::ClipData {
...@@ -113,6 +93,7 @@ struct SurfaceAggregator::PrewalkResult { ...@@ -113,6 +93,7 @@ struct SurfaceAggregator::PrewalkResult {
// not included in a SurfaceDrawQuad. // not included in a SurfaceDrawQuad.
base::flat_set<SurfaceId> undrawn_surfaces; base::flat_set<SurfaceId> undrawn_surfaces;
bool may_contain_video = false; bool may_contain_video = false;
gfx::ContentColorUsage content_color_usage = gfx::ContentColorUsage::kSRGB;
}; };
struct SurfaceAggregator::RoundedCornerInfo { struct SurfaceAggregator::RoundedCornerInfo {
...@@ -599,7 +580,7 @@ void SurfaceAggregator::EmitSurfaceContent( ...@@ -599,7 +580,7 @@ void SurfaceAggregator::EmitSurfaceContent(
source.transform_to_root_target, source.filters, source.transform_to_root_target, source.filters,
source.backdrop_filters, source.backdrop_filter_bounds, source.backdrop_filters, source.backdrop_filter_bounds,
display_color_spaces_.GetCompositingColorSpace( display_color_spaces_.GetCompositingColorSpace(
source.has_transparent_background, display_content_color_usage_), source.has_transparent_background, root_content_color_usage_),
source.has_transparent_background, source.cache_render_pass, source.has_transparent_background, source.cache_render_pass,
source.has_damage_from_contributing_content, source.generate_mipmap); source.has_damage_from_contributing_content, source.generate_mipmap);
...@@ -1184,7 +1165,7 @@ void SurfaceAggregator::CopyPasses(const CompositorFrame& frame, ...@@ -1184,7 +1165,7 @@ void SurfaceAggregator::CopyPasses(const CompositorFrame& frame,
remapped_pass_id, output_rect, damage_rect, transform_to_root_target, remapped_pass_id, output_rect, damage_rect, transform_to_root_target,
source.filters, source.backdrop_filters, source.backdrop_filter_bounds, source.filters, source.backdrop_filters, source.backdrop_filter_bounds,
display_color_spaces_.GetCompositingColorSpace( display_color_spaces_.GetCompositingColorSpace(
source.has_transparent_background, display_content_color_usage_), source.has_transparent_background, root_content_color_usage_),
source.has_transparent_background, source.cache_render_pass, source.has_transparent_background, source.cache_render_pass,
source.has_damage_from_contributing_content, source.generate_mipmap); source.has_damage_from_contributing_content, source.generate_mipmap);
...@@ -1538,6 +1519,8 @@ gfx::Rect SurfaceAggregator::PrewalkTree(Surface* surface, ...@@ -1538,6 +1519,8 @@ gfx::Rect SurfaceAggregator::PrewalkTree(Surface* surface,
referenced_surfaces_.erase(surface->surface_id()); referenced_surfaces_.erase(surface->surface_id());
if (!damage_rect.IsEmpty() && frame.metadata.may_contain_video) if (!damage_rect.IsEmpty() && frame.metadata.may_contain_video)
result->may_contain_video = true; result->may_contain_video = true;
result->content_color_usage =
std::max(result->content_color_usage, frame.metadata.content_color_usage);
// Repeat this operation until no new render pass with pixel moving backdrop // Repeat this operation until no new render pass with pixel moving backdrop
// filter intersects with the damage rect. // filter intersects with the damage rect.
...@@ -1685,14 +1668,12 @@ CompositorFrame SurfaceAggregator::Aggregate( ...@@ -1685,14 +1668,12 @@ CompositorFrame SurfaceAggregator::Aggregate(
PrewalkResult prewalk_result; PrewalkResult prewalk_result;
root_damage_rect_ = root_damage_rect_ =
PrewalkTree(surface, false, 0, true /* will_draw */, &prewalk_result); PrewalkTree(surface, false, 0, true /* will_draw */, &prewalk_result);
root_content_color_usage_ = prewalk_result.content_color_usage;
PropagateCopyRequestPasses(); PropagateCopyRequestPasses();
has_copy_requests_ = !copy_request_passes_.empty(); has_copy_requests_ = !copy_request_passes_.empty();
frame.metadata.may_contain_video = prewalk_result.may_contain_video; frame.metadata.may_contain_video = prewalk_result.may_contain_video;
frame.metadata.content_color_usage = prewalk_result.content_color_usage;
display_content_color_usage_ =
FindWidestContentColorUsage(surface, referenced_surfaces_, *manager_);
frame.metadata.content_color_usage = display_content_color_usage_;
CopyUndrawnSurfaces(&prewalk_result); CopyUndrawnSurfaces(&prewalk_result);
referenced_surfaces_.insert(surface_id); referenced_surfaces_.insert(surface_id);
......
...@@ -305,7 +305,7 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator { ...@@ -305,7 +305,7 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator {
// blending color space (e.g. for HDR), then a final render pass to convert // blending color space (e.g. for HDR), then a final render pass to convert
// between the two will be added. This space must always be valid. // between the two will be added. This space must always be valid.
gfx::DisplayColorSpaces display_color_spaces_; gfx::DisplayColorSpaces display_color_spaces_;
gfx::ContentColorUsage display_content_color_usage_;
// Maximum texture size which if positive, will limit the size of render // Maximum texture size which if positive, will limit the size of render
// passes. // passes.
int max_texture_size_ = 0; int max_texture_size_ = 0;
...@@ -363,6 +363,13 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator { ...@@ -363,6 +363,13 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator {
// The root damage rect of the currently-aggregating frame. // The root damage rect of the currently-aggregating frame.
gfx::Rect root_damage_rect_; gfx::Rect root_damage_rect_;
// The aggregate color content usage of the currently-aggregating frame. This
// is computed by the prewalk, and is used to determine the format and color
// space of all render passes. Note that that is more heavy-handed than is
// desirable.
gfx::ContentColorUsage root_content_color_usage_ =
gfx::ContentColorUsage::kSRGB;
// Occluding damage rect will be calculated for qualified candidates // Occluding damage rect will be calculated for qualified candidates
const bool needs_surface_occluding_damage_rect_; const bool needs_surface_occluding_damage_rect_;
......
...@@ -578,6 +578,8 @@ viz::CompositorFrame VideoFrameSubmitter::CreateCompositorFrame( ...@@ -578,6 +578,8 @@ viz::CompositorFrame VideoFrameSubmitter::CreateCompositorFrame(
gfx::Transform()); gfx::Transform());
if (video_frame) { if (video_frame) {
compositor_frame.metadata.content_color_usage =
video_frame->ColorSpace().GetContentColorUsage();
const bool is_opaque = media::IsOpaque(video_frame->format()); const bool is_opaque = media::IsOpaque(video_frame->format());
resource_provider_->AppendQuads(render_pass.get(), std::move(video_frame), resource_provider_->AppendQuads(render_pass.get(), std::move(video_frame),
rotation_, is_opaque); rotation_, is_opaque);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "third_party/skia/include/core/SkColorSpace.h" #include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkData.h" #include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkICC.h" #include "third_party/skia/include/core/SkICC.h"
#include "ui/gfx/display_color_spaces.h"
#include "ui/gfx/icc_profile.h" #include "ui/gfx/icc_profile.h"
#include "ui/gfx/skia_color_space_util.h" #include "ui/gfx/skia_color_space_util.h"
...@@ -496,6 +497,14 @@ ColorSpace ColorSpace::GetAsFullRangeRGB() const { ...@@ -496,6 +497,14 @@ ColorSpace ColorSpace::GetAsFullRangeRGB() const {
return result; return result;
} }
ContentColorUsage ColorSpace::GetContentColorUsage() const {
if (IsHDR())
return ContentColorUsage::kHDR;
if (IsWide())
return ContentColorUsage::kWideColorGamut;
return ContentColorUsage::kSRGB;
}
ColorSpace ColorSpace::GetAsRGB() const { ColorSpace ColorSpace::GetAsRGB() const {
ColorSpace result(*this); ColorSpace result(*this);
if (IsValid()) if (IsValid())
......
...@@ -36,6 +36,8 @@ struct _GLcolorSpace; ...@@ -36,6 +36,8 @@ struct _GLcolorSpace;
namespace gfx { namespace gfx {
enum class ContentColorUsage : uint8_t;
namespace mojom { namespace mojom {
class ColorSpaceDataView; class ColorSpaceDataView;
} // namespace mojom } // namespace mojom
...@@ -243,6 +245,9 @@ class COLOR_SPACE_EXPORT ColorSpace { ...@@ -243,6 +245,9 @@ class COLOR_SPACE_EXPORT ColorSpace {
// Returns true if the encoded values can be outside of the 0.0-1.0 range. // Returns true if the encoded values can be outside of the 0.0-1.0 range.
bool FullRangeEncodedValues() const; bool FullRangeEncodedValues() const;
// Returns the color space's content color usage category (sRGB, WCG, or HDR).
ContentColorUsage GetContentColorUsage() const;
// Return this color space with any YUV to RGB conversion stripped off. // Return this color space with any YUV to RGB conversion stripped off.
ColorSpace GetAsRGB() const; ColorSpace GetAsRGB() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment