blob: 4c70561bbca1d6356cb3d60309eed056c4ce1f64 [file] [log] [blame]
joshualitt7a9c45c2015-05-26 12:32:23 -07001/*
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 Kleinea3f0142019-03-20 11:12:10 -05008#include "ToolUtils.h"
joshualitt7a9c45c2015-05-26 12:32:23 -07009#include "gm.h"
10
joshualitt7a9c45c2015-05-26 12:32:23 -070011#include "SkCanvas.h"
12#include "SkSurface.h"
13#include "SkTextBlob.h"
bsalomon4ee6bd82015-05-27 13:23:23 -070014#include "GrContext.h"
joshualitt7a9c45c2015-05-26 12:32:23 -070015
16// This tests that we correctly regenerate textblobs after freeing all gpu resources crbug/491350
17namespace skiagm {
Chris Dalton3a778372019-02-07 15:23:36 -070018class TextBlobUseAfterGpuFree : public GpuGM {
joshualitt7a9c45c2015-05-26 12:32:23 -070019public:
20 TextBlobUseAfterGpuFree() { }
21
22protected:
23 SkString onShortName() override {
24 return SkString("textblobuseaftergpufree");
25 }
26
27 SkISize onISize() override {
28 return SkISize::Make(kWidth, kHeight);
29 }
30
Chris Dalton3a778372019-02-07 15:23:36 -070031 void onDraw(GrContext* context, GrRenderTargetContext*, SkCanvas* canvas) override {
joshualitt7a9c45c2015-05-26 12:32:23 -070032 const char text[] = "Hamburgefons";
33
Mike Kleinea3f0142019-03-20 11:12:10 -050034 SkFont font(ToolUtils::create_portable_typeface(), 20);
Mike Reed28bd8822018-12-22 22:29:45 -050035 auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
joshualitt7a9c45c2015-05-26 12:32:23 -070036
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 Reed28bd8822018-12-22 22:29:45 -050042 canvas->drawTextBlob(blob, 20, 60, SkPaint());
joshualitt7a9c45c2015-05-26 12:32:23 -070043
44 // This text should look fine
Chris Dalton3a778372019-02-07 15:23:36 -070045 context->freeGpuResources();
Mike Reed28bd8822018-12-22 22:29:45 -050046 canvas->drawTextBlob(blob, 20, 160, SkPaint());
joshualitt7a9c45c2015-05-26 12:32:23 -070047 }
48
49private:
mtkleindbfd7ab2016-09-01 11:24:54 -070050 static constexpr int kWidth = 200;
51 static constexpr int kHeight = 200;
joshualitt7a9c45c2015-05-26 12:32:23 -070052
53 typedef GM INHERITED;
54};
55
56//////////////////////////////////////////////////////////////////////////////
57
halcanary385fe4d2015-08-26 13:07:48 -070058DEF_GM(return new TextBlobUseAfterGpuFree;)
joshualitt7a9c45c2015-05-26 12:32:23 -070059}