chromium/third_party/blink/renderer/platform/graphics/graphics_context.cc

/*
 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
 * Copyright (C) 2013 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "third_party/blink/renderer/platform/graphics/graphics_context.h"

#include <memory>
#include <optional>

#include "base/logging.h"
#include "build/build_config.h"
#include "cc/paint/color_filter.h"
#include "components/paint_preview/common/paint_preview_tracker.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/blink/public/mojom/frame/color_scheme.mojom-blink.h"
#include "third_party/blink/renderer/platform/fonts/text_run_paint_info.h"
#include "third_party/blink/renderer/platform/geometry/float_rounded_rect.h"
#include "third_party/blink/renderer/platform/graphics/dark_mode_settings_builder.h"
#include "third_party/blink/renderer/platform/graphics/graphics_context_state_saver.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_canvas.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_controller.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_record.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_recorder.h"
#include "third_party/blink/renderer/platform/graphics/path.h"
#include "third_party/blink/renderer/platform/graphics/stroke_data.h"
#include "third_party/blink/renderer/platform/graphics/styled_stroke_data.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/skia/include/core/SkAnnotation.h"
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkRRect.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/pathops/SkPathOps.h"
#include "third_party/skia/include/utils/SkNullCanvas.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/skia_conversions.h"

// To avoid conflicts with the DrawText macro from the Windows SDK...
#undef DrawText

namespace blink {

namespace {

SkColor4f DarkModeColor(GraphicsContext& context,
                        const SkColor4f& color,
                        const AutoDarkMode& auto_dark_mode) {}

}  // namespace

// Helper class that copies |flags| only when dark mode is enabled.
//
// TODO(gilmanmh): Investigate removing const from |flags| in the calling
// methods and modifying the variable directly instead of copying it.
class GraphicsContext::DarkModeFlags final {};

GraphicsContext::GraphicsContext(PaintController& paint_controller)
    :{}

GraphicsContext::~GraphicsContext() {}

void GraphicsContext::CopyConfigFrom(GraphicsContext& other) {}

DarkModeFilter* GraphicsContext::GetDarkModeFilter() {}

DarkModeFilter* GraphicsContext::GetDarkModeFilterForImage(
    const ImageAutoDarkMode& auto_dark_mode) {}

void GraphicsContext::UpdateDarkModeSettingsForTest(
    const DarkModeSettings& settings) {}

void GraphicsContext::Save() {}

void GraphicsContext::Restore() {}

#if DCHECK_IS_ON()
unsigned GraphicsContext::SaveCount() const {}
#endif

void GraphicsContext::SetInDrawingRecorder(bool val) {}

void GraphicsContext::SetDOMNodeId(DOMNodeId new_node_id) {}

DOMNodeId GraphicsContext::GetDOMNodeId() const {}

void GraphicsContext::SetDrawLooper(sk_sp<cc::DrawLooper> draw_looper) {}

void GraphicsContext::Concat(const SkM44& matrix) {}

void GraphicsContext::BeginLayer(float opacity) {}

void GraphicsContext::BeginLayer(SkBlendMode xfermode) {}

void GraphicsContext::BeginLayer(sk_sp<cc::ColorFilter> color_filter,
                                 const SkBlendMode* blend_mode) {}

void GraphicsContext::BeginLayer(sk_sp<PaintFilter> image_filter) {}

void GraphicsContext::BeginLayer(const cc::PaintFlags& flags) {}

void GraphicsContext::EndLayer() {}

void GraphicsContext::BeginRecording() {}

PaintRecord GraphicsContext::EndRecording() {}

void GraphicsContext::DrawRecord(PaintRecord record) {}

void GraphicsContext::CompositeRecord(PaintRecord record,
                                      const gfx::RectF& dest,
                                      const gfx::RectF& src,
                                      SkBlendMode op) {}

void GraphicsContext::DrawFocusRingPath(const SkPath& path,
                                        const Color& color,
                                        float width,
                                        float corner_radius,
                                        const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::DrawFocusRingRect(const SkRRect& rrect,
                                        const Color& color,
                                        float width,
                                        const AutoDarkMode& auto_dark_mode) {}

static void EnforceDotsAtEndpoints(GraphicsContext& context,
                                   gfx::PointF& p1,
                                   gfx::PointF& p2,
                                   const int path_length,
                                   const int width,
                                   const cc::PaintFlags& flags,
                                   const bool is_vertical_line,
                                   const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::DrawLine(const gfx::Point& point1,
                               const gfx::Point& point2,
                               const StyledStrokeData& styled_stroke,
                               const AutoDarkMode& auto_dark_mode,
                               bool is_text_line,
                               const cc::PaintFlags* paint_flags) {}

void GraphicsContext::DrawText(const Font& font,
                               const TextFragmentPaintInfo& text_info,
                               const gfx::PointF& point,
                               const cc::PaintFlags& flags,
                               DOMNodeId node_id,
                               const AutoDarkMode& auto_dark_mode) {}

template <typename DrawTextFunc>
void GraphicsContext::DrawTextPasses(const DrawTextFunc& draw_text) {}

void GraphicsContext::DrawText(const Font& font,
                               const TextFragmentPaintInfo& text_info,
                               const gfx::PointF& point,
                               DOMNodeId node_id,
                               const AutoDarkMode& auto_dark_mode) {}

template <typename TextPaintInfo>
void GraphicsContext::DrawEmphasisMarksInternal(
    const Font& font,
    const TextPaintInfo& text_info,
    const AtomicString& mark,
    const gfx::PointF& point,
    const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::DrawEmphasisMarks(const Font& font,
                                        const TextRunPaintInfo& text_info,
                                        const AtomicString& mark,
                                        const gfx::PointF& point,
                                        const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::DrawEmphasisMarks(const Font& font,
                                        const TextFragmentPaintInfo& text_info,
                                        const AtomicString& mark,
                                        const gfx::PointF& point,
                                        const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::DrawBidiText(
    const Font& font,
    const TextRunPaintInfo& run_info,
    const gfx::PointF& point,
    const AutoDarkMode& auto_dark_mode,
    Font::CustomFontNotReadyAction custom_font_not_ready_action) {}

void GraphicsContext::DrawImage(
    Image& image,
    Image::ImageDecodingMode decode_mode,
    const ImageAutoDarkMode& auto_dark_mode,
    const ImagePaintTimingInfo& paint_timing_info,
    const gfx::RectF& dest,
    const gfx::RectF* src_ptr,
    SkBlendMode op,
    RespectImageOrientationEnum should_respect_image_orientation,
    Image::ImageClampingMode clamping_mode) {}
void GraphicsContext::DrawImageRRect(
    Image& image,
    Image::ImageDecodingMode decode_mode,
    const ImageAutoDarkMode& auto_dark_mode,
    const ImagePaintTimingInfo& paint_timing_info,
    const FloatRoundedRect& dest,
    const gfx::RectF& src_rect,
    SkBlendMode op,
    RespectImageOrientationEnum respect_orientation,
    Image::ImageClampingMode clamping_mode) {}

void GraphicsContext::SetImagePainted(bool report_paint_timing) {}

cc::PaintFlags::FilterQuality GraphicsContext::ComputeFilterQuality(
    Image& image,
    const gfx::RectF& dest,
    const gfx::RectF& src) const {}

void GraphicsContext::DrawImageTiled(
    Image& image,
    const gfx::RectF& dest_rect,
    const ImageTilingInfo& tiling_info,
    const ImageAutoDarkMode& auto_dark_mode,
    const ImagePaintTimingInfo& paint_timing_info,
    SkBlendMode op,
    RespectImageOrientationEnum respect_orientation) {}

void GraphicsContext::DrawLine(const gfx::PointF& from,
                               const gfx::PointF& to,
                               const cc::PaintFlags& flags,
                               const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::DrawOval(const SkRect& oval,
                               const cc::PaintFlags& flags,
                               const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::DrawPath(const SkPath& path,
                               const cc::PaintFlags& flags,
                               const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::DrawRect(const SkRect& rect,
                               const cc::PaintFlags& flags,
                               const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::DrawRRect(const SkRRect& rrect,
                                const cc::PaintFlags& flags,
                                const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::FillPath(const Path& path_to_fill,
                               const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::StrokePath(const Path& path_to_stroke,
                                 const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::FillRect(const gfx::Rect& rect,
                               const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::FillRect(const gfx::Rect& rect,
                               const Color& color,
                               const AutoDarkMode& auto_dark_mode,
                               SkBlendMode xfer_mode) {}

void GraphicsContext::FillRect(const gfx::RectF& rect,
                               const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::FillRect(const gfx::RectF& rect,
                               const Color& color,
                               const AutoDarkMode& auto_dark_mode,
                               SkBlendMode xfer_mode) {}

void GraphicsContext::FillRoundedRect(const FloatRoundedRect& rrect,
                                      const Color& color,
                                      const AutoDarkMode& auto_dark_mode) {}

namespace {

bool IsSimpleDRRect(const FloatRoundedRect& outer,
                    const FloatRoundedRect& inner) {}

}  // anonymous namespace

void GraphicsContext::FillDRRect(const FloatRoundedRect& outer,
                                 const FloatRoundedRect& inner,
                                 const Color& color,
                                 const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::FillRectWithRoundedHole(
    const gfx::RectF& rect,
    const FloatRoundedRect& rounded_hole_rect,
    const Color& color,
    const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::FillEllipse(const gfx::RectF& ellipse,
                                  const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::StrokeEllipse(const gfx::RectF& ellipse,
                                    const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::StrokeRect(const gfx::RectF& rect,
                                 const AutoDarkMode& auto_dark_mode) {}

void GraphicsContext::ClipRoundedRect(const FloatRoundedRect& rrect,
                                      SkClipOp clip_op,
                                      AntiAliasingMode should_antialias) {}

void GraphicsContext::ClipOut(const Path& path_to_clip) {}

void GraphicsContext::ClipOutRoundedRect(const FloatRoundedRect& rect) {}

void GraphicsContext::ClipRect(const SkRect& rect,
                               AntiAliasingMode aa,
                               SkClipOp op) {}

void GraphicsContext::ClipPath(const SkPath& path,
                               AntiAliasingMode aa,
                               SkClipOp op) {}

void GraphicsContext::ClipRRect(const SkRRect& rect,
                                AntiAliasingMode aa,
                                SkClipOp op) {}

void GraphicsContext::Rotate(float angle_in_radians) {}

void GraphicsContext::Translate(float x, float y) {}

void GraphicsContext::Scale(float x, float y) {}

void GraphicsContext::SetURLForRect(const KURL& link,
                                    const gfx::Rect& dest_rect) {}

void GraphicsContext::SetURLFragmentForRect(const String& dest_name,
                                            const gfx::Rect& rect) {}

void GraphicsContext::SetURLDestinationLocation(const String& name,
                                                const gfx::Point& location) {}

void GraphicsContext::ConcatCTM(const AffineTransform& affine) {}

void GraphicsContext::AdjustLineToPixelBoundaries(gfx::PointF& p1,
                                                  gfx::PointF& p2,
                                                  float stroke_width) {}

}  // namespace blink