2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BD-style license that can be
5 * found in the LICENSE file.
9 #include "sk_tool_utils.h"
14 #include "SkSurface.h"
15 #include "SkTextBlob.h"
16 #include "GrContext.h"
18 // This tests that we correctly regenerate textblobs after freeing all gpu resources crbug/491350
20 class TextBlobUseAfterGpuFree : public GM {
22 TextBlobUseAfterGpuFree() { }
25 SkString onShortName() override {
26 return SkString("textblobuseaftergpufree");
29 SkISize onISize() override {
30 return SkISize::Make(kWidth, kHeight);
33 void onDraw(SkCanvas* canvas) override {
34 // This GM exists to test a specific feature of the GPU backend.
35 if (nullptr == canvas->getGrContext()) {
36 skiagm::GM::DrawGpuOnlyMessage(canvas);
40 const char text[] = "Hamburgefons";
43 sk_tool_utils::set_portable_typeface(&paint);
44 paint.setAntiAlias(true);
45 paint.setTextSize(20);
47 SkTextBlobBuilder builder;
49 sk_tool_utils::add_to_text_blob(&builder, text, paint, 10, 10);
51 sk_sp<SkTextBlob> blob(builder.make());
54 SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
56 rectPaint.setColor(0xffffffff);
57 canvas->drawRect(rect, rectPaint);
58 canvas->drawTextBlob(blob, 10, 50, paint);
60 // This text should look fine
61 canvas->getGrContext()->freeGpuResources();
62 canvas->drawTextBlob(blob, 10, 150, paint);
66 static constexpr int kWidth = 200;
67 static constexpr int kHeight = 200;
72 //////////////////////////////////////////////////////////////////////////////
74 DEF_GM(return new TextBlobUseAfterGpuFree;)