fix crash in offscreen canvas measureText

This commit is contained in:
Carmelo Messina
2023-10-11 17:15:25 +02:00
parent fd59efe186
commit 002dc9166f
@@ -42,7 +42,7 @@ License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
.../renderer/core/html/canvas/text_metrics.h | 2 +
.../renderer/core/svg/svg_graphics_element.cc | 2 +
.../core/svg/svg_text_content_element.cc | 28 +++-
.../canvas2d/base_rendering_context_2d.cc | 12 +-
.../canvas2d/base_rendering_context_2d.cc | 24 ++-
third_party/blink/renderer/platform/BUILD.gn | 5 +-
.../platform/exported/web_runtime_features.cc | 12 ++
.../platform/graphics/image_data_buffer.cc | 7 +
@@ -52,7 +52,7 @@ License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
third_party/ungoogled/BUILD.gn | 10 ++
third_party/ungoogled/ungoogled_switches.cc | 18 ++
third_party/ungoogled/ungoogled_switches.h | 18 ++
26 files changed, 376 insertions(+), 8 deletions(-)
26 files changed, 388 insertions(+), 8 deletions(-)
create mode 100644 third_party/ungoogled/BUILD.gn
create mode 100644 third_party/ungoogled/ungoogled_switches.cc
create mode 100644 third_party/ungoogled/ungoogled_switches.h
@@ -475,7 +475,17 @@ diff --git a/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_c
#include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h"
#include "third_party/blink/renderer/platform/graphics/stroke_data.h"
#include "third_party/blink/renderer/platform/graphics/video_frame_image_util.h"
@@ -2188,6 +2189,10 @@ ImageData* BaseRenderingContext2D::getImageDataInternal(
@@ -53,6 +54,9 @@
#include "ui/gfx/geometry/quad_f.h"
#include "ui/gfx/geometry/skia_conversions.h"
+#include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h"
+#include "third_party/blink/renderer/core/frame/local_dom_window.h"
+
namespace blink {
BASE_FEATURE(kDisableCanvasOverdrawOptimization,
@@ -2188,6 +2192,10 @@ ImageData* BaseRenderingContext2D::getImageDataInternal(
snapshot->PaintImageForCurrentFrame().GetSkImageInfo().bounds();
DCHECK(!bounds.intersect(SkIRect::MakeXYWH(sx, sy, sw, sh)));
}
@@ -486,7 +496,7 @@ diff --git a/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_c
}
return image_data;
@@ -2865,9 +2870,14 @@ TextMetrics* BaseRenderingContext2D::measureText(const String& text) {
@@ -2865,9 +2873,23 @@ TextMetrics* BaseRenderingContext2D::measureText(const String& text) {
TextDirection direction = ToTextDirection(GetState().GetDirection(), canvas);
@@ -496,7 +506,16 @@ diff --git a/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_c
GetState().GetTextAlign(), text);
+ // Scale text metrics if enabled
+ if (RuntimeEnabledFeatures::FingerprintingCanvasMeasureTextNoiseEnabled()) {
+ text_metrics->Shuffle(canvas->GetDocument().GetNoiseFactorX());
+ OffscreenCanvas* offscreen_canvas = HostAsOffscreenCanvas();
+ if (offscreen_canvas) {
+ ExecutionContext* execution_context = GetTopExecutionContext();
+ if (auto* window = DynamicTo<LocalDOMWindow>(execution_context)) {
+ Document* document = window->GetFrame()->GetDocument();
+ text_metrics->Shuffle(document->GetNoiseFactorX());
+ }
+ }
+ else
+ text_metrics->Shuffle(canvas->GetDocument().GetNoiseFactorX());
+ }
+ return text_metrics;
}