#ifndef CC_LAYERS_LAYER_IMPL_H_
#define CC_LAYERS_LAYER_IMPL_H_
#include <stddef.h>
#include <stdint.h>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "arkweb/build/features/features.h"
#include "base/check.h"
#include "base/containers/flat_set.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "cc/base/region.h"
#include "cc/base/synced_property.h"
#include "cc/cc_export.h"
#include "cc/debug/layer_tree_debug_state.h"
#include "cc/input/hit_test_opaqueness.h"
#include "cc/input/input_handler.h"
#include "cc/layers/draw_mode.h"
#include "cc/layers/draw_properties.h"
#include "cc/layers/layer_collections.h"
#include "cc/layers/render_surface_impl.h"
#include "cc/layers/scroll_hit_test_rect.h"
#include "cc/layers/touch_action_region.h"
#include "cc/mojom/layer_type.mojom.h"
#include "cc/paint/element_id.h"
#include "cc/tiles/tile_priority.h"
#include "cc/trees/damage_reason.h"
#include "cc/trees/target_property.h"
#include "components/viz/common/quads/shared_quad_state.h"
#include "components/viz/common/surfaces/region_capture_bounds.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/display_color_spaces.h"
#include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/transform.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "arkweb/chromium_ext/cc/layer/layer_impl_utils.h"
namespace viz {
class ClientResourceProvider;
class CompositorRenderPass;
}
namespace cc {
class AppendQuadsData;
struct AppendQuadsContext;
struct LayerDebugInfo;
class LayerTreeImpl;
class MicroBenchmarkImpl;
class PrioritizedTile;
class SimpleEnclosedRegion;
class Tile;
class LayerImplUtils;
enum ViewportLayerType {
NOT_VIEWPORT_LAYER,
INNER_VIEWPORT_CONTAINER,
OUTER_VIEWPORT_CONTAINER,
INNER_VIEWPORT_SCROLL,
OUTER_VIEWPORT_SCROLL,
LAST_VIEWPORT_LAYER_TYPE = OUTER_VIEWPORT_SCROLL,
};
class CC_EXPORT LayerImpl {
public:
static std::unique_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) {
return base::WrapUnique(new LayerImpl(tree_impl, id));
}
LayerImpl(const LayerImpl&) = delete;
virtual ~LayerImpl();
virtual mojom::LayerType GetLayerType() const;
LayerImpl& operator=(const LayerImpl&) = delete;
int id() const { return layer_id_; }
int stable_id_for_shared_quad_state() const {
return stable_id_for_shared_quad_state_;
}
static int GetNextStableIdForSharedQuadState();
bool IsActive() const;
void SetHasTransformNode(bool val);
bool has_transform_node() const { return has_transform_node_; }
void set_property_tree_sequence_number(int sequence_number) {}
void SetTransformTreeIndex(int index);
int transform_tree_index() const { return transform_tree_index_; }
void SetClipTreeIndex(int index);
int clip_tree_index() const { return clip_tree_index_; }
void SetEffectTreeIndex(int index);
int effect_tree_index() const { return effect_tree_index_; }
int render_target_effect_tree_index() const;
void SetScrollTreeIndex(int index);
int scroll_tree_index() const { return scroll_tree_index_; }
void SetOffsetToTransformParent(const gfx::Vector2dF& offset);
gfx::Vector2dF offset_to_transform_parent() const {
return offset_to_transform_parent_;
}
bool is_clipped() const { return draw_properties_.is_clipped; }
LayerTreeImpl* layer_tree_impl() const { return layer_tree_impl_; }
void PopulateSharedQuadState(viz::SharedQuadState* state,
bool contents_opaque) const;
void PopulateScaledSharedQuadState(viz::SharedQuadState* state,
float layer_to_content_scale,
bool contents_opaque) const;
void PopulateScaledSharedQuadStateWithContentRects(
viz::SharedQuadState* state,
float layer_to_content_scale,
const gfx::Rect& content_rect,
const gfx::Rect& content_visible_rect,
bool contents_opaque) const;
virtual bool WillDraw(DrawMode draw_mode,
viz::ClientResourceProvider* resource_provider);
virtual void AppendQuads(const AppendQuadsContext& context,
viz::CompositorRenderPass* render_pass,
AppendQuadsData* append_quads_data) {}
virtual void DidDraw(viz::ClientResourceProvider* resource_provider) {}
void ValidateQuadResources(viz::DrawQuad* quad) const {
#if DCHECK_IS_ON()
ValidateQuadResourcesInternal(quad);
#endif
}
virtual void GetContentsResourceId(viz::ResourceId* resource_id,
gfx::Size* resource_size,
gfx::SizeF* resource_uv_size) const;
virtual void NotifyTileStateChanged(const Tile* tile, bool update_damage) {}
virtual bool IsScrollbarLayer() const;
bool IsScrollerOrScrollbar() const;
void SetDrawsContent(bool draws_content);
bool draws_content() const { return draws_content_; }
HitTestOpaqueness hit_test_opaqueness() const { return hit_test_opaqueness_; }
void SetHitTestOpaqueness(HitTestOpaqueness opaqueness);
bool HitTestable() const;
bool OpaqueToHitTest() const;
void SetBackgroundColor(SkColor4f background_color);
SkColor4f background_color() const { return background_color_; }
void SetSafeOpaqueBackgroundColor(SkColor4f background_color);
SkColor4f safe_opaque_background_color() const {
DCHECK_EQ(contents_opaque(), safe_opaque_background_color_.isOpaque());
return safe_opaque_background_color_;
}
void SetContentsOpaque(bool opaque);
bool contents_opaque() const { return contents_opaque_; }
void SetContentsOpaqueForText(bool opaque);
bool contents_opaque_for_text() const { return contents_opaque_for_text_; }
float Opacity() const;
void SetElementId(ElementId element_id);
ElementId element_id() const { return element_id_; }
bool IsAffectedByPageScale() const;
bool Is3dSorted() const { return GetSortingContextId() != 0; }
void SetShouldCheckBackfaceVisibility(bool should_check_backface_visibility);
bool should_check_backface_visibility() const {
return should_check_backface_visibility_;
}
bool ShowDebugBorders(DebugBorderType type) const;
RenderSurfaceImpl* render_target();
const RenderSurfaceImpl* render_target() const;
DrawProperties& draw_properties() { return draw_properties_; }
const DrawProperties& draw_properties() const { return draw_properties_; }
gfx::Transform DrawTransform() const;
gfx::Transform ScreenSpaceTransform() const;
void SetVisibleLayerRectForTesting(const gfx::Rect& visible_rect) {
draw_properties_.visible_layer_rect = visible_rect;
}
float draw_opacity() const { return draw_properties_.opacity; }
bool screen_space_transform_is_animating() const {
return draw_properties_.screen_space_transform_is_animating;
}
gfx::Rect clip_rect() const { return draw_properties_.clip_rect; }
gfx::Rect visible_drawable_content_rect() const {
return draw_properties_.visible_drawable_content_rect;
}
gfx::Rect visible_layer_rect() const {
return draw_properties_.visible_layer_rect;
}
void SetBounds(const gfx::Size& bounds);
gfx::Size bounds() const;
void set_is_inner_viewport_scroll_layer() {
is_inner_viewport_scroll_layer_ = true;
}
void SetCurrentScrollOffset(const gfx::PointF& scroll_offset);
gfx::Vector2dF ScrollBy(const gfx::Vector2dF& scroll);
struct CC_EXPORT RareProperties {
RareProperties();
RareProperties(const RareProperties&);
~RareProperties();
viz::RegionCaptureBounds capture_bounds;
Region main_thread_scroll_hit_test_region;
std::vector<ScrollHitTestRect> non_composited_scroll_hit_test_rects;
Region wheel_event_handler_region;
PaintFlags::FilterQuality filter_quality = PaintFlags::FilterQuality::kLow;
PaintFlags::DynamicRangeLimitMixture dynamic_range_limit{
PaintFlags::DynamicRangeLimit::kHigh};
};
bool HasAnyRarePropertySet() { return !!rare_properties_; }
RareProperties& EnsureRareProperties() {
if (!rare_properties_)
rare_properties_ = std::make_unique<RareProperties>();
return *rare_properties_;
}
void ResetRareProperties() {
if (rare_properties_) {
rare_properties_.reset();
SetNeedsPushProperties();
}
}
void SetMainThreadScrollHitTestRegion(const Region& region) {
if (rare_properties_ || !region.IsEmpty()) {
EnsureRareProperties().main_thread_scroll_hit_test_region = region;
SetNeedsPushProperties();
}
}
const Region& main_thread_scroll_hit_test_region() const {
return rare_properties_
? rare_properties_->main_thread_scroll_hit_test_region
: Region::Empty();
}
void SetNonCompositedScrollHitTestRects(
const std::vector<ScrollHitTestRect>& rects) {
if (rare_properties_ || !rects.empty()) {
EnsureRareProperties().non_composited_scroll_hit_test_rects = rects;
SetNeedsPushProperties();
}
}
const std::vector<ScrollHitTestRect>* non_composited_scroll_hit_test_rects()
const {
return rare_properties_
? &rare_properties_->non_composited_scroll_hit_test_rects
: nullptr;
}
void SetTouchActionRegion(TouchActionRegion);
const TouchActionRegion& touch_action_region() const {
return touch_action_region_;
}
const Region& GetAllTouchActionRegions() const;
bool has_touch_action_regions() const {
return !touch_action_region_.IsEmpty();
}
void SetCaptureBounds(viz::RegionCaptureBounds bounds);
const viz::RegionCaptureBounds* capture_bounds() const {
return rare_properties_ ? &rare_properties_->capture_bounds : nullptr;
}
void SetWheelEventHandlerRegion(const Region& wheel_event_handler_region) {
if (rare_properties_ || !wheel_event_handler_region.IsEmpty()) {
EnsureRareProperties().wheel_event_handler_region =
wheel_event_handler_region;
SetNeedsPushProperties();
}
}
const Region& wheel_event_handler_region() const {
return rare_properties_ ? rare_properties_->wheel_event_handler_region
: Region::Empty();
}
void UnionUpdateRect(const gfx::Rect& update_rect);
const gfx::Rect& update_rect() const { return update_rect_; }
virtual gfx::Rect GetDamageRect() const;
virtual DamageReasonSet GetDamageReasons() const;
DamageReasonSet GetDamageReasonsFromLayerPropertyChange() const;
bool LayerPropertyChanged() const;
bool LayerPropertyChangedFromPropertyTrees() const;
bool LayerPropertyChangedNotFromPropertyTrees() const;
virtual void ResetChangeTracking();
virtual SimpleEnclosedRegion VisibleOpaqueRegion() const;
virtual void DidBecomeActive() {}
virtual void DidBeginTracing();
virtual void ReleaseResources();
virtual void OnPurgeMemory();
virtual void ReleaseTileResources();
virtual void RecreateTileResources();
virtual std::unique_ptr<LayerImpl> CreateLayerImpl(
LayerTreeImpl* tree_impl) const;
virtual void PushPropertiesTo(LayerImpl* layer);
#if BUILDFLAG(ARKWEB_WEBGL)
virtual bool ShouldDeferImplInvalidation() const;
#endif
virtual bool IsSnappedToPixelGridInTarget();
virtual void GetAllPrioritizedTilesForTracing(
std::vector<PrioritizedTile>* prioritized_tiles) const;
virtual void AsValueInto(base::trace_event::TracedValue* dict) const;
std::string ToString() const;
virtual size_t GPUMemoryUsageInBytes() const;
void SetNeedsPushProperties(uint8_t changed_props = kChangedGeneralProperty);
virtual void RunMicroBenchmark(MicroBenchmarkImpl* benchmark);
void UpdateDebugInfo(LayerDebugInfo* debug_info);
void set_contributes_to_drawn_render_surface(bool is_member) {
contributes_to_drawn_render_surface_ = is_member;
}
bool contributes_to_drawn_render_surface() const {
return contributes_to_drawn_render_surface_;
}
int GetSortingContextId() const;
virtual Region GetInvalidationRegionForDebugging();
virtual gfx::Rect GetEnclosingVisibleRectInTargetSpace() const;
gfx::Rect GetScaledEnclosingVisibleRectInTargetSpace(float scale) const;
gfx::Vector2dF GetIdealContentsScale() const;
float GetIdealContentsScaleKey() const;
void SetFilterQuality(PaintFlags::FilterQuality);
PaintFlags::FilterQuality GetFilterQuality() const {
return rare_properties_ ? rare_properties_->filter_quality
: PaintFlags::FilterQuality::kLow;
}
void SetDynamicRangeLimit(
PaintFlags::DynamicRangeLimitMixture dynamic_range_limit);
PaintFlags::DynamicRangeLimitMixture GetDynamicRangeLimit() const {
return rare_properties_ ? rare_properties_->dynamic_range_limit
: PaintFlags::DynamicRangeLimitMixture(
PaintFlags::DynamicRangeLimit::kHigh);
}
void NoteLayerPropertyChanged();
void NoteLayerPropertyChangedFromPropertyTrees();
ElementListType GetElementTypeForAnimation() const;
void set_raster_even_if_not_drawn(bool yes) {
raster_even_if_not_drawn_ = yes;
}
bool raster_even_if_not_drawn() const { return raster_even_if_not_drawn_; }
void EnsureValidPropertyTreeIndices() const;
virtual bool is_surface_layer() const;
std::string DebugName() const;
virtual gfx::ContentColorUsage GetContentColorUsage() const;
virtual void NotifyKnownResourceIdsBeforeAppendQuads(
const base::flat_set<viz::ViewTransitionElementResourceId>&
known_resource_ids) {}
virtual viz::ViewTransitionElementResourceId ViewTransitionResourceId() const;
virtual void SetInInvisibleLayerTree() {}
#if BUILDFLAG(ARKWEB_TEST)
virtual LayerImplUtils* layer_impl_utils() {
#else
LayerImplUtils* layer_impl_utils() {
#endif
return layer_impl_utils_.get();
}
enum : uint8_t {
kChangedPropertyTreeIndex = 1 << 0,
kChangedGeneralProperty = 1 << 1,
kChangedAllProperties = kChangedPropertyTreeIndex | kChangedGeneralProperty,
};
bool GetChangeFlag(uint8_t mask) const { return changed_properties_ & mask; }
protected:
LayerImpl(LayerTreeImpl* layer_impl, int id);
virtual void GetDebugBorderProperties(SkColor4f* color, float* width) const;
void AppendDebugBorderQuad(viz::CompositorRenderPass* render_pass,
const gfx::Rect& quad_rect,
const viz::SharedQuadState* shared_quad_state,
AppendQuadsData* append_quads_data) const;
void AppendDebugBorderQuad(viz::CompositorRenderPass* render_pass,
const gfx::Rect& quad_rect,
const viz::SharedQuadState* shared_quad_state,
AppendQuadsData* append_quads_data,
SkColor4f color,
float width) const;
static float GetPreferredRasterScale(
gfx::Vector2dF raster_space_scale_factor);
private:
void ValidateQuadResourcesInternal(viz::DrawQuad* quad) const;
gfx::Transform GetScaledDrawTransform(float layer_to_content_scale) const;
const int layer_id_;
const raw_ptr<LayerTreeImpl> layer_tree_impl_;
const int stable_id_for_shared_quad_state_;
gfx::Size bounds_;
gfx::Vector2dF offset_to_transform_parent_;
bool layer_property_changed_not_from_property_trees_ : 1 = false;
bool layer_property_changed_from_property_trees_ : 1 = false;
bool contents_opaque_ : 1 = false;
bool contents_opaque_for_text_ : 1 = false;
bool should_check_backface_visibility_ : 1 = false;
bool draws_content_ : 1 = false;
bool contributes_to_drawn_render_surface_ : 1 = false;
bool is_inner_viewport_scroll_layer_ : 1 = false;
HitTestOpaqueness hit_test_opaqueness_ = HitTestOpaqueness::kTransparent;
TouchActionRegion touch_action_region_;
SkColor4f background_color_ = SkColors::kTransparent;
SkColor4f safe_opaque_background_color_ = SkColors::kTransparent;
int transform_tree_index_;
int effect_tree_index_;
int clip_tree_index_;
int scroll_tree_index_;
std::unique_ptr<RareProperties> rare_properties_;
protected:
friend class TreeSynchronizer;
friend class LayerImplUtils;
EffectTree& GetEffectTree() const;
PropertyTrees* GetPropertyTrees() const;
ClipTree& GetClipTree() const;
ScrollTree& GetScrollTree() const;
TransformTree& GetTransformTree() const;
private:
ElementId element_id_;
gfx::Rect update_rect_;
DrawProperties draw_properties_;
std::unique_ptr<LayerDebugInfo> debug_info_;
mutable std::unique_ptr<Region> all_touch_action_regions_;
uint8_t changed_properties_ = 0u;
bool needs_push_properties_ : 1 = false;
bool raster_even_if_not_drawn_ : 1 = false;
bool has_transform_node_ : 1 = false;
std::unique_ptr<LayerImplUtils> layer_impl_utils_;
};
}
#endif