0

[PDF Ink Signatures] Replace Ink stub

Delete all the code in //pdf/ink, which includes the Ink stub, and
switch over to the Ink library directly.

Temporarily disable a PdfInkModuleStrokeTest that is now failing, as the
Ink library behaves differently from the stub. The test case will be
fixed separately in the next CL in chain.

Bug: 339682315
Change-Id: I45464ebbd4a4025ab31bd775007abf4e64ac1f3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5867108
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Andy Phan <andyphan@chromium.org>
Reviewed-by: Alan Screen <awscreen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1357069}
This commit is contained in:
Lei Zhang
2024-09-18 14:23:33 +00:00
committed by Chromium LUCI CQ
parent 50f2081d8c
commit 557a290a77
53 changed files with 188 additions and 1613 deletions

@ -227,7 +227,7 @@ if (enable_pdf) {
"pdf_ink_undo_redo_model.h",
]
public_deps += [ "//pdf/ink" ]
public_deps += [ "//third_party/ink" ]
}
if (enable_screen_ai_service) {

@ -10,6 +10,7 @@ include_rules = [
"+services/screen_ai/public/mojom/screen_ai_service.mojom.h",
"+services/screen_ai/public/mojom/screen_ai_service.mojom-forward.h",
"+third_party/blink/public",
"+third_party/ink",
"+third_party/skia/include/core",
"+ui/base",
"+ui/events",

@ -24,7 +24,4 @@ declare_args() {
# Enable the next generation of ink libraries. This can co-exist with
# `enable_ink` above.
enable_pdf_ink2 = enable_pdf
# Enable Ink Stubs. Only applicable when `enable_pdf_ink2` is true.
enable_pdf_ink2_stubs = true
}

@ -1,51 +0,0 @@
# Copyright 2024 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//pdf/features.gni")
assert(enable_pdf_ink2)
group("ink") {
visibility = [ "//pdf/*" ]
public_deps = [ ":interface" ]
if (enable_pdf_ink2_stubs) {
deps = [ "//pdf/ink/stub" ]
} else {
# TODO(thestig): Add wrapper code.
deps = [ "//pdf/ink/wrapper" ]
}
}
source_set("interface") {
visibility = [ "//pdf/*" ]
sources = [
"ink_affine_transform.cc",
"ink_affine_transform.h",
"ink_brush.h",
"ink_brush_behavior.cc",
"ink_brush_behavior.h",
"ink_brush_family.h",
"ink_brush_paint.cc",
"ink_brush_paint.h",
"ink_brush_tip.cc",
"ink_brush_tip.h",
"ink_in_progress_stroke.h",
"ink_intersects.h",
"ink_modeled_shape_view.h",
"ink_point.h",
"ink_rect.h",
"ink_skia_renderer.h",
"ink_stroke.h",
"ink_stroke_input.h",
"ink_stroke_input_batch.h",
"ink_stroke_input_batch_view.h",
]
configs += [ "//pdf:strict" ]
public_deps = [ "//skia" ]
}

@ -1,5 +0,0 @@
include_rules = [
# This particular directory cannot depend on //base, as //base code conflicts
# with Ink code.
"-base",
]

@ -1,17 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/ink_affine_transform.h"
#include <ostream>
namespace chrome_pdf {
void PrintTo(const InkAffineTransform& transform, std::ostream* os) {
*os << "[ " << transform.a << ", " << transform.b << ", " << transform.c
<< ", " << transform.d << ", " << transform.e << ", " << transform.f
<< " ]";
}
} // namespace chrome_pdf

@ -1,33 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_AFFINE_TRANSFORM_H_
#define PDF_INK_INK_AFFINE_TRANSFORM_H_
#include <iosfwd>
namespace chrome_pdf {
// NOTE: This is the equivalent to the following 3x3 matrix:
//
// a b c
// d e f
// 0 0 1
//
// Thus the identity matrix is {1, 0, 0, 0, 1, 0}, and not {1, 0, 0, 1, 0, 0}.
struct InkAffineTransform {
float a;
float b;
float c;
float d;
float e;
float f;
};
// Supports pretty-printing transforms for test failures.
void PrintTo(const InkAffineTransform& transform, std::ostream* os);
} // namespace chrome_pdf
#endif // PDF_INK_INK_AFFINE_TRANSFORM_H_

@ -1,38 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_BRUSH_H_
#define PDF_INK_INK_BRUSH_H_
#include <memory>
#include "third_party/skia/include/core/SkColor.h"
namespace chrome_pdf {
class InkBrushFamily;
class InkBrush {
public:
static std::unique_ptr<InkBrush> Create(
std::unique_ptr<InkBrushFamily> family,
SkColor color,
float size,
float epsilon);
virtual ~InkBrush() = default;
virtual SkColor GetColor() const = 0;
virtual float GetSize() const = 0;
// Note that these methods do not necessarily correspond 1:1 to the method in
// the Ink library. It is provided for convenience when testing.
virtual float GetCornerRoundingForTesting() const = 0;
virtual float GetOpacityForTesting() const = 0;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_BRUSH_H_

@ -1,13 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/ink_brush_behavior.h"
namespace chrome_pdf {
InkBrushBehavior::InkBrushBehavior() = default;
InkBrushBehavior::~InkBrushBehavior() = default;
} // namespace chrome_pdf

@ -1,60 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_BRUSH_BEHAVIOR_H_
#define PDF_INK_INK_BRUSH_BEHAVIOR_H_
#include <cstdint>
#include <vector>
namespace chrome_pdf {
struct InkBrushBehavior {
struct EnabledToolTypes {
bool unknown = false;
bool mouse = false;
bool touch = false;
bool stylus = false;
};
static constexpr EnabledToolTypes kAllToolTypes = {.unknown = true,
.mouse = true,
.touch = true,
.stylus = true};
enum OptionalInputProperty : int8_t {
kPressure,
kTilt,
kOrientation,
kTiltXAndY,
};
// TODO(crbug.com/339682315): Add more types if needed.
enum class Type {
kFallbackFilter,
kToolTypeFilter,
};
// Deliberately avoid using absl::variant in this header.
struct BaseNode {
Type type;
};
struct FallbackFilterNode : public BaseNode {
OptionalInputProperty is_fallback_for;
};
struct ToolTypeFilterNode : public BaseNode {
EnabledToolTypes enabled_tool_types;
};
InkBrushBehavior();
~InkBrushBehavior();
std::vector<BaseNode> nodes;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_BRUSH_BEHAVIOR_H_

@ -1,32 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_BRUSH_FAMILY_H_
#define PDF_INK_INK_BRUSH_FAMILY_H_
#include <memory>
#include <string_view>
namespace chrome_pdf {
struct InkBrushPaint;
struct InkBrushTip;
class InkBrushFamily {
public:
static std::unique_ptr<InkBrushFamily> Create(InkBrushTip tip,
InkBrushPaint paint,
std::string_view uri_string);
virtual ~InkBrushFamily() = default;
// Note that these methods do not necessarily correspond 1:1 to method in the
// Ink library. This is provided for convenience when testing.
virtual float GetCornerRoundingForTesting() const = 0;
virtual float GetOpacityForTesting() const = 0;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_BRUSH_FAMILY_H_

@ -1,27 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/ink_brush_paint.h"
namespace chrome_pdf {
InkBrushPaint::InkBrushPaint() = default;
InkBrushPaint::InkBrushPaint(InkBrushPaint&&) noexcept = default;
InkBrushPaint& InkBrushPaint::operator=(InkBrushPaint&&) noexcept = default;
InkBrushPaint::~InkBrushPaint() = default;
InkBrushPaint::TextureLayer::TextureLayer() = default;
InkBrushPaint::TextureLayer::TextureLayer(const InkBrushPaint::TextureLayer&) =
default;
InkBrushPaint::TextureLayer& InkBrushPaint::TextureLayer::operator=(
const InkBrushPaint::TextureLayer&) = default;
InkBrushPaint::TextureLayer::~TextureLayer() = default;
} // namespace chrome_pdf

@ -1,89 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_BRUSH_PAINT_H_
#define PDF_INK_INK_BRUSH_PAINT_H_
#include <optional>
#include <string>
#include <vector>
namespace chrome_pdf {
struct InkBrushPaint {
InkBrushPaint();
InkBrushPaint(const InkBrushPaint&) = delete;
InkBrushPaint& operator=(const InkBrushPaint&) = delete;
InkBrushPaint(InkBrushPaint&&) noexcept;
InkBrushPaint& operator=(InkBrushPaint&&) noexcept;
~InkBrushPaint();
enum class TextureMapping {
kTiling,
kWinding,
};
enum class TextureSizeUnit {
kBrushSize,
kStrokeSize,
kStrokeCoordinates,
};
enum class BlendMode {
kModulate,
kDstIn,
kDstOut,
kSrcAtop,
kSrcIn,
kSrcOver,
};
struct TextureKeyframe {
float progress;
std::optional<float> size_x;
std::optional<float> size_y;
std::optional<float> offset_x;
std::optional<float> offset_y;
std::optional<float> rotation_in_radians;
std::optional<float> opacity;
};
struct TextureLayer {
TextureLayer();
TextureLayer(const TextureLayer&);
TextureLayer& operator=(const TextureLayer&);
~TextureLayer();
std::string color_texture_uri;
TextureMapping mapping = TextureMapping::kTiling;
TextureSizeUnit size_unit = TextureSizeUnit::kStrokeCoordinates;
float size_x = 1;
float size_y = 1;
float offset_x = 0;
float offset_y = 0;
float rotation_in_radians = 0;
float size_jitter_x = 0;
float size_jitter_y = 0;
float offset_jitter_x = 0;
float offset_jitter_y = 0;
float rotation_jitter_in_radians = 0;
float opacity = 1;
std::vector<TextureKeyframe> keyframes;
BlendMode blend_mode = BlendMode::kModulate;
};
std::vector<TextureLayer> texture_layers;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_BRUSH_PAINT_H_

@ -1,17 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/ink_brush_tip.h"
namespace chrome_pdf {
InkBrushTip::InkBrushTip() = default;
InkBrushTip::InkBrushTip(InkBrushTip&&) noexcept = default;
InkBrushTip& InkBrushTip::operator=(InkBrushTip&&) noexcept = default;
InkBrushTip::~InkBrushTip() = default;
} // namespace chrome_pdf

@ -1,34 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_BRUSH_TIP_H_
#define PDF_INK_INK_BRUSH_TIP_H_
#include <vector>
#include "pdf/ink/ink_brush_behavior.h"
namespace chrome_pdf {
struct InkBrushTip {
InkBrushTip();
InkBrushTip(const InkBrushTip&) = delete;
InkBrushTip& operator=(const InkBrushTip&) = delete;
InkBrushTip(InkBrushTip&&) noexcept;
InkBrushTip& operator=(InkBrushTip&&) noexcept;
~InkBrushTip();
float scale_x = 1;
float scale_y = 1;
float corner_rounding = 1;
float slant = 0;
float pinch = 0;
float rotation = 0;
float opacity_multiplier = 1;
std::vector<InkBrushBehavior> behaviors;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_BRUSH_TIP_H_

@ -1,41 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_IN_PROGRESS_STROKE_H_
#define PDF_INK_INK_IN_PROGRESS_STROKE_H_
#include <memory>
namespace chrome_pdf {
class InkBrush;
class InkStroke;
class InkStrokeInputBatch;
class InkInProgressStroke {
public:
static std::unique_ptr<InkInProgressStroke> Create();
InkInProgressStroke(const InkInProgressStroke&) = delete;
InkInProgressStroke& operator=(const InkInProgressStroke&) = delete;
virtual ~InkInProgressStroke() = default;
virtual void Start(const InkBrush& brush) = 0;
virtual bool EnqueueInputs(const InkStrokeInputBatch* real_inputs,
const InkStrokeInputBatch* predicted_inputs) = 0;
virtual void FinishInputs() = 0;
virtual bool UpdateShape(float current_elapsed_time_seconds) = 0;
virtual std::unique_ptr<InkStroke> CopyToStroke() const = 0;
protected:
InkInProgressStroke() = default;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_IN_PROGRESS_STROKE_H_

@ -1,20 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_INTERSECTS_H_
#define PDF_INK_INK_INTERSECTS_H_
namespace chrome_pdf {
class InkModeledShapeView;
struct InkAffineTransform;
struct InkRect;
bool InkIntersectsRectWithShape(const InkRect& rect,
const InkModeledShapeView& shape,
const InkAffineTransform& transform);
} // namespace chrome_pdf
#endif // PDF_INK_INK_INTERSECTS_H_

@ -1,38 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_MODELED_SHAPE_VIEW_H_
#define PDF_INK_INK_MODELED_SHAPE_VIEW_H_
#include <stdint.h>
#include <vector>
#include "pdf/ink/ink_point.h"
#include "pdf/ink/ink_rect.h"
namespace chrome_pdf {
class InkModeledShapeView {
public:
using OutlinePositions = std::vector<InkPoint>;
using GroupsOutlines = std::vector<std::vector<OutlinePositions>>;
virtual ~InkModeledShapeView() = default;
virtual uint32_t RenderGroupCount() const = 0;
virtual uint32_t OutlineCount(uint32_t group_index) const = 0;
// Gets the collection of all outline positions for the 0-based render group
// index.
virtual std::vector<OutlinePositions> GetRenderGroupOutlinePositions(
uint32_t group_index) const = 0;
// Note that the return type is simpler and more straight-forward than Ink's.
virtual InkRect Bounds() const = 0;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_MODELED_SHAPE_VIEW_H_

@ -1,18 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_POINT_H_
#define PDF_INK_INK_POINT_H_
namespace chrome_pdf {
// A simple version of an Ink's Point struct.
struct InkPoint {
float x;
float y;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_POINT_H_

@ -1,25 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_RECT_H_
#define PDF_INK_INK_RECT_H_
namespace chrome_pdf {
// A simpler version of Ink's Rect class.
struct InkRect {
constexpr InkRect() = default;
constexpr InkRect(float x_min, float y_min, float x_max, float y_max)
: x_min(x_min), y_min(y_min), x_max(x_max), y_max(y_max) {}
~InkRect() = default;
float x_min = 0;
float y_min = 0;
float x_max = 0;
float y_max = 0;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_RECT_H_

@ -1,41 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_SKIA_RENDERER_H_
#define PDF_INK_INK_SKIA_RENDERER_H_
#include <memory>
class SkCanvas;
namespace chrome_pdf {
class InkInProgressStroke;
class InkStroke;
struct InkAffineTransform;
class InkSkiaRenderer {
public:
static std::unique_ptr<InkSkiaRenderer> Create();
InkSkiaRenderer(const InkSkiaRenderer&) = delete;
InkSkiaRenderer& operator=(const InkSkiaRenderer&) = delete;
virtual ~InkSkiaRenderer() = default;
// Note that the context parameter has been omitted, as it is always set to
// nullptr.
virtual bool Draw(const InkInProgressStroke& stroke,
const InkAffineTransform& object_to_canvas,
SkCanvas& canvas) = 0;
virtual bool Draw(const InkStroke& stroke,
const InkAffineTransform& object_to_canvas,
SkCanvas& canvas) = 0;
protected:
InkSkiaRenderer() = default;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_SKIA_RENDERER_H_

@ -1,47 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_STROKE_H_
#define PDF_INK_INK_STROKE_H_
#include <memory>
#include "pdf/ink/ink_modeled_shape_view.h"
#include "third_party/skia/include/core/SkColor.h"
namespace chrome_pdf {
class InkBrush;
class InkStrokeInputBatch;
class InkStrokeInputBatchView;
class InkStroke {
public:
// Create a stroke for use in testing. The `groups_outlines` and `bounds`
// parameters are needed only by the stub implementation; they will be
// ignored by the wrapper, which can generate a real modeled shape using
// `inputs`.
// TODO(crbug.com/339682315): Remove the parameters used only by the stub
// implementation once the wrapper is fully available.
static std::unique_ptr<InkStroke> CreateForTesting(
const InkBrush& brush,
const InkStrokeInputBatch& inputs,
const InkModeledShapeView::GroupsOutlines& groups_outlines,
const InkRect& bounds);
virtual ~InkStroke() = default;
// Get the color used with the brush for this stroke. Ink's API allows
// access to the entire ink brush from a stroke; this is a simplication of
// that, to allow only getting the color of the brush used.
virtual SkColor GetBrushColor() const = 0;
virtual const InkStrokeInputBatchView& GetInputs() const = 0;
virtual const InkModeledShapeView& GetShape() const = 0;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_STROKE_H_

@ -1,31 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_STROKE_INPUT_H_
#define PDF_INK_INK_STROKE_INPUT_H_
#include <cstdint>
#include "pdf/ink/ink_point.h"
namespace chrome_pdf {
struct InkStrokeInput {
enum class ToolType : int8_t { kUnknown, kMouse, kTouch, kStylus };
static constexpr float kNoPressure = -1;
static constexpr float kNoTilt = -1;
static constexpr float kNoOrientation = -1;
ToolType tool_type = ToolType::kUnknown;
InkPoint position;
float elapsed_time_seconds;
float pressure = kNoPressure;
float tilt_in_radians = kNoTilt;
float orientation_in_radians = kNoOrientation;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_STROKE_INPUT_H_

@ -1,31 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_STROKE_INPUT_BATCH_H_
#define PDF_INK_INK_STROKE_INPUT_BATCH_H_
#include <stddef.h>
#include <memory>
#include <vector>
#include "pdf/ink/ink_stroke_input.h"
namespace chrome_pdf {
class InkStrokeInputBatch {
public:
static std::unique_ptr<InkStrokeInputBatch> Create(
const std::vector<InkStrokeInput>& inputs);
virtual ~InkStrokeInputBatch() = default;
virtual size_t Size() const = 0;
virtual InkStrokeInput Get(size_t i) const = 0;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_STROKE_INPUT_BATCH_H_

@ -1,25 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_INK_STROKE_INPUT_BATCH_VIEW_H_
#define PDF_INK_INK_STROKE_INPUT_BATCH_VIEW_H_
#include <stddef.h>
#include "pdf/ink/ink_stroke_input.h"
namespace chrome_pdf {
class InkStrokeInputBatchView {
public:
virtual ~InkStrokeInputBatchView() = default;
virtual size_t Size() const = 0;
virtual InkStrokeInput Get(size_t i) const = 0;
};
} // namespace chrome_pdf
#endif // PDF_INK_INK_STROKE_INPUT_BATCH_VIEW_H_

@ -1,40 +0,0 @@
# Copyright 2024 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//pdf/features.gni")
assert(enable_pdf_ink2)
source_set("stub") {
visibility = [ "//pdf/ink" ]
sources = [
"ink_brush_family_stub.cc",
"ink_brush_family_stub.h",
"ink_brush_stub.cc",
"ink_brush_stub.h",
"ink_in_progress_stroke_stub.cc",
"ink_in_progress_stroke_stub.h",
"ink_intersects_stub.cc",
"ink_modeled_shape_view_stub.cc",
"ink_modeled_shape_view_stub.h",
"ink_skia_renderer_stub.cc",
"ink_skia_renderer_stub.h",
"ink_stroke_input_batch_stub.cc",
"ink_stroke_input_batch_stub.h",
"ink_stroke_input_batch_view_stub.cc",
"ink_stroke_input_batch_view_stub.h",
"ink_stroke_stub.cc",
"ink_stroke_stub.h",
]
configs += [ "//pdf:strict" ]
public_deps = [ "//pdf/ink:interface" ]
deps = [
"//base",
"//skia",
]
}

@ -1,5 +0,0 @@
include_rules = [
# This overrides the -base rule in the parent directory, as this is a stub and
# there is no Ink code here.
"+base",
]

@ -1,36 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/stub/ink_brush_family_stub.h"
#include <memory>
#include <utility>
#include "pdf/ink/ink_brush_paint.h"
#include "pdf/ink/ink_brush_tip.h"
namespace chrome_pdf {
// static
std::unique_ptr<InkBrushFamily> InkBrushFamily::Create(
InkBrushTip tip,
InkBrushPaint paint,
std::string_view uri_string) {
return std::make_unique<InkBrushFamilyStub>(std::move(tip));
}
InkBrushFamilyStub::InkBrushFamilyStub(InkBrushTip tip)
: corner_rounding_(tip.corner_rounding), opacity_(tip.opacity_multiplier) {}
InkBrushFamilyStub::~InkBrushFamilyStub() = default;
float InkBrushFamilyStub::GetCornerRoundingForTesting() const {
return corner_rounding_;
}
float InkBrushFamilyStub::GetOpacityForTesting() const {
return opacity_;
}
} // namespace chrome_pdf

@ -1,31 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_STUB_INK_BRUSH_FAMILY_STUB_H_
#define PDF_INK_STUB_INK_BRUSH_FAMILY_STUB_H_
#include "pdf/ink/ink_brush_family.h"
#include "pdf/ink/ink_brush_tip.h"
namespace chrome_pdf {
class InkBrushFamilyStub : public InkBrushFamily {
public:
explicit InkBrushFamilyStub(InkBrushTip tip);
InkBrushFamilyStub(const InkBrushFamilyStub&) = delete;
InkBrushFamilyStub& operator=(const InkBrushFamilyStub&) = delete;
~InkBrushFamilyStub() override;
// InkBrushFamily:
float GetCornerRoundingForTesting() const override;
float GetOpacityForTesting() const override;
private:
const float corner_rounding_;
const float opacity_;
};
} // namespace chrome_pdf
#endif // PDF_INK_STUB_INK_BRUSH_FAMILY_STUB_H_

@ -1,54 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/stub/ink_brush_stub.h"
#include <memory>
#include <utility>
#include "pdf/ink/ink_brush_family.h"
#include "pdf/ink/ink_brush_tip.h"
#include "third_party/skia/include/core/SkColor.h"
namespace chrome_pdf {
// static
std::unique_ptr<InkBrush> InkBrush::Create(
std::unique_ptr<InkBrushFamily> family,
SkColor color,
float size,
float epsilon) {
if (!family) {
return nullptr;
}
return std::make_unique<InkBrushStub>(std::move(family), color, size,
epsilon);
}
InkBrushStub::InkBrushStub(std::unique_ptr<InkBrushFamily> family,
SkColor color,
float size,
float epsilon)
: family_(std::move(family)), color_(color), size_(size) {}
InkBrushStub::~InkBrushStub() = default;
float InkBrushStub::GetSize() const {
return size_;
}
SkColor InkBrushStub::GetColor() const {
return color_;
}
float InkBrushStub::GetCornerRoundingForTesting() const {
return family_->GetCornerRoundingForTesting(); // IN-TEST
}
float InkBrushStub::GetOpacityForTesting() const {
return family_->GetOpacityForTesting(); // IN-TEST
}
} // namespace chrome_pdf

@ -1,41 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_STUB_INK_BRUSH_STUB_H_
#define PDF_INK_STUB_INK_BRUSH_STUB_H_
#include <memory>
#include "pdf/ink/ink_brush.h"
#include "third_party/skia/include/core/SkColor.h"
namespace chrome_pdf {
class InkBrushFamily;
class InkBrushStub : public InkBrush {
public:
InkBrushStub(std::unique_ptr<InkBrushFamily> family,
SkColor color,
float size,
float epsilon);
InkBrushStub(const InkBrushStub&) = delete;
InkBrushStub& operator=(const InkBrushStub&) = delete;
~InkBrushStub() override;
// InkBrush:
float GetSize() const override;
SkColor GetColor() const override;
float GetCornerRoundingForTesting() const override;
float GetOpacityForTesting() const override;
private:
std::unique_ptr<InkBrushFamily> family_;
const SkColor color_;
const float size_;
};
} // namespace chrome_pdf
#endif // PDF_INK_STUB_INK_BRUSH_STUB_H_

@ -1,50 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/stub/ink_in_progress_stroke_stub.h"
#include <memory>
#include "pdf/ink/ink_brush.h"
#include "pdf/ink/stub/ink_stroke_stub.h"
namespace chrome_pdf {
// static
std::unique_ptr<InkInProgressStroke> InkInProgressStroke::Create() {
return std::make_unique<InkInProgressStrokeStub>();
}
InkInProgressStrokeStub::InkInProgressStrokeStub() = default;
InkInProgressStrokeStub::~InkInProgressStrokeStub() = default;
void InkInProgressStrokeStub::Start(const InkBrush& brush) {
brush_color_ = brush.GetColor();
}
bool InkInProgressStrokeStub::EnqueueInputs(
const InkStrokeInputBatch* real_inputs,
const InkStrokeInputBatch* predicted_inputs) {
if (!real_inputs) {
return false;
}
// Capture copy of input.
inputs_ = *static_cast<const InkStrokeInputBatchStub*>(real_inputs);
return true;
}
void InkInProgressStrokeStub::FinishInputs() {}
bool InkInProgressStrokeStub::UpdateShape(float current_elapsed_time_seconds) {
// Pretend shape update succeeded, even though nothing is done here.
return true;
}
std::unique_ptr<InkStroke> InkInProgressStrokeStub::CopyToStroke() const {
return std::make_unique<InkStrokeStub>(brush_color_, inputs_);
}
} // namespace chrome_pdf

@ -1,36 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_STUB_INK_IN_PROGRESS_STROKE_STUB_H_
#define PDF_INK_STUB_INK_IN_PROGRESS_STROKE_STUB_H_
#include "pdf/ink/ink_in_progress_stroke.h"
#include "pdf/ink/stub/ink_stroke_input_batch_stub.h"
#include "third_party/skia/include/core/SkColor.h"
namespace chrome_pdf {
class InkInProgressStrokeStub : public InkInProgressStroke {
public:
InkInProgressStrokeStub();
InkInProgressStrokeStub(const InkInProgressStrokeStub&) = delete;
InkInProgressStrokeStub& operator=(const InkInProgressStrokeStub&) = delete;
~InkInProgressStrokeStub() override;
// InkInProgressStroke:
void Start(const InkBrush& brush) override;
bool EnqueueInputs(const InkStrokeInputBatch* real_inputs,
const InkStrokeInputBatch* predicted_inputs) override;
void FinishInputs() override;
bool UpdateShape(float current_elapsed_time_seconds) override;
std::unique_ptr<InkStroke> CopyToStroke() const override;
private:
SkColor brush_color_ = SkColorSetARGB(0, 0, 0, 0);
InkStrokeInputBatchStub inputs_;
};
} // namespace chrome_pdf
#endif // PDF_INK_STUB_INK_IN_PROGRESS_STROKE_STUB_H_

@ -1,15 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/ink_intersects.h"
namespace chrome_pdf {
bool InkIntersectsRectWithShape(const InkRect& rect,
const InkModeledShapeView& shape,
const InkAffineTransform& transform) {
return true;
}
} // namespace chrome_pdf

@ -1,42 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/stub/ink_modeled_shape_view_stub.h"
#include <memory>
#include "base/check_op.h"
namespace chrome_pdf {
InkModeledShapeViewStub::InkModeledShapeViewStub() = default;
InkModeledShapeViewStub::InkModeledShapeViewStub(
const GroupsOutlines& groups_outlines,
const InkRect& bounds)
: groups_outlines_(groups_outlines), bounds_(bounds) {}
InkModeledShapeViewStub::~InkModeledShapeViewStub() = default;
uint32_t InkModeledShapeViewStub::RenderGroupCount() const {
return groups_outlines_.size();
}
uint32_t InkModeledShapeViewStub::OutlineCount(uint32_t group_index) const {
CHECK_LT(group_index, groups_outlines_.size());
return groups_outlines_[group_index].size();
}
std::vector<InkModeledShapeView::OutlinePositions>
InkModeledShapeViewStub::GetRenderGroupOutlinePositions(
uint32_t group_index) const {
CHECK_LT(group_index, groups_outlines_.size());
return groups_outlines_[group_index];
}
InkRect InkModeledShapeViewStub::Bounds() const {
return bounds_;
}
} // namespace chrome_pdf

@ -1,35 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_STUB_INK_MODELED_SHAPE_VIEW_STUB_H_
#define PDF_INK_STUB_INK_MODELED_SHAPE_VIEW_STUB_H_
#include "pdf/ink/ink_modeled_shape_view.h"
namespace chrome_pdf {
class InkModeledShapeViewStub : public InkModeledShapeView {
public:
InkModeledShapeViewStub();
InkModeledShapeViewStub(const GroupsOutlines& groups_outlines,
const InkRect& bounds);
InkModeledShapeViewStub(const InkModeledShapeViewStub&) = delete;
InkModeledShapeViewStub& operator=(const InkModeledShapeViewStub&) = delete;
~InkModeledShapeViewStub() override;
// InkModeledShapeView:
uint32_t RenderGroupCount() const override;
uint32_t OutlineCount(uint32_t group_index) const override;
std::vector<OutlinePositions> GetRenderGroupOutlinePositions(
uint32_t group_index) const override;
InkRect Bounds() const override;
private:
const GroupsOutlines groups_outlines_;
const InkRect bounds_;
};
} // namespace chrome_pdf
#endif // PDF_INK_STUB_INK_MODELED_SHAPE_VIEW_STUB_H_

@ -1,28 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/stub/ink_skia_renderer_stub.h"
#include <memory>
namespace chrome_pdf {
// static
std::unique_ptr<InkSkiaRenderer> InkSkiaRenderer::Create() {
return std::make_unique<InkSkiaRendererStub>();
}
bool InkSkiaRendererStub::Draw(const InkInProgressStroke& stroke,
const InkAffineTransform& object_to_canvas,
SkCanvas& canvas) {
return true;
}
bool InkSkiaRendererStub::Draw(const InkStroke& stroke,
const InkAffineTransform& object_to_canvas,
SkCanvas& canvas) {
return true;
}
} // namespace chrome_pdf

@ -1,25 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_STUB_INK_SKIA_RENDERER_STUB_H_
#define PDF_INK_STUB_INK_SKIA_RENDERER_STUB_H_
#include "pdf/ink/ink_skia_renderer.h"
namespace chrome_pdf {
class InkSkiaRendererStub : public InkSkiaRenderer {
public:
// InkSkiaRenderer:
bool Draw(const InkInProgressStroke& stroke,
const InkAffineTransform& object_to_canvas,
SkCanvas& canvas) override;
bool Draw(const InkStroke& stroke,
const InkAffineTransform& object_to_canvas,
SkCanvas& canvas) override;
};
} // namespace chrome_pdf
#endif // PDF_INK_STUB_INK_SKIA_RENDERER_STUB_H_

@ -1,42 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/stub/ink_stroke_input_batch_stub.h"
#include <memory>
#include "base/check_op.h"
namespace chrome_pdf {
// static
std::unique_ptr<InkStrokeInputBatch> InkStrokeInputBatch::Create(
const std::vector<InkStrokeInput>& inputs) {
return std::make_unique<InkStrokeInputBatchStub>(inputs);
}
InkStrokeInputBatchStub::InkStrokeInputBatchStub() = default;
InkStrokeInputBatchStub::InkStrokeInputBatchStub(
const InkStrokeInputBatchStub& other) = default;
InkStrokeInputBatchStub& InkStrokeInputBatchStub::operator=(
const InkStrokeInputBatchStub& other) = default;
InkStrokeInputBatchStub::InkStrokeInputBatchStub(
const std::vector<InkStrokeInput>& inputs)
: inputs_(std::move(inputs)) {}
InkStrokeInputBatchStub::~InkStrokeInputBatchStub() = default;
size_t InkStrokeInputBatchStub::Size() const {
return inputs_.size();
}
InkStrokeInput InkStrokeInputBatchStub::Get(size_t i) const {
CHECK_LT(i, inputs_.size());
return inputs_[i];
}
} // namespace chrome_pdf

@ -1,33 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_STUB_INK_STROKE_INPUT_BATCH_STUB_H_
#define PDF_INK_STUB_INK_STROKE_INPUT_BATCH_STUB_H_
#include <vector>
#include "pdf/ink/ink_stroke_input.h"
#include "pdf/ink/ink_stroke_input_batch.h"
namespace chrome_pdf {
class InkStrokeInputBatchStub : public InkStrokeInputBatch {
public:
InkStrokeInputBatchStub();
explicit InkStrokeInputBatchStub(const std::vector<InkStrokeInput>& inputs);
InkStrokeInputBatchStub(const InkStrokeInputBatchStub& other);
InkStrokeInputBatchStub& operator=(const InkStrokeInputBatchStub& other);
~InkStrokeInputBatchStub() override;
// `InkStrokeInputBatch`:
size_t Size() const override;
InkStrokeInput Get(size_t i) const override;
private:
std::vector<InkStrokeInput> inputs_;
};
} // namespace chrome_pdf
#endif // PDF_INK_STUB_INK_STROKE_INPUT_BATCH_STUB_H_

@ -1,25 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/stub/ink_stroke_input_batch_view_stub.h"
#include "pdf/ink/stub/ink_stroke_input_batch_stub.h"
namespace chrome_pdf {
InkStrokeInputBatchViewStub::InkStrokeInputBatchViewStub(
const InkStrokeInputBatchStub& impl)
: impl_(impl) {}
InkStrokeInputBatchViewStub::~InkStrokeInputBatchViewStub() = default;
size_t InkStrokeInputBatchViewStub::Size() const {
return impl_->Size();
}
InkStrokeInput InkStrokeInputBatchViewStub::Get(size_t i) const {
return impl_->Get(i);
}
} // namespace chrome_pdf

@ -1,33 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_STUB_INK_STROKE_INPUT_BATCH_VIEW_STUB_H_
#define PDF_INK_STUB_INK_STROKE_INPUT_BATCH_VIEW_STUB_H_
#include "base/memory/raw_ref.h"
#include "pdf/ink/ink_stroke_input_batch_view.h"
namespace chrome_pdf {
class InkStrokeInputBatchStub;
class InkStrokeInputBatchViewStub : public InkStrokeInputBatchView {
public:
explicit InkStrokeInputBatchViewStub(const InkStrokeInputBatchStub& impl);
InkStrokeInputBatchViewStub(const InkStrokeInputBatchViewStub&) = delete;
InkStrokeInputBatchViewStub& operator=(const InkStrokeInputBatchViewStub&) =
delete;
~InkStrokeInputBatchViewStub() override;
// InkStrokeInputBatchView:
size_t Size() const override;
InkStrokeInput Get(size_t i) const override;
private:
const base::raw_ref<const InkStrokeInputBatchStub> impl_;
};
} // namespace chrome_pdf
#endif // PDF_INK_STUB_INK_STROKE_INPUT_BATCH_VIEW_STUB_H_

@ -1,61 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ink/stub/ink_stroke_stub.h"
#include "base/check_is_test.h"
#include "pdf/ink/ink_brush.h"
#include "pdf/ink/ink_rect.h"
#include "pdf/ink/stub/ink_modeled_shape_view_stub.h"
#include "pdf/ink/stub/ink_stroke_input_batch_stub.h"
#include "pdf/ink/stub/ink_stroke_input_batch_view_stub.h"
namespace chrome_pdf {
InkStrokeStub::InkStrokeStub(SkColor brush_color,
const InkStrokeInputBatchStub& inputs)
: brush_color_(brush_color),
shape_(InkModeledShapeViewStub(InkModeledShapeView::GroupsOutlines(),
InkRect())),
inputs_(inputs),
inputs_view_(inputs_) {}
InkStrokeStub::InkStrokeStub(
SkColor brush_color,
const InkStrokeInputBatchStub& inputs,
const InkModeledShapeView::GroupsOutlines& groups_outlines,
const InkRect& bounds)
: brush_color_(brush_color),
shape_(InkModeledShapeViewStub(groups_outlines, bounds)),
inputs_(inputs),
inputs_view_(inputs_) {
CHECK_IS_TEST();
}
InkStrokeStub::~InkStrokeStub() = default;
SkColor InkStrokeStub::GetBrushColor() const {
return brush_color_;
}
const InkStrokeInputBatchView& InkStrokeStub::GetInputs() const {
return inputs_view_;
}
const InkModeledShapeView& InkStrokeStub::GetShape() const {
return shape_;
}
// static
std::unique_ptr<InkStroke> InkStroke::CreateForTesting(
const InkBrush& brush,
const InkStrokeInputBatch& inputs,
const InkModeledShapeView::GroupsOutlines& groups_outlines,
const InkRect& bounds) {
return std::make_unique<InkStrokeStub>(
brush.GetColor(), static_cast<const InkStrokeInputBatchStub&>(inputs),
groups_outlines, bounds);
}
} // namespace chrome_pdf

@ -1,43 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_INK_STUB_INK_STROKE_STUB_H_
#define PDF_INK_STUB_INK_STROKE_STUB_H_
#include "pdf/ink/ink_stroke.h"
#include "pdf/ink/stub/ink_modeled_shape_view_stub.h"
#include "pdf/ink/stub/ink_stroke_input_batch_stub.h"
#include "pdf/ink/stub/ink_stroke_input_batch_view_stub.h"
#include "third_party/skia/include/core/SkColor.h"
namespace chrome_pdf {
struct InkRect;
class InkStrokeStub : public InkStroke {
public:
InkStrokeStub(SkColor brush_color, const InkStrokeInputBatchStub& inputs);
InkStrokeStub(SkColor brush_color,
const InkStrokeInputBatchStub& inputs,
const InkModeledShapeView::GroupsOutlines& groups_outlines,
const InkRect& bounds);
InkStrokeStub(const InkStrokeStub&) = delete;
InkStrokeStub& operator=(const InkStrokeStub&) = delete;
~InkStrokeStub() override;
// InkStroke:
SkColor GetBrushColor() const override;
const InkStrokeInputBatchView& GetInputs() const override;
const InkModeledShapeView& GetShape() const override;
private:
const SkColor brush_color_;
const InkModeledShapeViewStub shape_;
const InkStrokeInputBatchStub inputs_;
const InkStrokeInputBatchViewStub inputs_view_;
};
} // namespace chrome_pdf
#endif // PDF_INK_STUB_INK_STROKE_STUB_H_

@ -10,10 +10,10 @@
#include "base/check_op.h"
#include "base/notreached.h"
#include "pdf/ink/ink_brush.h"
#include "pdf/ink/ink_brush_family.h"
#include "pdf/ink/ink_brush_paint.h"
#include "pdf/ink/ink_brush_tip.h"
#include "third_party/ink/src/ink/brush/brush.h"
#include "third_party/ink/src/ink/brush/brush_family.h"
#include "third_party/ink/src/ink/brush/brush_paint.h"
#include "third_party/ink/src/ink/brush/brush_tip.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect_conversions.h"
@ -21,9 +21,11 @@ namespace chrome_pdf {
namespace {
std::string CreateBrushUri() {
ink::Uri CreateBrushUri() {
// TODO(crbug.com/353942923): Use real value here.
return "ink://ink/texture:test-texture";
auto uri = ink::Uri::Parse("ink://ink/texture:test-texture");
CHECK(uri.ok());
return *uri;
}
float GetCornerRounding(PdfInkBrush::Type type) {
@ -48,36 +50,42 @@ float GetOpacity(PdfInkBrush::Type type) {
NOTREACHED();
}
std::unique_ptr<InkBrush> CreateInkBrush(PdfInkBrush::Type type,
PdfInkBrush::Params params) {
ink::Brush CreateInkBrush(PdfInkBrush::Type type, PdfInkBrush::Params params) {
CHECK_GT(params.size, 0);
// TODO(crbug.com/353942923): Use real values here.
InkBrushTip tip;
ink::BrushTip tip;
tip.corner_rounding = GetCornerRounding(type);
tip.opacity_multiplier = GetOpacity(type);
InkBrushPaint::TextureLayer layer;
// TODO(crbug.com/353942923): Use real value here.
ink::BrushPaint::TextureLayer layer;
layer.color_texture_uri = CreateBrushUri();
layer.mapping = InkBrushPaint::TextureMapping::kWinding;
layer.size_unit = InkBrushPaint::TextureSizeUnit::kBrushSize;
layer.size_x = 3;
layer.size_y = 5;
layer.size_jitter_x = 0.1;
layer.size_jitter_y = 2;
layer.mapping = ink::BrushPaint::TextureMapping::kWinding;
layer.size_unit = ink::BrushPaint::TextureSizeUnit::kBrushSize;
layer.size = {3, 5};
layer.size_jitter = {0.1, 2};
layer.keyframes = {
{.progress = 0.1, .rotation_in_radians = std::numbers::pi_v<float> / 4}};
layer.blend_mode = InkBrushPaint::BlendMode::kSrcIn;
{.progress = 0.1,
.rotation = ink::Angle::Radians(std::numbers::pi_v<float> / 4)}};
layer.blend_mode = ink::BrushPaint::BlendMode::kSrcIn;
InkBrushPaint paint;
ink::BrushPaint paint;
paint.texture_layers.push_back(layer);
auto family = InkBrushFamily::Create(std::move(tip), std::move(paint), "");
CHECK(family);
auto family = ink::BrushFamily::Create(std::move(tip), std::move(paint), "");
CHECK(family.ok());
return InkBrush::Create(std::move(family),
/*color=*/params.color,
/*size=*/params.size,
/*epsilon=*/0.1f);
auto brush = ink::Brush::Create(*family,
/*color=*/
ink::Color::FromUint8(
/*red=*/SkColorGetR(params.color),
/*green=*/SkColorGetG(params.color),
/*blue=*/SkColorGetB(params.color),
/*alpha=*/SkColorGetA(params.color)),
/*size=*/params.size,
/*epsilon=*/0.1f);
CHECK(brush.ok());
return *brush;
}
// Determine the area to invalidate centered around a point where a brush is
@ -113,20 +121,19 @@ void PdfInkBrush::CheckToolSizeIsInRange(float size) {
PdfInkBrush::PdfInkBrush(Type brush_type, Params brush_params)
: ink_brush_(CreateInkBrush(brush_type, brush_params)) {
CHECK(ink_brush_);
}
PdfInkBrush::~PdfInkBrush() = default;
const InkBrush& PdfInkBrush::GetInkBrush() const {
return *ink_brush_;
const ink::Brush& PdfInkBrush::GetInkBrush() const {
return ink_brush_;
}
gfx::Rect PdfInkBrush::GetInvalidateArea(const gfx::PointF& center1,
const gfx::PointF& center2) const {
// For a line connecting `center1` to `center2`, the invalidate
// region is the union between the areas affected by them both.
float brush_diameter = ink_brush_->GetSize();
float brush_diameter = ink_brush_.GetSize();
gfx::Rect area1 = GetPointInvalidateArea(brush_diameter, center1);
gfx::Rect area2 = GetPointInvalidateArea(brush_diameter, center2);
area2.Union(area1);

@ -9,6 +9,7 @@
#include <optional>
#include <string>
#include "third_party/ink/src/ink/brush/brush.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/rect.h"
@ -18,8 +19,6 @@ class PointF;
namespace chrome_pdf {
class InkBrush;
// A class used to create ink brushes for PDF annotation mode and support
// invalidation for rendering.
class PdfInkBrush {
@ -56,12 +55,12 @@ class PdfInkBrush {
// Validates `size` is in range.
static void CheckToolSizeIsInRange(float size);
// Returns the `InkBrush` that `this` represents.
const InkBrush& GetInkBrush() const;
// Returns the `ink::Brush` that `this` represents.
const ink::Brush& GetInkBrush() const;
private:
// The ink brush of type `type_` with params` params_`. Always non-nullptr.
std::unique_ptr<InkBrush> ink_brush_;
// The ink brush of type `type_` with params` params_`.
ink::Brush ink_brush_;
};
} // namespace chrome_pdf

@ -24,16 +24,6 @@
#include "base/time/time.h"
#include "base/values.h"
#include "pdf/draw_utils/page_boundary_intersect.h"
#include "pdf/ink/ink_affine_transform.h"
#include "pdf/ink/ink_brush.h"
#include "pdf/ink/ink_in_progress_stroke.h"
#include "pdf/ink/ink_intersects.h"
#include "pdf/ink/ink_modeled_shape_view.h"
#include "pdf/ink/ink_rect.h"
#include "pdf/ink/ink_skia_renderer.h"
#include "pdf/ink/ink_stroke.h"
#include "pdf/ink/ink_stroke_input_batch.h"
#include "pdf/ink/ink_stroke_input_batch_view.h"
#include "pdf/input_utils.h"
#include "pdf/pdf_features.h"
#include "pdf/pdf_ink_brush.h"
@ -42,6 +32,15 @@
#include "pdf/pdf_ink_transform.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"
#include "third_party/ink/src/ink/brush/brush.h"
#include "third_party/ink/src/ink/geometry/affine_transform.h"
#include "third_party/ink/src/ink/geometry/intersects.h"
#include "third_party/ink/src/ink/geometry/modeled_shape.h"
#include "third_party/ink/src/ink/geometry/rect.h"
#include "third_party/ink/src/ink/rendering/skia/native/skia_renderer.h"
#include "third_party/ink/src/ink/strokes/in_progress_stroke.h"
#include "third_party/ink/src/ink/strokes/input/stroke_input_batch.h"
#include "third_party/ink/src/ink/strokes/stroke.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
@ -56,11 +55,11 @@ namespace chrome_pdf {
namespace {
PdfInkModule::StrokeInputPoints GetStrokePointsForTesting( // IN-TEST
const InkStrokeInputBatchView& input_batch) {
const ink::StrokeInputBatch& input_batch) {
PdfInkModule::StrokeInputPoints stroke_points;
stroke_points.reserve(input_batch.Size());
for (size_t i = 0; i < input_batch.Size(); ++i) {
InkStrokeInput stroke_input = input_batch.Get(i);
ink::StrokeInput stroke_input = input_batch.Get(i);
stroke_points.emplace_back(stroke_input.position.x,
stroke_input.position.y);
}
@ -80,34 +79,15 @@ void CheckColorIsWithinRange(int color) {
CHECK_LE(color, 255);
}
InkRect GetEraserRect(const gfx::PointF& center, int distance_to_center) {
return {
center.x() - distance_to_center,
center.y() - distance_to_center,
center.x() + distance_to_center,
center.y() + distance_to_center,
};
ink::Rect GetEraserRect(const gfx::PointF& center, int distance_to_center) {
return ink::Rect::FromTwoPoints(
{center.x() - distance_to_center, center.y() - distance_to_center},
{center.x() + distance_to_center, center.y() + distance_to_center});
}
void UnionInkRects(std::optional<InkRect>& result_rect,
const InkRect& new_rect) {
if (result_rect.has_value()) {
auto& value = result_rect.value();
value.x_min = std::min(value.x_min, new_rect.x_min);
value.y_min = std::min(value.y_min, new_rect.y_min);
value.x_max = std::max(value.x_max, new_rect.x_max);
value.y_max = std::max(value.y_max, new_rect.y_max);
} else {
result_rect = new_rect;
}
}
gfx::Rect InkRectToEnclosingGfxRect(const InkRect& rect) {
const float x = rect.x_min;
const float y = rect.y_min;
const float width = rect.x_max - x;
const float height = rect.y_max - y;
return gfx::ToEnclosingRect(gfx::RectF(x, y, width, height));
gfx::Rect InkRectToEnclosingGfxRect(const ink::Rect& rect) {
return gfx::ToEnclosingRect(
gfx::RectF(rect.XMin(), rect.YMin(), rect.Width(), rect.Height()));
}
SkRect GetDrawPageClipRect(const gfx::Rect& content_rect,
@ -128,7 +108,7 @@ PdfInkModule::PdfInkModule(PdfInkModuleClient& client) : client_(client) {
PdfInkModule::~PdfInkModule() = default;
void PdfInkModule::Draw(SkCanvas& canvas) {
auto skia_renderer = InkSkiaRenderer::Create();
ink::SkiaRenderer skia_renderer;
const gfx::Vector2dF origin_offset = client_->GetViewportOriginOffset();
const PageOrientation rotation = client_->GetOrientation();
@ -142,7 +122,7 @@ void PdfInkModule::Draw(SkCanvas& canvas) {
// Use an updated transform based on the page and its position in the
// viewport.
const gfx::Rect content_rect = client_->GetPageContentsRect(page_index);
const InkAffineTransform transform =
const ink::AffineTransform transform =
GetInkRenderTransform(origin_offset, rotation, content_rect, zoom);
if (draw_render_transform_callback_for_testing_) {
draw_render_transform_callback_for_testing_.Run(transform);
@ -155,9 +135,9 @@ void PdfInkModule::Draw(SkCanvas& canvas) {
continue;
}
bool success =
skia_renderer->Draw(*finished_stroke.stroke, transform, canvas);
CHECK(success);
auto status = skia_renderer.Draw(nullptr, finished_stroke.stroke,
transform, canvas);
CHECK(status.ok());
}
}
@ -167,7 +147,7 @@ void PdfInkModule::Draw(SkCanvas& canvas) {
const gfx::Rect content_rect =
client_->GetPageContentsRect(state.page_index);
const InkAffineTransform transform =
const ink::AffineTransform transform =
GetInkRenderTransform(origin_offset, rotation, content_rect, zoom);
if (draw_render_transform_callback_for_testing_) {
draw_render_transform_callback_for_testing_.Run(transform);
@ -176,8 +156,8 @@ void PdfInkModule::Draw(SkCanvas& canvas) {
SkAutoCanvasRestore save_restore(&canvas, /*doSave=*/true);
canvas.clipRect(GetDrawPageClipRect(content_rect, origin_offset));
for (const auto& segment : in_progress_stroke) {
bool success = skia_renderer->Draw(*segment, transform, canvas);
CHECK(success);
auto status = skia_renderer.Draw(nullptr, segment, transform, canvas);
CHECK(status.ok());
}
}
}
@ -197,17 +177,17 @@ bool PdfInkModule::DrawThumbnail(SkCanvas& canvas, int page_index) {
std::min(
static_cast<float>(canvas_info.width()) / content_rect.width(),
static_cast<float>(canvas_info.height()) / content_rect.height());
const InkAffineTransform transform = {ratio, 0, 0, 0, ratio, 0};
const ink::AffineTransform transform = {ratio, 0, 0, 0, ratio, 0};
auto skia_renderer = InkSkiaRenderer::Create();
ink::SkiaRenderer skia_renderer;
for (const FinishedStrokeState& finished_stroke : it->second) {
if (!finished_stroke.should_draw) {
continue;
}
bool success =
skia_renderer->Draw(*finished_stroke.stroke, transform, canvas);
CHECK(success);
auto status =
skia_renderer.Draw(nullptr, finished_stroke.stroke, transform, canvas);
CHECK(status.ok());
}
// No need to draw in-progress strokes, since DrawThumbnail() only gets called
@ -276,7 +256,7 @@ PdfInkModule::GetStrokesInputPositionsForTesting() const {
for (const auto& [page_index, strokes] : strokes_) {
for (const auto& stroke : strokes) {
all_strokes_points[page_index].push_back(
GetStrokePointsForTesting(stroke.stroke->GetInputs())); // IN-TEST
GetStrokePointsForTesting(stroke.stroke.GetInputs())); // IN-TEST
}
}
@ -294,7 +274,7 @@ PdfInkModule::GetVisibleStrokesInputPositionsForTesting() const {
}
all_strokes_points[page_index].push_back(
GetStrokePointsForTesting(stroke.stroke->GetInputs())); // IN-TEST
GetStrokePointsForTesting(stroke.stroke.GetInputs())); // IN-TEST
}
}
@ -359,8 +339,7 @@ bool PdfInkModule::StartStroke(const gfx::PointF& position) {
// Start of the first segment of a stroke.
StrokeInputSegment segment;
segment.push_back({
.position = InkPoint{page_position.x(), page_position.y()},
.elapsed_time_seconds = 0,
.position = {page_position.x(), page_position.y()},
});
state.inputs.push_back(std::move(segment));
@ -468,7 +447,7 @@ bool PdfInkModule::FinishStroke(const gfx::PointF& position) {
for (const auto& segment : in_progress_stroke_segments) {
size_t id = stroke_id_generator_.GetIdAndAdvance();
strokes_[state.page_index].push_back(
FinishedStrokeState(segment->CopyToStroke(), id));
FinishedStrokeState(segment.CopyToStroke(), id));
bool undo_redo_success = undo_redo_model_.Draw(id);
CHECK(undo_redo_success);
}
@ -567,9 +546,9 @@ bool PdfInkModule::EraseHelper(const gfx::PointF& position, int page_index) {
gfx::PointF canonical_position =
ConvertEventPositionToCanonicalPosition(position, page_index);
const InkRect eraser_rect =
const ink::Rect eraser_rect =
GetEraserRect(canonical_position, erasing_stroke_state().eraser_size);
std::optional<InkRect> invalidate_rect;
ink::Envelope invalidate_envelope;
for (auto& stroke : it->second) {
if (!stroke.should_draw) {
// Already erased.
@ -578,20 +557,22 @@ bool PdfInkModule::EraseHelper(const gfx::PointF& position, int page_index) {
// No transform needed, as `eraser_rect` is already using transformed
// coordinates from `canonical_position`.
static constexpr InkAffineTransform kIdentityTransform = {1, 0, 0, 0, 1, 0};
const InkModeledShapeView& shape = stroke.stroke->GetShape();
if (!InkIntersectsRectWithShape(eraser_rect, shape, kIdentityTransform)) {
static constexpr ink::AffineTransform kIdentityTransform;
const ink::ModeledShape& shape = stroke.stroke.GetShape();
if (!ink::Intersects(eraser_rect, shape, kIdentityTransform)) {
continue;
}
stroke.should_draw = false;
UnionInkRects(invalidate_rect, shape.Bounds());
invalidate_envelope.Add(shape.Bounds());
bool undo_redo_success = undo_redo_model_.Erase(stroke.id);
CHECK(undo_redo_success);
}
const std::optional<ink::Rect>& invalidate_rect =
invalidate_envelope.AsRect();
if (!invalidate_rect.has_value()) {
return false;
}
@ -662,14 +643,14 @@ void PdfInkModule::HandleSetAnnotationModeMessage(
MaybeSetCursor();
}
std::vector<std::unique_ptr<InkInProgressStroke>>
std::vector<ink::InProgressStroke>
PdfInkModule::CreateInProgressStrokeSegmentsFromInputs() const {
if (!is_drawing_stroke()) {
return {};
}
const DrawingStrokeState& state = drawing_stroke_state();
std::vector<std::unique_ptr<InkInProgressStroke>> stroke_segments;
std::vector<ink::InProgressStroke> stroke_segments;
stroke_segments.reserve(state.inputs.size());
for (size_t segment_number = 0; const auto& segment : state.inputs) {
++segment_number;
@ -680,21 +661,17 @@ PdfInkModule::CreateInProgressStrokeSegmentsFromInputs() const {
break;
}
auto stroke = InkInProgressStroke::Create();
// TODO(crbug.com/339682315): This should not fail with the wrapper.
if (!stroke) {
return {};
}
ink::InProgressStroke stroke;
auto input_batch = ink::StrokeInputBatch::Create(segment);
CHECK(input_batch.ok());
auto input_batch = InkStrokeInputBatch::Create(segment);
CHECK(input_batch);
stroke->Start(state.brush->GetInkBrush());
bool enqueue_results = stroke->EnqueueInputs(input_batch.get(), nullptr);
CHECK(enqueue_results);
stroke->FinishInputs();
bool update_results = stroke->UpdateShape(0);
CHECK(update_results);
stroke.Start(state.brush->GetInkBrush());
auto enqueue_results =
stroke.EnqueueInputs(*input_batch, /*predicted_inputs=*/{});
CHECK(enqueue_results.ok());
stroke.FinishInputs();
auto update_results = stroke.UpdateShape(ink::Duration32());
CHECK(update_results.ok());
stroke_segments.push_back(std::move(stroke));
}
return stroke_segments;
@ -719,8 +696,9 @@ void PdfInkModule::RecordStrokePosition(const gfx::PointF& position) {
ConvertEventPositionToCanonicalPosition(position, state.page_index);
base::TimeDelta time_diff = base::Time::Now() - state.start_time.value();
state.inputs.back().push_back({
.position = InkPoint{canonical_position.x(), canonical_position.y()},
.elapsed_time_seconds = static_cast<float>(time_diff.InSecondsF()),
.position = {canonical_position.x(), canonical_position.y()},
.elapsed_time =
ink::Duration32::Seconds(static_cast<float>(time_diff.InSecondsF())),
});
}
@ -768,7 +746,7 @@ void PdfInkModule::ApplyUndoRedoCommandsHelper(std::set<size_t> ids,
// `it` is always valid, because all the IDs in `ids_to_apply_command` are
// in `page_ink_strokes`.
auto it = page_ink_strokes.begin();
std::optional<InkRect> invalidate_rect;
ink::Envelope invalidate_envelope;
for (size_t id : ids_to_apply_command) {
it = base::ranges::lower_bound(
it, page_ink_strokes.end(), id, {},
@ -777,11 +755,13 @@ void PdfInkModule::ApplyUndoRedoCommandsHelper(std::set<size_t> ids,
CHECK_NE(stroke.should_draw, should_draw);
stroke.should_draw = should_draw;
UnionInkRects(invalidate_rect, stroke.stroke->GetShape().Bounds());
invalidate_envelope.Add(stroke.stroke.GetShape().Bounds());
ids.erase(id);
}
const std::optional<ink::Rect>& invalidate_rect =
invalidate_envelope.AsRect();
CHECK(invalidate_rect.has_value());
client_->Invalidate(InkRectToEnclosingGfxRect(invalidate_rect.value()));
client_->UpdateThumbnail(page_index);
@ -848,7 +828,8 @@ void PdfInkModule::MaybeSetCursor() {
float brush_size;
if (is_drawing_stroke()) {
const auto& ink_brush = drawing_stroke_state().brush->GetInkBrush();
color = ink_brush.GetColor();
auto rgba = ink_brush.GetColor().AsUint8(ink::Color::Format::kGammaEncoded);
color = SkColorSetARGB(rgba.a, rgba.r, rgba.g, rgba.b);
brush_size = ink_brush.GetSize();
} else {
CHECK(is_erasing_stroke());
@ -870,9 +851,8 @@ PdfInkModule::EraserState::EraserState() = default;
PdfInkModule::EraserState::~EraserState() = default;
PdfInkModule::FinishedStrokeState::FinishedStrokeState(
std::unique_ptr<InkStroke> stroke,
size_t id)
PdfInkModule::FinishedStrokeState::FinishedStrokeState(ink::Stroke stroke,
size_t id)
: stroke(std::move(stroke)), id(id) {}
PdfInkModule::FinishedStrokeState::FinishedStrokeState(

@ -19,10 +19,11 @@
#include "base/time/time.h"
#include "base/values.h"
#include "pdf/buildflags.h"
#include "pdf/ink/ink_affine_transform.h"
#include "pdf/ink/ink_stroke_input.h"
#include "pdf/pdf_ink_undo_redo_model.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/ink/src/ink/strokes/in_progress_stroke.h"
#include "third_party/ink/src/ink/strokes/input/stroke_input.h"
#include "third_party/ink/src/ink/strokes/stroke.h"
#include "ui/gfx/geometry/point_f.h"
static_assert(BUILDFLAG(ENABLE_PDF_INK2), "ENABLE_PDF_INK2 not set to true");
@ -34,10 +35,12 @@ class WebInputEvent;
class WebMouseEvent;
} // namespace blink
namespace ink {
class AffineTransform;
}
namespace chrome_pdf {
class InkInProgressStroke;
class InkStroke;
class PdfInkBrush;
class PdfInkModuleClient;
@ -54,7 +57,7 @@ class PdfInkModule {
using DocumentStrokeInputPointsMap = std::map<int, PageStrokeInputPoints>;
using RenderTransformCallback =
base::RepeatingCallback<void(const InkAffineTransform& transform)>;
base::RepeatingCallback<void(const ink::AffineTransform& transform)>;
explicit PdfInkModule(PdfInkModuleClient& client);
PdfInkModule(const PdfInkModule&) = delete;
@ -101,7 +104,7 @@ class PdfInkModule {
RenderTransformCallback callback);
private:
using StrokeInputSegment = std::vector<InkStrokeInput>;
using StrokeInputSegment = std::vector<ink::StrokeInput>;
struct DrawingStrokeState {
DrawingStrokeState();
@ -135,7 +138,7 @@ class PdfInkModule {
// A stroke that has been completed, its ID, and whether it should be drawn
// or not.
struct FinishedStrokeState {
FinishedStrokeState(std::unique_ptr<InkStroke> stroke, size_t id);
FinishedStrokeState(ink::Stroke stroke, size_t id);
FinishedStrokeState(const FinishedStrokeState&) = delete;
FinishedStrokeState& operator=(const FinishedStrokeState&) = delete;
FinishedStrokeState(FinishedStrokeState&&) noexcept;
@ -144,7 +147,7 @@ class PdfInkModule {
// Coordinates for each stroke are stored in a canonical format specified in
// pdf_ink_transform.h.
std::unique_ptr<InkStroke> stroke;
ink::Stroke stroke;
// A unique ID to identify this stroke.
size_t id;
@ -229,12 +232,12 @@ class PdfInkModule {
return absl::get<EraserState>(current_tool_state_);
}
// Converts `current_tool_state_` into segments of `InkInProgressStroke`.
// Converts `current_tool_state_` into segments of `ink::InProgressStroke`.
// Requires `current_tool_state_` to hold a `DrawingStrokeState`. If there is
// no `DrawingStrokeState`, or the state currently has no inputs, then the
// segments will be empty.
std::vector<std::unique_ptr<InkInProgressStroke>>
CreateInProgressStrokeSegmentsFromInputs() const;
std::vector<ink::InProgressStroke> CreateInProgressStrokeSegmentsFromInputs()
const;
// Wrapper around EventPositionToCanonicalPosition(). `page_index` is the page
// that `position` is on. The page must be visible.

@ -15,8 +15,6 @@
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "pdf/ink/ink_affine_transform.h"
#include "pdf/ink/ink_brush.h"
#include "pdf/pdf_features.h"
#include "pdf/pdf_ink_brush.h"
#include "pdf/pdf_ink_module_client.h"
@ -26,6 +24,8 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"
#include "third_party/ink/src/ink/brush/brush.h"
#include "third_party/ink/src/ink/geometry/affine_transform.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
@ -231,11 +231,16 @@ TEST_F(PdfInkModuleTest, HandleSetAnnotationBrushMessagePen) {
const PdfInkBrush* brush = ink_module().GetPdfInkBrushForTesting();
ASSERT_TRUE(brush);
const InkBrush& ink_brush = brush->GetInkBrush();
EXPECT_EQ(SkColorSetRGB(10, 255, 50), ink_brush.GetColor());
const ink::Brush& ink_brush = brush->GetInkBrush();
EXPECT_EQ(ink::Color::FromUint8(/*red=*/10, /*green=*/255, /*blue=*/50,
/*alpha=*/255),
ink_brush.GetColor());
EXPECT_EQ(8.0f, ink_brush.GetSize());
EXPECT_EQ(1.0f, ink_brush.GetCornerRoundingForTesting());
EXPECT_EQ(1.0f, ink_brush.GetOpacityForTesting());
ASSERT_EQ(1u, ink_brush.CoatCount());
const ink::BrushCoat& coat = ink_brush.GetCoats()[0];
ASSERT_EQ(1u, coat.tips.size());
EXPECT_EQ(1.0f, coat.tips[0].corner_rounding);
EXPECT_EQ(1.0f, coat.tips[0].opacity_multiplier);
}
// Verify that a set highlighter message sets the annotation brush to a
@ -254,11 +259,16 @@ TEST_F(PdfInkModuleTest, HandleSetAnnotationBrushMessageHighlighter) {
const PdfInkBrush* brush = ink_module().GetPdfInkBrushForTesting();
ASSERT_TRUE(brush);
const InkBrush& ink_brush = brush->GetInkBrush();
EXPECT_EQ(SkColorSetRGB(240, 133, 0), ink_brush.GetColor());
const ink::Brush& ink_brush = brush->GetInkBrush();
EXPECT_EQ(ink::Color::FromUint8(/*red=*/240, /*green=*/133, /*blue=*/0,
/*alpha=*/255),
ink_brush.GetColor());
EXPECT_EQ(4.5f, ink_brush.GetSize());
EXPECT_EQ(0.0f, ink_brush.GetCornerRoundingForTesting());
EXPECT_EQ(0.4f, ink_brush.GetOpacityForTesting());
ASSERT_EQ(1u, ink_brush.CoatCount());
const ink::BrushCoat& coat = ink_brush.GetCoats()[0];
ASSERT_EQ(1u, coat.tips.size());
EXPECT_EQ(0.0f, coat.tips[0].corner_rounding);
EXPECT_EQ(0.4f, coat.tips[0].opacity_multiplier);
}
// Verify that brushes with zero color values can be set as the annotation
@ -276,11 +286,14 @@ TEST_F(PdfInkModuleTest, HandleSetAnnotationBrushMessageColorZero) {
const PdfInkBrush* brush = ink_module().GetPdfInkBrushForTesting();
ASSERT_TRUE(brush);
const InkBrush& ink_brush = brush->GetInkBrush();
EXPECT_EQ(SkColorSetRGB(0, 0, 0), ink_brush.GetColor());
const ink::Brush& ink_brush = brush->GetInkBrush();
EXPECT_EQ(ink::Color::Black(), ink_brush.GetColor());
EXPECT_EQ(4.5f, ink_brush.GetSize());
EXPECT_EQ(1.0f, ink_brush.GetCornerRoundingForTesting());
EXPECT_EQ(1.0f, ink_brush.GetOpacityForTesting());
ASSERT_EQ(1u, ink_brush.CoatCount());
const ink::BrushCoat& coat = ink_brush.GetCoats()[0];
ASSERT_EQ(1u, coat.tips.size());
EXPECT_EQ(1.0f, coat.tips[0].corner_rounding);
EXPECT_EQ(1.0f, coat.tips[0].opacity_multiplier);
}
TEST_F(PdfInkModuleTest, HandleSetAnnotationModeMessage) {
@ -545,9 +558,9 @@ TEST_F(PdfInkModuleStrokeTest, DrawRenderTransform) {
// Simulate drawing the strokes, and verify that the expected transform was
// used.
std::vector<InkAffineTransform> draw_render_transforms;
std::vector<ink::AffineTransform> draw_render_transforms;
ink_module().SetDrawRenderTransformCallbackForTesting(
base::BindLambdaForTesting([&](const InkAffineTransform& transform) {
base::BindLambdaForTesting([&](const ink::AffineTransform& transform) {
draw_render_transforms.push_back(transform);
}));
SkCanvas canvas;
@ -772,7 +785,8 @@ TEST_F(PdfInkModuleStrokeTest, EraseStrokeEntirelyOffPage) {
EXPECT_THAT(updated_thumbnail_page_indices, ElementsAre(0));
}
TEST_F(PdfInkModuleStrokeTest, EraseStrokeErasesTwoStrokes) {
// TODO(crbug.com/339682315): Re-enable.
TEST_F(PdfInkModuleStrokeTest, DISABLED_EraseStrokeErasesTwoStrokes) {
InitializeSimpleSinglePageBasicLayout();
RunStrokeCheckTest(/*annotation_mode_enabled=*/true);

@ -5,6 +5,7 @@
#include "pdf/pdf_ink_transform.h"
#include "base/check_op.h"
#include "base/notreached.h"
#include "ui/gfx/geometry/rect.h"
namespace chrome_pdf {
@ -39,7 +40,7 @@ gfx::PointF EventPositionToCanonicalPosition(const gfx::PointF& event_position,
return page_position;
}
InkAffineTransform GetInkRenderTransform(
ink::AffineTransform GetInkRenderTransform(
const gfx::Vector2dF& viewport_origin_offset,
PageOrientation orientation,
const gfx::Rect& page_content_rect,
@ -48,45 +49,26 @@ InkAffineTransform GetInkRenderTransform(
CHECK_GE(viewport_origin_offset.y(), 0.0f);
CHECK_GT(scale_factor, 0.0f);
CHECK(!page_content_rect.IsEmpty());
float dx = viewport_origin_offset.x() + page_content_rect.x();
float dy = viewport_origin_offset.y() + page_content_rect.y();
InkAffineTransform transform;
const float dx = viewport_origin_offset.x() + page_content_rect.x();
const float dy = viewport_origin_offset.y() + page_content_rect.y();
switch (orientation) {
case PageOrientation::kOriginal:
transform.a = scale_factor;
transform.b = 0;
transform.c = dx;
transform.d = 0;
transform.e = scale_factor;
transform.f = dy;
break;
return ink::AffineTransform(scale_factor, 0, dx, 0, scale_factor, dy);
case PageOrientation::kClockwise90:
transform.a = 0;
transform.b = -scale_factor;
transform.c = dx + page_content_rect.width() - 1;
transform.d = scale_factor;
transform.e = 0;
transform.f = dy;
break;
return ink::AffineTransform(0, -scale_factor,
dx + page_content_rect.width() - 1,
scale_factor, 0, dy);
case PageOrientation::kClockwise180:
transform.a = -scale_factor;
transform.b = 0;
transform.c = dx + page_content_rect.width() - 1;
transform.d = 0;
transform.e = -scale_factor;
transform.f = dy + page_content_rect.height() - 1;
break;
return ink::AffineTransform(
-scale_factor, 0, dx + page_content_rect.width() - 1, 0,
-scale_factor, dy + page_content_rect.height() - 1);
case PageOrientation::kClockwise270:
transform.a = 0;
transform.b = scale_factor;
transform.c = dx;
transform.d = -scale_factor;
transform.e = 0;
transform.f = dy + page_content_rect.height() - 1;
break;
return ink::AffineTransform(0, scale_factor, dx, -scale_factor, 0,
dy + page_content_rect.height() - 1);
}
return transform;
NOTREACHED();
}
} // namespace chrome_pdf

@ -6,8 +6,8 @@
#define PDF_PDF_INK_TRANSFORM_H_
#include "pdf/buildflags.h"
#include "pdf/ink/ink_affine_transform.h"
#include "pdf/page_orientation.h"
#include "third_party/ink/src/ink/geometry/affine_transform.h"
#include "ui/gfx/geometry/point_f.h"
static_assert(BUILDFLAG(ENABLE_PDF_INK2), "ENABLE_PDF_INK2 not set to true");
@ -89,7 +89,7 @@ gfx::PointF EventPositionToCanonicalPosition(const gfx::PointF& event_position,
// | | | +
// +-------------+ +------------+
//
InkAffineTransform GetInkRenderTransform(
ink::AffineTransform GetInkRenderTransform(
const gfx::Vector2dF& viewport_origin_offset,
PageOrientation orientation,
const gfx::Rect& page_content_rect,

@ -6,11 +6,11 @@
#include <array>
#include "pdf/ink/ink_affine_transform.h"
#include "pdf/page_orientation.h"
#include "pdf/test/pdf_ink_test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/ink/src/ink/geometry/affine_transform.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
@ -204,7 +204,7 @@ TEST(PdfInkTransformTest,
}
TEST(PdfInkTransformTest, RenderTransformIdentity) {
InkAffineTransform transform = GetInkRenderTransform(
ink::AffineTransform transform = GetInkRenderTransform(
kViewportOriginOffsetNone, PageOrientation::kOriginal,
kPageContentAreaPortraitNoOffset, kScaleFactor1x);
EXPECT_THAT(transform,
@ -212,7 +212,7 @@ TEST(PdfInkTransformTest, RenderTransformIdentity) {
}
TEST(PdfInkTransformTest, RenderTransformZoom) {
InkAffineTransform transform = GetInkRenderTransform(
ink::AffineTransform transform = GetInkRenderTransform(
kViewportOriginOffsetNone, PageOrientation::kOriginal,
kPageContentAreaPortraitNoOffset2x, kScaleFactor2x);
EXPECT_THAT(transform,
@ -220,7 +220,7 @@ TEST(PdfInkTransformTest, RenderTransformZoom) {
}
TEST(PdfInkTransformTest, RenderTransformRotateClockwise90) {
InkAffineTransform transform = GetInkRenderTransform(
ink::AffineTransform transform = GetInkRenderTransform(
kViewportOriginOffsetNone, PageOrientation::kClockwise90,
kPageContentAreaLandscapeNoOffset, kScaleFactor1x);
EXPECT_THAT(transform,
@ -228,7 +228,7 @@ TEST(PdfInkTransformTest, RenderTransformRotateClockwise90) {
}
TEST(PdfInkTransformTest, RenderTransformRotateClockwise180) {
InkAffineTransform transform = GetInkRenderTransform(
ink::AffineTransform transform = GetInkRenderTransform(
kViewportOriginOffsetNone, PageOrientation::kClockwise180,
kPageContentAreaPortraitNoOffset, kScaleFactor1x);
EXPECT_THAT(transform,
@ -236,7 +236,7 @@ TEST(PdfInkTransformTest, RenderTransformRotateClockwise180) {
}
TEST(PdfInkTransformTest, RenderTransformRotateClockwise270) {
InkAffineTransform transform = GetInkRenderTransform(
ink::AffineTransform transform = GetInkRenderTransform(
kViewportOriginOffsetNone, PageOrientation::kClockwise270,
kPageContentAreaLandscapeNoOffset, kScaleFactor1x);
EXPECT_THAT(transform,
@ -244,7 +244,7 @@ TEST(PdfInkTransformTest, RenderTransformRotateClockwise270) {
}
TEST(PdfInkTransformTest, RenderTransformScrolled) {
InkAffineTransform transform = GetInkRenderTransform(
ink::AffineTransform transform = GetInkRenderTransform(
kViewportOriginOffsetNone, PageOrientation::kOriginal,
/*page_content_rect=*/gfx::Rect(gfx::Point(-8, -14), kPageSizePortrait),
kScaleFactor1x);
@ -253,7 +253,7 @@ TEST(PdfInkTransformTest, RenderTransformScrolled) {
}
TEST(PdfInkTransformTest, RenderTransformOffsetScrolled) {
InkAffineTransform transform = GetInkRenderTransform(
ink::AffineTransform transform = GetInkRenderTransform(
/*viewport_origin_offset=*/gfx::Vector2dF(18.0f, 24.0f),
PageOrientation::kOriginal,
/*page_content_rect=*/gfx::Rect(gfx::Point(0, -14), kPageSizePortrait),
@ -263,7 +263,7 @@ TEST(PdfInkTransformTest, RenderTransformOffsetScrolled) {
}
TEST(PdfInkTransformTest, RenderTransformZoomScrolledClockwise90) {
InkAffineTransform transform = GetInkRenderTransform(
ink::AffineTransform transform = GetInkRenderTransform(
kViewportOriginOffsetNone, PageOrientation::kClockwise90,
/*page_content_rect=*/
gfx::Rect(gfx::Point(-16, -28), kPageSizeLandscape2x), kScaleFactor2x);
@ -272,7 +272,7 @@ TEST(PdfInkTransformTest, RenderTransformZoomScrolledClockwise90) {
}
TEST(PdfInkTransformTest, RenderTransformOffsetZoomScrolledClockwise90) {
InkAffineTransform transform = GetInkRenderTransform(
ink::AffineTransform transform = GetInkRenderTransform(
/*viewport_origin_offset=*/gfx::Vector2dF(18.0f, 24.0f),
PageOrientation::kClockwise90,
/*page_content_rect=*/gfx::Rect(gfx::Point(0, -28), kPageSizeLandscape2x),

@ -8,8 +8,8 @@
#include <string>
#include "base/values.h"
#include "pdf/ink/ink_affine_transform.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/ink/src/ink/geometry/affine_transform.h"
namespace chrome_pdf {
@ -38,12 +38,12 @@ MATCHER_P6(InkAffineTransformEq,
"") {
using testing::FloatEq;
using testing::Matches;
return Matches(FloatEq(expected_a))(arg.a) &&
Matches(FloatEq(expected_b))(arg.b) &&
Matches(FloatEq(expected_c))(arg.c) &&
Matches(FloatEq(expected_d))(arg.d) &&
Matches(FloatEq(expected_e))(arg.e) &&
Matches(FloatEq(expected_f))(arg.f);
return Matches(FloatEq(expected_a))(arg.A()) &&
Matches(FloatEq(expected_b))(arg.B()) &&
Matches(FloatEq(expected_c))(arg.C()) &&
Matches(FloatEq(expected_d))(arg.D()) &&
Matches(FloatEq(expected_e))(arg.E()) &&
Matches(FloatEq(expected_f))(arg.F());
}
} // namespace chrome_pdf