Home | History | Annotate | Download | only in gm
      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 GpuGM {
     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(GrContext* context, GrRenderTargetContext*, SkCanvas* canvas) override {
     32         const char text[] = "Hamburgefons";
     33 
     34         SkFont font(sk_tool_utils::create_portable_typeface(), 20);
     35         auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
     36 
     37         // draw textblob
     38         SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
     39         SkPaint rectPaint;
     40         rectPaint.setColor(0xffffffff);
     41         canvas->drawRect(rect, rectPaint);
     42         canvas->drawTextBlob(blob, 20, 60, SkPaint());
     43 
     44         // This text should look fine
     45         context->freeGpuResources();
     46         canvas->drawTextBlob(blob, 20, 160, SkPaint());
     47     }
     48 
     49 private:
     50     static constexpr int kWidth = 200;
     51     static constexpr int kHeight = 200;
     52 
     53     typedef GM INHERITED;
     54 };
     55 
     56 //////////////////////////////////////////////////////////////////////////////
     57 
     58 DEF_GM(return new TextBlobUseAfterGpuFree;)
     59 }
     60