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

Public Member Functions

 DrawBitmapRectGM (DrawRectRectProc proc, const char suffix[])
 
- 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
 

Public Attributes

DrawRectRectProcfProc
 
SkBitmap fLargeBitmap
 
sk_sp< SkImagefImage
 
SkString fName
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
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 DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
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

Definition at line 168 of file drawbitmaprect.cpp.

Constructor & Destructor Documentation

◆ DrawBitmapRectGM()

DrawBitmapRectGM::DrawBitmapRectGM ( DrawRectRectProc  proc,
const char  suffix[] 
)
inline

Definition at line 170 of file drawbitmaprect.cpp.

170 : fProc(proc) {
171 fName.set("drawbitmaprect");
172 if (suffix) {
174 }
175 }
DrawRectRectProc * fProc
void set(const SkString &src)
Definition: SkString.h:186
void append(const char text[])
Definition: SkString.h:203

Member Function Documentation

◆ getISize()

SkISize DrawBitmapRectGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 185 of file drawbitmaprect.cpp.

185{ return SkISize::Make(gSize, gSize); }
constexpr int gSize
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString DrawBitmapRectGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 183 of file drawbitmaprect.cpp.

183{ return fName; }

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 187 of file drawbitmaprect.cpp.

187 {
188 if (!fImage || !fImage->isValid(canvas->recordingContext())) {
191 if (!fImage) {
192 *errorMsg = "Image creation failed";
193 return DrawResult::kSkip;
194 }
195 }
196
197 SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};
198 const int kMaxSrcRectSize = 1 << (SkNextLog2(gBmpSize) + 2);
199
200 const int kPadX = 30;
201 const int kPadY = 40;
202 SkPaint alphaPaint;
203 alphaPaint.setAlphaf(0.125f);
205 &alphaPaint);
206 canvas->translate(SK_Scalar1 * kPadX / 2,
207 SK_Scalar1 * kPadY / 2);
208 SkPaint blackPaint;
209 SkScalar titleHeight = SK_Scalar1 * 24;
210 blackPaint.setColor(SK_ColorBLACK);
211 blackPaint.setAntiAlias(true);
212
214
215 SkString title;
216 title.printf("Bitmap size: %d x %d", gBmpSize, gBmpSize);
217 canvas->drawString(title, 0, titleHeight, font, blackPaint);
218
219 canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight);
220 int rowCount = 0;
221 canvas->save();
222 for (int w = 1; w <= kMaxSrcRectSize; w *= 4) {
223 for (int h = 1; h <= kMaxSrcRectSize; h *= 4) {
224
225 SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSize - h) / 2, w, h);
226 fProc(canvas, fImage, fLargeBitmap, srcRect, dstRect, SkSamplingOptions(),
227 nullptr);
228
229 SkString label;
230 label.appendf("%d x %d", w, h);
231 blackPaint.setAntiAlias(true);
232 blackPaint.setStyle(SkPaint::kFill_Style);
233 font.setSize(SK_Scalar1 * 10);
234 SkScalar baseline = dstRect.height() + font.getSize() + SK_Scalar1 * 3;
235 canvas->drawString(label, 0, baseline, font, blackPaint);
237 blackPaint.setStrokeWidth(SK_Scalar1);
238 blackPaint.setAntiAlias(false);
239 canvas->drawRect(dstRect, blackPaint);
240
241 canvas->translate(dstRect.width() + SK_Scalar1 * kPadX, 0);
242 ++rowCount;
243 if ((dstRect.width() + kPadX) * rowCount > gSize) {
244 canvas->restore();
245 canvas->translate(0, dstRect.height() + SK_Scalar1 * kPadY);
246 canvas->save();
247 rowCount = 0;
248 }
249 }
250 }
251
252 {
253 // test the following code path:
254 // SkGpuDevice::drawPath() -> SkGpuDevice::drawWithMaskFilter()
255 SkIRect srcRect;
256 SkPaint maskPaint;
257 SkBitmap bm = make_chessbm(5, 5);
259
260 srcRect.setXYWH(1, 1, 3, 3);
264
265 fProc(canvas, img, bm, srcRect, dstRect,
267 }
268
269 return DrawResult::kOk;
270 }
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
static int SkNextLog2(uint32_t value)
Definition: SkMathPriv.h:238
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkIntToScalar(x)
Definition: SkScalar.h:57
sk_sp< SkImage > fImage
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
static SkScalar SK_SPI ConvertRadiusToSigma(SkScalar radius)
Definition: SkBlurMask.cpp:39
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
int save()
Definition: SkCanvas.cpp:447
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
virtual bool isValid(GrRecordingContext *context) const =0
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
void setMaskFilter(sk_sp< SkMaskFilter > maskFilter)
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
void setAlphaf(float a)
Definition: SkPaint.cpp:130
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
constexpr int gBmpSize
static SkBitmap make_chessbm(int w, int h)
static sk_sp< SkImage > makebm(SkCanvas *origCanvas, SkBitmap *resultBM, int w, int h)
float SkScalar
Definition: extension.cpp:12
sk_sp< SkTypeface > DefaultPortableTypeface()
sk_sp< SkImage > MakeTextureImage(SkCanvas *canvas, sk_sp< SkImage > orig)
font
Font Metadata and Metrics.
SkSamplingOptions(SkFilterMode::kLinear))
SkScalar w
SkScalar h
Definition: SkRect.h:32
void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height)
Definition: SkRect.h:268
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762

Member Data Documentation

◆ fImage

sk_sp<SkImage> DrawBitmapRectGM::fImage

Definition at line 179 of file drawbitmaprect.cpp.

◆ fLargeBitmap

SkBitmap DrawBitmapRectGM::fLargeBitmap

Definition at line 178 of file drawbitmaprect.cpp.

◆ fName

SkString DrawBitmapRectGM::fName

Definition at line 180 of file drawbitmaprect.cpp.

◆ fProc

DrawRectRectProc* DrawBitmapRectGM::fProc

Definition at line 177 of file drawbitmaprect.cpp.


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