joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 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 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame^] | 8 | #include "ToolUtils.h" |
joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 9 | #include "gm.h" |
| 10 | |
joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 11 | #include "SkCanvas.h" |
| 12 | #include "SkSurface.h" |
| 13 | #include "SkTextBlob.h" |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 14 | #include "GrContext.h" |
joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 15 | |
| 16 | // This tests that we correctly regenerate textblobs after freeing all gpu resources crbug/491350 |
| 17 | namespace skiagm { |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 18 | class TextBlobUseAfterGpuFree : public GpuGM { |
joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 19 | public: |
| 20 | TextBlobUseAfterGpuFree() { } |
| 21 | |
| 22 | protected: |
| 23 | SkString onShortName() override { |
| 24 | return SkString("textblobuseaftergpufree"); |
| 25 | } |
| 26 | |
| 27 | SkISize onISize() override { |
| 28 | return SkISize::Make(kWidth, kHeight); |
| 29 | } |
| 30 | |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 31 | void onDraw(GrContext* context, GrRenderTargetContext*, SkCanvas* canvas) override { |
joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 32 | const char text[] = "Hamburgefons"; |
| 33 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame^] | 34 | SkFont font(ToolUtils::create_portable_typeface(), 20); |
Mike Reed | 28bd882 | 2018-12-22 22:29:45 -0500 | [diff] [blame] | 35 | auto blob = SkTextBlob::MakeFromText(text, strlen(text), font); |
joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 36 | |
| 37 | // draw textblob |
| 38 | SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f); |
| 39 | SkPaint rectPaint; |
| 40 | rectPaint.setColor(0xffffffff); |
| 41 | canvas->drawRect(rect, rectPaint); |
Mike Reed | 28bd882 | 2018-12-22 22:29:45 -0500 | [diff] [blame] | 42 | canvas->drawTextBlob(blob, 20, 60, SkPaint()); |
joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 43 | |
| 44 | // This text should look fine |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 45 | context->freeGpuResources(); |
Mike Reed | 28bd882 | 2018-12-22 22:29:45 -0500 | [diff] [blame] | 46 | canvas->drawTextBlob(blob, 20, 160, SkPaint()); |
joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | private: |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 50 | static constexpr int kWidth = 200; |
| 51 | static constexpr int kHeight = 200; |
joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 52 | |
| 53 | typedef GM INHERITED; |
| 54 | }; |
| 55 | |
| 56 | ////////////////////////////////////////////////////////////////////////////// |
| 57 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 58 | DEF_GM(return new TextBlobUseAfterGpuFree;) |
joshualitt | 7a9c45c | 2015-05-26 12:32:23 -0700 | [diff] [blame] | 59 | } |