0

Delete chrome_pdf::Graphics

Removes obsolete Graphics and SkiaGraphics classes, moving all the
remaining functionality (scrolling and image painting) directly into
PaintManager.

Ports the remaining SkiaGraphicsTests, with a few changes:

1. Replaces loops with unrolled calls to subtest methods, and generally
   makes tests more explicit and self-contained.
2. Uses gfx::Rect consistently. gfx::Rect's constructor uses XYWH
   coordinates, while SkIRect's aggregate initialization uses LTRB
   coordinates. The old tests had several bugs related to this.
3. Erases unpainted areas to magenta. The new tests reuse the same
   underlying SkSurface, so each subtest must initialize any unpainted
   pixels to a known state.
4. Compares each scroll result to a golden image. The old tests only
   verified that each scroll result differed from the initial state.

Fixed: 1317832
Change-Id: If94a76641aa1801fd08127897536329db8255422
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3617141
Commit-Queue: K. Moon <kmoon@chromium.org>
Reviewed-by: Nigi <nigi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#997890}
This commit is contained in:
K. Moon
2022-04-29 20:41:30 +00:00
committed by Chromium LUCI CQ
parent cfe5e71ce4
commit 0bc3052a79
13 changed files with 159 additions and 326 deletions

@ -242,8 +242,6 @@ if (enable_pdf) {
sources = [
"ppapi_migration/bitmap.cc",
"ppapi_migration/bitmap.h",
"ppapi_migration/graphics.cc",
"ppapi_migration/graphics.h",
"ppapi_migration/result_codes.h",
"ppapi_migration/url_loader.cc",
"ppapi_migration/url_loader.h",
@ -380,7 +378,6 @@ if (enable_pdf) {
"pdfium/pdfium_print_unittest.cc",
"pdfium/pdfium_test_base.cc",
"pdfium/pdfium_test_base.h",
"ppapi_migration/graphics_unittest.cc",
"ppapi_migration/url_loader_unittest.cc",
"range_set_unittest.cc",
"test/run_all_unittests.cc",

@ -8,7 +8,7 @@
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <cmath>
#include <utility>
#include "base/auto_reset.h"
@ -20,15 +20,18 @@
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_task_runner_handle.h"
#include "pdf/paint_ready_rect.h"
#include "pdf/ppapi_migration/graphics.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkSamplingOptions.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "ui/gfx/blit.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/vector2d_f.h"
@ -94,7 +97,7 @@ void PaintManager::SetTransform(float scale,
const gfx::Point& origin,
const gfx::Vector2d& translate,
bool schedule_flush) {
if (!graphics_)
if (!surface_)
return;
if (scale <= 0.0f) {
@ -124,7 +127,7 @@ void PaintManager::ClearTransform() {
}
void PaintManager::Invalidate() {
if (!graphics_ && !has_pending_resize_)
if (!surface_ && !has_pending_resize_)
return;
EnsureCallbackPending();
@ -134,7 +137,7 @@ void PaintManager::Invalidate() {
void PaintManager::InvalidateRect(const gfx::Rect& rect) {
DCHECK(!in_paint_);
if (!graphics_ && !has_pending_resize_)
if (!surface_ && !has_pending_resize_)
return;
// Clip the rect to the device area.
@ -151,7 +154,7 @@ void PaintManager::ScrollRect(const gfx::Rect& clip_rect,
const gfx::Vector2d& amount) {
DCHECK(!in_paint_);
if (!graphics_ && !has_pending_resize_)
if (!surface_ && !has_pending_resize_)
return;
EnsureCallbackPending();
@ -200,7 +203,7 @@ void PaintManager::DoPaint() {
// do this later.
//
// Note that `has_pending_resize_` will always be set on the first DoPaint().
DCHECK(graphics_ || has_pending_resize_);
DCHECK(surface_ || has_pending_resize_);
if (has_pending_resize_) {
plugin_size_ = pending_size_;
// Only create a new graphics context if the current context isn't big
@ -214,7 +217,6 @@ void PaintManager::DoPaint() {
surface_ =
SkSurface::MakeRasterN32Premul(new_size.width(), new_size.height());
DCHECK(surface_);
graphics_ = std::make_unique<SkiaGraphics>(surface_.get());
// TODO(crbug.com/1317832): Can we guarantee repainting some other way?
client_->InvalidatePluginContainer();
@ -249,9 +251,14 @@ void PaintManager::DoPaint() {
ready_now = aggregator_.GetReadyRects();
aggregator_.ClearPendingUpdate();
// Apply any scroll first.
if (update.has_scroll)
graphics_->Scroll(update.scroll_rect, update.scroll_delta);
// First, apply any scroll amount less than the surface's size.
if (update.has_scroll &&
std::abs(update.scroll_delta.x()) < surface_->width() &&
std::abs(update.scroll_delta.y()) < surface_->height()) {
// TODO(crbug.com/1263614): Use `SkSurface::notifyContentWillChange()`.
gfx::ScrollCanvas(surface_->getCanvas(), update.scroll_rect,
update.scroll_delta);
}
view_size_changed_waiting_for_paint_ = false;
} else {
@ -280,7 +287,11 @@ void PaintManager::DoPaint() {
}
for (const auto& ready_rect : ready_now) {
graphics_->PaintImage(ready_rect.image(), ready_rect.rect());
// TODO(crbug.com/1284255): Avoid inefficient `SkBitmap::asImage()`.
SkRect skia_rect = gfx::RectToSkRect(ready_rect.rect());
surface_->getCanvas()->drawImageRect(
ready_rect.image().asImage(), skia_rect, skia_rect, SkSamplingOptions(),
nullptr, SkCanvas::kStrict_SrcRectConstraint);
}
Flush();

@ -5,16 +5,11 @@
#ifndef PDF_PAINT_MANAGER_H_
#define PDF_PAINT_MANAGER_H_
#include <stdint.h>
#include <memory>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "pdf/paint_aggregator.h"
#include "pdf/ppapi_migration/graphics.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "ui/gfx/geometry/size.h"
@ -164,9 +159,6 @@ class PaintManager {
// Backing Skia surface.
sk_sp<SkSurface> surface_;
// This graphics device will be null if no graphics has been set yet.
std::unique_ptr<Graphics> graphics_;
PaintAggregator aggregator_;
// See comment for EnsureCallbackPending for more on how these work.

@ -9,16 +9,20 @@
#include "base/files/file_path.h"
#include "base/run_loop.h"
#include "base/strings/string_piece.h"
#include "cc/test/pixel_comparator.h"
#include "cc/test/pixel_test_utils.h"
#include "pdf/paint_ready_rect.h"
#include "pdf/ppapi_migration/graphics.h"
#include "pdf/test/test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/skia_conversions.h"
namespace chrome_pdf {
@ -82,6 +86,78 @@ class PaintManagerTest : public testing::Test {
return saved_snapshot;
}
void TestPaintImage(const gfx::Size& plugin_size,
const gfx::Size& source_size,
const gfx::Rect& paint_rect,
const gfx::Rect& overlapped_rect) {
// Paint `paint_rect` from `source_size` image over a magenta background.
paint_manager_.SetSize(plugin_size, 1.0f);
sk_sp<SkImage> snapshot = WaitForFlush(
/*expected_paint_rects=*/{{gfx::Rect(plugin_size)}},
/*fake_ready=*/
{
{gfx::Rect(plugin_size),
CreateSkiaImageForTesting(plugin_size, SK_ColorMAGENTA)},
{paint_rect, CreateSkiaImageForTesting(source_size, SK_ColorRED)},
},
/*fake_pending=*/{});
ASSERT_TRUE(snapshot);
// Check if snapshot has `overlapped_rect` painted red.
snapshot = snapshot->makeSubset(
SkIRect::MakeWH(plugin_size.width(), plugin_size.height()));
ASSERT_TRUE(snapshot);
SkBitmap snapshot_bitmap;
ASSERT_TRUE(snapshot->asLegacyBitmap(&snapshot_bitmap));
SkBitmap expected_bitmap =
CreateSkiaImageForTesting(plugin_size, SK_ColorMAGENTA);
expected_bitmap.erase(SK_ColorRED, gfx::RectToSkIRect(overlapped_rect));
EXPECT_TRUE(
cc::MatchesBitmap(snapshot_bitmap, expected_bitmap,
cc::ExactPixelComparator(/*discard_alpha=*/false)));
}
void TestScroll(const gfx::Vector2d& scroll_amount,
const gfx::Rect& expected_paint_rect,
base::StringPiece expected_png) {
// Paint non-uniform initial image.
gfx::Size plugin_size = paint_manager_.GetEffectiveSize();
ASSERT_GE(plugin_size.width(), 4);
ASSERT_GE(plugin_size.height(), 4);
SkBitmap initial_bitmap =
CreateSkiaImageForTesting(plugin_size, SK_ColorRED);
initial_bitmap.erase(SK_ColorGREEN, {1, 1, plugin_size.width() - 1,
plugin_size.height() - 2});
paint_manager_.Invalidate();
ASSERT_TRUE(
WaitForFlush(/*expected_paint_rects=*/{gfx::Rect(plugin_size)},
/*fake_ready=*/{{gfx::Rect(plugin_size), initial_bitmap}},
/*fake_pending=*/{}));
// Scroll by `scroll_amount`, painting `expected_paint_rect` magenta.
paint_manager_.ScrollRect(gfx::Rect(plugin_size), scroll_amount);
sk_sp<SkImage> snapshot = WaitForFlush(
/*expected_paint_rects=*/{expected_paint_rect},
/*fake_ready=*/
{{expected_paint_rect,
CreateSkiaImageForTesting(plugin_size, SK_ColorMAGENTA)}},
/*fake_pending=*/{});
ASSERT_TRUE(snapshot);
// Compare snapshot to `expected_png`.
snapshot = snapshot->makeSubset(
SkIRect::MakeWH(plugin_size.width(), plugin_size.height()));
ASSERT_TRUE(snapshot);
EXPECT_TRUE(
MatchesPngFile(snapshot.get(), GetTestDataFilePath(expected_png)));
}
NiceMock<FakeClient> client_;
PaintManager paint_manager_{&client_};
};
@ -174,6 +250,65 @@ TEST_F(PaintManagerTest, DoPaintFirst) {
GetTestDataFilePath("do_paint_first.png")));
}
TEST_F(PaintManagerTest, PaintImage) {
// Painted area is within the plugin area and the source image.
TestPaintImage(/*plugin_size=*/{20, 20}, /*source_size=*/{15, 15},
/*paint_rect=*/{0, 0, 10, 10},
/*overlapped_rect=*/{0, 0, 10, 10});
// Painted area straddles the plugin area and the source image.
TestPaintImage(/*plugin_size=*/{50, 30}, /*source_size=*/{30, 50},
/*paint_rect=*/{10, 10, 30, 30},
/*overlapped_rect=*/{10, 10, 20, 20});
// Painted area is outside the plugin area.
TestPaintImage(/*plugin_size=*/{10, 10}, /*source_size=*/{30, 30},
/*paint_rect=*/{10, 10, 10, 10},
/*overlapped_rect=*/{0, 0, 0, 0});
// Painted area is outside the source image.
TestPaintImage(/*plugin_size=*/{15, 15}, /*source_size=*/{5, 5},
/*paint_rect=*/{10, 10, 5, 5},
/*overlapped_rect=*/{0, 0, 0, 0});
}
TEST_F(PaintManagerTest, Scroll) {
paint_manager_.SetSize({4, 5}, 1.0f);
TestScroll(/*scroll_amount=*/{1, 0}, /*expected_paint_rect=*/{0, 0, 1, 5},
"scroll_right.png");
TestScroll(/*scroll_amount=*/{-2, 0}, /*expected_paint_rect=*/{2, 0, 2, 5},
"scroll_left.png");
TestScroll(/*scroll_amount=*/{0, 3}, /*expected_paint_rect=*/{0, 0, 4, 3},
"scroll_down.png");
TestScroll(/*scroll_amount=*/{0, -3}, /*expected_paint_rect=*/{0, 2, 4, 3},
"scroll_up.png");
}
TEST_F(PaintManagerTest, ScrollIgnored) {
paint_manager_.SetSize({4, 5}, 1.0f);
// Scroll to the edge of the plugin area.
TestScroll(/*scroll_amount=*/{4, 0}, /*expected_paint_rect=*/{0, 0, 4, 5},
"scroll_ignored.png");
TestScroll(/*scroll_amount=*/{-4, 0}, /*expected_paint_rect=*/{0, 0, 4, 5},
"scroll_ignored.png");
TestScroll(/*scroll_amount=*/{0, 5}, /*expected_paint_rect=*/{0, 0, 4, 5},
"scroll_ignored.png");
TestScroll(/*scroll_amount=*/{0, -5}, /*expected_paint_rect=*/{0, 0, 4, 5},
"scroll_ignored.png");
// Scroll outside of the plugin area.
TestScroll(/*scroll_amount=*/{5, 0}, /*expected_paint_rect=*/{0, 0, 4, 5},
"scroll_ignored.png");
TestScroll(/*scroll_amount=*/{-7, 0}, /*expected_paint_rect=*/{0, 0, 4, 5},
"scroll_ignored.png");
TestScroll(/*scroll_amount=*/{0, 8}, /*expected_paint_rect=*/{0, 0, 4, 5},
"scroll_ignored.png");
TestScroll(/*scroll_amount=*/{0, -9}, /*expected_paint_rect=*/{0, 0, 4, 5},
"scroll_ignored.png");
}
} // namespace
} // namespace chrome_pdf

@ -23,7 +23,6 @@
#include "pdf/document_metadata.h"
#include "pdf/pdf_engine.h"
#include "pdf/pdfium/pdfium_form_filler.h"
#include "pdf/ppapi_migration/graphics.h"
#include "pdf/ppapi_migration/url_loader.h"
#include "pdf/test/test_pdfium_engine.h"
#include "testing/gmock/include/gmock/gmock.h"

@ -1,45 +0,0 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ppapi_migration/graphics.h"
#include <cmath>
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "ui/gfx/blit.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/geometry/vector2d.h"
namespace chrome_pdf {
SkiaGraphics::SkiaGraphics(SkSurface* surface) : surface_(surface) {}
SkiaGraphics::~SkiaGraphics() = default;
void SkiaGraphics::PaintImage(const SkBitmap& image,
const gfx::Rect& src_rect) {
SkRect skia_rect = RectToSkRect(src_rect);
// TODO(crbug.com/1284255): Avoid inefficient `SkBitmap::asImage()`.
surface_->getCanvas()->drawImageRect(image.asImage(), skia_rect, skia_rect,
SkSamplingOptions(), nullptr,
SkCanvas::kStrict_SrcRectConstraint);
}
void SkiaGraphics::Scroll(const gfx::Rect& clip, const gfx::Vector2d& amount) {
// If we are being asked to scroll by more than the graphics' rect size, just
// ignore the scroll command.
if (std::abs(amount.x()) >= surface_->width() ||
std::abs(amount.y()) >= surface_->height()) {
return;
}
// TODO(crbug.com/1263614): Use `SkSurface::notifyContentWillChange()`.
gfx::ScrollCanvas(surface_->getCanvas(), clip, amount);
}
} // namespace chrome_pdf

@ -1,54 +0,0 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PDF_PPAPI_MIGRATION_GRAPHICS_H_
#define PDF_PPAPI_MIGRATION_GRAPHICS_H_
#include "base/memory/raw_ptr.h"
class SkBitmap;
class SkSurface;
namespace gfx {
class Rect;
class Vector2d;
} // namespace gfx
namespace chrome_pdf {
// Abstraction for a Pepper or Skia graphics device.
class Graphics {
public:
virtual ~Graphics() = default;
// Paints the `src_rect` region of `image` to the graphics device. The image
// must be compatible with the concrete `Graphics` implementation.
virtual void PaintImage(const SkBitmap& image, const gfx::Rect& src_rect) = 0;
// Shifts the `clip` region of the graphics device by `amount`.
virtual void Scroll(const gfx::Rect& clip, const gfx::Vector2d& amount) = 0;
protected:
Graphics() = default;
};
// A Skia graphics device.
class SkiaGraphics final : public Graphics {
public:
// `surface` must outlive this object.
explicit SkiaGraphics(SkSurface* surface);
~SkiaGraphics() override;
void PaintImage(const SkBitmap& image, const gfx::Rect& src_rect) override;
void Scroll(const gfx::Rect& clip, const gfx::Vector2d& amount) override;
private:
// Unowned pointer. The surface is required to outlive this object.
raw_ptr<SkSurface> surface_;
};
} // namespace chrome_pdf
#endif // PDF_PPAPI_MIGRATION_GRAPHICS_H_

@ -1,202 +0,0 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/ppapi_migration/graphics.h"
#include <memory>
#include "cc/test/pixel_comparator.h"
#include "cc/test/pixel_test_utils.h"
#include "pdf/ppapi_migration/bitmap.h"
#include "pdf/test/test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
namespace chrome_pdf {
namespace {
SkBitmap GenerateExpectedBitmap(const SkISize& graphics_size,
const SkIRect& rect) {
SkBitmap bitmap = CreateN32PremulSkBitmap(graphics_size);
bitmap.erase(SK_ColorRED, rect);
return bitmap;
}
// Creates a nonuniform SkBitmap with given `width` and `height`, such
// that scrolling will cause a noticeable change to the bitmap. Returns an
// empty SkBitmap if either `width` or `height` is less than 4.
SkBitmap CreateNonuniformBitmap(int width, int height) {
if (width < 4 || height < 4)
return SkBitmap();
SkBitmap bitmap = CreateN32PremulSkBitmap(SkISize::Make(width, height));
bitmap.eraseColor(SK_ColorRED);
bitmap.erase(SK_ColorGREEN, {1, 1, width - 1, height - 2});
bitmap.erase(SK_ColorBLACK, {2, 3, 1, 2});
return bitmap;
}
} // namespace
class SkiaGraphicsTest : public testing::Test {
protected:
void TestPaintImageResult(const SkISize& graphics_size,
const gfx::Size& src_size,
const gfx::Rect& paint_rect,
const SkIRect& overlapped_rect) {
surface_ = SkSurface::MakeRasterN32Premul(graphics_size.width(),
graphics_size.height());
ASSERT_TRUE(surface_);
graphics_ = std::make_unique<SkiaGraphics>(surface_.get());
// Paint and snapshot.
graphics_->PaintImage(CreateSkiaImageForTesting(src_size, SK_ColorRED),
paint_rect);
SkBitmap snapshot_bitmap = MakeSnapshot();
// Verify snapshot dimensions.
EXPECT_EQ(snapshot_bitmap.dimensions(), graphics_size)
<< snapshot_bitmap.width() << " x " << snapshot_bitmap.height()
<< " != " << graphics_size.width() << " x " << graphics_size.height();
// Verify the snapshot matches the expected result.
const SkBitmap expected_bitmap =
GenerateExpectedBitmap(graphics_size, overlapped_rect);
EXPECT_TRUE(
cc::MatchesBitmap(snapshot_bitmap, expected_bitmap,
cc::ExactPixelComparator(/*discard_alpha=*/false)))
<< "SkBitmap comparison failed for graphics size of "
<< graphics_size.width() << " x " << graphics_size.height();
}
SkBitmap MakeSnapshot() {
SkBitmap bitmap;
surface_->makeImageSnapshot()->asLegacyBitmap(&bitmap);
return bitmap;
}
sk_sp<SkSurface> surface_;
std::unique_ptr<Graphics> graphics_;
};
class SkiaGraphicsScrollTest : public SkiaGraphicsTest {
protected:
static constexpr gfx::Rect kGraphicsRect = gfx::Rect(4, 5);
// Initializes `initial_bitmap_` and `graphics_` before scrolling tests.
void SetUp() override {
surface_ = SkSurface::MakeRasterN32Premul(kGraphicsRect.width(),
kGraphicsRect.height());
ASSERT_TRUE(surface_);
graphics_ = std::make_unique<SkiaGraphics>(surface_.get());
// Paint a nonuniform SkBitmap to graphics.
initial_bitmap_ =
CreateNonuniformBitmap(kGraphicsRect.width(), kGraphicsRect.height());
graphics_->PaintImage(initial_bitmap_, kGraphicsRect);
SkBitmap initial_snapshot = MakeSnapshot();
ASSERT_TRUE(cc::MatchesBitmap(initial_snapshot, initial_bitmap_,
cc::ExactPixelComparator(false)));
}
// Resets the canvas with `initial_bitmap_`, then scrolls it by
// `scroll_amount`.
void ResetAndScroll(const gfx::Vector2d& scroll_amount) {
if (!graphics_)
return;
graphics_->PaintImage(initial_bitmap_, kGraphicsRect);
graphics_->Scroll(kGraphicsRect, scroll_amount);
}
SkBitmap initial_bitmap_;
};
// static
constexpr gfx::Rect SkiaGraphicsScrollTest::kGraphicsRect;
TEST_F(SkiaGraphicsTest, PaintImage) {
struct PaintImageParams {
// Size of the graphics to be painted on.
SkISize graphics_size;
// Size of the source image.
gfx::Size src_size;
// Painting area.
gfx::Rect paint_rect;
// Common area of the graphics, the source image and the painting area.
SkIRect overlapped_rect;
};
static constexpr PaintImageParams kPaintImageTestParams[] = {
// Paint area is within the graphics and the source image.
{{20, 20}, {15, 15}, gfx::Rect(0, 0, 10, 10), {0, 0, 10, 10}},
// Paint area is not completely within the graphics, or the source
// image.
{{50, 30}, {30, 50}, gfx::Rect(10, 10, 30, 30), {10, 10, 30, 30}},
// Paint area is outside the graphics.
{{10, 10}, {30, 30}, gfx::Rect(10, 10, 10, 10), {0, 0, 0, 0}},
// Paint area is outside the source image.
{{15, 15}, {5, 5}, gfx::Rect(10, 10, 5, 5), {0, 0, 0, 0}},
};
for (const auto& params : kPaintImageTestParams)
TestPaintImageResult(params.graphics_size, params.src_size,
params.paint_rect, params.overlapped_rect);
}
TEST_F(SkiaGraphicsScrollTest, InvalidScroll) {
static constexpr gfx::Vector2d kNoOpScrollAmounts[] = {
// Scroll to the edge of the graphics rect.
{kGraphicsRect.width(), 0},
{-kGraphicsRect.width(), 0},
{0, kGraphicsRect.height()},
{0, -kGraphicsRect.height()},
// Scroll outside the graphics rect.
{kGraphicsRect.width() + 1, 0},
{-(kGraphicsRect.width() + 2), 0},
{0, kGraphicsRect.height() + 3},
{0, -(kGraphicsRect.height() + 4)},
};
for (const auto& no_op_amount : kNoOpScrollAmounts) {
ResetAndScroll(no_op_amount);
SkBitmap snapshot = MakeSnapshot();
EXPECT_TRUE(cc::MatchesBitmap(snapshot, initial_bitmap_,
cc::ExactPixelComparator(false)))
<< "SkBitmap comparison failed for scroll amount of "
<< no_op_amount.ToString();
}
}
TEST_F(SkiaGraphicsScrollTest, Scroll) {
static constexpr gfx::Vector2d kValidScrollAmounts[] = {
{1, 0},
{-2, 0},
{0, 3},
{0, -3},
};
for (const auto& valid_amount : kValidScrollAmounts) {
ResetAndScroll(valid_amount);
SkBitmap snapshot = MakeSnapshot();
EXPECT_FALSE(cc::MatchesBitmap(snapshot, initial_bitmap_,
cc::ExactPixelComparator(false)))
<< "The scroll amount of " << valid_amount.ToString()
<< " failed to change the snapshot of `graphics_`";
}
}
} // namespace chrome_pdf

Binary file not shown.

After

(image error) Size: 92 B

Binary file not shown.

After

(image error) Size: 79 B

Binary file not shown.

After

(image error) Size: 90 B

Binary file not shown.

After

(image error) Size: 92 B

Binary file not shown.

After

(image error) Size: 83 B