• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.h"
9 #include "sk_tool_utils.h"
10 
11 #include "SkCanvas.h"
12 #include "SkSurface.h"
13 #include "SkTextBlob.h"
14 #include "GrContext.h"
15 
16 // This tests that we correctly regenerate textblobs after freeing all gpu resources crbug/491350
17 namespace skiagm {
18 class TextBlobUseAfterGpuFree : public GM {
19 public:
TextBlobUseAfterGpuFree()20     TextBlobUseAfterGpuFree() { }
21 
22 protected:
onShortName()23     SkString onShortName() override {
24         return SkString("textblobuseaftergpufree");
25     }
26 
onISize()27     SkISize onISize() override {
28         return SkISize::Make(kWidth, kHeight);
29     }
30 
onDraw(SkCanvas * canvas)31     void onDraw(SkCanvas* canvas) override {
32         // This GM exists to test a specific feature of the GPU backend.
33         if (nullptr == canvas->getGrContext()) {
34             skiagm::GM::DrawGpuOnlyMessage(canvas);
35             return;
36         }
37 
38         const char text[] = "Hamburgefons";
39 
40         SkFont font(sk_tool_utils::create_portable_typeface(), 20);
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         canvas->getGrContext()->freeGpuResources();
52         canvas->drawTextBlob(blob, 20, 160, SkPaint());
53     }
54 
55 private:
56     static constexpr int kWidth = 200;
57     static constexpr int kHeight = 200;
58 
59     typedef GM INHERITED;
60 };
61 
62 //////////////////////////////////////////////////////////////////////////////
63 
64 DEF_GM(return new TextBlobUseAfterGpuFree;)
65 }
66