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

Public Member Functions

 ImageCacheratorGM (const char suffix[], FactoryFunc factory, bool useTexture)
 
- 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
 
bool makeCaches (SkCanvas *canvas)
 
void drawRow (GrDirectContext *dContext, SkCanvas *canvas, float scale) const
 
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
 

Static Protected Member Functions

static void draw_placeholder (SkCanvas *canvas, SkScalar x, SkScalar y, int w, int h)
 
static void draw_as_bitmap (GrDirectContext *dContext, SkCanvas *canvas, SkImage *image, SkScalar x, SkScalar y)
 
static void draw_as_tex (SkCanvas *canvas, SkImage *image, SkScalar x, SkScalar y)
 

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 250 of file image_pict.cpp.

Constructor & Destructor Documentation

◆ ImageCacheratorGM()

ImageCacheratorGM::ImageCacheratorGM ( const char  suffix[],
FactoryFunc  factory,
bool  useTexture 
)
inline

Definition at line 261 of file image_pict.cpp.

261 :
262 fFactory(factory), fUseTexture(useTexture) {
263 fName.printf("image-cacherator-from-%s", suffix);
264 }
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534

Member Function Documentation

◆ draw_as_bitmap()

static void ImageCacheratorGM::draw_as_bitmap ( GrDirectContext dContext,
SkCanvas canvas,
SkImage image,
SkScalar  x,
SkScalar  y 
)
inlinestaticprotected

Definition at line 344 of file image_pict.cpp.

345 {
347 if (as_IB(image)->getROPixels(dContext, &bitmap)) {
348 canvas->drawImage(bitmap.asImage(), x, y);
349 } else {
350 draw_placeholder(canvas, x, y, image->width(), image->height());
351 }
352 }
static SkImage_Base * as_IB(SkImage *image)
Definition: SkImage_Base.h:201
static void draw_placeholder(SkCanvas *canvas, SkScalar x, SkScalar y, int w, int h)
Definition: image_pict.cpp:335
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
double y
double x
sk_sp< const SkImage > image
Definition: SkRecords.h:269
Definition: bitmap.py:1

◆ draw_as_tex()

static void ImageCacheratorGM::draw_as_tex ( SkCanvas canvas,
SkImage image,
SkScalar  x,
SkScalar  y 
)
inlinestaticprotected

Definition at line 354 of file image_pict.cpp.

354 {
355 if (as_IB(image)->isGaneshBacked()) {
356 // The gpu-backed images are drawn in this manner bc the generator backed images
357 // aren't considered texture-backed
358 auto [view, ct] =
360 if (!view) {
361 // show placeholder if we have no texture
362 draw_placeholder(canvas, x, y, image->width(), image->height());
363 return;
364 }
366 image->alphaType(),
368 // No API to draw a GrTexture directly, so we cheat and create a private image subclass
370 image->uniqueID(),
371 std::move(view),
372 std::move(colorInfo)));
373 canvas->drawImage(texImage.get(), x, y);
374 } else {
375 canvas->drawImage(image, x, y);
376 }
377 }
static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct)
Definition: GrTypesPriv.h:589
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
uint32_t uniqueID() const
Definition: SkImage.h:311
SkAlphaType alphaType() const
Definition: SkImage.cpp:154
sk_sp< SkColorSpace > refColorSpace() const
Definition: SkImage.cpp:158
std::tuple< GrSurfaceProxyView, GrColorType > AsView(GrRecordingContext *rContext, const SkImage *img, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)

◆ draw_placeholder()

static void ImageCacheratorGM::draw_placeholder ( SkCanvas canvas,
SkScalar  x,
SkScalar  y,
int  w,
int  h 
)
inlinestaticprotected

Definition at line 335 of file image_pict.cpp.

335 {
339 canvas->drawRect(r, paint);
340 canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), paint);
341 canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint);
342 }
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
const Paint & paint
Definition: color_source.cc:38
SkScalar w
SkScalar h
constexpr float left() const
Definition: SkRect.h:734
constexpr float top() const
Definition: SkRect.h:741
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
constexpr float right() const
Definition: SkRect.h:748
constexpr float bottom() const
Definition: SkRect.h:755

◆ drawRow()

void ImageCacheratorGM::drawRow ( GrDirectContext dContext,
SkCanvas canvas,
float  scale 
) const
inlineprotected

Definition at line 379 of file image_pict.cpp.

379 {
380 canvas->scale(scale, scale);
381
382 SkMatrix matrix = SkMatrix::Translate(-100, -100);
383 canvas->drawPicture(fPicture, &matrix, nullptr);
384
385 // Draw the tex first, so it doesn't hit a lucky cache from the raster version. This
386 // way we also can force the generateTexture call.
387
388 draw_as_tex(canvas, fImage.get(), 150, 0);
389 draw_as_tex(canvas, fImageSubset.get(), 150+101, 0);
390
391 draw_as_bitmap(dContext, canvas, fImage.get(), 310, 0);
392 draw_as_bitmap(dContext, canvas, fImageSubset.get(), 310+101, 0);
393 }
static void draw_as_tex(SkCanvas *canvas, SkImage *image, SkScalar x, SkScalar y)
Definition: image_pict.cpp:354
static void draw_as_bitmap(GrDirectContext *dContext, SkCanvas *canvas, SkImage *image, SkScalar x, SkScalar y)
Definition: image_pict.cpp:344
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void drawPicture(const SkPicture *picture)
Definition: SkCanvas.h:1961
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
T * get() const
Definition: SkRefCnt.h:303
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
const Scalar scale

