blob: 0cefcd1951db4cd14d37b012f138e485e47228db [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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkCanvas.h"
10#include "include/core/SkFont.h"
11#include "include/core/SkPaint.h"
12#include "include/core/SkRect.h"
13#include "include/core/SkScalar.h"
14#include "include/core/SkSize.h"
15#include "include/core/SkString.h"
16#include "include/core/SkTextBlob.h"
17#include "include/core/SkTypeface.h"
18#include "include/gpu/GrContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "tools/ToolUtils.h"
joshualitt7a9c45c2015-05-26 12:32:23 -070020
Ben Wagner7fde8e12019-05-01 17:28:53 -040021#include <string.h>
22
23class GrRenderTargetContext;
joshualitt7a9c45c2015-05-26 12:32:23 -070024
25// This tests that we correctly regenerate textblobs after freeing all gpu resources crbug/491350
26namespace skiagm {
Chris Dalton3a778372019-02-07 15:23:36 -070027class TextBlobUseAfterGpuFree : public GpuGM {
joshualitt7a9c45c2015-05-26 12:32:23 -070028public:
29 TextBlobUseAfterGpuFree() { }
30
31protected:
32 SkString onShortName() override {
33 return SkString("textblobuseaftergpufree");
34 }
35
36 SkISize onISize() override {
37 return SkISize::Make(kWidth, kHeight);
38 }
39
Chris Dalton3a778372019-02-07 15:23:36 -070040 void onDraw(GrContext* context, GrRenderTargetContext*, SkCanvas* canvas) override {
joshualitt7a9c45c2015-05-26 12:32:23 -070041 const char text[] = "Hamburgefons";
42
Mike Kleinea3f0142019-03-20 11:12:10 -050043 SkFont font(ToolUtils::create_portable_typeface(), 20);
Mike Reed28bd8822018-12-22 22:29:45 -050044 auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
joshualitt7a9c45c2015-05-26 12:32:23 -070045
46 // draw textblob
47 SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
48 SkPaint rectPaint;
49 rectPaint.setColor(0xffffffff);
50 canvas->drawRect(rect, rectPaint);
Mike Reed28bd8822018-12-22 22:29:45 -050051 canvas->drawTextBlob(blob, 20, 60, SkPaint());
joshualitt7a9c45c2015-05-26 12:32:23 -070052
53 // This text should look fine
Chris Dalton3a778372019-02-07 15:23:36 -070054 context->freeGpuResources();
Mike Reed28bd8822018-12-22 22:29:45 -050055 canvas->drawTextBlob(blob, 20, 160, SkPaint());
joshualitt7a9c45c2015-05-26 12:32:23 -070056 }
57
58private:
mtkleindbfd7ab2016-09-01 11:24:54 -070059 static constexpr int kWidth = 200;
60 static constexpr int kHeight = 200;
joshualitt7a9c45c2015-05-26 12:32:23 -070061
62 typedef GM INHERITED;
63};
64
65//////////////////////////////////////////////////////////////////////////////
66
halcanary385fe4d2015-08-26 13:07:48 -070067DEF_GM(return new TextBlobUseAfterGpuFree;)
joshualitt7a9c45c2015-05-26 12:32:23 -070068}