Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
LatticeGM Class Reference
Inheritance diagram for LatticeGM:
skiagm::GM

Public Member Functions

 LatticeGM ()
 
- 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 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 onDrawHelper (GrDirectContext *dContext, SkCanvas *canvas, int padLeft, int padTop, int padRight, int padBottom)
 
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 void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () 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 []
 

Detailed Description

This is similar to NinePatchStretchGM, but it also tests "ninepatch" images with more than nine patches.

Definition at line 94 of file lattice.cpp.

Constructor & Destructor Documentation

◆ LatticeGM()

LatticeGM::LatticeGM ( )
inline

Definition at line 96 of file lattice.cpp.

96{}

Member Function Documentation

◆ getISize()

SkISize LatticeGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 101 of file lattice.cpp.

101{ return SkISize::Make(800, 800); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20

◆ getName()

SkString LatticeGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 99 of file lattice.cpp.

99{ return SkString("lattice"); }

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 206 of file lattice.cpp.

206 {
207 auto rContext = canvas->recordingContext();
208 auto dContext = GrAsDirectContext(rContext);
209 if (rContext && !dContext) {
210 *errorMsg = "not supported in ddl";
211 return DrawResult::kSkip;
212 }
213 this->onDrawHelper(dContext, canvas, 0, 0, 0, 0);
214 canvas->translate(0.0f, 400.0f);
215 this->onDrawHelper(dContext, canvas, 3, 7, 4, 11);
216 return DrawResult::kOk;
217 }
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
void onDrawHelper(GrDirectContext *dContext, SkCanvas *canvas, int padLeft, int padTop, int padRight, int padBottom)
Definition lattice.cpp:103
void translate(SkScalar dx, SkScalar dy)
virtual GrRecordingContext * recordingContext() const

◆ onDrawHelper()

void LatticeGM::onDrawHelper ( GrDirectContext dContext,
SkCanvas canvas,
int  padLeft,
int  padTop,
int  padRight,
int  padBottom 
)
inlineprotected

Definition at line 103 of file lattice.cpp.

104 {
105 canvas->save();
106
107 int xDivs[5];
108 int yDivs[5];
109 xDivs[0] = padLeft;
110 yDivs[0] = padTop;
111
113 sk_sp<SkImage> image = make_image(canvas, xDivs + 1, yDivs + 1, padLeft, padTop,
114 padRight, padBottom);
115 image_to_bitmap(dContext, image.get(), &bitmap);
116
117 const SkSize size[] = {
118 { 50, 50, }, // shrink in both axes
119 { 50, 200, }, // shrink in X
120 { 200, 50, }, // shrink in Y
121 { 200, 200, },
122 };
123
124 canvas->drawImage(image, 10, 10);
125
126 SkScalar x = SkIntToScalar(100);
127 SkScalar y = SkIntToScalar(100);
128
129 SkCanvas::Lattice lattice;
130 lattice.fXCount = 4;
131 lattice.fXDivs = xDivs + 1;
132 lattice.fYCount = 4;
133 lattice.fYDivs = yDivs + 1;
134 lattice.fRectTypes = nullptr;
135 lattice.fColors = nullptr;
136
137 SkIRect bounds = SkIRect::MakeLTRB(padLeft, padTop,
138 image->width() - padRight, image->height() - padBottom);
139 lattice.fBounds = (bounds == SkIRect::MakeWH(image->width(), image->height())) ?
140 nullptr : &bounds;
141
142 for (int iy = 0; iy < 2; ++iy) {
143 for (int ix = 0; ix < 2; ++ix) {
144 int i = ix * 2 + iy;
145 SkRect r = SkRect::MakeXYWH(x + ix * 60, y + iy * 60,
146 size[i].width(), size[i].height());
147 canvas->drawImageLattice(image.get(), lattice, r);
148 }
149 }
150
151 // Provide hints about 3 solid color rects. These colors match
152 // what was already in the bitmap.
153 int fixedColorX[3] = {2, 4, 1};
154 int fixedColorY[3] = {1, 1, 2};
158 for (int rectNum = 0; rectNum < 3; rectNum++) {
159 int srcX = xDivs[fixedColorX[rectNum]-1];
160 int srcY = yDivs[fixedColorY[rectNum]-1];
161 image->readPixels(dContext, info, &fixedColor[rectNum], 4, srcX, srcY);
162 }
163
164 // Include the degenerate first div. While normally the first patch is "scalable",
165 // this will mean that the first non-degenerate patch is "fixed".
166 lattice.fXCount = 5;
167 lattice.fXDivs = xDivs;
168 lattice.fYCount = 5;
169 lattice.fYDivs = yDivs;
170
171 // Let's skip a few rects.
178 for (int rectNum = 0; rectNum < 3; rectNum++) {
179 flags[fixedColorY[rectNum]*6 + fixedColorX[rectNum]]
181 }
182 lattice.fRectTypes = flags;
183
184 SkColor colors[36];
185 sk_bzero(colors, 36 * sizeof(SkColor));
186 for (int rectNum = 0; rectNum < 3; rectNum++) {
187 colors[fixedColorY[rectNum]*6 + fixedColorX[rectNum]]
188 = fixedColor[rectNum];
189 }
190
191 lattice.fColors = colors;
192
193 canvas->translate(400, 0);
194 for (int iy = 0; iy < 2; ++iy) {
195 for (int ix = 0; ix < 2; ++ix) {
196 int i = ix * 2 + iy;
197 SkRect r = SkRect::MakeXYWH(x + ix * 60, y + iy * 60,
198 size[i].width(), size[i].height());
199 canvas->drawImageLattice(image.get(), lattice, r);
200 }
201 }
202
203 canvas->restore();
204 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
kUnpremul_SkAlphaType
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
static void sk_bzero(void *buffer, size_t size)
Definition SkMalloc.h:105
#define SkIntToScalar(x)
Definition SkScalar.h:57
void restore()
Definition SkCanvas.cpp:465
void drawImageLattice(const SkImage *image, const Lattice &lattice, const SkRect &dst, SkFilterMode filter, const SkPaint *paint=nullptr)
int save()
Definition SkCanvas.cpp:451
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
bool readPixels(GrDirectContext *context, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
Definition SkImage.cpp:42
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
T * get() const
Definition SkRefCnt.h:303
SkScalar width()
Definition gm.h:159
SkScalar height()
Definition gm.h:162
sk_sp< SkImage > image
Definition examples.cpp:29
float SkScalar
Definition extension.cpp:12
FlutterSemanticsFlag flags
static void image_to_bitmap(GrDirectContext *dContext, const SkImage *image, SkBitmap *bm)
Definition lattice.cpp:84
static sk_sp< SkImage > make_image()
Definition mipmap.cpp:21
double y
double x
Optional< SkRect > bounds
Definition SkRecords.h:189
PODArray< int > xDivs
Definition SkRecords.h:271
PODArray< SkColor > colors
Definition SkRecords.h:276
PODArray< int > yDivs
Definition SkRecords.h:273
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
int fYCount
number of y-coordinates
Definition SkCanvas.h:1617
const SkIRect * fBounds
source bounds to draw from
Definition SkCanvas.h:1618
@ kFixedColor
draws one of fColors into lattice rectangle
Definition SkCanvas.h:1610
@ kTransparent
skips lattice rectangle by making it transparent
Definition SkCanvas.h:1609
const int * fYDivs
y-axis values dividing bitmap
Definition SkCanvas.h:1614
int fXCount
number of x-coordinates
Definition SkCanvas.h:1616
const RectType * fRectTypes
array of fill types
Definition SkCanvas.h:1615
const SkColor * fColors
array of colors
Definition SkCanvas.h:1619
const int * fXDivs
x-axis values dividing bitmap
Definition SkCanvas.h:1613
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition SkRect.h:91
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

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