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

Public Member Functions

 AnimatedImageGM (const char *path, const char *name, int step, SkIRect cropRect)
 
 ~AnimatedImageGM () override=default
 
SkString getName () const override
 
SkISize getISize () override
 
void onDraw (SkCanvas *canvas) override
 
- 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
 

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 []
 
- 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
 

Detailed Description

Definition at line 40 of file animated_image_orientation.cpp.

Constructor & Destructor Documentation

◆ AnimatedImageGM()

AnimatedImageGM::AnimatedImageGM ( const char *  path,
const char *  name,
int  step,
SkIRect  cropRect 
)
inline

Definition at line 69 of file animated_image_orientation.cpp.

70 : fPath(path)
71 , fName(name)
72 , fStep(step)
73 , fCropRect(cropRect)
74 , fSize{0, 0}
75 , fTranslate(0)
76 {}
static int step(int x, SkScalar min, SkScalar max)
Definition: BlurTest.cpp:215
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ ~AnimatedImageGM()

AnimatedImageGM::~AnimatedImageGM ( )
overridedefault

Member Function Documentation

◆ getISize()

SkISize AnimatedImageGM::getISize ( )
inlineoverridevirtual

Implements skiagm::GM.

Definition at line 81 of file animated_image_orientation.cpp.

81 {
82 this->init();
83 return fSize;
84 }

◆ getName()

SkString AnimatedImageGM::getName ( ) const
inlineoverridevirtual

Implements skiagm::GM.

Definition at line 79 of file animated_image_orientation.cpp.

79{ return SkStringPrintf("%s_animated_image", fName); }
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.

◆ onDraw()

void AnimatedImageGM::onDraw ( SkCanvas canvas)
inlineoverridevirtual

Reimplemented from skiagm::GM.

Definition at line 86 of file animated_image_orientation.cpp.

86 {
87 this->init();
88 for (bool usePic : { true, false }) {
89 auto drawProc = [canvas, usePic](const sk_sp<SkAnimatedImage>& animatedImage) {
90 if (usePic) {
91 sk_sp<SkPicture> pic = animatedImage->makePictureSnapshot();
92 canvas->drawPicture(pic);
93 } else {
94 auto image = animatedImage->getCurrentFrame();
95 canvas->drawImage(image, 0, 0);
96 }
97 };
98 for (float scale : { 1.25f, 1.0f, .75f, .5f }) {
99 canvas->save();
100 for (bool doCrop : { false, true }) {
101 for (bool doPostProcess : { false, true }) {
102 auto codec = SkCodec::MakeFromData(fData);
103 const auto origin = codec->getOrigin();
104 auto androidCodec = SkAndroidCodec::MakeFromCodec(std::move(codec));
105 auto info = androidCodec->getInfo();
106 const auto unscaledSize = SkEncodedOriginSwapsWidthHeight(origin)
107 ? SkISize{ info.height(), info.width() } : info.dimensions();
108
109 SkISize scaledSize = { SkScalarFloorToInt(unscaledSize.width() * scale) ,
110 SkScalarFloorToInt(unscaledSize.height() * scale) };
111 info = info.makeDimensions(scaledSize);
112
113 auto cropRect = SkIRect::MakeSize(scaledSize);
114 if (doCrop) {
115 auto matrix = SkMatrix::RectToRect(SkRect::Make(unscaledSize),
116 SkRect::Make(scaledSize));
117 matrix.preConcat(SkEncodedOriginToMatrix(origin,
118 unscaledSize.width(), unscaledSize.height()));
119 SkRect cropRectFloat = SkRect::Make(fCropRect);
120 matrix.mapRect(&cropRectFloat);
121 cropRectFloat.roundOut(&cropRect);
122 }
123
124 sk_sp<SkPicture> postProcessor = doPostProcess
125 ? post_processor(SkRect::Make(cropRect.size())) : nullptr;
126 auto animatedImage = SkAnimatedImage::Make(std::move(androidCodec),
127 info, cropRect, std::move(postProcessor));
128 animatedImage->setRepetitionCount(0);
129
130 for (int frame = 0; frame < kMaxFrames; frame++) {
131 {
132 SkAutoCanvasRestore acr(canvas, doCrop);
133 if (doCrop) {
134 canvas->translate(cropRect.left(), cropRect.top());
135 }
136 drawProc(animatedImage);
137 }
138
139 canvas->translate(fTranslate, 0);
140 const auto duration = animatedImage->currentFrameDuration();
142 break;
143 }
144 for (int i = 0; i < fStep; i++) {
145 animatedImage->decodeNextFrame();
146 }
147 }
148 }
149 }
150 canvas->restore();
151 canvas->translate(0, fTranslate);
152 }
153 }
154 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static bool SkEncodedOriginSwapsWidthHeight(SkEncodedOrigin origin)
static SkMatrix SkEncodedOriginToMatrix(SkEncodedOrigin origin, int w, int h)
#define SkScalarFloorToInt(x)
Definition: SkScalar.h:35
static sk_sp< SkPicture > post_processor(const SkRect &bounds)
static std::unique_ptr< SkAndroidCodec > MakeFromCodec(std::unique_ptr< SkCodec >)
static sk_sp< SkAnimatedImage > Make(std::unique_ptr< SkAndroidCodec >, const SkImageInfo &info, SkIRect cropRect, sk_sp< SkPicture > postProcess)
static constexpr int kFinished
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void drawPicture(const SkPicture *picture)
Definition: SkCanvas.h:1961
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
Definition: SkCodec.cpp:241
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition: SkMatrix.h:157
double duration
Definition: examples.cpp:30
double frame
Definition: examples.cpp:31
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
sk_sp< const SkImage > image
Definition: SkRecords.h:269
const Scalar scale
static constexpr SkIRect MakeSize(const SkISize &size)
Definition: SkRect.h:66
Definition: SkSize.h:16
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241

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