Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
localmatriximageshader.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkShader.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTileMode.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"

Go to the source code of this file.

Functions

static sk_sp< SkImagemake_image (SkCanvas *rootCanvas, SkColor color)
 
 DEF_SIMPLE_GM (localmatriximageshader, canvas, 250, 250)
 
 DEF_SIMPLE_GM (localmatriximageshader_filtering, canvas, 256, 256)
 

Function Documentation

◆ DEF_SIMPLE_GM() [1/2]

DEF_SIMPLE_GM ( localmatriximageshader  ,
canvas  ,
250  ,
250   
)

Definition at line 35 of file localmatriximageshader.cpp.

35 {
36 sk_sp<SkImage> redImage = make_image(canvas, SK_ColorRED);
37 SkMatrix translate = SkMatrix::Translate(100.0f, 0.0f);
39 rotate.setRotate(45.0f);
40 sk_sp<SkShader> redImageShader = redImage->makeShader(SkSamplingOptions(), &rotate);
41 sk_sp<SkShader> redLocalMatrixShader = redImageShader->makeWithLocalMatrix(translate);
42
43 // Rotate about the origin will happen first.
45 paint.setShader(redLocalMatrixShader);
46 canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
47
48 sk_sp<SkImage> blueImage = make_image(canvas, SK_ColorBLUE);
49 sk_sp<SkShader> blueImageShader = blueImage->makeShader(SkSamplingOptions(), &translate);
50 sk_sp<SkShader> blueLocalMatrixShader = blueImageShader->makeWithLocalMatrix(rotate);
51
52 // Translate will happen first.
53 paint.setShader(blueLocalMatrixShader);
54 canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
55
56 canvas->translate(100.0f, 0.0f);
57
58 // Use isAImage() and confirm that the shaders will draw exactly the same (to the right by 100).
61 SkImage* image = redLocalMatrixShader->isAImage(&matrix, mode);
62 paint.setShader(image->makeShader(mode[0], mode[1], SkSamplingOptions(), &matrix));
63 canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
64 image = blueLocalMatrixShader->isAImage(&matrix, mode);
65 paint.setShader(image->makeShader(mode[0], mode[1], SkSamplingOptions(), &matrix));
66 canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
67}
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
static bool rotate(const SkDCubic &cubic, int zero, int index, SkDCubic &rotPath)
SkTileMode
Definition SkTileMode.h:13
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkImage.cpp:179
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition SkMatrix.h:91
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition SkMatrix.cpp:452
const Paint & paint
sk_sp< SkImage > image
Definition examples.cpp:29
static sk_sp< SkImage > make_image()
Definition mipmap.cpp:21
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition switches.h:228
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56

◆ DEF_SIMPLE_GM() [2/2]

DEF_SIMPLE_GM ( localmatriximageshader_filtering  ,
canvas  ,
256  ,
256   
)

Definition at line 69 of file localmatriximageshader.cpp.

69 {
70 // Test that filtering decisions (eg bicubic for upscale) are made correctly when the scale
71 // comes from a local matrix shader.
72 auto image = ToolUtils::GetResourceAsImage("images/mandrill_256.png");
73 SkPaint p;
76 ->makeWithLocalMatrix(m));
77
78 canvas->drawRect(SkRect::MakeXYWH(0, 0, 256, 256), p);
79}
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition DecodeUtils.h:25
static constexpr SkCubicResampler Mitchell()
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

◆ make_image()

static sk_sp< SkImage > make_image ( SkCanvas rootCanvas,
SkColor  color 
)
static

Definition at line 24 of file localmatriximageshader.cpp.

24 {
26 auto surface(ToolUtils::makeSurface(rootCanvas, info));
27
29 paint.setAntiAlias(true);
30 paint.setColor(color);
31 surface->getCanvas()->drawIRect(SkIRect::MakeXYWH(25, 25, 50, 50), paint);
32 return surface->makeImageSnapshot();
33}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
SkColor4f color
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkSurface > makeSurface(SkCanvas *canvas, const SkImageInfo &info, const SkSurfaceProps *props)
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104
static SkImageInfo MakeN32Premul(int width, int height)