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