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

Public Member Functions

 ImageMakeWithFilterGM (Strategy strategy, bool filterWithCropRect=false)
 
- 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
 
SkISize getISize () override
 
void onOnceBeforeDraw () override
 
DrawResult onDraw (SkCanvas *canvas, SkString *errorMsg) 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 191 of file imagemakewithfilter.cpp.

Constructor & Destructor Documentation

◆ ImageMakeWithFilterGM()

ImageMakeWithFilterGM::ImageMakeWithFilterGM ( Strategy  strategy,
bool  filterWithCropRect = false 
)
inline

Definition at line 193 of file imagemakewithfilter.cpp.

194 : fStrategy(strategy)
195 , fFilterWithCropRect(filterWithCropRect)
196 , fMainImage(nullptr)
197 , fAuxImage(nullptr) {}

Member Function Documentation

◆ getISize()

SkISize ImageMakeWithFilterGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 212 of file imagemakewithfilter.cpp.

212{ return SkISize::Make(1840, 860); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString ImageMakeWithFilterGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 200 of file imagemakewithfilter.cpp.

200 {
201 SkString name = SkString("imagemakewithfilter");
202
203 if (fFilterWithCropRect) {
204 name.append("_crop");
205 }
206 if (fStrategy == Strategy::kSaveLayer) {
207 name.append("_ref");
208 }
209 return name;
210 }
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ onDraw()

DrawResult ImageMakeWithFilterGM::onDraw ( SkCanvas canvas,
SkString errorMsg 
)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 230 of file imagemakewithfilter.cpp.

230 {
231 FilterFactory filters[] = {
245 };
246 const char* filterNames[] = {
247 "Color",
248 "Blur",
249 "Drop Shadow",
250 "Offset",
251 "Dilate",
252 "Erode",
253 "Displacement",
254 "Arithmetic",
255 "Blend",
256 "Convolution",
257 "Matrix Xform",
258 "Lighting",
259 "Tile"
260 };
261 static_assert(std::size(filters) == std::size(filterNames), "filter name length");
262
263 SkIRect clipBounds[] {
264 { -20, -20, 100, 100 },
265 { 0, 0, 75, 75 },
266 { 20, 20, 100, 100 },
267 { -20, -20, 50, 50 },
268 { 20, 20, 50, 50 },
269 { 30, 30, 75, 75 }
270 };
271
272 auto rContext = canvas->recordingContext();
273 // In a DDL context, we can't use the GPU code paths and we will drop the work – skip.
274 auto dContext = GrAsDirectContext(rContext);
275 if (rContext) {
276 if (!dContext) {
277 *errorMsg = "Requires a direct context.";
278 return DrawResult::kSkip;
279 }
280 if (dContext->abandoned()) {
281 *errorMsg = "Direct context abandoned.";
282 return DrawResult::kSkip;
283 }
284 }
285
286 // These need to be GPU-backed when on the GPU to ensure that the image filters use the GPU
287 // code paths (otherwise they may choose to do CPU filtering then upload)
288 sk_sp<SkImage> mainImage = ToolUtils::MakeTextureImage(canvas, fMainImage);
289 sk_sp<SkImage> auxImage = ToolUtils::MakeTextureImage(canvas, fAuxImage);
290 if (!mainImage || !auxImage) {
291 return DrawResult::kFail;
292 }
293 SkASSERT(mainImage && (mainImage->isTextureBacked() || !dContext));
294 SkASSERT(auxImage && (auxImage->isTextureBacked() || !dContext));
295
297 SkScalar DX = mainImage->width() + MARGIN;
298 SkScalar DY = auxImage->height() + MARGIN;
299
300 // Header hinting at what the filters do
301 SkPaint textPaint;
302 textPaint.setAntiAlias(true);
304 font.setSize(12);
305 for (size_t i = 0; i < std::size(filterNames); ++i) {
306 canvas->drawString(filterNames[i], DX * i + MARGIN, 15, font, textPaint);
307 }
308
309 canvas->translate(MARGIN, MARGIN);
310
311 for (auto clipBound : clipBounds) {
312 canvas->save();
313 for (size_t i = 0; i < std::size(filters); ++i) {
314 SkIRect subset = SkIRect::MakeXYWH(25, 25, 50, 50);
315 SkIRect outSubset;
316
317 // Draw the original image faintly so that it aids in checking alignment of the
318 // filtered result.
319 SkPaint alpha;
320 alpha.setAlphaf(0.3f);
321 canvas->drawImage(mainImage, 0, 0, SkSamplingOptions(), &alpha);
322
323 this->drawImageWithFilter(canvas, mainImage, auxImage, filters[i], clipBound,
324 subset, &outSubset);
325
326 // Draw outlines to highlight what was subset, what was cropped, and what was output
327 // (no output subset is displayed for kSaveLayer since that information isn't avail)
328 SkIRect* outSubsetBounds = nullptr;
329 if (fStrategy != Strategy::kSaveLayer) {
330 outSubsetBounds = &outSubset;
331 }
332 show_bounds(canvas, &clipBound, &subset, outSubsetBounds);
333
334 canvas->translate(DX, 0);
335 }
336 canvas->restore();
337 canvas->translate(0, DY);
338 }
339 return DrawResult::kOk;
340 }
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
int save()
Definition: SkCanvas.cpp:447
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
Definition: SkFont.h:35
int width() const
Definition: SkImage.h:285
virtual bool isTextureBacked() const =0
int height() const
Definition: SkImage.h:291
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setAlphaf(float a)
Definition: SkPaint.cpp:130
#define MARGIN
float SkScalar
Definition: extension.cpp:12
static sk_sp< SkImageFilter > tile_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
static void show_bounds(SkCanvas *canvas, const SkIRect *clip, const SkIRect *inSubset, const SkIRect *outSubset)
static sk_sp< SkImageFilter > drop_shadow_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
static sk_sp< SkImageFilter > lighting_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
static sk_sp< SkImageFilter > dilate_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
static sk_sp< SkImageFilter > blur_filter_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
static sk_sp< SkImageFilter > convolution_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
static sk_sp< SkImageFilter > offset_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
static sk_sp< SkImageFilter > blend_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
static sk_sp< SkImageFilter > erode_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
static sk_sp< SkImageFilter > color_filter_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
static sk_sp< SkImageFilter > matrix_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
sk_sp< SkImageFilter >(* FilterFactory)(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
static sk_sp< SkImageFilter > arithmetic_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
static sk_sp< SkImageFilter > displacement_factory(sk_sp< SkImage > auxImage, const SkIRect *cropRect)
SkFont DefaultPortableFont()
sk_sp< SkImage > MakeTextureImage(SkCanvas *canvas, sk_sp< SkImage > orig)
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 keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
SkSamplingOptions(SkFilterMode::kLinear))
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104

◆ onOnceBeforeDraw()

void ImageMakeWithFilterGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 214 of file imagemakewithfilter.cpp.

214 {
216 auto surface = SkSurfaces::Raster(info, nullptr);
217
218 sk_sp<SkImage> colorImage = ToolUtils::GetResourceAsImage("images/mandrill_128.png");
219 // Resize to 100x100
220 surface->getCanvas()->drawImageRect(
221 colorImage, SkRect::MakeWH(colorImage->width(), colorImage->height()),
222 SkRect::MakeWH(info.width(), info.height()), SkSamplingOptions(), nullptr,
224 fMainImage = surface->makeImageSnapshot();
225
227 fAuxImage = surface->makeImageSnapshot();
228 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
kUnpremul_SkAlphaType
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
void draw_checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)
Definition: ToolUtils.cpp:174
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

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