#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_state.h"
#include <optional>
#include "base/check.h"
#include "base/check_op.h"
#include "base/compiler_specific.h"
#include "base/dcheck_is_on.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "cc/paint/draw_looper.h"
#include "cc/paint/paint_flags.h"
#include "cc/paint/path_effect.h"
#include "third_party/blink/public/common/metrics/document_update_reason.h"
#include "third_party/blink/public/mojom/frame/color_scheme.mojom-blink.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_canvas_font_stretch.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_canvas_text_rendering.h"
#include "third_party/blink/renderer/core/css/css_primitive_value.h"
#include "third_party/blink/renderer/core/css/css_to_length_conversion_data.h"
#include "third_party/blink/renderer/core/css/css_value.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_token.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_token_range.h"
#include "third_party/blink/renderer/core/css/parser/css_tokenizer.h"
#include "third_party/blink/renderer/core/css/resolver/filter_operation_resolver.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/paint/filter_effect_builder.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/style/filter_operations.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_filter.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_style.h"
#include "third_party/blink/renderer/platform/fonts/font_selection_types.h"
#include "third_party/blink/renderer/platform/fonts/font_selector.h"
#include "third_party/blink/renderer/platform/fonts/text_rendering_mode.h"
#include "third_party/blink/renderer/platform/graphics/draw_looper_builder.h"
#include "third_party/blink/renderer/platform/graphics/filters/filter_effect.h"
#include "third_party/blink/renderer/platform/graphics/filters/paint_filter_builder.h"
#include "third_party/blink/renderer/platform/graphics/graphics_types.h"
#include "third_party/blink/renderer/platform/graphics/interpolation_space.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_filter.h"
#include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h"
#include "third_party/blink/renderer/platform/heap/visitor.h"
#include "third_party/blink/renderer/platform/transforms/affine_transform.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "third_party/skia/include/core/SkBlendMode.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_f.h"
namespace blink {
enum class FontInvalidationReason;
}
static const char defaultFont[] = …;
static const char defaultFilter[] = …;
static const char defaultSpacing[] = …;
namespace blink {
bool StringToNumWithUnit(String spacing,
float* number_spacing,
CSSPrimitiveValue::UnitType* unit) { … }
FontSelectionValue CanvasFontStretchToSelectionValue(
V8CanvasFontStretch font_stretch) { … }
TextRenderingMode CanvasTextRenderingToTextRendering(
V8CanvasTextRendering text_rendering) { … }
CanvasRenderingContext2DState::CanvasRenderingContext2DState()
: … { … }
CanvasRenderingContext2DState::CanvasRenderingContext2DState(
const CanvasRenderingContext2DState& other,
ClipListCopyMode mode,
SaveType save_type)
: … { … }
CanvasRenderingContext2DState::~CanvasRenderingContext2DState() = default;
void CanvasRenderingContext2DState::FontsNeedUpdate(FontSelector* font_selector,
FontInvalidationReason) { … }
void CanvasRenderingContext2DState::Trace(Visitor* visitor) const { … }
void CanvasRenderingContext2DState::SetLineDashOffset(double offset) { … }
void CanvasRenderingContext2DState::SetLineDash(const Vector<double>& dash) { … }
static bool HasANonZeroElement(const Vector<double>& line_dash) { … }
ALWAYS_INLINE void CanvasRenderingContext2DState::UpdateLineDash() const { … }
void CanvasRenderingContext2DState::SetShouldAntialias(bool should_antialias) { … }
bool CanvasRenderingContext2DState::ShouldAntialias() const { … }
void CanvasRenderingContext2DState::SetGlobalAlpha(double alpha) { … }
void CanvasRenderingContext2DState::ClipPath(
const SkPath& path,
AntiAliasingMode anti_aliasing_mode) { … }
void CanvasRenderingContext2DState::SetFont(
const FontDescription& passed_font_description,
FontSelector* selector) { … }
void CanvasRenderingContext2DState::SetFontInternal(
const FontDescription& passed_font_description,
FontSelector* selector) { … }
bool CanvasRenderingContext2DState::IsFontDirtyForFilter() const { … }
const Font& CanvasRenderingContext2DState::GetFont() const { … }
const FontDescription& CanvasRenderingContext2DState::GetFontDescription()
const { … }
void CanvasRenderingContext2DState::SetFontKerning(
FontDescription::Kerning font_kerning,
FontSelector* selector) { … }
void CanvasRenderingContext2DState::SetFontStretch(
V8CanvasFontStretch font_stretch,
FontSelector* selector) { … }
void CanvasRenderingContext2DState::SetFontVariantCaps(
FontDescription::FontVariantCaps font_variant_caps,
FontSelector* selector) { … }
void CanvasRenderingContext2DState::SetTransform(
const AffineTransform& transform) { … }
void CanvasRenderingContext2DState::ResetTransform() { … }
void CanvasRenderingContext2DState::ValidateFilterState() const { … }
sk_sp<PaintFilter> CanvasRenderingContext2DState::GetFilterForOffscreenCanvas(
gfx::Size canvas_size,
BaseRenderingContext2D* context) { … }
sk_sp<PaintFilter> CanvasRenderingContext2DState::GetFilter(
Element* style_resolution_host,
gfx::Size canvas_size,
CanvasRenderingContext2D* context) { … }
void CanvasRenderingContext2DState::ClearResolvedFilter() { … }
sk_sp<cc::DrawLooper>& CanvasRenderingContext2DState::EmptyDrawLooper() const { … }
sk_sp<cc::DrawLooper>& CanvasRenderingContext2DState::ShadowOnlyDrawLooper()
const { … }
sk_sp<cc::DrawLooper>&
CanvasRenderingContext2DState::ShadowAndForegroundDrawLooper() const { … }
sk_sp<PaintFilter>& CanvasRenderingContext2DState::ShadowOnlyImageFilter()
const { … }
sk_sp<PaintFilter>&
CanvasRenderingContext2DState::ShadowAndForegroundImageFilter() const { … }
void CanvasRenderingContext2DState::ShadowParameterChanged() { … }
void CanvasRenderingContext2DState::SetShadowOffsetX(double x) { … }
void CanvasRenderingContext2DState::SetShadowOffsetY(double y) { … }
void CanvasRenderingContext2DState::SetShadowBlur(double shadow_blur) { … }
void CanvasRenderingContext2DState::SetShadowColor(Color shadow_color) { … }
void CanvasRenderingContext2DState::SetCSSFilter(const CSSValue* filter_value) { … }
void CanvasRenderingContext2DState::SetCanvasFilter(
CanvasFilter* canvas_filter) { … }
void CanvasRenderingContext2DState::SetGlobalComposite(SkBlendMode mode) { … }
SkBlendMode CanvasRenderingContext2DState::GlobalComposite() const { … }
void CanvasRenderingContext2DState::SetImageSmoothingEnabled(bool enabled) { … }
bool CanvasRenderingContext2DState::ImageSmoothingEnabled() const { … }
void CanvasRenderingContext2DState::SetImageSmoothingQuality(
const String& quality_string) { … }
String CanvasRenderingContext2DState::ImageSmoothingQuality() const { … }
void CanvasRenderingContext2DState::UpdateFilterQuality() const { … }
void CanvasRenderingContext2DState::UpdateFilterQuality(
cc::PaintFlags::FilterQuality filter_quality) const { … }
const cc::PaintFlags* CanvasRenderingContext2DState::GetFlags(
PaintType paint_type,
ShadowMode shadow_mode,
ImageType image_type) const { … }
void CanvasRenderingContext2DState::SetLetterSpacing(
const String& letter_spacing) { … }
void CanvasRenderingContext2DState::SetWordSpacing(const String& word_spacing) { … }
void CanvasRenderingContext2DState::SetTextRendering(
V8CanvasTextRendering text_rendering,
FontSelector* selector) { … }
}