blob: 070c9ef1556c35bffde9b2a572fd99217a09350f [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
8#include "gm.h"
9
10#if SK_SUPPORT_GPU
11
12#include "SkCanvas.h"
13#include "SkSurface.h"
14#include "SkTextBlob.h"
bsalomon4ee6bd82015-05-27 13:23:23 -070015#include "GrContext.h"
joshualitt7a9c45c2015-05-26 12:32:23 -070016
17// This tests that we correctly regenerate textblobs after freeing all gpu resources crbug/491350
18namespace skiagm {
19class TextBlobUseAfterGpuFree : public GM {
20public:
21 TextBlobUseAfterGpuFree() { }
22
23protected:
24 SkString onShortName() override {
25 return SkString("textblobuseaftergpufree");
26 }
27
28 SkISize onISize() override {
29 return SkISize::Make(kWidth, kHeight);
30 }
31
32 void onDraw(SkCanvas* canvas) override {
33 // This GM exists to test a specific feature of the GPU backend.
34 if (NULL == canvas->getGrContext()) {
35 this->drawGpuOnlyMessage(canvas);
36 return;
37 }
38
39 const char text[] = "Hamburgefons";
40
41 SkPaint paint;
42 sk_tool_utils::set_portable_typeface(&paint);
43 paint.setTextSize(20);
44
45 SkTextBlobBuilder builder;
46
47 sk_tool_utils::add_to_text_blob(&builder, text, paint, 10, 10);
48
49 SkAutoTUnref<const SkTextBlob> blob(builder.build());
50
51 // draw textblob
52 SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
53 SkPaint rectPaint;
54 rectPaint.setColor(0xffffffff);
55 canvas->drawRect(rect, rectPaint);
56 canvas->drawTextBlob(blob.get(), 10, 50, paint);
57
58 // This text should look fine
59 canvas->getGrContext()->freeGpuResources();
60 canvas->drawTextBlob(blob.get(), 10, 150, paint);
61 }
62
63private:
64 static const int kWidth = 200;
65 static const int kHeight = 200;
66
67 typedef GM INHERITED;
68};
69
70//////////////////////////////////////////////////////////////////////////////
71
72DEF_GM( return SkNEW(TextBlobUseAfterGpuFree); )
73}
74#endif