| 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" |
| 17 |
#include "include/core/SkCanvas.h" |
| 18 |
#include "include/core/SkColor.h" |
| 19 |
#include "include/core/SkFont.h" |
| 20 |
#include "include/core/SkFontTypes.h" |
| 21 |
#include "include/core/SkPaint.h" |
| 22 |
#include "include/core/SkPoint.h" |
| 23 |
#include "include/core/SkRect.h" |
| 24 |
#include "include/core/SkSize.h" |
| 25 |
#include "include/core/SkString.h" |
| 26 |
#include "include/core/SkTypeface.h" |
| 27 |
#include "tools/Resources.h" |
| 28 |
#include "tools/ToolUtils.h" |
| 29 |
#include "tools/fonts/FontToolUtils.h" |
| 30 |
|
| 31 |
class HelloBazelWorldGM : public skiagm::GM { |
| 32 |
public: |
| 33 |
HelloBazelWorldGM() {} |
| 34 |
|
| 35 |
protected: |
| 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 { |
| 43 |
SkPaint paint; |
| 44 |
paint.setAntiAlias(true); |
| 45 |
SkFont font(ToolUtils::DefaultPortableTypeface(), 50); |
| 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 |
|
| 60 |
DEF_GM(return new HelloBazelWorldGM;) |