Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Member Functions | List of all members
DrawAtlasDrawable Class Reference
Inheritance diagram for DrawAtlasDrawable:
SkDrawable SkFlattenable SkRefCnt SkRefCntBase

Public Member Functions

 DrawAtlasDrawable (DrawAtlasProc proc, const SkRect &r)
 
void toggleUseColors ()
 
- Public Member Functions inherited from SkDrawable
void draw (SkCanvas *, const SkMatrix *=nullptr)
 
void draw (SkCanvas *, SkScalar x, SkScalar y)
 
std::unique_ptr< GpuDrawHandlersnapGpuDrawHandler (GrBackendApi backendApi, const SkMatrix &matrix, const SkIRect &clipBounds, const SkImageInfo &bufferInfo)
 
sk_sp< SkPicturemakePictureSnapshot ()
 
uint32_t getGenerationID ()
 
SkRect getBounds ()
 
size_t approximateBytesUsed ()
 
void notifyDrawingChanged ()
 
SkFlattenable::Type getFlattenableType () const override
 
Factory getFactory () const override
 
const char * getTypeName () const override
 
- Public Member Functions inherited from SkFlattenable
 SkFlattenable ()
 
virtual Factory getFactory () const =0
 
virtual const char * getTypeName () const =0
 
virtual void flatten (SkWriteBuffer &) const
 
virtual Type getFlattenableType () const =0
 
sk_sp< SkDataserialize (const SkSerialProcs *=nullptr) const
 
size_t serialize (void *memory, size_t memory_size, const SkSerialProcs *=nullptr) const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

void onDraw (SkCanvas *canvas) override
 
SkRect onGetBounds () override
 
- Protected Member Functions inherited from SkDrawable
 SkDrawable ()
 
virtual SkRect onGetBounds ()=0
 
virtual size_t onApproximateBytesUsed ()
 
virtual void onDraw (SkCanvas *)=0
 
virtual std::unique_ptr< GpuDrawHandleronSnapGpuDrawHandler (GrBackendApi, const SkMatrix &, const SkIRect &, const SkImageInfo &)
 
virtual std::unique_ptr< GpuDrawHandleronSnapGpuDrawHandler (GrBackendApi, const SkMatrix &)
 
virtual sk_sp< SkPictureonMakePictureSnapshot ()
 

Additional Inherited Members

- Public Types inherited from SkFlattenable
enum  Type {
  kSkColorFilter_Type , kSkBlender_Type , kSkDrawable_Type , kSkDrawLooper_Type ,
  kSkImageFilter_Type , kSkMaskFilter_Type , kSkPathEffect_Type , kSkShader_Type
}
 
typedef sk_sp< SkFlattenable >(* Factory) (SkReadBuffer &)
 
- Static Public Member Functions inherited from SkDrawable
static SkFlattenable::Type GetFlattenableType ()
 
static sk_sp< SkDrawableDeserialize (const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
 
- Static Public Member Functions inherited from SkFlattenable
static Factory NameToFactory (const char name[])
 
static const char * FactoryToName (Factory)
 
static void Register (const char name[], Factory)
 
static sk_sp< SkFlattenableDeserialize (Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)
 

Detailed Description

Definition at line 73 of file AtlasSlide.cpp.

Constructor & Destructor Documentation

◆ DrawAtlasDrawable()

DrawAtlasDrawable::DrawAtlasDrawable ( DrawAtlasProc  proc,
const SkRect r 
)
inline

Definition at line 144 of file AtlasSlide.cpp.

145 : fProc(proc), fBounds(r), fUseColors(false)
146 {
147 SkRandom rand;
148 fAtlas = make_atlas(kAtlasSize, kCellSize);
149 const SkScalar kMaxSpeed = 5;
150 const SkScalar cell = SkIntToScalar(kCellSize);
151 int i = 0;
152 for (int y = 0; y < kAtlasSize; y += kCellSize) {
153 for (int x = 0; x < kAtlasSize; x += kCellSize) {
154 const SkScalar sx = SkIntToScalar(x);
155 const SkScalar sy = SkIntToScalar(y);
156 fTex[i].setXYWH(sx, sy, cell, cell);
157
158 fRec[i].fCenter.set(sx + cell/2, sy + 3*cell/4);
159 fRec[i].fVelocity.fX = rand.nextSScalar1() * kMaxSpeed;
160 fRec[i].fVelocity.fY = rand.nextSScalar1() * kMaxSpeed;
161 fRec[i].fScale = 1;
162 fRec[i].fDScale = rand.nextSScalar1() / 16;
163 fRec[i].fRadian = 0;
164 fRec[i].fDRadian = rand.nextSScalar1() / 8;
165 fRec[i].fAlpha = rand.nextUScalar1();
166 fRec[i].fDAlpha = rand.nextSScalar1() / 10;
167 i += 1;
168 }
169 }
170 }
static sk_sp< SkImage > make_atlas(int atlasSize, int cellSize)
Definition: AtlasSlide.cpp:46
#define SkIntToScalar(x)
Definition: SkScalar.h:57
SkScalar nextUScalar1()
Definition: SkRandom.h:101
SkScalar nextSScalar1()
Definition: SkRandom.h:113
float SkScalar
Definition: extension.cpp:12
double y
double x
void setXYWH(float x, float y, float width, float height)
Definition: SkRect.h:931

Member Function Documentation

◆ onDraw()

void DrawAtlasDrawable::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Implements SkDrawable.

Definition at line 177 of file AtlasSlide.cpp.

177 {
178 SkRSXform xform[N];
179 SkColor colors[N];
180
181 for (int i = 0; i < N; ++i) {
182 fRec[i].advance(fBounds);
183 xform[i] = fRec[i].asRSXform();
184 if (fUseColors) {
185 colors[i] = SkColorSetARGB((int)(fRec[i].fAlpha * 0xFF), 0xFF, 0xFF, 0xFF);
186 }
187 }
190
191 const SkRect cull = this->getBounds();
192 const SkColor* colorsPtr = fUseColors ? colors : nullptr;
193 fProc(canvas, fAtlas.get(), xform, fTex, colorsPtr, N, &cull, sampling, &paint);
194 }
uint32_t SkColor
Definition: SkColor.h:37
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
SkRect getBounds()
Definition: SkDrawable.cpp:71
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
PODArray< SkColor > colors
Definition: SkRecords.h:276
SkSamplingOptions sampling
Definition: SkRecords.h:337

◆ onGetBounds()

SkRect DrawAtlasDrawable::onGetBounds ( )
inlineoverrideprotectedvirtual

Implements SkDrawable.

Definition at line 196 of file AtlasSlide.cpp.

196 {
197 const SkScalar border = kMaxScale * kCellSize;
198 SkRect r = fBounds;
199 r.outset(border, border);
200 return r;
201 }
void outset(float dx, float dy)
Definition: SkRect.h:1077

◆ toggleUseColors()

void DrawAtlasDrawable::toggleUseColors ( )
inline

Definition at line 172 of file AtlasSlide.cpp.

172 {
173 fUseColors = !fUseColors;
174 }

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