Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
textblobuseaftergpufree.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
10#include "include/core/SkFont.h"
12#include "include/core/SkRect.h"
14#include "include/core/SkSize.h"
19#include "tools/ToolUtils.h"
21
22#include <string.h>
23
24// This tests that we correctly regenerate textblobs after freeing all gpu resources crbug/491350
25namespace skiagm {
27public:
29
30protected:
31 SkString getName() const override { return SkString("textblobuseaftergpufree"); }
32
33 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
34
35 void onDraw(SkCanvas* canvas) override {
36 auto dContext = GrAsDirectContext(canvas->recordingContext());
37
38 const char text[] = "Hamburgefons";
39
41 auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
42
43 // draw textblob
44 SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
45 SkPaint rectPaint;
46 rectPaint.setColor(0xffffffff);
47 canvas->drawRect(rect, rectPaint);
48 canvas->drawTextBlob(blob, 20, 60, SkPaint());
49
50 // This text should look fine
51 if (dContext) {
52 dContext->freeGpuResources();
53 }
54 canvas->drawTextBlob(blob, 20, 160, SkPaint());
55 }
56
57private:
58 inline static constexpr int kWidth = 200;
59 inline static constexpr int kHeight = 200;
60
61 using INHERITED = GM;
62};
63
64//////////////////////////////////////////////////////////////////////////////
65
66DEF_GM(return new TextBlobUseAfterGpuFree;)
67} // namespace skiagm
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
#define SkIntToScalar(x)
Definition SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
virtual GrRecordingContext * recordingContext() const
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
void setColor(SkColor color)
Definition SkPaint.cpp:119
static sk_sp< SkTextBlob > MakeFromText(const void *text, size_t byteLength, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
void onDraw(SkCanvas *canvas) override
#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
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646