Flutter Engine
The Flutter Engine
Namespaces | Functions
gm.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkShader.h"
#include "include/core/SkTileMode.h"
#include "src/core/SkTraceEvent.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include <cstdarg>
#include <cstdint>

Go to the source code of this file.

Namespaces

namespace  skiagm
 

Functions

static void draw_failure_message (SkCanvas *canvas, const char format[],...) SK_PRINTF_LIKE(2
 
static void draw_gpu_only_message (SkCanvas *canvas)
 
static void handle_gm_failure (SkCanvas *canvas, DrawResult result, const SkString &errorMsg)
 
template<typename Fn >
static void mark (SkCanvas *canvas, SkScalar x, SkScalar y, Fn &&fn)
 
void MarkGMGood (SkCanvas *canvas, SkScalar x, SkScalar y)
 
void MarkGMBad (SkCanvas *canvas, SkScalar x, SkScalar y)
 
void skiagm::Register (skiagm::GM *gm)
 

Function Documentation

◆ draw_failure_message()

static void static void draw_failure_message ( SkCanvas canvas,
const char  format[],
  ... 
)
static

Definition at line 36 of file gm.cpp.

36 {
37 SkString failureMsg;
38
39 va_list argp;
40 va_start(argp, format);
41 failureMsg.appendVAList(format, argp);
42 va_end(argp);
43
44 constexpr SkScalar kOffset = 5.0f;
45 canvas->drawColor(SkColorSetRGB(200,0,0));
48 font.measureText(failureMsg.c_str(), failureMsg.size(), SkTextEncoding::kUTF8, &bounds);
49 SkPaint textPaint(SkColors::kWhite);
50 canvas->drawString(failureMsg, kOffset, bounds.height() + kOffset, font, textPaint);
51}
static constexpr uint64_t kOffset
Definition: DrawPass.cpp:53
#define SkColorSetRGB(r, g, b)
Definition: SkColor.h:57
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
void void void void appendVAList(const char format[], va_list) SK_PRINTF_LIKE(2
Definition: SkString.cpp:557
size_t size() const
Definition: SkString.h:131
const char * c_str() const
Definition: SkString.h:133
float SkScalar
Definition: extension.cpp:12
uint32_t uint32_t * format
constexpr SkColor4f kWhite
Definition: SkColor.h:439
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkFont DefaultPortableFont()
va_start(args, format)
va_end(args)
font
Font Metadata and Metrics.

◆ draw_gpu_only_message()

static void draw_gpu_only_message ( SkCanvas canvas)
static

Definition at line 53 of file gm.cpp.

53 {
54 SkBitmap bmp;
55 bmp.allocN32Pixels(128, 64);
56 SkCanvas bmpCanvas(bmp);
57 bmpCanvas.drawColor(SK_ColorWHITE);
60 bmpCanvas.drawString("GPU Only", 20, 40, font, paint);
61 SkMatrix localM;
62 localM.setRotate(35.f);
63 localM.postTranslate(10.f, 0.f);
67 localM));
68 canvas->drawPaint(paint);
69}
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkBitmap.cpp:669
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
SkMatrix & postTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:281
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:452
const Paint & paint
Definition: color_source.cc:38
constexpr SkColor4f kRed
Definition: SkColor.h:440
sk_sp< SkTypeface > DefaultPortableTypeface()

◆ handle_gm_failure()

static void handle_gm_failure ( SkCanvas canvas,
DrawResult  result,
const SkString errorMsg 
)
static

Definition at line 71 of file gm.cpp.

71 {
73 draw_failure_message(canvas, "DRAW FAILED: %s", errorMsg.c_str());
74 } else if (SkString(GM::kErrorMsg_DrawSkippedGpuOnly) == errorMsg) {
76 } else {
77 draw_failure_message(canvas, "DRAW SKIPPED: %s", errorMsg.c_str());
78 }
79}
GAsyncResult * result
static void draw_failure_message(SkCanvas *canvas, const char format[],...) SK_PRINTF_LIKE(2
Definition: gm.cpp:36
static void draw_gpu_only_message(SkCanvas *canvas)
Definition: gm.cpp:53

◆ mark()

template<typename Fn >
static void mark ( SkCanvas canvas,
SkScalar  x,
SkScalar  y,
Fn &&  fn 
)
static

Definition at line 211 of file gm.cpp.

211 {
212 SkPaint alpha;
213 alpha.setAlpha(0x50);
214 canvas->saveLayer(nullptr, &alpha);
215 canvas->translate(x,y);
216 canvas->scale(2,2);
217 fn();
218 canvas->restore();
219}
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void setAlpha(U8CPU a)
Definition: SkPaint.h:279
double y
double x

◆ MarkGMBad()

void MarkGMBad ( SkCanvas canvas,
SkScalar  x,
SkScalar  y 
)

Definition at line 238 of file gm.cpp.

238 {
239 mark(canvas, x,y, [&] {
240 // A red circle.
241 canvas->drawCircle(0,0, 12, SkPaint(SkColor4f::FromColor(SkColorSetRGB(231, 41, 138))));
242
243 // Cut out an 'X'.
245 paint.setBlendMode(SkBlendMode::kSrc);
246 paint.setStrokeWidth(2);
248 canvas->drawLine(-5,-5,
249 +5,+5, paint);
250 canvas->drawLine(+5,-5,
251 -5,+5, paint);
252 });
253}
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
static void mark(SkCanvas *canvas, SkScalar x, SkScalar y, Fn &&fn)
Definition: gm.cpp:211
constexpr SkColor4f kTransparent
Definition: SkColor.h:434

◆ MarkGMGood()

void MarkGMGood ( SkCanvas canvas,
SkScalar  x,
SkScalar  y 
)

Definition at line 221 of file gm.cpp.

221 {
222 mark(canvas, x,y, [&]{
223 // A green circle.
224 canvas->drawCircle(0, 0, 12, SkPaint(SkColor4f::FromColor(SkColorSetRGB(27, 158, 119))));
225
226 // Cut out a check mark.
228 paint.setBlendMode(SkBlendMode::kSrc);
229 paint.setStrokeWidth(2);
231 canvas->drawLine(-6, 0,
232 -1, 5, paint);
233 canvas->drawLine(-1, +5,
234 +7, -5, paint);
235 });
236}