Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
TextureUploadSlide Class Reference
Inheritance diagram for TextureUploadSlide:
Slide SkRefCnt SkRefCntBase

Public Member Functions

 TextureUploadSlide ()
 
bool onChar (SkUnichar uni) override
 
SkISize getDimensions () const override
 
void draw (SkCanvas *canvas) override
 
bool animate (double nanos) override
 
- Public Member Functions inherited from Slide
virtual SkISize getDimensions () const
 
virtual void gpuTeardown ()
 
virtual void draw (SkCanvas *canvas)=0
 
virtual bool animate (double nanos)
 
virtual void load (SkScalar winWidth, SkScalar winHeight)
 
virtual void resize (SkScalar winWidth, SkScalar winHeight)
 
virtual void unload ()
 
virtual bool onChar (SkUnichar c)
 
virtual bool onMouse (SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
const SkStringgetName ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

This sample exercises heavy texture updates and uploads.

Definition at line 22 of file TextureUploadSlide.cpp.

Constructor & Destructor Documentation

◆ TextureUploadSlide()

TextureUploadSlide::TextureUploadSlide ( )
inline

Definition at line 24 of file TextureUploadSlide.cpp.

24{ fName = "TextureUpload"; }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ animate()

bool TextureUploadSlide::animate ( double  nanos)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 81 of file TextureUploadSlide.cpp.

81 {
82 constexpr SkScalar kDesiredDurationSecs = 16.0f;
83 float numTiles = fTileRows*fTileCols;
84 fActiveTileIndex = floorf(TimeUtils::Scaled(1e-9 * nanos,
85 numTiles/kDesiredDurationSecs, numTiles));
86 return true;
87 }
float SkScalar
Definition: extension.cpp:12
static float Scaled(float time, float speed, float period=0)
Definition: TimeUtils.h:27

◆ draw()

void TextureUploadSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 46 of file TextureUploadSlide.cpp.

46 {
47 canvas->clear(0xFFFFFFFF);
48#if defined(SK_GANESH)
49 auto direct = GrAsDirectContext(canvas->recordingContext());
50 if (direct) {
51 // One-time context-specific setup.
52 if (direct != fCachedContext) {
53 fCachedContext = direct;
54 this->initializeTextures(direct);
55 }
56
57 // Upload new texture data for all textures, simulating a full page of tiles
58 // needing refresh.
59 int textureCount = fTileRows * fTileCols;
60 for (int i = 0; i < textureCount; i++) {
61 fTextures[i]->uploadRasterSurface(i == fActiveTileIndex ? fBlueSurface
62 : fGraySurface);
63 }
64
65 // Scale grid.
66 canvas->scale(kGridScale, kGridScale);
67
68 if (fDrawTexturesToScreen) {
69 for (int y = 0; y < fTileRows; y++) {
70 for (int x = 0; x < fTileCols; x++) {
71 int currentIndex = y * fTileCols + x;
72 canvas->drawImage(fTextures[currentIndex]->getImage(),
73 x * fTileSize, y * fTileSize);
74 }
75 }
76 }
77 }
78#endif
79 }
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void clear(SkColor color)
Definition: SkCanvas.h:1199
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
double y
double x

◆ getDimensions()

SkISize TextureUploadSlide::getDimensions ( ) const
inlineoverridevirtual

A slide may have a content dimensions that is independent of the current window size. An empty size indicates that the Slide's dimensions are equal to the window's dimensions.

Reimplemented from Slide.

Definition at line 44 of file TextureUploadSlide.cpp.

44{ return {1024, 1024}; }

◆ onChar()

bool TextureUploadSlide::onChar ( SkUnichar  uni)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 26 of file TextureUploadSlide.cpp.

26 {
27 if ('m' == uni) {
28 fDrawTexturesToScreen = !fDrawTexturesToScreen;
29 return true;
30 } else if ('>' == uni) {
31 fTileSize = std::min(kMaxTileSize, 2*fTileSize);
32 fTileRows = kMaxTileSize/fTileSize;
33 fTileCols = kMaxTileSize/fTileSize;
34 fCachedContext = nullptr;
35 } else if ('<' == uni) {
36 fTileSize = std::max(kMinTileSize, fTileSize/2);
37 fTileRows = kMaxTileSize/fTileSize;
38 fTileCols = kMaxTileSize/fTileSize;
39 fCachedContext = nullptr;
40 }
41 return false;
42 }
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48

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