chromium/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.h

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_CANVAS2D_BASE_RENDERING_CONTEXT_2D_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_CANVAS2D_BASE_RENDERING_CONTEXT_2D_H_

#include <cmath>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <utility>

#include "base/check.h"
#include "base/compiler_specific.h"
#include "base/dcheck_is_on.h"
#include "base/feature_list.h"
#include "base/memory/scoped_refptr.h"
#include "base/notreached.h"
#include "cc/paint/paint_canvas.h"
#include "cc/paint/paint_flags.h"
#include "cc/paint/paint_record.h"
#include "cc/paint/record_paint_canvas.h"
#include "third_party/blink/public/mojom/frame/color_scheme.mojom-blink.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_typedefs.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_performance_monitor.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/cached_color.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_path.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_state.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/graphics/color.h"
#include "third_party/blink/renderer/platform/graphics/graphics_types.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_filter.h"
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_linked_hash_set.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/heap/forward.h"  // IWYU pragma: keep (blink::Visitor)
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/timer.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/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/SkImageInfo.h"
#include "third_party/skia/include/core/SkM44.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/skia_conversions.h"

// IWYU pragma: no_include "third_party/blink/renderer/platform/heap/visitor.h"

enum class SkPathFillType;
class SkPixmap;
struct SkSamplingOptions;

namespace base {
class SingleThreadTaskRunner;
}  // namespace base

namespace gfx {
class Rect;
class Vector2d;
}  // namespace gfx

namespace ui {
class ColorProvider;
}  // namespace ui

namespace v8 {
class Isolate;
class Value;
template <class T>
class Local;
class String;
}  // namespace v8

namespace blink {

MODULES_EXPORT BASE_DECLARE_FEATURE(kDisableCanvasOverdrawOptimization);

class BeginLayerOptions;
class CanvasGradient;
class CanvasImageSource;
class Canvas2dGPUTransferOption;
class CanvasPattern;
class CanvasRenderingContextHost;
class CanvasResourceProvider;
class DOMMatrix;
class DOMMatrixInit;
class ExceptionState;
class ExecutionContext;
class Font;
class FontSelector;
class GPUTexture;
class HTMLCanvasElement;
class Image;
class ImageData;
class ImageDataSettings;
class MemoryManagedPaintRecorder;
class Mesh2DVertexBuffer;
class Mesh2DUVBuffer;
class Mesh2DIndexBuffer;
class OffscreenCanvas;
class Path;
class Path2D;
class ScriptState;
class SimpleFontData;
class TextMetrics;
class V8GPUTextureFormat;
class V8UnionCanvasFilterOrString;
struct V8CanvasStyle;
enum class CanvasOps;
enum class ColorParseResult;
enum RespectImageOrientationEnum : uint8_t;
template <typename T>
class NotShared;

class MODULES_EXPORT BaseRenderingContext2D : public CanvasPath {};

namespace {

// Blend modes that require compositing with layers when shadows are drawn.
ALWAYS_INLINE bool BlendModeRequiresLayersForShadows(SkBlendMode blendMode) {}

ALWAYS_INLINE bool BlendModeDoesntPreserveOpaqueDestinationAlpha(
    SkBlendMode blendMode) {}

}  // namespace

ALWAYS_INLINE bool BaseRenderingContext2D::BlendModeRequiresCompositedDraw(
    const CanvasRenderingContext2DState& state) const {}

ALWAYS_INLINE void BaseRenderingContext2D::ResetAlphaIfNeeded(
    cc::PaintCanvas* c,
    SkBlendMode blend_mode,
    const gfx::RectF* bounds) {}

ALWAYS_INLINE void BaseRenderingContext2D::CheckOverdraw(
    const cc::PaintFlags* flags,
    CanvasRenderingContext2DState::ImageType image_type,
    BaseRenderingContext2D::OverdrawOp overdraw_op) {}

template <BaseRenderingContext2D::OverdrawOp CurrentOverdrawOp,
          typename DrawFunc,
          typename DrawCoversClipBoundsFunc>
void BaseRenderingContext2D::DrawInternal(
    cc::PaintCanvas* paint_canvas,
    const DrawFunc& draw_func,
    const DrawCoversClipBoundsFunc& draw_covers_clip_bounds,
    const gfx::RectF& bounds,
    CanvasRenderingContext2DState::PaintType paint_type,
    CanvasRenderingContext2DState::ImageType image_type,
    const SkIRect& clip_bounds,
    CanvasPerformanceMonitor::DrawType draw_type) {}

template <BaseRenderingContext2D::OverdrawOp CurrentOverdrawOp,
          typename DrawFunc,
          typename DrawCoversClipBoundsFunc>
void BaseRenderingContext2D::Draw(
    const DrawFunc& draw_func,
    const DrawCoversClipBoundsFunc& draw_covers_clip_bounds,
    const gfx::RectF& bounds,
    CanvasRenderingContext2DState::PaintType paint_type,
    CanvasRenderingContext2DState::ImageType image_type,
    CanvasPerformanceMonitor::DrawType draw_type) {}

template <typename DrawFunc>
void BaseRenderingContext2D::CompositedDraw(
    const DrawFunc& draw_func,
    cc::PaintCanvas* c,
    CanvasRenderingContext2DState::PaintType paint_type,
    CanvasRenderingContext2DState::ImageType image_type) {}

template <typename T>
bool BaseRenderingContext2D::ValidateRectForCanvas(T x,
                                                   T y,
                                                   T width,
                                                   T height) {}

template <typename T>
void BaseRenderingContext2D::AdjustRectForCanvas(T& x,
                                                 T& y,
                                                 T& width,
                                                 T& height) {}

ALWAYS_INLINE void BaseRenderingContext2D::SetTransform(
    const AffineTransform& matrix) {}

ALWAYS_INLINE bool BaseRenderingContext2D::IsFullCanvasCompositeMode(
    SkBlendMode op) {}

ALWAYS_INLINE bool BaseRenderingContext2D::StateHasFilter() {}

ALWAYS_INLINE bool BaseRenderingContext2D::ComputeDirtyRect(
    const gfx::RectF& local_rect,
    const SkIRect& transformed_clip_bounds,
    SkIRect* dirty_rect) {}

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_CANVAS2D_BASE_RENDERING_CONTEXT_2D_H_