Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
hello_bazel_world.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8// The purpose of this Bazel-only GM is to experiment with a task driver that uploads PNGs produced
9// by GMs executed via Bazel. By creating a GM specific for these experiments, we avoid uploading
10// spurious digests with potentially incorrect keys that would be grouped with existing digests.
11//
12// Based on //gm/bigtext.cpp.
13//
14// TODO(lovisolo): Delete once we migrate other GMs to Bazel.
15
16#include "gm/gm.h"
19#include "include/core/SkFont.h"
23#include "include/core/SkRect.h"
24#include "include/core/SkSize.h"
27#include "tools/Resources.h"
28#include "tools/ToolUtils.h"
30
32public:
34
35protected:
36 SkString getName() const override { return SkString("HelloBazelWorld"); }
37
38 SkISize getISize() override { return SkISize::Make(500, 500); }
39
40 bool isBazelOnly() const override { return true; }
41
42 void onDraw(SkCanvas* canvas) override {
44 paint.setAntiAlias(true);
46
47 const char* text = "Hello, Bazel world!";
48 size_t text_length = strlen(text);
49
50 SkRect r;
51 (void)font.measureText(text, text_length, SkTextEncoding::kUTF8, &r);
52 SkPoint pos = {this->width() / 2 - r.centerX(), this->height() / 2 - r.centerY()};
53
54 paint.setColor(SK_ColorRED);
55 canvas->drawSimpleText(
56 text, text_length, SkTextEncoding::kUTF8, pos.fX, pos.fY, font, paint);
57 }
58};
59
60DEF_GM(return new HelloBazelWorldGM;)
SkPoint pos
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
@ kUTF8
uses bytes to represent UTF-8 or ASCII
SkString getName() const override
void onDraw(SkCanvas *canvas) override
bool isBazelOnly() const override
SkISize getISize() override
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
SkScalar width()
Definition gm.h:159
SkScalar height()
Definition gm.h:162
const Paint & paint
#define DEF_GM(CODE)
Definition gm.h:40
std::u16string text
sk_sp< SkTypeface > DefaultPortableTypeface()
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
float fX
x-axis value
float fY
y-axis value
constexpr float centerX() const
Definition SkRect.h:776
constexpr float centerY() const
Definition SkRect.h:785