Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
skiagm::ResizeGM Class Reference
Inheritance diagram for skiagm::ResizeGM:
skiagm::GM

Public Member Functions

 ResizeGM ()
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
virtual SkISize getISize ()=0
 
virtual SkString getName () const =0
 
virtual bool runAsBench () const
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Protected Member Functions

SkString getName () const override
 
void draw (SkCanvas *canvas, const SkRect &rect, const SkSize &deviceSize, const SkSamplingOptions &sampling, sk_sp< SkImageFilter > input)
 
SkISize getISize () override
 
void onDraw (SkCanvas *canvas) override
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Additional Inherited Members

- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 27 of file resizeimagefilter.cpp.

Constructor & Destructor Documentation

◆ ResizeGM()

skiagm::ResizeGM::ResizeGM ( )
inline

Definition at line 29 of file resizeimagefilter.cpp.

29 {
30 this->setBGColor(0x00000000);
31 }
void setBGColor(SkColor)
Definition: gm.cpp:159

Member Function Documentation

◆ draw()

void skiagm::ResizeGM::draw ( SkCanvas canvas,
const SkRect rect,
const SkSize deviceSize,
const SkSamplingOptions sampling,
sk_sp< SkImageFilter input 
)
inlineprotected

Definition at line 36 of file resizeimagefilter.cpp.

40 {
41 SkRect dstRect;
42 canvas->getLocalToDeviceAs3x3().mapRect(&dstRect, rect);
43 canvas->save();
44 SkScalar deviceScaleX = deviceSize.width() / dstRect.width();
45 SkScalar deviceScaleY = deviceSize.height() / dstRect.height();
46 canvas->translate(rect.x(), rect.y());
47 canvas->scale(deviceScaleX, deviceScaleY);
48 canvas->translate(-rect.x(), -rect.y());
50 matrix.setScale(SkScalarInvert(deviceScaleX), SkScalarInvert(deviceScaleY));
53 std::move(input)));
54 SkPaint filteredPaint;
55 filteredPaint.setImageFilter(std::move(filter));
56 canvas->saveLayer(&rect, &filteredPaint);
58 paint.setColor(0xFF00FF00);
59 SkRect ovalRect = rect;
60 ovalRect.inset(SkIntToScalar(4), SkIntToScalar(4));
61 canvas->drawOval(ovalRect, paint);
62 canvas->restore(); // for saveLayer
63 canvas->restore();
64 }
#define SkScalarInvert(x)
Definition: SkScalar.h:73
#define SkIntToScalar(x)
Definition: SkScalar.h:57
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawOval(const SkRect &oval, const SkPaint &paint)
Definition: SkCanvas.cpp:1698
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
SkMatrix getLocalToDeviceAs3x3() const
Definition: SkCanvas.h:2222
int save()
Definition: SkCanvas.cpp:447
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
static sk_sp< SkImageFilter > MatrixTransform(const SkMatrix &matrix, const SkSamplingOptions &sampling, sk_sp< SkImageFilter > input)
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkMatrix.cpp:1141
void setImageFilter(sk_sp< SkImageFilter > imageFilter)
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
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
void inset(float dx, float dy)
Definition: SkRect.h:1060
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
SkScalar width() const
Definition: SkSize.h:76
SkScalar height() const
Definition: SkSize.h:77

◆ getISize()

SkISize skiagm::ResizeGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 66 of file resizeimagefilter.cpp.

66{ return SkISize::Make(630, 100); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString skiagm::ResizeGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 34 of file resizeimagefilter.cpp.

34{ return SkString("resizeimagefilter"); }

◆ onDraw()

void skiagm::ResizeGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 68 of file resizeimagefilter.cpp.

68 {
69 canvas->clear(SK_ColorBLACK);
70
71 const SkSamplingOptions samplings[] = {
77 };
78 const SkRect srcRect = SkRect::MakeWH(96, 96);
79 const SkSize deviceSize = SkSize::Make(16, 16);
80
81 for (const auto& sampling : samplings) {
82 this->draw(canvas, srcRect, deviceSize, sampling, nullptr);
83 canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
84 }
85
86 {
88 SkCanvas* surfaceCanvas = surface->getCanvas();
89 surfaceCanvas->clear(0x000000);
90 {
92 paint.setColor(0xFF00FF00);
93 SkRect ovalRect = SkRect::MakeWH(16, 16);
94 ovalRect.inset(SkIntToScalar(2)/3, SkIntToScalar(2)/3);
95 surfaceCanvas->drawOval(ovalRect, paint);
96 }
97 sk_sp<SkImage> image(surface->makeImageSnapshot());
98 SkRect inRect = SkRect::MakeXYWH(-4, -4, 20, 20);
99 SkRect outRect = SkRect::MakeXYWH(-24, -24, 120, 120);
101 SkImageFilters::Image(std::move(image), inRect, outRect,
102 SkSamplingOptions({1/3.0f, 1/3.0f})));
103 this->draw(canvas, srcRect, deviceSize, samplings[3], std::move(source));
104 }
105 }
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
void clear(SkColor color)
Definition: SkCanvas.h:1199
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)
void draw(SkCanvas *canvas, const SkRect &rect, const SkSize &deviceSize, const SkSamplingOptions &sampling, sk_sp< SkImageFilter > input)
VkSurfaceKHR surface
Definition: main.cc:49
SkBitmap source
Definition: examples.cpp:28
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SkSamplingOptions(SkFilterMode::kLinear))
static constexpr SkCubicResampler Mitchell()
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
static constexpr SkSamplingOptions Aniso(int maxAniso)
Definition: SkSize.h:52
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56

The documentation for this class was generated from the following file: