Flutter Engine
The Flutter Engine
matriximagefilter.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
15#include "include/core/SkRect.h"
18
19static void draw(SkCanvas* canvas, const SkRect& rect, const SkBitmap& bitmap,
22 paint.setImageFilter(SkImageFilters::MatrixTransform(matrix, sampling, nullptr));
23 canvas->saveLayer(&rect, &paint);
24 canvas->drawImage(bitmap.asImage(), 0, 0, sampling);
25 canvas->restore();
26}
27
29 bitmap->allocN32Pixels(64, 64);
30 SkCanvas canvas(*bitmap);
31 SkPaint darkPaint;
32 darkPaint.setColor(0xFF404040);
33 SkPaint lightPaint;
34 lightPaint.setColor(0xFFA0A0A0);
35 for (int y = 0; y < 64; y += 32) {
36 for (int x = 0; x < 64; x += 32) {
37 canvas.save();
39 canvas.drawRect(SkRect::MakeXYWH(0, 0, 16, 16), darkPaint);
40 canvas.drawRect(SkRect::MakeXYWH(16, 0, 16, 16), lightPaint);
41 canvas.drawRect(SkRect::MakeXYWH(0, 16, 16, 16), lightPaint);
42 canvas.drawRect(SkRect::MakeXYWH(16, 16, 16, 16), darkPaint);
43 canvas.restore();
44 }
45 }
46}
47
48DEF_SIMPLE_GM_BG(matriximagefilter, canvas, 420, 100, SK_ColorBLACK) {
50 SkScalar margin = SkIntToScalar(10);
51 matrix.setSkew(SkDoubleToScalar(0.5), SkDoubleToScalar(0.2));
54
55 SkRect srcRect = SkRect::MakeWH(96, 96);
56
57 canvas->translate(margin, margin);
58 draw(canvas, srcRect, checkerboard, matrix, SkSamplingOptions());
59
60 canvas->translate(srcRect.width() + margin, 0);
62}
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
#define SkDoubleToScalar(x)
Definition: SkScalar.h:64
#define SkIntToScalar(x)
Definition: SkScalar.h:57
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static sk_sp< SkImageFilter > MatrixTransform(const SkMatrix &matrix, const SkSamplingOptions &sampling, sk_sp< SkImageFilter > input)
void setColor(SkColor color)
Definition: SkPaint.cpp:119
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
static void draw(SkCanvas *canvas, const SkRect &rect, const SkBitmap &bitmap, const SkMatrix &matrix, const SkSamplingOptions &sampling)
DEF_SIMPLE_GM_BG(matriximagefilter, canvas, 420, 100, SK_ColorBLACK)
static void make_checkerboard(SkBitmap *bitmap)
double y
double x
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
SkSamplingOptions sampling
Definition: SkRecords.h:337
Definition: bitmap.py:1
SkSamplingOptions(SkFilterMode::kLinear))
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
constexpr float width() const
Definition: SkRect.h:762
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
static void checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)