Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 void flatten (SkWriteBuffer &) const
 
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 size_t onApproximateBytesUsed ()
 
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 146 of file AtlasSlide.cpp.

147 : fProc(proc), fBounds(r), fUseColors(false)
148 {
149 SkRandom rand;
150 fAtlas = make_atlas(kAtlasSize, kCellSize);
151 const SkScalar kMaxSpeed = 5;
152 const SkScalar cell = SkIntToScalar(kCellSize);
153 int i = 0;
154 for (int y = 0; y < kAtlasSize; y += kCellSize) {
155 for (int x = 0; x < kAtlasSize; x += kCellSize) {
156 const SkScalar sx = SkIntToScalar(x);
157 const SkScalar sy = SkIntToScalar(y);
158 fTex[i].setXYWH(sx, sy, cell, cell);
159
160 fRec[i].fCenter.set(sx + cell/2, sy + 3*cell/4);
161 fRec[i].fVelocity.fX = rand.nextSScalar1() * kMaxSpeed;
162 fRec[i].fVelocity.fY = rand.nextSScalar1() * kMaxSpeed;
163 fRec[i].fScale = 1;
164 fRec[i].fDScale = rand.nextSScalar1() / 16;
165 fRec[i].fRadian = 0;
166 fRec[i].fDRadian = rand.nextSScalar1() / 8;
167 fRec[i].fAlpha = rand.nextUScalar1();
168 fRec[i].fDAlpha = rand.nextSScalar1() / 10;
169 i += 1;
170 }
171 }
172 }
static sk_sp< SkImage > make_atlas(int atlasSize, int cellSize)
#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 179 of file AtlasSlide.cpp.

179 {
180 SkRSXform xform[N];
181 SkColor colors[N];
182
183 for (int i = 0; i < N; ++i) {
184 fRec[i].advance(fBounds);
185 xform[i] = fRec[i].asRSXform();
186 if (fUseColors) {
187 colors[i] = SkColorSetARGB((int)(fRec[i].fAlpha * 0xFF), 0xFF, 0xFF, 0xFF);
188 }
189 }
192
193 const SkRect cull = this->getBounds();
194 const SkColor* colorsPtr = fUseColors ? colors : nullptr;
195 fProc(canvas, fAtlas.get(), xform, fTex, colorsPtr, N, &cull, sampling, &paint);
196 }
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()
T * get() const
Definition SkRefCnt.h:303
const Paint & paint
PODArray< SkColor > colors
Definition SkRecords.h:276
SkSamplingOptions sampling
Definition SkRecords.h:337

◆ onGetBounds()

SkRect DrawAtlasDrawable::onGetBounds ( )
inlineoverrideprotectedvirtual

Implements SkDrawable.

Definition at line 198 of file AtlasSlide.cpp.

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

◆ toggleUseColors()

void DrawAtlasDrawable::toggleUseColors ( )
inline

Definition at line 174 of file AtlasSlide.cpp.

174 {
175 fUseColors = !fUseColors;
176 }

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