skia2/gm/matriximagefilter.cpp
Michael Ludwig 7c6abf86f5 Reland "Remove deprecated SkImageFilter::MakeMatrixFilter"
This reverts commit fde740c7f2.

Reason for revert: g3 updated so roll won't be stopped

Original change's description:
> Revert "Remove deprecated SkImageFilter::MakeMatrixFilter"
>
> This reverts commit ed63d4f177.
>
> Reason for revert: Breaking G3 roll?
>
> Original change's description:
> > Remove deprecated SkImageFilter::MakeMatrixFilter
> >
> > The equivalent functionality is available in
> > include/effects/SkImageFilters.h via SkImageFilters::MatrixTransform.
> >
> > Bug: skia:11230
> > Change-Id: I77b78d508d653a32c913a7599f1004ab634e3e6d
> > Docs-Preview: https://skia.org/?cl=361497
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/361497
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> > Commit-Queue: Mike Reed <reed@google.com>
> > Auto-Submit: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Mike Reed <reed@google.com>
>
> TBR=reed@google.com,michaelludwig@google.com
>
> Change-Id: I60a98a1ca9a42db6bfc5796cf4df69042571161e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:11230
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/364097
> Reviewed-by: Robert Phillips <robertphillips@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>

TBR=robertphillips@google.com,reed@google.com,michaelludwig@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: skia:11230
Change-Id: I76ef4d762151475c498e8cf9392bc2191d84fe1a
Docs-Preview: https://skia.org/?cl=366318
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/366318
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2021-02-04 21:17:58 +00:00

73 lines
2.6 KiB
C++

/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkImage.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/effects/SkImageFilters.h"
static void draw(SkCanvas* canvas, const SkRect& rect, const SkBitmap& bitmap,
const SkMatrix& matrix, const SkSamplingOptions& sampling) {
SkPaint paint;
paint.setImageFilter(SkImageFilters::MatrixTransform(matrix, sampling, nullptr));
canvas->saveLayer(&rect, &paint);
canvas->drawImage(bitmap.asImage(), 0, 0, sampling);
canvas->restore();
}
static void make_checkerboard(SkBitmap* bitmap) {
bitmap->allocN32Pixels(64, 64);
SkCanvas canvas(*bitmap);
SkPaint darkPaint;
darkPaint.setColor(0xFF404040);
SkPaint lightPaint;
lightPaint.setColor(0xFFA0A0A0);
for (int y = 0; y < 64; y += 32) {
for (int x = 0; x < 64; x += 32) {
canvas.save();
canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
canvas.drawRect(SkRect::MakeXYWH(0, 0, 16, 16), darkPaint);
canvas.drawRect(SkRect::MakeXYWH(16, 0, 16, 16), lightPaint);
canvas.drawRect(SkRect::MakeXYWH(0, 16, 16, 16), lightPaint);
canvas.drawRect(SkRect::MakeXYWH(16, 16, 16, 16), darkPaint);
canvas.restore();
}
}
}
DEF_SIMPLE_GM_BG(matriximagefilter, canvas, 420, 100, SK_ColorBLACK) {
SkMatrix matrix;
SkScalar margin = SkIntToScalar(10);
matrix.setSkew(SkDoubleToScalar(0.5), SkDoubleToScalar(0.2));
SkBitmap checkerboard;
make_checkerboard(&checkerboard);
SkRect srcRect = SkRect::MakeWH(96, 96);
canvas->translate(margin, margin);
draw(canvas, srcRect, checkerboard, matrix, SkSamplingOptions());
canvas->translate(srcRect.width() + margin, 0);
draw(canvas, srcRect, checkerboard, matrix, SkSamplingOptions(SkFilterMode::kLinear));
#if 0
// This may be causing Mac 10.6 to barf.
canvas->translate(srcRect.width() + margin, 0);
draw(canvas, srcRect, checkerboard, matrix, kMedium_SkFilterQuality);
canvas->translate(srcRect.width() + margin, 0);
draw(canvas, srcRect, checkerboard, matrix, kHigh_SkFilterQuality);
#endif
}