◆ getISize()

SkISize ImageCacheratorGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 269 of file image_pict.cpp.

269{ return SkISize::Make(960, 450); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString ImageCacheratorGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 267 of file image_pict.cpp.

267{ return fName; }

◆ makeCaches()

bool ImageCacheratorGM::makeCaches ( SkCanvas canvas)
inlineprotected

Definition at line 278 of file image_pict.cpp.

278 {
279 auto dContext = GrAsDirectContext(canvas->recordingContext());
280
281 {
282 auto gen = fFactory(canvas, fPicture);
283 if (!gen) {
284 return false;
285 }
286 if (fUseTexture) {
287 auto textureGen = std::unique_ptr<GrTextureGenerator>(
288 static_cast<GrTextureGenerator*>(gen.release()));
289 fImage = SkImages::DeferredFromTextureGenerator(std::move(textureGen));
290 } else {
291 fImage = SkImages::DeferredFromGenerator(std::move(gen));
292 }
293 if (!fImage) {
294 return false;
295 }
296 SkASSERT(fImage->dimensions() == SkISize::Make(100, 100));
297 }
298
299 {
300 const SkIRect subset = SkIRect::MakeLTRB(50, 50, 100, 100);
301
302 // We re-create the generator here on the off chance that making a subset from
303 // 'fImage' might perturb its state.
304 auto gen = fFactory(canvas, fPicture);
305 if (!gen) {
306 return false;
307 }
308
309 if (dContext) {
310 if (fUseTexture) {
311 auto textureGen = std::unique_ptr<GrTextureGenerator>(
312 static_cast<GrTextureGenerator*>(gen.release()));
313 fImageSubset = SkImages::DeferredFromTextureGenerator(std::move(textureGen))
314 ->makeSubset(dContext, subset);
315 } else {
316 fImageSubset = SkImages::DeferredFromGenerator(std::move(gen))
317 ->makeSubset(dContext, subset);
318 }
319 } else {
320#if defined(SK_GRAPHITE)
321 auto recorder = canvas->recorder();
322 fImageSubset = SkImages::DeferredFromGenerator(std::move(gen))
323 ->makeSubset(recorder, subset, {});
324#endif
325 }
326 if (!fImageSubset) {
327 return false;
328 }
329 SkASSERT(fImageSubset->dimensions() == SkISize::Make(50, 50));
330 }
331
332 return true;
333 }
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
#define SkASSERT(cond)
Definition: SkAssert.h:116
virtual skgpu::graphite::Recorder * recorder() const
Definition: SkCanvas.cpp:1641
SkISize dimensions() const
Definition: SkImage.h:297
virtual sk_sp< SkImage > makeSubset(GrDirectContext *direct, const SkIRect &subset) const =0
SK_API sk_sp< SkImage > DeferredFromTextureGenerator(std::unique_ptr< GrTextureGenerator > gen)
SK_API sk_sp< SkImage > DeferredFromGenerator(std::unique_ptr< SkImageGenerator > imageGenerator)
Definition: gen.py:1
Definition: SkRect.h:32
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition: SkRect.h:91

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 395 of file image_pict.cpp.

395 {
396 auto dContext = GrAsDirectContext(canvas->recordingContext());
397 if (!this->makeCaches(canvas)) {
398 errorMsg->printf("Could not create cached images");
399 return DrawResult::kSkip;
400 }
401
402 canvas->save();
403 canvas->translate(20, 20);
404 this->drawRow(dContext, canvas, 1.0);
405 canvas->restore();
406
407 canvas->save();
408 canvas->translate(20, 150);
409 this->drawRow(dContext, canvas, 0.25f);
410 canvas->restore();
411
412 canvas->save();
413 canvas->translate(20, 220);
414 this->drawRow(dContext, canvas, 2.0f);
415 canvas->restore();
416
417 return DrawResult::kOk;
418 }
void drawRow(GrDirectContext *dContext, SkCanvas *canvas, float scale) const
Definition: image_pict.cpp:379
bool makeCaches(SkCanvas *canvas)
Definition: image_pict.cpp:278
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447

◆ onOnceBeforeDraw()

void ImageCacheratorGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 271 of file image_pict.cpp.

271 {
272 const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100);
273 SkPictureRecorder recorder;
275 fPicture = recorder.finishRecordingAsPicture();
276 }
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
static void draw_something(SkCanvas *canvas, const SkRect &bounds)
Definition: image_pict.cpp:53
Optional< SkRect > bounds
Definition: SkRecords.h:189

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