| 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/gm.h" |
| 9 |
#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 "tools/ToolUtils.h" |
| 19 |
#include "tools/fonts/FontToolUtils.h" |
| 20 |
|
| 21 |
#include <string.h> |
| 22 |
|
| 23 |
#if defined(SK_GANESH) |
| 24 |
#include "include/gpu/ganesh/GrDirectContext.h" |
| 25 |
#include "include/gpu/ganesh/GrRecordingContext.h" |
| 26 |
#endif |
| 27 |
|
| 28 |
// This tests that we correctly regenerate textblobs after freeing all gpu resources crbug/491350 |
| 29 |
namespace skiagm { |
| 30 |
class TextBlobUseAfterGpuFree : public GM { |
| 31 |
public: |
| 32 |
TextBlobUseAfterGpuFree() { } |
| 33 |
|
| 34 |
protected: |
| 35 |
SkString getName() const override { return SkString("textblobuseaftergpufree"); } |
| 36 |
|
| 37 |
SkISize getISize() override { return SkISize::Make(kWidth, kHeight); } |
| 38 |
|
| 39 |
void onDraw(SkCanvas* canvas) override { |
| 40 |
const char text[] = "Hamburgefons"; |
| 41 |
|
| 42 |
SkFont font(ToolUtils::DefaultPortableTypeface(), 20); |
| 43 |
auto blob = SkTextBlob::MakeFromText(text, strlen(text), font); |
| 44 |
|
| 45 |
// draw textblob |
| 46 |
SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f); |
| 47 |
SkPaint rectPaint; |
| 48 |
rectPaint.setColor(0xffffffff); |
| 49 |
canvas->drawRect(rect, rectPaint); |
| 50 |
canvas->drawTextBlob(blob, 20, 60, SkPaint()); |
| 51 |
|
| 52 |
#if defined(SK_GANESH) |
| 53 |
// This text should look fine |
| 54 |
if (auto dContext = GrAsDirectContext(canvas->recordingContext())) { |
| 55 |
dContext->freeGpuResources(); |
| 56 |
} |
| 57 |
#endif |
| 58 |
|
| 59 |
canvas->drawTextBlob(blob, 20, 160, SkPaint()); |
| 60 |
} |
| 61 |
|
| 62 |
private: |
| 63 |
inline static constexpr int kWidth = 200; |
| 64 |
inline static constexpr int kHeight = 200; |
| 65 |
|
| 66 |
using INHERITED = GM; |
| 67 |
}; |
| 68 |
|
| 69 |
////////////////////////////////////////////////////////////////////////////// |
| 70 |
|
| 71 |
DEF_GM(return new TextBlobUseAfterGpuFree;) |
| 72 |
} // namespace skiagm |